pkg-pr-new 0.0.30 → 0.0.32

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 +34 -18
  2. package/index.ts +49 -29
  3. package/package.json +1 -2
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,15 +87,22 @@ 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 > 0
94
- ? await glob(args._, {
95
- expandDirectories: false,
96
- onlyDirectories: true,
97
- absolute: true,
98
- })
99
- : [process.cwd()];
98
+ const paths =
99
+ args._.length > 0
100
+ ? await glob(args._, {
101
+ expandDirectories: false,
102
+ onlyDirectories: true,
103
+ absolute: true,
104
+ })
105
+ : [process.cwd()];
100
106
 
101
107
  const templates = await glob(args.template ?? [], {
102
108
  expandDirectories: false,
@@ -112,6 +118,14 @@ const main = defineCommand({
112
118
  const isOnlyTemplates = !!args["only-templates"];
113
119
 
114
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
+ }
115
129
 
116
130
  if (!process.env.TEST && process.env.GITHUB_ACTIONS !== "true") {
117
131
  console.error(
@@ -154,7 +168,6 @@ const main = defineCommand({
154
168
  }
155
169
 
156
170
  const { sha } = await checkResponse.json();
157
- const abbreviatedSha = abbreviateCommitHash(sha);
158
171
 
159
172
  const deps: Map<string, string> = new Map(); // pkg.pr.new versions of the package
160
173
  const realDeps: Map<string, string> | null = isPeerDepsEnabled
@@ -188,7 +201,7 @@ const main = defineCommand({
188
201
  }
189
202
 
190
203
  const depUrl = new URL(
191
- `/${owner}/${repo}/${pJson.name}@${abbreviatedSha}`,
204
+ `/${owner}/${repo}/${pJson.name}@${sha}`,
192
205
  apiUrl,
193
206
  ).href;
194
207
  deps.set(pJson.name, depUrl);
@@ -197,7 +210,7 @@ const main = defineCommand({
197
210
  const resource = await fetch(depUrl);
198
211
  if (resource.ok) {
199
212
  console.warn(
200
- `${pJson.name}@${abbreviatedSha} was already published on ${depUrl}`,
213
+ `${pJson.name}@${abbreviateCommitHash(sha)} was already published on ${depUrl}`,
201
214
  );
202
215
  }
203
216
 
@@ -329,14 +342,13 @@ const main = defineCommand({
329
342
  );
330
343
 
331
344
  shasums[pJson.name] = shasum;
332
- console.warn(`shasum for ${pJson.name}(${filename}): ${shasum}`);
333
345
 
334
346
  const outputPkg = outputMetadata.packages.find(
335
347
  (p) => p.name === pJson.name,
336
348
  )!;
337
349
  outputPkg.shasum = shasum;
338
350
 
339
- const filePath = path.resolve(p, filename)
351
+ const filePath = path.resolve(p, filename);
340
352
  const buffer = await fs.readFile(filePath);
341
353
 
342
354
  const blob = new Blob([buffer], {
@@ -344,7 +356,7 @@ const main = defineCommand({
344
356
  });
345
357
  formData.append(`package:${pJson.name}`, blob, filename);
346
358
 
347
- await fs.rm(filePath)
359
+ await fs.rm(filePath);
348
360
  } finally {
349
361
  await restoreMap.get(p)?.();
350
362
  }
@@ -376,8 +388,11 @@ const main = defineCommand({
376
388
  console.error(await createMultipartRes.text());
377
389
  continue;
378
390
  }
379
- const { key: uploadKey, id: uploadId, ...data } =
380
- await createMultipartRes.json();
391
+ const {
392
+ key: uploadKey,
393
+ id: uploadId,
394
+ ...data
395
+ } = await createMultipartRes.json();
381
396
 
382
397
  interface R2UploadedPart {
383
398
  partNumber: number;
@@ -431,8 +446,6 @@ const main = defineCommand({
431
446
  }
432
447
  }
433
448
 
434
- const packageManager = await detect();
435
- const agent = packageManager.agent.includes('@') ? packageManager.agent.split('@')[0] : packageManager.agent;
436
449
  const res = await fetch(publishUrl, {
437
450
  method: "POST",
438
451
  headers: {
@@ -441,7 +454,7 @@ const main = defineCommand({
441
454
  "sb-key": key,
442
455
  "sb-shasums": JSON.stringify(shasums),
443
456
  "sb-run-id": GITHUB_RUN_ID,
444
- "sb-package-manager": agent ?? "npm",
457
+ "sb-package-manager": selectedPackageManager,
445
458
  "sb-only-templates": `${isOnlyTemplates}`,
446
459
  },
447
460
  body: formData,
@@ -454,15 +467,22 @@ const main = defineCommand({
454
467
  );
455
468
 
456
469
  console.warn("\n");
457
- console.warn(
458
- `⚡️ Your npm packages are published.\n${[...formData.keys()]
459
- .filter((k) => k.startsWith("package:"))
460
- .map(
461
- (name, i) =>
462
- `${name.slice("package:".length)}: npm i ${laterRes.urls[i]}`,
463
- )
464
- .join("\n")}`,
465
- );
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);
466
486
 
467
487
  const output = JSON.stringify(outputMetadata, null, 2);
468
488
  if (printJson) {
@@ -542,7 +562,7 @@ function hijackDeps(
542
562
  }
543
563
 
544
564
  function getFormEntrySize(entry: FormDataEntryValue) {
545
- if (typeof entry === 'string') {
565
+ if (typeof entry === "string") {
546
566
  return entry.length;
547
567
  }
548
568
  return entry.size;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pkg-pr-new",
3
- "version": "0.0.30",
3
+ "version": "0.0.32",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -25,7 +25,6 @@
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
30
  "tinyglobby": "^0.2.9"