pkg-pr-new 0.0.16 → 0.0.18

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 +31 -10
  2. package/index.ts +28 -9
  3. package/package.json +6 -1
package/index.ts CHANGED
@@ -44,6 +44,12 @@ const main = defineCommand({
44
44
  description:
45
45
  "compact urls. The shortest form of urls like pkg.pr.new/tinybench@a832a55)",
46
46
  },
47
+ peerDeps: {
48
+ type: "boolean",
49
+ description:
50
+ "handle peerDependencies by setting the workspace version instead of what has been set in the peerDeps itself. --peerDeps not being true would leave peerDependencies to the package manager itself (npm, pnpm)",
51
+ default: false,
52
+ },
47
53
  pnpm: {
48
54
  type: "boolean",
49
55
  description: "use `pnpm pack` instead of `npm pack --json`",
@@ -76,6 +82,7 @@ const main = defineCommand({
76
82
 
77
83
  const isCompact = !!args.compact;
78
84
  const isPnpm = !!args.pnpm;
85
+ const isPeerDepsEnabled = !!args.peerDeps
79
86
 
80
87
  const comment: Comment = args.comment as Comment;
81
88
 
@@ -122,7 +129,8 @@ const main = defineCommand({
122
129
  const { sha } = await checkResponse.json();
123
130
  const abbreviatedSha = abbreviateCommitHash(sha);
124
131
 
125
- const deps: Map<string, string> = new Map();
132
+ const deps: Map<string, string> = new Map(); // pkg.pr.new versions of the package
133
+ const realDeps: Map<string, string> | null = isPeerDepsEnabled ? new Map() : null // real versions of the package, useful for peerDependencies
126
134
 
127
135
  for (const p of paths) {
128
136
  if (!(await hasPackageJson(p))) {
@@ -142,13 +150,20 @@ const main = defineCommand({
142
150
  await verifyCompactMode(pJson.name);
143
151
  }
144
152
 
145
- deps.set(
146
- pJson.name,
147
- new URL(
153
+ const depUrl = new URL(
148
154
  `/${owner}/${repo}/${pJson.name}@${abbreviatedSha}`,
149
155
  apiUrl,
150
- ).href,
156
+ ).href
157
+ deps.set(
158
+ pJson.name,
159
+ depUrl,
151
160
  );
161
+ realDeps?.set(pJson.name, pJson.version ?? depUrl)
162
+
163
+ const resource = await fetch(depUrl)
164
+ if (resource.ok) {
165
+ console.warn(`${pJson.name}@${abbreviatedSha} was already published on ${depUrl}`)
166
+ }
152
167
  }
153
168
 
154
169
  for (const templateDir of templates) {
@@ -167,7 +182,7 @@ const main = defineCommand({
167
182
 
168
183
  console.log("preparing template:", pJson.name);
169
184
 
170
- const restore = await writeDeps(templateDir, deps);
185
+ const restore = await writeDeps(templateDir, deps, realDeps);
171
186
 
172
187
  const gitignorePath = path.join(templateDir, ".gitignore");
173
188
  const ig = ignore()
@@ -204,7 +219,7 @@ const main = defineCommand({
204
219
 
205
220
  const noDefaultTemplate = args.template === false;
206
221
 
207
- if (!templates.length && !noDefaultTemplate) {
222
+ if (!noDefaultTemplate) {
208
223
  const project = createDefaultTemplate(
209
224
  Object.fromEntries(deps.entries()),
210
225
  );
@@ -232,7 +247,7 @@ const main = defineCommand({
232
247
  continue;
233
248
  }
234
249
 
235
- restoreMap.set(p, await writeDeps(p, deps));
250
+ restoreMap.set(p, await writeDeps(p, deps, realDeps));
236
251
  }
237
252
 
238
253
  const shasums: Record<string, string> = {};
@@ -334,7 +349,7 @@ async function resolveTarball(pm: "npm" | "pnpm", p: string) {
334
349
  return { filename, shasum };
335
350
  }
336
351
 
337
- async function writeDeps(p: string, deps: Map<string, string>) {
352
+ async function writeDeps(p: string, deps: Map<string, string>, realDeps: Map<string, string> | null) {
338
353
  const pJsonPath = path.resolve(p, "package.json");
339
354
  const content = await fs.readFile(pJsonPath, "utf-8");
340
355
 
@@ -343,6 +358,10 @@ async function writeDeps(p: string, deps: Map<string, string>) {
343
358
  hijackDeps(deps, pJson.dependencies);
344
359
  hijackDeps(deps, pJson.devDependencies);
345
360
 
361
+ if (realDeps) {
362
+ hijackDeps(realDeps, pJson.peerDependencies);
363
+ }
364
+
346
365
  await writePackageJSON(pJsonPath, pJson);
347
366
 
348
367
  return () => fs.writeFile(pJsonPath, content);
package/package.json CHANGED
@@ -1,12 +1,17 @@
1
1
  {
2
2
  "name": "pkg-pr-new",
3
- "version": "0.0.16",
3
+ "version": "0.0.18",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "type": "module",
7
7
  "bin": {
8
8
  "pkg-pr-new": "bin/cli.js"
9
9
  },
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "https://github.com/stackblitz-labs/pkg.pr.new",
13
+ "directory": "packages/cli"
14
+ },
10
15
  "scripts": {
11
16
  "dev": "tsup --watch",
12
17
  "build": "tsup",