nx 18.3.0-canary.20240409-32144bb → 18.3.0-canary.20240410-7a7cbec

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 (77) 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/run/executor-utils.js +2 -2
  8. package/src/config/nx-json.d.ts +2 -1
  9. package/src/config/schema-utils.js +2 -2
  10. package/src/daemon/server/plugins.d.ts +3 -0
  11. package/src/daemon/server/plugins.js +22 -0
  12. package/src/daemon/server/project-graph-incremental-recomputation.js +10 -9
  13. package/src/daemon/server/shutdown-utils.js +2 -0
  14. package/src/devkit-exports.d.ts +3 -2
  15. package/src/executors/run-commands/run-commands.impl.js +1 -1
  16. package/src/executors/utils/convert-nx-executor.js +4 -1
  17. package/src/generators/utils/project-configuration.js +2 -2
  18. package/src/migrations/update-15-1-0/set-project-names.js +4 -2
  19. package/src/plugins/js/index.d.ts +1 -1
  20. package/src/plugins/js/lock-file/lock-file.d.ts +1 -1
  21. package/src/plugins/js/lock-file/npm-parser.d.ts +1 -1
  22. package/src/plugins/js/lock-file/pnpm-parser.d.ts +1 -1
  23. package/src/plugins/js/lock-file/yarn-parser.d.ts +1 -1
  24. package/src/plugins/js/project-graph/build-dependencies/build-dependencies.d.ts +1 -1
  25. package/src/plugins/js/project-graph/build-dependencies/explicit-package-json-dependencies.d.ts +1 -1
  26. package/src/plugins/js/project-graph/build-dependencies/explicit-project-dependencies.d.ts +1 -1
  27. package/src/plugins/package-json-workspaces/create-nodes.d.ts +2 -2
  28. package/src/plugins/package-json-workspaces/create-nodes.js +24 -31
  29. package/src/plugins/package-json-workspaces/index.d.ts +1 -0
  30. package/src/plugins/package-json-workspaces/index.js +2 -0
  31. package/src/plugins/project-json/build-nodes/package-json-next-to-project-json.d.ts +2 -1
  32. package/src/plugins/project-json/build-nodes/package-json-next-to-project-json.js +1 -0
  33. package/src/plugins/project-json/build-nodes/project-json.d.ts +2 -1
  34. package/src/plugins/project-json/build-nodes/project-json.js +1 -0
  35. package/src/plugins/target-defaults/symbols.d.ts +17 -0
  36. package/src/plugins/target-defaults/symbols.js +20 -0
  37. package/src/plugins/target-defaults/target-defaults-plugin.d.ts +2 -18
  38. package/src/plugins/target-defaults/target-defaults-plugin.js +5 -20
  39. package/src/project-graph/affected/locators/project-glob-changes.js +3 -3
  40. package/src/project-graph/build-project-graph.d.ts +2 -1
  41. package/src/project-graph/build-project-graph.js +11 -13
  42. package/src/project-graph/error-types.d.ts +34 -0
  43. package/src/project-graph/error-types.js +65 -0
  44. package/src/project-graph/file-utils.js +3 -3
  45. package/src/project-graph/plugins/index.d.ts +2 -0
  46. package/src/project-graph/plugins/index.js +8 -0
  47. package/src/project-graph/plugins/internal-api.d.ts +28 -0
  48. package/src/project-graph/plugins/internal-api.js +85 -0
  49. package/src/project-graph/plugins/isolation/index.d.ts +3 -0
  50. package/src/project-graph/plugins/isolation/index.js +16 -0
  51. package/src/project-graph/plugins/isolation/messaging.d.ts +94 -0
  52. package/src/project-graph/plugins/isolation/messaging.js +23 -0
  53. package/src/project-graph/plugins/isolation/plugin-pool.d.ts +3 -0
  54. package/src/project-graph/plugins/isolation/plugin-pool.js +189 -0
  55. package/src/project-graph/plugins/isolation/plugin-worker.d.ts +1 -0
  56. package/src/project-graph/plugins/isolation/plugin-worker.js +81 -0
  57. package/src/project-graph/plugins/loader.d.ts +24 -0
  58. package/src/project-graph/plugins/loader.js +206 -0
  59. package/src/{utils/nx-plugin.d.ts → project-graph/plugins/public-api.d.ts} +8 -44
  60. package/src/project-graph/plugins/public-api.js +4 -0
  61. package/src/project-graph/plugins/utils.d.ts +7 -0
  62. package/src/project-graph/plugins/utils.js +88 -0
  63. package/src/project-graph/project-graph-builder.d.ts +1 -1
  64. package/src/project-graph/project-graph.d.ts +3 -2
  65. package/src/project-graph/project-graph.js +9 -7
  66. package/src/project-graph/utils/normalize-project-nodes.d.ts +1 -1
  67. package/src/project-graph/utils/project-configuration-utils.d.ts +3 -26
  68. package/src/project-graph/utils/project-configuration-utils.js +29 -97
  69. package/src/project-graph/utils/retrieve-workspace-files.d.ts +11 -10
  70. package/src/project-graph/utils/retrieve-workspace-files.js +18 -21
  71. package/src/utils/logger.d.ts +1 -0
  72. package/src/utils/logger.js +5 -0
  73. package/src/utils/nx-plugin.deprecated.d.ts +2 -2
  74. package/src/utils/nx-plugin.deprecated.js +5 -7
  75. package/src/utils/plugins/plugin-capabilities.d.ts +1 -1
  76. package/src/utils/plugins/plugin-capabilities.js +18 -12
  77. package/src/utils/nx-plugin.js +0 -309
@@ -0,0 +1,17 @@
1
+ /**
2
+ * This marks that a target provides information which should modify a target already registered
3
+ * on the project via other plugins. If the target has not already been registered, and this symbol is true,
4
+ * the information provided by it will be discarded.
5
+ *
6
+ * NOTE: This cannot be a symbol, as they are not serialized in JSON the communication
7
+ * between the plugin-worker and the main process.
8
+ */
9
+ export declare const ONLY_MODIFIES_EXISTING_TARGET = "NX_ONLY_MODIFIES_EXISTING_TARGET";
10
+ /**
11
+ * This is used to override the source file for the target defaults plugin.
12
+ * This allows the plugin to use the project files as the context, but point to nx.json as the source file.
13
+ *
14
+ * NOTE: This cannot be a symbol, as they are not serialized in JSON the communication
15
+ * between the plugin-worker and the main process.
16
+ */
17
+ export declare const OVERRIDE_SOURCE_FILE = "NX_OVERRIDE_SOURCE_FILE";
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.OVERRIDE_SOURCE_FILE = exports.ONLY_MODIFIES_EXISTING_TARGET = void 0;
4
+ /**
5
+ * This marks that a target provides information which should modify a target already registered
6
+ * on the project via other plugins. If the target has not already been registered, and this symbol is true,
7
+ * the information provided by it will be discarded.
8
+ *
9
+ * NOTE: This cannot be a symbol, as they are not serialized in JSON the communication
10
+ * between the plugin-worker and the main process.
11
+ */
12
+ exports.ONLY_MODIFIES_EXISTING_TARGET = 'NX_ONLY_MODIFIES_EXISTING_TARGET';
13
+ /**
14
+ * This is used to override the source file for the target defaults plugin.
15
+ * This allows the plugin to use the project files as the context, but point to nx.json as the source file.
16
+ *
17
+ * NOTE: This cannot be a symbol, as they are not serialized in JSON the communication
18
+ * between the plugin-worker and the main process.
19
+ */
20
+ exports.OVERRIDE_SOURCE_FILE = 'NX_OVERRIDE_SOURCE_FILE';
@@ -1,23 +1,7 @@
1
1
  import { TargetConfiguration } from '../../config/workspace-json-project-json';
2
- import { NxPluginV2 } from '../../utils/nx-plugin';
3
- /**
4
- * This marks that a target provides information which should modify a target already registered
5
- * on the project via other plugins. If the target has not already been registered, and this symbol is true,
6
- * the information provided by it will be discarded.
7
- *
8
- * NOTE: This cannot be a symbol, as they are not serialized in JSON the communication
9
- * between the plugin-worker and the main process.
10
- */
11
- export declare const ONLY_MODIFIES_EXISTING_TARGET = "NX_ONLY_MODIFIES_EXISTING_TARGET";
12
- /**
13
- * This is used to override the source file for the target defaults plugin.
14
- * This allows the plugin to use the project files as the context, but point to nx.json as the source file.
15
- *
16
- * NOTE: This cannot be a symbol, as they are not serialized in JSON the communication
17
- * between the plugin-worker and the main process.
18
- */
19
- export declare const OVERRIDE_SOURCE_FILE = "NX_OVERRIDE_SOURCE_FILE";
2
+ import { NxPluginV2 } from '../../project-graph/plugins';
20
3
  export declare const TargetDefaultsPlugin: NxPluginV2;
4
+ export default TargetDefaultsPlugin;
21
5
  /**
22
6
  * This fn gets target info that would make a target uniquely compatible
23
7
  * with what is described by project.json or package.json. As the merge process
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getTargetInfo = exports.TargetDefaultsPlugin = exports.OVERRIDE_SOURCE_FILE = exports.ONLY_MODIFIES_EXISTING_TARGET = void 0;
3
+ exports.getTargetInfo = exports.TargetDefaultsPlugin = void 0;
4
4
  const minimatch_1 = require("minimatch");
5
5
  const node_fs_1 = require("node:fs");
6
6
  const node_path_1 = require("node:path");
@@ -8,23 +8,7 @@ const fileutils_1 = require("../../utils/fileutils");
8
8
  const globs_1 = require("../../utils/globs");
9
9
  const package_json_1 = require("../../utils/package-json");
10
10
  const package_json_workspaces_1 = require("../package-json-workspaces");
11
- /**
12
- * This marks that a target provides information which should modify a target already registered
13
- * on the project via other plugins. If the target has not already been registered, and this symbol is true,
14
- * the information provided by it will be discarded.
15
- *
16
- * NOTE: This cannot be a symbol, as they are not serialized in JSON the communication
17
- * between the plugin-worker and the main process.
18
- */
19
- exports.ONLY_MODIFIES_EXISTING_TARGET = 'NX_ONLY_MODIFIES_EXISTING_TARGET';
20
- /**
21
- * This is used to override the source file for the target defaults plugin.
22
- * This allows the plugin to use the project files as the context, but point to nx.json as the source file.
23
- *
24
- * NOTE: This cannot be a symbol, as they are not serialized in JSON the communication
25
- * between the plugin-worker and the main process.
26
- */
27
- exports.OVERRIDE_SOURCE_FILE = 'NX_OVERRIDE_SOURCE_FILE';
11
+ const symbols_1 = require("./symbols");
28
12
  exports.TargetDefaultsPlugin = {
29
13
  name: 'nx/core/target-defaults',
30
14
  createNodes: [
@@ -72,7 +56,7 @@ exports.TargetDefaultsPlugin = {
72
56
  // TODO: Remove this after we figure out a way to define new targets
73
57
  // in target defaults
74
58
  if (!projectDefinedTargets.has(targetName)) {
75
- modifiedTargets[targetName][exports.ONLY_MODIFIES_EXISTING_TARGET] = true;
59
+ modifiedTargets[targetName][symbols_1.ONLY_MODIFIES_EXISTING_TARGET] = true;
76
60
  }
77
61
  }
78
62
  }
@@ -82,11 +66,12 @@ exports.TargetDefaultsPlugin = {
82
66
  targets: modifiedTargets,
83
67
  },
84
68
  },
85
- [exports.OVERRIDE_SOURCE_FILE]: 'nx.json',
69
+ [symbols_1.OVERRIDE_SOURCE_FILE]: 'nx.json',
86
70
  };
87
71
  },
88
72
  ],
89
73
  };
74
+ exports.default = exports.TargetDefaultsPlugin;
90
75
  function getExecutorToTargetMap(packageJsonTargets, projectJsonTargets) {
91
76
  const executorToTargetMap = new Map();
92
77
  const targets = Object.keys({
@@ -3,14 +3,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getTouchedProjectsFromProjectGlobChanges = void 0;
4
4
  const minimatch_1 = require("minimatch");
5
5
  const workspace_root_1 = require("../../../utils/workspace-root");
6
- const installation_directory_1 = require("../../../utils/installation-directory");
7
6
  const path_1 = require("path");
8
7
  const fs_1 = require("fs");
9
8
  const retrieve_workspace_files_1 = require("../../utils/retrieve-workspace-files");
10
- const nx_plugin_1 = require("../../../utils/nx-plugin");
9
+ const internal_api_1 = require("../../plugins/internal-api");
11
10
  const globs_1 = require("../../../utils/globs");
12
11
  const getTouchedProjectsFromProjectGlobChanges = async (touchedFiles, projectGraphNodes, nxJson) => {
13
- const globPattern = (0, globs_1.combineGlobPatterns)((0, retrieve_workspace_files_1.configurationGlobs)(await (0, nx_plugin_1.loadNxPlugins)(nxJson?.plugins, (0, installation_directory_1.getNxRequirePaths)(workspace_root_1.workspaceRoot), workspace_root_1.workspaceRoot)));
12
+ const [plugins] = await (0, internal_api_1.loadNxPlugins)(nxJson?.plugins ?? [], workspace_root_1.workspaceRoot);
13
+ const globPattern = (0, globs_1.combineGlobPatterns)((0, retrieve_workspace_files_1.configurationGlobs)(plugins));
14
14
  const touchedProjects = new Set();
15
15
  for (const touchedFile of touchedFiles) {
16
16
  const isProjectFile = (0, minimatch_1.minimatch)(touchedFile.file, globPattern, {
@@ -1,5 +1,6 @@
1
1
  import { FileData } from './file-utils';
2
2
  import { FileMapCache } from './nx-deps-cache';
3
+ import { LoadedNxPlugin } from './plugins/internal-api';
3
4
  import { FileMap, ProjectGraph, ProjectGraphExternalNode } from '../config/project-graph';
4
5
  import { ProjectConfiguration } from '../config/workspace-json-project-json';
5
6
  import { NxWorkspaceFilesExternals } from '../native';
@@ -8,7 +9,7 @@ export declare function getFileMap(): {
8
9
  allWorkspaceFiles: FileData[];
9
10
  rustReferences: NxWorkspaceFilesExternals | null;
10
11
  };
11
- export declare function buildProjectGraphUsingProjectFileMap(projects: Record<string, ProjectConfiguration>, externalNodes: Record<string, ProjectGraphExternalNode>, fileMap: FileMap, allWorkspaceFiles: FileData[], rustReferences: NxWorkspaceFilesExternals, fileMapCache: FileMapCache | null): Promise<{
12
+ export declare function buildProjectGraphUsingProjectFileMap(projects: Record<string, ProjectConfiguration>, externalNodes: Record<string, ProjectGraphExternalNode>, fileMap: FileMap, allWorkspaceFiles: FileData[], rustReferences: NxWorkspaceFilesExternals, fileMapCache: FileMapCache | null, plugins: LoadedNxPlugin[]): Promise<{
12
13
  projectGraph: ProjectGraph;
13
14
  projectFileMapCache: FileMapCache;
14
15
  }>;
@@ -8,13 +8,12 @@ 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 nx_plugin_1 = require("../utils/nx-plugin");
11
+ const utils_1 = require("./plugins/utils");
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");
18
17
  const output_1 = require("../utils/output");
19
18
  let storedFileMap = null;
20
19
  let storedAllWorkspaceFiles = null;
@@ -39,7 +38,7 @@ function getFileMap() {
39
38
  }
40
39
  }
41
40
  exports.getFileMap = getFileMap;
42
- async function buildProjectGraphUsingProjectFileMap(projects, externalNodes, fileMap, allWorkspaceFiles, rustReferences, fileMapCache) {
41
+ async function buildProjectGraphUsingProjectFileMap(projects, externalNodes, fileMap, allWorkspaceFiles, rustReferences, fileMapCache, plugins) {
43
42
  storedFileMap = fileMap;
44
43
  storedAllWorkspaceFiles = allWorkspaceFiles;
45
44
  storedRustReferences = rustReferences;
@@ -65,7 +64,7 @@ async function buildProjectGraphUsingProjectFileMap(projects, externalNodes, fil
65
64
  };
66
65
  }
67
66
  const context = createContext(projects, nxJson, externalNodes, fileMap, filesToProcess);
68
- let projectGraph = await buildProjectGraphUsingContext(externalNodes, context, cachedFileData, projectGraphVersion);
67
+ let projectGraph = await buildProjectGraphUsingContext(externalNodes, context, cachedFileData, projectGraphVersion, plugins);
69
68
  const projectFileMapCache = (0, nx_deps_cache_1.createProjectFileMapCache)(nxJson, packageJsonDeps, fileMap, rootTsConfig);
70
69
  return {
71
70
  projectGraph,
@@ -89,7 +88,7 @@ function readCombinedDeps() {
89
88
  ...installationPackageJson.devDependencies,
90
89
  };
91
90
  }
92
- async function buildProjectGraphUsingContext(knownExternalNodes, ctx, cachedFileData, projectGraphVersion) {
91
+ async function buildProjectGraphUsingContext(knownExternalNodes, ctx, cachedFileData, projectGraphVersion, plugins) {
93
92
  perf_hooks_1.performance.mark('build project graph:start');
94
93
  const builder = new project_graph_builder_1.ProjectGraphBuilder(null, ctx.fileMap.projectFileMap);
95
94
  builder.setVersion(projectGraphVersion);
@@ -101,7 +100,7 @@ async function buildProjectGraphUsingContext(knownExternalNodes, ctx, cachedFile
101
100
  let updatedGraph;
102
101
  let error;
103
102
  try {
104
- updatedGraph = await updateProjectGraphWithPlugins(ctx, initProjectGraph);
103
+ updatedGraph = await updateProjectGraphWithPlugins(ctx, initProjectGraph, plugins);
105
104
  }
106
105
  catch (e) {
107
106
  if (e instanceof CreateDependenciesError) {
@@ -154,13 +153,12 @@ function createContext(projects, nxJson, externalNodes, fileMap, filesToProcess)
154
153
  filesToProcess,
155
154
  };
156
155
  }
157
- async function updateProjectGraphWithPlugins(context, initProjectGraph) {
158
- const plugins = await (0, nx_plugin_1.loadNxPlugins)(context.nxJsonConfiguration?.plugins, (0, installation_directory_1.getNxRequirePaths)(), context.workspaceRoot, context.projects);
156
+ async function updateProjectGraphWithPlugins(context, initProjectGraph, plugins) {
159
157
  let graph = initProjectGraph;
160
158
  const errors = [];
161
- for (const { plugin } of plugins) {
159
+ for (const plugin of plugins) {
162
160
  try {
163
- if ((0, nx_plugin_1.isNxPluginV1)(plugin) &&
161
+ if ((0, utils_1.isNxPluginV1)(plugin) &&
164
162
  plugin.processProjectGraph &&
165
163
  !plugin.createDependencies) {
166
164
  output_1.output.warn({
@@ -195,11 +193,11 @@ async function updateProjectGraphWithPlugins(context, initProjectGraph) {
195
193
  }
196
194
  }
197
195
  const builder = new project_graph_builder_1.ProjectGraphBuilder(graph, context.fileMap.projectFileMap, context.fileMap.nonProjectFiles);
198
- const createDependencyPlugins = plugins.filter(({ plugin }) => (0, nx_plugin_1.isNxPluginV2)(plugin) && plugin.createDependencies);
199
- await Promise.all(createDependencyPlugins.map(async ({ plugin, options }) => {
196
+ const createDependencyPlugins = plugins.filter((plugin) => (0, utils_1.isNxPluginV2)(plugin) && plugin.createDependencies);
197
+ await Promise.all(createDependencyPlugins.map(async (plugin) => {
200
198
  perf_hooks_1.performance.mark(`${plugin.name}:createDependencies - start`);
201
199
  try {
202
- const dependencies = await plugin.createDependencies(options, {
200
+ const dependencies = await plugin.createDependencies({
203
201
  ...context,
204
202
  });
205
203
  for (const dep of dependencies) {
@@ -0,0 +1,34 @@
1
+ import { CreateNodesResultWithContext } from './plugins/internal-api';
2
+ import { ConfigurationResult } from './utils/project-configuration-utils';
3
+ export declare class ProjectConfigurationsError extends Error {
4
+ readonly errors: Array<MergeNodesError | CreateNodesError>;
5
+ readonly partialProjectConfigurationsResult: ConfigurationResult;
6
+ constructor(errors: Array<MergeNodesError | CreateNodesError>, partialProjectConfigurationsResult: ConfigurationResult);
7
+ }
8
+ export declare class CreateNodesError extends Error {
9
+ file: string;
10
+ pluginName: string;
11
+ constructor({ file, pluginName, error, }: {
12
+ file: string;
13
+ pluginName: string;
14
+ error: Error;
15
+ });
16
+ }
17
+ export declare class AggregateCreateNodesError extends Error {
18
+ readonly pluginName: string;
19
+ readonly errors: Array<CreateNodesError>;
20
+ readonly partialResults: Array<CreateNodesResultWithContext>;
21
+ constructor(pluginName: string, errors: Array<CreateNodesError>, partialResults: Array<CreateNodesResultWithContext>);
22
+ }
23
+ export declare class MergeNodesError extends Error {
24
+ file: string;
25
+ pluginName: string;
26
+ constructor({ file, pluginName, error, }: {
27
+ file: string;
28
+ pluginName: string;
29
+ error: Error;
30
+ });
31
+ }
32
+ export declare function isCreateNodesError(e: unknown): e is CreateNodesError;
33
+ export declare function isAggregateCreateNodesError(e: unknown): e is AggregateCreateNodesError;
34
+ export declare function isMergeNodesError(e: unknown): e is MergeNodesError;
@@ -0,0 +1,65 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isMergeNodesError = exports.isAggregateCreateNodesError = exports.isCreateNodesError = exports.MergeNodesError = exports.AggregateCreateNodesError = exports.CreateNodesError = exports.ProjectConfigurationsError = void 0;
4
+ class ProjectConfigurationsError extends Error {
5
+ constructor(errors, partialProjectConfigurationsResult) {
6
+ super('Failed to create project configurations');
7
+ this.errors = errors;
8
+ this.partialProjectConfigurationsResult = partialProjectConfigurationsResult;
9
+ this.name = this.constructor.name;
10
+ }
11
+ }
12
+ exports.ProjectConfigurationsError = ProjectConfigurationsError;
13
+ class CreateNodesError extends Error {
14
+ constructor({ file, pluginName, error, }) {
15
+ const msg = `The "${pluginName}" plugin threw an error while creating nodes from ${file}:`;
16
+ super(msg, { cause: error });
17
+ this.name = this.constructor.name;
18
+ this.file = file;
19
+ this.pluginName = pluginName;
20
+ this.stack = `${this.message}\n ${error.stack.split('\n').join('\n ')}`;
21
+ }
22
+ }
23
+ exports.CreateNodesError = CreateNodesError;
24
+ class AggregateCreateNodesError extends Error {
25
+ constructor(pluginName, errors, partialResults) {
26
+ super('Failed to create nodes');
27
+ this.pluginName = pluginName;
28
+ this.errors = errors;
29
+ this.partialResults = partialResults;
30
+ this.name = this.constructor.name;
31
+ }
32
+ }
33
+ exports.AggregateCreateNodesError = AggregateCreateNodesError;
34
+ class MergeNodesError extends Error {
35
+ constructor({ file, pluginName, error, }) {
36
+ const msg = `The nodes created from ${file} by the "${pluginName}" could not be merged into the project graph:`;
37
+ super(msg, { cause: error });
38
+ this.name = this.constructor.name;
39
+ this.file = file;
40
+ this.pluginName = pluginName;
41
+ this.stack = `${this.message}\n ${error.stack.split('\n').join('\n ')}`;
42
+ }
43
+ }
44
+ exports.MergeNodesError = MergeNodesError;
45
+ function isCreateNodesError(e) {
46
+ return (e instanceof CreateNodesError ||
47
+ (typeof e === 'object' &&
48
+ 'name' in e &&
49
+ e?.name === CreateNodesError.prototype.name));
50
+ }
51
+ exports.isCreateNodesError = isCreateNodesError;
52
+ function isAggregateCreateNodesError(e) {
53
+ return (e instanceof AggregateCreateNodesError ||
54
+ (typeof e === 'object' &&
55
+ 'name' in e &&
56
+ e?.name === AggregateCreateNodesError.prototype.name));
57
+ }
58
+ exports.isAggregateCreateNodesError = isAggregateCreateNodesError;
59
+ function isMergeNodesError(e) {
60
+ return (e instanceof MergeNodesError ||
61
+ (typeof e === 'object' &&
62
+ 'name' in e &&
63
+ e?.name === MergeNodesError.prototype.name));
64
+ }
65
+ exports.isMergeNodesError = isMergeNodesError;
@@ -149,12 +149,12 @@ Object.defineProperty(exports, "workspaceLayout", { enumerable: true, get: funct
149
149
  function getProjectsSyncNoInference(root, nxJson) {
150
150
  const allConfigFiles = (0, retrieve_workspace_files_1.retrieveProjectConfigurationPaths)(root, (0, nx_plugin_deprecated_1.getDefaultPluginsSync)(root));
151
151
  const plugins = [
152
- { plugin: package_json_next_to_project_json_1.PackageJsonProjectsNextToProjectJsonPlugin },
152
+ 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, options } of plugins) {
157
+ for (const plugin of plugins) {
158
158
  const [pattern, createNodes] = plugin.createNodes ?? [];
159
159
  if (!pattern) {
160
160
  continue;
@@ -162,7 +162,7 @@ function getProjectsSyncNoInference(root, nxJson) {
162
162
  const matchingConfigFiles = allConfigFiles.filter((file) => (0, minimatch_1.minimatch)(file, pattern, { dot: true }));
163
163
  for (const file of matchingConfigFiles) {
164
164
  if ((0, minimatch_1.minimatch)(file, pattern, { dot: true })) {
165
- let r = createNodes(file, options, {
165
+ let r = createNodes(file, {}, {
166
166
  nxJsonConfiguration: nxJson,
167
167
  workspaceRoot: root,
168
168
  configFiles: matchingConfigFiles,
@@ -0,0 +1,2 @@
1
+ export * from './public-api';
2
+ export { readPluginPackageJson, registerPluginTSTranspiler } from './loader';
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.registerPluginTSTranspiler = exports.readPluginPackageJson = void 0;
4
+ const tslib_1 = require("tslib");
5
+ tslib_1.__exportStar(require("./public-api"), exports);
6
+ var loader_1 = require("./loader");
7
+ Object.defineProperty(exports, "readPluginPackageJson", { enumerable: true, get: function () { return loader_1.readPluginPackageJson; } });
8
+ Object.defineProperty(exports, "registerPluginTSTranspiler", { enumerable: true, get: function () { return loader_1.registerPluginTSTranspiler; } });
@@ -0,0 +1,28 @@
1
+ import { PluginConfiguration } from '../../config/nx-json';
2
+ import { NxPluginV1 } from '../../utils/nx-plugin.deprecated';
3
+ import { CreateDependencies, CreateDependenciesContext, CreateNodesContext, CreateNodesResult, NxPluginV2 } from './public-api';
4
+ import { ProjectGraphProcessor } from '../../config/project-graph';
5
+ export declare class LoadedNxPlugin {
6
+ readonly name: string;
7
+ readonly createNodes?: [
8
+ filePattern: string,
9
+ fn: (matchedFiles: string[], context: CreateNodesContext) => Promise<CreateNodesResultWithContext[]>
10
+ ];
11
+ readonly createDependencies?: (context: CreateDependenciesContext) => ReturnType<CreateDependencies>;
12
+ readonly processProjectGraph?: ProjectGraphProcessor;
13
+ readonly options?: unknown;
14
+ readonly include?: string[];
15
+ readonly exclude?: string[];
16
+ constructor(plugin: NormalizedPlugin, pluginDefinition: PluginConfiguration);
17
+ }
18
+ export type CreateNodesResultWithContext = CreateNodesResult & {
19
+ file: string;
20
+ pluginName: string;
21
+ };
22
+ export type NormalizedPlugin = NxPluginV2 & Pick<NxPluginV1, 'processProjectGraph'>;
23
+ export declare const nxPluginCache: Map<unknown, [
24
+ Promise<LoadedNxPlugin>,
25
+ () => void
26
+ ]>;
27
+ export declare function loadNxPlugins(plugins: PluginConfiguration[], root?: string): Promise<[LoadedNxPlugin[], () => void]>;
28
+ export declare function getDefaultPlugins(root: string): Promise<string[]>;
@@ -0,0 +1,85 @@
1
+ "use strict";
2
+ // This file contains the bits and bobs of the internal API for loading and interacting with Nx plugins.
3
+ // For the public API, used by plugin authors, see `./public-api.ts`.
4
+ Object.defineProperty(exports, "__esModule", { value: true });
5
+ exports.getDefaultPlugins = exports.loadNxPlugins = exports.nxPluginCache = exports.LoadedNxPlugin = void 0;
6
+ const path_1 = require("path");
7
+ const workspace_root_1 = require("../../utils/workspace-root");
8
+ const angular_json_1 = require("../../adapter/angular-json");
9
+ const utils_1 = require("./utils");
10
+ const isolation_1 = require("./isolation");
11
+ const loader_1 = require("./loader");
12
+ class LoadedNxPlugin {
13
+ constructor(plugin, pluginDefinition) {
14
+ this.name = plugin.name;
15
+ if (typeof pluginDefinition !== 'string') {
16
+ this.options = pluginDefinition.options;
17
+ this.include = pluginDefinition.include;
18
+ this.exclude = pluginDefinition.exclude;
19
+ }
20
+ if (plugin.createNodes) {
21
+ this.createNodes = [
22
+ plugin.createNodes[0],
23
+ (files, context) => (0, utils_1.runCreateNodesInParallel)(files, plugin, this.options, context),
24
+ ];
25
+ }
26
+ if (plugin.createDependencies) {
27
+ this.createDependencies = (context) => plugin.createDependencies(this.options, context);
28
+ }
29
+ this.processProjectGraph = plugin.processProjectGraph;
30
+ }
31
+ }
32
+ exports.LoadedNxPlugin = LoadedNxPlugin;
33
+ // Short lived cache (cleared between cmd runs)
34
+ // holding resolved nx plugin objects.
35
+ // Allows loaded plugins to not be reloaded when
36
+ // referenced multiple times.
37
+ exports.nxPluginCache = new Map();
38
+ async function loadNxPlugins(plugins, root = workspace_root_1.workspaceRoot) {
39
+ const result = [];
40
+ const loadingMethod = process.env.NX_ISOLATE_PLUGINS === 'true'
41
+ ? isolation_1.loadNxPluginInIsolation
42
+ : loader_1.loadNxPlugin;
43
+ plugins = await normalizePlugins(plugins, root);
44
+ const cleanupFunctions = [];
45
+ for (const plugin of plugins) {
46
+ const [loadedPluginPromise, cleanup] = loadingMethod(plugin, root);
47
+ result.push(loadedPluginPromise);
48
+ cleanupFunctions.push(cleanup);
49
+ }
50
+ return [
51
+ await Promise.all(result),
52
+ () => {
53
+ for (const fn of cleanupFunctions) {
54
+ fn();
55
+ }
56
+ if (loader_1.unregisterPluginTSTranspiler) {
57
+ (0, loader_1.unregisterPluginTSTranspiler)();
58
+ }
59
+ },
60
+ ];
61
+ }
62
+ exports.loadNxPlugins = loadNxPlugins;
63
+ async function normalizePlugins(plugins, root) {
64
+ plugins ??= [];
65
+ return [
66
+ // This plugin adds targets that we want to be able to overwrite
67
+ // in any user-land plugin, so it has to be first :).
68
+ (0, path_1.join)(__dirname, '../../plugins/project-json/build-nodes/package-json-next-to-project-json'),
69
+ ...plugins,
70
+ // Most of the nx core node plugins go on the end, s.t. it overwrites any other plugins
71
+ ...(await getDefaultPlugins(root)),
72
+ ];
73
+ }
74
+ async function getDefaultPlugins(root) {
75
+ return [
76
+ (0, path_1.join)(__dirname, '../../plugins/js'),
77
+ (0, path_1.join)(__dirname, '../../plugins/target-defaults/target-defaults-plugin'),
78
+ ...((0, angular_json_1.shouldMergeAngularProjects)(root, false)
79
+ ? [(0, path_1.join)(__dirname, '../../adapter/angular-json')]
80
+ : []),
81
+ (0, path_1.join)(__dirname, '../../plugins/package-json-workspaces'),
82
+ (0, path_1.join)(__dirname, '../../plugins/project-json/build-nodes/project-json'),
83
+ ];
84
+ }
85
+ exports.getDefaultPlugins = getDefaultPlugins;
@@ -0,0 +1,3 @@
1
+ import { PluginConfiguration } from '../../../config/nx-json';
2
+ import { LoadedNxPlugin } from '../internal-api';
3
+ export declare function loadNxPluginInIsolation(plugin: PluginConfiguration, root?: string): [Promise<LoadedNxPlugin>, () => void];
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.loadNxPluginInIsolation = void 0;
4
+ const workspace_root_1 = require("../../../utils/workspace-root");
5
+ const plugin_pool_1 = require("./plugin-pool");
6
+ const remotePluginCache = new Map();
7
+ function loadNxPluginInIsolation(plugin, root = workspace_root_1.workspaceRoot) {
8
+ const cacheKey = JSON.stringify(plugin);
9
+ if (remotePluginCache.has(cacheKey)) {
10
+ return remotePluginCache.get(cacheKey);
11
+ }
12
+ const [loadingPlugin, cleanup] = (0, plugin_pool_1.loadRemoteNxPlugin)(plugin, root);
13
+ remotePluginCache.set(cacheKey, [loadingPlugin, cleanup]);
14
+ return [loadingPlugin, cleanup];
15
+ }
16
+ exports.loadNxPluginInIsolation = loadNxPluginInIsolation;
@@ -0,0 +1,94 @@
1
+ import { ProjectGraph, ProjectGraphProcessorContext } from '../../../config/project-graph';
2
+ import { PluginConfiguration } from '../../../config/nx-json';
3
+ import { CreateDependenciesContext, CreateNodesContext } from '../public-api';
4
+ import { LoadedNxPlugin } from '../internal-api';
5
+ export interface PluginWorkerLoadMessage {
6
+ type: 'load';
7
+ payload: {
8
+ plugin: PluginConfiguration;
9
+ root: string;
10
+ };
11
+ }
12
+ export interface PluginWorkerLoadResult {
13
+ type: 'load-result';
14
+ payload: {
15
+ name: string;
16
+ createNodesPattern: string;
17
+ hasCreateDependencies: boolean;
18
+ hasProcessProjectGraph: boolean;
19
+ success: true;
20
+ } | {
21
+ success: false;
22
+ error: string;
23
+ };
24
+ }
25
+ export interface PluginWorkerCreateNodesMessage {
26
+ type: 'createNodes';
27
+ payload: {
28
+ configFiles: string[];
29
+ context: CreateNodesContext;
30
+ tx: string;
31
+ };
32
+ }
33
+ export interface PluginWorkerCreateNodesResult {
34
+ type: 'createNodesResult';
35
+ payload: {
36
+ success: true;
37
+ result: Awaited<ReturnType<LoadedNxPlugin['createNodes'][1]>>;
38
+ tx: string;
39
+ } | {
40
+ success: false;
41
+ error: string;
42
+ tx: string;
43
+ };
44
+ }
45
+ export interface PluginCreateDependenciesMessage {
46
+ type: 'createDependencies';
47
+ payload: {
48
+ context: CreateDependenciesContext;
49
+ tx: string;
50
+ };
51
+ }
52
+ export interface PluginCreateDependenciesResult {
53
+ type: 'createDependenciesResult';
54
+ payload: {
55
+ dependencies: ReturnType<LoadedNxPlugin['createDependencies']>;
56
+ success: true;
57
+ tx: string;
58
+ } | {
59
+ success: false;
60
+ error: string;
61
+ tx: string;
62
+ };
63
+ }
64
+ export interface PluginWorkerProcessProjectGraphMessage {
65
+ type: 'processProjectGraph';
66
+ payload: {
67
+ graph: ProjectGraph;
68
+ ctx: ProjectGraphProcessorContext;
69
+ tx: string;
70
+ };
71
+ }
72
+ export interface PluginWorkerProcessProjectGraphResult {
73
+ type: 'processProjectGraphResult';
74
+ payload: {
75
+ graph: ProjectGraph;
76
+ success: true;
77
+ tx: string;
78
+ } | {
79
+ success: false;
80
+ error: string;
81
+ tx: string;
82
+ };
83
+ }
84
+ export type PluginWorkerMessage = PluginWorkerLoadMessage | PluginWorkerCreateNodesMessage | PluginCreateDependenciesMessage | PluginWorkerProcessProjectGraphMessage;
85
+ export type PluginWorkerResult = PluginWorkerLoadResult | PluginWorkerCreateNodesResult | PluginCreateDependenciesResult | PluginWorkerProcessProjectGraphResult;
86
+ type MaybePromise<T> = T | Promise<T>;
87
+ type MessageHandlerReturn<T extends PluginWorkerMessage | PluginWorkerResult> = T extends PluginWorkerResult ? MaybePromise<PluginWorkerMessage | void> : MaybePromise<PluginWorkerResult | void>;
88
+ export declare function consumeMessage<T extends PluginWorkerMessage | PluginWorkerResult>(raw: string | T, handlers: {
89
+ [K in T['type']]: (payload: Extract<T, {
90
+ type: K;
91
+ }>['payload']) => MessageHandlerReturn<T>;
92
+ }): Promise<void>;
93
+ export declare function createMessage(message: PluginWorkerMessage | PluginWorkerResult): string;
94
+ export {};
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createMessage = exports.consumeMessage = void 0;
4
+ // Takes a message and a map of handlers and calls the appropriate handler
5
+ // type safe and requires all handlers to be handled
6
+ async function consumeMessage(raw, handlers) {
7
+ const message = typeof raw === 'string' ? JSON.parse(raw) : raw;
8
+ const handler = handlers[message.type];
9
+ if (handler) {
10
+ const response = await handler(message.payload);
11
+ if (response) {
12
+ process.send(createMessage(response));
13
+ }
14
+ }
15
+ else {
16
+ throw new Error(`Unhandled message type: ${message.type}`);
17
+ }
18
+ }
19
+ exports.consumeMessage = consumeMessage;
20
+ function createMessage(message) {
21
+ return JSON.stringify(message);
22
+ }
23
+ exports.createMessage = createMessage;
@@ -0,0 +1,3 @@
1
+ import { PluginConfiguration } from '../../../config/nx-json';
2
+ import { LoadedNxPlugin } from '../internal-api';
3
+ export declare function loadRemoteNxPlugin(plugin: PluginConfiguration, root: string): [Promise<LoadedNxPlugin>, () => void];