pkg-pr-new 0.0.29 → 0.0.31

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/dist/index.js +38 -28
  2. package/index.ts +52 -47
  3. package/package.json +2 -3
package/index.ts CHANGED
@@ -6,7 +6,6 @@ import { createHash } from "node:crypto";
6
6
  import { hash } from "ohash";
7
7
  import fsSync from "fs";
8
8
  import fs from "fs/promises";
9
- import { detect } from "package-manager-detector";
10
9
  import { getPackageManifest, type PackageManifest } from "query-registry";
11
10
  import type { Comment } from "@pkg-pr-new/utils";
12
11
  import {
@@ -88,38 +87,29 @@ const main = defineCommand({
88
87
  type: "mixed",
89
88
  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.`,
90
89
  },
90
+ packageManager: {
91
+ type: "string",
92
+ description: "Specify the package manager to use (npm, bun, pnpm, yarn)",
93
+ enum: ["npm", "bun", "pnpm", "yarn"],
94
+ default: "npm",
95
+ },
91
96
  },
92
97
  run: async ({ args }) => {
93
- const paths = args._.length
94
- ? await glob(args._, {
95
- expandDirectories: false,
96
- onlyDirectories: true,
97
- absolute: true,
98
- })
99
- : [process.cwd()];
100
-
101
- if (args._.includes(".") || args._.includes("./")) {
102
- paths.push(process.cwd());
103
- }
104
-
105
- const templatePatterns =
106
- typeof args.template === "string"
107
- ? [args.template]
108
- : ([...(args.template || [])] as string[]);
109
-
110
- const templates = await glob(templatePatterns, {
98
+ const paths =
99
+ args._.length > 0
100
+ ? await glob(args._, {
101
+ expandDirectories: false,
102
+ onlyDirectories: true,
103
+ absolute: true,
104
+ })
105
+ : [process.cwd()];
106
+
107
+ const templates = await glob(args.template ?? [], {
111
108
  expandDirectories: false,
112
109
  onlyDirectories: true,
113
110
  absolute: true,
114
111
  });
115
112
 
116
- if (
117
- templatePatterns.includes(".") ||
118
- templatePatterns.includes("./")
119
- ) {
120
- templates.push(process.cwd());
121
- }
122
-
123
113
  const formData = new FormData();
124
114
 
125
115
  const isCompact = !!args.compact;
@@ -128,10 +118,18 @@ const main = defineCommand({
128
118
  const isOnlyTemplates = !!args["only-templates"];
129
119
 
130
120
  const comment: Comment = args.comment as Comment;
121
+ const selectedPackageManager = args.packageManager as "npm" | "bun" | "pnpm" | "yarn";
122
+
123
+ if (!["npm", "bun", "pnpm", "yarn"].includes(selectedPackageManager)) {
124
+ console.error(
125
+ `Unsupported package manager: ${selectedPackageManager}. Supported managers are npm, bun, pnpm, yarn.`
126
+ );
127
+ process.exit(1);
128
+ }
131
129
 
132
130
  if (!process.env.TEST && process.env.GITHUB_ACTIONS !== "true") {
133
131
  console.error(
134
- "Continuous Releases are only available in Github Actions.",
132
+ "Continuous Releases are only available in GitHub Actions.",
135
133
  );
136
134
  process.exit(1);
137
135
  }
@@ -170,7 +168,6 @@ const main = defineCommand({
170
168
  }
171
169
 
172
170
  const { sha } = await checkResponse.json();
173
- const abbreviatedSha = abbreviateCommitHash(sha);
174
171
 
175
172
  const deps: Map<string, string> = new Map(); // pkg.pr.new versions of the package
176
173
  const realDeps: Map<string, string> | null = isPeerDepsEnabled
@@ -204,7 +201,7 @@ const main = defineCommand({
204
201
  }
205
202
 
206
203
  const depUrl = new URL(
207
- `/${owner}/${repo}/${pJson.name}@${abbreviatedSha}`,
204
+ `/${owner}/${repo}/${pJson.name}@${sha}`,
208
205
  apiUrl,
209
206
  ).href;
210
207
  deps.set(pJson.name, depUrl);
@@ -213,7 +210,7 @@ const main = defineCommand({
213
210
  const resource = await fetch(depUrl);
214
211
  if (resource.ok) {
215
212
  console.warn(
216
- `${pJson.name}@${abbreviatedSha} was already published on ${depUrl}`,
213
+ `${pJson.name}@${abbreviateCommitHash(sha)} was already published on ${depUrl}`,
217
214
  );
218
215
  }
219
216
 
@@ -345,14 +342,13 @@ const main = defineCommand({
345
342
  );
346
343
 
347
344
  shasums[pJson.name] = shasum;
348
- console.warn(`shasum for ${pJson.name}(${filename}): ${shasum}`);
349
345
 
350
346
  const outputPkg = outputMetadata.packages.find(
351
347
  (p) => p.name === pJson.name,
352
348
  )!;
353
349
  outputPkg.shasum = shasum;
354
350
 
355
- const filePath = path.resolve(p, filename)
351
+ const filePath = path.resolve(p, filename);
356
352
  const buffer = await fs.readFile(filePath);
357
353
 
358
354
  const blob = new Blob([buffer], {
@@ -360,7 +356,7 @@ const main = defineCommand({
360
356
  });
361
357
  formData.append(`package:${pJson.name}`, blob, filename);
362
358
 
363
- await fs.rm(filePath)
359
+ await fs.rm(filePath);
364
360
  } finally {
365
361
  await restoreMap.get(p)?.();
366
362
  }
@@ -392,8 +388,11 @@ const main = defineCommand({
392
388
  console.error(await createMultipartRes.text());
393
389
  continue;
394
390
  }
395
- const { key: uploadKey, id: uploadId, ...data } =
396
- await createMultipartRes.json();
391
+ const {
392
+ key: uploadKey,
393
+ id: uploadId,
394
+ ...data
395
+ } = await createMultipartRes.json();
397
396
 
398
397
  interface R2UploadedPart {
399
398
  partNumber: number;
@@ -447,7 +446,6 @@ const main = defineCommand({
447
446
  }
448
447
  }
449
448
 
450
- const packageManager = await detect();
451
449
  const res = await fetch(publishUrl, {
452
450
  method: "POST",
453
451
  headers: {
@@ -456,7 +454,7 @@ const main = defineCommand({
456
454
  "sb-key": key,
457
455
  "sb-shasums": JSON.stringify(shasums),
458
456
  "sb-run-id": GITHUB_RUN_ID,
459
- "sb-package-manager": packageManager.agent ?? "npm",
457
+ "sb-package-manager": selectedPackageManager,
460
458
  "sb-only-templates": `${isOnlyTemplates}`,
461
459
  },
462
460
  body: formData,
@@ -469,15 +467,22 @@ const main = defineCommand({
469
467
  );
470
468
 
471
469
  console.warn("\n");
472
- console.warn(
473
- `⚡️ Your npm packages are published.\n${[...formData.keys()]
474
- .filter((k) => k.startsWith("package:"))
475
- .map(
476
- (name, i) =>
477
- `${name.slice("package:".length)}: npm i ${laterRes.urls[i]}`,
478
- )
479
- .join("\n")}`,
480
- );
470
+ console.warn("⚡️ Your npm packages are published.\n");
471
+
472
+ const packageLogs = [...formData.keys()]
473
+ .filter((k) => k.startsWith("package:"))
474
+ .map((name, i) => {
475
+ const packageName = name.slice("package:".length);
476
+ const url = new URL(laterRes.urls[i])
477
+ const publintUrl = new URL(`/pkg.pr.new${url.pathname}`, "https://publint.dev")
478
+ return `${packageName}:
479
+ - sha: ${shasums[packageName]}
480
+ - publint: ${publintUrl}
481
+ - npm: npm i ${url}`;
482
+ })
483
+ .join("\n\n");
484
+
485
+ console.warn(packageLogs);
481
486
 
482
487
  const output = JSON.stringify(outputMetadata, null, 2);
483
488
  if (printJson) {
@@ -557,7 +562,7 @@ function hijackDeps(
557
562
  }
558
563
 
559
564
  function getFormEntrySize(entry: FormDataEntryValue) {
560
- if (typeof entry === 'string') {
565
+ if (typeof entry === "string") {
561
566
  return entry.length;
562
567
  }
563
568
  return entry.size;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pkg-pr-new",
3
- "version": "0.0.29",
3
+ "version": "0.0.31",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -25,10 +25,9 @@
25
25
  "@octokit/action": "^6.1.0",
26
26
  "ignore": "^5.3.1",
27
27
  "isbinaryfile": "^5.0.2",
28
- "package-manager-detector": "^0.1.2",
29
28
  "pkg-types": "^1.1.1",
30
29
  "query-registry": "^3.0.1",
31
- "tinyglobby": "0.2.6"
30
+ "tinyglobby": "^0.2.9"
32
31
  },
33
32
  "devDependencies": {
34
33
  "@pkg-pr-new/utils": "workspace:^",