nx 19.0.0-beta.3 → 19.0.0-beta.4
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.
- package/package.json +12 -12
- package/src/daemon/server/project-graph-incremental-recomputation.js +8 -8
- package/src/devkit-exports.d.ts +1 -1
- package/src/devkit-internals.d.ts +1 -0
- package/src/devkit-internals.js +3 -1
- package/src/executors/utils/convert-nx-executor.js +2 -1
- package/src/generators/utils/project-configuration.js +2 -2
- package/src/project-graph/build-project-graph.d.ts +8 -18
- package/src/project-graph/build-project-graph.js +58 -54
- package/src/project-graph/error-types.d.ts +26 -3
- package/src/project-graph/error-types.js +57 -1
- package/src/project-graph/file-utils.js +1 -1
- package/src/project-graph/plugins/internal-api.d.ts +3 -2
- package/src/project-graph/plugins/internal-api.js +3 -0
- package/src/project-graph/plugins/isolation/messaging.d.ts +24 -3
- package/src/project-graph/plugins/isolation/plugin-pool.js +20 -0
- package/src/project-graph/plugins/isolation/plugin-worker.js +16 -0
- package/src/project-graph/plugins/loader.js +13 -5
- package/src/project-graph/plugins/public-api.d.ts +10 -0
- package/src/project-graph/project-graph.js +6 -6
- package/src/project-graph/utils/find-project-for-path.js +2 -3
- package/src/project-graph/utils/normalize-project-nodes.d.ts +1 -1
- package/src/project-graph/utils/normalize-project-nodes.js +8 -8
- package/src/project-graph/utils/project-configuration-utils.d.ts +21 -5
- package/src/project-graph/utils/project-configuration-utils.js +23 -14
- package/src/project-graph/utils/retrieve-workspace-files.d.ts +3 -3
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "nx",
|
3
|
-
"version": "19.0.0-beta.
|
3
|
+
"version": "19.0.0-beta.4",
|
4
4
|
"private": false,
|
5
5
|
"description": "The core Nx plugin contains the core functionality of Nx like the project graph, nx commands and task orchestration.",
|
6
6
|
"repository": {
|
@@ -66,7 +66,7 @@
|
|
66
66
|
"yargs-parser": "21.1.1",
|
67
67
|
"node-machine-id": "1.1.12",
|
68
68
|
"ora": "5.3.0",
|
69
|
-
"@nrwl/tao": "19.0.0-beta.
|
69
|
+
"@nrwl/tao": "19.0.0-beta.4"
|
70
70
|
},
|
71
71
|
"peerDependencies": {
|
72
72
|
"@swc-node/register": "^1.8.0",
|
@@ -81,16 +81,16 @@
|
|
81
81
|
}
|
82
82
|
},
|
83
83
|
"optionalDependencies": {
|
84
|
-
"@nx/nx-darwin-x64": "19.0.0-beta.
|
85
|
-
"@nx/nx-darwin-arm64": "19.0.0-beta.
|
86
|
-
"@nx/nx-linux-x64-gnu": "19.0.0-beta.
|
87
|
-
"@nx/nx-linux-x64-musl": "19.0.0-beta.
|
88
|
-
"@nx/nx-win32-x64-msvc": "19.0.0-beta.
|
89
|
-
"@nx/nx-linux-arm64-gnu": "19.0.0-beta.
|
90
|
-
"@nx/nx-linux-arm64-musl": "19.0.0-beta.
|
91
|
-
"@nx/nx-linux-arm-gnueabihf": "19.0.0-beta.
|
92
|
-
"@nx/nx-win32-arm64-msvc": "19.0.0-beta.
|
93
|
-
"@nx/nx-freebsd-x64": "19.0.0-beta.
|
84
|
+
"@nx/nx-darwin-x64": "19.0.0-beta.4",
|
85
|
+
"@nx/nx-darwin-arm64": "19.0.0-beta.4",
|
86
|
+
"@nx/nx-linux-x64-gnu": "19.0.0-beta.4",
|
87
|
+
"@nx/nx-linux-x64-musl": "19.0.0-beta.4",
|
88
|
+
"@nx/nx-win32-x64-msvc": "19.0.0-beta.4",
|
89
|
+
"@nx/nx-linux-arm64-gnu": "19.0.0-beta.4",
|
90
|
+
"@nx/nx-linux-arm64-musl": "19.0.0-beta.4",
|
91
|
+
"@nx/nx-linux-arm-gnueabihf": "19.0.0-beta.4",
|
92
|
+
"@nx/nx-win32-arm64-msvc": "19.0.0-beta.4",
|
93
|
+
"@nx/nx-freebsd-x64": "19.0.0-beta.4"
|
94
94
|
},
|
95
95
|
"nx-migrations": {
|
96
96
|
"migrations": "./migrations.json",
|
@@ -142,26 +142,26 @@ async function processFilesAndCreateAndSerializeProjectGraph(plugins) {
|
|
142
142
|
logger_1.serverLogger.requestLog([...deletedFiles]);
|
143
143
|
const nxJson = (0, nx_json_1.readNxJson)(workspace_root_1.workspaceRoot);
|
144
144
|
global.NX_GRAPH_CREATION = true;
|
145
|
-
let
|
145
|
+
let projectConfigurationsResult;
|
146
146
|
let projectConfigurationsError;
|
147
147
|
try {
|
148
|
-
|
148
|
+
projectConfigurationsResult = await (0, retrieve_workspace_files_1.retrieveProjectConfigurations)(plugins, workspace_root_1.workspaceRoot, nxJson);
|
149
149
|
}
|
150
150
|
catch (e) {
|
151
151
|
if (e instanceof error_types_1.ProjectConfigurationsError) {
|
152
|
-
|
152
|
+
projectConfigurationsResult = e.partialProjectConfigurationsResult;
|
153
153
|
projectConfigurationsError = e;
|
154
154
|
}
|
155
155
|
else {
|
156
156
|
throw e;
|
157
157
|
}
|
158
158
|
}
|
159
|
-
await processCollectedUpdatedAndDeletedFiles(
|
160
|
-
const g = await createAndSerializeProjectGraph(
|
159
|
+
await processCollectedUpdatedAndDeletedFiles(projectConfigurationsResult, updatedFileHashes, deletedFiles);
|
160
|
+
const g = await createAndSerializeProjectGraph(projectConfigurationsResult);
|
161
161
|
delete global.NX_GRAPH_CREATION;
|
162
162
|
const errors = [...(projectConfigurationsError?.errors ?? [])];
|
163
163
|
if (g.error) {
|
164
|
-
if (g.error
|
164
|
+
if ((0, error_types_1.isAggregateProjectGraphError)(g.error)) {
|
165
165
|
errors.push(...g.error.errors);
|
166
166
|
}
|
167
167
|
else {
|
@@ -179,7 +179,7 @@ async function processFilesAndCreateAndSerializeProjectGraph(plugins) {
|
|
179
179
|
}
|
180
180
|
if (errors.length > 0) {
|
181
181
|
return {
|
182
|
-
error: new error_types_1.DaemonProjectGraphError(errors, g.projectGraph,
|
182
|
+
error: new error_types_1.DaemonProjectGraphError(errors, g.projectGraph, projectConfigurationsResult.sourceMaps),
|
183
183
|
projectGraph: null,
|
184
184
|
projectFileMapCache: null,
|
185
185
|
fileMap: null,
|
@@ -226,7 +226,7 @@ async function createAndSerializeProjectGraph({ projects, sourceMaps, }) {
|
|
226
226
|
const fileMap = copyFileMap(exports.fileMapWithFiles.fileMap);
|
227
227
|
const allWorkspaceFiles = copyFileData(exports.fileMapWithFiles.allWorkspaceFiles);
|
228
228
|
const rustReferences = exports.fileMapWithFiles.rustReferences;
|
229
|
-
const { projectGraph, projectFileMapCache } = await (0, build_project_graph_1.buildProjectGraphUsingProjectFileMap)(projects, knownExternalNodes, fileMap, allWorkspaceFiles, rustReferences, exports.currentProjectFileMapCache || (0, nx_deps_cache_1.readFileMapCache)(), await (0, plugins_1.getPlugins)());
|
229
|
+
const { projectGraph, projectFileMapCache } = await (0, build_project_graph_1.buildProjectGraphUsingProjectFileMap)(projects, knownExternalNodes, fileMap, allWorkspaceFiles, rustReferences, exports.currentProjectFileMapCache || (0, nx_deps_cache_1.readFileMapCache)(), await (0, plugins_1.getPlugins)(), sourceMaps);
|
230
230
|
exports.currentProjectFileMapCache = projectFileMapCache;
|
231
231
|
exports.currentProjectGraph = projectGraph;
|
232
232
|
perf_hooks_1.performance.mark('create-project-graph-end');
|
package/src/devkit-exports.d.ts
CHANGED
@@ -19,7 +19,7 @@ export type { Generator, GeneratorCallback, Executor, ExecutorContext, TaskGraph
|
|
19
19
|
*/
|
20
20
|
export { Workspaces } from './config/workspaces';
|
21
21
|
export { workspaceLayout } from './config/configuration';
|
22
|
-
export type { NxPlugin, NxPluginV2, CreateNodes, CreateNodesFunction, CreateNodesResult, CreateNodesContext, CreateDependencies, CreateDependenciesContext, } from './project-graph/plugins';
|
22
|
+
export type { NxPlugin, NxPluginV2, CreateNodes, CreateNodesFunction, CreateNodesResult, CreateNodesContext, CreateDependencies, CreateDependenciesContext, CreateMetadata, CreateMetadataContext, ProjectsMetadata, } from './project-graph/plugins';
|
23
23
|
export type { NxPluginV1, ProjectTargetConfigurator, } from './utils/nx-plugin.deprecated';
|
24
24
|
/**
|
25
25
|
* @category Workspace
|
@@ -8,6 +8,7 @@ export { getExecutorInformation } from './command-line/run/executor-utils';
|
|
8
8
|
export { readNxJson as readNxJsonFromDisk } from './config/nx-json';
|
9
9
|
export { calculateDefaultProjectName } from './config/calculate-default-project-name';
|
10
10
|
export { retrieveProjectConfigurationsWithAngularProjects } from './project-graph/utils/retrieve-workspace-files';
|
11
|
+
export { readProjectConfigurationsFromRootMap } from './project-graph/utils/project-configuration-utils';
|
11
12
|
export { splitTarget } from './utils/split-target';
|
12
13
|
export { combineOptionsForExecutor } from './utils/params';
|
13
14
|
export { sortObjectByKeys } from './utils/object-sort';
|
package/src/devkit-internals.js
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.registerTsProject = exports.LoadedNxPlugin = exports.retrieveProjectConfigurations = exports.findProjectForPath = exports.createProjectRootMappingsFromProjectConfigurations = exports.hashWithWorkspaceContext = exports.hashObject = exports.splitByColons = exports.readModulePackageJson = exports.stripIndent = exports.sortObjectByKeys = exports.combineOptionsForExecutor = exports.splitTarget = exports.retrieveProjectConfigurationsWithAngularProjects = exports.calculateDefaultProjectName = exports.readNxJsonFromDisk = exports.getExecutorInformation = exports.createTempNpmDirectory = void 0;
|
3
|
+
exports.registerTsProject = exports.LoadedNxPlugin = exports.retrieveProjectConfigurations = exports.findProjectForPath = exports.createProjectRootMappingsFromProjectConfigurations = exports.hashWithWorkspaceContext = exports.hashObject = exports.splitByColons = exports.readModulePackageJson = exports.stripIndent = exports.sortObjectByKeys = exports.combineOptionsForExecutor = exports.splitTarget = exports.readProjectConfigurationsFromRootMap = exports.retrieveProjectConfigurationsWithAngularProjects = exports.calculateDefaultProjectName = exports.readNxJsonFromDisk = exports.getExecutorInformation = exports.createTempNpmDirectory = void 0;
|
4
4
|
const tslib_1 = require("tslib");
|
5
5
|
/**
|
6
6
|
* Note to developers: STOP! These exports are available via requireNx in @nx/devkit.
|
@@ -17,6 +17,8 @@ var calculate_default_project_name_1 = require("./config/calculate-default-proje
|
|
17
17
|
Object.defineProperty(exports, "calculateDefaultProjectName", { enumerable: true, get: function () { return calculate_default_project_name_1.calculateDefaultProjectName; } });
|
18
18
|
var retrieve_workspace_files_1 = require("./project-graph/utils/retrieve-workspace-files");
|
19
19
|
Object.defineProperty(exports, "retrieveProjectConfigurationsWithAngularProjects", { enumerable: true, get: function () { return retrieve_workspace_files_1.retrieveProjectConfigurationsWithAngularProjects; } });
|
20
|
+
var project_configuration_utils_1 = require("./project-graph/utils/project-configuration-utils");
|
21
|
+
Object.defineProperty(exports, "readProjectConfigurationsFromRootMap", { enumerable: true, get: function () { return project_configuration_utils_1.readProjectConfigurationsFromRootMap; } });
|
20
22
|
var split_target_1 = require("./utils/split-target");
|
21
23
|
Object.defineProperty(exports, "splitTarget", { enumerable: true, get: function () { return split_target_1.splitTarget; } });
|
22
24
|
var params_1 = require("./utils/params");
|
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.convertNxExecutor = void 0;
|
7
7
|
const nx_json_1 = require("../../config/nx-json");
|
8
8
|
const retrieve_workspace_files_1 = require("../../project-graph/utils/retrieve-workspace-files");
|
9
|
+
const project_configuration_utils_1 = require("../../project-graph/utils/project-configuration-utils");
|
9
10
|
const internal_api_1 = require("../../project-graph/plugins/internal-api");
|
10
11
|
/**
|
11
12
|
* Convert an Nx Executor into an Angular Devkit Builder
|
@@ -19,7 +20,7 @@ function convertNxExecutor(executor) {
|
|
19
20
|
const [plugins, cleanup] = await (0, internal_api_1.loadNxPlugins)(nxJsonConfiguration.plugins, builderContext.workspaceRoot);
|
20
21
|
const projectsConfigurations = {
|
21
22
|
version: 2,
|
22
|
-
projects: (await (0, retrieve_workspace_files_1.retrieveProjectConfigurations)(plugins, builderContext.workspaceRoot, nxJsonConfiguration)).projects,
|
23
|
+
projects: (0, project_configuration_utils_1.readProjectConfigurationsFromRootMap)((await (0, retrieve_workspace_files_1.retrieveProjectConfigurations)(plugins, builderContext.workspaceRoot, nxJsonConfiguration)).projects),
|
23
24
|
};
|
24
25
|
cleanup();
|
25
26
|
const context = {
|
@@ -143,7 +143,7 @@ function readAndCombineAllProjectConfigurations(tree) {
|
|
143
143
|
const createdFiles = findCreatedProjectFiles(tree, patterns);
|
144
144
|
const deletedFiles = findDeletedProjectFiles(tree, patterns);
|
145
145
|
const projectFiles = [...globbedFiles, ...createdFiles].filter((r) => deletedFiles.indexOf(r) === -1);
|
146
|
-
const rootMap =
|
146
|
+
const rootMap = {};
|
147
147
|
for (const projectFile of projectFiles) {
|
148
148
|
if ((0, path_1.basename)(projectFile) === 'project.json') {
|
149
149
|
const json = (0, json_1.readJson)(tree, projectFile);
|
@@ -153,7 +153,7 @@ function readAndCombineAllProjectConfigurations(tree) {
|
|
153
153
|
else if ((0, path_1.basename)(projectFile) === 'package.json') {
|
154
154
|
const packageJson = (0, json_1.readJson)(tree, projectFile);
|
155
155
|
const config = (0, package_json_workspaces_1.buildProjectConfigurationFromPackageJson)(packageJson, projectFile, (0, nx_json_1.readNxJson)(tree));
|
156
|
-
if (!rootMap
|
156
|
+
if (!rootMap[config.root]) {
|
157
157
|
(0, project_configuration_utils_1.mergeProjectConfigurationIntoRootMap)(rootMap,
|
158
158
|
// Inferred targets, tags, etc don't show up when running generators
|
159
159
|
// This is to help avoid running into issues when trying to update the workspace
|
@@ -1,32 +1,22 @@
|
|
1
1
|
import { FileData } from './file-utils';
|
2
2
|
import { FileMapCache } from './nx-deps-cache';
|
3
3
|
import { LoadedNxPlugin } from './plugins/internal-api';
|
4
|
+
import { CreateMetadataContext } from './plugins';
|
4
5
|
import { FileMap, ProjectGraph, ProjectGraphExternalNode } from '../config/project-graph';
|
5
6
|
import { ProjectConfiguration } from '../config/workspace-json-project-json';
|
6
7
|
import { NxWorkspaceFilesExternals } from '../native';
|
8
|
+
import { CreateMetadataError } from './error-types';
|
9
|
+
import { ConfigurationSourceMaps } from './utils/project-configuration-utils';
|
7
10
|
export declare function getFileMap(): {
|
8
11
|
fileMap: FileMap;
|
9
12
|
allWorkspaceFiles: FileData[];
|
10
13
|
rustReferences: NxWorkspaceFilesExternals | null;
|
11
14
|
};
|
12
|
-
export declare function buildProjectGraphUsingProjectFileMap(
|
15
|
+
export declare function buildProjectGraphUsingProjectFileMap(projectRootMap: Record<string, ProjectConfiguration>, externalNodes: Record<string, ProjectGraphExternalNode>, fileMap: FileMap, allWorkspaceFiles: FileData[], rustReferences: NxWorkspaceFilesExternals, fileMapCache: FileMapCache | null, plugins: LoadedNxPlugin[], sourceMap: ConfigurationSourceMaps): Promise<{
|
13
16
|
projectGraph: ProjectGraph;
|
14
17
|
projectFileMapCache: FileMapCache;
|
15
18
|
}>;
|
16
|
-
export declare
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
});
|
21
|
-
}
|
22
|
-
export declare class ProcessProjectGraphError extends Error {
|
23
|
-
readonly pluginName: string;
|
24
|
-
constructor(pluginName: string, { cause }: {
|
25
|
-
cause: any;
|
26
|
-
});
|
27
|
-
}
|
28
|
-
export declare class CreateDependenciesError extends Error {
|
29
|
-
readonly errors: Array<ProcessDependenciesError | ProcessProjectGraphError>;
|
30
|
-
readonly partialProjectGraph: ProjectGraph;
|
31
|
-
constructor(errors: Array<ProcessDependenciesError | ProcessProjectGraphError>, partialProjectGraph: ProjectGraph);
|
32
|
-
}
|
19
|
+
export declare function applyProjectMetadata(graph: ProjectGraph, plugins: LoadedNxPlugin[], context: CreateMetadataContext, sourceMap: ConfigurationSourceMaps): Promise<{
|
20
|
+
graph: ProjectGraph;
|
21
|
+
errors?: CreateMetadataError[];
|
22
|
+
}>;
|
@@ -1,6 +1,6 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.
|
3
|
+
exports.applyProjectMetadata = exports.buildProjectGraphUsingProjectFileMap = exports.getFileMap = void 0;
|
4
4
|
const workspace_root_1 = require("../utils/workspace-root");
|
5
5
|
const path_1 = require("path");
|
6
6
|
const perf_hooks_1 = require("perf_hooks");
|
@@ -15,6 +15,8 @@ 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
17
|
const output_1 = require("../utils/output");
|
18
|
+
const error_types_1 = require("./error-types");
|
19
|
+
const project_configuration_utils_1 = require("./utils/project-configuration-utils");
|
18
20
|
let storedFileMap = null;
|
19
21
|
let storedAllWorkspaceFiles = null;
|
20
22
|
let storedRustReferences = null;
|
@@ -38,10 +40,15 @@ function getFileMap() {
|
|
38
40
|
}
|
39
41
|
}
|
40
42
|
exports.getFileMap = getFileMap;
|
41
|
-
async function buildProjectGraphUsingProjectFileMap(
|
43
|
+
async function buildProjectGraphUsingProjectFileMap(projectRootMap, externalNodes, fileMap, allWorkspaceFiles, rustReferences, fileMapCache, plugins, sourceMap) {
|
42
44
|
storedFileMap = fileMap;
|
43
45
|
storedAllWorkspaceFiles = allWorkspaceFiles;
|
44
46
|
storedRustReferences = rustReferences;
|
47
|
+
const projects = {};
|
48
|
+
for (const root in projectRootMap) {
|
49
|
+
const project = projectRootMap[root];
|
50
|
+
projects[project.name] = project;
|
51
|
+
}
|
45
52
|
const nxJson = (0, configuration_1.readNxJson)();
|
46
53
|
const projectGraphVersion = '6.0';
|
47
54
|
(0, assert_workspace_validity_1.assertWorkspaceValidity)(projects, nxJson);
|
@@ -64,7 +71,7 @@ async function buildProjectGraphUsingProjectFileMap(projects, externalNodes, fil
|
|
64
71
|
};
|
65
72
|
}
|
66
73
|
const context = createContext(projects, nxJson, externalNodes, fileMap, filesToProcess);
|
67
|
-
let projectGraph = await buildProjectGraphUsingContext(externalNodes, context, cachedFileData, projectGraphVersion, plugins);
|
74
|
+
let projectGraph = await buildProjectGraphUsingContext(externalNodes, context, cachedFileData, projectGraphVersion, plugins, sourceMap);
|
68
75
|
const projectFileMapCache = (0, nx_deps_cache_1.createProjectFileMapCache)(nxJson, packageJsonDeps, fileMap, rootTsConfig);
|
69
76
|
return {
|
70
77
|
projectGraph,
|
@@ -88,7 +95,7 @@ function readCombinedDeps() {
|
|
88
95
|
...installationPackageJson.devDependencies,
|
89
96
|
};
|
90
97
|
}
|
91
|
-
async function buildProjectGraphUsingContext(knownExternalNodes, ctx, cachedFileData, projectGraphVersion, plugins) {
|
98
|
+
async function buildProjectGraphUsingContext(knownExternalNodes, ctx, cachedFileData, projectGraphVersion, plugins, sourceMap) {
|
92
99
|
perf_hooks_1.performance.mark('build project graph:start');
|
93
100
|
const builder = new project_graph_builder_1.ProjectGraphBuilder(null, ctx.fileMap.projectFileMap);
|
94
101
|
builder.setVersion(projectGraphVersion);
|
@@ -100,10 +107,10 @@ async function buildProjectGraphUsingContext(knownExternalNodes, ctx, cachedFile
|
|
100
107
|
let updatedGraph;
|
101
108
|
let error;
|
102
109
|
try {
|
103
|
-
updatedGraph = await updateProjectGraphWithPlugins(ctx, initProjectGraph, plugins);
|
110
|
+
updatedGraph = await updateProjectGraphWithPlugins(ctx, initProjectGraph, plugins, sourceMap);
|
104
111
|
}
|
105
112
|
catch (e) {
|
106
|
-
if (
|
113
|
+
if ((0, error_types_1.isAggregateProjectGraphError)(e)) {
|
107
114
|
updatedGraph = e.partialProjectGraph;
|
108
115
|
error = e;
|
109
116
|
}
|
@@ -134,26 +141,20 @@ async function buildProjectGraphUsingContext(knownExternalNodes, ctx, cachedFile
|
|
134
141
|
return finalGraph;
|
135
142
|
}
|
136
143
|
else {
|
137
|
-
throw new
|
144
|
+
throw new error_types_1.AggregateProjectGraphError(error.errors, finalGraph);
|
138
145
|
}
|
139
146
|
}
|
140
147
|
function createContext(projects, nxJson, externalNodes, fileMap, filesToProcess) {
|
141
|
-
const clonedProjects = Object.keys(projects).reduce((map, projectName) => {
|
142
|
-
map[projectName] = {
|
143
|
-
...projects[projectName],
|
144
|
-
};
|
145
|
-
return map;
|
146
|
-
}, {});
|
147
148
|
return {
|
148
149
|
nxJsonConfiguration: nxJson,
|
149
|
-
projects
|
150
|
+
projects,
|
150
151
|
externalNodes,
|
151
152
|
workspaceRoot: workspace_root_1.workspaceRoot,
|
152
153
|
fileMap,
|
153
154
|
filesToProcess,
|
154
155
|
};
|
155
156
|
}
|
156
|
-
async function updateProjectGraphWithPlugins(context, initProjectGraph, plugins) {
|
157
|
+
async function updateProjectGraphWithPlugins(context, initProjectGraph, plugins, sourceMap) {
|
157
158
|
let graph = initProjectGraph;
|
158
159
|
const errors = [];
|
159
160
|
for (const plugin of plugins) {
|
@@ -187,7 +188,7 @@ async function updateProjectGraphWithPlugins(context, initProjectGraph, plugins)
|
|
187
188
|
}
|
188
189
|
}
|
189
190
|
catch (e) {
|
190
|
-
errors.push(new ProcessProjectGraphError(plugin.name, {
|
191
|
+
errors.push(new error_types_1.ProcessProjectGraphError(plugin.name, {
|
191
192
|
cause: e,
|
192
193
|
}));
|
193
194
|
}
|
@@ -205,52 +206,24 @@ async function updateProjectGraphWithPlugins(context, initProjectGraph, plugins)
|
|
205
206
|
}
|
206
207
|
}
|
207
208
|
catch (cause) {
|
208
|
-
errors.push(new ProcessDependenciesError(plugin.name, {
|
209
|
+
errors.push(new error_types_1.ProcessDependenciesError(plugin.name, {
|
209
210
|
cause,
|
210
211
|
}));
|
211
212
|
}
|
212
213
|
perf_hooks_1.performance.mark(`${plugin.name}:createDependencies - end`);
|
213
214
|
perf_hooks_1.performance.measure(`${plugin.name}:createDependencies`, `${plugin.name}:createDependencies - start`, `${plugin.name}:createDependencies - end`);
|
214
215
|
}));
|
215
|
-
const
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
class ProcessDependenciesError extends Error {
|
224
|
-
constructor(pluginName, { cause }) {
|
225
|
-
super(`The "${pluginName}" plugin threw an error while creating dependencies:`, {
|
226
|
-
cause,
|
227
|
-
});
|
228
|
-
this.pluginName = pluginName;
|
229
|
-
this.name = this.constructor.name;
|
230
|
-
this.stack = `${this.message}\n ${cause.stack.split('\n').join('\n ')}`;
|
231
|
-
}
|
232
|
-
}
|
233
|
-
exports.ProcessDependenciesError = ProcessDependenciesError;
|
234
|
-
class ProcessProjectGraphError extends Error {
|
235
|
-
constructor(pluginName, { cause }) {
|
236
|
-
super(`The "${pluginName}" plugin threw an error while processing the project graph:`, {
|
237
|
-
cause,
|
238
|
-
});
|
239
|
-
this.pluginName = pluginName;
|
240
|
-
this.name = this.constructor.name;
|
241
|
-
this.stack = `${this.message}\n ${cause.stack.split('\n').join('\n ')}`;
|
242
|
-
}
|
243
|
-
}
|
244
|
-
exports.ProcessProjectGraphError = ProcessProjectGraphError;
|
245
|
-
class CreateDependenciesError extends Error {
|
246
|
-
constructor(errors, partialProjectGraph) {
|
247
|
-
super('Failed to create dependencies. See above for errors');
|
248
|
-
this.errors = errors;
|
249
|
-
this.partialProjectGraph = partialProjectGraph;
|
250
|
-
this.name = this.constructor.name;
|
216
|
+
const graphWithDeps = builder.getUpdatedProjectGraph();
|
217
|
+
const { errors: metadataErrors, graph: updatedGraph } = await applyProjectMetadata(graphWithDeps, plugins, {
|
218
|
+
nxJsonConfiguration: context.nxJsonConfiguration,
|
219
|
+
workspaceRoot: workspace_root_1.workspaceRoot,
|
220
|
+
}, sourceMap);
|
221
|
+
errors.push(...metadataErrors);
|
222
|
+
if (errors.length > 0) {
|
223
|
+
throw new error_types_1.AggregateProjectGraphError(errors, updatedGraph);
|
251
224
|
}
|
225
|
+
return updatedGraph;
|
252
226
|
}
|
253
|
-
exports.CreateDependenciesError = CreateDependenciesError;
|
254
227
|
function readRootTsConfig() {
|
255
228
|
try {
|
256
229
|
const tsConfigPath = (0, typescript_1.getRootTsConfigPath)();
|
@@ -262,3 +235,34 @@ function readRootTsConfig() {
|
|
262
235
|
return {};
|
263
236
|
}
|
264
237
|
}
|
238
|
+
async function applyProjectMetadata(graph, plugins, context, sourceMap) {
|
239
|
+
const results = [];
|
240
|
+
const errors = [];
|
241
|
+
const promises = plugins.map(async (plugin) => {
|
242
|
+
if ((0, utils_1.isNxPluginV2)(plugin) && plugin.createMetadata) {
|
243
|
+
perf_hooks_1.performance.mark(`${plugin.name}:createMetadata - start`);
|
244
|
+
try {
|
245
|
+
const metadata = await plugin.createMetadata(graph, undefined, context);
|
246
|
+
results.push({ metadata, pluginName: plugin.name });
|
247
|
+
}
|
248
|
+
catch (e) {
|
249
|
+
errors.push(new error_types_1.CreateMetadataError(e, plugin.name));
|
250
|
+
}
|
251
|
+
finally {
|
252
|
+
perf_hooks_1.performance.mark(`${plugin.name}:createMetadata - end`);
|
253
|
+
perf_hooks_1.performance.measure(`${plugin.name}:createMetadata`, `${plugin.name}:createMetadata - start`, `${plugin.name}:createMetadata - end`);
|
254
|
+
}
|
255
|
+
}
|
256
|
+
});
|
257
|
+
await Promise.all(promises);
|
258
|
+
for (const { metadata: projectsMetadata, pluginName } of results) {
|
259
|
+
for (const project in projectsMetadata) {
|
260
|
+
const projectConfiguration = graph.nodes[project]?.data;
|
261
|
+
if (projectConfiguration) {
|
262
|
+
projectConfiguration.metadata = (0, project_configuration_utils_1.mergeMetadata)(sourceMap[project], [null, pluginName], 'metadata', projectsMetadata[project].metadata, projectConfiguration.metadata);
|
263
|
+
}
|
264
|
+
}
|
265
|
+
}
|
266
|
+
return { errors, graph };
|
267
|
+
}
|
268
|
+
exports.applyProjectMetadata = applyProjectMetadata;
|
@@ -1,11 +1,10 @@
|
|
1
1
|
import { CreateNodesResultWithContext } from './plugins/internal-api';
|
2
2
|
import { ConfigurationResult, ConfigurationSourceMaps } from './utils/project-configuration-utils';
|
3
3
|
import { ProjectConfiguration } from '../config/workspace-json-project-json';
|
4
|
-
import { ProcessDependenciesError, ProcessProjectGraphError } from './build-project-graph';
|
5
4
|
import { ProjectGraph } from '../config/project-graph';
|
6
5
|
export declare class ProjectGraphError extends Error {
|
7
6
|
#private;
|
8
|
-
constructor(errors: Array<CreateNodesError | MergeNodesError | ProjectsWithNoNameError | ProjectsWithConflictingNamesError | ProcessDependenciesError | ProcessProjectGraphError>, partialProjectGraph: ProjectGraph, partialSourceMaps: ConfigurationSourceMaps);
|
7
|
+
constructor(errors: Array<CreateNodesError | MergeNodesError | ProjectsWithNoNameError | ProjectsWithConflictingNamesError | ProcessDependenciesError | ProcessProjectGraphError | CreateMetadataError>, partialProjectGraph: ProjectGraph, partialSourceMaps: ConfigurationSourceMaps);
|
9
8
|
/**
|
10
9
|
* The daemon cannot throw errors which contain methods as they are not serializable.
|
11
10
|
*
|
@@ -19,7 +18,7 @@ export declare class ProjectGraphError extends Error {
|
|
19
18
|
*/
|
20
19
|
getPartialProjectGraph(): ProjectGraph;
|
21
20
|
getPartialSourcemaps(): ConfigurationSourceMaps;
|
22
|
-
getErrors(): (
|
21
|
+
getErrors(): (CreateNodesError | MergeNodesError | CreateMetadataError | ProjectsWithNoNameError | ProjectsWithConflictingNamesError | ProcessDependenciesError | ProcessProjectGraphError)[];
|
23
22
|
}
|
24
23
|
export declare class ProjectsWithConflictingNamesError extends Error {
|
25
24
|
projects: Record<string, ProjectConfiguration>;
|
@@ -60,6 +59,30 @@ export declare class MergeNodesError extends Error {
|
|
60
59
|
error: Error;
|
61
60
|
});
|
62
61
|
}
|
62
|
+
export declare class CreateMetadataError extends Error {
|
63
|
+
readonly error: Error;
|
64
|
+
readonly plugin: string;
|
65
|
+
constructor(error: Error, plugin: string);
|
66
|
+
}
|
67
|
+
export declare class ProcessDependenciesError extends Error {
|
68
|
+
readonly pluginName: string;
|
69
|
+
constructor(pluginName: string, { cause }: {
|
70
|
+
cause: any;
|
71
|
+
});
|
72
|
+
}
|
73
|
+
export declare class ProcessProjectGraphError extends Error {
|
74
|
+
readonly pluginName: string;
|
75
|
+
constructor(pluginName: string, { cause }: {
|
76
|
+
cause: any;
|
77
|
+
});
|
78
|
+
}
|
79
|
+
export declare class AggregateProjectGraphError extends Error {
|
80
|
+
readonly errors: Array<CreateMetadataError | ProcessDependenciesError | ProcessProjectGraphError>;
|
81
|
+
readonly partialProjectGraph: ProjectGraph;
|
82
|
+
constructor(errors: Array<CreateMetadataError | ProcessDependenciesError | ProcessProjectGraphError>, partialProjectGraph: ProjectGraph);
|
83
|
+
}
|
84
|
+
export declare function isAggregateProjectGraphError(e: unknown): e is AggregateProjectGraphError;
|
85
|
+
export declare function isCreateMetadataError(e: unknown): e is CreateMetadataError;
|
63
86
|
export declare function isCreateNodesError(e: unknown): e is CreateNodesError;
|
64
87
|
export declare function isAggregateCreateNodesError(e: unknown): e is AggregateCreateNodesError;
|
65
88
|
export declare function isMergeNodesError(e: unknown): e is MergeNodesError;
|
@@ -1,7 +1,7 @@
|
|
1
1
|
"use strict";
|
2
2
|
var _ProjectGraphError_errors, _ProjectGraphError_partialProjectGraph, _ProjectGraphError_partialSourceMaps;
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
4
|
-
exports.LoadPluginError = exports.DaemonProjectGraphError = exports.isMergeNodesError = exports.isAggregateCreateNodesError = exports.isCreateNodesError = exports.MergeNodesError = exports.AggregateCreateNodesError = exports.CreateNodesError = exports.ProjectConfigurationsError = exports.isProjectsWithNoNameError = exports.ProjectsWithNoNameError = exports.isProjectsWithConflictingNamesError = exports.ProjectsWithConflictingNamesError = exports.ProjectGraphError = void 0;
|
4
|
+
exports.LoadPluginError = exports.DaemonProjectGraphError = exports.isMergeNodesError = exports.isAggregateCreateNodesError = exports.isCreateNodesError = exports.isCreateMetadataError = exports.isAggregateProjectGraphError = exports.AggregateProjectGraphError = exports.ProcessProjectGraphError = exports.ProcessDependenciesError = exports.CreateMetadataError = exports.MergeNodesError = exports.AggregateCreateNodesError = exports.CreateNodesError = exports.ProjectConfigurationsError = exports.isProjectsWithNoNameError = exports.ProjectsWithNoNameError = exports.isProjectsWithConflictingNamesError = exports.ProjectsWithConflictingNamesError = exports.ProjectGraphError = void 0;
|
5
5
|
const tslib_1 = require("tslib");
|
6
6
|
class ProjectGraphError extends Error {
|
7
7
|
constructor(errors, partialProjectGraph, partialSourceMaps) {
|
@@ -118,6 +118,62 @@ class MergeNodesError extends Error {
|
|
118
118
|
}
|
119
119
|
}
|
120
120
|
exports.MergeNodesError = MergeNodesError;
|
121
|
+
class CreateMetadataError extends Error {
|
122
|
+
constructor(error, plugin) {
|
123
|
+
super(`The "${plugin}" plugin threw an error while creating metadata:`, {
|
124
|
+
cause: error,
|
125
|
+
});
|
126
|
+
this.error = error;
|
127
|
+
this.plugin = plugin;
|
128
|
+
this.name = this.constructor.name;
|
129
|
+
}
|
130
|
+
}
|
131
|
+
exports.CreateMetadataError = CreateMetadataError;
|
132
|
+
class ProcessDependenciesError extends Error {
|
133
|
+
constructor(pluginName, { cause }) {
|
134
|
+
super(`The "${pluginName}" plugin threw an error while creating dependencies:`, {
|
135
|
+
cause,
|
136
|
+
});
|
137
|
+
this.pluginName = pluginName;
|
138
|
+
this.name = this.constructor.name;
|
139
|
+
this.stack = `${this.message}\n ${cause.stack.split('\n').join('\n ')}`;
|
140
|
+
}
|
141
|
+
}
|
142
|
+
exports.ProcessDependenciesError = ProcessDependenciesError;
|
143
|
+
class ProcessProjectGraphError extends Error {
|
144
|
+
constructor(pluginName, { cause }) {
|
145
|
+
super(`The "${pluginName}" plugin threw an error while processing the project graph:`, {
|
146
|
+
cause,
|
147
|
+
});
|
148
|
+
this.pluginName = pluginName;
|
149
|
+
this.name = this.constructor.name;
|
150
|
+
this.stack = `${this.message}\n ${cause.stack.split('\n').join('\n ')}`;
|
151
|
+
}
|
152
|
+
}
|
153
|
+
exports.ProcessProjectGraphError = ProcessProjectGraphError;
|
154
|
+
class AggregateProjectGraphError extends Error {
|
155
|
+
constructor(errors, partialProjectGraph) {
|
156
|
+
super('Failed to create project graph. See above for errors');
|
157
|
+
this.errors = errors;
|
158
|
+
this.partialProjectGraph = partialProjectGraph;
|
159
|
+
this.name = this.constructor.name;
|
160
|
+
}
|
161
|
+
}
|
162
|
+
exports.AggregateProjectGraphError = AggregateProjectGraphError;
|
163
|
+
function isAggregateProjectGraphError(e) {
|
164
|
+
return (e instanceof AggregateProjectGraphError ||
|
165
|
+
(typeof e === 'object' &&
|
166
|
+
'name' in e &&
|
167
|
+
e?.name === AggregateProjectGraphError.prototype.name));
|
168
|
+
}
|
169
|
+
exports.isAggregateProjectGraphError = isAggregateProjectGraphError;
|
170
|
+
function isCreateMetadataError(e) {
|
171
|
+
return (e instanceof CreateMetadataError ||
|
172
|
+
(typeof e === 'object' &&
|
173
|
+
'name' in e &&
|
174
|
+
e?.name === CreateMetadataError.prototype.name));
|
175
|
+
}
|
176
|
+
exports.isCreateMetadataError = isCreateMetadataError;
|
121
177
|
function isCreateNodesError(e) {
|
122
178
|
return (e instanceof CreateNodesError ||
|
123
179
|
(typeof e === 'object' && 'name' in e && e?.name === CreateNodesError.name));
|
@@ -152,7 +152,7 @@ function getProjectsSyncNoInference(root, nxJson) {
|
|
152
152
|
package_json_next_to_project_json_1.PackageJsonProjectsNextToProjectJsonPlugin,
|
153
153
|
...(0, nx_plugin_deprecated_1.getDefaultPluginsSync)(root),
|
154
154
|
];
|
155
|
-
const projectRootMap =
|
155
|
+
const projectRootMap = {};
|
156
156
|
// We iterate over plugins first - this ensures that plugins specified first take precedence.
|
157
157
|
for (const plugin of plugins) {
|
158
158
|
const [pattern, createNodes] = plugin.createNodes ?? [];
|
@@ -1,7 +1,7 @@
|
|
1
1
|
import { PluginConfiguration } from '../../config/nx-json';
|
2
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';
|
3
|
+
import { CreateDependencies, CreateDependenciesContext, CreateMetadata, CreateMetadataContext, CreateNodesContext, CreateNodesResult, NxPluginV2 } from './public-api';
|
4
|
+
import { ProjectGraph, ProjectGraphProcessor } from '../../config/project-graph';
|
5
5
|
export declare class LoadedNxPlugin {
|
6
6
|
readonly name: string;
|
7
7
|
readonly createNodes?: [
|
@@ -9,6 +9,7 @@ export declare class LoadedNxPlugin {
|
|
9
9
|
fn: (matchedFiles: string[], context: CreateNodesContext) => Promise<CreateNodesResultWithContext[]>
|
10
10
|
];
|
11
11
|
readonly createDependencies?: (context: CreateDependenciesContext) => ReturnType<CreateDependencies>;
|
12
|
+
readonly createMetadata?: (graph: ProjectGraph, context: CreateMetadataContext) => ReturnType<CreateMetadata>;
|
12
13
|
readonly processProjectGraph?: ProjectGraphProcessor;
|
13
14
|
readonly options?: unknown;
|
14
15
|
readonly include?: string[];
|
@@ -26,6 +26,9 @@ class LoadedNxPlugin {
|
|
26
26
|
if (plugin.createDependencies) {
|
27
27
|
this.createDependencies = (context) => plugin.createDependencies(this.options, context);
|
28
28
|
}
|
29
|
+
if (plugin.createMetadata) {
|
30
|
+
this.createMetadata = (graph, context) => plugin.createMetadata(graph, this.options, context);
|
31
|
+
}
|
29
32
|
this.processProjectGraph = plugin.processProjectGraph;
|
30
33
|
}
|
31
34
|
}
|
@@ -1,7 +1,7 @@
|
|
1
1
|
/// <reference types="node" />
|
2
2
|
import { ProjectGraph, ProjectGraphProcessorContext } from '../../../config/project-graph';
|
3
3
|
import { PluginConfiguration } from '../../../config/nx-json';
|
4
|
-
import { CreateDependenciesContext, CreateNodesContext } from '../public-api';
|
4
|
+
import { CreateDependenciesContext, CreateMetadataContext, CreateNodesContext } from '../public-api';
|
5
5
|
import { LoadedNxPlugin } from '../internal-api';
|
6
6
|
import { Serializable } from 'child_process';
|
7
7
|
export interface PluginWorkerLoadMessage {
|
@@ -18,6 +18,7 @@ export interface PluginWorkerLoadResult {
|
|
18
18
|
createNodesPattern: string;
|
19
19
|
hasCreateDependencies: boolean;
|
20
20
|
hasProcessProjectGraph: boolean;
|
21
|
+
hasCreateMetadata: boolean;
|
21
22
|
success: true;
|
22
23
|
} | {
|
23
24
|
success: false;
|
@@ -51,6 +52,14 @@ export interface PluginCreateDependenciesMessage {
|
|
51
52
|
tx: string;
|
52
53
|
};
|
53
54
|
}
|
55
|
+
export interface PluginCreateMetadataMessage {
|
56
|
+
type: 'createMetadata';
|
57
|
+
payload: {
|
58
|
+
graph: ProjectGraph;
|
59
|
+
context: CreateMetadataContext;
|
60
|
+
tx: string;
|
61
|
+
};
|
62
|
+
}
|
54
63
|
export interface PluginCreateDependenciesResult {
|
55
64
|
type: 'createDependenciesResult';
|
56
65
|
payload: {
|
@@ -63,6 +72,18 @@ export interface PluginCreateDependenciesResult {
|
|
63
72
|
tx: string;
|
64
73
|
};
|
65
74
|
}
|
75
|
+
export interface PluginCreateMetadataResult {
|
76
|
+
type: 'createMetadataResult';
|
77
|
+
payload: {
|
78
|
+
metadata: ReturnType<LoadedNxPlugin['createMetadata']>;
|
79
|
+
success: true;
|
80
|
+
tx: string;
|
81
|
+
} | {
|
82
|
+
success: false;
|
83
|
+
error: string;
|
84
|
+
tx: string;
|
85
|
+
};
|
86
|
+
}
|
66
87
|
export interface PluginWorkerProcessProjectGraphMessage {
|
67
88
|
type: 'processProjectGraph';
|
68
89
|
payload: {
|
@@ -83,8 +104,8 @@ export interface PluginWorkerProcessProjectGraphResult {
|
|
83
104
|
tx: string;
|
84
105
|
};
|
85
106
|
}
|
86
|
-
export type PluginWorkerMessage = PluginWorkerLoadMessage | PluginWorkerCreateNodesMessage | PluginCreateDependenciesMessage | PluginWorkerProcessProjectGraphMessage;
|
87
|
-
export type PluginWorkerResult = PluginWorkerLoadResult | PluginWorkerCreateNodesResult | PluginCreateDependenciesResult | PluginWorkerProcessProjectGraphResult;
|
107
|
+
export type PluginWorkerMessage = PluginWorkerLoadMessage | PluginWorkerCreateNodesMessage | PluginCreateDependenciesMessage | PluginWorkerProcessProjectGraphMessage | PluginCreateMetadataMessage;
|
108
|
+
export type PluginWorkerResult = PluginWorkerLoadResult | PluginWorkerCreateNodesResult | PluginCreateDependenciesResult | PluginWorkerProcessProjectGraphResult | PluginCreateMetadataResult;
|
88
109
|
export declare function isPluginWorkerMessage(message: Serializable): message is PluginWorkerMessage;
|
89
110
|
export declare function isPluginWorkerResult(message: Serializable): message is PluginWorkerResult;
|
90
111
|
type MaybePromise<T> = T | Promise<T>;
|
@@ -114,6 +114,17 @@ function createWorkerHandler(worker, pending, onload, onloadError) {
|
|
114
114
|
});
|
115
115
|
}
|
116
116
|
: undefined,
|
117
|
+
createMetadata: result.hasCreateMetadata
|
118
|
+
? (graph, ctx) => {
|
119
|
+
const tx = pluginName + ':createMetadata:' + performance.now();
|
120
|
+
return registerPendingPromise(tx, pending, () => {
|
121
|
+
worker.send({
|
122
|
+
type: 'createMetadata',
|
123
|
+
payload: { graph, context: ctx, tx },
|
124
|
+
});
|
125
|
+
});
|
126
|
+
}
|
127
|
+
: undefined,
|
117
128
|
});
|
118
129
|
}
|
119
130
|
else if (result.success === false) {
|
@@ -147,6 +158,15 @@ function createWorkerHandler(worker, pending, onload, onloadError) {
|
|
147
158
|
rejector(result.error);
|
148
159
|
}
|
149
160
|
},
|
161
|
+
createMetadataResult: ({ tx, ...result }) => {
|
162
|
+
const { resolver, rejector } = pending.get(tx);
|
163
|
+
if (result.success) {
|
164
|
+
resolver(result.metadata);
|
165
|
+
}
|
166
|
+
else if (result.success === false) {
|
167
|
+
rejector(result.error);
|
168
|
+
}
|
169
|
+
},
|
150
170
|
});
|
151
171
|
};
|
152
172
|
}
|
@@ -22,6 +22,7 @@ process.on('message', async (message) => {
|
|
22
22
|
createNodesPattern: plugin.createNodes?.[0],
|
23
23
|
hasCreateDependencies: 'createDependencies' in plugin && !!plugin.createDependencies,
|
24
24
|
hasProcessProjectGraph: 'processProjectGraph' in plugin && !!plugin.processProjectGraph,
|
25
|
+
hasCreateMetadata: 'createMetadata' in plugin && !!plugin.createMetadata,
|
25
26
|
success: true,
|
26
27
|
},
|
27
28
|
};
|
@@ -93,5 +94,20 @@ process.on('message', async (message) => {
|
|
93
94
|
};
|
94
95
|
}
|
95
96
|
},
|
97
|
+
createMetadata: async ({ graph, context, tx }) => {
|
98
|
+
try {
|
99
|
+
const result = await plugin.createMetadata(graph, context);
|
100
|
+
return {
|
101
|
+
type: 'createMetadataResult',
|
102
|
+
payload: { metadata: result, success: true, tx },
|
103
|
+
};
|
104
|
+
}
|
105
|
+
catch (e) {
|
106
|
+
return {
|
107
|
+
type: 'createMetadataResult',
|
108
|
+
payload: { success: false, error: e.stack, tx },
|
109
|
+
};
|
110
|
+
}
|
111
|
+
},
|
96
112
|
});
|
97
113
|
});
|
@@ -32,6 +32,9 @@ function readPluginPackageJson(pluginName, projects, paths = (0, installation_di
|
|
32
32
|
const localPluginPath = resolveLocalNxPlugin(pluginName, projects);
|
33
33
|
if (localPluginPath) {
|
34
34
|
const localPluginPackageJson = path.join(localPluginPath.path, 'package.json');
|
35
|
+
if (!exports.unregisterPluginTSTranspiler) {
|
36
|
+
registerPluginTSTranspiler();
|
37
|
+
}
|
35
38
|
return {
|
36
39
|
path: localPluginPackageJson,
|
37
40
|
json: (0, fileutils_1.readJsonFile)(localPluginPackageJson),
|
@@ -77,22 +80,27 @@ function registerPluginTSTranspiler() {
|
|
77
80
|
}
|
78
81
|
exports.registerPluginTSTranspiler = registerPluginTSTranspiler;
|
79
82
|
function lookupLocalPlugin(importPath, projects, root = workspace_root_1.workspaceRoot) {
|
80
|
-
const
|
81
|
-
if (!
|
83
|
+
const projectConfig = findNxProjectForImportPath(importPath, projects, root);
|
84
|
+
if (!projectConfig) {
|
82
85
|
return null;
|
83
86
|
}
|
84
|
-
const projectConfig = projects[plugin];
|
85
87
|
return { path: path.join(root, projectConfig.root), projectConfig };
|
86
88
|
}
|
87
89
|
function findNxProjectForImportPath(importPath, projects, root = workspace_root_1.workspaceRoot) {
|
88
90
|
const tsConfigPaths = readTsConfigPaths(root);
|
89
91
|
const possiblePaths = tsConfigPaths[importPath]?.map((p) => (0, path_1.normalizePath)(path.relative(root, path.join(root, p))));
|
90
92
|
if (possiblePaths?.length) {
|
91
|
-
const projectRootMappings =
|
93
|
+
const projectRootMappings = new Map();
|
94
|
+
const projectNameMap = new Map();
|
95
|
+
for (const projectRoot in projects) {
|
96
|
+
const project = projects[projectRoot];
|
97
|
+
projectRootMappings.set(project.root, project.name);
|
98
|
+
projectNameMap.set(project.name, project);
|
99
|
+
}
|
92
100
|
for (const tsConfigPath of possiblePaths) {
|
93
101
|
const nxProject = (0, find_project_for_path_1.findProjectForPath)(tsConfigPath, projectRootMappings);
|
94
102
|
if (nxProject) {
|
95
|
-
return nxProject;
|
103
|
+
return projectNameMap.get(nxProject);
|
96
104
|
}
|
97
105
|
}
|
98
106
|
logger_1.logger.verbose('Unable to find local plugin', possiblePaths, projectRootMappings);
|
@@ -68,6 +68,12 @@ export interface CreateDependenciesContext {
|
|
68
68
|
* Use {@link validateDependency} to validate dependencies
|
69
69
|
*/
|
70
70
|
export type CreateDependencies<T = unknown> = (options: T | undefined, context: CreateDependenciesContext) => RawProjectGraphDependency[] | Promise<RawProjectGraphDependency[]>;
|
71
|
+
export type CreateMetadataContext = {
|
72
|
+
readonly nxJsonConfiguration: NxJsonConfiguration;
|
73
|
+
readonly workspaceRoot: string;
|
74
|
+
};
|
75
|
+
export type ProjectsMetadata = Record<string, Pick<ProjectConfiguration, 'metadata'>>;
|
76
|
+
export type CreateMetadata<T = unknown> = (graph: ProjectGraph, options: T | undefined, context: CreateMetadataContext) => ProjectsMetadata | Promise<ProjectsMetadata>;
|
71
77
|
/**
|
72
78
|
* A plugin for Nx which creates nodes and dependencies for the {@link ProjectGraph}
|
73
79
|
*/
|
@@ -82,6 +88,10 @@ export type NxPluginV2<TOptions = unknown> = {
|
|
82
88
|
* Provides a function to analyze files to create dependencies for the {@link ProjectGraph}
|
83
89
|
*/
|
84
90
|
createDependencies?: CreateDependencies<TOptions>;
|
91
|
+
/**
|
92
|
+
* Provides a function to create metadata for the {@link ProjectGraph}
|
93
|
+
*/
|
94
|
+
createMetadata?: CreateMetadata<TOptions>;
|
85
95
|
};
|
86
96
|
/**
|
87
97
|
* A plugin for Nx
|
@@ -10,8 +10,8 @@ const output_1 = require("../utils/output");
|
|
10
10
|
const strip_indents_1 = require("../utils/strip-indents");
|
11
11
|
const workspace_root_1 = require("../utils/workspace-root");
|
12
12
|
const build_project_graph_1 = require("./build-project-graph");
|
13
|
-
const nx_deps_cache_1 = require("./nx-deps-cache");
|
14
13
|
const error_types_1 = require("./error-types");
|
14
|
+
const nx_deps_cache_1 = require("./nx-deps-cache");
|
15
15
|
const internal_api_1 = require("./plugins/internal-api");
|
16
16
|
const retrieve_workspace_files_1 = require("./utils/retrieve-workspace-files");
|
17
17
|
/**
|
@@ -92,18 +92,18 @@ async function buildProjectGraphAndSourceMapsWithoutDaemon() {
|
|
92
92
|
perf_hooks_1.performance.mark('retrieve-workspace-files:end');
|
93
93
|
const cacheEnabled = process.env.NX_CACHE_PROJECT_GRAPH !== 'false';
|
94
94
|
perf_hooks_1.performance.mark('build-project-graph-using-project-file-map:start');
|
95
|
-
let
|
95
|
+
let projectGraphError;
|
96
96
|
let projectGraphResult;
|
97
97
|
try {
|
98
|
-
projectGraphResult = await (0, build_project_graph_1.buildProjectGraphUsingProjectFileMap)(projects, externalNodes, fileMap, allWorkspaceFiles, rustReferences, cacheEnabled ? (0, nx_deps_cache_1.readFileMapCache)() : null, plugins);
|
98
|
+
projectGraphResult = await (0, build_project_graph_1.buildProjectGraphUsingProjectFileMap)(projects, externalNodes, fileMap, allWorkspaceFiles, rustReferences, cacheEnabled ? (0, nx_deps_cache_1.readFileMapCache)() : null, plugins, sourceMaps);
|
99
99
|
}
|
100
100
|
catch (e) {
|
101
|
-
if (
|
101
|
+
if ((0, error_types_1.isAggregateProjectGraphError)(e)) {
|
102
102
|
projectGraphResult = {
|
103
103
|
projectGraph: e.partialProjectGraph,
|
104
104
|
projectFileMapCache: null,
|
105
105
|
};
|
106
|
-
|
106
|
+
projectGraphError = e;
|
107
107
|
}
|
108
108
|
else {
|
109
109
|
throw e;
|
@@ -117,7 +117,7 @@ async function buildProjectGraphAndSourceMapsWithoutDaemon() {
|
|
117
117
|
delete global.NX_GRAPH_CREATION;
|
118
118
|
const errors = [
|
119
119
|
...(projectConfigurationsError?.errors ?? []),
|
120
|
-
...(
|
120
|
+
...(projectGraphError?.errors ?? []),
|
121
121
|
];
|
122
122
|
if (errors.length > 0) {
|
123
123
|
throw new error_types_1.ProjectGraphError(errors, projectGraph, sourceMaps);
|
@@ -9,9 +9,8 @@ const path_2 = require("../../utils/path");
|
|
9
9
|
*/
|
10
10
|
function createProjectRootMappingsFromProjectConfigurations(projects) {
|
11
11
|
const projectRootMappings = new Map();
|
12
|
-
for (const
|
13
|
-
|
14
|
-
projectRootMappings.set(normalizeProjectRoot(root), projectName);
|
12
|
+
for (const { name, root } of Object.values(projects)) {
|
13
|
+
projectRootMappings.set(normalizeProjectRoot(root), name);
|
15
14
|
}
|
16
15
|
return projectRootMappings;
|
17
16
|
}
|
@@ -2,7 +2,7 @@ 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
4
|
import { CreateDependenciesContext } from '../plugins';
|
5
|
-
export declare function normalizeProjectNodes(
|
5
|
+
export declare function normalizeProjectNodes({ projects }: CreateDependenciesContext, builder: ProjectGraphBuilder): Promise<void>;
|
6
6
|
/**
|
7
7
|
* Apply target defaults and normalization
|
8
8
|
*/
|
@@ -3,15 +3,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.normalizeImplicitDependencies = exports.normalizeProjectTargets = exports.normalizeProjectNodes = void 0;
|
4
4
|
const find_matching_projects_1 = require("../../utils/find-matching-projects");
|
5
5
|
const project_configuration_utils_1 = require("../utils/project-configuration-utils");
|
6
|
-
async function normalizeProjectNodes(
|
7
|
-
const toAdd = [];
|
6
|
+
async function normalizeProjectNodes({ projects }, builder) {
|
8
7
|
// Sorting projects by name to make sure that the order of projects in the graph is deterministic.
|
9
8
|
// This is important to ensure that expanded properties referencing projects (e.g. implicit dependencies)
|
10
9
|
// are also deterministic, and thus don't cause the calculated project configuration hash to shift.
|
11
|
-
const
|
10
|
+
const sortedProjectNames = Object.keys(projects).sort();
|
12
11
|
// Used for expanding implicit dependencies (e.g. `@proj/*` or `tag:foo`)
|
13
|
-
const partialProjectGraphNodes =
|
14
|
-
const projectConfiguration =
|
12
|
+
const partialProjectGraphNodes = sortedProjectNames.reduce((graph, project) => {
|
13
|
+
const projectConfiguration = projects[project];
|
15
14
|
graph[project] = {
|
16
15
|
name: project,
|
17
16
|
type: projectConfiguration.projectType === 'library' ? 'lib' : 'app', // missing fallback to `e2e`
|
@@ -21,8 +20,9 @@ async function normalizeProjectNodes(ctx, builder) {
|
|
21
20
|
};
|
22
21
|
return graph;
|
23
22
|
}, {});
|
24
|
-
|
25
|
-
|
23
|
+
const toAdd = [];
|
24
|
+
for (const key of sortedProjectNames) {
|
25
|
+
const p = projects[key];
|
26
26
|
p.implicitDependencies = normalizeImplicitDependencies(key, p.implicitDependencies, partialProjectGraphNodes);
|
27
27
|
p.targets = normalizeProjectTargets(p, key);
|
28
28
|
// TODO: remove in v16
|
@@ -31,7 +31,7 @@ async function normalizeProjectNodes(ctx, builder) {
|
|
31
31
|
? 'e2e'
|
32
32
|
: 'app'
|
33
33
|
: 'lib';
|
34
|
-
const tags =
|
34
|
+
const tags = p.tags || [];
|
35
35
|
toAdd.push({
|
36
36
|
name: key,
|
37
37
|
type: projectType,
|
@@ -1,20 +1,36 @@
|
|
1
1
|
import { NxJsonConfiguration, TargetDefaults } from '../../config/nx-json';
|
2
2
|
import { ProjectGraphExternalNode } from '../../config/project-graph';
|
3
|
-
import { ProjectConfiguration, TargetConfiguration } from '../../config/workspace-json-project-json';
|
3
|
+
import { ProjectConfiguration, ProjectMetadata, TargetConfiguration, TargetMetadata } from '../../config/workspace-json-project-json';
|
4
4
|
import { ONLY_MODIFIES_EXISTING_TARGET } from '../../plugins/target-defaults/symbols';
|
5
5
|
import { LoadedNxPlugin } from '../plugins/internal-api';
|
6
|
-
export type SourceInformation = [file: string, plugin: string];
|
6
|
+
export type SourceInformation = [file: string | null, plugin: string];
|
7
7
|
export type ConfigurationSourceMaps = Record<string, Record<string, SourceInformation>>;
|
8
|
-
export declare function mergeProjectConfigurationIntoRootMap(projectRootMap:
|
8
|
+
export declare function mergeProjectConfigurationIntoRootMap(projectRootMap: Record<string, ProjectConfiguration>, project: ProjectConfiguration & {
|
9
9
|
targets?: Record<string, TargetConfiguration & {
|
10
10
|
[ONLY_MODIFIES_EXISTING_TARGET]?: boolean;
|
11
11
|
}>;
|
12
12
|
}, configurationSourceMaps?: ConfigurationSourceMaps, sourceInformation?: SourceInformation, skipCommandNormalization?: boolean): void;
|
13
|
+
export declare function mergeMetadata<T = ProjectMetadata | TargetMetadata>(sourceMap: Record<string, [file: string, plugin: string]>, sourceInformation: [file: string, plugin: string], baseSourceMapPath: string, metadata: T, matchingMetadata?: T): T;
|
13
14
|
export type ConfigurationResult = {
|
14
|
-
|
15
|
+
/**
|
16
|
+
* A map of project configurations, keyed by project root.
|
17
|
+
*/
|
18
|
+
projects: {
|
19
|
+
[projectRoot: string]: ProjectConfiguration;
|
20
|
+
};
|
21
|
+
/**
|
22
|
+
* Node Name -> Node info
|
23
|
+
*/
|
15
24
|
externalNodes: Record<string, ProjectGraphExternalNode>;
|
25
|
+
/**
|
26
|
+
* Project Root -> Project Name
|
27
|
+
*/
|
16
28
|
projectRootMap: Record<string, string>;
|
17
29
|
sourceMaps: ConfigurationSourceMaps;
|
30
|
+
/**
|
31
|
+
* The list of files that were used to create project configurations
|
32
|
+
*/
|
33
|
+
matchingProjectFiles: string[];
|
18
34
|
};
|
19
35
|
/**
|
20
36
|
* Transforms a list of project paths into a map of project configurations.
|
@@ -26,7 +42,7 @@ export type ConfigurationResult = {
|
|
26
42
|
*/
|
27
43
|
export declare function createProjectConfigurations(root: string, nxJson: NxJsonConfiguration, projectFiles: string[], // making this parameter allows devkit to pick up newly created projects
|
28
44
|
plugins: LoadedNxPlugin[]): Promise<ConfigurationResult>;
|
29
|
-
export declare function readProjectConfigurationsFromRootMap(projectRootMap:
|
45
|
+
export declare function readProjectConfigurationsFromRootMap(projectRootMap: Record<string, ProjectConfiguration>): Record<string, ProjectConfiguration>;
|
30
46
|
/**
|
31
47
|
* Merges two targets.
|
32
48
|
*
|
@@ -1,6 +1,6 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.readTargetDefaultsForTarget = exports.resolveNxTokensInOptions = exports.isCompatibleTarget = exports.mergeTargetConfigurations = exports.readProjectConfigurationsFromRootMap = exports.createProjectConfigurations = exports.mergeProjectConfigurationIntoRootMap = void 0;
|
3
|
+
exports.readTargetDefaultsForTarget = exports.resolveNxTokensInOptions = exports.isCompatibleTarget = exports.mergeTargetConfigurations = exports.readProjectConfigurationsFromRootMap = exports.createProjectConfigurations = exports.mergeMetadata = 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");
|
@@ -17,12 +17,12 @@ skipCommandNormalization) {
|
|
17
17
|
configurationSourceMaps[project.root] = {};
|
18
18
|
}
|
19
19
|
const sourceMap = configurationSourceMaps?.[project.root];
|
20
|
-
let matchingProject = projectRootMap
|
20
|
+
let matchingProject = projectRootMap[project.root];
|
21
21
|
if (!matchingProject) {
|
22
|
-
projectRootMap
|
22
|
+
projectRootMap[project.root] = {
|
23
23
|
root: project.root,
|
24
|
-
}
|
25
|
-
matchingProject = projectRootMap
|
24
|
+
};
|
25
|
+
matchingProject = projectRootMap[project.root];
|
26
26
|
if (sourceMap) {
|
27
27
|
sourceMap[`root`] = sourceInformation;
|
28
28
|
}
|
@@ -138,7 +138,8 @@ skipCommandNormalization) {
|
|
138
138
|
updatedProjectConfiguration.targets[targetName] = mergedTarget;
|
139
139
|
}
|
140
140
|
}
|
141
|
-
projectRootMap
|
141
|
+
projectRootMap[updatedProjectConfiguration.root] =
|
142
|
+
updatedProjectConfiguration;
|
142
143
|
}
|
143
144
|
exports.mergeProjectConfigurationIntoRootMap = mergeProjectConfigurationIntoRootMap;
|
144
145
|
function mergeMetadata(sourceMap, sourceInformation, baseSourceMapPath, metadata, matchingMetadata) {
|
@@ -210,6 +211,7 @@ function mergeMetadata(sourceMap, sourceInformation, baseSourceMapPath, metadata
|
|
210
211
|
}
|
211
212
|
return result;
|
212
213
|
}
|
214
|
+
exports.mergeMetadata = mergeMetadata;
|
213
215
|
/**
|
214
216
|
* Transforms a list of project paths into a map of project configurations.
|
215
217
|
*
|
@@ -264,7 +266,7 @@ plugins) {
|
|
264
266
|
}
|
265
267
|
return Promise.all(results).then((results) => {
|
266
268
|
perf_hooks_1.performance.mark('createNodes:merge - start');
|
267
|
-
const projectRootMap =
|
269
|
+
const projectRootMap = {};
|
268
270
|
const externalNodes = {};
|
269
271
|
const configurationSourceMaps = {};
|
270
272
|
for (const result of results.flat()) {
|
@@ -291,14 +293,17 @@ plugins) {
|
|
291
293
|
}
|
292
294
|
Object.assign(externalNodes, pluginExternalNodes);
|
293
295
|
}
|
294
|
-
let projects;
|
295
296
|
try {
|
296
|
-
|
297
|
+
// We still call this just to assert that the root map
|
298
|
+
// only contains valid project names. This is a safety check.
|
299
|
+
//
|
300
|
+
// The signature itself can't be changed as we need it to return
|
301
|
+
// project configurations for use in devkit.
|
302
|
+
readProjectConfigurationsFromRootMap(projectRootMap);
|
297
303
|
}
|
298
304
|
catch (e) {
|
299
305
|
if ((0, error_types_1.isProjectsWithNoNameError)(e) ||
|
300
306
|
(0, error_types_1.isProjectsWithConflictingNamesError)(e)) {
|
301
|
-
projects = e.projects;
|
302
307
|
errors.push(e);
|
303
308
|
}
|
304
309
|
else {
|
@@ -312,18 +317,20 @@ plugins) {
|
|
312
317
|
perf_hooks_1.performance.measure('build-project-configs', 'build-project-configs:start', 'build-project-configs:end');
|
313
318
|
if (errors.length === 0) {
|
314
319
|
return {
|
315
|
-
projects,
|
320
|
+
projects: projectRootMap,
|
316
321
|
externalNodes,
|
317
322
|
projectRootMap: rootMap,
|
318
323
|
sourceMaps: configurationSourceMaps,
|
324
|
+
matchingProjectFiles: projectFiles,
|
319
325
|
};
|
320
326
|
}
|
321
327
|
else {
|
322
328
|
throw new error_types_1.ProjectConfigurationsError(errors, {
|
323
|
-
projects,
|
329
|
+
projects: projectRootMap,
|
324
330
|
externalNodes,
|
325
331
|
projectRootMap: rootMap,
|
326
332
|
sourceMaps: configurationSourceMaps,
|
333
|
+
matchingProjectFiles: projectFiles,
|
327
334
|
});
|
328
335
|
}
|
329
336
|
});
|
@@ -336,7 +343,8 @@ function readProjectConfigurationsFromRootMap(projectRootMap) {
|
|
336
343
|
// to provide better error messaging.
|
337
344
|
const conflicts = new Map();
|
338
345
|
const projectRootsWithNoName = [];
|
339
|
-
for (const
|
346
|
+
for (const root in projectRootMap) {
|
347
|
+
const configuration = projectRootMap[root];
|
340
348
|
// We're setting `// targets` as a comment `targets` is empty due to Project Crystal.
|
341
349
|
// Strip it before returning configuration for usage.
|
342
350
|
if (configuration['// targets'])
|
@@ -544,7 +552,8 @@ function readTargetDefaultsForTarget(targetName, targetDefaults, executor) {
|
|
544
552
|
exports.readTargetDefaultsForTarget = readTargetDefaultsForTarget;
|
545
553
|
function createRootMap(projectRootMap) {
|
546
554
|
const map = {};
|
547
|
-
for (const
|
555
|
+
for (const projectRoot in projectRootMap) {
|
556
|
+
const projectName = projectRootMap[projectRoot].name;
|
548
557
|
map[projectRoot] = projectName;
|
549
558
|
}
|
550
559
|
return map;
|
@@ -9,12 +9,12 @@ import { LoadedNxPlugin } from '../plugins/internal-api';
|
|
9
9
|
* @param nxJson
|
10
10
|
*/
|
11
11
|
export declare function retrieveWorkspaceFiles(workspaceRoot: string, projectRootMap: Record<string, string>): Promise<{
|
12
|
-
allWorkspaceFiles: import("
|
12
|
+
allWorkspaceFiles: import("nx/src/devkit-exports").FileData[];
|
13
13
|
fileMap: {
|
14
14
|
projectFileMap: ProjectFiles;
|
15
|
-
nonProjectFiles: import("
|
15
|
+
nonProjectFiles: import("nx/src/native").FileData[];
|
16
16
|
};
|
17
|
-
rustReferences: import("
|
17
|
+
rustReferences: import("nx/src/native").NxWorkspaceFilesExternals;
|
18
18
|
}>;
|
19
19
|
/**
|
20
20
|
* Walk through the workspace and return `ProjectConfigurations`. Only use this if the projectFileMap is not needed.
|