@nx/js 23.3.0-beta.1 → 23.3.0-beta.2

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.
@@ -39,6 +39,19 @@ function isAlreadyPublishedPublishError(stdoutData, stderr = '', stdout = '') {
39
39
  (error?.code === 'E409' &&
40
40
  errorMessage.includes('this package is already present')));
41
41
  }
42
+ function isNpmViewNotFoundError(err) {
43
+ if (err.code === 'ENOBUFS' || err.signal) {
44
+ return false;
45
+ }
46
+ try {
47
+ const errorCode = JSON.parse(err.stdout?.toString() || '{}').error?.code;
48
+ if (errorCode) {
49
+ return errorCode === 'E404';
50
+ }
51
+ }
52
+ catch { }
53
+ return /(?:^|\n)npm (?:ERR!|error) code E404(?:\n|$)/i.test(err.stderr?.toString() || '');
54
+ }
42
55
  async function runExecutor(options, context) {
43
56
  const pm = (0, devkit_1.detectPackageManager)();
44
57
  // Check if npm is installed (needed for dist-tag management and as fallback for view command)
@@ -146,10 +159,11 @@ Please update the local dependency on "${depName}" to be a valid semantic versio
146
159
  }, warnFn);
147
160
  // Use bun info when bun is the package manager, otherwise use npm view
148
161
  // (npm view works across npm/pnpm/yarn environments and is the established default)
162
+ const npmViewDistTagField = `dist-tags[${tag}]`;
149
163
  const npmViewCommandSegments = pm === 'bun'
150
164
  ? ['bun info', packageName, `--json --"${registryConfigKey}=${registry}"`]
151
165
  : [
152
- `npm view ${packageName} versions dist-tags --json --"${registryConfigKey}=${registry}"`,
166
+ `npm view ${packageName}@${packageJson.version} name version "${npmViewDistTagField}" --json --"${registryConfigKey}=${registry}"`,
153
167
  ];
154
168
  const npmDistTagAddCommandSegments = [
155
169
  `npm dist-tag add ${packageName}@${packageJson.version} ${tag} --"${registryConfigKey}=${registry}"`,
@@ -172,22 +186,46 @@ Please update the local dependency on "${depName}" to be a valid semantic versio
172
186
  windowsHide: true,
173
187
  });
174
188
  // `npm view`/`bun info` can exit 0 with empty stdout when the package exists in the registry but has
175
- // no published versions or dist-tags yet (e.g. GitHub packages). Treat empty output the samme as
189
+ // no published versions or dist-tags yet (e.g. GitHub packages). Treat empty output the same as
176
190
  // package not existing yet and continue to the publish step.
177
- const resultJson = JSON.parse(result.toString().trim() || '{}');
178
- const distTags = resultJson['dist-tags'] || {};
179
- if (distTags[tag] === currentVersion) {
191
+ const output = result.toString().trim();
192
+ let distTagVersion;
193
+ let versionExists;
194
+ if (!output) {
195
+ versionExists = false;
196
+ }
197
+ else {
198
+ const resultJson = JSON.parse(output);
199
+ if (pm === 'bun') {
200
+ distTagVersion = resultJson['dist-tags']?.[tag];
201
+ versionExists = (Array.isArray(resultJson.versions)
202
+ ? resultJson.versions
203
+ : [resultJson.versions]).includes(currentVersion);
204
+ }
205
+ else {
206
+ const metadataEntries = Array.isArray(resultJson)
207
+ ? resultJson
208
+ : [resultJson];
209
+ const currentVersionMetadata = metadataEntries.find((metadata) => metadata?.name === packageName &&
210
+ metadata?.version === currentVersion);
211
+ if (!currentVersionMetadata) {
212
+ console.error(`Something unexpected went wrong when checking for existing dist-tags. The registry returned metadata that did not match ${packageName}@${currentVersion}.`);
213
+ return {
214
+ success: false,
215
+ };
216
+ }
217
+ distTagVersion = currentVersionMetadata[npmViewDistTagField];
218
+ versionExists = true;
219
+ }
220
+ }
221
+ if (distTagVersion === currentVersion) {
180
222
  console.warn(`Skipped ${packageTxt} because v${currentVersion} already exists in ${registry} with tag "${tag}"`);
181
223
  return {
182
224
  success: true,
183
225
  };
184
226
  }
185
227
  if (isNpmInstalled) {
186
- // If only one version of a package exists in the registry, versions will be a string instead of an array.
187
- const versions = Array.isArray(resultJson.versions)
188
- ? resultJson.versions
189
- : [resultJson.versions];
190
- if (versions.includes(currentVersion)) {
228
+ if (versionExists) {
191
229
  try {
192
230
  if (!isDryRun) {
193
231
  (0, child_process_1.execSync)(npmDistTagAddCommandSegments.join(' '), {
@@ -248,35 +286,15 @@ Please update the local dependency on "${depName}" to be a valid semantic versio
248
286
  }
249
287
  }
250
288
  catch (err) {
251
- try {
252
- const stdoutData = JSON.parse(err.stdout?.toString() || '{}');
253
- // If the error is that the package doesn't exist, then we can ignore it because we will be publishing it for the first time in the next step
254
- if (!(stdoutData.error?.code?.includes('E404') &&
255
- stdoutData.error?.summary?.toLowerCase().includes('not found')) &&
256
- !(err.stderr?.toString().includes('E404') &&
257
- err.stderr?.toString().toLowerCase().includes('not found')) &&
258
- // bun uses plain '404' instead of 'E404'
259
- !(err.stderr?.toString().includes('404') &&
260
- err.stderr?.toString().toLowerCase().includes('not found'))) {
261
- console.error(`Something unexpected went wrong when checking for existing dist-tags.\n`, err);
262
- return {
263
- success: false,
264
- };
265
- }
266
- }
267
- catch {
268
- // JSON parse failed entirely — check stderr/stdout for plain 404
269
- const stderrStr = err.stderr?.toString() || '';
270
- const stdoutStr = err.stdout?.toString() || '';
271
- if (!((stderrStr.includes('404') &&
272
- stderrStr.toLowerCase().includes('not found')) ||
273
- (stdoutStr.includes('404') &&
274
- stdoutStr.toLowerCase().includes('not found')))) {
275
- console.error(`Something unexpected went wrong when checking for existing dist-tags.\n`, err);
276
- return {
277
- success: false,
278
- };
279
- }
289
+ const isNotFound = pm === 'bun'
290
+ ? [err.stderr?.toString(), err.stdout?.toString()].some((output) => output?.includes('404') &&
291
+ output.toLowerCase().includes('not found'))
292
+ : isNpmViewNotFoundError(err);
293
+ if (!isNotFound) {
294
+ console.error(`Something unexpected went wrong when checking for existing dist-tags.\n`, err);
295
+ return {
296
+ success: false,
297
+ };
280
298
  }
281
299
  }
282
300
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nx/js",
3
- "version": "23.3.0-beta.1",
3
+ "version": "23.3.0-beta.2",
4
4
  "private": false,
5
5
  "type": "commonjs",
6
6
  "files": [
@@ -147,18 +147,18 @@
147
147
  "source-map-support": "0.5.19",
148
148
  "tinyglobby": "^0.2.12",
149
149
  "tslib": "^2.3.0",
150
- "@nx/devkit": "23.3.0-beta.1",
151
- "@nx/workspace": "23.3.0-beta.1"
150
+ "@nx/workspace": "23.3.0-beta.2",
151
+ "@nx/devkit": "23.3.0-beta.2"
152
152
  },
153
153
  "devDependencies": {
154
- "@nx/jest": "23.3.0-beta.1",
155
- "@nx/esbuild": "23.3.0-beta.1",
156
- "@nx/eslint": "23.3.0-beta.1",
157
- "@nx/oxlint": "23.3.0-beta.1",
158
- "@nx/rollup": "23.3.0-beta.1",
159
- "@nx/vite": "23.3.0-beta.1",
160
- "@nx/vitest": "23.3.0-beta.1",
161
- "nx": "23.3.0-beta.1"
154
+ "@nx/jest": "23.3.0-beta.2",
155
+ "@nx/esbuild": "23.3.0-beta.2",
156
+ "@nx/eslint": "23.3.0-beta.2",
157
+ "@nx/oxlint": "23.3.0-beta.2",
158
+ "@nx/vitest": "23.3.0-beta.2",
159
+ "@nx/rollup": "23.3.0-beta.2",
160
+ "nx": "23.3.0-beta.2",
161
+ "@nx/vite": "23.3.0-beta.2"
162
162
  },
163
163
  "peerDependencies": {
164
164
  "@swc/cli": ">=0.6.0 <0.9.0",