@nx/js 18.2.2 → 18.2.3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nx/js",
3
- "version": "18.2.2",
3
+ "version": "18.2.3",
4
4
  "private": false,
5
5
  "description": "The JS plugin for Nx contains executors and generators that provide the best experience for developing JavaScript and TypeScript projects. ",
6
6
  "repository": {
@@ -57,9 +57,9 @@
57
57
  "semver": "^7.5.3",
58
58
  "source-map-support": "0.5.19",
59
59
  "tslib": "^2.3.0",
60
- "@nx/devkit": "18.2.2",
61
- "@nx/workspace": "18.2.2",
62
- "@nrwl/js": "18.2.2"
60
+ "@nx/devkit": "18.2.3",
61
+ "@nx/workspace": "18.2.3",
62
+ "@nrwl/js": "18.2.3"
63
63
  },
64
64
  "peerDependencies": {
65
65
  "verdaccio": "^5.0.4"
@@ -112,8 +112,14 @@ async function* nodeExecutor(options, context) {
112
112
  if (options.watch && !task.killed) {
113
113
  devkit_1.logger.info(`NX Process exited with code ${code}, waiting for changes to restart...`);
114
114
  }
115
- if (!options.watch)
116
- done();
115
+ if (!options.watch) {
116
+ if (code !== 0) {
117
+ error(new Error(`Process exited with code ${code}`));
118
+ }
119
+ else {
120
+ done();
121
+ }
122
+ }
117
123
  resolve();
118
124
  });
119
125
  next({ success: true, options: buildOptions });
@@ -3,6 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const devkit_1 = require("@nx/devkit");
4
4
  const child_process_1 = require("child_process");
5
5
  const npm_run_path_1 = require("npm-run-path");
6
+ const path_1 = require("path");
7
+ const npm_config_1 = require("../../utils/npm-config");
6
8
  const log_tar_1 = require("./log-tar");
7
9
  const chalk = require("chalk");
8
10
  const LARGE_BUFFER = 1024 * 1000000;
@@ -23,40 +25,36 @@ async function runExecutor(options, context) {
23
25
  */
24
26
  const isDryRun = process.env.NX_DRY_RUN === 'true' || options.dryRun || false;
25
27
  const projectConfig = context.projectsConfigurations.projects[context.projectName];
26
- const packageRoot = (0, devkit_1.joinPathFragments)(context.root, options.packageRoot ?? projectConfig.root);
27
- const packageJsonPath = (0, devkit_1.joinPathFragments)(packageRoot, 'package.json');
28
- const projectPackageJson = (0, devkit_1.readJsonFile)(packageJsonPath);
29
- const packageName = projectPackageJson.name;
28
+ const packageRoot = (0, path_1.join)(context.root, options.packageRoot ?? projectConfig.root);
29
+ const packageJsonPath = (0, path_1.join)(packageRoot, 'package.json');
30
+ const packageJson = (0, devkit_1.readJsonFile)(packageJsonPath);
31
+ const packageName = packageJson.name;
30
32
  // If package and project name match, we can make log messages terser
31
33
  let packageTxt = packageName === context.projectName
32
34
  ? `package "${packageName}"`
33
35
  : `package "${packageName}" from project "${context.projectName}"`;
34
- if (projectPackageJson.private === true) {
36
+ if (packageJson.private === true) {
35
37
  console.warn(`Skipped ${packageTxt}, because it has \`"private": true\` in ${packageJsonPath}`);
36
38
  return {
37
39
  success: true,
38
40
  };
39
41
  }
40
- const npmPublishCommandSegments = [`npm publish --json`];
42
+ const warnFn = (message) => {
43
+ console.log(chalk.keyword('orange')(message));
44
+ };
45
+ const { registry, tag, registryConfigKey } = await (0, npm_config_1.parseRegistryOptions)(context.root, {
46
+ packageRoot,
47
+ packageJson,
48
+ }, {
49
+ registry: options.registry,
50
+ tag: options.tag,
51
+ }, warnFn);
41
52
  const npmViewCommandSegments = [
42
- `npm view ${packageName} versions dist-tags --json`,
53
+ `npm view ${packageName} versions dist-tags --json --"${registryConfigKey}=${registry}"`,
54
+ ];
55
+ const npmDistTagAddCommandSegments = [
56
+ `npm dist-tag add ${packageName}@${packageJson.version} ${tag} --"${registryConfigKey}=${registry}"`,
43
57
  ];
44
- if (options.registry) {
45
- npmPublishCommandSegments.push(`--registry=${options.registry}`);
46
- npmViewCommandSegments.push(`--registry=${options.registry}`);
47
- }
48
- if (options.tag) {
49
- npmPublishCommandSegments.push(`--tag=${options.tag}`);
50
- }
51
- if (options.otp) {
52
- npmPublishCommandSegments.push(`--otp=${options.otp}`);
53
- }
54
- if (isDryRun) {
55
- npmPublishCommandSegments.push(`--dry-run`);
56
- }
57
- // Resolve values using the `npm config` command so that things like environment variables and `publishConfig`s are accounted for
58
- const registry = options.registry ?? (0, child_process_1.execSync)(`npm config get registry`).toString().trim();
59
- const tag = options.tag ?? (0, child_process_1.execSync)(`npm config get tag`).toString().trim();
60
58
  /**
61
59
  * In a dry-run scenario, it is most likely that all commands are being run with dry-run, therefore
62
60
  * the most up to date/relevant version might not exist on disk for us to read and make the npm view
@@ -66,11 +64,11 @@ async function runExecutor(options, context) {
66
64
  * perform the npm view step, and just show npm publish's dry-run output.
67
65
  */
68
66
  if (!isDryRun && !options.firstRelease) {
69
- const currentVersion = projectPackageJson.version;
67
+ const currentVersion = packageJson.version;
70
68
  try {
71
69
  const result = (0, child_process_1.execSync)(npmViewCommandSegments.join(' '), {
72
70
  env: processEnv(true),
73
- cwd: packageRoot,
71
+ cwd: context.root,
74
72
  stdio: ['ignore', 'pipe', 'pipe'],
75
73
  });
76
74
  const resultJson = JSON.parse(result.toString());
@@ -84,9 +82,9 @@ async function runExecutor(options, context) {
84
82
  if (resultJson.versions.includes(currentVersion)) {
85
83
  try {
86
84
  if (!isDryRun) {
87
- (0, child_process_1.execSync)(`npm dist-tag add ${packageName}@${currentVersion} ${tag} --registry=${registry}`, {
85
+ (0, child_process_1.execSync)(npmDistTagAddCommandSegments.join(' '), {
88
86
  env: processEnv(true),
89
- cwd: packageRoot,
87
+ cwd: context.root,
90
88
  stdio: 'ignore',
91
89
  });
92
90
  console.log(`Added the dist-tag ${tag} to v${currentVersion} for registry ${registry}.\n`);
@@ -148,11 +146,20 @@ async function runExecutor(options, context) {
148
146
  if (options.firstRelease && context.isVerbose) {
149
147
  console.log('Skipped npm view because --first-release was set');
150
148
  }
149
+ const npmPublishCommandSegments = [
150
+ `npm publish ${packageRoot} --json --"${registryConfigKey}=${registry}" --tag=${tag}`,
151
+ ];
152
+ if (options.otp) {
153
+ npmPublishCommandSegments.push(`--otp=${options.otp}`);
154
+ }
155
+ if (isDryRun) {
156
+ npmPublishCommandSegments.push(`--dry-run`);
157
+ }
151
158
  try {
152
159
  const output = (0, child_process_1.execSync)(npmPublishCommandSegments.join(' '), {
153
160
  maxBuffer: LARGE_BUFFER,
154
161
  env: processEnv(true),
155
- cwd: packageRoot,
162
+ cwd: context.root,
156
163
  stdio: ['ignore', 'pipe', 'pipe'],
157
164
  });
158
165
  const stdoutData = JSON.parse(output.toString());
@@ -13,6 +13,7 @@ const version_1 = require("nx/src/command-line/release/version");
13
13
  const utils_1 = require("nx/src/tasks-runner/utils");
14
14
  const ora = require("ora");
15
15
  const semver_2 = require("semver");
16
+ const npm_config_1 = require("../../utils/npm-config");
16
17
  const resolve_local_package_dependencies_1 = require("./utils/resolve-local-package-dependencies");
17
18
  const update_lock_file_1 = require("./utils/update-lock-file");
18
19
  async function releaseVersionGenerator(tree, options) {
@@ -61,28 +62,37 @@ Valid values are: ${version_1.validReleaseVersionPrefixes
61
62
  if (!packageRoot) {
62
63
  throw new Error(`The project "${projectName}" does not have a packageRoot available. Please report this issue on https://github.com/nrwl/nx`);
63
64
  }
64
- const packageJsonPath = (0, devkit_1.joinPathFragments)(packageRoot, 'package.json');
65
- const workspaceRelativePackageJsonPath = (0, node_path_1.relative)(devkit_1.workspaceRoot, packageJsonPath);
65
+ const packageJsonPath = (0, node_path_1.join)(packageRoot, 'package.json');
66
66
  const color = getColor(projectName);
67
67
  const log = (msg) => {
68
68
  console.log(color.instance.bold(projectName) + ' ' + msg);
69
69
  };
70
70
  if (!tree.exists(packageJsonPath)) {
71
- throw new Error(`The project "${projectName}" does not have a package.json available at ${workspaceRelativePackageJsonPath}.
71
+ throw new Error(`The project "${projectName}" does not have a package.json available at ${packageJsonPath}.
72
72
 
73
73
  To fix this you will either need to add a package.json file at that location, or configure "release" within your nx.json to exclude "${projectName}" from the current release group, or amend the packageRoot configuration to point to where the package.json should be.`);
74
74
  }
75
75
  devkit_1.output.logSingleLine(`Running release version for project: ${color.instance.bold(project.name)}`);
76
- const projectPackageJson = (0, devkit_1.readJson)(tree, packageJsonPath);
77
- log(`🔍 Reading data for package "${projectPackageJson.name}" from ${workspaceRelativePackageJsonPath}`);
78
- const { name: packageName, version: currentVersionFromDisk } = projectPackageJson;
76
+ const packageJson = (0, devkit_1.readJson)(tree, packageJsonPath);
77
+ log(`🔍 Reading data for package "${packageJson.name}" from ${packageJsonPath}`);
78
+ const { name: packageName, version: currentVersionFromDisk } = packageJson;
79
79
  switch (options.currentVersionResolver) {
80
80
  case 'registry': {
81
81
  const metadata = options.currentVersionResolverMetadata;
82
- const registry = metadata?.registry ??
83
- (await getNpmRegistry()) ??
84
- 'https://registry.npmjs.org';
85
- const tag = metadata?.tag ?? 'latest';
82
+ const registryArg = typeof metadata?.registry === 'string'
83
+ ? metadata.registry
84
+ : undefined;
85
+ const tagArg = typeof metadata?.tag === 'string' ? metadata.tag : undefined;
86
+ const warnFn = (message) => {
87
+ console.log(chalk.keyword('orange')(message));
88
+ };
89
+ const { registry, tag, registryConfigKey } = await (0, npm_config_1.parseRegistryOptions)(devkit_1.workspaceRoot, {
90
+ packageRoot: (0, node_path_1.join)(devkit_1.workspaceRoot, packageRoot),
91
+ packageJson,
92
+ }, {
93
+ registry: registryArg,
94
+ tag: tagArg,
95
+ }, warnFn);
86
96
  /**
87
97
  * If the currentVersionResolver is set to registry, and the projects are not independent, we only want to make the request once for the whole batch of projects.
88
98
  * For independent projects, we need to make a request for each project individually as they will most likely have different versions.
@@ -96,7 +106,7 @@ To fix this you will either need to add a package.json file at that location, or
96
106
  try {
97
107
  // Must be non-blocking async to allow spinner to render
98
108
  currentVersion = await new Promise((resolve, reject) => {
99
- (0, node_child_process_1.exec)(`npm view ${packageName} version --registry=${registry} --tag=${tag}`, (error, stdout, stderr) => {
109
+ (0, node_child_process_1.exec)(`npm view ${packageName} version --"${registryConfigKey}=${registry}" --tag=${tag}`, (error, stdout, stderr) => {
100
110
  if (error) {
101
111
  return reject(error);
102
112
  }
@@ -266,16 +276,16 @@ To fix this you will either need to add a package.json file at that location, or
266
276
  newVersion: null, // will stay as null in the final result in the case that no changes are detected
267
277
  };
268
278
  if (!specifier) {
269
- log(`🚫 Skipping versioning "${projectPackageJson.name}" as no changes were detected.`);
279
+ log(`🚫 Skipping versioning "${packageJson.name}" as no changes were detected.`);
270
280
  continue;
271
281
  }
272
282
  const newVersion = (0, version_1.deriveNewSemverVersion)(currentVersion, specifier, options.preid);
273
283
  versionData[projectName].newVersion = newVersion;
274
284
  (0, devkit_1.writeJson)(tree, packageJsonPath, {
275
- ...projectPackageJson,
285
+ ...packageJson,
276
286
  version: newVersion,
277
287
  });
278
- log(`✍️ New version ${newVersion} written to ${workspaceRelativePackageJsonPath}`);
288
+ log(`✍️ New version ${newVersion} written to ${packageJsonPath}`);
279
289
  if (dependentProjects.length > 0) {
280
290
  log(`✍️ Applying new version ${newVersion} to ${dependentProjects.length} ${dependentProjects.length > 1
281
291
  ? 'packages which depend'
@@ -286,7 +296,7 @@ To fix this you will either need to add a package.json file at that location, or
286
296
  if (!dependentPackageRoot) {
287
297
  throw new Error(`The dependent project "${dependentProject.source}" does not have a packageRoot available. Please report this issue on https://github.com/nrwl/nx`);
288
298
  }
289
- (0, devkit_1.updateJson)(tree, (0, devkit_1.joinPathFragments)(dependentPackageRoot, 'package.json'), (json) => {
299
+ (0, devkit_1.updateJson)(tree, (0, node_path_1.join)(dependentPackageRoot, 'package.json'), (json) => {
290
300
  // Auto (i.e.infer existing) by default
291
301
  let versionPrefix = options.versionPrefix ?? 'auto';
292
302
  // For auto, we infer the prefix based on the current version of the dependent
@@ -374,17 +384,3 @@ function getColor(projectName) {
374
384
  const colorIndex = code % colors.length;
375
385
  return colors[colorIndex];
376
386
  }
377
- async function getNpmRegistry() {
378
- // Must be non-blocking async to allow spinner to render
379
- return await new Promise((resolve, reject) => {
380
- (0, node_child_process_1.exec)('npm config get registry', (error, stdout, stderr) => {
381
- if (error) {
382
- return reject(error);
383
- }
384
- if (stderr) {
385
- return reject(stderr);
386
- }
387
- return resolve(stdout.trim());
388
- });
389
- });
390
- }
@@ -223,7 +223,7 @@ function computeCompilerOptionsPaths(tsConfig, dependencies) {
223
223
  }
224
224
  exports.computeCompilerOptionsPaths = computeCompilerOptionsPaths;
225
225
  function createTmpTsConfig(tsconfigPath, workspaceRoot, projectRoot, dependencies) {
226
- const tmpTsConfigPath = (0, path_1.join)(workspaceRoot, 'tmp', projectRoot, 'tsconfig.generated.json');
226
+ const tmpTsConfigPath = (0, path_1.join)(workspaceRoot, 'tmp', projectRoot, process.env.NX_TASK_TARGET_TARGET ?? 'build', 'tsconfig.generated.json');
227
227
  const parsedTSConfig = readTsConfigWithRemappedPaths(tsconfigPath, tmpTsConfigPath, dependencies);
228
228
  process.on('exit', () => cleanupTmpTsConfigFile(tmpTsConfigPath));
229
229
  (0, devkit_1.writeJsonFile)(tmpTsConfigPath, parsedTSConfig);
@@ -0,0 +1,25 @@
1
+ import { PackageJson } from 'nx/src/utils/package-json';
2
+ export declare function parseRegistryOptions(cwd: string, pkg: {
3
+ packageRoot: string;
4
+ packageJson: PackageJson;
5
+ }, options: {
6
+ registry?: string;
7
+ tag?: string;
8
+ }, logWarnFn?: (message: string) => void): Promise<{
9
+ registry: string;
10
+ tag: string;
11
+ registryConfigKey: string;
12
+ }>;
13
+ /**
14
+ * Returns the npm registry that is used for publishing.
15
+ *
16
+ * @param scope the scope of the package for which to determine the registry
17
+ * @param cwd the directory where the npm config should be read from
18
+ */
19
+ export declare function getNpmRegistry(cwd: string, scope?: string): Promise<string>;
20
+ /**
21
+ * Returns the npm tag that is used for publishing.
22
+ *
23
+ * @param cwd the directory where the npm config should be read from
24
+ */
25
+ export declare function getNpmTag(cwd: string): Promise<string>;
@@ -0,0 +1,90 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getNpmTag = exports.getNpmRegistry = exports.parseRegistryOptions = void 0;
4
+ const child_process_1 = require("child_process");
5
+ const fs_1 = require("fs");
6
+ const path_1 = require("path");
7
+ async function parseRegistryOptions(cwd, pkg, options, logWarnFn = console.warn) {
8
+ const npmRcPath = (0, path_1.join)(pkg.packageRoot, '.npmrc');
9
+ if ((0, fs_1.existsSync)(npmRcPath)) {
10
+ const relativeNpmRcPath = (0, path_1.relative)(cwd, npmRcPath);
11
+ logWarnFn(`\nIgnoring .npmrc file detected in the package root: ${relativeNpmRcPath}. Nested .npmrc files are not supported by npm. Only the .npmrc file at the root of the workspace will be used. To customize the registry or tag for specific packages, see https://nx.dev/recipes/nx-release/configure-custom-registries\n`);
12
+ }
13
+ const scope = pkg.packageJson.name.startsWith('@')
14
+ ? pkg.packageJson.name.split('/')[0]
15
+ : '';
16
+ // If the package is scoped, then the registry argument that will
17
+ // correctly override the registry in the .npmrc file must be scoped.
18
+ const registryConfigKey = scope ? `${scope}:registry` : 'registry';
19
+ const publishConfigRegistry = pkg.packageJson.publishConfig?.[registryConfigKey];
20
+ // Even though it won't override the actual registry that's actually used,
21
+ // the user might think otherwise, so we should still warn if the user has
22
+ // set a 'registry' in 'publishConfig' for a scoped package.
23
+ if (publishConfigRegistry || pkg.packageJson.publishConfig?.registry) {
24
+ const relativePackageJsonPath = (0, path_1.relative)(cwd, (0, path_1.join)(pkg.packageRoot, 'package.json'));
25
+ if (options.registry) {
26
+ logWarnFn(`\nRegistry detected in the 'publishConfig' of the package manifest: ${relativePackageJsonPath}. This will override your registry option set in the project configuration or passed via the --registry argument, which is why configuring the registry with 'publishConfig' is not recommended. For details, see https://nx.dev/recipes/nx-release/configure-custom-registries\n`);
27
+ }
28
+ else {
29
+ logWarnFn(`\nRegistry detected in the 'publishConfig' of the package manifest: ${relativePackageJsonPath}. Configuring the registry in this way is not recommended because it prevents the registry from being overridden in project configuration or via the --registry argument. To customize the registry for specific packages, see https://nx.dev/recipes/nx-release/configure-custom-registries\n`);
30
+ }
31
+ }
32
+ const registry =
33
+ // `npm publish` will always use the publishConfig registry if it exists, even over the --registry arg
34
+ publishConfigRegistry ||
35
+ options.registry ||
36
+ (await getNpmRegistry(cwd, scope));
37
+ const tag = options.tag || (await getNpmTag(cwd));
38
+ return { registry, tag, registryConfigKey };
39
+ }
40
+ exports.parseRegistryOptions = parseRegistryOptions;
41
+ /**
42
+ * Returns the npm registry that is used for publishing.
43
+ *
44
+ * @param scope the scope of the package for which to determine the registry
45
+ * @param cwd the directory where the npm config should be read from
46
+ */
47
+ async function getNpmRegistry(cwd, scope) {
48
+ let registry;
49
+ if (scope) {
50
+ registry = await getNpmConfigValue(`${scope}:registry`, cwd);
51
+ }
52
+ if (!registry) {
53
+ registry = await getNpmConfigValue('registry', cwd);
54
+ }
55
+ return registry;
56
+ }
57
+ exports.getNpmRegistry = getNpmRegistry;
58
+ /**
59
+ * Returns the npm tag that is used for publishing.
60
+ *
61
+ * @param cwd the directory where the npm config should be read from
62
+ */
63
+ async function getNpmTag(cwd) {
64
+ // npm does not support '@scope:tag' in the npm config, so we only need to check for 'tag'.
65
+ return getNpmConfigValue('tag', cwd);
66
+ }
67
+ exports.getNpmTag = getNpmTag;
68
+ async function getNpmConfigValue(key, cwd) {
69
+ try {
70
+ const result = await execAsync(`npm config get ${key}`, cwd);
71
+ return result === 'undefined' ? undefined : result;
72
+ }
73
+ catch (e) {
74
+ return Promise.resolve(undefined);
75
+ }
76
+ }
77
+ async function execAsync(command, cwd) {
78
+ // Must be non-blocking async to allow spinner to render
79
+ return new Promise((resolve, reject) => {
80
+ (0, child_process_1.exec)(command, { cwd }, (error, stdout, stderr) => {
81
+ if (error) {
82
+ return reject(error);
83
+ }
84
+ if (stderr) {
85
+ return reject(stderr);
86
+ }
87
+ return resolve(stdout.trim());
88
+ });
89
+ });
90
+ }