pkg-pr-new 0.0.22 → 0.0.24

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 +30 -12
  2. package/index.ts +60 -33
  3. package/package.json +1 -1
package/index.ts CHANGED
@@ -14,7 +14,7 @@ import {
14
14
  extractOwnerAndRepo,
15
15
  extractRepository,
16
16
  } from "@pkg-pr-new/utils";
17
- import { glob, globSync } from "tinyglobby";
17
+ import { glob } from "tinyglobby";
18
18
  import ignore from "ignore";
19
19
  import "./environments";
20
20
  import pkg from "./package.json" with { type: "json" };
@@ -87,24 +87,42 @@ const main = defineCommand({
87
87
  },
88
88
  },
89
89
  run: async ({ args }) => {
90
- const paths = (args._.length ? args._ : ["."])
91
- .flatMap((p) => globSync([p], { expandDirectories: false, onlyDirectories: true }))
92
- .map((p) => path.resolve(p.trim()));
90
+ const paths = args._.length
91
+ ? await glob(args._, {
92
+ expandDirectories: false,
93
+ onlyDirectories: true,
94
+ absolute: true,
95
+ })
96
+ : [process.cwd()];
97
+
98
+ if (args._.includes(".") || args._.includes("./")) {
99
+ paths.push(process.cwd());
100
+ }
93
101
 
94
- const templates = (
102
+ const templatePatterns =
95
103
  typeof args.template === "string"
96
104
  ? [args.template]
97
- : ([...(args.template || [])] as string[])
98
- )
99
- .flatMap((p) => globSync([p], { expandDirectories: false, onlyDirectories: true }))
100
- .map((p) => path.resolve(p.trim()));
105
+ : ([...(args.template || [])] as string[]);
106
+
107
+ const templates = await glob(templatePatterns, {
108
+ expandDirectories: false,
109
+ onlyDirectories: true,
110
+ absolute: true,
111
+ });
112
+
113
+ if (
114
+ templatePatterns.includes(".") ||
115
+ templatePatterns.includes("./")
116
+ ) {
117
+ templates.push(process.cwd());
118
+ }
101
119
 
102
120
  const formData = new FormData();
103
121
 
104
122
  const isCompact = !!args.compact;
105
123
  const isPnpm = !!args.pnpm;
106
- const isPeerDepsEnabled = !!args.peerDeps
107
- const isOnlyTemplates = !!args['only-templates']
124
+ const isPeerDepsEnabled = !!args.peerDeps;
125
+ const isOnlyTemplates = !!args["only-templates"];
108
126
 
109
127
  const comment: Comment = args.comment as Comment;
110
128
 
@@ -152,11 +170,13 @@ const main = defineCommand({
152
170
  const abbreviatedSha = abbreviateCommitHash(sha);
153
171
 
154
172
  const deps: Map<string, string> = new Map(); // pkg.pr.new versions of the package
155
- const realDeps: Map<string, string> | null = isPeerDepsEnabled ? new Map() : null // real versions of the package, useful for peerDependencies
173
+ const realDeps: Map<string, string> | null = isPeerDepsEnabled
174
+ ? new Map()
175
+ : null; // real versions of the package, useful for peerDependencies
156
176
 
157
- const printJson = typeof args.json === 'boolean';
158
- const saveJson = typeof args.json === 'string';
159
- const jsonFilePath = saveJson ? args.json : '';
177
+ const printJson = typeof args.json === "boolean";
178
+ const saveJson = typeof args.json === "string";
179
+ const jsonFilePath = saveJson ? args.json : "";
160
180
  const outputMetadata: OutputMetadata = {
161
181
  packages: [],
162
182
  templates: [],
@@ -183,16 +203,15 @@ const main = defineCommand({
183
203
  const depUrl = new URL(
184
204
  `/${owner}/${repo}/${pJson.name}@${abbreviatedSha}`,
185
205
  apiUrl,
186
- ).href
187
- deps.set(
188
- pJson.name,
189
- depUrl,
190
- );
191
- realDeps?.set(pJson.name, pJson.version ?? depUrl)
206
+ ).href;
207
+ deps.set(pJson.name, depUrl);
208
+ realDeps?.set(pJson.name, pJson.version ?? depUrl);
192
209
 
193
- const resource = await fetch(depUrl)
210
+ const resource = await fetch(depUrl);
194
211
  if (resource.ok) {
195
- console.warn(`${pJson.name}@${abbreviatedSha} was already published on ${depUrl}`)
212
+ console.warn(
213
+ `${pJson.name}@${abbreviatedSha} was already published on ${depUrl}`,
214
+ );
196
215
  }
197
216
 
198
217
  // Collect package metadata
@@ -222,9 +241,7 @@ const main = defineCommand({
222
241
  const restore = await writeDeps(templateDir, deps, realDeps);
223
242
 
224
243
  const gitignorePath = path.join(templateDir, ".gitignore");
225
- const ig = ignore()
226
- .add("node_modules")
227
- .add(".git");
244
+ const ig = ignore().add("node_modules").add(".git");
228
245
 
229
246
  if (fsSync.existsSync(gitignorePath)) {
230
247
  const gitignoreContent = await fs.readFile(gitignorePath, "utf8");
@@ -235,7 +252,7 @@ const main = defineCommand({
235
252
  cwd: templateDir,
236
253
  dot: true,
237
254
  onlyFiles: true,
238
- ignore: ['**/node_modules', '.git'], // always ignore node_modules and .git
255
+ ignore: ["**/node_modules", ".git"], // always ignore node_modules and .git
239
256
  });
240
257
 
241
258
  const filteredFiles = files.filter((file) => !ig.ignores(file));
@@ -300,7 +317,9 @@ const main = defineCommand({
300
317
  const shasums: Record<string, string> = {};
301
318
  for (const p of paths) {
302
319
  if (!(await hasPackageJson(p))) {
303
- console.warn(`skipping ${p} because there's no package.json file`);
320
+ console.warn(
321
+ `skipping ${p} because there's no package.json file`,
322
+ );
304
323
  continue;
305
324
  }
306
325
  const pJsonPath = path.resolve(p, "package.json");
@@ -325,7 +344,9 @@ const main = defineCommand({
325
344
  shasums[pJson.name] = shasum;
326
345
  console.warn(`shasum for ${pJson.name}(${filename}): ${shasum}`);
327
346
 
328
- const outputPkg = outputMetadata.packages.find(p => p.name === pJson.name)!;
347
+ const outputPkg = outputMetadata.packages.find(
348
+ (p) => p.name === pJson.name,
349
+ )!;
329
350
  outputPkg.shasum = shasum;
330
351
 
331
352
  const file = await fs.readFile(path.resolve(p, filename));
@@ -349,7 +370,7 @@ const main = defineCommand({
349
370
  "sb-shasums": JSON.stringify(shasums),
350
371
  "sb-run-id": GITHUB_RUN_ID,
351
372
  "sb-package-manager": packageManager.agent ?? "npm",
352
- "sb-only-templates": `${isOnlyTemplates}`
373
+ "sb-only-templates": `${isOnlyTemplates}`,
353
374
  },
354
375
  body: formData,
355
376
  });
@@ -385,13 +406,15 @@ const main = defineCommand({
385
406
  link: () => {
386
407
  return {
387
408
  meta: {},
388
- run: () => { },
409
+ run: () => {},
389
410
  };
390
411
  },
391
412
  },
392
413
  });
393
414
 
394
- runMain(main).then(() => process.exit(0)).catch(() => process.exit(1));
415
+ runMain(main)
416
+ .then(() => process.exit(0))
417
+ .catch(() => process.exit(1));
395
418
 
396
419
  // TODO: we'll add support for yarn if users hit issues with npm
397
420
  async function resolveTarball(pm: "npm" | "pnpm", p: string) {
@@ -409,7 +432,11 @@ async function resolveTarball(pm: "npm" | "pnpm", p: string) {
409
432
  return { filename, shasum };
410
433
  }
411
434
 
412
- async function writeDeps(p: string, deps: Map<string, string>, realDeps: Map<string, string> | null) {
435
+ async function writeDeps(
436
+ p: string,
437
+ deps: Map<string, string>,
438
+ realDeps: Map<string, string> | null,
439
+ ) {
413
440
  const pJsonPath = path.resolve(p, "package.json");
414
441
  const content = await fs.readFile(pJsonPath, "utf-8");
415
442
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pkg-pr-new",
3
- "version": "0.0.22",
3
+ "version": "0.0.24",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "type": "module",