Skip to content

Commit 88bbad4

Browse files
authored
feat: yarn pack (#329)
1 parent 86cec07 commit 88bbad4

File tree

3 files changed

+24
-8
lines changed

3 files changed

+24
-8
lines changed

Diff for: .eslintcache

-1
This file was deleted.

Diff for: README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ To customize which package manager is reflected in the comments, use the `--pack
159159

160160
For repositories with many packages, comments might get too long. In that case, you can use `--only-templates` to only show templates.
161161

162-
pkg.pr.new uses `npm pack --json` under the hood, in case you face issues, you can also use the `--pnpm` flag so it starts using `pnpm pack`. This is not necessary in most cases.
162+
pkg.pr.new uses `npm pack --json` under the hood, in case you face issues, you can also use the `--pnpm` or `--yarn` flag so it starts using `pnpm pack` or `yarn pack`. This is not necessary in most cases.
163163

164164
<img width="100%" src="https://github.com/stackblitz-labs/pkg.pr.new/assets/37929992/2fc03b94-ebae-4c47-a271-03a4ad5d2449" />
165165

Diff for: packages/cli/index.ts

+23-6
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,14 @@ const main = defineCommand({
115115
const formData = new FormData();
116116

117117
const isCompact = !!args.compact;
118-
const isPnpm = !!args.pnpm;
118+
let packMethod: PackMethod = "npm";
119+
120+
if (args.pnpm) {
121+
packMethod = "pnpm";
122+
} else if (args.yarn) {
123+
packMethod = "yarn";
124+
}
125+
119126
const isPeerDepsEnabled = !!args.peerDeps;
120127
const isOnlyTemplates = !!args["only-templates"];
121128

@@ -363,8 +370,9 @@ const main = defineCommand({
363370
}
364371

365372
const { filename, shasum } = await resolveTarball(
366-
isPnpm ? "pnpm" : "npm",
373+
packMethod,
367374
p,
375+
pJson,
368376
);
369377

370378
shasums[pJson.name] = shasum;
@@ -536,14 +544,23 @@ runMain(main)
536544
.then(() => process.exit(0))
537545
.catch(() => process.exit(1));
538546

539-
// TODO: we'll add support for yarn if users hit issues with npm
540-
async function resolveTarball(pm: "npm" | "pnpm", p: string) {
541-
const { stdout } = await ezSpawn.async(`${pm} pack`, {
547+
type PackMethod = "npm" | "pnpm" | "yarn";
548+
549+
async function resolveTarball(pm: PackMethod, p: string, pJson: PackageJson) {
550+
let cmd = `${pm} pack`;
551+
let filename = `${pJson.name!.replace("/", "-")}-${pJson.version}.tgz`;
552+
if (pm === "yarn") {
553+
cmd += ` --filename ${filename}`;
554+
}
555+
const { stdout } = await ezSpawn.async(cmd, {
542556
stdio: "overlapped",
543557
cwd: p,
544558
});
545559
const lines = stdout.split("\n").filter(Boolean);
546-
const filename = lines[lines.length - 1].trim();
560+
561+
if (pm !== "yarn") {
562+
filename = lines[lines.length - 1].trim();
563+
}
547564

548565
const shasum = createHash("sha1")
549566
.update(await fs.readFile(path.resolve(p, filename)))

0 commit comments

Comments
 (0)