nx 18.1.0-canary.20240223-21e7648 → 18.1.0-canary.20240224-26b266f
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/adapter/angular-json.d.ts +2 -1
- package/src/adapter/angular-json.js +1 -0
- package/src/adapter/ngcli-adapter.js +3 -3
- package/src/command-line/generate/generator-utils.js +2 -2
- package/src/command-line/init/init-v2.js +17 -11
- package/src/command-line/migrate/migrate.js +3 -1
- package/src/command-line/run/executor-utils.js +2 -2
- package/src/config/schema-utils.js +2 -2
- package/src/devkit-exports.d.ts +2 -1
- package/src/devkit-internals.d.ts +1 -0
- package/src/devkit-internals.js +3 -1
- package/src/generators/utils/project-configuration.js +2 -2
- package/src/migrations/update-15-1-0/set-project-names.js +2 -2
- package/src/plugins/js/index.d.ts +1 -1
- package/src/plugins/js/lock-file/lock-file.d.ts +1 -1
- package/src/plugins/js/lock-file/npm-parser.d.ts +1 -1
- package/src/plugins/js/lock-file/pnpm-parser.d.ts +1 -1
- package/src/plugins/js/lock-file/yarn-parser.d.ts +1 -1
- package/src/plugins/js/project-graph/build-dependencies/build-dependencies.d.ts +1 -1
- package/src/plugins/js/project-graph/build-dependencies/explicit-package-json-dependencies.d.ts +1 -1
- package/src/plugins/js/project-graph/build-dependencies/explicit-project-dependencies.d.ts +1 -1
- package/src/plugins/package-json-workspaces/create-nodes.d.ts +2 -2
- package/src/plugins/package-json-workspaces/create-nodes.js +24 -31
- package/src/plugins/package-json-workspaces/index.d.ts +1 -0
- package/src/plugins/package-json-workspaces/index.js +2 -0
- package/src/plugins/project-json/build-nodes/package-json-next-to-project-json.d.ts +2 -1
- package/src/plugins/project-json/build-nodes/package-json-next-to-project-json.js +1 -0
- package/src/plugins/project-json/build-nodes/project-json.d.ts +2 -1
- package/src/plugins/project-json/build-nodes/project-json.js +1 -0
- package/src/plugins/target-defaults/target-defaults-plugin.d.ts +4 -4
- package/src/plugins/target-defaults/target-defaults-plugin.js +24 -27
- package/src/project-graph/affected/locators/project-glob-changes.js +2 -3
- package/src/project-graph/build-project-graph.js +10 -8
- package/src/project-graph/file-utils.js +3 -3
- package/src/project-graph/plugins/index.d.ts +2 -0
- package/src/project-graph/plugins/index.js +8 -0
- package/src/project-graph/plugins/internal-api.d.ts +21 -0
- package/src/project-graph/plugins/internal-api.js +84 -0
- package/src/project-graph/plugins/messaging.d.ts +89 -0
- package/src/project-graph/plugins/messaging.js +23 -0
- package/src/project-graph/plugins/plugin-pool.d.ts +4 -0
- package/src/project-graph/plugins/plugin-pool.js +188 -0
- package/src/project-graph/plugins/plugin-worker.d.ts +1 -0
- package/src/project-graph/plugins/plugin-worker.js +122 -0
- package/src/{utils/nx-plugin.d.ts → project-graph/plugins/public-api.d.ts} +6 -40
- package/src/project-graph/plugins/public-api.js +4 -0
- package/src/project-graph/plugins/worker-api.d.ts +26 -0
- package/src/project-graph/plugins/worker-api.js +177 -0
- package/src/project-graph/project-graph-builder.d.ts +1 -1
- package/src/project-graph/project-graph.js +0 -2
- package/src/project-graph/utils/normalize-project-nodes.d.ts +1 -1
- package/src/project-graph/utils/project-configuration-utils.d.ts +2 -2
- package/src/project-graph/utils/project-configuration-utils.js +27 -47
- package/src/project-graph/utils/retrieve-workspace-files.d.ts +8 -4
- package/src/project-graph/utils/retrieve-workspace-files.js +11 -14
- package/src/utils/logger.d.ts +1 -0
- package/src/utils/logger.js +5 -0
- package/src/utils/nx-plugin.deprecated.d.ts +4 -2
- package/src/utils/nx-plugin.deprecated.js +4 -4
- package/src/utils/package-json.js +2 -2
- package/src/utils/plugins/plugin-capabilities.d.ts +1 -1
- package/src/utils/plugins/plugin-capabilities.js +8 -7
- package/src/utils/nx-plugin.js +0 -293
@@ -1,9 +1,8 @@
|
|
1
|
-
import {
|
2
|
-
import {
|
3
|
-
import { ProjectConfiguration } from '
|
4
|
-
import { NxJsonConfiguration
|
5
|
-
import {
|
6
|
-
import { RawProjectGraphDependency } from '../project-graph/project-graph-builder';
|
1
|
+
import { NxPluginV1 } from '../../utils/nx-plugin.deprecated';
|
2
|
+
import { FileMap, ProjectGraph, ProjectGraphExternalNode } from '../../config/project-graph';
|
3
|
+
import { ProjectConfiguration } from '../../config/workspace-json-project-json';
|
4
|
+
import { NxJsonConfiguration } from '../../config/nx-json';
|
5
|
+
import { RawProjectGraphDependency } from '../project-graph-builder';
|
7
6
|
/**
|
8
7
|
* Context for {@link CreateNodesFunction}
|
9
8
|
*/
|
@@ -16,6 +15,7 @@ export interface CreateNodesContext {
|
|
16
15
|
* Used for creating nodes for the {@link ProjectGraph}
|
17
16
|
*/
|
18
17
|
export type CreateNodesFunction<T = unknown> = (projectConfigurationFile: string, options: T | undefined, context: CreateNodesContext) => CreateNodesResult | Promise<CreateNodesResult>;
|
18
|
+
export type Optional<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
|
19
19
|
export interface CreateNodesResult {
|
20
20
|
/**
|
21
21
|
* A map of project root -> project configuration
|
@@ -79,41 +79,7 @@ export type NxPluginV2<TOptions = unknown> = {
|
|
79
79
|
*/
|
80
80
|
createDependencies?: CreateDependencies<TOptions>;
|
81
81
|
};
|
82
|
-
export * from './nx-plugin.deprecated';
|
83
82
|
/**
|
84
83
|
* A plugin for Nx
|
85
84
|
*/
|
86
85
|
export type NxPlugin = NxPluginV1 | NxPluginV2;
|
87
|
-
export type LoadedNxPlugin = {
|
88
|
-
plugin: NxPluginV2 & Pick<NxPluginV1, 'processProjectGraph'>;
|
89
|
-
options?: unknown;
|
90
|
-
};
|
91
|
-
export declare const nxPluginCache: Map<string, LoadedNxPlugin['plugin']>;
|
92
|
-
export declare function getPluginPathAndName(moduleName: string, paths: string[], projects: Record<string, ProjectConfiguration>, root: string): {
|
93
|
-
pluginPath: string;
|
94
|
-
name: any;
|
95
|
-
};
|
96
|
-
export declare function loadNxPluginAsync(pluginConfiguration: PluginConfiguration, paths: string[], projects: Record<string, ProjectConfiguration>, root: string): Promise<LoadedNxPlugin>;
|
97
|
-
export declare function loadNxPlugins(plugins: PluginConfiguration[], paths?: string[], root?: string, projects?: Record<string, ProjectConfiguration>): Promise<LoadedNxPlugin[]>;
|
98
|
-
export declare function ensurePluginIsV2(plugin: NxPlugin): NxPluginV2;
|
99
|
-
export declare function isNxPluginV2(plugin: NxPlugin): plugin is NxPluginV2;
|
100
|
-
export declare function isNxPluginV1(plugin: NxPlugin): plugin is NxPluginV1;
|
101
|
-
export declare function readPluginPackageJson(pluginName: string, projects: Record<string, ProjectConfiguration>, paths?: string[]): {
|
102
|
-
path: string;
|
103
|
-
json: PackageJson;
|
104
|
-
};
|
105
|
-
export declare function resolveLocalNxPlugin(importPath: string, nxJsonConfiguration: NxJsonConfiguration, projects: Record<string, ProjectConfiguration>, root?: string): {
|
106
|
-
path: string;
|
107
|
-
projectConfig: ProjectConfiguration;
|
108
|
-
} | null;
|
109
|
-
/**
|
110
|
-
* Register swc-node or ts-node if they are not currently registered
|
111
|
-
* with some default settings which work well for Nx plugins.
|
112
|
-
*/
|
113
|
-
export declare function registerPluginTSTranspiler(): void;
|
114
|
-
/**
|
115
|
-
* Unregister the ts-node transpiler if it is registered
|
116
|
-
*/
|
117
|
-
export declare function unregisterPluginTSTranspiler(): void;
|
118
|
-
export declare function getDefaultPlugins(root: string): Promise<LoadedNxPlugin[]>;
|
119
|
-
type Optional<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
|
@@ -0,0 +1,26 @@
|
|
1
|
+
import { ProjectConfiguration } from '../../config/workspace-json-project-json';
|
2
|
+
import { PluginConfiguration } from '../../config/nx-json';
|
3
|
+
import { PackageJson } from '../../utils/package-json';
|
4
|
+
import { NxPlugin } from './public-api';
|
5
|
+
export type LoadedNxPlugin = {
|
6
|
+
plugin: NxPlugin;
|
7
|
+
options?: unknown;
|
8
|
+
};
|
9
|
+
export declare function loadNxPluginAsync(pluginConfiguration: PluginConfiguration, paths: string[], projects: Record<string, ProjectConfiguration>, root: string): Promise<LoadedNxPlugin>;
|
10
|
+
export declare function readPluginPackageJson(pluginName: string, projects: Record<string, ProjectConfiguration>, paths?: string[]): {
|
11
|
+
path: string;
|
12
|
+
json: PackageJson;
|
13
|
+
};
|
14
|
+
export declare function resolveLocalNxPlugin(importPath: string, projects: Record<string, ProjectConfiguration>, root?: string): {
|
15
|
+
path: string;
|
16
|
+
projectConfig: ProjectConfiguration;
|
17
|
+
} | null;
|
18
|
+
/**
|
19
|
+
* Register swc-node or ts-node if they are not currently registered
|
20
|
+
* with some default settings which work well for Nx plugins.
|
21
|
+
*/
|
22
|
+
export declare function registerPluginTSTranspiler(): void;
|
23
|
+
export declare function getPluginPathAndName(moduleName: string, paths: string[], projects: Record<string, ProjectConfiguration>, root: string): {
|
24
|
+
pluginPath: string;
|
25
|
+
name: any;
|
26
|
+
};
|
@@ -0,0 +1,177 @@
|
|
1
|
+
"use strict";
|
2
|
+
// This file contains methods and utilities that should **only** be used by the plugin worker.
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
4
|
+
exports.getPluginPathAndName = exports.registerPluginTSTranspiler = exports.resolveLocalNxPlugin = exports.readPluginPackageJson = exports.loadNxPluginAsync = void 0;
|
5
|
+
const posix_1 = require("node:path/posix");
|
6
|
+
const installation_directory_1 = require("../../utils/installation-directory");
|
7
|
+
const package_json_1 = require("../../utils/package-json");
|
8
|
+
const fileutils_1 = require("../../utils/fileutils");
|
9
|
+
const path = require("node:path/posix");
|
10
|
+
const workspace_root_1 = require("../../utils/workspace-root");
|
11
|
+
const node_fs_1 = require("node:fs");
|
12
|
+
const typescript_1 = require("../../utils/typescript");
|
13
|
+
const register_1 = require("../../plugins/js/utils/register");
|
14
|
+
const find_project_for_path_1 = require("../utils/find-project-for-path");
|
15
|
+
const path_1 = require("../../utils/path");
|
16
|
+
const logger_1 = require("../../utils/logger");
|
17
|
+
const node_path_1 = require("node:path");
|
18
|
+
const internal_api_1 = require("./internal-api");
|
19
|
+
async function loadNxPluginAsync(pluginConfiguration, paths, projects, root) {
|
20
|
+
const { plugin: moduleName, options } = typeof pluginConfiguration === 'object'
|
21
|
+
? pluginConfiguration
|
22
|
+
: { plugin: pluginConfiguration, options: undefined };
|
23
|
+
performance.mark(`Load Nx Plugin: ${moduleName} - start`);
|
24
|
+
let { pluginPath, name } = await getPluginPathAndName(moduleName, paths, projects, root);
|
25
|
+
const plugin = (0, internal_api_1.normalizeNxPlugin)(await importPluginModule(pluginPath));
|
26
|
+
plugin.name ??= name;
|
27
|
+
performance.mark(`Load Nx Plugin: ${moduleName} - end`);
|
28
|
+
performance.measure(`Load Nx Plugin: ${moduleName}`, `Load Nx Plugin: ${moduleName} - start`, `Load Nx Plugin: ${moduleName} - end`);
|
29
|
+
return { plugin, options };
|
30
|
+
}
|
31
|
+
exports.loadNxPluginAsync = loadNxPluginAsync;
|
32
|
+
function readPluginPackageJson(pluginName, projects, paths = (0, installation_directory_1.getNxRequirePaths)()) {
|
33
|
+
try {
|
34
|
+
const result = (0, package_json_1.readModulePackageJsonWithoutFallbacks)(pluginName, paths);
|
35
|
+
return {
|
36
|
+
json: result.packageJson,
|
37
|
+
path: result.path,
|
38
|
+
};
|
39
|
+
}
|
40
|
+
catch (e) {
|
41
|
+
if (e.code === 'MODULE_NOT_FOUND') {
|
42
|
+
const localPluginPath = resolveLocalNxPlugin(pluginName, projects);
|
43
|
+
if (localPluginPath) {
|
44
|
+
const localPluginPackageJson = path.join(localPluginPath.path, 'package.json');
|
45
|
+
return {
|
46
|
+
path: localPluginPackageJson,
|
47
|
+
json: (0, fileutils_1.readJsonFile)(localPluginPackageJson),
|
48
|
+
};
|
49
|
+
}
|
50
|
+
}
|
51
|
+
throw e;
|
52
|
+
}
|
53
|
+
}
|
54
|
+
exports.readPluginPackageJson = readPluginPackageJson;
|
55
|
+
function resolveLocalNxPlugin(importPath, projects, root = workspace_root_1.workspaceRoot) {
|
56
|
+
return lookupLocalPlugin(importPath, projects, root);
|
57
|
+
}
|
58
|
+
exports.resolveLocalNxPlugin = resolveLocalNxPlugin;
|
59
|
+
/**
|
60
|
+
* Register swc-node or ts-node if they are not currently registered
|
61
|
+
* with some default settings which work well for Nx plugins.
|
62
|
+
*/
|
63
|
+
function registerPluginTSTranspiler() {
|
64
|
+
// Get the first tsconfig that matches the allowed set
|
65
|
+
const tsConfigName = [
|
66
|
+
(0, posix_1.join)(workspace_root_1.workspaceRoot, 'tsconfig.base.json'),
|
67
|
+
(0, posix_1.join)(workspace_root_1.workspaceRoot, 'tsconfig.json'),
|
68
|
+
].find((x) => (0, node_fs_1.existsSync)(x));
|
69
|
+
const tsConfig = tsConfigName
|
70
|
+
? (0, typescript_1.readTsConfig)(tsConfigName)
|
71
|
+
: {};
|
72
|
+
(0, register_1.registerTsConfigPaths)(tsConfigName);
|
73
|
+
(0, register_1.registerTranspiler)({
|
74
|
+
experimentalDecorators: true,
|
75
|
+
emitDecoratorMetadata: true,
|
76
|
+
...tsConfig.options,
|
77
|
+
});
|
78
|
+
}
|
79
|
+
exports.registerPluginTSTranspiler = registerPluginTSTranspiler;
|
80
|
+
function lookupLocalPlugin(importPath, projects, root = workspace_root_1.workspaceRoot) {
|
81
|
+
const plugin = findNxProjectForImportPath(importPath, projects, root);
|
82
|
+
if (!plugin) {
|
83
|
+
return null;
|
84
|
+
}
|
85
|
+
const projectConfig = projects[plugin];
|
86
|
+
return { path: path.join(root, projectConfig.root), projectConfig };
|
87
|
+
}
|
88
|
+
function findNxProjectForImportPath(importPath, projects, root = workspace_root_1.workspaceRoot) {
|
89
|
+
const tsConfigPaths = readTsConfigPaths(root);
|
90
|
+
const possiblePaths = tsConfigPaths[importPath]?.map((p) => (0, path_1.normalizePath)(path.relative(root, path.join(root, p))));
|
91
|
+
if (possiblePaths?.length) {
|
92
|
+
const projectRootMappings = (0, find_project_for_path_1.createProjectRootMappingsFromProjectConfigurations)(projects);
|
93
|
+
for (const tsConfigPath of possiblePaths) {
|
94
|
+
const nxProject = (0, find_project_for_path_1.findProjectForPath)(tsConfigPath, projectRootMappings);
|
95
|
+
if (nxProject) {
|
96
|
+
return nxProject;
|
97
|
+
}
|
98
|
+
}
|
99
|
+
logger_1.logger.verbose('Unable to find local plugin', possiblePaths, projectRootMappings);
|
100
|
+
throw new Error('Unable to resolve local plugin with import path ' + importPath);
|
101
|
+
}
|
102
|
+
}
|
103
|
+
let tsconfigPaths;
|
104
|
+
function readTsConfigPaths(root = workspace_root_1.workspaceRoot) {
|
105
|
+
if (!tsconfigPaths) {
|
106
|
+
const tsconfigPath = ['tsconfig.base.json', 'tsconfig.json']
|
107
|
+
.map((x) => path.join(root, x))
|
108
|
+
.filter((x) => (0, node_fs_1.existsSync)(x))[0];
|
109
|
+
if (!tsconfigPath) {
|
110
|
+
throw new Error('unable to find tsconfig.base.json or tsconfig.json');
|
111
|
+
}
|
112
|
+
const { compilerOptions } = (0, fileutils_1.readJsonFile)(tsconfigPath);
|
113
|
+
tsconfigPaths = compilerOptions?.paths;
|
114
|
+
}
|
115
|
+
return tsconfigPaths ?? {};
|
116
|
+
}
|
117
|
+
function readPluginMainFromProjectConfiguration(plugin) {
|
118
|
+
const { main } = Object.values(plugin.targets).find((x) => [
|
119
|
+
'@nx/js:tsc',
|
120
|
+
'@nrwl/js:tsc',
|
121
|
+
'@nx/js:swc',
|
122
|
+
'@nrwl/js:swc',
|
123
|
+
'@nx/node:package',
|
124
|
+
'@nrwl/node:package',
|
125
|
+
].includes(x.executor))?.options ||
|
126
|
+
plugin.targets?.build?.options ||
|
127
|
+
{};
|
128
|
+
return main;
|
129
|
+
}
|
130
|
+
function getPluginPathAndName(moduleName, paths, projects, root) {
|
131
|
+
let pluginPath;
|
132
|
+
let registerTSTranspiler = false;
|
133
|
+
try {
|
134
|
+
pluginPath = require.resolve(moduleName, {
|
135
|
+
paths,
|
136
|
+
});
|
137
|
+
const extension = path.extname(pluginPath);
|
138
|
+
registerTSTranspiler = extension === '.ts';
|
139
|
+
}
|
140
|
+
catch (e) {
|
141
|
+
if (e.code === 'MODULE_NOT_FOUND') {
|
142
|
+
const plugin = resolveLocalNxPlugin(moduleName, projects, root);
|
143
|
+
if (plugin) {
|
144
|
+
registerTSTranspiler = true;
|
145
|
+
const main = readPluginMainFromProjectConfiguration(plugin.projectConfig);
|
146
|
+
pluginPath = main ? path.join(root, main) : plugin.path;
|
147
|
+
}
|
148
|
+
else {
|
149
|
+
logger_1.logger.error(`Plugin listed in \`nx.json\` not found: ${moduleName}`);
|
150
|
+
throw e;
|
151
|
+
}
|
152
|
+
}
|
153
|
+
else {
|
154
|
+
throw e;
|
155
|
+
}
|
156
|
+
}
|
157
|
+
const packageJsonPath = path.join(pluginPath, 'package.json');
|
158
|
+
// Register the ts-transpiler if we are pointing to a
|
159
|
+
// plain ts file that's not part of a plugin project
|
160
|
+
if (registerTSTranspiler) {
|
161
|
+
registerPluginTSTranspiler();
|
162
|
+
}
|
163
|
+
const { name } = !['.ts', '.js'].some((x) => (0, node_path_1.extname)(moduleName) === x) && // Not trying to point to a ts or js file
|
164
|
+
(0, node_fs_1.existsSync)(packageJsonPath) // plugin has a package.json
|
165
|
+
? (0, fileutils_1.readJsonFile)(packageJsonPath) // read name from package.json
|
166
|
+
: { name: moduleName };
|
167
|
+
return { pluginPath, name };
|
168
|
+
}
|
169
|
+
exports.getPluginPathAndName = getPluginPathAndName;
|
170
|
+
async function importPluginModule(pluginPath) {
|
171
|
+
const m = await Promise.resolve(`${pluginPath}`).then(s => require(s));
|
172
|
+
if (m.default &&
|
173
|
+
('createNodes' in m.default || 'createDependencies' in m.default)) {
|
174
|
+
return m.default;
|
175
|
+
}
|
176
|
+
return m;
|
177
|
+
}
|
@@ -2,7 +2,7 @@
|
|
2
2
|
* Builder for adding nodes and dependencies to a {@link ProjectGraph}
|
3
3
|
*/
|
4
4
|
import { DependencyType, FileMap, ProjectFileMap, ProjectGraph, ProjectGraphExternalNode, ProjectGraphProjectNode } from '../config/project-graph';
|
5
|
-
import { CreateDependenciesContext } from '
|
5
|
+
import { CreateDependenciesContext } from './plugins';
|
6
6
|
/**
|
7
7
|
* A class which builds up a project graph
|
8
8
|
* @deprecated The {@link ProjectGraphProcessor} has been deprecated. Use a {@link CreateNodes} and/or a {@link CreateDependencies} instead. This will be removed in Nx 19.
|
@@ -12,7 +12,6 @@ const workspace_root_1 = require("../utils/workspace-root");
|
|
12
12
|
const perf_hooks_1 = require("perf_hooks");
|
13
13
|
const retrieve_workspace_files_1 = require("./utils/retrieve-workspace-files");
|
14
14
|
const nx_json_1 = require("../config/nx-json");
|
15
|
-
const nx_plugin_1 = require("../utils/nx-plugin");
|
16
15
|
/**
|
17
16
|
* Synchronously reads the latest cached copy of the workspace's ProjectGraph.
|
18
17
|
* @throws {Error} if there is no cached ProjectGraph to read from
|
@@ -77,7 +76,6 @@ async function buildProjectGraphAndSourceMapsWithoutDaemon() {
|
|
77
76
|
perf_hooks_1.performance.mark('build-project-graph-using-project-file-map:start');
|
78
77
|
const projectGraph = (await (0, build_project_graph_1.buildProjectGraphUsingProjectFileMap)(projects, externalNodes, fileMap, allWorkspaceFiles, rustReferences, cacheEnabled ? (0, nx_deps_cache_1.readFileMapCache)() : null, cacheEnabled)).projectGraph;
|
79
78
|
perf_hooks_1.performance.mark('build-project-graph-using-project-file-map:end');
|
80
|
-
(0, nx_plugin_1.unregisterPluginTSTranspiler)();
|
81
79
|
return { projectGraph, sourceMaps };
|
82
80
|
}
|
83
81
|
exports.buildProjectGraphAndSourceMapsWithoutDaemon = buildProjectGraphAndSourceMapsWithoutDaemon;
|
@@ -1,7 +1,7 @@
|
|
1
1
|
import { ProjectGraphProjectNode } from '../../config/project-graph';
|
2
2
|
import { ProjectGraphBuilder } from '../project-graph-builder';
|
3
3
|
import { ProjectConfiguration, TargetConfiguration } from '../../config/workspace-json-project-json';
|
4
|
-
import { CreateDependenciesContext } from '
|
4
|
+
import { CreateDependenciesContext } from '../plugins';
|
5
5
|
export declare function normalizeProjectNodes(ctx: CreateDependenciesContext, builder: ProjectGraphBuilder): Promise<void>;
|
6
6
|
/**
|
7
7
|
* Apply target defaults and normalization
|
@@ -1,8 +1,8 @@
|
|
1
1
|
import { NxJsonConfiguration, TargetDefaults } from '../../config/nx-json';
|
2
2
|
import { ProjectGraphExternalNode } from '../../config/project-graph';
|
3
3
|
import { ProjectConfiguration, TargetConfiguration } from '../../config/workspace-json-project-json';
|
4
|
-
import { LoadedNxPlugin } from '../../utils/nx-plugin';
|
5
4
|
import { ONLY_MODIFIES_EXISTING_TARGET } from '../../plugins/target-defaults/target-defaults-plugin';
|
5
|
+
import { RemotePlugin } from '../plugins/internal-api';
|
6
6
|
export type SourceInformation = [file: string, plugin: string];
|
7
7
|
export type ConfigurationSourceMaps = Record<string, Record<string, SourceInformation>>;
|
8
8
|
export declare function mergeProjectConfigurationIntoRootMap(projectRootMap: Map<string, ProjectConfiguration>, project: ProjectConfiguration & {
|
@@ -25,7 +25,7 @@ export type ConfigurationResult = {
|
|
25
25
|
* @param root The workspace root
|
26
26
|
*/
|
27
27
|
export declare function buildProjectsConfigurationsFromProjectPathsAndPlugins(nxJson: NxJsonConfiguration, projectFiles: string[], // making this parameter allows devkit to pick up newly created projects
|
28
|
-
plugins:
|
28
|
+
plugins: RemotePlugin[], root?: string): Promise<ConfigurationResult>;
|
29
29
|
export declare function readProjectConfigurationsFromRootMap(projectRootMap: Map<string, ProjectConfiguration>): Record<string, ProjectConfiguration>;
|
30
30
|
/**
|
31
31
|
* Merges two targets.
|
@@ -108,13 +108,13 @@ skipCommandNormalization) {
|
|
108
108
|
!matchingProject.targets?.[targetName]) {
|
109
109
|
continue;
|
110
110
|
}
|
111
|
+
const mergedTarget = mergeTargetConfigurations(skipCommandNormalization
|
112
|
+
? target
|
113
|
+
: resolveCommandSyntacticSugar(target, project.root), matchingProject.targets?.[targetName], sourceMap, sourceInformation, `targets.${targetName}`);
|
111
114
|
// We don't want the symbol to live on past the merge process
|
112
|
-
if (
|
113
|
-
delete
|
114
|
-
updatedProjectConfiguration.targets[targetName] =
|
115
|
-
mergeTargetConfigurations(skipCommandNormalization
|
116
|
-
? target
|
117
|
-
: resolveCommandSyntacticSugar(target, project.root), matchingProject.targets?.[targetName], sourceMap, sourceInformation, `targets.${targetName}`);
|
115
|
+
if (mergedTarget?.[target_defaults_plugin_1.ONLY_MODIFIES_EXISTING_TARGET])
|
116
|
+
delete mergedTarget?.[target_defaults_plugin_1.ONLY_MODIFIES_EXISTING_TARGET];
|
117
|
+
updatedProjectConfiguration.targets[targetName] = mergedTarget;
|
118
118
|
}
|
119
119
|
}
|
120
120
|
projectRootMap.set(updatedProjectConfiguration.root, updatedProjectConfiguration);
|
@@ -132,57 +132,30 @@ function buildProjectsConfigurationsFromProjectPathsAndPlugins(nxJson, projectFi
|
|
132
132
|
plugins, root = workspace_root_1.workspaceRoot) {
|
133
133
|
const results = [];
|
134
134
|
// We iterate over plugins first - this ensures that plugins specified first take precedence.
|
135
|
-
for (const
|
135
|
+
for (const plugin of plugins) {
|
136
136
|
const [pattern, createNodes] = plugin.createNodes ?? [];
|
137
|
-
const pluginResults = [];
|
138
|
-
performance.mark(`${plugin.name}:createNodes - start`);
|
139
137
|
if (!pattern) {
|
140
138
|
continue;
|
141
139
|
}
|
140
|
+
const matchedFiles = [];
|
141
|
+
performance.mark(`${plugin.name}:createNodes - start`);
|
142
142
|
// Set this globally to allow plugins to know if they are being called from the project graph creation
|
143
143
|
global.NX_GRAPH_CREATION = true;
|
144
144
|
for (const file of projectFiles) {
|
145
|
-
performance.mark(`${plugin.name}:createNodes:${file} - start`);
|
146
145
|
if ((0, minimatch_1.minimatch)(file, pattern, { dot: true })) {
|
147
|
-
|
148
|
-
let r = createNodes(file, options, {
|
149
|
-
nxJsonConfiguration: nxJson,
|
150
|
-
workspaceRoot: root,
|
151
|
-
});
|
152
|
-
if (r instanceof Promise) {
|
153
|
-
pluginResults.push(r
|
154
|
-
.catch((e) => {
|
155
|
-
performance.mark(`${plugin.name}:createNodes:${file} - end`);
|
156
|
-
throw new CreateNodesError(`Unable to create nodes for ${file} using plugin ${plugin.name}.`, e);
|
157
|
-
})
|
158
|
-
.then((r) => {
|
159
|
-
performance.mark(`${plugin.name}:createNodes:${file} - end`);
|
160
|
-
performance.measure(`${plugin.name}:createNodes:${file}`, `${plugin.name}:createNodes:${file} - start`, `${plugin.name}:createNodes:${file} - end`);
|
161
|
-
return { ...r, file, pluginName: plugin.name };
|
162
|
-
}));
|
163
|
-
}
|
164
|
-
else {
|
165
|
-
performance.mark(`${plugin.name}:createNodes:${file} - end`);
|
166
|
-
performance.measure(`${plugin.name}:createNodes:${file}`, `${plugin.name}:createNodes:${file} - start`, `${plugin.name}:createNodes:${file} - end`);
|
167
|
-
pluginResults.push({
|
168
|
-
...r,
|
169
|
-
file,
|
170
|
-
pluginName: plugin.name,
|
171
|
-
});
|
172
|
-
}
|
173
|
-
}
|
174
|
-
catch (e) {
|
175
|
-
throw new CreateNodesError(`Unable to create nodes for ${file} using plugin ${plugin.name}.`, e);
|
176
|
-
}
|
146
|
+
matchedFiles.push(file);
|
177
147
|
}
|
178
148
|
}
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
}
|
149
|
+
try {
|
150
|
+
let r = createNodes(matchedFiles, {
|
151
|
+
nxJsonConfiguration: nxJson,
|
152
|
+
workspaceRoot: root,
|
153
|
+
});
|
154
|
+
results.push(r);
|
155
|
+
}
|
156
|
+
catch (e) {
|
157
|
+
throw new CreateNodesError(`Unable to create nodes using plugin ${plugin.name}.`, e);
|
158
|
+
}
|
186
159
|
}
|
187
160
|
return Promise.all(results).then((results) => {
|
188
161
|
performance.mark('createNodes:merge - start');
|
@@ -288,6 +261,13 @@ function mergeTargetConfigurations(target, baseTarget, projectConfigSourceMap, s
|
|
288
261
|
// Target is "compatible", e.g. executor is defined only once or is the same
|
289
262
|
// in both places. This means that it is likely safe to merge
|
290
263
|
const isCompatible = isCompatibleTarget(baseTargetProperties, target);
|
264
|
+
// If the targets are not compatible, we would normally overwrite the old target
|
265
|
+
// with the new one. However, we have a special case for targets that have the
|
266
|
+
// ONLY_MODIFIES_EXISTING_TARGET symbol set. This prevents the merged target
|
267
|
+
// equaling info that should have only been used to modify the existing target.
|
268
|
+
if (!isCompatible && target[target_defaults_plugin_1.ONLY_MODIFIES_EXISTING_TARGET]) {
|
269
|
+
return baseTarget;
|
270
|
+
}
|
291
271
|
if (!isCompatible && projectConfigSourceMap) {
|
292
272
|
// if the target is not compatible, we will simply override the options
|
293
273
|
// we have to delete old entries from the source map
|
@@ -2,7 +2,7 @@ import { ProjectConfiguration } from '../../config/workspace-json-project-json';
|
|
2
2
|
import { NxJsonConfiguration } from '../../config/nx-json';
|
3
3
|
import { ProjectGraphExternalNode } from '../../config/project-graph';
|
4
4
|
import { ConfigurationSourceMaps } from './project-configuration-utils';
|
5
|
-
import {
|
5
|
+
import { RemotePlugin } from '../plugins/internal-api';
|
6
6
|
/**
|
7
7
|
* Walks the workspace directory to create the `projectFileMap`, `ProjectConfigurations` and `allWorkspaceFiles`
|
8
8
|
* @throws
|
@@ -31,7 +31,11 @@ export type RetrievedGraphNodes = {
|
|
31
31
|
sourceMaps: ConfigurationSourceMaps;
|
32
32
|
projectRootMap: Record<string, string>;
|
33
33
|
};
|
34
|
-
export declare function retrieveProjectConfigurationPaths(root: string, plugins:
|
34
|
+
export declare function retrieveProjectConfigurationPaths(root: string, plugins: PluginGlobsOnly): string[];
|
35
35
|
export declare function retrieveProjectConfigurationsWithoutPluginInference(root: string): Promise<Record<string, ProjectConfiguration>>;
|
36
|
-
export declare function createProjectConfigurations(workspaceRoot: string, nxJson: NxJsonConfiguration, configFiles: string[], plugins:
|
37
|
-
|
36
|
+
export declare function createProjectConfigurations(workspaceRoot: string, nxJson: NxJsonConfiguration, configFiles: string[], plugins: RemotePlugin[]): Promise<RetrievedGraphNodes>;
|
37
|
+
type PluginGlobsOnly = Array<{
|
38
|
+
createNodes?: readonly [string, ...unknown[]];
|
39
|
+
}>;
|
40
|
+
export declare function configurationGlobs(plugins: PluginGlobsOnly): string[];
|
41
|
+
export {};
|
@@ -2,15 +2,13 @@
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.configurationGlobs = exports.createProjectConfigurations = exports.retrieveProjectConfigurationsWithoutPluginInference = exports.retrieveProjectConfigurationPaths = exports.retrieveProjectConfigurationsWithAngularProjects = exports.retrieveProjectConfigurations = exports.retrieveWorkspaceFiles = void 0;
|
4
4
|
const perf_hooks_1 = require("perf_hooks");
|
5
|
-
const installation_directory_1 = require("../../utils/installation-directory");
|
6
5
|
const angular_json_1 = require("../../adapter/angular-json");
|
7
6
|
const nx_json_1 = require("../../config/nx-json");
|
8
|
-
const package_json_workspaces_1 = require("../../plugins/package-json-workspaces");
|
9
7
|
const project_configuration_utils_1 = require("./project-configuration-utils");
|
10
|
-
const
|
11
|
-
const project_json_1 = require("../../plugins/project-json/build-nodes/project-json");
|
8
|
+
const internal_api_1 = require("../plugins/internal-api");
|
12
9
|
const workspace_context_1 = require("../../utils/workspace-context");
|
13
10
|
const build_all_workspace_files_1 = require("./build-all-workspace-files");
|
11
|
+
const path_1 = require("path");
|
14
12
|
/**
|
15
13
|
* Walks the workspace directory to create the `projectFileMap`, `ProjectConfigurations` and `allWorkspaceFiles`
|
16
14
|
* @throws
|
@@ -42,16 +40,18 @@ exports.retrieveWorkspaceFiles = retrieveWorkspaceFiles;
|
|
42
40
|
* @param nxJson
|
43
41
|
*/
|
44
42
|
async function retrieveProjectConfigurations(workspaceRoot, nxJson) {
|
45
|
-
const plugins = await (0,
|
43
|
+
const plugins = await (0, internal_api_1.loadNxPlugins)(nxJson?.plugins ?? [], workspaceRoot);
|
46
44
|
return _retrieveProjectConfigurations(workspaceRoot, nxJson, plugins);
|
47
45
|
}
|
48
46
|
exports.retrieveProjectConfigurations = retrieveProjectConfigurations;
|
49
47
|
async function retrieveProjectConfigurationsWithAngularProjects(workspaceRoot, nxJson) {
|
50
|
-
const
|
48
|
+
const pluginsToLoad = nxJson?.plugins ?? [];
|
51
49
|
if ((0, angular_json_1.shouldMergeAngularProjects)(workspaceRoot, true) &&
|
52
|
-
!
|
53
|
-
|
50
|
+
!pluginsToLoad.some((p) => p === angular_json_1.NX_ANGULAR_JSON_PLUGIN_NAME ||
|
51
|
+
(typeof p === 'object' && p.plugin === angular_json_1.NX_ANGULAR_JSON_PLUGIN_NAME))) {
|
52
|
+
pluginsToLoad.push((0, path_1.join)(__dirname, '../../adapter/angular-json'));
|
54
53
|
}
|
54
|
+
const plugins = await (0, internal_api_1.loadNxPlugins)(nxJson?.plugins ?? [], workspaceRoot);
|
55
55
|
return _retrieveProjectConfigurations(workspaceRoot, nxJson, plugins);
|
56
56
|
}
|
57
57
|
exports.retrieveProjectConfigurationsWithAngularProjects = retrieveProjectConfigurationsWithAngularProjects;
|
@@ -69,17 +69,14 @@ const projectsWithoutPluginCache = new Map();
|
|
69
69
|
// TODO: This function is called way too often, it should be optimized without this cache
|
70
70
|
async function retrieveProjectConfigurationsWithoutPluginInference(root) {
|
71
71
|
const nxJson = (0, nx_json_1.readNxJson)(root);
|
72
|
-
const plugins = await (0,
|
72
|
+
const plugins = await (0, internal_api_1.loadNxPlugins)([]); // only load default plugins
|
73
73
|
const projectGlobPatterns = retrieveProjectConfigurationPaths(root, plugins);
|
74
74
|
const cacheKey = root + ',' + projectGlobPatterns.join(',');
|
75
75
|
if (projectsWithoutPluginCache.has(cacheKey)) {
|
76
76
|
return projectsWithoutPluginCache.get(cacheKey);
|
77
77
|
}
|
78
78
|
const projectFiles = (0, workspace_context_1.globWithWorkspaceContext)(root, projectGlobPatterns);
|
79
|
-
const { projects } = await createProjectConfigurations(root, nxJson, projectFiles,
|
80
|
-
{ plugin: (0, package_json_workspaces_1.getNxPackageJsonWorkspacesPlugin)(root) },
|
81
|
-
{ plugin: project_json_1.ProjectJsonProjectsPlugin },
|
82
|
-
]);
|
79
|
+
const { projects } = await createProjectConfigurations(root, nxJson, projectFiles, plugins);
|
83
80
|
projectsWithoutPluginCache.set(cacheKey, projects);
|
84
81
|
return projects;
|
85
82
|
}
|
@@ -99,7 +96,7 @@ async function createProjectConfigurations(workspaceRoot, nxJson, configFiles, p
|
|
99
96
|
exports.createProjectConfigurations = createProjectConfigurations;
|
100
97
|
function configurationGlobs(plugins) {
|
101
98
|
const globPatterns = [];
|
102
|
-
for (const
|
99
|
+
for (const plugin of plugins) {
|
103
100
|
if (plugin.createNodes) {
|
104
101
|
globPatterns.push(plugin.createNodes[0]);
|
105
102
|
}
|
package/src/utils/logger.d.ts
CHANGED
package/src/utils/logger.js
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
import { ProjectGraphProcessor } from '../config/project-graph';
|
2
2
|
import { TargetConfiguration } from '../config/workspace-json-project-json';
|
3
|
-
import {
|
3
|
+
import { NxPluginV2 } from '../project-graph/plugins';
|
4
4
|
/**
|
5
5
|
* @deprecated Add targets to the projects in a {@link CreateNodes} function instead. This will be removed in Nx 19
|
6
6
|
*/
|
@@ -28,4 +28,6 @@ export type NxPluginV1 = {
|
|
28
28
|
/**
|
29
29
|
* @todo(@agentender) v19: Remove this fn when we remove readWorkspaceConfig
|
30
30
|
*/
|
31
|
-
export declare function getDefaultPluginsSync(root: string):
|
31
|
+
export declare function getDefaultPluginsSync(root: string): {
|
32
|
+
plugin: NxPluginV2;
|
33
|
+
}[];
|
@@ -4,7 +4,7 @@ exports.getDefaultPluginsSync = void 0;
|
|
4
4
|
const angular_json_1 = require("../adapter/angular-json");
|
5
5
|
const project_json_1 = require("../plugins/project-json/build-nodes/project-json");
|
6
6
|
const target_defaults_plugin_1 = require("../plugins/target-defaults/target-defaults-plugin");
|
7
|
-
const
|
7
|
+
const PackageJsonWorkspacesPlugin = require("../plugins/package-json-workspaces");
|
8
8
|
/**
|
9
9
|
* @todo(@agentender) v19: Remove this fn when we remove readWorkspaceConfig
|
10
10
|
*/
|
@@ -14,9 +14,9 @@ function getDefaultPluginsSync(root) {
|
|
14
14
|
...((0, angular_json_1.shouldMergeAngularProjects)(root, false)
|
15
15
|
? [require('../adapter/angular-json').NxAngularJsonPlugin]
|
16
16
|
: []),
|
17
|
-
target_defaults_plugin_1.
|
18
|
-
|
19
|
-
project_json_1.
|
17
|
+
target_defaults_plugin_1.default,
|
18
|
+
PackageJsonWorkspacesPlugin,
|
19
|
+
project_json_1.default,
|
20
20
|
];
|
21
21
|
return plugins.map((p) => ({
|
22
22
|
plugin: p,
|
@@ -48,7 +48,7 @@ function buildTargetFromScript(script) {
|
|
48
48
|
}
|
49
49
|
exports.buildTargetFromScript = buildTargetFromScript;
|
50
50
|
function readTargetsFromPackageJson(packageJson) {
|
51
|
-
const { scripts, nx } = packageJson;
|
51
|
+
const { scripts, nx, private: isPrivate } = packageJson ?? {};
|
52
52
|
const res = {};
|
53
53
|
const includedScripts = nx?.includedScripts || Object.keys(scripts ?? {});
|
54
54
|
//
|
@@ -63,7 +63,7 @@ function readTargetsFromPackageJson(packageJson) {
|
|
63
63
|
* not marked as `"private": true` to allow for lightweight configuration for
|
64
64
|
* package based repos.
|
65
65
|
*/
|
66
|
-
if (!
|
66
|
+
if (!isPrivate && !res['nx-release-publish']) {
|
67
67
|
res['nx-release-publish'] = {
|
68
68
|
dependsOn: ['^nx-release-publish'],
|
69
69
|
executor: '@nx/js:release-publish',
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import type { PluginCapabilities } from './models';
|
2
1
|
import { ProjectConfiguration } from '../../config/workspace-json-project-json';
|
2
|
+
import type { PluginCapabilities } from './models';
|
3
3
|
export declare function getPluginCapabilities(workspaceRoot: string, pluginName: string, projects: Record<string, ProjectConfiguration>, includeRuntimeCapabilities?: boolean): Promise<PluginCapabilities | null>;
|
4
4
|
export declare function listPluginCapabilities(pluginName: string, projects: Record<string, ProjectConfiguration>): Promise<void>;
|