nx 18.0.0 → 18.0.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.
package/bin/init-local.js CHANGED
@@ -11,23 +11,6 @@ const Mod = require("module");
11
11
  * @param workspace Relevant local workspace properties
12
12
  */
13
13
  function initLocal(workspace) {
14
- // If module.register is not available, we need to restart the process with the experimental ESM loader.
15
- // Otherwise, usage of `registerTsProject` will not work for `.ts` files using ESM.
16
- // TODO: Remove this once Node 18 is out of LTS (March 2024).
17
- if (shouldRestartWithExperimentalTsEsmLoader()) {
18
- const child = require('child_process').fork(require.resolve('./nx'), process.argv.slice(2), {
19
- env: {
20
- ...process.env,
21
- RESTARTED_WITH_EXPERIMENTAL_TS_ESM_LOADER: '1',
22
- },
23
- execArgv: execArgvWithExperimentalLoaderOptions(),
24
- });
25
- child.on('close', (code) => {
26
- if (code !== 0 && code !== null)
27
- process.exit(code);
28
- });
29
- return;
30
- }
31
14
  process.env.NX_CLI_SET = 'true';
32
15
  try {
33
16
  perf_hooks_1.performance.mark('init-local');
@@ -136,7 +119,7 @@ function handleAngularCLIFallbacks(workspace) {
136
119
  if (!process.argv[3]) {
137
120
  console.log(`"ng completion" is not natively supported by Nx.
138
121
  Instead, you could try an Nx Editor Plugin for a visual tool to run Nx commands. If you're using VSCode, you can use the Nx Console plugin, or if you're using WebStorm, you could use one of the available community plugins.
139
- For more information, see https://nx.dev/core-features/integrate-with-editors`);
122
+ For more information, see https://nx.dev/features/integrate-with-editors`);
140
123
  }
141
124
  }
142
125
  else {
@@ -190,33 +173,3 @@ function monkeyPatchRequire() {
190
173
  // do some side-effect of your own
191
174
  };
192
175
  }
193
- function shouldRestartWithExperimentalTsEsmLoader() {
194
- // Already restarted with experimental loader
195
- if (process.env.RESTARTED_WITH_EXPERIMENTAL_TS_ESM_LOADER === '1')
196
- return false;
197
- const nodeVersion = parseInt(process.versions.node.split('.')[0]);
198
- // `--experimental-loader` is only supported in Nodejs >= 16 so there is no point restarting for older versions
199
- if (nodeVersion < 16)
200
- return false;
201
- // Node 20.6.0 adds `module.register`, otherwise we need to restart process with "--experimental-loader ts-node/esm".
202
- return (!require('node:module').register &&
203
- moduleResolves('ts-node/esm') &&
204
- moduleResolves('typescript'));
205
- }
206
- function execArgvWithExperimentalLoaderOptions() {
207
- return [
208
- ...process.execArgv,
209
- '--no-warnings',
210
- '--experimental-loader',
211
- 'ts-node/esm',
212
- ];
213
- }
214
- function moduleResolves(packageName) {
215
- try {
216
- require.resolve(packageName);
217
- return true;
218
- }
219
- catch {
220
- return false;
221
- }
222
- }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nx",
3
- "version": "18.0.0",
3
+ "version": "18.0.2",
4
4
  "private": false,
5
5
  "description": "The core Nx plugin contains the core functionality of Nx like the project graph, nx commands and task orchestration.",
6
6
  "repository": {
@@ -66,7 +66,7 @@
66
66
  "yargs-parser": "21.1.1",
67
67
  "node-machine-id": "1.1.12",
68
68
  "ora": "5.3.0",
69
- "@nrwl/tao": "18.0.0"
69
+ "@nrwl/tao": "18.0.2"
70
70
  },
71
71
  "peerDependencies": {
72
72
  "@swc-node/register": "^1.6.7",
@@ -81,16 +81,16 @@
81
81
  }
82
82
  },
83
83
  "optionalDependencies": {
84
- "@nx/nx-darwin-x64": "18.0.0",
85
- "@nx/nx-darwin-arm64": "18.0.0",
86
- "@nx/nx-linux-x64-gnu": "18.0.0",
87
- "@nx/nx-linux-x64-musl": "18.0.0",
88
- "@nx/nx-win32-x64-msvc": "18.0.0",
89
- "@nx/nx-linux-arm64-gnu": "18.0.0",
90
- "@nx/nx-linux-arm64-musl": "18.0.0",
91
- "@nx/nx-linux-arm-gnueabihf": "18.0.0",
92
- "@nx/nx-win32-arm64-msvc": "18.0.0",
93
- "@nx/nx-freebsd-x64": "18.0.0"
84
+ "@nx/nx-darwin-x64": "18.0.2",
85
+ "@nx/nx-darwin-arm64": "18.0.2",
86
+ "@nx/nx-linux-x64-gnu": "18.0.2",
87
+ "@nx/nx-linux-x64-musl": "18.0.2",
88
+ "@nx/nx-win32-x64-msvc": "18.0.2",
89
+ "@nx/nx-linux-arm64-gnu": "18.0.2",
90
+ "@nx/nx-linux-arm64-musl": "18.0.2",
91
+ "@nx/nx-linux-arm-gnueabihf": "18.0.2",
92
+ "@nx/nx-win32-arm64-msvc": "18.0.2",
93
+ "@nx/nx-freebsd-x64": "18.0.2"
94
94
  },
95
95
  "nx-migrations": {
96
96
  "migrations": "./migrations.json",
@@ -57,7 +57,7 @@ async function connectToNxCloudCommand() {
57
57
  exports.connectToNxCloudCommand = connectToNxCloudCommand;
58
58
  async function connectToNxCloudWithPrompt(command) {
59
59
  const setNxCloud = await nxCloudPrompt('setupNxCloud');
60
- const useCloud = setNxCloud ? await connectToNxCloudCommand() : false;
60
+ const useCloud = setNxCloud === 'yes' ? await connectToNxCloudCommand() : false;
61
61
  await (0, ab_testing_1.recordStat)({
62
62
  command,
63
63
  nxVersion: versions_1.nxVersion,
@@ -1,3 +1,4 @@
1
+ import { PackageJson } from '../../../utils/package-json';
1
2
  import { PackageManagerCommands } from '../../../utils/package-manager';
2
3
  export declare function createNxJsonFile(repoRoot: string, topologicalTargets: string[], cacheableOperations: string[], scriptOutputs: {
3
4
  [name: string]: string;
@@ -14,3 +15,4 @@ export declare function printFinalMessage({ learnMoreLink, bodyLines, }: {
14
15
  learnMoreLink?: string;
15
16
  bodyLines?: string[];
16
17
  }): void;
18
+ export declare function isMonorepo(packageJson: PackageJson): boolean;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.printFinalMessage = exports.markRootPackageJsonAsNxProject = exports.addVsCodeRecommendedExtensions = exports.initCloud = exports.runInstall = exports.updateGitIgnore = exports.addDepsToPackageJson = exports.createNxJsonFile = void 0;
3
+ exports.isMonorepo = exports.printFinalMessage = exports.markRootPackageJsonAsNxProject = exports.addVsCodeRecommendedExtensions = exports.initCloud = exports.runInstall = exports.updateGitIgnore = exports.addDepsToPackageJson = exports.createNxJsonFile = void 0;
4
4
  const child_process_1 = require("child_process");
5
5
  const path_1 = require("path");
6
6
  const child_process_2 = require("../../../utils/child-process");
@@ -174,3 +174,13 @@ function printFinalMessage({ learnMoreLink, bodyLines, }) {
174
174
  });
175
175
  }
176
176
  exports.printFinalMessage = printFinalMessage;
177
+ function isMonorepo(packageJson) {
178
+ if (!!packageJson.workspaces)
179
+ return true;
180
+ if ((0, fs_1.existsSync)('pnpm-workspace.yaml') || (0, fs_1.existsSync)('pnpm-workspace.yml'))
181
+ return true;
182
+ if ((0, fs_1.existsSync)('lerna.json'))
183
+ return true;
184
+ return false;
185
+ }
186
+ exports.isMonorepo = isMonorepo;
@@ -14,6 +14,7 @@ const react_1 = require("./implementation/react");
14
14
  const child_process_2 = require("../../utils/child-process");
15
15
  const fileutils_1 = require("../../utils/fileutils");
16
16
  const versions_1 = require("../../utils/versions");
17
+ const utils_1 = require("./implementation/utils");
17
18
  async function initHandler(options) {
18
19
  // strip the 'init' command itself so we don't forward it
19
20
  const args = process.argv.slice(3).join(' ');
@@ -35,7 +36,7 @@ async function initHandler(options) {
35
36
  else if (isNestCLI(packageJson)) {
36
37
  await (0, add_nx_to_nest_1.addNxToNest)(options, packageJson);
37
38
  }
38
- else if (isMonorepo(packageJson)) {
39
+ else if ((0, utils_1.isMonorepo)(packageJson)) {
39
40
  await (0, add_nx_to_monorepo_1.addNxToMonorepo)(options);
40
41
  }
41
42
  else {
@@ -96,15 +97,6 @@ function isNestCLI(packageJson) {
96
97
  combinedDependencies['@nestjs/core'] &&
97
98
  combinedDependencies['@nestjs/cli']);
98
99
  }
99
- function isMonorepo(packageJson) {
100
- if (!!packageJson.workspaces)
101
- return true;
102
- if ((0, fs_1.existsSync)('pnpm-workspace.yaml') || (0, fs_1.existsSync)('pnpm-workspace.yml'))
103
- return true;
104
- if ((0, fs_1.existsSync)('lerna.json'))
105
- return true;
106
- return false;
107
- }
108
100
  function setupDotNxInstallation(version) {
109
101
  if (process.platform !== 'win32') {
110
102
  console.log('Setting Nx up installation in `.nx`. You can run nx commands like: `./nx --help`');
@@ -16,6 +16,7 @@ const angular_1 = require("./implementation/angular");
16
16
  const workspace_context_1 = require("../../utils/workspace-context");
17
17
  const connect_to_nx_cloud_1 = require("../connect/connect-to-nx-cloud");
18
18
  const add_nx_to_npm_repo_1 = require("./implementation/add-nx-to-npm-repo");
19
+ const add_nx_to_monorepo_1 = require("./implementation/add-nx-to-monorepo");
19
20
  async function initHandler(options) {
20
21
  const version = process.env.NX_VERSION ?? ((0, semver_1.prerelease)(versions_1.nxVersion) ? 'next' : 'latest');
21
22
  if (process.env.NX_VERSION) {
@@ -41,24 +42,27 @@ async function initHandler(options) {
41
42
  });
42
43
  return;
43
44
  }
44
- const repoRoot = process.cwd();
45
- const cacheableOperations = [];
46
- (0, utils_1.createNxJsonFile)(repoRoot, [], cacheableOperations, {});
47
- const pmc = (0, package_manager_1.getPackageManagerCommand)();
48
- (0, utils_1.updateGitIgnore)(repoRoot);
49
45
  const detectPluginsResponse = await detectPlugins();
50
46
  if (!detectPluginsResponse?.plugins.length) {
51
47
  // If no plugins are detected/chosen, guide users to setup
52
48
  // their targetDefaults correctly so their package scripts will work.
53
- await (0, add_nx_to_npm_repo_1.addNxToNpmRepo)({
54
- interactive: options.interactive,
55
- });
49
+ const packageJson = (0, fileutils_1.readJsonFile)('package.json');
50
+ if ((0, utils_1.isMonorepo)(packageJson)) {
51
+ await (0, add_nx_to_monorepo_1.addNxToMonorepo)({ interactive: options.interactive });
52
+ }
53
+ else {
54
+ await (0, add_nx_to_npm_repo_1.addNxToNpmRepo)({ interactive: options.interactive });
55
+ }
56
56
  }
57
57
  else {
58
58
  const useNxCloud = options.nxCloud ??
59
59
  (options.interactive
60
60
  ? await (0, connect_to_nx_cloud_1.connectExistingRepoToNxCloudPrompt)()
61
61
  : false);
62
+ const repoRoot = process.cwd();
63
+ const pmc = (0, package_manager_1.getPackageManagerCommand)();
64
+ (0, utils_1.createNxJsonFile)(repoRoot, [], [], {});
65
+ (0, utils_1.updateGitIgnore)(repoRoot);
62
66
  (0, utils_1.addDepsToPackageJson)(repoRoot, detectPluginsResponse?.plugins ?? []);
63
67
  output_1.output.log({ title: '📦 Installing Nx' });
64
68
  (0, utils_1.runInstall)(repoRoot, pmc);
@@ -801,7 +801,7 @@ async function generateMigrationsJsonAndUpdatePackageJson(root, opts) {
801
801
  `- To learn more go to https://nx.dev/recipes/tips-n-tricks/advanced-update`,
802
802
  ]
803
803
  : [
804
- `- To learn more go to https://nx.dev/core-features/automate-updating-dependencies`,
804
+ `- To learn more go to https://nx.dev/features/automate-updating-dependencies`,
805
805
  ]),
806
806
  ...(showConnectToCloudMessage()
807
807
  ? [