Skip to content

Commit

Permalink
feat: yarn pack (#329)
Browse files Browse the repository at this point in the history
  • Loading branch information
Aslemammad authored Feb 21, 2025
1 parent 86cec07 commit 88bbad4
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 8 deletions.
1 change: 0 additions & 1 deletion .eslintcache

This file was deleted.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ To customize which package manager is reflected in the comments, use the `--pack

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

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.
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.

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

Expand Down
29 changes: 23 additions & 6 deletions packages/cli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,14 @@ const main = defineCommand({
const formData = new FormData();

const isCompact = !!args.compact;
const isPnpm = !!args.pnpm;
let packMethod: PackMethod = "npm";

if (args.pnpm) {
packMethod = "pnpm";
} else if (args.yarn) {
packMethod = "yarn";
}

const isPeerDepsEnabled = !!args.peerDeps;
const isOnlyTemplates = !!args["only-templates"];

Expand Down Expand Up @@ -363,8 +370,9 @@ const main = defineCommand({
}

const { filename, shasum } = await resolveTarball(
isPnpm ? "pnpm" : "npm",
packMethod,
p,
pJson,
);

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

// TODO: we'll add support for yarn if users hit issues with npm
async function resolveTarball(pm: "npm" | "pnpm", p: string) {
const { stdout } = await ezSpawn.async(`${pm} pack`, {
type PackMethod = "npm" | "pnpm" | "yarn";

async function resolveTarball(pm: PackMethod, p: string, pJson: PackageJson) {
let cmd = `${pm} pack`;
let filename = `${pJson.name!.replace("/", "-")}-${pJson.version}.tgz`;
if (pm === "yarn") {
cmd += ` --filename ${filename}`;
}
const { stdout } = await ezSpawn.async(cmd, {
stdio: "overlapped",
cwd: p,
});
const lines = stdout.split("\n").filter(Boolean);
const filename = lines[lines.length - 1].trim();

if (pm !== "yarn") {
filename = lines[lines.length - 1].trim();
}

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

0 comments on commit 88bbad4

Please sign in to comment.