@storm-software/workspace-tools 1.294.40 → 1.294.42

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.
@@ -1,548 +0,0 @@
1
- import {
2
- addPackageJsonGitHead
3
- } from "./chunk-NJLZBEYW.mjs";
4
- import {
5
- getConfig
6
- } from "./chunk-M7NAHAMC.mjs";
7
- import {
8
- findWorkspaceRoot
9
- } from "./chunk-3J2CP54B.mjs";
10
- import {
11
- joinPaths
12
- } from "./chunk-TBW5MCN6.mjs";
13
-
14
- // ../npm-tools/src/helpers/get-registry.ts
15
- import { exec } from "node:child_process";
16
-
17
- // ../npm-tools/src/constants.ts
18
- var DEFAULT_NPM_REGISTRY = "https://registry.npmjs.org";
19
-
20
- // ../npm-tools/src/helpers/get-registry.ts
21
- async function getRegistry(executable = "npm") {
22
- return new Promise((resolve, reject) => {
23
- exec(`${executable} config get registry`, (error, stdout, stderr) => {
24
- if (error && !error.message.toLowerCase().trim().startsWith("npm warn")) {
25
- return reject(error);
26
- }
27
- if (stderr && !stderr.toLowerCase().trim().startsWith("npm warn")) {
28
- return reject(stderr);
29
- }
30
- return resolve(stdout.trim());
31
- });
32
- });
33
- }
34
- async function getNpmRegistry() {
35
- if (process.env.STORM_REGISTRY_NPM) {
36
- return process.env.STORM_REGISTRY_NPM;
37
- }
38
- const workspaceConfig = await getConfig();
39
- if (workspaceConfig?.registry?.npm) {
40
- return workspaceConfig?.registry?.npm;
41
- }
42
- return DEFAULT_NPM_REGISTRY;
43
- }
44
-
45
- // ../pnpm-tools/src/helpers/replace-deps-aliases.ts
46
- import {
47
- createProjectGraphAsync,
48
- readCachedProjectGraph
49
- } from "@nx/devkit";
50
- import { existsSync as existsSync2 } from "node:fs";
51
- import { readFile as readFile2, writeFile as writeFile2 } from "node:fs/promises";
52
- import { format } from "prettier";
53
-
54
- // ../npm-tools/src/helpers/get-version.ts
55
- import { exec as exec2 } from "node:child_process";
56
-
57
- // ../pnpm-tools/src/helpers/catalog.ts
58
- import { coerce, gt, valid } from "semver";
59
-
60
- // ../pnpm-tools/src/helpers/pnpm-workspace.ts
61
- import { existsSync } from "node:fs";
62
- import { readFile, writeFile } from "node:fs/promises";
63
- import { parse, stringify } from "yaml";
64
- function getPnpmWorkspaceFilePath(workspaceRoot = findWorkspaceRoot(process.cwd())) {
65
- const pnpmWorkspacePath = joinPaths(workspaceRoot, "pnpm-workspace.yaml");
66
- if (!existsSync(pnpmWorkspacePath)) {
67
- throw new Error(
68
- `No \`pnpm-workspace.yaml\` file found in workspace root (searched in: ${pnpmWorkspacePath}).`
69
- );
70
- }
71
- return pnpmWorkspacePath;
72
- }
73
- async function readPnpmWorkspaceFile(workspaceRoot = findWorkspaceRoot(process.cwd())) {
74
- const result = await readFile(
75
- getPnpmWorkspaceFilePath(workspaceRoot),
76
- "utf8"
77
- );
78
- if (!result) {
79
- return void 0;
80
- }
81
- return parse(result);
82
- }
83
-
84
- // ../pnpm-tools/src/helpers/catalog.ts
85
- async function getCatalogSafe(workspaceRoot = findWorkspaceRoot(process.cwd())) {
86
- const pnpmWorkspaceFile = await readPnpmWorkspaceFile(workspaceRoot);
87
- if (!pnpmWorkspaceFile) {
88
- throw new Error("No pnpm-workspace.yaml file found");
89
- }
90
- if (pnpmWorkspaceFile?.catalog) {
91
- return Object.fromEntries(
92
- Object.entries(pnpmWorkspaceFile.catalog).map(([key, value]) => {
93
- return [key, value.replaceAll('"', "").replaceAll("'", "")];
94
- })
95
- );
96
- } else {
97
- console.warn(
98
- `No catalog found in pnpm-workspace.yaml file located in workspace root: ${workspaceRoot}
99
- File content: ${JSON.stringify(
100
- pnpmWorkspaceFile,
101
- null,
102
- 2
103
- )}`
104
- );
105
- }
106
- return void 0;
107
- }
108
- async function getCatalog(workspaceRoot = findWorkspaceRoot(process.cwd())) {
109
- const catalog = await getCatalogSafe(workspaceRoot);
110
- if (!catalog) {
111
- throw new Error("No catalog entries found in pnpm-workspace.yaml file");
112
- }
113
- return catalog;
114
- }
115
-
116
- // ../pnpm-tools/src/helpers/replace-deps-aliases.ts
117
- async function replaceDepsAliases(packageRoot = process.cwd(), workspaceRoot = findWorkspaceRoot(packageRoot)) {
118
- const packageJsonPath = joinPaths(packageRoot, "package.json");
119
- const packageJsonFile = await readFile2(packageJsonPath, "utf8");
120
- if (!packageJsonFile) {
121
- throw new Error(
122
- "No package.json file found in package root: " + packageRoot
123
- );
124
- }
125
- const catalog = await getCatalog(workspaceRoot);
126
- const packageJson = JSON.parse(packageJsonFile);
127
- const pnpmWorkspacePath = joinPaths(workspaceRoot, "pnpm-workspace.yaml");
128
- if (!existsSync2(pnpmWorkspacePath)) {
129
- console.warn(
130
- `No \`pnpm-workspace.yaml\` file found in workspace root (searching in: ${pnpmWorkspacePath}). Skipping pnpm catalog read for now.`
131
- );
132
- return packageJson;
133
- }
134
- if (!catalog) {
135
- console.warn(
136
- `No pnpm catalog found. Skipping dependencies replacement for now.`
137
- );
138
- return;
139
- }
140
- for (const dependencyType of [
141
- "dependencies",
142
- "devDependencies",
143
- "peerDependencies"
144
- ]) {
145
- const dependencies = packageJson[dependencyType];
146
- if (!dependencies) {
147
- continue;
148
- }
149
- for (const dependencyName of Object.keys(dependencies)) {
150
- if (dependencies[dependencyName] === "catalog:") {
151
- if (!catalog) {
152
- throw new Error(
153
- `Dependency ${dependencyName} is marked as \`catalog:\`, but no catalog exists in the workspace root's \`pnpm-workspace.yaml\` file.`
154
- );
155
- }
156
- const catalogVersion = catalog[dependencyName];
157
- if (!catalogVersion) {
158
- throw new Error("Missing pnpm catalog version for " + dependencyName);
159
- }
160
- dependencies[dependencyName] = catalogVersion;
161
- } else if (dependencies[dependencyName].startsWith("catalog:")) {
162
- throw new Error("multiple named catalogs not supported");
163
- }
164
- }
165
- }
166
- let projectGraph;
167
- try {
168
- projectGraph = readCachedProjectGraph();
169
- } catch {
170
- await createProjectGraphAsync();
171
- projectGraph = readCachedProjectGraph();
172
- }
173
- const workspacePackages = {};
174
- if (projectGraph) {
175
- await Promise.all(
176
- Object.keys(projectGraph.nodes).map(async (node) => {
177
- const projectNode = projectGraph.nodes[node];
178
- if (projectNode?.data.root) {
179
- const projectPackageJsonPath = joinPaths(
180
- workspaceRoot,
181
- projectNode.data.root,
182
- "package.json"
183
- );
184
- if (existsSync2(projectPackageJsonPath)) {
185
- const projectPackageJsonContent = await readFile2(
186
- projectPackageJsonPath,
187
- "utf8"
188
- );
189
- const projectPackageJson = JSON.parse(projectPackageJsonContent);
190
- if (projectPackageJson.private !== true) {
191
- workspacePackages[projectPackageJson.name] = projectPackageJson.version;
192
- }
193
- }
194
- }
195
- })
196
- );
197
- }
198
- for (const dependencyType of [
199
- "dependencies",
200
- "devDependencies",
201
- "peerDependencies"
202
- ]) {
203
- const dependencies = packageJson[dependencyType];
204
- if (!dependencies) {
205
- continue;
206
- }
207
- for (const dependencyName of Object.keys(dependencies)) {
208
- if (dependencies[dependencyName].startsWith("workspace:")) {
209
- if (workspacePackages[dependencyName]) {
210
- dependencies[dependencyName] = `^${workspacePackages[dependencyName]}`;
211
- } else {
212
- throw new Error(
213
- `Workspace dependency ${dependencyName} not found in workspace packages.`
214
- );
215
- }
216
- }
217
- }
218
- }
219
- return writeFile2(
220
- packageJsonPath,
221
- await format(JSON.stringify(packageJson), {
222
- parser: "json",
223
- proseWrap: "preserve",
224
- trailingComma: "none",
225
- tabWidth: 2,
226
- semi: true,
227
- singleQuote: false,
228
- quoteProps: "as-needed",
229
- insertPragma: false,
230
- bracketSameLine: true,
231
- printWidth: 80,
232
- bracketSpacing: true,
233
- arrowParens: "avoid",
234
- endOfLine: "lf",
235
- plugins: ["prettier-plugin-packagejson"]
236
- })
237
- );
238
- }
239
-
240
- // src/executors/npm-publish/executor.ts
241
- import { execSync } from "node:child_process";
242
- import { readFile as readFile3, writeFile as writeFile3 } from "node:fs/promises";
243
- import { format as format2 } from "prettier";
244
- var LARGE_BUFFER = 1024 * 1e6;
245
- async function npmPublishExecutorFn(options, context) {
246
- const isDryRun = process.env.NX_DRY_RUN === "true" || options.dryRun || false;
247
- if (!context.projectName) {
248
- throw new Error("The `npm-publish` executor requires a `projectName`.");
249
- }
250
- const projectConfig = context.projectsConfigurations?.projects?.[context.projectName];
251
- if (!projectConfig) {
252
- throw new Error(
253
- `Could not find project configuration for \`${context.projectName}\``
254
- );
255
- }
256
- const packageRoot = joinPaths(
257
- context.root,
258
- options.packageRoot || joinPaths("dist", projectConfig.root)
259
- );
260
- const projectRoot = context.projectsConfigurations.projects[context.projectName]?.root ? joinPaths(
261
- context.root,
262
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
263
- context.projectsConfigurations.projects[context.projectName].root
264
- ) : packageRoot;
265
- const packageJsonPath = joinPaths(packageRoot, "package.json");
266
- const packageJsonFile = await readFile3(packageJsonPath, "utf8");
267
- if (!packageJsonFile) {
268
- throw new Error(`Could not find \`package.json\` at ${packageJsonPath}`);
269
- }
270
- const packageJson = JSON.parse(packageJsonFile);
271
- const projectPackageJsonPath = joinPaths(projectRoot, "package.json");
272
- const projectPackageJsonFile = await readFile3(projectPackageJsonPath, "utf8");
273
- if (!projectPackageJsonFile) {
274
- throw new Error(
275
- `Could not find \`package.json\` at ${projectPackageJsonPath}`
276
- );
277
- }
278
- const projectPackageJson = JSON.parse(projectPackageJsonFile);
279
- if (packageJson.version !== projectPackageJson.version) {
280
- console.warn(
281
- `The version in the package.json file at ${packageJsonPath} (current: ${packageJson.version}) does not match the version in the package.json file at ${projectPackageJsonPath} (current: ${projectPackageJson.version}). This file will be updated to match the version in the project package.json file.`
282
- );
283
- if (projectPackageJson.version) {
284
- packageJson.version = projectPackageJson.version;
285
- await writeFile3(
286
- packageJsonPath,
287
- await format2(JSON.stringify(packageJson), {
288
- parser: "json",
289
- proseWrap: "preserve",
290
- trailingComma: "none",
291
- tabWidth: 2,
292
- semi: true,
293
- singleQuote: false,
294
- quoteProps: "as-needed",
295
- insertPragma: false,
296
- bracketSameLine: true,
297
- printWidth: 80,
298
- bracketSpacing: true,
299
- arrowParens: "avoid",
300
- endOfLine: "lf",
301
- plugins: ["prettier-plugin-packagejson"]
302
- })
303
- );
304
- }
305
- }
306
- const packageName = packageJson.name;
307
- console.info(
308
- `\u{1F680} Running Storm NPM Publish executor on the ${packageName} package`
309
- );
310
- const packageTxt = packageName === context.projectName ? `package "${packageName}"` : `package "${packageName}" from project "${context.projectName}"`;
311
- if (packageJson.private === true) {
312
- console.warn(
313
- `Skipped ${packageTxt}, because it has \`"private": true\` in ${packageJsonPath}`
314
- );
315
- return { success: true };
316
- }
317
- await replaceDepsAliases(packageRoot, context.root);
318
- await addPackageJsonGitHead(packageRoot);
319
- const npmPublishCommandSegments = [`npm publish --json`];
320
- const npmViewCommandSegments = [
321
- `npm view ${packageName} versions dist-tags --json`
322
- ];
323
- const registry = options.registry ?? (await getRegistry() || getNpmRegistry());
324
- if (registry) {
325
- npmPublishCommandSegments.push(`--registry="${registry}" `);
326
- npmViewCommandSegments.push(`--registry="${registry}" `);
327
- }
328
- if (options.otp) {
329
- npmPublishCommandSegments.push(`--otp="${options.otp}" `);
330
- }
331
- if (isDryRun) {
332
- npmPublishCommandSegments.push("--dry-run");
333
- }
334
- npmPublishCommandSegments.push("--provenance --access=public ");
335
- const tag = options.tag || execSync("npm config get tag", {
336
- cwd: packageRoot,
337
- env: {
338
- ...process.env,
339
- FORCE_COLOR: "true"
340
- },
341
- maxBuffer: LARGE_BUFFER,
342
- killSignal: "SIGTERM"
343
- }).toString().trim();
344
- if (tag) {
345
- npmPublishCommandSegments.push(`--tag="${tag}" `);
346
- }
347
- if (!isDryRun) {
348
- const currentVersion = options.version || packageJson.version;
349
- try {
350
- try {
351
- const result = execSync(npmViewCommandSegments.join(" "), {
352
- cwd: packageRoot,
353
- env: {
354
- ...process.env,
355
- FORCE_COLOR: "true"
356
- },
357
- maxBuffer: LARGE_BUFFER,
358
- killSignal: "SIGTERM"
359
- });
360
- const resultJson = JSON.parse(result.toString());
361
- const distTags = resultJson["dist-tags"] || {};
362
- if (distTags[tag] === currentVersion) {
363
- console.warn(
364
- `Skipped ${packageTxt} because v${currentVersion} already exists in ${registry} with tag "${tag}"`
365
- );
366
- return { success: true };
367
- }
368
- } catch (err) {
369
- console.warn("\n ********************** \n");
370
- console.warn(
371
- `An error occurred while checking for existing dist-tags
372
- ${JSON.stringify(err)}
373
-
374
- Note: If this is the first time this package has been published to NPM, this can be ignored.
375
-
376
- `
377
- );
378
- console.info("");
379
- }
380
- try {
381
- if (!isDryRun) {
382
- const command = `npm dist-tag add ${packageName}@${currentVersion} ${tag} --registry="${registry}" `;
383
- console.info(
384
- `Adding the dist-tag ${tag} - preparing to run the following:
385
- ${command}
386
- `
387
- );
388
- const result = execSync(command, {
389
- cwd: packageRoot,
390
- env: {
391
- ...process.env,
392
- FORCE_COLOR: "true"
393
- },
394
- maxBuffer: LARGE_BUFFER,
395
- killSignal: "SIGTERM"
396
- });
397
- console.info(
398
- `Added the dist-tag ${tag} to v${currentVersion} for registry "${registry}"
399
-
400
- Execution response: ${result.toString()}
401
- `
402
- );
403
- } else {
404
- console.info(
405
- `Would add the dist-tag ${tag} to v${currentVersion} for registry "${registry}", but [dry-run] was set.
406
- `
407
- );
408
- }
409
- return { success: true };
410
- } catch (err) {
411
- try {
412
- console.warn("\n ********************** \n");
413
- let error = err;
414
- if (Buffer.isBuffer(error)) {
415
- error = error.toString();
416
- }
417
- console.warn(
418
- `An error occurred while adding dist-tags:
419
- ${error}
420
-
421
- Note: If this is the first time this package has been published to NPM, this can be ignored.
422
-
423
- `
424
- );
425
- console.info("");
426
- const stdoutData = JSON.parse(err.stdout?.toString() || "{}");
427
- if (stdoutData?.error && !(stdoutData.error?.code?.includes("E404") && stdoutData.error?.summary?.includes("no such package available")) && !(err.stderr?.toString().includes("E404") && err.stderr?.toString().includes("no such package available"))) {
428
- console.error(
429
- "npm dist-tag add error please see below for more information:"
430
- );
431
- if (stdoutData.error.summary) {
432
- console.error(stdoutData.error?.summary);
433
- }
434
- if (stdoutData.error.detail) {
435
- console.error(stdoutData.error?.detail);
436
- }
437
- if (context.isVerbose) {
438
- console.error(
439
- `npm dist-tag add stdout: ${JSON.stringify(stdoutData, null, 2)}`
440
- );
441
- }
442
- return { success: false };
443
- }
444
- } catch (err2) {
445
- console.error(
446
- `Something unexpected went wrong when processing the npm dist-tag add output
447
- ${JSON.stringify(err2)}`
448
- );
449
- return { success: false };
450
- }
451
- }
452
- } catch (err) {
453
- let error = err;
454
- if (Buffer.isBuffer(error)) {
455
- error = error.toString();
456
- }
457
- console.error("\n ********************** \n");
458
- console.info("");
459
- console.error(
460
- "An error occured trying to run the npm dist-tag add command."
461
- );
462
- console.error(error);
463
- console.info("");
464
- const stdoutData = JSON.parse(err.stdout?.toString() || "{}");
465
- if (!(stdoutData.error?.code?.includes("E404") && stdoutData.error?.summary?.toLowerCase().includes("not found")) && !(err.stderr?.toString().includes("E404") && err.stderr?.toString().toLowerCase().includes("not found"))) {
466
- console.error(
467
- `Something unexpected went wrong when checking for existing dist-tags.
468
-
469
- Error: ${JSON.stringify(err)}
470
- `
471
- );
472
- return { success: false };
473
- }
474
- }
475
- }
476
- try {
477
- const cwd = packageRoot;
478
- const command = npmPublishCommandSegments.join(" ");
479
- console.info(
480
- `Running publish command "${command}" in current working directory: "${cwd}" `
481
- );
482
- const result = execSync(command, {
483
- cwd,
484
- env: {
485
- ...process.env,
486
- FORCE_COLOR: "true"
487
- },
488
- maxBuffer: LARGE_BUFFER,
489
- killSignal: "SIGTERM"
490
- });
491
- if (isDryRun) {
492
- console.info(
493
- `Would publish to ${registry} with tag "${tag}", but [dry-run] was set ${result ? `
494
-
495
- Execution response: ${result.toString()}` : ""}
496
- `
497
- );
498
- } else {
499
- console.info(`Published to ${registry} with tag "${tag}" ${result ? `
500
-
501
- Execution response: ${result.toString()}` : ""}
502
- `);
503
- }
504
- return { success: true };
505
- } catch (err) {
506
- try {
507
- console.error("\n ********************** \n");
508
- console.info("");
509
- console.error("An error occured running npm publish.");
510
- console.error("Please see below for more information:");
511
- console.info("");
512
- const stdoutData = JSON.parse(err.stdout?.toString() || "{}");
513
- if (stdoutData.error.summary) {
514
- console.error(stdoutData.error.summary);
515
- console.error(stdoutData.error.summary);
516
- }
517
- if (stdoutData.error.detail) {
518
- console.error(stdoutData.error.detail);
519
- }
520
- if (context.isVerbose) {
521
- console.error(
522
- `npm publish stdout:
523
- ${JSON.stringify(stdoutData, null, 2)}`
524
- );
525
- }
526
- console.error("\n ********************** \n");
527
- return { success: false };
528
- } catch (err2) {
529
- let error = err2;
530
- if (Buffer.isBuffer(error)) {
531
- error = error.toString();
532
- }
533
- console.error(
534
- `Something unexpected went wrong when processing the npm publish output
535
-
536
- Error: ${JSON.stringify(error)}
537
- `
538
- );
539
- console.error("\n ********************** \n");
540
- return { success: false };
541
- }
542
- }
543
- }
544
-
545
- export {
546
- LARGE_BUFFER,
547
- npmPublishExecutorFn
548
- };