nx 18.0.1 → 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');
@@ -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.1",
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.1"
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.1",
85
- "@nx/nx-darwin-arm64": "18.0.1",
86
- "@nx/nx-linux-x64-gnu": "18.0.1",
87
- "@nx/nx-linux-x64-musl": "18.0.1",
88
- "@nx/nx-win32-x64-msvc": "18.0.1",
89
- "@nx/nx-linux-arm64-gnu": "18.0.1",
90
- "@nx/nx-linux-arm64-musl": "18.0.1",
91
- "@nx/nx-linux-arm-gnueabihf": "18.0.1",
92
- "@nx/nx-win32-arm64-msvc": "18.0.1",
93
- "@nx/nx-freebsd-x64": "18.0.1"
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",
@@ -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);
@@ -1,4 +1,6 @@
1
+ import { ProjectConfiguration } from '../../config/workspace-json-project-json';
1
2
  import { NxPluginV2 } from '../../utils/nx-plugin';
3
+ import { PackageJson } from '../../utils/package-json';
2
4
  /**
3
5
  * This symbol marks that a target provides information which should modify a target already registered
4
6
  * on the project via other plugins. If the target has not already been registered, and this symbol is true,
@@ -6,3 +8,49 @@ import { NxPluginV2 } from '../../utils/nx-plugin';
6
8
  */
7
9
  export declare const ONLY_MODIFIES_EXISTING_TARGET: unique symbol;
8
10
  export declare const TargetDefaultsPlugin: NxPluginV2;
11
+ /**
12
+ * This fn gets target info that would make a target uniquely compatible
13
+ * with what is described by project.json or package.json. As the merge process
14
+ * for config happens, without this, the target defaults may be compatible
15
+ * with a config from a plugin and then that combined target be incompatible
16
+ * with the project json configuration resulting in the target default values
17
+ * being scrapped. By adding enough information from the project.json / package.json,
18
+ * we can make sure that the target after merging is compatible with the defined target.
19
+ */
20
+ export declare function getTargetInfo(target: string, projectJson: Pick<ProjectConfiguration, 'targets'>, packageJson: Pick<PackageJson, 'scripts' | 'nx'>): {
21
+ command: string;
22
+ executor?: undefined;
23
+ options?: undefined;
24
+ } | {
25
+ executor: string;
26
+ options: {
27
+ command: any;
28
+ commands?: undefined;
29
+ script?: undefined;
30
+ };
31
+ command?: undefined;
32
+ } | {
33
+ executor: string;
34
+ options: {
35
+ commands: any;
36
+ command?: undefined;
37
+ script?: undefined;
38
+ };
39
+ command?: undefined;
40
+ } | {
41
+ executor: string;
42
+ command?: undefined;
43
+ options?: undefined;
44
+ } | {
45
+ executor: string;
46
+ options: {
47
+ script: any;
48
+ command?: undefined;
49
+ commands?: undefined;
50
+ };
51
+ command?: undefined;
52
+ } | {
53
+ command?: undefined;
54
+ executor?: undefined;
55
+ options?: undefined;
56
+ };
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TargetDefaultsPlugin = exports.ONLY_MODIFIES_EXISTING_TARGET = void 0;
3
+ exports.getTargetInfo = exports.TargetDefaultsPlugin = exports.ONLY_MODIFIES_EXISTING_TARGET = void 0;
4
4
  const minimatch_1 = require("minimatch");
5
5
  const node_fs_1 = require("node:fs");
6
6
  const node_path_1 = require("node:path");
@@ -57,7 +57,11 @@ exports.TargetDefaultsPlugin = {
57
57
  // Prevents `build` from overwriting `@nx/js:tsc` if both are present
58
58
  // and build is specified later in the ordering.
59
59
  if (!modifiedTargets[targetName] || targetName !== defaultSpecifier) {
60
- modifiedTargets[targetName] = JSON.parse(JSON.stringify(targetDefaults[defaultSpecifier]));
60
+ const defaults = JSON.parse(JSON.stringify(targetDefaults[defaultSpecifier]));
61
+ modifiedTargets[targetName] = {
62
+ ...getTargetInfo(targetName, projectJson, packageJson),
63
+ ...defaults,
64
+ };
61
65
  }
62
66
  // TODO: Remove this after we figure out a way to define new targets
63
67
  // in target defaults
@@ -101,3 +105,74 @@ function readJsonOrNull(path) {
101
105
  return null;
102
106
  }
103
107
  }
108
+ /**
109
+ * This fn gets target info that would make a target uniquely compatible
110
+ * with what is described by project.json or package.json. As the merge process
111
+ * for config happens, without this, the target defaults may be compatible
112
+ * with a config from a plugin and then that combined target be incompatible
113
+ * with the project json configuration resulting in the target default values
114
+ * being scrapped. By adding enough information from the project.json / package.json,
115
+ * we can make sure that the target after merging is compatible with the defined target.
116
+ */
117
+ function getTargetInfo(target, projectJson, packageJson) {
118
+ const projectJsonTarget = projectJson?.targets?.[target];
119
+ const packageJsonTarget = packageJson?.nx?.targets?.[target];
120
+ const executor = getTargetExecutor(target, projectJson, packageJson);
121
+ const targetOptions = {
122
+ ...packageJsonTarget?.options,
123
+ ...projectJsonTarget?.options,
124
+ };
125
+ if (projectJsonTarget?.command) {
126
+ return {
127
+ command: projectJsonTarget?.command,
128
+ };
129
+ }
130
+ if (executor === 'nx:run-commands') {
131
+ if (targetOptions?.command) {
132
+ return {
133
+ executor: 'nx:run-commands',
134
+ options: {
135
+ command: projectJsonTarget.options?.command,
136
+ },
137
+ };
138
+ }
139
+ else if (targetOptions?.commands) {
140
+ return {
141
+ executor: 'nx:run-commands',
142
+ options: {
143
+ commands: targetOptions.commands,
144
+ },
145
+ };
146
+ }
147
+ return {
148
+ executor: 'nx:run-commands',
149
+ };
150
+ }
151
+ if (executor === 'nx:run-script') {
152
+ return {
153
+ executor: 'nx:run-script',
154
+ options: {
155
+ script: targetOptions?.script ?? target,
156
+ },
157
+ };
158
+ }
159
+ if (executor) {
160
+ return { executor };
161
+ }
162
+ return {};
163
+ }
164
+ exports.getTargetInfo = getTargetInfo;
165
+ function getTargetExecutor(target, projectJson, packageJson) {
166
+ const projectJsonTarget = projectJson?.targets?.[target];
167
+ const packageJsonTarget = packageJson?.nx?.targets?.[target];
168
+ const packageJsonScript = packageJson?.scripts?.[target];
169
+ if (projectJsonTarget?.command) {
170
+ return 'nx:run-commands';
171
+ }
172
+ if (!projectJsonTarget?.executor &&
173
+ !packageJsonTarget?.executor &&
174
+ packageJsonScript) {
175
+ return 'nx:run-script';
176
+ }
177
+ return projectJsonTarget?.executor ?? packageJsonTarget?.executor;
178
+ }