nx 18.3.0-beta.0 → 18.3.0-beta.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.
Files changed (96) hide show
  1. package/bin/post-install.js +7 -5
  2. package/package.json +12 -12
  3. package/src/adapter/angular-json.d.ts +2 -1
  4. package/src/adapter/angular-json.js +1 -0
  5. package/src/adapter/ngcli-adapter.d.ts +2 -2
  6. package/src/adapter/ngcli-adapter.js +13 -13
  7. package/src/command-line/generate/generator-utils.js +2 -2
  8. package/src/command-line/init/implementation/add-nx-to-monorepo.js +1 -1
  9. package/src/command-line/init/implementation/add-nx-to-npm-repo.js +1 -1
  10. package/src/command-line/init/implementation/react/index.js +1 -1
  11. package/src/command-line/init/implementation/utils.d.ts +1 -1
  12. package/src/command-line/init/implementation/utils.js +2 -7
  13. package/src/command-line/init/init-v2.js +29 -37
  14. package/src/command-line/release/command-object.js +1 -1
  15. package/src/command-line/run/executor-utils.js +2 -2
  16. package/src/config/nx-json.d.ts +2 -1
  17. package/src/config/schema-utils.js +2 -2
  18. package/src/core/graph/3rdpartylicenses.txt +23 -26
  19. package/src/core/graph/main.js +1 -1
  20. package/src/core/graph/runtime.js +1 -1
  21. package/src/core/graph/styles.js +1 -1
  22. package/src/daemon/client/client.js +1 -2
  23. package/src/daemon/server/plugins.d.ts +3 -0
  24. package/src/daemon/server/plugins.js +22 -0
  25. package/src/daemon/server/project-graph-incremental-recomputation.js +11 -10
  26. package/src/daemon/server/shutdown-utils.js +2 -0
  27. package/src/devkit-exports.d.ts +3 -2
  28. package/src/devkit-internals.d.ts +3 -0
  29. package/src/devkit-internals.js +7 -1
  30. package/src/executors/run-commands/run-commands.impl.d.ts +4 -1
  31. package/src/executors/run-commands/run-commands.impl.js +51 -4
  32. package/src/executors/utils/convert-nx-executor.js +4 -1
  33. package/src/generators/utils/project-configuration.js +2 -2
  34. package/src/migrations/update-15-1-0/set-project-names.js +4 -2
  35. package/src/native/assert-supported-platform.js +1 -1
  36. package/src/plugins/js/index.d.ts +1 -1
  37. package/src/plugins/js/lock-file/lock-file.d.ts +1 -1
  38. package/src/plugins/js/lock-file/npm-parser.d.ts +1 -1
  39. package/src/plugins/js/lock-file/pnpm-parser.d.ts +1 -1
  40. package/src/plugins/js/lock-file/yarn-parser.d.ts +1 -1
  41. package/src/plugins/js/project-graph/build-dependencies/build-dependencies.d.ts +1 -1
  42. package/src/plugins/js/project-graph/build-dependencies/explicit-package-json-dependencies.d.ts +1 -1
  43. package/src/plugins/js/project-graph/build-dependencies/explicit-project-dependencies.d.ts +1 -1
  44. package/src/plugins/package-json-workspaces/create-nodes.d.ts +2 -2
  45. package/src/plugins/package-json-workspaces/create-nodes.js +24 -31
  46. package/src/plugins/package-json-workspaces/index.d.ts +1 -0
  47. package/src/plugins/package-json-workspaces/index.js +2 -0
  48. package/src/plugins/project-json/build-nodes/package-json-next-to-project-json.d.ts +2 -1
  49. package/src/plugins/project-json/build-nodes/package-json-next-to-project-json.js +1 -0
  50. package/src/plugins/project-json/build-nodes/project-json.d.ts +2 -1
  51. package/src/plugins/project-json/build-nodes/project-json.js +1 -0
  52. package/src/plugins/target-defaults/symbols.d.ts +17 -0
  53. package/src/plugins/target-defaults/symbols.js +20 -0
  54. package/src/plugins/target-defaults/target-defaults-plugin.d.ts +2 -18
  55. package/src/plugins/target-defaults/target-defaults-plugin.js +5 -20
  56. package/src/project-graph/affected/locators/project-glob-changes.js +3 -3
  57. package/src/project-graph/build-project-graph.d.ts +2 -1
  58. package/src/project-graph/build-project-graph.js +11 -13
  59. package/src/project-graph/error-types.d.ts +45 -0
  60. package/src/project-graph/error-types.js +100 -0
  61. package/src/project-graph/file-utils.js +3 -3
  62. package/src/project-graph/plugins/index.d.ts +2 -0
  63. package/src/project-graph/plugins/index.js +8 -0
  64. package/src/project-graph/plugins/internal-api.d.ts +28 -0
  65. package/src/project-graph/plugins/internal-api.js +85 -0
  66. package/src/project-graph/plugins/isolation/index.d.ts +3 -0
  67. package/src/project-graph/plugins/isolation/index.js +16 -0
  68. package/src/project-graph/plugins/isolation/messaging.d.ts +94 -0
  69. package/src/project-graph/plugins/isolation/messaging.js +23 -0
  70. package/src/project-graph/plugins/isolation/plugin-pool.d.ts +3 -0
  71. package/src/project-graph/plugins/isolation/plugin-pool.js +189 -0
  72. package/src/project-graph/plugins/isolation/plugin-worker.d.ts +1 -0
  73. package/src/project-graph/plugins/isolation/plugin-worker.js +81 -0
  74. package/src/project-graph/plugins/loader.d.ts +24 -0
  75. package/src/project-graph/plugins/loader.js +206 -0
  76. package/src/{utils/nx-plugin.d.ts → project-graph/plugins/public-api.d.ts} +8 -44
  77. package/src/project-graph/plugins/public-api.js +4 -0
  78. package/src/project-graph/plugins/utils.d.ts +7 -0
  79. package/src/project-graph/plugins/utils.js +80 -0
  80. package/src/project-graph/project-graph-builder.d.ts +1 -1
  81. package/src/project-graph/project-graph.d.ts +4 -3
  82. package/src/project-graph/project-graph.js +9 -7
  83. package/src/project-graph/utils/normalize-project-nodes.d.ts +1 -1
  84. package/src/project-graph/utils/project-configuration-utils.d.ts +3 -26
  85. package/src/project-graph/utils/project-configuration-utils.js +54 -109
  86. package/src/project-graph/utils/retrieve-workspace-files.d.ts +11 -10
  87. package/src/project-graph/utils/retrieve-workspace-files.js +19 -26
  88. package/src/tasks-runner/cache.js +1 -1
  89. package/src/utils/is-ci.js +1 -1
  90. package/src/utils/logger.d.ts +1 -0
  91. package/src/utils/logger.js +5 -0
  92. package/src/utils/nx-plugin.deprecated.d.ts +2 -2
  93. package/src/utils/nx-plugin.deprecated.js +5 -7
  94. package/src/utils/plugins/plugin-capabilities.d.ts +1 -1
  95. package/src/utils/plugins/plugin-capabilities.js +18 -12
  96. package/src/utils/nx-plugin.js +0 -309
@@ -0,0 +1,80 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.runCreateNodesInParallel = exports.normalizeNxPlugin = exports.isNxPluginV1 = exports.isNxPluginV2 = void 0;
4
+ const node_path_1 = require("node:path");
5
+ const workspaces_1 = require("../../config/workspaces");
6
+ const globs_1 = require("../../utils/globs");
7
+ const error_types_1 = require("../error-types");
8
+ function isNxPluginV2(plugin) {
9
+ return 'createNodes' in plugin || 'createDependencies' in plugin;
10
+ }
11
+ exports.isNxPluginV2 = isNxPluginV2;
12
+ function isNxPluginV1(plugin) {
13
+ return 'processProjectGraph' in plugin || 'projectFilePatterns' in plugin;
14
+ }
15
+ exports.isNxPluginV1 = isNxPluginV1;
16
+ function normalizeNxPlugin(plugin) {
17
+ if (isNxPluginV2(plugin)) {
18
+ return plugin;
19
+ }
20
+ if (isNxPluginV1(plugin) && plugin.projectFilePatterns) {
21
+ return {
22
+ ...plugin,
23
+ createNodes: [
24
+ `*/**/${(0, globs_1.combineGlobPatterns)(plugin.projectFilePatterns)}`,
25
+ (configFilePath) => {
26
+ const root = (0, node_path_1.dirname)(configFilePath);
27
+ return {
28
+ projects: {
29
+ [root]: {
30
+ name: (0, workspaces_1.toProjectName)(configFilePath),
31
+ targets: plugin.registerProjectTargets?.(configFilePath),
32
+ },
33
+ },
34
+ };
35
+ },
36
+ ],
37
+ };
38
+ }
39
+ return plugin;
40
+ }
41
+ exports.normalizeNxPlugin = normalizeNxPlugin;
42
+ async function runCreateNodesInParallel(configFiles, plugin, options, context) {
43
+ performance.mark(`${plugin.name}:createNodes - start`);
44
+ const errors = [];
45
+ const results = [];
46
+ const promises = configFiles.map((file) => {
47
+ performance.mark(`${plugin.name}:createNodes:${file} - start`);
48
+ // Result is either static or a promise, using Promise.resolve lets us
49
+ // handle both cases with same logic
50
+ const value = Promise.resolve(plugin.createNodes[1](file, options, context));
51
+ return value
52
+ .catch((e) => {
53
+ performance.mark(`${plugin.name}:createNodes:${file} - end`);
54
+ errors.push(new error_types_1.CreateNodesError({
55
+ error: e,
56
+ pluginName: plugin.name,
57
+ file,
58
+ }));
59
+ return null;
60
+ })
61
+ .then((r) => {
62
+ performance.mark(`${plugin.name}:createNodes:${file} - end`);
63
+ performance.measure(`${plugin.name}:createNodes:${file}`, `${plugin.name}:createNodes:${file} - start`, `${plugin.name}:createNodes:${file} - end`);
64
+ // Existing behavior is to ignore null results of
65
+ // createNodes function.
66
+ if (r) {
67
+ results.push(r);
68
+ }
69
+ });
70
+ });
71
+ await Promise.all(promises).then(() => {
72
+ performance.mark(`${plugin.name}:createNodes - end`);
73
+ performance.measure(`${plugin.name}:createNodes`, `${plugin.name}:createNodes - start`, `${plugin.name}:createNodes - end`);
74
+ });
75
+ if (errors.length > 0) {
76
+ throw new error_types_1.AggregateCreateNodesError(plugin.name, errors, results);
77
+ }
78
+ return results;
79
+ }
80
+ exports.runCreateNodesInParallel = runCreateNodesInParallel;
@@ -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 '../utils/nx-plugin';
5
+ import { CreateDependenciesContext } from './plugins';
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.
@@ -1,7 +1,8 @@
1
1
  import { ProcessDependenciesError, ProcessProjectGraphError } from './build-project-graph';
2
2
  import { ProjectGraph } from '../config/project-graph';
3
3
  import { ProjectConfiguration, ProjectsConfigurations } from '../config/workspace-json-project-json';
4
- import { ConfigurationSourceMaps, CreateNodesError, MergeNodesError } from './utils/project-configuration-utils';
4
+ import { ConfigurationSourceMaps } from './utils/project-configuration-utils';
5
+ import { CreateNodesError, MergeNodesError, ProjectsWithNoNameError, ProjectsWithConflictingNamesError } from './error-types';
5
6
  import { DaemonProjectGraphError } from '../daemon/daemon-project-graph-error';
6
7
  /**
7
8
  * Synchronously reads the latest cached copy of the workspace's ProjectGraph.
@@ -19,7 +20,7 @@ export declare function buildProjectGraphAndSourceMapsWithoutDaemon(): Promise<{
19
20
  }>;
20
21
  export declare class ProjectGraphError extends Error {
21
22
  #private;
22
- constructor(errors: Array<CreateNodesError | MergeNodesError | ProcessDependenciesError | ProcessProjectGraphError>, partialProjectGraph: ProjectGraph, partialSourceMaps: ConfigurationSourceMaps);
23
+ constructor(errors: Array<CreateNodesError | MergeNodesError | ProjectsWithNoNameError | ProjectsWithConflictingNamesError | ProcessDependenciesError | ProcessProjectGraphError>, partialProjectGraph: ProjectGraph, partialSourceMaps: ConfigurationSourceMaps);
23
24
  /**
24
25
  * The daemon cannot throw errors which contain methods as they are not serializable.
25
26
  *
@@ -33,7 +34,7 @@ export declare class ProjectGraphError extends Error {
33
34
  */
34
35
  getPartialProjectGraph(): ProjectGraph;
35
36
  getPartialSourcemaps(): ConfigurationSourceMaps;
36
- getErrors(): (ProcessDependenciesError | ProcessProjectGraphError | CreateNodesError)[];
37
+ getErrors(): (ProjectsWithConflictingNamesError | ProjectsWithNoNameError | MergeNodesError | CreateNodesError | ProcessDependenciesError | ProcessProjectGraphError)[];
37
38
  }
38
39
  /**
39
40
  * Computes and returns a ProjectGraph.
@@ -14,8 +14,8 @@ const workspace_root_1 = require("../utils/workspace-root");
14
14
  const perf_hooks_1 = require("perf_hooks");
15
15
  const retrieve_workspace_files_1 = require("./utils/retrieve-workspace-files");
16
16
  const nx_json_1 = require("../config/nx-json");
17
- const nx_plugin_1 = require("../utils/nx-plugin");
18
- const project_configuration_utils_1 = require("./utils/project-configuration-utils");
17
+ const error_types_1 = require("./error-types");
18
+ const internal_api_1 = require("./plugins/internal-api");
19
19
  /**
20
20
  * Synchronously reads the latest cached copy of the workspace's ProjectGraph.
21
21
  * @throws {Error} if there is no cached ProjectGraph to read from
@@ -69,17 +69,17 @@ function readProjectsConfigurationFromProjectGraph(projectGraph) {
69
69
  }
70
70
  exports.readProjectsConfigurationFromProjectGraph = readProjectsConfigurationFromProjectGraph;
71
71
  async function buildProjectGraphAndSourceMapsWithoutDaemon() {
72
- // Set this globally to allow plugins to know if they are being called from the project graph creation
73
72
  global.NX_GRAPH_CREATION = true;
74
73
  const nxJson = (0, nx_json_1.readNxJson)();
75
74
  perf_hooks_1.performance.mark('retrieve-project-configurations:start');
76
75
  let configurationResult;
77
76
  let projectConfigurationsError;
77
+ const [plugins, cleanup] = await (0, internal_api_1.loadNxPlugins)(nxJson.plugins);
78
78
  try {
79
- configurationResult = await (0, retrieve_workspace_files_1.retrieveProjectConfigurations)(workspace_root_1.workspaceRoot, nxJson);
79
+ configurationResult = await (0, retrieve_workspace_files_1.retrieveProjectConfigurations)(plugins, workspace_root_1.workspaceRoot, nxJson);
80
80
  }
81
81
  catch (e) {
82
- if (e instanceof project_configuration_utils_1.ProjectConfigurationsError) {
82
+ if (e instanceof error_types_1.ProjectConfigurationsError) {
83
83
  projectConfigurationsError = e;
84
84
  configurationResult = e.partialProjectConfigurationsResult;
85
85
  }
@@ -97,7 +97,7 @@ async function buildProjectGraphAndSourceMapsWithoutDaemon() {
97
97
  let createDependenciesError;
98
98
  let projectGraphResult;
99
99
  try {
100
- projectGraphResult = await (0, build_project_graph_1.buildProjectGraphUsingProjectFileMap)(projects, externalNodes, fileMap, allWorkspaceFiles, rustReferences, cacheEnabled ? (0, nx_deps_cache_1.readFileMapCache)() : null);
100
+ projectGraphResult = await (0, build_project_graph_1.buildProjectGraphUsingProjectFileMap)(projects, externalNodes, fileMap, allWorkspaceFiles, rustReferences, cacheEnabled ? (0, nx_deps_cache_1.readFileMapCache)() : null, plugins);
101
101
  }
102
102
  catch (e) {
103
103
  if (e instanceof build_project_graph_1.CreateDependenciesError) {
@@ -111,9 +111,11 @@ async function buildProjectGraphAndSourceMapsWithoutDaemon() {
111
111
  throw e;
112
112
  }
113
113
  }
114
+ finally {
115
+ cleanup();
116
+ }
114
117
  const { projectGraph, projectFileMapCache } = projectGraphResult;
115
118
  perf_hooks_1.performance.mark('build-project-graph-using-project-file-map:end');
116
- (0, nx_plugin_1.unregisterPluginTSTranspiler)();
117
119
  delete global.NX_GRAPH_CREATION;
118
120
  const errors = [
119
121
  ...(projectConfigurationsError?.errors ?? []),
@@ -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 '../../utils/nx-plugin';
4
+ import { CreateDependenciesContext } from '../plugins';
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';
5
- import { ONLY_MODIFIES_EXISTING_TARGET } from '../../plugins/target-defaults/target-defaults-plugin';
4
+ import { ONLY_MODIFIES_EXISTING_TARGET } from '../../plugins/target-defaults/symbols';
5
+ import { LoadedNxPlugin } 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 & {
@@ -24,32 +24,9 @@ export type ConfigurationResult = {
24
24
  * @param workspaceFiles A list of non-ignored workspace files
25
25
  * @param plugins The plugins that should be used to infer project configuration
26
26
  */
27
- export declare function createProjectConfigurations(root: string, nxJson: NxJsonConfiguration, workspaceFiles: string[], // making this parameter allows devkit to pick up newly created projects
27
+ export declare function createProjectConfigurations(root: string, nxJson: NxJsonConfiguration, projectFiles: string[], // making this parameter allows devkit to pick up newly created projects
28
28
  plugins: LoadedNxPlugin[]): Promise<ConfigurationResult>;
29
29
  export declare function readProjectConfigurationsFromRootMap(projectRootMap: Map<string, ProjectConfiguration>): Record<string, ProjectConfiguration>;
30
- export declare class ProjectConfigurationsError extends Error {
31
- readonly errors: Array<MergeNodesError | CreateNodesError>;
32
- readonly partialProjectConfigurationsResult: ConfigurationResult;
33
- constructor(errors: Array<MergeNodesError | CreateNodesError>, partialProjectConfigurationsResult: ConfigurationResult);
34
- }
35
- export declare class CreateNodesError extends Error {
36
- file: string;
37
- pluginName: string;
38
- constructor({ file, pluginName, error, }: {
39
- file: string;
40
- pluginName: string;
41
- error: Error;
42
- });
43
- }
44
- export declare class MergeNodesError extends Error {
45
- file: string;
46
- pluginName: string;
47
- constructor({ file, pluginName, error, }: {
48
- file: string;
49
- pluginName: string;
50
- error: Error;
51
- });
52
- }
53
30
  /**
54
31
  * Merges two targets.
55
32
  *
@@ -1,13 +1,14 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.readTargetDefaultsForTarget = exports.resolveNxTokensInOptions = exports.isCompatibleTarget = exports.mergeTargetConfigurations = exports.MergeNodesError = exports.CreateNodesError = exports.ProjectConfigurationsError = exports.readProjectConfigurationsFromRootMap = exports.createProjectConfigurations = exports.mergeProjectConfigurationIntoRootMap = void 0;
3
+ exports.readTargetDefaultsForTarget = exports.resolveNxTokensInOptions = exports.isCompatibleTarget = exports.mergeTargetConfigurations = exports.readProjectConfigurationsFromRootMap = exports.createProjectConfigurations = exports.mergeProjectConfigurationIntoRootMap = void 0;
4
4
  const logger_1 = require("../../utils/logger");
5
5
  const fileutils_1 = require("../../utils/fileutils");
6
6
  const workspace_root_1 = require("../../utils/workspace-root");
7
- const target_defaults_plugin_1 = require("../../plugins/target-defaults/target-defaults-plugin");
7
+ const symbols_1 = require("../../plugins/target-defaults/symbols");
8
8
  const minimatch_1 = require("minimatch");
9
9
  const path_1 = require("path");
10
10
  const perf_hooks_1 = require("perf_hooks");
11
+ const error_types_1 = require("../error-types");
11
12
  function mergeProjectConfigurationIntoRootMap(projectRootMap, project, configurationSourceMaps, sourceInformation,
12
13
  // This function is used when reading project configuration
13
14
  // in generators, where we don't want to do this.
@@ -119,12 +120,12 @@ skipCommandNormalization) {
119
120
  // Always set source map info for the target, but don't overwrite info already there
120
121
  // if augmenting an existing target.
121
122
  const target = project.targets?.[targetName];
122
- if (sourceMap && !target?.[target_defaults_plugin_1.ONLY_MODIFIES_EXISTING_TARGET]) {
123
+ if (sourceMap && !target?.[symbols_1.ONLY_MODIFIES_EXISTING_TARGET]) {
123
124
  sourceMap[`targets.${targetName}`] = sourceInformation;
124
125
  }
125
126
  // If ONLY_MODIFIES_EXISTING_TARGET is true, and its not on the matching project
126
127
  // we shouldn't merge its info into the graph
127
- if (target?.[target_defaults_plugin_1.ONLY_MODIFIES_EXISTING_TARGET] &&
128
+ if (target?.[symbols_1.ONLY_MODIFIES_EXISTING_TARGET] &&
128
129
  !matchingProject.targets?.[targetName]) {
129
130
  continue;
130
131
  }
@@ -132,8 +133,8 @@ skipCommandNormalization) {
132
133
  ? target
133
134
  : resolveCommandSyntacticSugar(target, project.root), matchingProject.targets?.[targetName], sourceMap, sourceInformation, `targets.${targetName}`);
134
135
  // We don't want the symbol to live on past the merge process
135
- if (mergedTarget?.[target_defaults_plugin_1.ONLY_MODIFIES_EXISTING_TARGET])
136
- delete mergedTarget?.[target_defaults_plugin_1.ONLY_MODIFIES_EXISTING_TARGET];
136
+ if (mergedTarget?.[symbols_1.ONLY_MODIFIES_EXISTING_TARGET])
137
+ delete mergedTarget?.[symbols_1.ONLY_MODIFIES_EXISTING_TARGET];
137
138
  updatedProjectConfiguration.targets[targetName] = mergedTarget;
138
139
  }
139
140
  }
@@ -217,21 +218,19 @@ function mergeMetadata(sourceMap, sourceInformation, baseSourceMapPath, metadata
217
218
  * @param workspaceFiles A list of non-ignored workspace files
218
219
  * @param plugins The plugins that should be used to infer project configuration
219
220
  */
220
- function createProjectConfigurations(root = workspace_root_1.workspaceRoot, nxJson, workspaceFiles, // making this parameter allows devkit to pick up newly created projects
221
+ async function createProjectConfigurations(root = workspace_root_1.workspaceRoot, nxJson, projectFiles, // making this parameter allows devkit to pick up newly created projects
221
222
  plugins) {
222
223
  perf_hooks_1.performance.mark('build-project-configs:start');
223
224
  const results = [];
224
225
  const errors = [];
225
226
  // We iterate over plugins first - this ensures that plugins specified first take precedence.
226
- for (const { plugin, options, include, exclude } of plugins) {
227
- const [pattern, createNodes] = plugin.createNodes ?? [];
228
- const pluginResults = [];
229
- perf_hooks_1.performance.mark(`${plugin.name}:createNodes - start`);
227
+ for (const { name: pluginName, createNodes: createNodesTuple, include, exclude, } of plugins) {
228
+ const [pattern, createNodes] = createNodesTuple ?? [];
230
229
  if (!pattern) {
231
230
  continue;
232
231
  }
233
232
  const matchingConfigFiles = [];
234
- for (const file of workspaceFiles) {
233
+ for (const file of projectFiles) {
235
234
  if ((0, minimatch_1.minimatch)(file, pattern, { dot: true })) {
236
235
  if (include) {
237
236
  const included = include.some((includedPattern) => (0, minimatch_1.minimatch)(file, includedPattern, { dot: true }));
@@ -240,7 +239,7 @@ plugins) {
240
239
  }
241
240
  }
242
241
  if (exclude) {
243
- const excluded = include.some((excludedPattern) => (0, minimatch_1.minimatch)(file, excludedPattern, { dot: true }));
242
+ const excluded = exclude.some((excludedPattern) => (0, minimatch_1.minimatch)(file, excludedPattern, { dot: true }));
244
243
  if (excluded) {
245
244
  continue;
246
245
  }
@@ -248,56 +247,20 @@ plugins) {
248
247
  matchingConfigFiles.push(file);
249
248
  }
250
249
  }
251
- for (const file of matchingConfigFiles) {
252
- perf_hooks_1.performance.mark(`${plugin.name}:createNodes:${file} - start`);
253
- try {
254
- let r = createNodes(file, options, {
255
- nxJsonConfiguration: nxJson,
256
- workspaceRoot: root,
257
- configFiles: matchingConfigFiles,
258
- });
259
- if (r instanceof Promise) {
260
- pluginResults.push(r
261
- .catch((error) => {
262
- perf_hooks_1.performance.mark(`${plugin.name}:createNodes:${file} - end`);
263
- errors.push(new CreateNodesError({
264
- file,
265
- pluginName: plugin.name,
266
- error,
267
- }));
268
- return {
269
- projects: {},
270
- };
271
- })
272
- .then((r) => {
273
- perf_hooks_1.performance.mark(`${plugin.name}:createNodes:${file} - end`);
274
- perf_hooks_1.performance.measure(`${plugin.name}:createNodes:${file}`, `${plugin.name}:createNodes:${file} - start`, `${plugin.name}:createNodes:${file} - end`);
275
- return { ...r, file, pluginName: plugin.name };
276
- }));
277
- }
278
- else {
279
- perf_hooks_1.performance.mark(`${plugin.name}:createNodes:${file} - end`);
280
- perf_hooks_1.performance.measure(`${plugin.name}:createNodes:${file}`, `${plugin.name}:createNodes:${file} - start`, `${plugin.name}:createNodes:${file} - end`);
281
- pluginResults.push({
282
- ...r,
283
- file,
284
- pluginName: plugin.name,
285
- });
286
- }
250
+ let r = createNodes(matchingConfigFiles, {
251
+ nxJsonConfiguration: nxJson,
252
+ workspaceRoot: root,
253
+ configFiles: matchingConfigFiles,
254
+ }).catch((e) => {
255
+ if ((0, error_types_1.isAggregateCreateNodesError)(e)) {
256
+ errors.push(...e.errors);
257
+ return e.partialResults;
287
258
  }
288
- catch (error) {
289
- errors.push(new CreateNodesError({
290
- file,
291
- pluginName: plugin.name,
292
- error,
293
- }));
259
+ else {
260
+ throw e;
294
261
  }
295
- }
296
- results.push(Promise.all(pluginResults).then((results) => {
297
- perf_hooks_1.performance.mark(`${plugin.name}:createNodes - end`);
298
- perf_hooks_1.performance.measure(`${plugin.name}:createNodes`, `${plugin.name}:createNodes - start`, `${plugin.name}:createNodes - end`);
299
- return results;
300
- }));
262
+ });
263
+ results.push(r);
301
264
  }
302
265
  return Promise.all(results).then((results) => {
303
266
  perf_hooks_1.performance.mark('createNodes:merge - start');
@@ -307,8 +270,8 @@ plugins) {
307
270
  for (const result of results.flat()) {
308
271
  const { projects: projectNodes, externalNodes: pluginExternalNodes, file, pluginName, } = result;
309
272
  const sourceInfo = [file, pluginName];
310
- if (result[target_defaults_plugin_1.OVERRIDE_SOURCE_FILE]) {
311
- sourceInfo[0] = result[target_defaults_plugin_1.OVERRIDE_SOURCE_FILE];
273
+ if (result[symbols_1.OVERRIDE_SOURCE_FILE]) {
274
+ sourceInfo[0] = result[symbols_1.OVERRIDE_SOURCE_FILE];
312
275
  }
313
276
  for (const node in projectNodes) {
314
277
  const project = {
@@ -319,7 +282,7 @@ plugins) {
319
282
  mergeProjectConfigurationIntoRootMap(projectRootMap, project, configurationSourceMaps, sourceInfo);
320
283
  }
321
284
  catch (error) {
322
- errors.push(new MergeNodesError({
285
+ errors.push(new error_types_1.MergeNodesError({
323
286
  file,
324
287
  pluginName,
325
288
  error,
@@ -328,7 +291,20 @@ plugins) {
328
291
  }
329
292
  Object.assign(externalNodes, pluginExternalNodes);
330
293
  }
331
- const projects = readProjectConfigurationsFromRootMap(projectRootMap);
294
+ let projects;
295
+ try {
296
+ projects = readProjectConfigurationsFromRootMap(projectRootMap);
297
+ }
298
+ catch (e) {
299
+ if ((0, error_types_1.isProjectsWithNoNameError)(e) ||
300
+ (0, error_types_1.isProjectsWithConflictingNamesError)(e)) {
301
+ projects = e.projects;
302
+ errors.push(e);
303
+ }
304
+ else {
305
+ throw e;
306
+ }
307
+ }
332
308
  const rootMap = createRootMap(projectRootMap);
333
309
  perf_hooks_1.performance.mark('createNodes:merge - end');
334
310
  perf_hooks_1.performance.measure('createNodes:merge', 'createNodes:merge - start', 'createNodes:merge - end');
@@ -343,7 +319,7 @@ plugins) {
343
319
  };
344
320
  }
345
321
  else {
346
- throw new ProjectConfigurationsError(errors, {
322
+ throw new error_types_1.ProjectConfigurationsError(errors, {
347
323
  projects,
348
324
  externalNodes,
349
325
  projectRootMap: rootMap,
@@ -358,7 +334,8 @@ function readProjectConfigurationsFromRootMap(projectRootMap) {
358
334
  // If there are projects that have the same name, that is an error.
359
335
  // This object tracks name -> (all roots of projects with that name)
360
336
  // to provide better error messaging.
361
- const errors = new Map();
337
+ const conflicts = new Map();
338
+ const projectRootsWithNoName = [];
362
339
  for (const [root, configuration] of projectRootMap.entries()) {
363
340
  // We're setting `// targets` as a comment `targets` is empty due to Project Crystal.
364
341
  // Strip it before returning configuration for usage.
@@ -370,62 +347,30 @@ function readProjectConfigurationsFromRootMap(projectRootMap) {
370
347
  configuration.name = name;
371
348
  }
372
349
  catch {
373
- throw new Error(`Project at ${root} has no name provided.`);
350
+ projectRootsWithNoName.push(root);
374
351
  }
375
352
  }
376
353
  if (configuration.name in projects) {
377
- let rootErrors = errors.get(configuration.name) ?? [
354
+ let rootErrors = conflicts.get(configuration.name) ?? [
378
355
  projects[configuration.name].root,
379
356
  ];
380
357
  rootErrors.push(root);
381
- errors.set(configuration.name, rootErrors);
358
+ conflicts.set(configuration.name, rootErrors);
359
+ projects[configuration.name] = configuration;
382
360
  }
383
361
  else {
384
362
  projects[configuration.name] = configuration;
385
363
  }
386
364
  }
387
- if (errors.size > 0) {
388
- throw new Error([
389
- `The following projects are defined in multiple locations:`,
390
- ...Array.from(errors.entries()).map(([project, roots]) => [`- ${project}: `, ...roots.map((r) => ` - ${r}`)].join('\n')),
391
- '',
392
- "To fix this, set a unique name for each project in a project.json inside the project's root. If the project does not currently have a project.json, you can create one that contains only a name.",
393
- ].join('\n'));
365
+ if (conflicts.size > 0) {
366
+ throw new error_types_1.ProjectsWithConflictingNamesError(conflicts, projects);
367
+ }
368
+ if (projectRootsWithNoName.length > 0) {
369
+ throw new error_types_1.ProjectsWithNoNameError(projectRootsWithNoName, projects);
394
370
  }
395
371
  return projects;
396
372
  }
397
373
  exports.readProjectConfigurationsFromRootMap = readProjectConfigurationsFromRootMap;
398
- class ProjectConfigurationsError extends Error {
399
- constructor(errors, partialProjectConfigurationsResult) {
400
- super('Failed to create project configurations');
401
- this.errors = errors;
402
- this.partialProjectConfigurationsResult = partialProjectConfigurationsResult;
403
- this.name = this.constructor.name;
404
- }
405
- }
406
- exports.ProjectConfigurationsError = ProjectConfigurationsError;
407
- class CreateNodesError extends Error {
408
- constructor({ file, pluginName, error, }) {
409
- const msg = `The "${pluginName}" plugin threw an error while creating nodes from ${file}:`;
410
- super(msg, { cause: error });
411
- this.name = this.constructor.name;
412
- this.file = file;
413
- this.pluginName = pluginName;
414
- this.stack = `${this.message}\n ${error.stack.split('\n').join('\n ')}`;
415
- }
416
- }
417
- exports.CreateNodesError = CreateNodesError;
418
- class MergeNodesError extends Error {
419
- constructor({ file, pluginName, error, }) {
420
- const msg = `The nodes created from ${file} by the "${pluginName}" could not be merged into the project graph:`;
421
- super(msg, { cause: error });
422
- this.name = this.constructor.name;
423
- this.file = file;
424
- this.pluginName = pluginName;
425
- this.stack = `${this.message}\n ${error.stack.split('\n').join('\n ')}`;
426
- }
427
- }
428
- exports.MergeNodesError = MergeNodesError;
429
374
  /**
430
375
  * Merges two targets.
431
376
  *
@@ -448,7 +393,7 @@ function mergeTargetConfigurations(target, baseTarget, projectConfigSourceMap, s
448
393
  // with the new one. However, we have a special case for targets that have the
449
394
  // ONLY_MODIFIES_EXISTING_TARGET symbol set. This prevents the merged target
450
395
  // equaling info that should have only been used to modify the existing target.
451
- if (!isCompatible && target[target_defaults_plugin_1.ONLY_MODIFIES_EXISTING_TARGET]) {
396
+ if (!isCompatible && target[symbols_1.ONLY_MODIFIES_EXISTING_TARGET]) {
452
397
  return baseTarget;
453
398
  }
454
399
  if (!isCompatible && projectConfigSourceMap) {
@@ -1,7 +1,7 @@
1
1
  import { ProjectConfiguration } from '../../config/workspace-json-project-json';
2
2
  import { NxJsonConfiguration } from '../../config/nx-json';
3
3
  import { ConfigurationResult } from './project-configuration-utils';
4
- import { LoadedNxPlugin } from '../../utils/nx-plugin';
4
+ import { LoadedNxPlugin } from '../plugins/internal-api';
5
5
  /**
6
6
  * Walks the workspace directory to create the `projectFileMap`, `ProjectConfigurations` and `allWorkspaceFiles`
7
7
  * @throws
@@ -9,21 +9,22 @@ 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.
21
- *
22
- * @param workspaceRoot
23
- * @param nxJson
24
21
  */
25
- export declare function retrieveProjectConfigurations(workspaceRoot: string, nxJson: NxJsonConfiguration): Promise<ConfigurationResult>;
22
+ export declare function retrieveProjectConfigurations(plugins: LoadedNxPlugin[], workspaceRoot: string, nxJson: NxJsonConfiguration): Promise<ConfigurationResult>;
26
23
  export declare function retrieveProjectConfigurationsWithAngularProjects(workspaceRoot: string, nxJson: NxJsonConfiguration): Promise<ConfigurationResult>;
27
- export declare function retrieveProjectConfigurationPaths(root: string, plugins: LoadedNxPlugin[]): string[];
24
+ export declare function retrieveProjectConfigurationPaths(root: string, plugins: Array<{
25
+ createNodes?: readonly [string, ...unknown[]];
26
+ } & unknown>): string[];
28
27
  export declare function retrieveProjectConfigurationsWithoutPluginInference(root: string): Promise<Record<string, ProjectConfiguration>>;
29
- export declare function configurationGlobs(plugins: LoadedNxPlugin[]): string[];
28
+ export declare function configurationGlobs(plugins: Array<{
29
+ createNodes?: readonly [string, ...unknown[]];
30
+ }>): string[];
@@ -2,15 +2,13 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.configurationGlobs = 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");
6
5
  const angular_json_1 = require("../../adapter/angular-json");
7
6
  const nx_json_1 = require("../../config/nx-json");
8
- const package_json_workspaces_1 = require("../../plugins/package-json-workspaces");
9
7
  const project_configuration_utils_1 = require("./project-configuration-utils");
10
- const nx_plugin_1 = require("../../utils/nx-plugin");
11
- const project_json_1 = require("../../plugins/project-json/build-nodes/project-json");
8
+ const internal_api_1 = require("../plugins/internal-api");
12
9
  const workspace_context_1 = require("../../utils/workspace-context");
13
10
  const build_all_workspace_files_1 = require("./build-all-workspace-files");
11
+ const path_1 = require("path");
14
12
  /**
15
13
  * Walks the workspace directory to create the `projectFileMap`, `ProjectConfigurations` and `allWorkspaceFiles`
16
14
  * @throws
@@ -37,29 +35,26 @@ async function retrieveWorkspaceFiles(workspaceRoot, projectRootMap) {
37
35
  exports.retrieveWorkspaceFiles = retrieveWorkspaceFiles;
38
36
  /**
39
37
  * Walk through the workspace and return `ProjectConfigurations`. Only use this if the projectFileMap is not needed.
40
- *
41
- * @param workspaceRoot
42
- * @param nxJson
43
38
  */
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);
39
+ function retrieveProjectConfigurations(plugins, workspaceRoot, nxJson) {
40
+ const globPatterns = configurationGlobs(plugins);
41
+ const workspaceFiles = (0, workspace_context_1.globWithWorkspaceContext)(workspaceRoot, globPatterns);
42
+ return (0, project_configuration_utils_1.createProjectConfigurations)(workspaceRoot, nxJson, workspaceFiles, plugins);
47
43
  }
48
44
  exports.retrieveProjectConfigurations = retrieveProjectConfigurations;
49
45
  async function retrieveProjectConfigurationsWithAngularProjects(workspaceRoot, nxJson) {
50
- const plugins = await (0, nx_plugin_1.loadNxPlugins)(nxJson?.plugins ?? [], (0, installation_directory_1.getNxRequirePaths)(workspaceRoot), workspaceRoot);
46
+ const pluginsToLoad = nxJson?.plugins ?? [];
51
47
  if ((0, angular_json_1.shouldMergeAngularProjects)(workspaceRoot, true) &&
52
- !plugins.some((p) => p.plugin.name === angular_json_1.NX_ANGULAR_JSON_PLUGIN_NAME)) {
53
- plugins.push({ plugin: angular_json_1.NxAngularJsonPlugin });
48
+ !pluginsToLoad.some((p) => p === angular_json_1.NX_ANGULAR_JSON_PLUGIN_NAME ||
49
+ (typeof p === 'object' && p.plugin === angular_json_1.NX_ANGULAR_JSON_PLUGIN_NAME))) {
50
+ pluginsToLoad.push((0, path_1.join)(__dirname, '../../adapter/angular-json'));
54
51
  }
55
- return _retrieveProjectConfigurations(workspaceRoot, nxJson, plugins);
52
+ const [plugins, cleanup] = await (0, internal_api_1.loadNxPlugins)(nxJson?.plugins ?? [], workspaceRoot);
53
+ const res = retrieveProjectConfigurations(plugins, workspaceRoot, nxJson);
54
+ cleanup();
55
+ return res;
56
56
  }
57
57
  exports.retrieveProjectConfigurationsWithAngularProjects = retrieveProjectConfigurationsWithAngularProjects;
58
- function _retrieveProjectConfigurations(workspaceRoot, nxJson, plugins) {
59
- const globPatterns = configurationGlobs(plugins);
60
- const workspaceFiles = (0, workspace_context_1.globWithWorkspaceContext)(workspaceRoot, globPatterns);
61
- return (0, project_configuration_utils_1.createProjectConfigurations)(workspaceRoot, nxJson, workspaceFiles, plugins);
62
- }
63
58
  function retrieveProjectConfigurationPaths(root, plugins) {
64
59
  const projectGlobPatterns = configurationGlobs(plugins);
65
60
  return (0, workspace_context_1.globWithWorkspaceContext)(root, projectGlobPatterns);
@@ -69,25 +64,23 @@ const projectsWithoutPluginCache = new Map();
69
64
  // TODO: This function is called way too often, it should be optimized without this cache
70
65
  async function retrieveProjectConfigurationsWithoutPluginInference(root) {
71
66
  const nxJson = (0, nx_json_1.readNxJson)(root);
72
- const plugins = await (0, nx_plugin_1.getDefaultPlugins)(root);
67
+ const [plugins, cleanup] = await (0, internal_api_1.loadNxPlugins)([]); // only load default plugins
73
68
  const projectGlobPatterns = retrieveProjectConfigurationPaths(root, plugins);
74
69
  const cacheKey = root + ',' + projectGlobPatterns.join(',');
75
70
  if (projectsWithoutPluginCache.has(cacheKey)) {
76
71
  return projectsWithoutPluginCache.get(cacheKey);
77
72
  }
78
73
  const projectFiles = (0, workspace_context_1.globWithWorkspaceContext)(root, projectGlobPatterns) ?? [];
79
- const { projects } = await (0, project_configuration_utils_1.createProjectConfigurations)(root, nxJson, projectFiles, [
80
- { plugin: (0, package_json_workspaces_1.getNxPackageJsonWorkspacesPlugin)(root) },
81
- { plugin: project_json_1.ProjectJsonProjectsPlugin },
82
- ]);
74
+ const { projects } = await (0, project_configuration_utils_1.createProjectConfigurations)(root, nxJson, projectFiles, plugins);
83
75
  projectsWithoutPluginCache.set(cacheKey, projects);
76
+ cleanup();
84
77
  return projects;
85
78
  }
86
79
  exports.retrieveProjectConfigurationsWithoutPluginInference = retrieveProjectConfigurationsWithoutPluginInference;
87
80
  function configurationGlobs(plugins) {
88
81
  const globPatterns = [];
89
- for (const { plugin } of plugins) {
90
- if (plugin.createNodes) {
82
+ for (const plugin of plugins) {
83
+ if ('createNodes' in plugin && plugin.createNodes) {
91
84
  globPatterns.push(plugin.createNodes[0]);
92
85
  }
93
86
  }