nx 18.2.0-canary.20240322-61cb63d → 18.2.0-canary.20240323-54d4780

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/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  (The MIT License)
2
2
 
3
- Copyright (c) 2017-2023 Narwhal Technologies Inc.
3
+ Copyright (c) 2017-2024 Narwhal Technologies Inc.
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining
6
6
  a copy of this software and associated documentation files (the
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nx",
3
- "version": "18.2.0-canary.20240322-61cb63d",
3
+ "version": "18.2.0-canary.20240323-54d4780",
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.2.0-canary.20240322-61cb63d"
69
+ "@nrwl/tao": "18.2.0-canary.20240323-54d4780"
70
70
  },
71
71
  "peerDependencies": {
72
72
  "@swc-node/register": "^1.8.0",
@@ -81,16 +81,16 @@
81
81
  }
82
82
  },
83
83
  "optionalDependencies": {
84
- "@nx/nx-darwin-x64": "18.2.0-canary.20240322-61cb63d",
85
- "@nx/nx-darwin-arm64": "18.2.0-canary.20240322-61cb63d",
86
- "@nx/nx-linux-x64-gnu": "18.2.0-canary.20240322-61cb63d",
87
- "@nx/nx-linux-x64-musl": "18.2.0-canary.20240322-61cb63d",
88
- "@nx/nx-win32-x64-msvc": "18.2.0-canary.20240322-61cb63d",
89
- "@nx/nx-linux-arm64-gnu": "18.2.0-canary.20240322-61cb63d",
90
- "@nx/nx-linux-arm64-musl": "18.2.0-canary.20240322-61cb63d",
91
- "@nx/nx-linux-arm-gnueabihf": "18.2.0-canary.20240322-61cb63d",
92
- "@nx/nx-win32-arm64-msvc": "18.2.0-canary.20240322-61cb63d",
93
- "@nx/nx-freebsd-x64": "18.2.0-canary.20240322-61cb63d"
84
+ "@nx/nx-darwin-x64": "18.2.0-canary.20240323-54d4780",
85
+ "@nx/nx-darwin-arm64": "18.2.0-canary.20240323-54d4780",
86
+ "@nx/nx-linux-x64-gnu": "18.2.0-canary.20240323-54d4780",
87
+ "@nx/nx-linux-x64-musl": "18.2.0-canary.20240323-54d4780",
88
+ "@nx/nx-win32-x64-msvc": "18.2.0-canary.20240323-54d4780",
89
+ "@nx/nx-linux-arm64-gnu": "18.2.0-canary.20240323-54d4780",
90
+ "@nx/nx-linux-arm64-musl": "18.2.0-canary.20240323-54d4780",
91
+ "@nx/nx-linux-arm-gnueabihf": "18.2.0-canary.20240323-54d4780",
92
+ "@nx/nx-win32-arm64-msvc": "18.2.0-canary.20240323-54d4780",
93
+ "@nx/nx-freebsd-x64": "18.2.0-canary.20240323-54d4780"
94
94
  },
95
95
  "nx-migrations": {
96
96
  "migrations": "./migrations.json",
@@ -270,7 +270,9 @@
270
270
  {
271
271
  "type": "array",
272
272
  "description": "The projects that the targets belong to.",
273
- "items": { "type": "string" }
273
+ "items": {
274
+ "type": "string"
275
+ }
274
276
  }
275
277
  ]
276
278
  },
@@ -294,8 +296,12 @@
294
296
  "required": ["input"],
295
297
  "not": {
296
298
  "anyOf": [
297
- { "required": ["projects"] },
298
- { "required": ["dependencies"] }
299
+ {
300
+ "required": ["projects"]
301
+ },
302
+ {
303
+ "required": ["dependencies"]
304
+ }
299
305
  ]
300
306
  }
301
307
  }
@@ -327,7 +333,9 @@
327
333
  "properties": {
328
334
  "externalDependencies": {
329
335
  "type": "array",
330
- "items": { "type": "string" },
336
+ "items": {
337
+ "type": "string"
338
+ },
331
339
  "description": "The list of external dependencies that our target depends on for `nx:run-commands` and community plugins."
332
340
  }
333
341
  },
@@ -495,8 +503,12 @@
495
503
  "required": ["target"],
496
504
  "not": {
497
505
  "anyOf": [
498
- { "required": ["projects"] },
499
- { "required": ["dependencies"] }
506
+ {
507
+ "required": ["projects"]
508
+ },
509
+ {
510
+ "required": ["dependencies"]
511
+ }
500
512
  ]
501
513
  }
502
514
  }
@@ -529,6 +541,20 @@
529
541
  "options": {
530
542
  "type": "object",
531
543
  "description": "The options passed to the plugin when creating nodes and dependencies"
544
+ },
545
+ "include": {
546
+ "type": "array",
547
+ "description": "File patterns which are included by the plugin",
548
+ "items": {
549
+ "type": "string"
550
+ }
551
+ },
552
+ "exclude": {
553
+ "type": "array",
554
+ "description": "File patterns which are excluded by the plugin",
555
+ "items": {
556
+ "type": "string"
557
+ }
532
558
  }
533
559
  }
534
560
  }
@@ -55,7 +55,7 @@ async function installPackage(pkgName, version) {
55
55
  nxJson.installation.plugins[pkgName] = version;
56
56
  (0, fileutils_1.writeJsonFile)('nx.json', nxJson);
57
57
  try {
58
- await (0, child_process_2.runNxAsync)('--help');
58
+ await (0, child_process_2.runNxAsync)('--help', { silent: true });
59
59
  }
60
60
  catch (e) {
61
61
  // revert adding the plugin to nx.json
@@ -51,8 +51,8 @@ async function initHandler(options) {
51
51
  return;
52
52
  }
53
53
  output_1.output.log({ title: '🧐 Checking dependencies' });
54
- const detectPluginsResponse = await detectPlugins();
55
- if (!detectPluginsResponse?.plugins.length) {
54
+ const { plugins, updatePackageScripts } = await detectPlugins();
55
+ if (!plugins.length) {
56
56
  // If no plugins are detected/chosen, guide users to setup
57
57
  // their targetDefaults correctly so their package scripts will work.
58
58
  const packageJson = (0, fileutils_1.readJsonFile)('package.json');
@@ -72,19 +72,17 @@ async function initHandler(options) {
72
72
  const pmc = (0, package_manager_1.getPackageManagerCommand)();
73
73
  (0, utils_1.createNxJsonFile)(repoRoot, [], [], {});
74
74
  (0, utils_1.updateGitIgnore)(repoRoot);
75
- (0, utils_1.addDepsToPackageJson)(repoRoot, detectPluginsResponse.plugins);
75
+ (0, utils_1.addDepsToPackageJson)(repoRoot, plugins);
76
76
  output_1.output.log({ title: '📦 Installing Nx' });
77
77
  (0, utils_1.runInstall)(repoRoot, pmc);
78
78
  output_1.output.log({ title: '🔨 Configuring plugins' });
79
- for (const plugin of detectPluginsResponse.plugins) {
80
- (0, child_process_2.execSync)(`${pmc.exec} nx g ${plugin}:init --keepExistingVersions ${detectPluginsResponse.updatePackageScripts
81
- ? '--updatePackageScripts'
82
- : ''} --no-interactive`, {
79
+ for (const plugin of plugins) {
80
+ (0, child_process_2.execSync)(`${pmc.exec} nx g ${plugin}:init --keepExistingVersions ${updatePackageScripts ? '--updatePackageScripts' : ''} --no-interactive`, {
83
81
  stdio: [0, 1, 2],
84
82
  cwd: repoRoot,
85
83
  });
86
84
  }
87
- if (!detectPluginsResponse.updatePackageScripts) {
85
+ if (!updatePackageScripts) {
88
86
  const rootPackageJsonPath = (0, path_1.join)(repoRoot, 'package.json');
89
87
  const json = (0, fileutils_1.readJsonFile)(rootPackageJsonPath);
90
88
  json.nx = { includedScripts: [] };
@@ -156,8 +154,12 @@ async function detectPlugins() {
156
154
  detectedPlugins.add('@nx/gradle');
157
155
  }
158
156
  const plugins = Array.from(detectedPlugins);
159
- if (plugins.length === 0)
160
- return undefined;
157
+ if (plugins.length === 0) {
158
+ return {
159
+ plugins: [],
160
+ updatePackageScripts: false,
161
+ };
162
+ }
161
163
  output_1.output.log({
162
164
  title: `Recommended Plugins:`,
163
165
  bodyLines: [
@@ -174,7 +176,10 @@ async function detectPlugins() {
174
176
  },
175
177
  ]).then((r) => r.plugins);
176
178
  if (pluginsToInstall?.length === 0)
177
- return undefined;
179
+ return {
180
+ plugins: [],
181
+ updatePackageScripts: false,
182
+ };
178
183
  const updatePackageScripts = (0, fs_1.existsSync)('package.json') &&
179
184
  (await (0, enquirer_1.prompt)([
180
185
  {
@@ -397,6 +397,8 @@ export interface NxJsonConfiguration<T = '*' | string[]> {
397
397
  export type PluginConfiguration = string | {
398
398
  plugin: string;
399
399
  options?: unknown;
400
+ include?: string[];
401
+ exclude?: string[];
400
402
  };
401
403
  export declare function readNxJson(root?: string): NxJsonConfiguration;
402
404
  export declare function hasNxJson(root: string): boolean;
@@ -220,14 +220,31 @@ plugins) {
220
220
  const results = [];
221
221
  const errors = [];
222
222
  // We iterate over plugins first - this ensures that plugins specified first take precedence.
223
- for (const { plugin, options } of plugins) {
223
+ for (const { plugin, options, include, exclude } of plugins) {
224
224
  const [pattern, createNodes] = plugin.createNodes ?? [];
225
225
  const pluginResults = [];
226
226
  perf_hooks_1.performance.mark(`${plugin.name}:createNodes - start`);
227
227
  if (!pattern) {
228
228
  continue;
229
229
  }
230
- const matchingConfigFiles = workspaceFiles.filter(minimatch_1.minimatch.filter(pattern, { dot: true }));
230
+ const matchingConfigFiles = [];
231
+ for (const file of workspaceFiles) {
232
+ if ((0, minimatch_1.minimatch)(file, pattern, { dot: true })) {
233
+ if (include) {
234
+ const included = include.some((includedPattern) => (0, minimatch_1.minimatch)(file, includedPattern, { dot: true }));
235
+ if (!included) {
236
+ continue;
237
+ }
238
+ }
239
+ if (exclude) {
240
+ const excluded = include.some((excludedPattern) => (0, minimatch_1.minimatch)(file, excludedPattern, { dot: true }));
241
+ if (excluded) {
242
+ continue;
243
+ }
244
+ }
245
+ matchingConfigFiles.push(file);
246
+ }
247
+ }
231
248
  for (const file of matchingConfigFiles) {
232
249
  perf_hooks_1.performance.mark(`${plugin.name}:createNodes:${file} - start`);
233
250
  try {
@@ -9,12 +9,12 @@ import { LoadedNxPlugin } from '../../utils/nx-plugin';
9
9
  * @param nxJson
10
10
  */
11
11
  export declare function retrieveWorkspaceFiles(workspaceRoot: string, projectRootMap: Record<string, string>): Promise<{
12
- allWorkspaceFiles: import("nx/src/devkit-exports").FileData[];
12
+ allWorkspaceFiles: import("../file-utils").FileData[];
13
13
  fileMap: {
14
14
  projectFileMap: ProjectFiles;
15
- nonProjectFiles: import("nx/src/native").FileData[];
15
+ nonProjectFiles: import("../../native").FileData[];
16
16
  };
17
- rustReferences: import("nx/src/native").NxWorkspaceFilesExternals;
17
+ rustReferences: import("../../native").NxWorkspaceFilesExternals;
18
18
  }>;
19
19
  /**
20
20
  * Walk through the workspace and return `ProjectConfigurations`. Only use this if the projectFileMap is not needed.
@@ -215,18 +215,21 @@ class Cache {
215
215
  }
216
216
  tryAndRetry(fn) {
217
217
  let attempts = 0;
218
- const baseTimeout = 100;
218
+ const baseTimeout = 5;
219
+ // Generate a random number between 2 and 4 to raise to the power of attempts
220
+ const baseExponent = Math.random() * 2 + 2;
219
221
  const _try = async () => {
220
222
  try {
221
223
  attempts++;
222
224
  return await fn();
223
225
  }
224
226
  catch (e) {
225
- if (attempts === 10) {
227
+ // Max time is 5 * 4^3 = 20480ms
228
+ if (attempts === 6) {
226
229
  // After enough attempts, throw the error
227
230
  throw e;
228
231
  }
229
- await new Promise((res) => setTimeout(res, baseTimeout * attempts));
232
+ await new Promise((res) => setTimeout(res, baseExponent ** attempts));
230
233
  return await _try();
231
234
  }
232
235
  };
@@ -91,6 +91,8 @@ export type NxPlugin = NxPluginV1 | NxPluginV2;
91
91
  export type LoadedNxPlugin = {
92
92
  plugin: NxPluginV2 & Pick<NxPluginV1, 'processProjectGraph'>;
93
93
  options?: unknown;
94
+ include?: string[];
95
+ exclude?: string[];
94
96
  };
95
97
  export declare const nxPluginCache: Map<string, LoadedNxPlugin['plugin']>;
96
98
  export declare function getPluginPathAndName(moduleName: string, paths: string[], projects: Record<string, ProjectConfiguration>, root: string): {
@@ -71,8 +71,19 @@ async function loadNxPluginAsync(pluginConfiguration, paths, projects, root) {
71
71
  ? pluginConfiguration
72
72
  : { plugin: pluginConfiguration, options: undefined };
73
73
  let pluginModule = exports.nxPluginCache.get(moduleName);
74
+ const include = typeof pluginConfiguration === 'object'
75
+ ? pluginConfiguration.include
76
+ : undefined;
77
+ const exclude = typeof pluginConfiguration === 'object'
78
+ ? pluginConfiguration.exclude
79
+ : undefined;
74
80
  if (pluginModule) {
75
- return { plugin: pluginModule, options };
81
+ return {
82
+ plugin: pluginModule,
83
+ options,
84
+ include,
85
+ exclude,
86
+ };
76
87
  }
77
88
  performance.mark(`Load Nx Plugin: ${moduleName} - start`);
78
89
  let { pluginPath, name } = await getPluginPathAndName(moduleName, paths, projects, root);
@@ -81,7 +92,12 @@ async function loadNxPluginAsync(pluginConfiguration, paths, projects, root) {
81
92
  exports.nxPluginCache.set(moduleName, plugin);
82
93
  performance.mark(`Load Nx Plugin: ${moduleName} - end`);
83
94
  performance.measure(`Load Nx Plugin: ${moduleName}`, `Load Nx Plugin: ${moduleName} - start`, `Load Nx Plugin: ${moduleName} - end`);
84
- return { plugin, options };
95
+ return {
96
+ plugin,
97
+ options,
98
+ include,
99
+ exclude,
100
+ };
85
101
  }
86
102
  exports.loadNxPluginAsync = loadNxPluginAsync;
87
103
  async function loadNxPlugins(plugins, paths = (0, installation_directory_1.getNxRequirePaths)(), root = workspace_root_1.workspaceRoot, projects) {