Skip to content

Commit df89bc4

Browse files
authored
feat: packageManager option support multiple value (#415)
1 parent f79956b commit df89bc4

File tree

3 files changed

+47
-34
lines changed

3 files changed

+47
-34
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ With `--comment=create`, each commit would generate a comment for itself, useful
198198

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

201-
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.
201+
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. Multiple valid values ​​can also be configured at the same time, such as `--packageManager=ABC,XYZ`.
202202

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

packages/app/server/utils/markdown.ts

Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -35,18 +35,22 @@ export function generateCommitPublishMessage(
3535
workflowData,
3636
compact,
3737
);
38-
39-
if (packageManager === "yarn") {
40-
shaUrl = `${shaUrl}.tgz`;
41-
}
42-
43-
const descriptor = `${packageManager === "yarn" ? `${packageName}@` : ""}${shaUrl}`;
44-
45-
return `
46-
\`\`\`
47-
${bin ? binCommands[packageManager] : installCommands[packageManager]} ${descriptor}
48-
\`\`\`
49-
`;
38+
return packageManager
39+
.split(",")
40+
.map((pm) => {
41+
if (pm === "yarn") {
42+
shaUrl = `${shaUrl}.tgz`;
43+
}
44+
45+
const descriptor = `${pm === "yarn" ? `${packageName}@` : ""}${shaUrl}`;
46+
47+
return `
48+
\`\`\`
49+
${bin ? binCommands[pm as PackageManager] : installCommands[pm as PackageManager]} ${descriptor}
50+
\`\`\`
51+
`;
52+
})
53+
.join("\n");
5054
})
5155
.map((message, i) =>
5256
isMoreThanFour
@@ -86,16 +90,20 @@ export function generatePullRequestPublishMessage(
8690
workflowData,
8791
compact,
8892
);
89-
90-
if (packageManager === "yarn") {
91-
refUrl = `${refUrl}.tgz`;
92-
}
93-
94-
return `
95-
\`\`\`
96-
${bin ? binCommands[packageManager] : installCommands[packageManager]} ${refUrl}
97-
\`\`\`
98-
`;
93+
return packageManager
94+
.split(",")
95+
.map((pm) => {
96+
if (pm === "yarn") {
97+
refUrl = `${refUrl}.tgz`;
98+
}
99+
100+
return `
101+
\`\`\`
102+
${bin ? binCommands[pm as PackageManager] : installCommands[pm as PackageManager]} ${refUrl}
103+
\`\`\`
104+
`;
105+
})
106+
.join("\n");
99107
})
100108
.map((message, i) =>
101109
isMoreThanFour

packages/cli/index.ts

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -143,20 +143,25 @@ const main = defineCommand({
143143
const isOnlyTemplates = !!args["only-templates"];
144144
const isBinaryApplication = !!args.bin;
145145
const comment: Comment = args.comment as Comment;
146-
const selectedPackageManager = args.packageManager as
147-
| "npm"
148-
| "bun"
149-
| "pnpm"
150-
| "yarn";
151-
152-
if (
153-
!["npm", "bun", "pnpm", "yarn"].includes(selectedPackageManager)
154-
) {
146+
const selectedPackageManager = (args.packageManager as string)
147+
.split(",")
148+
.filter((s) => s.trim()) as Array<"npm" | "bun" | "pnpm" | "yarn">;
149+
const packageManagers = ["npm", "bun", "pnpm", "yarn"];
150+
151+
if (!selectedPackageManager.length) {
155152
console.error(
156-
`Unsupported package manager: ${selectedPackageManager}. Supported managers are npm, bun, pnpm, yarn.`,
153+
`Unsupported package manager: ${args.packageManager}. Supported managers are npm, bun, pnpm, yarn.`,
157154
);
158155
process.exit(1);
159156
}
157+
for (let i = 0; i < packageManagers.length; i++) {
158+
if (!packageManagers.includes(packageManagers[i])) {
159+
console.error(
160+
`Unsupported package manager: ${packageManagers[i]}. Supported managers are npm, bun, pnpm, yarn.`,
161+
);
162+
process.exit(1);
163+
}
164+
}
160165

161166
if (!process.env.TEST && process.env.GITHUB_ACTIONS !== "true") {
162167
console.error(
@@ -511,7 +516,7 @@ const main = defineCommand({
511516
"sb-shasums": JSON.stringify(shasums),
512517
"sb-run-id": GITHUB_RUN_ID,
513518
"sb-bin": `${isBinaryApplication}`,
514-
"sb-package-manager": selectedPackageManager,
519+
"sb-package-manager": selectedPackageManager[0],
515520
"sb-only-templates": `${isOnlyTemplates}`,
516521
},
517522
body: formData,

0 commit comments

Comments
 (0)