nx 18.3.0-beta.0 → 18.3.0-beta.1

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 (81) 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.js +3 -3
  6. package/src/command-line/generate/generator-utils.js +2 -2
  7. package/src/command-line/init/implementation/react/index.js +1 -1
  8. package/src/command-line/run/executor-utils.js +2 -2
  9. package/src/config/nx-json.d.ts +2 -1
  10. package/src/config/schema-utils.js +2 -2
  11. package/src/daemon/server/plugins.d.ts +3 -0
  12. package/src/daemon/server/plugins.js +22 -0
  13. package/src/daemon/server/project-graph-incremental-recomputation.js +11 -10
  14. package/src/daemon/server/shutdown-utils.js +2 -0
  15. package/src/devkit-exports.d.ts +3 -2
  16. package/src/executors/run-commands/run-commands.impl.d.ts +4 -1
  17. package/src/executors/run-commands/run-commands.impl.js +51 -4
  18. package/src/executors/utils/convert-nx-executor.js +4 -1
  19. package/src/generators/utils/project-configuration.js +2 -2
  20. package/src/migrations/update-15-1-0/set-project-names.js +4 -2
  21. package/src/native/assert-supported-platform.js +1 -1
  22. package/src/plugins/js/index.d.ts +1 -1
  23. package/src/plugins/js/lock-file/lock-file.d.ts +1 -1
  24. package/src/plugins/js/lock-file/npm-parser.d.ts +1 -1
  25. package/src/plugins/js/lock-file/pnpm-parser.d.ts +1 -1
  26. package/src/plugins/js/lock-file/yarn-parser.d.ts +1 -1
  27. package/src/plugins/js/project-graph/build-dependencies/build-dependencies.d.ts +1 -1
  28. package/src/plugins/js/project-graph/build-dependencies/explicit-package-json-dependencies.d.ts +1 -1
  29. package/src/plugins/js/project-graph/build-dependencies/explicit-project-dependencies.d.ts +1 -1
  30. package/src/plugins/package-json-workspaces/create-nodes.d.ts +2 -2
  31. package/src/plugins/package-json-workspaces/create-nodes.js +24 -31
  32. package/src/plugins/package-json-workspaces/index.d.ts +1 -0
  33. package/src/plugins/package-json-workspaces/index.js +2 -0
  34. package/src/plugins/project-json/build-nodes/package-json-next-to-project-json.d.ts +2 -1
  35. package/src/plugins/project-json/build-nodes/package-json-next-to-project-json.js +1 -0
  36. package/src/plugins/project-json/build-nodes/project-json.d.ts +2 -1
  37. package/src/plugins/project-json/build-nodes/project-json.js +1 -0
  38. package/src/plugins/target-defaults/symbols.d.ts +17 -0
  39. package/src/plugins/target-defaults/symbols.js +20 -0
  40. package/src/plugins/target-defaults/target-defaults-plugin.d.ts +2 -18
  41. package/src/plugins/target-defaults/target-defaults-plugin.js +5 -20
  42. package/src/project-graph/affected/locators/project-glob-changes.js +3 -3
  43. package/src/project-graph/build-project-graph.d.ts +2 -1
  44. package/src/project-graph/build-project-graph.js +11 -13
  45. package/src/project-graph/error-types.d.ts +34 -0
  46. package/src/project-graph/error-types.js +65 -0
  47. package/src/project-graph/file-utils.js +3 -3
  48. package/src/project-graph/plugins/index.d.ts +2 -0
  49. package/src/project-graph/plugins/index.js +8 -0
  50. package/src/project-graph/plugins/internal-api.d.ts +28 -0
  51. package/src/project-graph/plugins/internal-api.js +85 -0
  52. package/src/project-graph/plugins/isolation/index.d.ts +3 -0
  53. package/src/project-graph/plugins/isolation/index.js +16 -0
  54. package/src/project-graph/plugins/isolation/messaging.d.ts +94 -0
  55. package/src/project-graph/plugins/isolation/messaging.js +23 -0
  56. package/src/project-graph/plugins/isolation/plugin-pool.d.ts +3 -0
  57. package/src/project-graph/plugins/isolation/plugin-pool.js +189 -0
  58. package/src/project-graph/plugins/isolation/plugin-worker.d.ts +1 -0
  59. package/src/project-graph/plugins/isolation/plugin-worker.js +81 -0
  60. package/src/project-graph/plugins/loader.d.ts +24 -0
  61. package/src/project-graph/plugins/loader.js +206 -0
  62. package/src/{utils/nx-plugin.d.ts → project-graph/plugins/public-api.d.ts} +8 -44
  63. package/src/project-graph/plugins/public-api.js +4 -0
  64. package/src/project-graph/plugins/utils.d.ts +7 -0
  65. package/src/project-graph/plugins/utils.js +88 -0
  66. package/src/project-graph/project-graph-builder.d.ts +1 -1
  67. package/src/project-graph/project-graph.d.ts +3 -2
  68. package/src/project-graph/project-graph.js +9 -7
  69. package/src/project-graph/utils/normalize-project-nodes.d.ts +1 -1
  70. package/src/project-graph/utils/project-configuration-utils.d.ts +3 -26
  71. package/src/project-graph/utils/project-configuration-utils.js +29 -97
  72. package/src/project-graph/utils/retrieve-workspace-files.d.ts +11 -10
  73. package/src/project-graph/utils/retrieve-workspace-files.js +18 -21
  74. package/src/tasks-runner/cache.js +1 -1
  75. package/src/utils/logger.d.ts +1 -0
  76. package/src/utils/logger.js +5 -0
  77. package/src/utils/nx-plugin.deprecated.d.ts +2 -2
  78. package/src/utils/nx-plugin.deprecated.js +5 -7
  79. package/src/utils/plugins/plugin-capabilities.d.ts +1 -1
  80. package/src/utils/plugins/plugin-capabilities.js +18 -12
  81. package/src/utils/nx-plugin.js +0 -309
@@ -1,9 +1,8 @@
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';
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';
7
6
  /**
8
7
  * Context for {@link CreateNodesFunction}
9
8
  */
@@ -20,6 +19,7 @@ export interface CreateNodesContext {
20
19
  * Used for creating nodes for the {@link ProjectGraph}
21
20
  */
22
21
  export type CreateNodesFunction<T = unknown> = (projectConfigurationFile: string, options: T | undefined, context: CreateNodesContext) => CreateNodesResult | Promise<CreateNodesResult>;
22
+ export type Optional<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
23
23
  export interface CreateNodesResult {
24
24
  /**
25
25
  * A map of project root -> project configuration
@@ -34,7 +34,7 @@ export interface CreateNodesResult {
34
34
  * A pair of file patterns and {@link CreateNodesFunction}
35
35
  */
36
36
  export type CreateNodes<T = unknown> = readonly [
37
- configFilePattern: string,
37
+ projectFilePattern: string,
38
38
  createNodesFunction: CreateNodesFunction<T>
39
39
  ];
40
40
  /**
@@ -77,49 +77,13 @@ export type NxPluginV2<TOptions = unknown> = {
77
77
  * Provides a file pattern and function that retrieves configuration info from
78
78
  * those files. e.g. { '**\/*.csproj': buildProjectsFromCsProjFile }
79
79
  */
80
- createNodes?: CreateNodes;
80
+ createNodes?: CreateNodes<TOptions>;
81
81
  /**
82
82
  * Provides a function to analyze files to create dependencies for the {@link ProjectGraph}
83
83
  */
84
84
  createDependencies?: CreateDependencies<TOptions>;
85
85
  };
86
- export * from './nx-plugin.deprecated';
87
86
  /**
88
87
  * A plugin for Nx
89
88
  */
90
89
  export type NxPlugin = NxPluginV1 | NxPluginV2;
91
- export type LoadedNxPlugin = {
92
- plugin: NxPluginV2 & Pick<NxPluginV1, 'processProjectGraph'>;
93
- options?: unknown;
94
- include?: string[];
95
- exclude?: string[];
96
- };
97
- export declare const nxPluginCache: Map<string, LoadedNxPlugin['plugin']>;
98
- export declare function getPluginPathAndName(moduleName: string, paths: string[], projects: Record<string, ProjectConfiguration>, root: string): {
99
- pluginPath: string;
100
- name: any;
101
- };
102
- export declare function loadNxPluginAsync(pluginConfiguration: PluginConfiguration, paths: string[], projects: Record<string, ProjectConfiguration>, root: string): Promise<LoadedNxPlugin>;
103
- export declare function loadNxPlugins(plugins: PluginConfiguration[], paths?: string[], root?: string, projects?: Record<string, ProjectConfiguration>): Promise<LoadedNxPlugin[]>;
104
- export declare function ensurePluginIsV2(plugin: NxPlugin): NxPluginV2;
105
- export declare function isNxPluginV2(plugin: NxPlugin): plugin is NxPluginV2;
106
- export declare function isNxPluginV1(plugin: NxPlugin): plugin is NxPluginV1;
107
- export declare function readPluginPackageJson(pluginName: string, projects: Record<string, ProjectConfiguration>, paths?: string[]): {
108
- path: string;
109
- json: PackageJson;
110
- };
111
- export declare function resolveLocalNxPlugin(importPath: string, nxJsonConfiguration: NxJsonConfiguration, projects: Record<string, ProjectConfiguration>, root?: string): {
112
- path: string;
113
- projectConfig: ProjectConfiguration;
114
- } | null;
115
- /**
116
- * Register swc-node or ts-node if they are not currently registered
117
- * with some default settings which work well for Nx plugins.
118
- */
119
- export declare function registerPluginTSTranspiler(): void;
120
- /**
121
- * Unregister the ts-node transpiler if it is registered
122
- */
123
- export declare function unregisterPluginTSTranspiler(): void;
124
- export declare function getDefaultPlugins(root: string): Promise<LoadedNxPlugin[]>;
125
- type Optional<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ // This file represents the public API for plugins which live in nx.json's plugins array.
3
+ // For methods to interact with plugins from within Nx, see `./internal-api.ts`.
4
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,7 @@
1
+ import type { NxPluginV1 } from '../../utils/nx-plugin.deprecated';
2
+ import type { CreateNodesResultWithContext, LoadedNxPlugin, NormalizedPlugin } from './internal-api';
3
+ import type { CreateNodesContext, NxPlugin, NxPluginV2 } from './public-api';
4
+ export declare function isNxPluginV2(plugin: NxPlugin): plugin is NxPluginV2;
5
+ export declare function isNxPluginV1(plugin: NxPlugin | LoadedNxPlugin): plugin is NxPluginV1;
6
+ export declare function normalizeNxPlugin(plugin: NxPlugin): NormalizedPlugin;
7
+ export declare function runCreateNodesInParallel(configFiles: string[], plugin: NormalizedPlugin, options: unknown, context: CreateNodesContext): Promise<CreateNodesResultWithContext[]>;
@@ -0,0 +1,88 @@
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 promises = configFiles.map((file) => {
45
+ performance.mark(`${plugin.name}:createNodes:${file} - start`);
46
+ // Result is either static or a promise, using Promise.resolve lets us
47
+ // handle both cases with same logic
48
+ const value = Promise.resolve(plugin.createNodes[1](file, options, context));
49
+ return value
50
+ .catch((e) => {
51
+ performance.mark(`${plugin.name}:createNodes:${file} - end`);
52
+ return new error_types_1.CreateNodesError({
53
+ error: e,
54
+ pluginName: plugin.name,
55
+ file,
56
+ });
57
+ })
58
+ .then((r) => {
59
+ performance.mark(`${plugin.name}:createNodes:${file} - end`);
60
+ performance.measure(`${plugin.name}:createNodes:${file}`, `${plugin.name}:createNodes:${file} - start`, `${plugin.name}:createNodes:${file} - end`);
61
+ return { ...r, pluginName: plugin.name, file };
62
+ });
63
+ });
64
+ const results = await Promise.all(promises).then((results) => {
65
+ performance.mark(`${plugin.name}:createNodes - end`);
66
+ performance.measure(`${plugin.name}:createNodes`, `${plugin.name}:createNodes - start`, `${plugin.name}:createNodes - end`);
67
+ return results;
68
+ });
69
+ const [errors, successful] = partition(results, (r) => r instanceof error_types_1.CreateNodesError);
70
+ if (errors.length > 0) {
71
+ throw new error_types_1.AggregateCreateNodesError(plugin.name, errors, successful);
72
+ }
73
+ return results;
74
+ }
75
+ exports.runCreateNodesInParallel = runCreateNodesInParallel;
76
+ function partition(arr, test) {
77
+ const pass = [];
78
+ const fail = [];
79
+ for (const item of arr) {
80
+ if (test(item)) {
81
+ pass.push(item);
82
+ }
83
+ else {
84
+ fail.push(item);
85
+ }
86
+ }
87
+ return [pass, fail];
88
+ }
@@ -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 } 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.
@@ -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(): (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,
@@ -343,7 +306,7 @@ plugins) {
343
306
  };
344
307
  }
345
308
  else {
346
- throw new ProjectConfigurationsError(errors, {
309
+ throw new error_types_1.ProjectConfigurationsError(errors, {
347
310
  projects,
348
311
  externalNodes,
349
312
  projectRootMap: rootMap,
@@ -395,37 +358,6 @@ function readProjectConfigurationsFromRootMap(projectRootMap) {
395
358
  return projects;
396
359
  }
397
360
  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
361
  /**
430
362
  * Merges two targets.
431
363
  *
@@ -448,7 +380,7 @@ function mergeTargetConfigurations(target, baseTarget, projectConfigSourceMap, s
448
380
  // with the new one. However, we have a special case for targets that have the
449
381
  // ONLY_MODIFIES_EXISTING_TARGET symbol set. This prevents the merged target
450
382
  // 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]) {
383
+ if (!isCompatible && target[symbols_1.ONLY_MODIFIES_EXISTING_TARGET]) {
452
384
  return baseTarget;
453
385
  }
454
386
  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[];