pkg-pr-new 0.0.21 → 0.0.23
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.
- package/dist/index.js +24 -11
- package/index.ts +49 -28
- package/package.json +1 -1
package/index.ts
CHANGED
|
@@ -87,24 +87,36 @@ const main = defineCommand({
|
|
|
87
87
|
},
|
|
88
88
|
},
|
|
89
89
|
run: async ({ args }) => {
|
|
90
|
-
const paths = (
|
|
91
|
-
.
|
|
92
|
-
|
|
90
|
+
const paths = (
|
|
91
|
+
args._.length
|
|
92
|
+
? args._.flatMap((p) =>
|
|
93
|
+
globSync([p], {
|
|
94
|
+
expandDirectories: false,
|
|
95
|
+
onlyDirectories: true,
|
|
96
|
+
}),
|
|
97
|
+
)
|
|
98
|
+
: ["."]
|
|
99
|
+
).map((p) => path.resolve(p.trim()));
|
|
93
100
|
|
|
94
101
|
const templates = (
|
|
95
102
|
typeof args.template === "string"
|
|
96
103
|
? [args.template]
|
|
97
104
|
: ([...(args.template || [])] as string[])
|
|
98
105
|
)
|
|
99
|
-
.flatMap((p) =>
|
|
106
|
+
.flatMap((p) =>
|
|
107
|
+
globSync([p], {
|
|
108
|
+
expandDirectories: false,
|
|
109
|
+
onlyDirectories: true,
|
|
110
|
+
}),
|
|
111
|
+
)
|
|
100
112
|
.map((p) => path.resolve(p.trim()));
|
|
101
113
|
|
|
102
114
|
const formData = new FormData();
|
|
103
115
|
|
|
104
116
|
const isCompact = !!args.compact;
|
|
105
117
|
const isPnpm = !!args.pnpm;
|
|
106
|
-
const isPeerDepsEnabled = !!args.peerDeps
|
|
107
|
-
const isOnlyTemplates = !!args[
|
|
118
|
+
const isPeerDepsEnabled = !!args.peerDeps;
|
|
119
|
+
const isOnlyTemplates = !!args["only-templates"];
|
|
108
120
|
|
|
109
121
|
const comment: Comment = args.comment as Comment;
|
|
110
122
|
|
|
@@ -152,11 +164,13 @@ const main = defineCommand({
|
|
|
152
164
|
const abbreviatedSha = abbreviateCommitHash(sha);
|
|
153
165
|
|
|
154
166
|
const deps: Map<string, string> = new Map(); // pkg.pr.new versions of the package
|
|
155
|
-
const realDeps: Map<string, string> | null = isPeerDepsEnabled
|
|
167
|
+
const realDeps: Map<string, string> | null = isPeerDepsEnabled
|
|
168
|
+
? new Map()
|
|
169
|
+
: null; // real versions of the package, useful for peerDependencies
|
|
156
170
|
|
|
157
|
-
const printJson = typeof args.json ===
|
|
158
|
-
const saveJson = typeof args.json ===
|
|
159
|
-
const jsonFilePath = saveJson ? args.json :
|
|
171
|
+
const printJson = typeof args.json === "boolean";
|
|
172
|
+
const saveJson = typeof args.json === "string";
|
|
173
|
+
const jsonFilePath = saveJson ? args.json : "";
|
|
160
174
|
const outputMetadata: OutputMetadata = {
|
|
161
175
|
packages: [],
|
|
162
176
|
templates: [],
|
|
@@ -183,16 +197,15 @@ const main = defineCommand({
|
|
|
183
197
|
const depUrl = new URL(
|
|
184
198
|
`/${owner}/${repo}/${pJson.name}@${abbreviatedSha}`,
|
|
185
199
|
apiUrl,
|
|
186
|
-
).href
|
|
187
|
-
deps.set(
|
|
188
|
-
|
|
189
|
-
depUrl,
|
|
190
|
-
);
|
|
191
|
-
realDeps?.set(pJson.name, pJson.version ?? depUrl)
|
|
200
|
+
).href;
|
|
201
|
+
deps.set(pJson.name, depUrl);
|
|
202
|
+
realDeps?.set(pJson.name, pJson.version ?? depUrl);
|
|
192
203
|
|
|
193
|
-
const resource = await fetch(depUrl)
|
|
204
|
+
const resource = await fetch(depUrl);
|
|
194
205
|
if (resource.ok) {
|
|
195
|
-
console.warn(
|
|
206
|
+
console.warn(
|
|
207
|
+
`${pJson.name}@${abbreviatedSha} was already published on ${depUrl}`,
|
|
208
|
+
);
|
|
196
209
|
}
|
|
197
210
|
|
|
198
211
|
// Collect package metadata
|
|
@@ -222,9 +235,7 @@ const main = defineCommand({
|
|
|
222
235
|
const restore = await writeDeps(templateDir, deps, realDeps);
|
|
223
236
|
|
|
224
237
|
const gitignorePath = path.join(templateDir, ".gitignore");
|
|
225
|
-
const ig = ignore()
|
|
226
|
-
.add("node_modules")
|
|
227
|
-
.add(".git");
|
|
238
|
+
const ig = ignore().add("node_modules").add(".git");
|
|
228
239
|
|
|
229
240
|
if (fsSync.existsSync(gitignorePath)) {
|
|
230
241
|
const gitignoreContent = await fs.readFile(gitignorePath, "utf8");
|
|
@@ -235,7 +246,7 @@ const main = defineCommand({
|
|
|
235
246
|
cwd: templateDir,
|
|
236
247
|
dot: true,
|
|
237
248
|
onlyFiles: true,
|
|
238
|
-
ignore: [
|
|
249
|
+
ignore: ["**/node_modules", ".git"], // always ignore node_modules and .git
|
|
239
250
|
});
|
|
240
251
|
|
|
241
252
|
const filteredFiles = files.filter((file) => !ig.ignores(file));
|
|
@@ -300,7 +311,9 @@ const main = defineCommand({
|
|
|
300
311
|
const shasums: Record<string, string> = {};
|
|
301
312
|
for (const p of paths) {
|
|
302
313
|
if (!(await hasPackageJson(p))) {
|
|
303
|
-
console.warn(
|
|
314
|
+
console.warn(
|
|
315
|
+
`skipping ${p} because there's no package.json file`,
|
|
316
|
+
);
|
|
304
317
|
continue;
|
|
305
318
|
}
|
|
306
319
|
const pJsonPath = path.resolve(p, "package.json");
|
|
@@ -325,7 +338,9 @@ const main = defineCommand({
|
|
|
325
338
|
shasums[pJson.name] = shasum;
|
|
326
339
|
console.warn(`shasum for ${pJson.name}(${filename}): ${shasum}`);
|
|
327
340
|
|
|
328
|
-
const outputPkg = outputMetadata.packages.find(
|
|
341
|
+
const outputPkg = outputMetadata.packages.find(
|
|
342
|
+
(p) => p.name === pJson.name,
|
|
343
|
+
)!;
|
|
329
344
|
outputPkg.shasum = shasum;
|
|
330
345
|
|
|
331
346
|
const file = await fs.readFile(path.resolve(p, filename));
|
|
@@ -349,7 +364,7 @@ const main = defineCommand({
|
|
|
349
364
|
"sb-shasums": JSON.stringify(shasums),
|
|
350
365
|
"sb-run-id": GITHUB_RUN_ID,
|
|
351
366
|
"sb-package-manager": packageManager.agent ?? "npm",
|
|
352
|
-
"sb-only-templates": `${isOnlyTemplates}
|
|
367
|
+
"sb-only-templates": `${isOnlyTemplates}`,
|
|
353
368
|
},
|
|
354
369
|
body: formData,
|
|
355
370
|
});
|
|
@@ -385,13 +400,15 @@ const main = defineCommand({
|
|
|
385
400
|
link: () => {
|
|
386
401
|
return {
|
|
387
402
|
meta: {},
|
|
388
|
-
run: () => {
|
|
403
|
+
run: () => {},
|
|
389
404
|
};
|
|
390
405
|
},
|
|
391
406
|
},
|
|
392
407
|
});
|
|
393
408
|
|
|
394
|
-
runMain(main)
|
|
409
|
+
runMain(main)
|
|
410
|
+
.then(() => process.exit(0))
|
|
411
|
+
.catch(() => process.exit(1));
|
|
395
412
|
|
|
396
413
|
// TODO: we'll add support for yarn if users hit issues with npm
|
|
397
414
|
async function resolveTarball(pm: "npm" | "pnpm", p: string) {
|
|
@@ -409,7 +426,11 @@ async function resolveTarball(pm: "npm" | "pnpm", p: string) {
|
|
|
409
426
|
return { filename, shasum };
|
|
410
427
|
}
|
|
411
428
|
|
|
412
|
-
async function writeDeps(
|
|
429
|
+
async function writeDeps(
|
|
430
|
+
p: string,
|
|
431
|
+
deps: Map<string, string>,
|
|
432
|
+
realDeps: Map<string, string> | null,
|
|
433
|
+
) {
|
|
413
434
|
const pJsonPath = path.resolve(p, "package.json");
|
|
414
435
|
const content = await fs.readFile(pJsonPath, "utf-8");
|
|
415
436
|
|