Skip to content
Merged
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,8 @@ With `--comment=create`, each commit would generate a comment for itself, useful

And `--comment=off` would turn off comments for maintainers who prefer minimal pull requests.

To customize which package manager is reflected in the comments, use the `--packageManager=XYZ` flag. XYZ can be one of the following: npm (default), pnpm, yarn, or bun.

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.
Expand Down
21 changes: 15 additions & 6 deletions packages/cli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { createHash } from "node:crypto";
import { hash } from "ohash";
import fsSync from "fs";
import fs from "fs/promises";
import { detect } from "package-manager-detector";
import { getPackageManifest, type PackageManifest } from "query-registry";
import type { Comment } from "@pkg-pr-new/utils";
import {
Expand Down Expand Up @@ -88,6 +87,12 @@ const main = defineCommand({
type: "mixed",
description: `Save metadata to a JSON file. If true, log the output for piping. If a string, save the output to the specified file path.`,
},
packageManager: {
type: "string",
description: "Specify the package manager to use (npm, bun, pnpm, yarn)",
enum: ["npm", "bun", "pnpm", "yarn"],
default: "npm",
},
},
run: async ({ args }) => {
const paths =
Expand All @@ -113,6 +118,14 @@ const main = defineCommand({
const isOnlyTemplates = !!args["only-templates"];

const comment: Comment = args.comment as Comment;
const selectedPackageManager = args.packageManager as "npm" | "bun" | "pnpm" | "yarn";

if (!["npm", "bun", "pnpm", "yarn"].includes(selectedPackageManager)) {
console.error(
`Unsupported package manager: ${selectedPackageManager}. Supported managers are npm, bun, pnpm, yarn.`
);
process.exit(1);
}

if (!process.env.TEST && process.env.GITHUB_ACTIONS !== "true") {
console.error(
Expand Down Expand Up @@ -433,10 +446,6 @@ const main = defineCommand({
}
}

const packageManager = await detect();
const agent = packageManager.agent.includes("@")
? packageManager.agent.split("@")[0]
: packageManager.agent;
const res = await fetch(publishUrl, {
method: "POST",
headers: {
Expand All @@ -445,7 +454,7 @@ const main = defineCommand({
"sb-key": key,
"sb-shasums": JSON.stringify(shasums),
"sb-run-id": GITHUB_RUN_ID,
"sb-package-manager": agent ?? "npm",
"sb-package-manager": selectedPackageManager,
"sb-only-templates": `${isOnlyTemplates}`,
},
body: formData,
Expand Down
1 change: 0 additions & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
"@octokit/action": "^6.1.0",
"ignore": "^5.3.1",
"isbinaryfile": "^5.0.2",
"package-manager-detector": "^0.1.2",
"pkg-types": "^1.1.1",
"query-registry": "^3.0.1",
"tinyglobby": "^0.2.9"
Expand Down
75 changes: 39 additions & 36 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.