Skip to content

Commit 68e4319

Browse files
authored
feat: add commentWithDev option (#436)
1 parent e8b6466 commit 68e4319

File tree

4 files changed

+31
-2
lines changed

4 files changed

+31
-2
lines changed

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,20 @@ Without `--commentWithSha`:
213213
npm i https://pkg.pr.new/tinybench@123
214214
```
215215

216+
> `--commentWithDev` specify whether the generated link includes the `-D` parameter.
217+
218+
With `--commentWithDev`:
219+
220+
```sh
221+
npm i https://pkg.pr.new/tinybench@123 -D
222+
```
223+
224+
Without `--commentWithDev`:
225+
226+
```sh
227+
npm i https://pkg.pr.new/tinybench@123
228+
```
229+
216230
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`.
217231

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

packages/app/server/routes/publish.post.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export default eventHandler(async (event) => {
2222
"sb-package-manager": packageManagerHeader,
2323
"sb-only-templates": onlyTemplatesHeader,
2424
"sb-comment-with-sha": commentWithShaHeader,
25+
"sb-comment-with-dev": commentWithDevHeader,
2526
} = getHeaders(event);
2627
const compact = compactHeader === "true";
2728
const onlyTemplates = onlyTemplatesHeader === "true";
@@ -30,6 +31,7 @@ export default eventHandler(async (event) => {
3031
const packageManager: PackageManager =
3132
(packageManagerHeader as PackageManager) || "npm";
3233
const commentWithSha = commentWithShaHeader === "true";
34+
const commentWithDev = commentWithDevHeader === "true";
3335

3436
if (!key || !runIdHeader || !shasumsHeader) {
3537
throw createError({
@@ -232,6 +234,7 @@ export default eventHandler(async (event) => {
232234
compact,
233235
packageManager,
234236
bin,
237+
commentWithDev,
235238
),
236239
},
237240
conclusion: "success",
@@ -294,6 +297,7 @@ export default eventHandler(async (event) => {
294297
packageManager,
295298
commentWithSha ? "sha" : "ref",
296299
bin,
300+
commentWithDev,
297301
),
298302
},
299303
);
@@ -315,6 +319,7 @@ export default eventHandler(async (event) => {
315319
packageManager,
316320
comment === "update" ? "ref" : "sha",
317321
bin,
322+
commentWithDev,
318323
),
319324
},
320325
);

packages/app/server/utils/markdown.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export function generateCommitPublishMessage(
2828
compact: boolean,
2929
packageManager: PackageManager,
3030
bin: boolean,
31+
commentWithDev: boolean,
3132
) {
3233
const isMoreThanFour = isMoreThanFourPackages(packages, packageManager);
3334
const shaMessages = packages
@@ -46,7 +47,7 @@ export function generateCommitPublishMessage(
4647
shaUrl = `${shaUrl}.tgz`;
4748
}
4849

49-
const descriptor = `${pm === "yarn" ? `${packageName}@` : ""}${shaUrl}`;
50+
const descriptor = `${pm === "yarn" ? `${packageName}@` : ""}${shaUrl + (commentWithDev ? " -D" : "")}`;
5051

5152
return `
5253
\`\`\`
@@ -83,6 +84,7 @@ export function generatePullRequestPublishMessage(
8384
packageManager: PackageManager,
8485
base: "sha" | "ref",
8586
bin: boolean,
87+
commentWithDev: boolean,
8688
) {
8789
const isMoreThanFour = isMoreThanFourPackages(packages, packageManager);
8890
const refMessages = packages
@@ -103,7 +105,7 @@ export function generatePullRequestPublishMessage(
103105

104106
return `
105107
\`\`\`
106-
${bin ? binCommands[pm as PackageManager] : installCommands[pm as PackageManager]} ${refUrl}
108+
${bin ? binCommands[pm as PackageManager] : installCommands[pm as PackageManager]} ${refUrl + (commentWithDev ? " -D" : "")}
107109
\`\`\`
108110
`;
109111
})

packages/cli/index.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,12 @@ const main = defineCommand({
9494
"use commit sha instead of the pr number in the comment links",
9595
default: false,
9696
},
97+
commentWithDev: {
98+
type: "boolean",
99+
description:
100+
"should install the packages with the 'dev' tag in the comment links",
101+
default: false,
102+
},
97103
"only-templates": {
98104
type: "boolean",
99105
description: `generate only stackblitz templates`,
@@ -149,6 +155,7 @@ const main = defineCommand({
149155
const isOnlyTemplates = !!args["only-templates"];
150156
const isBinaryApplication = !!args.bin;
151157
const isCommentWithSha = !!args.commentWithSha;
158+
const isCommentWithDev = !!args.commentWithDev;
152159
const comment: Comment = args.comment as Comment;
153160
const selectedPackageManager = [
154161
...new Set(
@@ -551,6 +558,7 @@ const main = defineCommand({
551558
"sb-package-manager": selectedPackageManager.join(","),
552559
"sb-only-templates": `${isOnlyTemplates}`,
553560
"sb-comment-with-sha": `${isCommentWithSha}`,
561+
"sb-comment-with-dev": `${isCommentWithDev}`,
554562
},
555563
body: formData,
556564
});

0 commit comments

Comments
 (0)