nx 19.7.0-canary.20240828-13170da → 19.7.0-canary.20240829-0ef6892

Sign up to get free protection for your applications and to get access to all the features.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nx",
3
- "version": "19.7.0-canary.20240828-13170da",
3
+ "version": "19.7.0-canary.20240829-0ef6892",
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": {
@@ -71,7 +71,7 @@
71
71
  "yargs-parser": "21.1.1",
72
72
  "node-machine-id": "1.1.12",
73
73
  "ora": "5.3.0",
74
- "@nrwl/tao": "19.7.0-canary.20240828-13170da"
74
+ "@nrwl/tao": "19.7.0-canary.20240829-0ef6892"
75
75
  },
76
76
  "peerDependencies": {
77
77
  "@swc-node/register": "^1.8.0",
@@ -86,16 +86,16 @@
86
86
  }
87
87
  },
88
88
  "optionalDependencies": {
89
- "@nx/nx-darwin-x64": "19.7.0-canary.20240828-13170da",
90
- "@nx/nx-darwin-arm64": "19.7.0-canary.20240828-13170da",
91
- "@nx/nx-linux-x64-gnu": "19.7.0-canary.20240828-13170da",
92
- "@nx/nx-linux-x64-musl": "19.7.0-canary.20240828-13170da",
93
- "@nx/nx-win32-x64-msvc": "19.7.0-canary.20240828-13170da",
94
- "@nx/nx-linux-arm64-gnu": "19.7.0-canary.20240828-13170da",
95
- "@nx/nx-linux-arm64-musl": "19.7.0-canary.20240828-13170da",
96
- "@nx/nx-linux-arm-gnueabihf": "19.7.0-canary.20240828-13170da",
97
- "@nx/nx-win32-arm64-msvc": "19.7.0-canary.20240828-13170da",
98
- "@nx/nx-freebsd-x64": "19.7.0-canary.20240828-13170da"
89
+ "@nx/nx-darwin-x64": "19.7.0-canary.20240829-0ef6892",
90
+ "@nx/nx-darwin-arm64": "19.7.0-canary.20240829-0ef6892",
91
+ "@nx/nx-linux-x64-gnu": "19.7.0-canary.20240829-0ef6892",
92
+ "@nx/nx-linux-x64-musl": "19.7.0-canary.20240829-0ef6892",
93
+ "@nx/nx-win32-x64-msvc": "19.7.0-canary.20240829-0ef6892",
94
+ "@nx/nx-linux-arm64-gnu": "19.7.0-canary.20240829-0ef6892",
95
+ "@nx/nx-linux-arm64-musl": "19.7.0-canary.20240829-0ef6892",
96
+ "@nx/nx-linux-arm-gnueabihf": "19.7.0-canary.20240829-0ef6892",
97
+ "@nx/nx-win32-arm64-msvc": "19.7.0-canary.20240829-0ef6892",
98
+ "@nx/nx-freebsd-x64": "19.7.0-canary.20240829-0ef6892"
99
99
  },
100
100
  "nx-migrations": {
101
101
  "migrations": "./migrations.json",
@@ -282,6 +282,13 @@
282
282
  "applyChanges": {
283
283
  "type": "boolean",
284
284
  "description": "Whether to automatically apply sync generator changes when running tasks. If not set, the user will be prompted. If set to `true`, the user will not be prompted and the changes will be applied. If set to `false`, the user will not be prompted and the changes will not be applied."
285
+ },
286
+ "disabledTaskSyncGenerators": {
287
+ "type": "array",
288
+ "items": {
289
+ "type": "string"
290
+ },
291
+ "description": "List of registered task sync generators to disable."
285
292
  }
286
293
  },
287
294
  "additionalProperties": false
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.syncHandler = syncHandler;
4
4
  const ora = require("ora");
5
+ const nx_json_1 = require("../../config/nx-json");
5
6
  const project_graph_1 = require("../../project-graph/project-graph");
6
7
  const output_1 = require("../../utils/output");
7
8
  const params_1 = require("../../utils/params");
@@ -10,7 +11,17 @@ const chalk = require("chalk");
10
11
  function syncHandler(options) {
11
12
  return (0, params_1.handleErrors)(options.verbose, async () => {
12
13
  const projectGraph = await (0, project_graph_1.createProjectGraphAsync)();
13
- const syncGenerators = await (0, sync_generators_1.collectAllRegisteredSyncGenerators)(projectGraph);
14
+ const nxJson = (0, nx_json_1.readNxJson)();
15
+ const syncGenerators = await (0, sync_generators_1.collectAllRegisteredSyncGenerators)(projectGraph, nxJson);
16
+ if (!syncGenerators.length) {
17
+ output_1.output.success({
18
+ title: options.check
19
+ ? 'The workspace is up to date'
20
+ : 'The workspace is already up to date',
21
+ bodyLines: ['There are no sync generators to run.'],
22
+ });
23
+ return 0;
24
+ }
14
25
  const results = await (0, sync_generators_1.getSyncGeneratorChanges)(syncGenerators);
15
26
  if (!results.length) {
16
27
  output_1.output.success({
@@ -286,11 +286,15 @@ export interface NxSyncConfiguration {
286
286
  };
287
287
  /**
288
288
  * Whether to automatically apply sync generator changes when running tasks.
289
- * If not set, the user will be prompted.
289
+ * If not set, the user will be prompted in interactive mode.
290
290
  * If set to `true`, the user will not be prompted and the changes will be applied.
291
291
  * If set to `false`, the user will not be prompted and the changes will not be applied.
292
292
  */
293
293
  applyChanges?: boolean;
294
+ /**
295
+ * List of registered task sync generators to disable.
296
+ */
297
+ disabledTaskSyncGenerators?: string[];
294
298
  }
295
299
  /**
296
300
  * Nx.json configuration
@@ -21,6 +21,7 @@ let registeredSyncGenerators;
21
21
  let scheduledTimeoutId;
22
22
  let storedProjectGraphHash;
23
23
  let storedNxJsonHash;
24
+ let storedDisabledTaskSyncGeneratorsHash;
24
25
  const log = (...messageParts) => {
25
26
  logger_1.serverLogger.log('[SYNC]:', ...messageParts);
26
27
  };
@@ -107,6 +108,10 @@ function collectAndScheduleSyncGenerators(projectGraph) {
107
108
  // a change imply we need to re-run all the generators
108
109
  // make sure to schedule all the collected generators
109
110
  scheduledGenerators.clear();
111
+ if (!registeredSyncGenerators.size) {
112
+ // there are no generators to run
113
+ return;
114
+ }
110
115
  for (const generator of registeredSyncGenerators) {
111
116
  scheduledGenerators.add(generator);
112
117
  }
@@ -144,16 +149,19 @@ async function getCachedRegisteredSyncGenerators() {
144
149
  return [...registeredSyncGenerators];
145
150
  }
146
151
  function collectAllRegisteredSyncGenerators(projectGraph) {
152
+ const nxJson = (0, nx_json_1.readNxJson)();
147
153
  const projectGraphHash = hashProjectGraph(projectGraph);
148
- if (storedProjectGraphHash !== projectGraphHash) {
154
+ const disabledTaskSyncGeneratorsHash = (0, file_hasher_1.hashArray)(nxJson.sync?.disabledTaskSyncGenerators?.sort() ?? []);
155
+ if (projectGraphHash !== storedProjectGraphHash ||
156
+ disabledTaskSyncGeneratorsHash !== storedDisabledTaskSyncGeneratorsHash) {
149
157
  storedProjectGraphHash = projectGraphHash;
158
+ storedDisabledTaskSyncGeneratorsHash = disabledTaskSyncGeneratorsHash;
150
159
  registeredTaskSyncGenerators =
151
- (0, sync_generators_1.collectRegisteredTaskSyncGenerators)(projectGraph);
160
+ (0, sync_generators_1.collectEnabledTaskSyncGeneratorsFromProjectGraph)(projectGraph, nxJson);
152
161
  }
153
162
  else {
154
163
  log('project graph hash is the same, not collecting task sync generators');
155
164
  }
156
- const nxJson = (0, nx_json_1.readNxJson)();
157
165
  const nxJsonHash = (0, file_hasher_1.hashArray)(nxJson.sync?.globalGenerators?.sort() ?? []);
158
166
  if (storedNxJsonHash !== nxJsonHash) {
159
167
  storedNxJsonHash = nxJsonHash;
Binary file
@@ -42,18 +42,6 @@ function getNxInitDate() {
42
42
  return null;
43
43
  }
44
44
  }
45
- async function createNxCloudWorkspaceV1(workspaceName, installationSource, nxInitDate) {
46
- const apiUrl = (0, get_cloud_options_1.getCloudUrl)();
47
- const response = await require('axios').post(`${apiUrl}/nx-cloud/create-org-and-workspace`, {
48
- workspaceName,
49
- installationSource,
50
- nxInitDate,
51
- });
52
- if (response.data.message) {
53
- throw new Error(response.data.message);
54
- }
55
- return response.data;
56
- }
57
45
  async function createNxCloudWorkspaceV2(workspaceName, installationSource, nxInitDate) {
58
46
  const apiUrl = (0, get_cloud_options_1.getCloudUrl)();
59
47
  const response = await require('axios').post(`${apiUrl}/nx-cloud/v2/create-org-and-workspace`, {
@@ -81,19 +69,6 @@ async function printSuccessMessage(token, installationSource, usesGithub) {
81
69
  });
82
70
  return connectCloudUrl;
83
71
  }
84
- function addNxCloudOptionsToNxJson(tree, token, directory = '') {
85
- const nxJsonPath = (0, path_1.join)(directory, 'nx.json');
86
- if (tree.exists(nxJsonPath)) {
87
- (0, json_1.updateJson)(tree, (0, path_1.join)(directory, 'nx.json'), (nxJson) => {
88
- const overrideUrl = process.env.NX_CLOUD_API || process.env.NRWL_API;
89
- if (overrideUrl) {
90
- nxJson.nxCloudUrl = overrideUrl;
91
- }
92
- nxJson.nxCloudAccessToken = token;
93
- return nxJson;
94
- });
95
- }
96
- }
97
72
  function addNxCloudIdToNxJson(tree, nxCloudId, directory = '') {
98
73
  const nxJsonPath = (0, path_1.join)(directory, 'nx.json');
99
74
  if (tree.exists(nxJsonPath)) {
@@ -115,27 +90,16 @@ async function connectToNxCloud(tree, schema, nxJson = (0, nx_json_1.readNxJson)
115
90
  }
116
91
  else {
117
92
  const usesGithub = schema.github ?? (await (0, url_shorten_1.repoUsesGithub)(schema.github));
118
- let responseFromCreateNxCloudWorkspaceV1;
119
93
  let responseFromCreateNxCloudWorkspaceV2;
120
94
  // do NOT create Nx Cloud token (createNxCloudWorkspace)
121
95
  // if user is using github and is running nx-connect
122
96
  if (!(usesGithub && schema.installationSource === 'nx-connect')) {
123
- if (process.env.NX_ENABLE_LOGIN === 'true') {
124
- responseFromCreateNxCloudWorkspaceV2 = await createNxCloudWorkspaceV2(getRootPackageName(tree), schema.installationSource, getNxInitDate());
125
- addNxCloudIdToNxJson(tree, responseFromCreateNxCloudWorkspaceV2?.nxCloudId, schema.directory);
126
- await (0, format_changed_files_with_prettier_if_available_1.formatChangedFilesWithPrettierIfAvailable)(tree, {
127
- silent: schema.hideFormatLogs,
128
- });
129
- return responseFromCreateNxCloudWorkspaceV2.nxCloudId;
130
- }
131
- else {
132
- responseFromCreateNxCloudWorkspaceV1 = await createNxCloudWorkspaceV1(getRootPackageName(tree), schema.installationSource, getNxInitDate());
133
- addNxCloudOptionsToNxJson(tree, responseFromCreateNxCloudWorkspaceV1?.token, schema.directory);
134
- await (0, format_changed_files_with_prettier_if_available_1.formatChangedFilesWithPrettierIfAvailable)(tree, {
135
- silent: schema.hideFormatLogs,
136
- });
137
- return responseFromCreateNxCloudWorkspaceV1.token;
138
- }
97
+ responseFromCreateNxCloudWorkspaceV2 = await createNxCloudWorkspaceV2(getRootPackageName(tree), schema.installationSource, getNxInitDate());
98
+ addNxCloudIdToNxJson(tree, responseFromCreateNxCloudWorkspaceV2?.nxCloudId, schema.directory);
99
+ await (0, format_changed_files_with_prettier_if_available_1.formatChangedFilesWithPrettierIfAvailable)(tree, {
100
+ silent: schema.hideFormatLogs,
101
+ });
102
+ return responseFromCreateNxCloudWorkspaceV2.nxCloudId;
139
103
  }
140
104
  }
141
105
  }
@@ -11,7 +11,7 @@ export interface NxCloudClient {
11
11
  configureLightClientRequire: () => (paths: string[]) => void;
12
12
  commands: Record<string, () => Promise<void>>;
13
13
  nxCloudTasksRunner: TasksRunner<CloudTaskRunnerOptions>;
14
- remoteCache: RemoteCacheV2;
14
+ getRemoteCache: () => RemoteCacheV2;
15
15
  }
16
16
  export declare function verifyOrUpdateNxCloudClient(options: CloudTaskRunnerOptions): Promise<{
17
17
  nxCloudClient: NxCloudClient;
@@ -18,6 +18,13 @@ const defaultNpmResolutionCache = new Map();
18
18
  const builtInModuleSet = new Set([
19
19
  ...node_module_1.builtinModules,
20
20
  ...node_module_1.builtinModules.map((x) => `node:${x}`),
21
+ // These are missing in the builtinModules list
22
+ // See: https://github.com/nodejs/node/issues/42785
23
+ // TODO(v20): We should be safe to use `isBuiltin` function instead of keep the set here (https://nodejs.org/api/module.html#moduleisbuiltinmodulename)
24
+ 'test',
25
+ 'node:test',
26
+ 'node:sea',
27
+ 'node:sqlite',
21
28
  ]);
22
29
  function isBuiltinModuleImport(importExpr) {
23
30
  const packageName = (0, get_package_name_from_import_path_1.getPackageNameFromImportPath)(importExpr);
@@ -265,7 +272,7 @@ class TargetProjectLocator {
265
272
  // Resolve the main entry point of the package
266
273
  const pathOfFileInPackage = packageJsonPath ?? (0, resolve_relative_to_dir_1.resolveRelativeToDir)(packageName, relativeToDir);
267
274
  let dir = (0, node_path_1.dirname)(pathOfFileInPackage);
268
- while (dir !== (0, node_path_1.parse)(dir).root) {
275
+ while (dir !== (0, node_path_1.dirname)(dir)) {
269
276
  const packageJsonPath = (0, node_path_1.join)(dir, 'package.json');
270
277
  try {
271
278
  const parsedPackageJson = (0, fileutils_1.readJsonFile)(packageJsonPath);
@@ -81,8 +81,8 @@ class DbCache {
81
81
  if ((0, nx_cloud_utils_1.isNxCloudUsed)(nxJson)) {
82
82
  const options = (0, get_cloud_options_1.getCloudOptions)();
83
83
  const { nxCloudClient } = await (0, update_manager_1.verifyOrUpdateNxCloudClient)(options);
84
- if (nxCloudClient.remoteCache) {
85
- return nxCloudClient.remoteCache;
84
+ if (nxCloudClient.getRemoteCache) {
85
+ return nxCloudClient.getRemoteCache();
86
86
  }
87
87
  else {
88
88
  // old nx cloud instance
@@ -121,16 +121,7 @@ async function runCommand(projectsToRun, currentProjectGraph, { nxJson }, nxArgs
121
121
  async function ensureWorkspaceIsInSyncAndGetGraphs(projectGraph, nxJson, projectNames, nxArgs, overrides, extraTargetDependencies, extraOptions) {
122
122
  let taskGraph = createTaskGraphAndRunValidations(projectGraph, extraTargetDependencies ?? {}, projectNames, nxArgs, overrides, extraOptions);
123
123
  // collect unique syncGenerators from the tasks
124
- const uniqueSyncGenerators = new Set();
125
- for (const { target } of Object.values(taskGraph.tasks)) {
126
- const { syncGenerators } = projectGraph.nodes[target.project].data.targets[target.target];
127
- if (!syncGenerators) {
128
- continue;
129
- }
130
- for (const generator of syncGenerators) {
131
- uniqueSyncGenerators.add(generator);
132
- }
133
- }
124
+ const uniqueSyncGenerators = (0, sync_generators_1.collectEnabledTaskSyncGeneratorsFromTaskGraph)(taskGraph, projectGraph, nxJson);
134
125
  if (!uniqueSyncGenerators.size) {
135
126
  // There are no sync generators registered in the tasks to run
136
127
  return { projectGraph, taskGraph };
@@ -1,5 +1,7 @@
1
1
  import type { GeneratorCallback } from '../config/misc-interfaces';
2
+ import { type NxJsonConfiguration } from '../config/nx-json';
2
3
  import type { ProjectGraph } from '../config/project-graph';
4
+ import type { TaskGraph } from '../config/task-graph';
3
5
  import type { ProjectConfiguration } from '../config/workspace-json-project-json';
4
6
  import { FsTree, type FileChange, type Tree } from '../generators/tree';
5
7
  export type SyncGeneratorResult = void | {
@@ -15,8 +17,9 @@ export type SyncGeneratorChangesResult = {
15
17
  };
16
18
  export declare function getSyncGeneratorChanges(generators: string[]): Promise<SyncGeneratorChangesResult[]>;
17
19
  export declare function flushSyncGeneratorChanges(results: SyncGeneratorChangesResult[]): Promise<void>;
18
- export declare function collectAllRegisteredSyncGenerators(projectGraph: ProjectGraph): Promise<string[]>;
20
+ export declare function collectAllRegisteredSyncGenerators(projectGraph: ProjectGraph, nxJson: NxJsonConfiguration): Promise<string[]>;
19
21
  export declare function runSyncGenerator(tree: FsTree, generatorSpecifier: string, projects: Record<string, ProjectConfiguration>): Promise<SyncGeneratorChangesResult>;
20
- export declare function collectRegisteredTaskSyncGenerators(projectGraph: ProjectGraph): Set<string>;
21
- export declare function collectRegisteredGlobalSyncGenerators(nxJson?: import("../config/nx-json").NxJsonConfiguration<string[] | "*">): Set<string>;
22
+ export declare function collectEnabledTaskSyncGeneratorsFromProjectGraph(projectGraph: ProjectGraph, nxJson: NxJsonConfiguration): Set<string>;
23
+ export declare function collectEnabledTaskSyncGeneratorsFromTaskGraph(taskGraph: TaskGraph, projectGraph: ProjectGraph, nxJson: NxJsonConfiguration): Set<string>;
24
+ export declare function collectRegisteredGlobalSyncGenerators(nxJson?: NxJsonConfiguration<string[] | "*">): Set<string>;
22
25
  export declare function syncGeneratorResultsToMessageLines(results: SyncGeneratorChangesResult[]): string[];
@@ -4,7 +4,8 @@ exports.getSyncGeneratorChanges = getSyncGeneratorChanges;
4
4
  exports.flushSyncGeneratorChanges = flushSyncGeneratorChanges;
5
5
  exports.collectAllRegisteredSyncGenerators = collectAllRegisteredSyncGenerators;
6
6
  exports.runSyncGenerator = runSyncGenerator;
7
- exports.collectRegisteredTaskSyncGenerators = collectRegisteredTaskSyncGenerators;
7
+ exports.collectEnabledTaskSyncGeneratorsFromProjectGraph = collectEnabledTaskSyncGeneratorsFromProjectGraph;
8
+ exports.collectEnabledTaskSyncGeneratorsFromTaskGraph = collectEnabledTaskSyncGeneratorsFromTaskGraph;
8
9
  exports.collectRegisteredGlobalSyncGenerators = collectRegisteredGlobalSyncGenerators;
9
10
  exports.syncGeneratorResultsToMessageLines = syncGeneratorResultsToMessageLines;
10
11
  const perf_hooks_1 = require("perf_hooks");
@@ -39,10 +40,10 @@ async function flushSyncGeneratorChanges(results) {
39
40
  await client_1.daemonClient.flushSyncGeneratorChangesToDisk(results.map((r) => r.generatorName));
40
41
  }
41
42
  }
42
- async function collectAllRegisteredSyncGenerators(projectGraph) {
43
+ async function collectAllRegisteredSyncGenerators(projectGraph, nxJson) {
43
44
  if (!client_1.daemonClient.enabled()) {
44
45
  return [
45
- ...collectRegisteredTaskSyncGenerators(projectGraph),
46
+ ...collectEnabledTaskSyncGeneratorsFromProjectGraph(projectGraph, nxJson),
46
47
  ...collectRegisteredGlobalSyncGenerators(),
47
48
  ];
48
49
  }
@@ -69,17 +70,38 @@ async function runSyncGenerator(tree, generatorSpecifier, projects) {
69
70
  outOfSyncMessage,
70
71
  };
71
72
  }
72
- function collectRegisteredTaskSyncGenerators(projectGraph) {
73
+ function collectEnabledTaskSyncGeneratorsFromProjectGraph(projectGraph, nxJson) {
73
74
  const taskSyncGenerators = new Set();
75
+ const disabledTaskSyncGenerators = new Set(nxJson.sync?.disabledTaskSyncGenerators ?? []);
74
76
  for (const { data: { targets }, } of Object.values(projectGraph.nodes)) {
75
77
  if (!targets) {
76
78
  continue;
77
79
  }
78
80
  for (const target of Object.values(targets)) {
79
- if (!target.syncGenerators) {
81
+ if (!target.syncGenerators?.length) {
80
82
  continue;
81
83
  }
82
84
  for (const generator of target.syncGenerators) {
85
+ if (!disabledTaskSyncGenerators.has(generator) &&
86
+ !taskSyncGenerators.has(generator)) {
87
+ taskSyncGenerators.add(generator);
88
+ }
89
+ }
90
+ }
91
+ }
92
+ return taskSyncGenerators;
93
+ }
94
+ function collectEnabledTaskSyncGeneratorsFromTaskGraph(taskGraph, projectGraph, nxJson) {
95
+ const taskSyncGenerators = new Set();
96
+ const disabledTaskSyncGenerators = new Set(nxJson.sync?.disabledTaskSyncGenerators ?? []);
97
+ for (const { target } of Object.values(taskGraph.tasks)) {
98
+ const { syncGenerators } = projectGraph.nodes[target.project].data.targets[target.target];
99
+ if (!syncGenerators?.length) {
100
+ continue;
101
+ }
102
+ for (const generator of syncGenerators) {
103
+ if (!disabledTaskSyncGenerators.has(generator) &&
104
+ !taskSyncGenerators.has(generator)) {
83
105
  taskSyncGenerators.add(generator);
84
106
  }
85
107
  }