nx 19.2.0-canary.20240530-316dcb9 → 19.2.0-canary.20240601-6f22300
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/command-line/deprecated/command-objects.js +2 -1
- package/src/command-line/examples.js +59 -5
- package/src/command-line/graph/command-object.d.ts +25 -2
- package/src/command-line/graph/command-object.js +57 -3
- package/src/command-line/graph/graph.js +2 -1
- package/src/command-line/init/implementation/react/index.js +1 -1
- package/src/command-line/init/implementation/react/rename-js-to-jsx.d.ts +1 -1
- package/src/command-line/init/implementation/react/rename-js-to-jsx.js +2 -2
- package/src/command-line/init/init-v2.js +1 -1
- package/src/command-line/nx-commands.js +1 -1
- package/src/command-line/yargs-utils/shared-options.d.ts +0 -21
- package/src/command-line/yargs-utils/shared-options.js +2 -52
- package/src/daemon/client/client.d.ts +6 -0
- package/src/daemon/client/client.js +45 -2
- package/src/daemon/is-on-daemon.d.ts +1 -0
- package/src/daemon/is-on-daemon.js +7 -0
- package/src/daemon/message-types/get-context-file-data.d.ts +5 -0
- package/src/daemon/message-types/get-context-file-data.js +11 -0
- package/src/daemon/message-types/get-files-in-directory.d.ts +6 -0
- package/src/daemon/message-types/get-files-in-directory.js +11 -0
- package/src/daemon/message-types/get-nx-workspace-files.d.ts +6 -0
- package/src/daemon/message-types/get-nx-workspace-files.js +11 -0
- package/src/daemon/message-types/glob.d.ts +7 -0
- package/src/daemon/message-types/glob.js +11 -0
- package/src/daemon/message-types/hash-glob.d.ts +7 -0
- package/src/daemon/message-types/hash-glob.js +11 -0
- package/src/daemon/message-types/update-context-files.d.ts +7 -0
- package/src/daemon/message-types/update-context-files.js +11 -0
- package/src/daemon/server/handle-context-file-data.d.ts +2 -0
- package/src/daemon/server/handle-context-file-data.js +13 -0
- package/src/daemon/server/handle-get-files-in-directory.d.ts +2 -0
- package/src/daemon/server/handle-get-files-in-directory.js +13 -0
- package/src/daemon/server/handle-glob.d.ts +2 -0
- package/src/daemon/server/handle-glob.js +13 -0
- package/src/daemon/server/handle-hash-glob.d.ts +2 -0
- package/src/daemon/server/handle-hash-glob.js +13 -0
- package/src/daemon/server/handle-nx-workspace-files.d.ts +2 -0
- package/src/daemon/server/handle-nx-workspace-files.js +13 -0
- package/src/daemon/server/server.js +39 -9
- package/src/devkit-exports.d.ts +4 -2
- package/src/devkit-exports.js +6 -1
- package/src/generators/utils/glob.d.ts +11 -0
- package/src/generators/utils/glob.js +20 -3
- package/src/generators/utils/project-configuration.js +1 -1
- package/src/plugins/js/project-graph/build-dependencies/build-dependencies.js +16 -3
- package/src/plugins/js/project-graph/build-dependencies/explicit-package-json-dependencies.d.ts +2 -1
- package/src/plugins/js/project-graph/build-dependencies/explicit-package-json-dependencies.js +40 -27
- package/src/plugins/js/project-graph/build-dependencies/explicit-project-dependencies.d.ts +2 -1
- package/src/plugins/js/project-graph/build-dependencies/explicit-project-dependencies.js +14 -19
- package/src/plugins/js/project-graph/build-dependencies/target-project-locator.d.ts +32 -5
- package/src/plugins/js/project-graph/build-dependencies/target-project-locator.js +146 -47
- package/src/plugins/js/utils/resolve-relative-to-dir.d.ts +5 -0
- package/src/plugins/js/utils/resolve-relative-to-dir.js +18 -0
- package/src/project-graph/error-types.d.ts +37 -19
- package/src/project-graph/error-types.js +31 -19
- package/src/project-graph/file-map-utils.js +1 -8
- package/src/project-graph/file-utils.js +33 -34
- package/src/project-graph/plugins/index.d.ts +1 -0
- package/src/project-graph/plugins/index.js +3 -1
- package/src/project-graph/plugins/internal-api.d.ts +2 -2
- package/src/project-graph/plugins/internal-api.js +33 -3
- package/src/project-graph/plugins/isolation/plugin-pool.js +10 -9
- package/src/project-graph/plugins/public-api.d.ts +34 -3
- package/src/project-graph/plugins/utils.d.ts +4 -3
- package/src/project-graph/plugins/utils.js +13 -26
- package/src/project-graph/utils/project-configuration-utils.js +89 -74
- package/src/project-graph/utils/retrieve-workspace-files.d.ts +4 -4
- package/src/project-graph/utils/retrieve-workspace-files.js +6 -6
- package/src/utils/all-file-data.js +1 -7
- package/src/utils/workspace-context.d.ts +13 -5
- package/src/utils/workspace-context.js +45 -14
- package/src/daemon/server/handle-request-file-data.d.ts +0 -4
- package/src/daemon/server/handle-request-file-data.js +0 -13
@@ -6,9 +6,10 @@ exports.getDefaultPlugins = exports.loadNxPlugins = exports.nxPluginCache = expo
|
|
6
6
|
const path_1 = require("path");
|
7
7
|
const workspace_root_1 = require("../../utils/workspace-root");
|
8
8
|
const angular_json_1 = require("../../adapter/angular-json");
|
9
|
-
const utils_1 = require("./utils");
|
10
9
|
const isolation_1 = require("./isolation");
|
11
10
|
const loader_1 = require("./loader");
|
11
|
+
const utils_1 = require("./utils");
|
12
|
+
const error_types_1 = require("../error-types");
|
12
13
|
class LoadedNxPlugin {
|
13
14
|
constructor(plugin, pluginDefinition) {
|
14
15
|
this.name = plugin.name;
|
@@ -17,12 +18,41 @@ class LoadedNxPlugin {
|
|
17
18
|
this.include = pluginDefinition.include;
|
18
19
|
this.exclude = pluginDefinition.exclude;
|
19
20
|
}
|
20
|
-
if (plugin.createNodes) {
|
21
|
+
if (plugin.createNodes && !plugin.createNodesV2) {
|
21
22
|
this.createNodes = [
|
22
23
|
plugin.createNodes[0],
|
23
|
-
(
|
24
|
+
(configFiles, context) => (0, utils_1.createNodesFromFiles)(plugin.createNodes[1], configFiles, this.options, context).then((results) => results.map((r) => [this.name, r[0], r[1]])),
|
25
|
+
];
|
26
|
+
}
|
27
|
+
if (plugin.createNodesV2) {
|
28
|
+
this.createNodes = [
|
29
|
+
plugin.createNodesV2[0],
|
30
|
+
async (configFiles, context) => {
|
31
|
+
const result = await plugin.createNodesV2[1](configFiles, this.options, context);
|
32
|
+
return result.map((r) => [this.name, r[0], r[1]]);
|
33
|
+
},
|
24
34
|
];
|
25
35
|
}
|
36
|
+
if (this.createNodes) {
|
37
|
+
const inner = this.createNodes[1];
|
38
|
+
this.createNodes[1] = async (...args) => {
|
39
|
+
performance.mark(`${plugin.name}:createNodes - start`);
|
40
|
+
try {
|
41
|
+
return await inner(...args);
|
42
|
+
}
|
43
|
+
catch (e) {
|
44
|
+
if ((0, error_types_1.isAggregateCreateNodesError)(e)) {
|
45
|
+
throw e;
|
46
|
+
}
|
47
|
+
// The underlying plugin errored out. We can't know any partial results.
|
48
|
+
throw new error_types_1.AggregateCreateNodesError([null, e], []);
|
49
|
+
}
|
50
|
+
finally {
|
51
|
+
performance.mark(`${plugin.name}:createNodes - end`);
|
52
|
+
performance.measure(`${plugin.name}:createNodes`, `${plugin.name}:createNodes - start`, `${plugin.name}:createNodes - end`);
|
53
|
+
}
|
54
|
+
};
|
55
|
+
}
|
26
56
|
if (plugin.createDependencies) {
|
27
57
|
this.createDependencies = (context) => plugin.createDependencies(this.options, context);
|
28
58
|
}
|
@@ -15,17 +15,18 @@ function loadRemoteNxPlugin(plugin, root) {
|
|
15
15
|
// but its typescript.
|
16
16
|
const isWorkerTypescript = path.extname(__filename) === '.ts';
|
17
17
|
const workerPath = path.join(__dirname, 'plugin-worker');
|
18
|
+
const env = {
|
19
|
+
...process.env,
|
20
|
+
...(isWorkerTypescript
|
21
|
+
? {
|
22
|
+
// Ensures that the worker uses the same tsconfig as the main process
|
23
|
+
TS_NODE_PROJECT: path.join(__dirname, '../../../../tsconfig.lib.json'),
|
24
|
+
}
|
25
|
+
: {}),
|
26
|
+
};
|
18
27
|
const worker = (0, child_process_1.fork)(workerPath, [], {
|
19
28
|
stdio: ['ignore', 'inherit', 'inherit', 'ipc'],
|
20
|
-
env
|
21
|
-
...process.env,
|
22
|
-
...(isWorkerTypescript
|
23
|
-
? {
|
24
|
-
// Ensures that the worker uses the same tsconfig as the main process
|
25
|
-
TS_NODE_PROJECT: path.join(__dirname, '../../../tsconfig.lib.json'),
|
26
|
-
}
|
27
|
-
: {}),
|
28
|
-
},
|
29
|
+
env,
|
29
30
|
execArgv: [
|
30
31
|
...process.execArgv,
|
31
32
|
// If the worker is typescript, we need to register ts-node
|
@@ -6,19 +6,23 @@ import { RawProjectGraphDependency } from '../project-graph-builder';
|
|
6
6
|
/**
|
7
7
|
* Context for {@link CreateNodesFunction}
|
8
8
|
*/
|
9
|
-
export interface CreateNodesContext {
|
10
|
-
readonly nxJsonConfiguration: NxJsonConfiguration;
|
11
|
-
readonly workspaceRoot: string;
|
9
|
+
export interface CreateNodesContext extends CreateNodesContextV2 {
|
12
10
|
/**
|
13
11
|
* The subset of configuration files which match the createNodes pattern
|
14
12
|
*/
|
15
13
|
readonly configFiles: readonly string[];
|
16
14
|
}
|
15
|
+
export interface CreateNodesContextV2 {
|
16
|
+
readonly nxJsonConfiguration: NxJsonConfiguration;
|
17
|
+
readonly workspaceRoot: string;
|
18
|
+
}
|
17
19
|
/**
|
18
20
|
* A function which parses a configuration file into a set of nodes.
|
19
21
|
* Used for creating nodes for the {@link ProjectGraph}
|
20
22
|
*/
|
21
23
|
export type CreateNodesFunction<T = unknown> = (projectConfigurationFile: string, options: T | undefined, context: CreateNodesContext) => CreateNodesResult | Promise<CreateNodesResult>;
|
24
|
+
export type CreateNodesResultV2 = Array<readonly [configFileSource: string, result: CreateNodesResult]>;
|
25
|
+
export type CreateNodesFunctionV2<T = unknown> = (projectConfigurationFiles: readonly string[], options: T | undefined, context: CreateNodesContextV2) => CreateNodesResultV2 | Promise<CreateNodesResultV2>;
|
22
26
|
export type Optional<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
|
23
27
|
export interface CreateNodesResult {
|
24
28
|
/**
|
@@ -32,11 +36,29 @@ export interface CreateNodesResult {
|
|
32
36
|
}
|
33
37
|
/**
|
34
38
|
* A pair of file patterns and {@link CreateNodesFunction}
|
39
|
+
*
|
40
|
+
* Nx 19.2+: Both original `CreateNodes` and `CreateNodesV2` are supported. Nx will only invoke `CreateNodesV2` if it is present.
|
41
|
+
* Nx 20.X : The `CreateNodesV2` will be the only supported API. This typing will still exist, but be identical to `CreateNodesV2`.
|
42
|
+
Nx **will not** invoke the original `plugin.createNodes` callback. This should give plugin authors a window to transition.
|
43
|
+
Plugin authors should update their plugin's `createNodes` function to align with `CreateNodesV2` / the updated `CreateNodes`.
|
44
|
+
The plugin should contain something like: `export createNodes = createNodesV2;` during this period. This will allow the plugin
|
45
|
+
to maintain compatibility with Nx 19.2 and up.
|
46
|
+
* Nx 21.X : The `CreateNodesV2` typing will be removed, as it has replaced `CreateNodes`.
|
47
|
+
*
|
48
|
+
* @deprecated Use {@link CreateNodesV2} instead. CreateNodesV2 will replace this API. Read more about the transition above.
|
35
49
|
*/
|
36
50
|
export type CreateNodes<T = unknown> = readonly [
|
37
51
|
projectFilePattern: string,
|
38
52
|
createNodesFunction: CreateNodesFunction<T>
|
39
53
|
];
|
54
|
+
/**
|
55
|
+
* A pair of file patterns and {@link CreateNodesFunctionV2}
|
56
|
+
* In Nx 20 {@link CreateNodes} will be replaced with this type. In Nx 21, this type will be removed.
|
57
|
+
*/
|
58
|
+
export type CreateNodesV2<T = unknown> = readonly [
|
59
|
+
projectFilePattern: string,
|
60
|
+
createNodesFunction: CreateNodesFunctionV2<T>
|
61
|
+
];
|
40
62
|
/**
|
41
63
|
* Context for {@link CreateDependencies}
|
42
64
|
*/
|
@@ -82,8 +104,17 @@ export type NxPluginV2<TOptions = unknown> = {
|
|
82
104
|
/**
|
83
105
|
* Provides a file pattern and function that retrieves configuration info from
|
84
106
|
* those files. e.g. { '**\/*.csproj': buildProjectsFromCsProjFile }
|
107
|
+
*
|
108
|
+
* @deprecated Use {@link createNodesV2} instead. In Nx 20 support for calling createNodes with a single file for the first argument will be removed.
|
85
109
|
*/
|
86
110
|
createNodes?: CreateNodes<TOptions>;
|
111
|
+
/**
|
112
|
+
* Provides a file pattern and function that retrieves configuration info from
|
113
|
+
* those files. e.g. { '**\/*.csproj': buildProjectsFromCsProjFiles }
|
114
|
+
*
|
115
|
+
* In Nx 20 {@link createNodes} will be replaced with this property. In Nx 21, this property will be removed.
|
116
|
+
*/
|
117
|
+
createNodesV2?: CreateNodesV2<TOptions>;
|
87
118
|
/**
|
88
119
|
* Provides a function to analyze files to create dependencies for the {@link ProjectGraph}
|
89
120
|
*/
|
@@ -1,7 +1,8 @@
|
|
1
1
|
import type { NxPluginV1 } from '../../utils/nx-plugin.deprecated';
|
2
|
-
import type {
|
3
|
-
import {
|
2
|
+
import type { LoadedNxPlugin, NormalizedPlugin } from './internal-api';
|
3
|
+
import { CreateNodesContextV2, CreateNodesFunction, CreateNodesResult, type NxPlugin, type NxPluginV2 } from './public-api';
|
4
4
|
export declare function isNxPluginV2(plugin: NxPlugin): plugin is NxPluginV2;
|
5
5
|
export declare function isNxPluginV1(plugin: NxPlugin | LoadedNxPlugin): plugin is NxPluginV1;
|
6
6
|
export declare function normalizeNxPlugin(plugin: NxPlugin): NormalizedPlugin;
|
7
|
-
export
|
7
|
+
export type AsyncFn<T extends Function> = T extends (...args: infer A) => infer R ? (...args: A) => Promise<Awaited<R>> : never;
|
8
|
+
export declare function createNodesFromFiles<T = unknown>(createNodes: CreateNodesFunction<T>, configFiles: readonly string[], options: T, context: CreateNodesContextV2): Promise<[file: string, value: CreateNodesResult][]>;
|
@@ -1,11 +1,10 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.
|
3
|
+
exports.createNodesFromFiles = exports.normalizeNxPlugin = exports.isNxPluginV1 = exports.isNxPluginV2 = void 0;
|
4
4
|
const node_path_1 = require("node:path");
|
5
5
|
const to_project_name_1 = require("../../config/to-project-name");
|
6
6
|
const globs_1 = require("../../utils/globs");
|
7
7
|
const error_types_1 = require("../error-types");
|
8
|
-
const perf_hooks_1 = require("perf_hooks");
|
9
8
|
function isNxPluginV2(plugin) {
|
10
9
|
return 'createNodes' in plugin || 'createDependencies' in plugin;
|
11
10
|
}
|
@@ -40,36 +39,24 @@ function normalizeNxPlugin(plugin) {
|
|
40
39
|
return plugin;
|
41
40
|
}
|
42
41
|
exports.normalizeNxPlugin = normalizeNxPlugin;
|
43
|
-
async function
|
44
|
-
perf_hooks_1.performance.mark(`${plugin.name}:createNodes - start`);
|
45
|
-
const errors = [];
|
42
|
+
async function createNodesFromFiles(createNodes, configFiles, options, context) {
|
46
43
|
const results = [];
|
47
|
-
const
|
44
|
+
const errors = [];
|
45
|
+
await Promise.all(configFiles.map(async (file) => {
|
48
46
|
try {
|
49
|
-
const value = await
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
pluginName: plugin.name,
|
55
|
-
});
|
56
|
-
}
|
47
|
+
const value = await createNodes(file, options, {
|
48
|
+
...context,
|
49
|
+
configFiles,
|
50
|
+
});
|
51
|
+
results.push([file, value]);
|
57
52
|
}
|
58
53
|
catch (e) {
|
59
|
-
errors.push(
|
60
|
-
error: e,
|
61
|
-
pluginName: plugin.name,
|
62
|
-
file,
|
63
|
-
}));
|
54
|
+
errors.push([file, e]);
|
64
55
|
}
|
65
|
-
});
|
66
|
-
await Promise.all(promises).then(() => {
|
67
|
-
perf_hooks_1.performance.mark(`${plugin.name}:createNodes - end`);
|
68
|
-
perf_hooks_1.performance.measure(`${plugin.name}:createNodes`, `${plugin.name}:createNodes - start`, `${plugin.name}:createNodes - end`);
|
69
|
-
});
|
56
|
+
}));
|
70
57
|
if (errors.length > 0) {
|
71
|
-
throw new error_types_1.AggregateCreateNodesError(
|
58
|
+
throw new error_types_1.AggregateCreateNodesError(errors, results);
|
72
59
|
}
|
73
60
|
return results;
|
74
61
|
}
|
75
|
-
exports.
|
62
|
+
exports.createNodesFromFiles = createNodesFromFiles;
|
@@ -227,92 +227,35 @@ plugins) {
|
|
227
227
|
const results = [];
|
228
228
|
const errors = [];
|
229
229
|
// We iterate over plugins first - this ensures that plugins specified first take precedence.
|
230
|
-
for (const {
|
230
|
+
for (const { createNodes: createNodesTuple, include, exclude, name: pluginName, } of plugins) {
|
231
231
|
const [pattern, createNodes] = createNodesTuple ?? [];
|
232
232
|
if (!pattern) {
|
233
233
|
continue;
|
234
234
|
}
|
235
|
-
const matchingConfigFiles =
|
236
|
-
for (const file of projectFiles) {
|
237
|
-
if ((0, minimatch_1.minimatch)(file, pattern, { dot: true })) {
|
238
|
-
if (include) {
|
239
|
-
const included = include.some((includedPattern) => (0, minimatch_1.minimatch)(file, includedPattern, { dot: true }));
|
240
|
-
if (!included) {
|
241
|
-
continue;
|
242
|
-
}
|
243
|
-
}
|
244
|
-
if (exclude) {
|
245
|
-
const excluded = exclude.some((excludedPattern) => (0, minimatch_1.minimatch)(file, excludedPattern, { dot: true }));
|
246
|
-
if (excluded) {
|
247
|
-
continue;
|
248
|
-
}
|
249
|
-
}
|
250
|
-
matchingConfigFiles.push(file);
|
251
|
-
}
|
252
|
-
}
|
235
|
+
const matchingConfigFiles = findMatchingConfigFiles(projectFiles, pattern, include, exclude);
|
253
236
|
let r = createNodes(matchingConfigFiles, {
|
254
237
|
nxJsonConfiguration: nxJson,
|
255
238
|
workspaceRoot: root,
|
256
|
-
configFiles: matchingConfigFiles,
|
257
239
|
}).catch((e) => {
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
240
|
+
const errorBodyLines = [
|
241
|
+
`An error occurred while processing files for the ${pluginName} plugin.`,
|
242
|
+
];
|
243
|
+
const error = (0, error_types_1.isAggregateCreateNodesError)(e)
|
244
|
+
? // This is an expected error if something goes wrong while processing files.
|
245
|
+
e
|
246
|
+
: // This represents a single plugin erroring out with a hard error.
|
247
|
+
new error_types_1.AggregateCreateNodesError([[null, e]], []);
|
248
|
+
errorBodyLines.push(...error.errors.map(([file, e]) => ` - ${file}: ${e.message}`));
|
249
|
+
error.message = errorBodyLines.join('\n');
|
250
|
+
// This represents a single plugin erroring out with a hard error.
|
251
|
+
errors.push(error);
|
252
|
+
// The plugin didn't return partial results, so we return an empty array.
|
253
|
+
return error.partialResults.map((r) => [pluginName, r[0], r[1]]);
|
265
254
|
});
|
266
255
|
results.push(r);
|
267
256
|
}
|
268
257
|
return Promise.all(results).then((results) => {
|
269
|
-
|
270
|
-
const projectRootMap = {};
|
271
|
-
const externalNodes = {};
|
272
|
-
const configurationSourceMaps = {};
|
273
|
-
for (const result of results.flat()) {
|
274
|
-
const { projects: projectNodes, externalNodes: pluginExternalNodes, file, pluginName, } = result;
|
275
|
-
const sourceInfo = [file, pluginName];
|
276
|
-
if (result[symbols_1.OVERRIDE_SOURCE_FILE]) {
|
277
|
-
sourceInfo[0] = result[symbols_1.OVERRIDE_SOURCE_FILE];
|
278
|
-
}
|
279
|
-
for (const node in projectNodes) {
|
280
|
-
// Handles `{projects: {'libs/foo': undefined}}`.
|
281
|
-
if (!projectNodes[node]) {
|
282
|
-
continue;
|
283
|
-
}
|
284
|
-
const project = {
|
285
|
-
root: node,
|
286
|
-
...projectNodes[node],
|
287
|
-
};
|
288
|
-
try {
|
289
|
-
mergeProjectConfigurationIntoRootMap(projectRootMap, project, configurationSourceMaps, sourceInfo);
|
290
|
-
}
|
291
|
-
catch (error) {
|
292
|
-
errors.push(new error_types_1.MergeNodesError({
|
293
|
-
file,
|
294
|
-
pluginName,
|
295
|
-
error,
|
296
|
-
}));
|
297
|
-
}
|
298
|
-
}
|
299
|
-
Object.assign(externalNodes, pluginExternalNodes);
|
300
|
-
}
|
301
|
-
try {
|
302
|
-
validateAndNormalizeProjectRootMap(projectRootMap);
|
303
|
-
}
|
304
|
-
catch (e) {
|
305
|
-
if ((0, error_types_1.isProjectsWithNoNameError)(e) ||
|
306
|
-
(0, error_types_1.isMultipleProjectsWithSameNameError)(e)) {
|
307
|
-
errors.push(e);
|
308
|
-
}
|
309
|
-
else {
|
310
|
-
throw e;
|
311
|
-
}
|
312
|
-
}
|
313
|
-
const rootMap = createRootMap(projectRootMap);
|
314
|
-
perf_hooks_1.performance.mark('createNodes:merge - end');
|
315
|
-
perf_hooks_1.performance.measure('createNodes:merge', 'createNodes:merge - start', 'createNodes:merge - end');
|
258
|
+
const { projectRootMap, externalNodes, rootMap, configurationSourceMaps } = mergeCreateNodesResults(results, errors);
|
316
259
|
perf_hooks_1.performance.mark('build-project-configs:end');
|
317
260
|
perf_hooks_1.performance.measure('build-project-configs', 'build-project-configs:start', 'build-project-configs:end');
|
318
261
|
if (errors.length === 0) {
|
@@ -336,6 +279,78 @@ plugins) {
|
|
336
279
|
});
|
337
280
|
}
|
338
281
|
exports.createProjectConfigurations = createProjectConfigurations;
|
282
|
+
function mergeCreateNodesResults(results, errors) {
|
283
|
+
perf_hooks_1.performance.mark('createNodes:merge - start');
|
284
|
+
const projectRootMap = {};
|
285
|
+
const externalNodes = {};
|
286
|
+
const configurationSourceMaps = {};
|
287
|
+
for (const result of results.flat()) {
|
288
|
+
const [file, pluginName, nodes] = result;
|
289
|
+
const { projects: projectNodes, externalNodes: pluginExternalNodes } = nodes;
|
290
|
+
const sourceInfo = [file, pluginName];
|
291
|
+
if (result[symbols_1.OVERRIDE_SOURCE_FILE]) {
|
292
|
+
sourceInfo[0] = result[symbols_1.OVERRIDE_SOURCE_FILE];
|
293
|
+
}
|
294
|
+
for (const node in projectNodes) {
|
295
|
+
// Handles `{projects: {'libs/foo': undefined}}`.
|
296
|
+
if (!projectNodes[node]) {
|
297
|
+
continue;
|
298
|
+
}
|
299
|
+
const project = {
|
300
|
+
root: node,
|
301
|
+
...projectNodes[node],
|
302
|
+
};
|
303
|
+
try {
|
304
|
+
mergeProjectConfigurationIntoRootMap(projectRootMap, project, configurationSourceMaps, sourceInfo);
|
305
|
+
}
|
306
|
+
catch (error) {
|
307
|
+
errors.push(new error_types_1.MergeNodesError({
|
308
|
+
file,
|
309
|
+
pluginName,
|
310
|
+
error,
|
311
|
+
}));
|
312
|
+
}
|
313
|
+
}
|
314
|
+
Object.assign(externalNodes, pluginExternalNodes);
|
315
|
+
}
|
316
|
+
try {
|
317
|
+
validateAndNormalizeProjectRootMap(projectRootMap);
|
318
|
+
}
|
319
|
+
catch (e) {
|
320
|
+
if ((0, error_types_1.isProjectsWithNoNameError)(e) ||
|
321
|
+
(0, error_types_1.isMultipleProjectsWithSameNameError)(e)) {
|
322
|
+
errors.push(e);
|
323
|
+
}
|
324
|
+
else {
|
325
|
+
throw e;
|
326
|
+
}
|
327
|
+
}
|
328
|
+
const rootMap = createRootMap(projectRootMap);
|
329
|
+
perf_hooks_1.performance.mark('createNodes:merge - end');
|
330
|
+
perf_hooks_1.performance.measure('createNodes:merge', 'createNodes:merge - start', 'createNodes:merge - end');
|
331
|
+
return { projectRootMap, externalNodes, rootMap, configurationSourceMaps };
|
332
|
+
}
|
333
|
+
function findMatchingConfigFiles(projectFiles, pattern, include, exclude) {
|
334
|
+
const matchingConfigFiles = [];
|
335
|
+
for (const file of projectFiles) {
|
336
|
+
if ((0, minimatch_1.minimatch)(file, pattern, { dot: true })) {
|
337
|
+
if (include) {
|
338
|
+
const included = include.some((includedPattern) => (0, minimatch_1.minimatch)(file, includedPattern, { dot: true }));
|
339
|
+
if (!included) {
|
340
|
+
continue;
|
341
|
+
}
|
342
|
+
}
|
343
|
+
if (exclude) {
|
344
|
+
const excluded = exclude.some((excludedPattern) => (0, minimatch_1.minimatch)(file, excludedPattern, { dot: true }));
|
345
|
+
if (excluded) {
|
346
|
+
continue;
|
347
|
+
}
|
348
|
+
}
|
349
|
+
matchingConfigFiles.push(file);
|
350
|
+
}
|
351
|
+
}
|
352
|
+
return matchingConfigFiles;
|
353
|
+
}
|
339
354
|
function readProjectConfigurationsFromRootMap(projectRootMap) {
|
340
355
|
const projects = {};
|
341
356
|
// If there are projects that have the same name, that is an error.
|
@@ -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.
|
@@ -23,7 +23,7 @@ export declare function retrieveProjectConfigurations(plugins: LoadedNxPlugin[],
|
|
23
23
|
export declare function retrieveProjectConfigurationsWithAngularProjects(workspaceRoot: string, nxJson: NxJsonConfiguration): Promise<ConfigurationResult>;
|
24
24
|
export declare function retrieveProjectConfigurationPaths(root: string, plugins: Array<{
|
25
25
|
createNodes?: readonly [string, ...unknown[]];
|
26
|
-
} & unknown>): string[]
|
26
|
+
} & unknown>): Promise<string[]>;
|
27
27
|
export declare function retrieveProjectConfigurationsWithoutPluginInference(root: string): Promise<Record<string, ProjectConfiguration>>;
|
28
28
|
export declare function configurationGlobs(plugins: Array<{
|
29
29
|
createNodes?: readonly [string, ...unknown[]];
|
@@ -20,7 +20,7 @@ async function retrieveWorkspaceFiles(workspaceRoot, projectRootMap) {
|
|
20
20
|
perf_hooks_1.performance.mark('native-file-deps:end');
|
21
21
|
perf_hooks_1.performance.measure('native-file-deps', 'native-file-deps:start', 'native-file-deps:end');
|
22
22
|
perf_hooks_1.performance.mark('get-workspace-files:start');
|
23
|
-
const { projectFileMap, globalFiles, externalReferences } = (0, workspace_context_1.getNxWorkspaceFilesFromContext)(workspaceRoot, projectRootMap);
|
23
|
+
const { projectFileMap, globalFiles, externalReferences } = await (0, workspace_context_1.getNxWorkspaceFilesFromContext)(workspaceRoot, projectRootMap);
|
24
24
|
perf_hooks_1.performance.mark('get-workspace-files:end');
|
25
25
|
perf_hooks_1.performance.measure('get-workspace-files', 'get-workspace-files:start', 'get-workspace-files:end');
|
26
26
|
return {
|
@@ -36,9 +36,9 @@ exports.retrieveWorkspaceFiles = retrieveWorkspaceFiles;
|
|
36
36
|
/**
|
37
37
|
* Walk through the workspace and return `ProjectConfigurations`. Only use this if the projectFileMap is not needed.
|
38
38
|
*/
|
39
|
-
function retrieveProjectConfigurations(plugins, workspaceRoot, nxJson) {
|
39
|
+
async function retrieveProjectConfigurations(plugins, workspaceRoot, nxJson) {
|
40
40
|
const globPatterns = configurationGlobs(plugins);
|
41
|
-
const workspaceFiles = (0, workspace_context_1.globWithWorkspaceContext)(workspaceRoot, globPatterns);
|
41
|
+
const workspaceFiles = await (0, workspace_context_1.globWithWorkspaceContext)(workspaceRoot, globPatterns);
|
42
42
|
return (0, project_configuration_utils_1.createProjectConfigurations)(workspaceRoot, nxJson, workspaceFiles, plugins);
|
43
43
|
}
|
44
44
|
exports.retrieveProjectConfigurations = retrieveProjectConfigurations;
|
@@ -50,7 +50,7 @@ async function retrieveProjectConfigurationsWithAngularProjects(workspaceRoot, n
|
|
50
50
|
pluginsToLoad.push((0, path_1.join)(__dirname, '../../adapter/angular-json'));
|
51
51
|
}
|
52
52
|
const [plugins, cleanup] = await (0, internal_api_1.loadNxPlugins)(nxJson?.plugins ?? [], workspaceRoot);
|
53
|
-
const res = retrieveProjectConfigurations(plugins, workspaceRoot, nxJson);
|
53
|
+
const res = await retrieveProjectConfigurations(plugins, workspaceRoot, nxJson);
|
54
54
|
cleanup();
|
55
55
|
return res;
|
56
56
|
}
|
@@ -65,12 +65,12 @@ const projectsWithoutPluginCache = new Map();
|
|
65
65
|
async function retrieveProjectConfigurationsWithoutPluginInference(root) {
|
66
66
|
const nxJson = (0, nx_json_1.readNxJson)(root);
|
67
67
|
const [plugins, cleanup] = await (0, internal_api_1.loadNxPlugins)([]); // only load default plugins
|
68
|
-
const projectGlobPatterns = retrieveProjectConfigurationPaths(root, plugins);
|
68
|
+
const projectGlobPatterns = await retrieveProjectConfigurationPaths(root, plugins);
|
69
69
|
const cacheKey = root + ',' + projectGlobPatterns.join(',');
|
70
70
|
if (projectsWithoutPluginCache.has(cacheKey)) {
|
71
71
|
return projectsWithoutPluginCache.get(cacheKey);
|
72
72
|
}
|
73
|
-
const projectFiles = (0, workspace_context_1.globWithWorkspaceContext)(root, projectGlobPatterns) ?? [];
|
73
|
+
const projectFiles = (await (0, workspace_context_1.globWithWorkspaceContext)(root, projectGlobPatterns)) ?? [];
|
74
74
|
const { projects } = await (0, project_configuration_utils_1.createProjectConfigurations)(root, nxJson, projectFiles, plugins);
|
75
75
|
projectsWithoutPluginCache.set(cacheKey, projects);
|
76
76
|
cleanup();
|
@@ -1,15 +1,9 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.allFileData = void 0;
|
4
|
-
const client_1 = require("../daemon/client/client");
|
5
4
|
const workspace_context_1 = require("./workspace-context");
|
6
5
|
const workspace_root_1 = require("./workspace-root");
|
7
6
|
function allFileData() {
|
8
|
-
|
9
|
-
return client_1.daemonClient.getAllFileData();
|
10
|
-
}
|
11
|
-
else {
|
12
|
-
return Promise.resolve((0, workspace_context_1.getAllFileDataInContext)(workspace_root_1.workspaceRoot));
|
13
|
-
}
|
7
|
+
return (0, workspace_context_1.getAllFileDataInContext)(workspace_root_1.workspaceRoot);
|
14
8
|
}
|
15
9
|
exports.allFileData = allFileData;
|
@@ -1,10 +1,18 @@
|
|
1
1
|
import type { NxWorkspaceFilesExternals } from '../native';
|
2
2
|
export declare function setupWorkspaceContext(workspaceRoot: string): void;
|
3
|
-
export declare function getNxWorkspaceFilesFromContext(workspaceRoot: string, projectRootMap: Record<string, string>): import("../native").NxWorkspaceFiles
|
4
|
-
|
5
|
-
|
3
|
+
export declare function getNxWorkspaceFilesFromContext(workspaceRoot: string, projectRootMap: Record<string, string>): Promise<import("../native").NxWorkspaceFiles>;
|
4
|
+
/**
|
5
|
+
* Sync method to get files matching globs from workspace context.
|
6
|
+
* NOTE: This method will create the workspace context if it doesn't exist.
|
7
|
+
* It should only be used within Nx internal in code paths that **must** be sync.
|
8
|
+
* If used in an isolated plugin thread this will cause the workspace context
|
9
|
+
* to be recreated which is slow.
|
10
|
+
*/
|
11
|
+
export declare function globWithWorkspaceContextSync(workspaceRoot: string, globs: string[], exclude?: string[]): string[];
|
12
|
+
export declare function globWithWorkspaceContext(workspaceRoot: string, globs: string[], exclude?: string[]): Promise<string[]>;
|
13
|
+
export declare function hashWithWorkspaceContext(workspaceRoot: string, globs: string[], exclude?: string[]): Promise<string>;
|
6
14
|
export declare function updateFilesInContext(updatedFiles: string[], deletedFiles: string[]): Record<string, string>;
|
7
|
-
export declare function getAllFileDataInContext(workspaceRoot: string): import("../native").FileData[]
|
8
|
-
export declare function getFilesInDirectoryUsingContext(workspaceRoot: string, dir: string): string[]
|
15
|
+
export declare function getAllFileDataInContext(workspaceRoot: string): Promise<import("../native").FileData[]>;
|
16
|
+
export declare function getFilesInDirectoryUsingContext(workspaceRoot: string, dir: string): Promise<string[]>;
|
9
17
|
export declare function updateProjectFiles(projectRootMappings: Record<string, string>, rustReferences: NxWorkspaceFilesExternals, updatedFiles: Record<string, string>, deletedFiles: string[]): import("../native").UpdatedWorkspaceFiles;
|
10
18
|
export declare function resetWorkspaceContext(): void;
|
@@ -1,8 +1,10 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.resetWorkspaceContext = exports.updateProjectFiles = exports.getFilesInDirectoryUsingContext = exports.getAllFileDataInContext = exports.updateFilesInContext = exports.hashWithWorkspaceContext = exports.globWithWorkspaceContext = exports.getNxWorkspaceFilesFromContext = exports.setupWorkspaceContext = void 0;
|
3
|
+
exports.resetWorkspaceContext = exports.updateProjectFiles = exports.getFilesInDirectoryUsingContext = exports.getAllFileDataInContext = exports.updateFilesInContext = exports.hashWithWorkspaceContext = exports.globWithWorkspaceContext = exports.globWithWorkspaceContextSync = exports.getNxWorkspaceFilesFromContext = exports.setupWorkspaceContext = void 0;
|
4
4
|
const perf_hooks_1 = require("perf_hooks");
|
5
5
|
const cache_directory_1 = require("./cache-directory");
|
6
|
+
const is_on_daemon_1 = require("../daemon/is-on-daemon");
|
7
|
+
const client_1 = require("../daemon/client/client");
|
6
8
|
let workspaceContext;
|
7
9
|
function setupWorkspaceContext(workspaceRoot) {
|
8
10
|
const { WorkspaceContext } = require('../native');
|
@@ -12,33 +14,62 @@ function setupWorkspaceContext(workspaceRoot) {
|
|
12
14
|
perf_hooks_1.performance.measure('workspace context init', 'workspace-context', 'workspace-context:end');
|
13
15
|
}
|
14
16
|
exports.setupWorkspaceContext = setupWorkspaceContext;
|
15
|
-
function getNxWorkspaceFilesFromContext(workspaceRoot, projectRootMap) {
|
16
|
-
|
17
|
-
|
17
|
+
async function getNxWorkspaceFilesFromContext(workspaceRoot, projectRootMap) {
|
18
|
+
if ((0, is_on_daemon_1.isOnDaemon)() || !client_1.daemonClient.enabled()) {
|
19
|
+
ensureContextAvailable(workspaceRoot);
|
20
|
+
return workspaceContext.getWorkspaceFiles(projectRootMap);
|
21
|
+
}
|
22
|
+
return client_1.daemonClient.getWorkspaceFiles(projectRootMap);
|
18
23
|
}
|
19
24
|
exports.getNxWorkspaceFilesFromContext = getNxWorkspaceFilesFromContext;
|
20
|
-
|
25
|
+
/**
|
26
|
+
* Sync method to get files matching globs from workspace context.
|
27
|
+
* NOTE: This method will create the workspace context if it doesn't exist.
|
28
|
+
* It should only be used within Nx internal in code paths that **must** be sync.
|
29
|
+
* If used in an isolated plugin thread this will cause the workspace context
|
30
|
+
* to be recreated which is slow.
|
31
|
+
*/
|
32
|
+
function globWithWorkspaceContextSync(workspaceRoot, globs, exclude) {
|
21
33
|
ensureContextAvailable(workspaceRoot);
|
22
34
|
return workspaceContext.glob(globs, exclude);
|
23
35
|
}
|
36
|
+
exports.globWithWorkspaceContextSync = globWithWorkspaceContextSync;
|
37
|
+
async function globWithWorkspaceContext(workspaceRoot, globs, exclude) {
|
38
|
+
if ((0, is_on_daemon_1.isOnDaemon)() || !client_1.daemonClient.enabled()) {
|
39
|
+
ensureContextAvailable(workspaceRoot);
|
40
|
+
return workspaceContext.glob(globs, exclude);
|
41
|
+
}
|
42
|
+
else {
|
43
|
+
return client_1.daemonClient.glob(globs, exclude);
|
44
|
+
}
|
45
|
+
}
|
24
46
|
exports.globWithWorkspaceContext = globWithWorkspaceContext;
|
25
|
-
function hashWithWorkspaceContext(workspaceRoot, globs, exclude) {
|
26
|
-
|
27
|
-
|
47
|
+
async function hashWithWorkspaceContext(workspaceRoot, globs, exclude) {
|
48
|
+
if ((0, is_on_daemon_1.isOnDaemon)() || !client_1.daemonClient.enabled()) {
|
49
|
+
ensureContextAvailable(workspaceRoot);
|
50
|
+
return workspaceContext.hashFilesMatchingGlob(globs, exclude);
|
51
|
+
}
|
52
|
+
return client_1.daemonClient.hashGlob(globs, exclude);
|
28
53
|
}
|
29
54
|
exports.hashWithWorkspaceContext = hashWithWorkspaceContext;
|
30
55
|
function updateFilesInContext(updatedFiles, deletedFiles) {
|
31
56
|
return workspaceContext?.incrementalUpdate(updatedFiles, deletedFiles);
|
32
57
|
}
|
33
58
|
exports.updateFilesInContext = updateFilesInContext;
|
34
|
-
function getAllFileDataInContext(workspaceRoot) {
|
35
|
-
|
36
|
-
|
59
|
+
async function getAllFileDataInContext(workspaceRoot) {
|
60
|
+
if ((0, is_on_daemon_1.isOnDaemon)() || !client_1.daemonClient.enabled()) {
|
61
|
+
ensureContextAvailable(workspaceRoot);
|
62
|
+
return workspaceContext.allFileData();
|
63
|
+
}
|
64
|
+
return client_1.daemonClient.getWorkspaceContextFileData();
|
37
65
|
}
|
38
66
|
exports.getAllFileDataInContext = getAllFileDataInContext;
|
39
|
-
function getFilesInDirectoryUsingContext(workspaceRoot, dir) {
|
40
|
-
|
41
|
-
|
67
|
+
async function getFilesInDirectoryUsingContext(workspaceRoot, dir) {
|
68
|
+
if ((0, is_on_daemon_1.isOnDaemon)() || !client_1.daemonClient.enabled()) {
|
69
|
+
ensureContextAvailable(workspaceRoot);
|
70
|
+
return workspaceContext.getFilesInDirectory(dir);
|
71
|
+
}
|
72
|
+
return client_1.daemonClient.getFilesInDirectory(dir);
|
42
73
|
}
|
43
74
|
exports.getFilesInDirectoryUsingContext = getFilesInDirectoryUsingContext;
|
44
75
|
function updateProjectFiles(projectRootMappings, rustReferences, updatedFiles, deletedFiles) {
|
@@ -1,13 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.handleRequestFileData = void 0;
|
4
|
-
const workspace_context_1 = require("../../utils/workspace-context");
|
5
|
-
const workspace_root_1 = require("../../utils/workspace-root");
|
6
|
-
async function handleRequestFileData() {
|
7
|
-
const response = JSON.stringify((0, workspace_context_1.getAllFileDataInContext)(workspace_root_1.workspaceRoot));
|
8
|
-
return {
|
9
|
-
response,
|
10
|
-
description: 'handleRequestFileData',
|
11
|
-
};
|
12
|
-
}
|
13
|
-
exports.handleRequestFileData = handleRequestFileData;
|