nx 18.1.0-canary.20240309-235ca8c → 18.1.0-canary.20240312-9520aa2

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.
Files changed (69) hide show
  1. package/bin/post-install.js +5 -7
  2. package/package.json +12 -12
  3. package/src/adapter/angular-json.d.ts +1 -2
  4. package/src/adapter/angular-json.js +0 -1
  5. package/src/adapter/ngcli-adapter.js +3 -3
  6. package/src/command-line/generate/generator-utils.js +2 -2
  7. package/src/command-line/run/executor-utils.js +2 -2
  8. package/src/config/schema-utils.js +2 -2
  9. package/src/daemon/server/project-graph-incremental-recomputation.js +7 -8
  10. package/src/daemon/server/shutdown-utils.js +0 -2
  11. package/src/devkit-exports.d.ts +1 -2
  12. package/src/executors/utils/convert-nx-executor.js +1 -4
  13. package/src/generators/utils/project-configuration.js +2 -2
  14. package/src/migrations/update-15-1-0/set-project-names.js +2 -2
  15. package/src/plugins/js/index.d.ts +1 -1
  16. package/src/plugins/js/lock-file/lock-file.d.ts +1 -1
  17. package/src/plugins/js/lock-file/npm-parser.d.ts +1 -1
  18. package/src/plugins/js/lock-file/pnpm-parser.d.ts +1 -1
  19. package/src/plugins/js/lock-file/yarn-parser.d.ts +1 -1
  20. package/src/plugins/js/project-graph/build-dependencies/build-dependencies.d.ts +1 -1
  21. package/src/plugins/js/project-graph/build-dependencies/explicit-package-json-dependencies.d.ts +1 -1
  22. package/src/plugins/js/project-graph/build-dependencies/explicit-project-dependencies.d.ts +1 -1
  23. package/src/plugins/js/utils/register.js +3 -1
  24. package/src/plugins/package-json-workspaces/create-nodes.d.ts +2 -2
  25. package/src/plugins/package-json-workspaces/create-nodes.js +31 -24
  26. package/src/plugins/package-json-workspaces/index.d.ts +0 -1
  27. package/src/plugins/package-json-workspaces/index.js +0 -2
  28. package/src/plugins/project-json/build-nodes/package-json-next-to-project-json.d.ts +1 -2
  29. package/src/plugins/project-json/build-nodes/package-json-next-to-project-json.js +0 -1
  30. package/src/plugins/project-json/build-nodes/project-json.d.ts +1 -2
  31. package/src/plugins/project-json/build-nodes/project-json.js +0 -1
  32. package/src/plugins/target-defaults/target-defaults-plugin.d.ts +1 -2
  33. package/src/plugins/target-defaults/target-defaults-plugin.js +0 -1
  34. package/src/project-graph/affected/locators/project-glob-changes.js +3 -3
  35. package/src/project-graph/build-project-graph.d.ts +1 -2
  36. package/src/project-graph/build-project-graph.js +13 -12
  37. package/src/project-graph/file-utils.js +3 -3
  38. package/src/project-graph/project-graph-builder.d.ts +1 -1
  39. package/src/project-graph/project-graph.js +15 -19
  40. package/src/project-graph/utils/normalize-project-nodes.d.ts +1 -1
  41. package/src/project-graph/utils/project-configuration-utils.d.ts +2 -2
  42. package/src/project-graph/utils/project-configuration-utils.js +55 -11
  43. package/src/project-graph/utils/retrieve-workspace-files.d.ts +8 -6
  44. package/src/project-graph/utils/retrieve-workspace-files.js +21 -18
  45. package/src/utils/logger.d.ts +0 -1
  46. package/src/utils/logger.js +0 -5
  47. package/src/{project-graph/plugins/public-api.d.ts → utils/nx-plugin.d.ts} +41 -7
  48. package/src/utils/nx-plugin.deprecated.d.ts +2 -4
  49. package/src/utils/nx-plugin.deprecated.js +4 -4
  50. package/src/utils/nx-plugin.js +293 -0
  51. package/src/utils/plugins/plugin-capabilities.d.ts +1 -1
  52. package/src/utils/plugins/plugin-capabilities.js +9 -10
  53. package/src/daemon/server/plugins.d.ts +0 -3
  54. package/src/daemon/server/plugins.js +0 -22
  55. package/src/project-graph/plugins/index.d.ts +0 -2
  56. package/src/project-graph/plugins/index.js +0 -8
  57. package/src/project-graph/plugins/internal-api.d.ts +0 -22
  58. package/src/project-graph/plugins/internal-api.js +0 -64
  59. package/src/project-graph/plugins/messaging.d.ts +0 -94
  60. package/src/project-graph/plugins/messaging.js +0 -23
  61. package/src/project-graph/plugins/plugin-pool.d.ts +0 -3
  62. package/src/project-graph/plugins/plugin-pool.js +0 -189
  63. package/src/project-graph/plugins/plugin-worker.d.ts +0 -1
  64. package/src/project-graph/plugins/plugin-worker.js +0 -101
  65. package/src/project-graph/plugins/public-api.js +0 -4
  66. package/src/project-graph/plugins/utils.d.ts +0 -9
  67. package/src/project-graph/plugins/utils.js +0 -55
  68. package/src/project-graph/plugins/worker-api.d.ts +0 -28
  69. package/src/project-graph/plugins/worker-api.js +0 -195
@@ -8,12 +8,13 @@ const assert_workspace_validity_1 = require("../utils/assert-workspace-validity"
8
8
  const nx_deps_cache_1 = require("./nx-deps-cache");
9
9
  const implicit_project_dependencies_1 = require("./utils/implicit-project-dependencies");
10
10
  const normalize_project_nodes_1 = require("./utils/normalize-project-nodes");
11
- const utils_1 = require("./plugins/utils");
11
+ const nx_plugin_1 = require("../utils/nx-plugin");
12
12
  const typescript_1 = require("../plugins/js/utils/typescript");
13
13
  const fileutils_1 = require("../utils/fileutils");
14
14
  const project_graph_builder_1 = require("./project-graph-builder");
15
15
  const configuration_1 = require("../config/configuration");
16
16
  const fs_1 = require("fs");
17
+ const installation_directory_1 = require("../utils/installation-directory");
17
18
  const output_1 = require("../utils/output");
18
19
  let storedFileMap = null;
19
20
  let storedAllWorkspaceFiles = null;
@@ -38,7 +39,7 @@ function getFileMap() {
38
39
  }
39
40
  }
40
41
  exports.getFileMap = getFileMap;
41
- async function buildProjectGraphUsingProjectFileMap(projects, externalNodes, fileMap, allWorkspaceFiles, rustReferences, fileMapCache, shouldWriteCache, plugins) {
42
+ async function buildProjectGraphUsingProjectFileMap(projects, externalNodes, fileMap, allWorkspaceFiles, rustReferences, fileMapCache, shouldWriteCache) {
42
43
  storedFileMap = fileMap;
43
44
  storedAllWorkspaceFiles = allWorkspaceFiles;
44
45
  storedRustReferences = rustReferences;
@@ -64,7 +65,7 @@ async function buildProjectGraphUsingProjectFileMap(projects, externalNodes, fil
64
65
  };
65
66
  }
66
67
  const context = createContext(projects, nxJson, externalNodes, fileMap, filesToProcess);
67
- let projectGraph = await buildProjectGraphUsingContext(nxJson, externalNodes, context, cachedFileData, projectGraphVersion, plugins);
68
+ let projectGraph = await buildProjectGraphUsingContext(nxJson, externalNodes, context, cachedFileData, projectGraphVersion);
68
69
  const projectFileMapCache = (0, nx_deps_cache_1.createProjectFileMapCache)(nxJson, packageJsonDeps, fileMap, rootTsConfig);
69
70
  if (shouldWriteCache) {
70
71
  (0, nx_deps_cache_1.writeCache)(projectFileMapCache, projectGraph);
@@ -91,7 +92,7 @@ function readCombinedDeps() {
91
92
  ...installationPackageJson.devDependencies,
92
93
  };
93
94
  }
94
- async function buildProjectGraphUsingContext(nxJson, knownExternalNodes, ctx, cachedFileData, projectGraphVersion, plugins) {
95
+ async function buildProjectGraphUsingContext(nxJson, knownExternalNodes, ctx, cachedFileData, projectGraphVersion) {
95
96
  perf_hooks_1.performance.mark('build project graph:start');
96
97
  const builder = new project_graph_builder_1.ProjectGraphBuilder(null, ctx.fileMap.projectFileMap);
97
98
  builder.setVersion(projectGraphVersion);
@@ -100,7 +101,7 @@ async function buildProjectGraphUsingContext(nxJson, knownExternalNodes, ctx, ca
100
101
  }
101
102
  await (0, normalize_project_nodes_1.normalizeProjectNodes)(ctx, builder);
102
103
  const initProjectGraph = builder.getUpdatedProjectGraph();
103
- const r = await updateProjectGraphWithPlugins(ctx, initProjectGraph, plugins);
104
+ const r = await updateProjectGraphWithPlugins(ctx, initProjectGraph);
104
105
  const updatedBuilder = new project_graph_builder_1.ProjectGraphBuilder(r, ctx.fileMap.projectFileMap);
105
106
  for (const proj of Object.keys(cachedFileData.projectFileMap)) {
106
107
  for (const f of ctx.fileMap.projectFileMap[proj] || []) {
@@ -138,11 +139,12 @@ function createContext(projects, nxJson, externalNodes, fileMap, filesToProcess)
138
139
  filesToProcess,
139
140
  };
140
141
  }
141
- async function updateProjectGraphWithPlugins(context, initProjectGraph, plugins) {
142
+ async function updateProjectGraphWithPlugins(context, initProjectGraph) {
143
+ const plugins = await (0, nx_plugin_1.loadNxPlugins)(context.nxJsonConfiguration?.plugins, (0, installation_directory_1.getNxRequirePaths)(), context.workspaceRoot, context.projects);
142
144
  let graph = initProjectGraph;
143
- for (const plugin of plugins) {
145
+ for (const { plugin } of plugins) {
144
146
  try {
145
- if ((0, utils_1.isNxPluginV1)(plugin) &&
147
+ if ((0, nx_plugin_1.isNxPluginV1)(plugin) &&
146
148
  plugin.processProjectGraph &&
147
149
  !plugin.createDependencies) {
148
150
  output_1.output.warn({
@@ -180,12 +182,11 @@ async function updateProjectGraphWithPlugins(context, initProjectGraph, plugins)
180
182
  }
181
183
  }
182
184
  const builder = new project_graph_builder_1.ProjectGraphBuilder(graph, context.fileMap.projectFileMap, context.fileMap.nonProjectFiles);
183
- const createDependencyPlugins = plugins.filter((plugin) => (0, utils_1.isNxPluginV2)(plugin) && plugin.createDependencies);
184
- await Promise.all(createDependencyPlugins.map(async (plugin) => {
185
+ const createDependencyPlugins = plugins.filter(({ plugin }) => (0, nx_plugin_1.isNxPluginV2)(plugin) && plugin.createDependencies);
186
+ await Promise.all(createDependencyPlugins.map(async ({ plugin, options }) => {
185
187
  perf_hooks_1.performance.mark(`${plugin.name}:createDependencies - start`);
186
188
  try {
187
- // TODO: we shouldn't have to pass null here
188
- const dependencies = await plugin.createDependencies(null, {
189
+ const dependencies = await plugin.createDependencies(options, {
189
190
  ...context,
190
191
  });
191
192
  for (const dep of dependencies) {
@@ -147,21 +147,21 @@ Object.defineProperty(exports, "workspaceLayout", { enumerable: true, get: funct
147
147
  * TODO(v19): Remove this function.
148
148
  */
149
149
  function getProjectsSyncNoInference(root, nxJson) {
150
- const projectFiles = (0, retrieve_workspace_files_1.retrieveProjectConfigurationPaths)(root, (0, nx_plugin_deprecated_1.getDefaultPluginsSync)(root).map((p) => p.plugin));
150
+ const projectFiles = (0, retrieve_workspace_files_1.retrieveProjectConfigurationPaths)(root, (0, nx_plugin_deprecated_1.getDefaultPluginsSync)(root));
151
151
  const plugins = [
152
152
  { plugin: package_json_next_to_project_json_1.PackageJsonProjectsNextToProjectJsonPlugin },
153
153
  ...(0, nx_plugin_deprecated_1.getDefaultPluginsSync)(root),
154
154
  ];
155
155
  const projectRootMap = new Map();
156
156
  // We iterate over plugins first - this ensures that plugins specified first take precedence.
157
- for (const { plugin } of plugins) {
157
+ for (const { plugin, options } of plugins) {
158
158
  const [pattern, createNodes] = plugin.createNodes ?? [];
159
159
  if (!pattern) {
160
160
  continue;
161
161
  }
162
162
  for (const file of projectFiles) {
163
163
  if ((0, minimatch_1.minimatch)(file, pattern, { dot: true })) {
164
- let r = createNodes(file, {}, {
164
+ let r = createNodes(file, options, {
165
165
  nxJsonConfiguration: nxJson,
166
166
  workspaceRoot: root,
167
167
  });
@@ -2,7 +2,7 @@
2
2
  * Builder for adding nodes and dependencies to a {@link ProjectGraph}
3
3
  */
4
4
  import { DependencyType, FileMap, ProjectFileMap, ProjectGraph, ProjectGraphExternalNode, ProjectGraphProjectNode } from '../config/project-graph';
5
- import { CreateDependenciesContext } from './plugins';
5
+ import { CreateDependenciesContext } from '../utils/nx-plugin';
6
6
  /**
7
7
  * A class which builds up a project graph
8
8
  * @deprecated The {@link ProjectGraphProcessor} has been deprecated. Use a {@link CreateNodes} and/or a {@link CreateDependencies} instead. This will be removed in Nx 19.
@@ -12,7 +12,7 @@ const workspace_root_1 = require("../utils/workspace-root");
12
12
  const perf_hooks_1 = require("perf_hooks");
13
13
  const retrieve_workspace_files_1 = require("./utils/retrieve-workspace-files");
14
14
  const nx_json_1 = require("../config/nx-json");
15
- const internal_api_1 = require("./plugins/internal-api");
15
+ const nx_plugin_1 = require("../utils/nx-plugin");
16
16
  /**
17
17
  * Synchronously reads the latest cached copy of the workspace's ProjectGraph.
18
18
  * @throws {Error} if there is no cached ProjectGraph to read from
@@ -66,26 +66,22 @@ function readProjectsConfigurationFromProjectGraph(projectGraph) {
66
66
  }
67
67
  exports.readProjectsConfigurationFromProjectGraph = readProjectsConfigurationFromProjectGraph;
68
68
  async function buildProjectGraphAndSourceMapsWithoutDaemon() {
69
+ // Set this globally to allow plugins to know if they are being called from the project graph creation
69
70
  global.NX_GRAPH_CREATION = true;
70
71
  const nxJson = (0, nx_json_1.readNxJson)();
71
- const [plugins, cleanup] = await (0, internal_api_1.loadNxPluginsInIsolation)(nxJson.plugins);
72
- try {
73
- perf_hooks_1.performance.mark('retrieve-project-configurations:start');
74
- const { projects, externalNodes, sourceMaps, projectRootMap } = await (0, retrieve_workspace_files_1.retrieveProjectConfigurations)(plugins, workspace_root_1.workspaceRoot, nxJson);
75
- perf_hooks_1.performance.mark('retrieve-project-configurations:end');
76
- perf_hooks_1.performance.mark('retrieve-workspace-files:start');
77
- const { allWorkspaceFiles, fileMap, rustReferences } = await (0, retrieve_workspace_files_1.retrieveWorkspaceFiles)(workspace_root_1.workspaceRoot, projectRootMap);
78
- perf_hooks_1.performance.mark('retrieve-workspace-files:end');
79
- const cacheEnabled = process.env.NX_CACHE_PROJECT_GRAPH !== 'false';
80
- perf_hooks_1.performance.mark('build-project-graph-using-project-file-map:start');
81
- const projectGraph = (await (0, build_project_graph_1.buildProjectGraphUsingProjectFileMap)(projects, externalNodes, fileMap, allWorkspaceFiles, rustReferences, cacheEnabled ? (0, nx_deps_cache_1.readFileMapCache)() : null, cacheEnabled, plugins)).projectGraph;
82
- perf_hooks_1.performance.mark('build-project-graph-using-project-file-map:end');
83
- delete global.NX_GRAPH_CREATION;
84
- return { projectGraph, sourceMaps };
85
- }
86
- finally {
87
- cleanup();
88
- }
72
+ perf_hooks_1.performance.mark('retrieve-project-configurations:start');
73
+ const { projects, externalNodes, sourceMaps, projectRootMap } = await (0, retrieve_workspace_files_1.retrieveProjectConfigurations)(workspace_root_1.workspaceRoot, nxJson);
74
+ perf_hooks_1.performance.mark('retrieve-project-configurations:end');
75
+ perf_hooks_1.performance.mark('retrieve-workspace-files:start');
76
+ const { allWorkspaceFiles, fileMap, rustReferences } = await (0, retrieve_workspace_files_1.retrieveWorkspaceFiles)(workspace_root_1.workspaceRoot, projectRootMap);
77
+ perf_hooks_1.performance.mark('retrieve-workspace-files:end');
78
+ const cacheEnabled = process.env.NX_CACHE_PROJECT_GRAPH !== 'false';
79
+ perf_hooks_1.performance.mark('build-project-graph-using-project-file-map:start');
80
+ const projectGraph = (await (0, build_project_graph_1.buildProjectGraphUsingProjectFileMap)(projects, externalNodes, fileMap, allWorkspaceFiles, rustReferences, cacheEnabled ? (0, nx_deps_cache_1.readFileMapCache)() : null, cacheEnabled)).projectGraph;
81
+ perf_hooks_1.performance.mark('build-project-graph-using-project-file-map:end');
82
+ (0, nx_plugin_1.unregisterPluginTSTranspiler)();
83
+ delete global.NX_GRAPH_CREATION;
84
+ return { projectGraph, sourceMaps };
89
85
  }
90
86
  exports.buildProjectGraphAndSourceMapsWithoutDaemon = buildProjectGraphAndSourceMapsWithoutDaemon;
91
87
  function handleProjectGraphError(opts, e) {
@@ -1,7 +1,7 @@
1
1
  import { ProjectGraphProjectNode } from '../../config/project-graph';
2
2
  import { ProjectGraphBuilder } from '../project-graph-builder';
3
3
  import { ProjectConfiguration, TargetConfiguration } from '../../config/workspace-json-project-json';
4
- import { CreateDependenciesContext } from '../plugins';
4
+ import { CreateDependenciesContext } from '../../utils/nx-plugin';
5
5
  export declare function normalizeProjectNodes(ctx: CreateDependenciesContext, builder: ProjectGraphBuilder): Promise<void>;
6
6
  /**
7
7
  * Apply target defaults and normalization
@@ -1,8 +1,8 @@
1
1
  import { NxJsonConfiguration, TargetDefaults } from '../../config/nx-json';
2
2
  import { ProjectGraphExternalNode } from '../../config/project-graph';
3
3
  import { ProjectConfiguration, TargetConfiguration } from '../../config/workspace-json-project-json';
4
+ import { LoadedNxPlugin } from '../../utils/nx-plugin';
4
5
  import { ONLY_MODIFIES_EXISTING_TARGET } from '../../plugins/target-defaults/target-defaults-plugin';
5
- import { RemotePlugin } from '../plugins/internal-api';
6
6
  export type SourceInformation = [file: string, plugin: string];
7
7
  export type ConfigurationSourceMaps = Record<string, Record<string, SourceInformation>>;
8
8
  export declare function mergeProjectConfigurationIntoRootMap(projectRootMap: Map<string, ProjectConfiguration>, project: ProjectConfiguration & {
@@ -25,7 +25,7 @@ export type ConfigurationResult = {
25
25
  * @param root The workspace root
26
26
  */
27
27
  export declare function buildProjectsConfigurationsFromProjectPathsAndPlugins(nxJson: NxJsonConfiguration, projectFiles: string[], // making this parameter allows devkit to pick up newly created projects
28
- plugins: RemotePlugin[], root?: string): Promise<ConfigurationResult>;
28
+ plugins: LoadedNxPlugin[], root?: string): Promise<ConfigurationResult>;
29
29
  export declare function readProjectConfigurationsFromRootMap(projectRootMap: Map<string, ProjectConfiguration>): Record<string, ProjectConfiguration>;
30
30
  /**
31
31
  * Merges two targets.
@@ -7,7 +7,6 @@ const workspace_root_1 = require("../../utils/workspace-root");
7
7
  const target_defaults_plugin_1 = require("../../plugins/target-defaults/target-defaults-plugin");
8
8
  const minimatch_1 = require("minimatch");
9
9
  const path_1 = require("path");
10
- const utils_1 = require("../plugins/utils");
11
10
  function mergeProjectConfigurationIntoRootMap(projectRootMap, project, configurationSourceMaps, sourceInformation,
12
11
  // This function is used when reading project configuration
13
12
  // in generators, where we don't want to do this.
@@ -133,23 +132,54 @@ function buildProjectsConfigurationsFromProjectPathsAndPlugins(nxJson, projectFi
133
132
  plugins, root = workspace_root_1.workspaceRoot) {
134
133
  const results = [];
135
134
  // We iterate over plugins first - this ensures that plugins specified first take precedence.
136
- for (const plugin of plugins) {
135
+ for (const { plugin, options } of plugins) {
137
136
  const [pattern, createNodes] = plugin.createNodes ?? [];
137
+ const pluginResults = [];
138
+ performance.mark(`${plugin.name}:createNodes - start`);
138
139
  if (!pattern) {
139
140
  continue;
140
141
  }
141
- const matchedFiles = [];
142
- performance.mark(`${plugin.name}:createNodes - start`);
143
142
  for (const file of projectFiles) {
143
+ performance.mark(`${plugin.name}:createNodes:${file} - start`);
144
144
  if ((0, minimatch_1.minimatch)(file, pattern, { dot: true })) {
145
- matchedFiles.push(file);
145
+ try {
146
+ let r = createNodes(file, options, {
147
+ nxJsonConfiguration: nxJson,
148
+ workspaceRoot: root,
149
+ });
150
+ if (r instanceof Promise) {
151
+ pluginResults.push(r
152
+ .catch((e) => {
153
+ performance.mark(`${plugin.name}:createNodes:${file} - end`);
154
+ throw new CreateNodesError(`Unable to create nodes for ${file} using plugin ${plugin.name}.`, e);
155
+ })
156
+ .then((r) => {
157
+ performance.mark(`${plugin.name}:createNodes:${file} - end`);
158
+ performance.measure(`${plugin.name}:createNodes:${file}`, `${plugin.name}:createNodes:${file} - start`, `${plugin.name}:createNodes:${file} - end`);
159
+ return { ...r, file, pluginName: plugin.name };
160
+ }));
161
+ }
162
+ else {
163
+ performance.mark(`${plugin.name}:createNodes:${file} - end`);
164
+ performance.measure(`${plugin.name}:createNodes:${file}`, `${plugin.name}:createNodes:${file} - start`, `${plugin.name}:createNodes:${file} - end`);
165
+ pluginResults.push({
166
+ ...r,
167
+ file,
168
+ pluginName: plugin.name,
169
+ });
170
+ }
171
+ }
172
+ catch (e) {
173
+ throw new CreateNodesError(`Unable to create nodes for ${file} using plugin ${plugin.name}.`, e);
174
+ }
146
175
  }
147
176
  }
148
- let r = createNodes(matchedFiles, {
149
- nxJsonConfiguration: nxJson,
150
- workspaceRoot: root,
151
- });
152
- results.push(r);
177
+ // If there are no promises (counter undefined) or all promises have resolved (counter === 0)
178
+ results.push(Promise.all(pluginResults).then((results) => {
179
+ performance.mark(`${plugin.name}:createNodes - end`);
180
+ performance.measure(`${plugin.name}:createNodes`, `${plugin.name}:createNodes - start`, `${plugin.name}:createNodes - end`);
181
+ return results;
182
+ }));
153
183
  }
154
184
  return Promise.all(results).then((results) => {
155
185
  performance.mark('createNodes:merge - start');
@@ -171,7 +201,7 @@ plugins, root = workspace_root_1.workspaceRoot) {
171
201
  mergeProjectConfigurationIntoRootMap(projectRootMap, project, configurationSourceMaps, sourceInfo);
172
202
  }
173
203
  catch (e) {
174
- throw new utils_1.CreateNodesError(`Unable to merge project information for "${project.root}" from ${result.file} using plugin ${result.pluginName}.`, e);
204
+ throw new CreateNodesError(`Unable to merge project information for "${project.root}" from ${result.file} using plugin ${result.pluginName}.`, e);
175
205
  }
176
206
  }
177
207
  Object.assign(externalNodes, pluginExternalNodes);
@@ -231,6 +261,20 @@ function readProjectConfigurationsFromRootMap(projectRootMap) {
231
261
  return projects;
232
262
  }
233
263
  exports.readProjectConfigurationsFromRootMap = readProjectConfigurationsFromRootMap;
264
+ class CreateNodesError extends Error {
265
+ constructor(msg, cause) {
266
+ const message = `${msg} ${!cause
267
+ ? ''
268
+ : cause instanceof Error
269
+ ? `\n\n\t Inner Error: ${cause.stack}`
270
+ : cause}`;
271
+ // These errors are thrown during a JS callback which is invoked via rust.
272
+ // The errors messaging gets lost in the rust -> js -> rust transition, but
273
+ // logging the error here will ensure that it is visible in the console.
274
+ console.error(message);
275
+ super(message, { cause });
276
+ }
277
+ }
234
278
  /**
235
279
  * Merges two targets.
236
280
  *
@@ -2,8 +2,7 @@ import { ProjectConfiguration } from '../../config/workspace-json-project-json';
2
2
  import { NxJsonConfiguration } from '../../config/nx-json';
3
3
  import { ProjectGraphExternalNode } from '../../config/project-graph';
4
4
  import { ConfigurationSourceMaps } from './project-configuration-utils';
5
- import { RemotePlugin } from '../plugins/internal-api';
6
- import { NxPlugin } from '../plugins';
5
+ import { LoadedNxPlugin } from '../../utils/nx-plugin';
7
6
  /**
8
7
  * Walks the workspace directory to create the `projectFileMap`, `ProjectConfigurations` and `allWorkspaceFiles`
9
8
  * @throws
@@ -20,8 +19,11 @@ export declare function retrieveWorkspaceFiles(workspaceRoot: string, projectRoo
20
19
  }>;
21
20
  /**
22
21
  * Walk through the workspace and return `ProjectConfigurations`. Only use this if the projectFileMap is not needed.
22
+ *
23
+ * @param workspaceRoot
24
+ * @param nxJson
23
25
  */
24
- export declare function retrieveProjectConfigurations(plugins: RemotePlugin[], workspaceRoot: string, nxJson: NxJsonConfiguration): Promise<RetrievedGraphNodes>;
26
+ export declare function retrieveProjectConfigurations(workspaceRoot: string, nxJson: NxJsonConfiguration): Promise<RetrievedGraphNodes>;
25
27
  export declare function retrieveProjectConfigurationsWithAngularProjects(workspaceRoot: string, nxJson: NxJsonConfiguration): Promise<RetrievedGraphNodes>;
26
28
  export type RetrievedGraphNodes = {
27
29
  externalNodes: Record<string, ProjectGraphExternalNode>;
@@ -29,7 +31,7 @@ export type RetrievedGraphNodes = {
29
31
  sourceMaps: ConfigurationSourceMaps;
30
32
  projectRootMap: Record<string, string>;
31
33
  };
32
- export declare function retrieveProjectConfigurationPaths(root: string, plugins: NxPlugin[]): string[];
34
+ export declare function retrieveProjectConfigurationPaths(root: string, plugins: LoadedNxPlugin[]): string[];
33
35
  export declare function retrieveProjectConfigurationsWithoutPluginInference(root: string): Promise<Record<string, ProjectConfiguration>>;
34
- export declare function createProjectConfigurations(workspaceRoot: string, nxJson: NxJsonConfiguration, configFiles: string[], plugins: RemotePlugin[]): Promise<RetrievedGraphNodes>;
35
- export declare function configurationGlobs(plugins: Array<NxPlugin>): string[];
36
+ export declare function createProjectConfigurations(workspaceRoot: string, nxJson: NxJsonConfiguration, configFiles: string[], plugins: LoadedNxPlugin[]): Promise<RetrievedGraphNodes>;
37
+ export declare function configurationGlobs(plugins: LoadedNxPlugin[]): string[];
@@ -2,13 +2,15 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.configurationGlobs = exports.createProjectConfigurations = exports.retrieveProjectConfigurationsWithoutPluginInference = exports.retrieveProjectConfigurationPaths = exports.retrieveProjectConfigurationsWithAngularProjects = exports.retrieveProjectConfigurations = exports.retrieveWorkspaceFiles = void 0;
4
4
  const perf_hooks_1 = require("perf_hooks");
5
+ const installation_directory_1 = require("../../utils/installation-directory");
5
6
  const angular_json_1 = require("../../adapter/angular-json");
6
7
  const nx_json_1 = require("../../config/nx-json");
8
+ const package_json_workspaces_1 = require("../../plugins/package-json-workspaces");
7
9
  const project_configuration_utils_1 = require("./project-configuration-utils");
8
- const internal_api_1 = require("../plugins/internal-api");
10
+ const nx_plugin_1 = require("../../utils/nx-plugin");
11
+ const project_json_1 = require("../../plugins/project-json/build-nodes/project-json");
9
12
  const workspace_context_1 = require("../../utils/workspace-context");
10
13
  const build_all_workspace_files_1 = require("./build-all-workspace-files");
11
- const path_1 = require("path");
12
14
  /**
13
15
  * Walks the workspace directory to create the `projectFileMap`, `ProjectConfigurations` and `allWorkspaceFiles`
14
16
  * @throws
@@ -35,23 +37,22 @@ async function retrieveWorkspaceFiles(workspaceRoot, projectRootMap) {
35
37
  exports.retrieveWorkspaceFiles = retrieveWorkspaceFiles;
36
38
  /**
37
39
  * Walk through the workspace and return `ProjectConfigurations`. Only use this if the projectFileMap is not needed.
40
+ *
41
+ * @param workspaceRoot
42
+ * @param nxJson
38
43
  */
39
- async function retrieveProjectConfigurations(plugins, workspaceRoot, nxJson) {
40
- const projects = await _retrieveProjectConfigurations(workspaceRoot, nxJson, plugins);
41
- return projects;
44
+ async function retrieveProjectConfigurations(workspaceRoot, nxJson) {
45
+ const plugins = await (0, nx_plugin_1.loadNxPlugins)(nxJson?.plugins ?? [], (0, installation_directory_1.getNxRequirePaths)(workspaceRoot), workspaceRoot);
46
+ return _retrieveProjectConfigurations(workspaceRoot, nxJson, plugins);
42
47
  }
43
48
  exports.retrieveProjectConfigurations = retrieveProjectConfigurations;
44
49
  async function retrieveProjectConfigurationsWithAngularProjects(workspaceRoot, nxJson) {
45
- const pluginsToLoad = nxJson?.plugins ?? [];
50
+ const plugins = await (0, nx_plugin_1.loadNxPlugins)(nxJson?.plugins ?? [], (0, installation_directory_1.getNxRequirePaths)(workspaceRoot), workspaceRoot);
46
51
  if ((0, angular_json_1.shouldMergeAngularProjects)(workspaceRoot, true) &&
47
- !pluginsToLoad.some((p) => p === angular_json_1.NX_ANGULAR_JSON_PLUGIN_NAME ||
48
- (typeof p === 'object' && p.plugin === angular_json_1.NX_ANGULAR_JSON_PLUGIN_NAME))) {
49
- pluginsToLoad.push((0, path_1.join)(__dirname, '../../adapter/angular-json'));
52
+ !plugins.some((p) => p.plugin.name === angular_json_1.NX_ANGULAR_JSON_PLUGIN_NAME)) {
53
+ plugins.push({ plugin: angular_json_1.NxAngularJsonPlugin });
50
54
  }
51
- const [plugins, cleanup] = await (0, internal_api_1.loadNxPluginsInIsolation)(nxJson?.plugins ?? [], workspaceRoot);
52
- const res = _retrieveProjectConfigurations(workspaceRoot, nxJson, await plugins);
53
- cleanup();
54
- return res;
55
+ return _retrieveProjectConfigurations(workspaceRoot, nxJson, plugins);
55
56
  }
56
57
  exports.retrieveProjectConfigurationsWithAngularProjects = retrieveProjectConfigurationsWithAngularProjects;
57
58
  function _retrieveProjectConfigurations(workspaceRoot, nxJson, plugins) {
@@ -68,16 +69,18 @@ const projectsWithoutPluginCache = new Map();
68
69
  // TODO: This function is called way too often, it should be optimized without this cache
69
70
  async function retrieveProjectConfigurationsWithoutPluginInference(root) {
70
71
  const nxJson = (0, nx_json_1.readNxJson)(root);
71
- const [plugins, cleanup] = await (0, internal_api_1.loadNxPluginsInIsolation)([]); // only load default plugins
72
+ const plugins = await (0, nx_plugin_1.getDefaultPlugins)(root);
72
73
  const projectGlobPatterns = retrieveProjectConfigurationPaths(root, plugins);
73
74
  const cacheKey = root + ',' + projectGlobPatterns.join(',');
74
75
  if (projectsWithoutPluginCache.has(cacheKey)) {
75
76
  return projectsWithoutPluginCache.get(cacheKey);
76
77
  }
77
78
  const projectFiles = (0, workspace_context_1.globWithWorkspaceContext)(root, projectGlobPatterns);
78
- const { projects } = await createProjectConfigurations(root, nxJson, projectFiles, plugins);
79
+ const { projects } = await createProjectConfigurations(root, nxJson, projectFiles, [
80
+ { plugin: (0, package_json_workspaces_1.getNxPackageJsonWorkspacesPlugin)(root) },
81
+ { plugin: project_json_1.ProjectJsonProjectsPlugin },
82
+ ]);
79
83
  projectsWithoutPluginCache.set(cacheKey, projects);
80
- cleanup();
81
84
  return projects;
82
85
  }
83
86
  exports.retrieveProjectConfigurationsWithoutPluginInference = retrieveProjectConfigurationsWithoutPluginInference;
@@ -96,8 +99,8 @@ async function createProjectConfigurations(workspaceRoot, nxJson, configFiles, p
96
99
  exports.createProjectConfigurations = createProjectConfigurations;
97
100
  function configurationGlobs(plugins) {
98
101
  const globPatterns = [];
99
- for (const plugin of plugins) {
100
- if ('createNodes' in plugin && plugin.createNodes) {
102
+ for (const { plugin } of plugins) {
103
+ if (plugin.createNodes) {
101
104
  globPatterns.push(plugin.createNodes[0]);
102
105
  }
103
106
  }
@@ -7,6 +7,5 @@ export declare const logger: {
7
7
  log: (...s: any[]) => void;
8
8
  debug: (...s: any[]) => void;
9
9
  fatal: (...s: any[]) => void;
10
- verbose: (...s: any[]) => void;
11
10
  };
12
11
  export declare function stripIndent(str: string): string;
@@ -34,11 +34,6 @@ exports.logger = {
34
34
  fatal: (...s) => {
35
35
  console.error(...s);
36
36
  },
37
- verbose: (...s) => {
38
- if (process.env.NX_VERBOSE_LOGGING) {
39
- console.log(...s);
40
- }
41
- },
42
37
  };
43
38
  function stripIndent(str) {
44
39
  const match = str.match(/^[ \t]*(?=\S)/gm);
@@ -1,8 +1,9 @@
1
- import { NxPluginV1 } from '../../utils/nx-plugin.deprecated';
2
- import { FileMap, ProjectGraph, ProjectGraphExternalNode } from '../../config/project-graph';
3
- import { ProjectConfiguration } from '../../config/workspace-json-project-json';
4
- import { NxJsonConfiguration } from '../../config/nx-json';
5
- import { RawProjectGraphDependency } from '../project-graph-builder';
1
+ import { FileMap, ProjectGraph, ProjectGraphExternalNode } from '../config/project-graph';
2
+ import { PackageJson } from './package-json';
3
+ import { ProjectConfiguration } from '../config/workspace-json-project-json';
4
+ import { NxJsonConfiguration, PluginConfiguration } from '../config/nx-json';
5
+ import { NxPluginV1 } from './nx-plugin.deprecated';
6
+ import { RawProjectGraphDependency } from '../project-graph/project-graph-builder';
6
7
  /**
7
8
  * Context for {@link CreateNodesFunction}
8
9
  */
@@ -15,7 +16,6 @@ export interface CreateNodesContext {
15
16
  * Used for creating nodes for the {@link ProjectGraph}
16
17
  */
17
18
  export type CreateNodesFunction<T = unknown> = (projectConfigurationFile: string, options: T | undefined, context: CreateNodesContext) => CreateNodesResult | Promise<CreateNodesResult>;
18
- export type Optional<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
19
19
  export interface CreateNodesResult {
20
20
  /**
21
21
  * A map of project root -> project configuration
@@ -73,13 +73,47 @@ export type NxPluginV2<TOptions = unknown> = {
73
73
  * Provides a file pattern and function that retrieves configuration info from
74
74
  * those files. e.g. { '**\/*.csproj': buildProjectsFromCsProjFile }
75
75
  */
76
- createNodes?: CreateNodes<TOptions>;
76
+ createNodes?: CreateNodes;
77
77
  /**
78
78
  * Provides a function to analyze files to create dependencies for the {@link ProjectGraph}
79
79
  */
80
80
  createDependencies?: CreateDependencies<TOptions>;
81
81
  };
82
+ export * from './nx-plugin.deprecated';
82
83
  /**
83
84
  * A plugin for Nx
84
85
  */
85
86
  export type NxPlugin = NxPluginV1 | NxPluginV2;
87
+ export type LoadedNxPlugin = {
88
+ plugin: NxPluginV2 & Pick<NxPluginV1, 'processProjectGraph'>;
89
+ options?: unknown;
90
+ };
91
+ export declare const nxPluginCache: Map<string, LoadedNxPlugin['plugin']>;
92
+ export declare function getPluginPathAndName(moduleName: string, paths: string[], projects: Record<string, ProjectConfiguration>, root: string): {
93
+ pluginPath: string;
94
+ name: any;
95
+ };
96
+ export declare function loadNxPluginAsync(pluginConfiguration: PluginConfiguration, paths: string[], projects: Record<string, ProjectConfiguration>, root: string): Promise<LoadedNxPlugin>;
97
+ export declare function loadNxPlugins(plugins: PluginConfiguration[], paths?: string[], root?: string, projects?: Record<string, ProjectConfiguration>): Promise<LoadedNxPlugin[]>;
98
+ export declare function ensurePluginIsV2(plugin: NxPlugin): NxPluginV2;
99
+ export declare function isNxPluginV2(plugin: NxPlugin): plugin is NxPluginV2;
100
+ export declare function isNxPluginV1(plugin: NxPlugin): plugin is NxPluginV1;
101
+ export declare function readPluginPackageJson(pluginName: string, projects: Record<string, ProjectConfiguration>, paths?: string[]): {
102
+ path: string;
103
+ json: PackageJson;
104
+ };
105
+ export declare function resolveLocalNxPlugin(importPath: string, nxJsonConfiguration: NxJsonConfiguration, projects: Record<string, ProjectConfiguration>, root?: string): {
106
+ path: string;
107
+ projectConfig: ProjectConfiguration;
108
+ } | null;
109
+ /**
110
+ * Register swc-node or ts-node if they are not currently registered
111
+ * with some default settings which work well for Nx plugins.
112
+ */
113
+ export declare function registerPluginTSTranspiler(): void;
114
+ /**
115
+ * Unregister the ts-node transpiler if it is registered
116
+ */
117
+ export declare function unregisterPluginTSTranspiler(): void;
118
+ export declare function getDefaultPlugins(root: string): Promise<LoadedNxPlugin[]>;
119
+ type Optional<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
@@ -1,6 +1,6 @@
1
1
  import { ProjectGraphProcessor } from '../config/project-graph';
2
2
  import { TargetConfiguration } from '../config/workspace-json-project-json';
3
- import { NxPluginV2 } from '../project-graph/plugins';
3
+ import { LoadedNxPlugin } from './nx-plugin';
4
4
  /**
5
5
  * @deprecated Add targets to the projects in a {@link CreateNodes} function instead. This will be removed in Nx 19
6
6
  */
@@ -28,6 +28,4 @@ export type NxPluginV1 = {
28
28
  /**
29
29
  * @todo(@agentender) v19: Remove this fn when we remove readWorkspaceConfig
30
30
  */
31
- export declare function getDefaultPluginsSync(root: string): {
32
- plugin: NxPluginV2;
33
- }[];
31
+ export declare function getDefaultPluginsSync(root: string): LoadedNxPlugin[];
@@ -4,7 +4,7 @@ exports.getDefaultPluginsSync = void 0;
4
4
  const angular_json_1 = require("../adapter/angular-json");
5
5
  const project_json_1 = require("../plugins/project-json/build-nodes/project-json");
6
6
  const target_defaults_plugin_1 = require("../plugins/target-defaults/target-defaults-plugin");
7
- const PackageJsonWorkspacesPlugin = require("../plugins/package-json-workspaces");
7
+ const package_json_workspaces_1 = require("../plugins/package-json-workspaces");
8
8
  /**
9
9
  * @todo(@agentender) v19: Remove this fn when we remove readWorkspaceConfig
10
10
  */
@@ -14,9 +14,9 @@ function getDefaultPluginsSync(root) {
14
14
  ...((0, angular_json_1.shouldMergeAngularProjects)(root, false)
15
15
  ? [require('../adapter/angular-json').NxAngularJsonPlugin]
16
16
  : []),
17
- target_defaults_plugin_1.default,
18
- PackageJsonWorkspacesPlugin,
19
- project_json_1.default,
17
+ target_defaults_plugin_1.TargetDefaultsPlugin,
18
+ (0, package_json_workspaces_1.getNxPackageJsonWorkspacesPlugin)(root),
19
+ project_json_1.ProjectJsonProjectsPlugin,
20
20
  ];
21
21
  return plugins.map((p) => ({
22
22
  plugin: p,