@nx/js 24.0.3 → 24.0.5

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.
@@ -155,18 +155,15 @@ Please update the local dependency on "${depName}" to be a valid semantic versio
155
155
  registry: options.registry,
156
156
  tag: options.tag,
157
157
  }, warnFn);
158
+ const registryArgs = registry ? [`--${registryConfigKey}=${registry}`] : [];
159
+ const registryLabel = describeRegistry(registry, registryConfigKey);
158
160
  // Use bun info when bun is the package manager, otherwise use npm view
159
161
  // (npm view works across npm/pnpm/yarn environments and is the established default)
160
162
  const npmViewDistTagField = `dist-tags[${tag}]`;
161
163
  const npmViewCommand = pm === 'bun'
162
164
  ? {
163
165
  command: 'bun',
164
- args: [
165
- 'info',
166
- packageName,
167
- '--json',
168
- `--${registryConfigKey}=${registry}`,
169
- ],
166
+ args: ['info', packageName, '--json', ...registryArgs],
170
167
  }
171
168
  : {
172
169
  command: 'npm',
@@ -177,7 +174,7 @@ Please update the local dependency on "${depName}" to be a valid semantic versio
177
174
  'version',
178
175
  npmViewDistTagField,
179
176
  '--json',
180
- `--${registryConfigKey}=${registry}`,
177
+ ...registryArgs,
181
178
  ],
182
179
  };
183
180
  const npmDistTagAddCommand = {
@@ -187,7 +184,7 @@ Please update the local dependency on "${depName}" to be a valid semantic versio
187
184
  'add',
188
185
  `${packageName}@${packageJson.version}`,
189
186
  tag,
190
- `--${registryConfigKey}=${registry}`,
187
+ ...registryArgs,
191
188
  ],
192
189
  };
193
190
  /**
@@ -240,7 +237,7 @@ Please update the local dependency on "${depName}" to be a valid semantic versio
240
237
  }
241
238
  }
242
239
  if (distTagVersion === currentVersion) {
243
- console.warn(`Skipped ${packageTxt} because v${currentVersion} already exists in ${registry} with tag "${tag}"`);
240
+ console.warn(`Skipped ${packageTxt} because v${currentVersion} already exists in ${registryLabel} with tag "${tag}"`);
244
241
  return {
245
242
  success: true,
246
243
  };
@@ -254,10 +251,10 @@ Please update the local dependency on "${depName}" to be a valid semantic versio
254
251
  cwd: context.root,
255
252
  stdio: 'ignore',
256
253
  });
257
- console.log(`Added the dist-tag ${tag} to v${currentVersion} for registry ${registry}.\n`);
254
+ console.log(`Added the dist-tag ${tag} to v${currentVersion} for registry ${registryLabel}.\n`);
258
255
  }
259
256
  else {
260
- console.log(`Would add the dist-tag ${tag} to v${currentVersion} for registry ${registry}, but ${chalk.keyword('orange')('[dry-run]')} was set.\n`);
257
+ console.log(`Would add the dist-tag ${tag} to v${currentVersion} for registry ${registryLabel}, but ${chalk.keyword('orange')('[dry-run]')} was set.\n`);
261
258
  }
262
259
  return {
263
260
  success: true,
@@ -340,8 +337,12 @@ Please update the local dependency on "${depName}" to be a valid semantic versio
340
337
  packageTxt,
341
338
  });
342
339
  }
340
+ function describeRegistry(registry, registryConfigKey) {
341
+ return registry ?? `the configured ${registryConfigKey}`;
342
+ }
343
343
  function runPublish(ctx) {
344
344
  const { pm, options, context, packageRoot, packageJson, registry, registryConfigKey, tag, isDryRun, isNpmInstalled, packageTxt, } = ctx;
345
+ const registryLabel = describeRegistry(registry, registryConfigKey);
345
346
  const pmCommand = (0, devkit_1.getPackageManagerCommand)(pm);
346
347
  const { command: publishCommand, args: publishArgs } = pmCommand.publishArgv(packageRoot, registry, registryConfigKey, tag);
347
348
  if (options.otp) {
@@ -363,8 +364,8 @@ function runPublish(ctx) {
363
364
  // If in dry-run mode, the version on disk will not represent the version that would be published, so we scrub it from the output to avoid confusion.
364
365
  const dryRunVersionPlaceholder = 'X.X.X-dry-run';
365
366
  const publishSummaryMessage = isDryRun
366
- ? `Would publish to ${registry} with tag "${tag}", but ${chalk.keyword('orange')('[dry-run]')} was set`
367
- : `Published to ${registry} with tag "${tag}"`;
367
+ ? `Would publish to ${registryLabel} with tag "${tag}", but ${chalk.keyword('orange')('[dry-run]')} was set`
368
+ : `Published to ${registryLabel} with tag "${tag}"`;
368
369
  // bun publish does not support outputting JSON, so we need to modify and print the output string directly
369
370
  if (pm === 'bun') {
370
371
  let outputStr = output;
@@ -456,7 +457,7 @@ function runPublish(ctx) {
456
457
  const stderr = err.stderr?.toString() || '';
457
458
  const stdout = err.stdout?.toString() || '';
458
459
  if (isAlreadyPublishedPublishError(undefined, stderr, stdout)) {
459
- console.warn(`Skipped ${packageTxt}, as v${packageJson.version} has already been published to ${registry} with tag "${tag}"`);
460
+ console.warn(`Skipped ${packageTxt}, as v${packageJson.version} has already been published to ${registryLabel} with tag "${tag}"`);
460
461
  return {
461
462
  success: true,
462
463
  };
@@ -468,7 +469,7 @@ function runPublish(ctx) {
468
469
  };
469
470
  }
470
471
  if (isAlreadyPublishedPublishError(stdoutData, err.stderr?.toString() || '', err.stdout?.toString() || '')) {
471
- console.warn(`Skipped ${packageTxt}, as v${packageJson.version} has already been published to ${registry} with tag "${tag}"`);
472
+ console.warn(`Skipped ${packageTxt}, as v${packageJson.version} has already been published to ${registryLabel} with tag "${tag}"`);
472
473
  return {
473
474
  success: true,
474
475
  };
@@ -22,7 +22,7 @@ function resolveTypescriptPath(projectRoot, workspaceRoot) {
22
22
  });
23
23
  return resolvedTypescriptPaths[projectRoot];
24
24
  }
25
- const TSCONFIG_CACHE_VERSION = 2;
25
+ const TSCONFIG_CACHE_VERSION = 3;
26
26
  const TS_CONFIG_CACHE_PATH = (0, node_path_1.join)(internal_1.workspaceDataDirectory, 'tsconfig-files.hash');
27
27
  // Module-level cache store — each invocation gets a unique Symbol key
28
28
  const cacheStore = new Map();
@@ -1106,16 +1106,17 @@ function toAbsolutePaths(cache, workspaceRoot) {
1106
1106
  extendedFilesHash,
1107
1107
  hash,
1108
1108
  };
1109
- if (data.options.rootDir) {
1109
+ // '' is a valid cached path (the workspace root), so check for undefined
1110
+ if (data.options.rootDir !== undefined) {
1110
1111
  updatedCache[key].data.options.rootDir = (0, node_path_1.join)(workspaceRoot, data.options.rootDir);
1111
1112
  }
1112
- if (data.options.outDir) {
1113
+ if (data.options.outDir !== undefined) {
1113
1114
  updatedCache[key].data.options.outDir = (0, node_path_1.join)(workspaceRoot, data.options.outDir);
1114
1115
  }
1115
- if (data.options.outFile) {
1116
+ if (data.options.outFile !== undefined) {
1116
1117
  updatedCache[key].data.options.outFile = (0, node_path_1.join)(workspaceRoot, data.options.outFile);
1117
1118
  }
1118
- if (data.options.tsBuildInfoFile) {
1119
+ if (data.options.tsBuildInfoFile !== undefined) {
1119
1120
  updatedCache[key].data.options.tsBuildInfoFile = (0, node_path_1.join)(workspaceRoot, data.options.tsBuildInfoFile);
1120
1121
  }
1121
1122
  if (data.extendedConfigFiles.length) {
@@ -1160,16 +1161,16 @@ function toRelativePaths(cache, workspaceRoot) {
1160
1161
  hash,
1161
1162
  };
1162
1163
  if (data.options.rootDir) {
1163
- updatedCache[key].data.options.rootDir = posixRelative(workspaceRoot, data.options.rootDir);
1164
+ updatedCache[key].data.options.rootDir = toCachedPath(workspaceRoot, data.options.rootDir);
1164
1165
  }
1165
1166
  if (data.options.outDir) {
1166
- updatedCache[key].data.options.outDir = posixRelative(workspaceRoot, data.options.outDir);
1167
+ updatedCache[key].data.options.outDir = toCachedPath(workspaceRoot, data.options.outDir);
1167
1168
  }
1168
1169
  if (data.options.outFile) {
1169
- updatedCache[key].data.options.outFile = posixRelative(workspaceRoot, data.options.outFile);
1170
+ updatedCache[key].data.options.outFile = toCachedPath(workspaceRoot, data.options.outFile);
1170
1171
  }
1171
1172
  if (data.options.tsBuildInfoFile) {
1172
- updatedCache[key].data.options.tsBuildInfoFile = posixRelative(workspaceRoot, data.options.tsBuildInfoFile);
1173
+ updatedCache[key].data.options.tsBuildInfoFile = toCachedPath(workspaceRoot, data.options.tsBuildInfoFile);
1173
1174
  }
1174
1175
  if (data.extendedConfigFiles.length) {
1175
1176
  updatedCache[key].data.extendedConfigFiles.forEach((file) => {
@@ -1188,3 +1189,7 @@ function toRelativePaths(cache, workspaceRoot) {
1188
1189
  function posixRelative(workspaceRoot, path) {
1189
1190
  return (0, devkit_1.normalizePath)((0, node_path_1.relative)(workspaceRoot, path));
1190
1191
  }
1192
+ // relative() returns '' for the workspace root, which is falsy like an unset option
1193
+ function toCachedPath(workspaceRoot, path) {
1194
+ return posixRelative(workspaceRoot, path) || '.';
1195
+ }
@@ -72,7 +72,7 @@ class JsVersionActions extends release_1.VersionActions {
72
72
  'view',
73
73
  packageName,
74
74
  'version',
75
- `--${registryConfigKey}=${registry}`,
75
+ ...(registry ? [`--${registryConfigKey}=${registry}`] : []),
76
76
  `--tag=${tag}`,
77
77
  ], { stdio: ['ignore', 'pipe', 'pipe'] });
78
78
  let stdout = '';
@@ -105,7 +105,9 @@ class JsVersionActions extends release_1.VersionActions {
105
105
  return {
106
106
  currentVersion,
107
107
  // Make troubleshooting easier by including the registry and tag data in the log text
108
- logText: `"${registryConfigKey}=${registry}" tag=${tag}`,
108
+ logText: registry
109
+ ? `"${registryConfigKey}=${registry}" tag=${tag}`
110
+ : `the configured "${registryConfigKey}" tag=${tag}`,
109
111
  };
110
112
  }
111
113
  async readCurrentVersionOfDependency(tree, projectGraph, dependencyProjectName) {
@@ -2,9 +2,11 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.findNpmDependencies = findNpmDependencies;
4
4
  const path_1 = require("path");
5
+ const semver_1 = require("semver");
5
6
  const devkit_1 = require("@nx/devkit");
6
7
  const ts_config_1 = require("./typescript/ts-config");
7
8
  const internal_1 = require("@nx/devkit/internal");
9
+ const highestHelperVersions = new WeakMap();
8
10
  /**
9
11
  * Finds all npm dependencies and their expected versions for a given project.
10
12
  */
@@ -114,10 +116,11 @@ function readPackageJson(project, workspaceRoot) {
114
116
  function collectHelperDependencies(workspaceRoot, sourceProject, projectGraph, buildTarget, runtimeHelpers, npmDeps) {
115
117
  if (runtimeHelpers?.length > 0) {
116
118
  for (const helper of runtimeHelpers) {
117
- if (!npmDeps[helper] &&
118
- projectGraph.externalNodes[`npm:${helper}`]?.type === 'npm') {
119
- npmDeps[helper] =
120
- projectGraph.externalNodes[`npm:${helper}`].data.version;
119
+ if (npmDeps[helper])
120
+ continue;
121
+ const version = findHelperVersion(projectGraph, sourceProject, helper);
122
+ if (version) {
123
+ npmDeps[helper] = version;
121
124
  }
122
125
  }
123
126
  return;
@@ -127,9 +130,10 @@ function collectHelperDependencies(workspaceRoot, sourceProject, projectGraph, b
127
130
  return;
128
131
  if (target.executor === '@nx/js:tsc' && target.options?.tsConfig) {
129
132
  const tsConfig = (0, ts_config_1.readTsConfig)((0, path_1.join)(workspaceRoot, target.options.tsConfig));
130
- if (tsConfig?.options['importHelpers'] &&
131
- projectGraph.externalNodes['npm:tslib']?.type === 'npm') {
132
- npmDeps['tslib'] = projectGraph.externalNodes['npm:tslib'].data.version;
133
+ const version = tsConfig?.options['importHelpers'] &&
134
+ findHelperVersion(projectGraph, sourceProject, 'tslib');
135
+ if (version) {
136
+ npmDeps['tslib'] = version;
133
137
  }
134
138
  }
135
139
  if (target.executor === '@nx/js:swc') {
@@ -139,10 +143,10 @@ function collectHelperDependencies(workspaceRoot, sourceProject, projectGraph, b
139
143
  const swcConfig = (0, internal_1.fileExists)(swcConfigPath)
140
144
  ? (0, devkit_1.readJsonFile)(swcConfigPath)
141
145
  : {};
142
- if (swcConfig?.jsc?.externalHelpers &&
143
- projectGraph.externalNodes['npm:@swc/helpers']?.type === 'npm') {
144
- npmDeps['@swc/helpers'] =
145
- projectGraph.externalNodes['npm:@swc/helpers'].data.version;
146
+ const version = swcConfig?.jsc?.externalHelpers &&
147
+ findHelperVersion(projectGraph, sourceProject, '@swc/helpers');
148
+ if (version) {
149
+ npmDeps['@swc/helpers'] = version;
146
150
  }
147
151
  }
148
152
  // For inferred targets or manually added run-commands, check if user is using `tsc` in build target.
@@ -151,13 +155,49 @@ function collectHelperDependencies(workspaceRoot, sourceProject, projectGraph, b
151
155
  const tsConfigPath = resolveTsConfigForRunCommandsTarget(workspaceRoot, sourceProject, target.options);
152
156
  if (tsConfigPath) {
153
157
  const tsConfig = (0, ts_config_1.readTsConfig)(tsConfigPath);
154
- if (tsConfig?.options['importHelpers'] &&
155
- projectGraph.externalNodes['npm:tslib']?.type === 'npm') {
156
- npmDeps['tslib'] = projectGraph.externalNodes['npm:tslib'].data.version;
158
+ const version = tsConfig?.options['importHelpers'] &&
159
+ findHelperVersion(projectGraph, sourceProject, 'tslib');
160
+ if (version) {
161
+ npmDeps['tslib'] = version;
157
162
  }
158
163
  }
159
164
  }
160
165
  }
166
+ function findHelperVersion(projectGraph, sourceProject, helper) {
167
+ const bareNode = projectGraph.externalNodes[`npm:${helper}`];
168
+ const bareLinkVersion = bareNode?.data.version.startsWith('link:')
169
+ ? bareNode.data.version
170
+ : undefined;
171
+ if (bareNode && !bareLinkVersion) {
172
+ return bareNode.type === 'npm' ? bareNode.data.version : undefined;
173
+ }
174
+ // A helper with several versions can have only versioned nodes, for
175
+ // example when the pnpm root importer does not declare it, and an outside
176
+ // `link:` can then hold the bare name. Prefer the version that the project
177
+ // depends on, else the highest registry version, else the link.
178
+ const isHelperNode = (name) => projectGraph.externalNodes[name]?.type === 'npm' &&
179
+ projectGraph.externalNodes[name].data.packageName === helper;
180
+ const projectDependency = projectGraph.dependencies[sourceProject.name]?.find((dependency) => isHelperNode(dependency.target));
181
+ if (projectDependency) {
182
+ return projectGraph.externalNodes[projectDependency.target].data.version;
183
+ }
184
+ let versions = highestHelperVersions.get(projectGraph.externalNodes);
185
+ if (!versions) {
186
+ versions = new Map();
187
+ highestHelperVersions.set(projectGraph.externalNodes, versions);
188
+ }
189
+ if (!versions.has(helper)) {
190
+ const candidates = Object.keys(projectGraph.externalNodes)
191
+ .filter(isHelperNode)
192
+ .map((name) => projectGraph.externalNodes[name].data.version)
193
+ .filter((version) => (0, semver_1.valid)(version) !== null)
194
+ .sort(semver_1.rcompare);
195
+ // A stable version wins over a prerelease.
196
+ versions.set(helper, candidates.find((version) => (0, semver_1.prerelease)(version) === null) ??
197
+ candidates[0]);
198
+ }
199
+ return versions.get(helper) ?? bareLinkVersion;
200
+ }
161
201
  function resolveTsConfigForRunCommandsTarget(workspaceRoot, sourceProject, targetOptions) {
162
202
  const commandTsConfig = extractTsConfigFromCommand(targetOptions.command);
163
203
  if (commandTsConfig) {
@@ -6,7 +6,7 @@ export declare function parseRegistryOptions(cwd: string, pkg: {
6
6
  registry?: string;
7
7
  tag?: string;
8
8
  }, logWarnFn?: (message: string) => void): Promise<{
9
- registry: string;
9
+ registry: string | undefined;
10
10
  tag: string;
11
11
  registryConfigKey: string;
12
12
  }>;
@@ -16,7 +16,7 @@ export declare function parseRegistryOptions(cwd: string, pkg: {
16
16
  * @param scope the scope of the package for which to determine the registry
17
17
  * @param cwd the directory where the npm config should be read from
18
18
  */
19
- export declare function getNpmRegistry(cwd: string, scope?: string): Promise<string>;
19
+ export declare function getNpmRegistry(cwd: string, scope?: string): Promise<string | undefined>;
20
20
  /**
21
21
  * Returns the npm tag that is used for publishing.
22
22
  *
@@ -46,14 +46,21 @@ async function parseRegistryOptions(cwd, pkg, options, logWarnFn = console.warn)
46
46
  * @param cwd the directory where the npm config should be read from
47
47
  */
48
48
  async function getNpmRegistry(cwd, scope) {
49
- let registry;
50
49
  if (scope) {
51
- registry = await getNpmConfigValue(`${scope}:registry`, cwd);
52
- }
53
- if (!registry) {
54
- registry = await getNpmConfigValue('registry', cwd);
50
+ let scopedRegistry;
51
+ try {
52
+ scopedRegistry = await readNpmConfigValue(`${scope}:registry`, cwd);
53
+ }
54
+ catch {
55
+ // npm refuses to print values it would redact, so the scope may still
56
+ // have a registry. Falling back to the unscoped one would override it.
57
+ return undefined;
58
+ }
59
+ if (scopedRegistry) {
60
+ return scopedRegistry;
61
+ }
55
62
  }
56
- return registry;
63
+ return getNpmConfigValue('registry', cwd);
57
64
  }
58
65
  /**
59
66
  * Returns the npm tag that is used for publishing.
@@ -66,13 +73,16 @@ async function getNpmTag(cwd) {
66
73
  }
67
74
  async function getNpmConfigValue(key, cwd) {
68
75
  try {
69
- const result = await npmConfigGet(key, cwd);
70
- return result === 'undefined' ? undefined : result;
76
+ return await readNpmConfigValue(key, cwd);
71
77
  }
72
- catch (e) {
73
- return Promise.resolve(undefined);
78
+ catch {
79
+ return undefined;
74
80
  }
75
81
  }
82
+ async function readNpmConfigValue(key, cwd) {
83
+ const result = await npmConfigGet(key, cwd);
84
+ return result === 'undefined' ? undefined : result;
85
+ }
76
86
  // `key` carries the package's own scope, so it goes to npm as an argument
77
87
  // rather than through a shell.
78
88
  async function npmConfigGet(key, cwd) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nx/js",
3
- "version": "24.0.3",
3
+ "version": "24.0.5",
4
4
  "private": false,
5
5
  "type": "commonjs",
6
6
  "files": [
@@ -162,8 +162,8 @@
162
162
  "@babel/preset-env": "^7.23.2",
163
163
  "@babel/preset-typescript": "^7.22.5",
164
164
  "@babel/runtime": "^7.22.6",
165
- "@nx/devkit": "24.0.3",
166
- "@nx/workspace": "24.0.3",
165
+ "@nx/devkit": "24.0.5",
166
+ "@nx/workspace": "24.0.5",
167
167
  "@zkochan/js-yaml": "0.0.7",
168
168
  "babel-plugin-const-enum": "^1.0.1",
169
169
  "babel-plugin-macros": "^3.1.0",
@@ -176,21 +176,21 @@
176
176
  "jsonc-parser": "^3.2.0",
177
177
  "npm-run-path": "^4.0.1",
178
178
  "picocolors": "^1.1.0",
179
- "picomatch": "4.0.4",
179
+ "picomatch": "^4.0.7",
180
180
  "semver": "^7.6.3",
181
- "source-map-support": "0.5.19",
181
+ "source-map-support": "0.5.21",
182
182
  "tinyglobby": "^0.2.12",
183
183
  "tslib": "^2.3.0"
184
184
  },
185
185
  "devDependencies": {
186
- "@nx/esbuild": "24.0.3",
187
- "@nx/eslint": "24.0.3",
188
- "@nx/jest": "24.0.3",
189
- "@nx/oxlint": "24.0.3",
190
- "@nx/rollup": "24.0.3",
191
- "@nx/vite": "24.0.3",
192
- "@nx/vitest": "24.0.3",
193
- "nx": "24.0.3"
186
+ "@nx/esbuild": "24.0.5",
187
+ "@nx/eslint": "24.0.5",
188
+ "@nx/jest": "24.0.5",
189
+ "@nx/oxlint": "24.0.5",
190
+ "@nx/rollup": "24.0.5",
191
+ "@nx/vite": "24.0.5",
192
+ "@nx/vitest": "24.0.5",
193
+ "nx": "24.0.5"
194
194
  },
195
195
  "peerDependencies": {
196
196
  "@swc/cli": ">=0.6.0 <0.9.0",