nx 18.1.0-canary.20240309-235ca8c → 18.1.0-canary.20240313-81df848
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/bin/post-install.js +5 -7
- package/package.json +12 -12
- package/src/adapter/angular-json.d.ts +1 -2
- package/src/adapter/angular-json.js +0 -1
- package/src/adapter/ngcli-adapter.js +3 -3
- package/src/command-line/generate/generator-utils.js +2 -2
- package/src/command-line/run/executor-utils.js +2 -2
- package/src/config/schema-utils.js +2 -2
- package/src/core/graph/3rdpartylicenses.txt +51 -0
- package/src/core/graph/main.js +1 -1
- package/src/core/graph/polyfills.js +1 -1
- package/src/core/graph/runtime.js +1 -1
- package/src/core/graph/styles.js +1 -1
- package/src/daemon/server/project-graph-incremental-recomputation.js +7 -8
- package/src/daemon/server/shutdown-utils.js +0 -2
- package/src/devkit-exports.d.ts +1 -2
- package/src/executors/run-commands/run-commands.impl.d.ts +3 -0
- package/src/executors/run-commands/run-commands.impl.js +77 -38
- package/src/executors/utils/convert-nx-executor.js +1 -4
- package/src/generators/utils/project-configuration.js +2 -2
- package/src/hasher/hash-task.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/js/utils/register.js +3 -1
- package/src/plugins/package-json-workspaces/create-nodes.d.ts +2 -2
- package/src/plugins/package-json-workspaces/create-nodes.js +31 -24
- package/src/plugins/package-json-workspaces/index.d.ts +0 -1
- package/src/plugins/package-json-workspaces/index.js +0 -2
- package/src/plugins/project-json/build-nodes/package-json-next-to-project-json.d.ts +1 -2
- package/src/plugins/project-json/build-nodes/package-json-next-to-project-json.js +0 -1
- package/src/plugins/project-json/build-nodes/project-json.d.ts +1 -2
- package/src/plugins/project-json/build-nodes/project-json.js +0 -1
- package/src/plugins/target-defaults/target-defaults-plugin.d.ts +1 -2
- package/src/plugins/target-defaults/target-defaults-plugin.js +0 -1
- package/src/project-graph/affected/locators/project-glob-changes.js +3 -3
- package/src/project-graph/build-project-graph.d.ts +1 -2
- package/src/project-graph/build-project-graph.js +13 -12
- package/src/project-graph/file-utils.js +3 -3
- package/src/project-graph/project-graph-builder.d.ts +1 -1
- package/src/project-graph/project-graph.js +15 -19
- 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 +55 -11
- package/src/project-graph/utils/retrieve-workspace-files.d.ts +8 -6
- package/src/project-graph/utils/retrieve-workspace-files.js +21 -18
- package/src/tasks-runner/task-orchestrator.js +45 -8
- package/src/tasks-runner/tasks-schedule.js +3 -3
- package/src/tasks-runner/utils.d.ts +7 -6
- package/src/tasks-runner/utils.js +11 -7
- package/src/utils/logger.d.ts +0 -1
- package/src/utils/logger.js +0 -5
- package/src/{project-graph/plugins/public-api.d.ts → utils/nx-plugin.d.ts} +41 -7
- package/src/utils/nx-plugin.deprecated.d.ts +2 -4
- package/src/utils/nx-plugin.deprecated.js +4 -4
- package/src/utils/nx-plugin.js +293 -0
- package/src/utils/output.js +1 -1
- package/src/utils/plugins/plugin-capabilities.d.ts +1 -1
- package/src/utils/plugins/plugin-capabilities.js +9 -10
- package/src/daemon/server/plugins.d.ts +0 -3
- package/src/daemon/server/plugins.js +0 -22
- package/src/project-graph/plugins/index.d.ts +0 -2
- package/src/project-graph/plugins/index.js +0 -8
- package/src/project-graph/plugins/internal-api.d.ts +0 -22
- package/src/project-graph/plugins/internal-api.js +0 -64
- package/src/project-graph/plugins/messaging.d.ts +0 -94
- package/src/project-graph/plugins/messaging.js +0 -23
- package/src/project-graph/plugins/plugin-pool.d.ts +0 -3
- package/src/project-graph/plugins/plugin-pool.js +0 -189
- package/src/project-graph/plugins/plugin-worker.d.ts +0 -1
- package/src/project-graph/plugins/plugin-worker.js +0 -101
- package/src/project-graph/plugins/public-api.js +0 -4
- package/src/project-graph/plugins/utils.d.ts +0 -9
- package/src/project-graph/plugins/utils.js +0 -55
- package/src/project-graph/plugins/worker-api.d.ts +0 -28
- package/src/project-graph/plugins/worker-api.js +0 -195
@@ -1,6 +1,6 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.unparse = exports.isCacheableTask = exports.shouldStreamOutput = exports.getSerializedArgsForTask = exports.getPrintableCommandArgsForTask = exports.getCliPath = exports.calculateReverseDeps = exports.removeIdsFromGraph = exports.removeTasksFromTaskGraph = exports.getCustomHasher = exports.getExecutorForTask = exports.getExecutorNameForTask = exports.interpolate = exports.getOutputsForTargetAndConfiguration = exports.transformLegacyOutputs = exports.validateOutputs = exports.getOutputs = exports.expandDependencyConfigSyntaxSugar = exports.getDependencyConfigs = exports.getCommandAsString = void 0;
|
3
|
+
exports.unparse = exports.isCacheableTask = exports.shouldStreamOutput = exports.getSerializedArgsForTask = exports.getPrintableCommandArgsForTask = exports.getCliPath = exports.calculateReverseDeps = exports.removeIdsFromGraph = exports.removeTasksFromTaskGraph = exports.getCustomHasher = exports.getExecutorForTask = exports.getExecutorNameForTask = exports.getTargetConfigurationForTask = exports.interpolate = exports.getOutputsForTargetAndConfiguration = exports.transformLegacyOutputs = exports.validateOutputs = exports.getOutputs = exports.expandDependencyConfigSyntaxSugar = exports.getDependencyConfigs = exports.getCommandAsString = void 0;
|
4
4
|
const output_1 = require("../utils/output");
|
5
5
|
const path_1 = require("path");
|
6
6
|
const workspace_root_1 = require("../utils/workspace-root");
|
@@ -177,19 +177,23 @@ function interpolate(template, data) {
|
|
177
177
|
});
|
178
178
|
}
|
179
179
|
exports.interpolate = interpolate;
|
180
|
-
|
180
|
+
function getTargetConfigurationForTask(task, projectGraph) {
|
181
181
|
const project = projectGraph.nodes[task.target.project].data;
|
182
|
-
return project.targets[task.target.target]
|
182
|
+
return project.targets[task.target.target];
|
183
|
+
}
|
184
|
+
exports.getTargetConfigurationForTask = getTargetConfigurationForTask;
|
185
|
+
function getExecutorNameForTask(task, projectGraph) {
|
186
|
+
return getTargetConfigurationForTask(task, projectGraph)?.executor;
|
183
187
|
}
|
184
188
|
exports.getExecutorNameForTask = getExecutorNameForTask;
|
185
|
-
|
186
|
-
const executor =
|
189
|
+
function getExecutorForTask(task, projectGraph) {
|
190
|
+
const executor = getExecutorNameForTask(task, projectGraph);
|
187
191
|
const [nodeModule, executorName] = executor.split(':');
|
188
192
|
return (0, executor_utils_1.getExecutorInformation)(nodeModule, executorName, workspace_root_1.workspaceRoot, (0, project_graph_1.readProjectsConfigurationFromProjectGraph)(projectGraph).projects);
|
189
193
|
}
|
190
194
|
exports.getExecutorForTask = getExecutorForTask;
|
191
|
-
|
192
|
-
const factory =
|
195
|
+
function getCustomHasher(task, projectGraph) {
|
196
|
+
const factory = getExecutorForTask(task, projectGraph).hasherFactory;
|
193
197
|
return factory ? factory() : null;
|
194
198
|
}
|
195
199
|
exports.getCustomHasher = getCustomHasher;
|
package/src/utils/logger.d.ts
CHANGED
package/src/utils/logger.js
CHANGED
@@ -1,8 +1,9 @@
|
|
1
|
-
import {
|
2
|
-
import {
|
3
|
-
import { ProjectConfiguration } from '
|
4
|
-
import { NxJsonConfiguration } from '
|
5
|
-
import {
|
1
|
+
import { FileMap, ProjectGraph, ProjectGraphExternalNode } from '../config/project-graph';
|
2
|
+
import { PackageJson } from './package-json';
|
3
|
+
import { ProjectConfiguration } from '../config/workspace-json-project-json';
|
4
|
+
import { NxJsonConfiguration, PluginConfiguration } from '../config/nx-json';
|
5
|
+
import { NxPluginV1 } from './nx-plugin.deprecated';
|
6
|
+
import { RawProjectGraphDependency } from '../project-graph/project-graph-builder';
|
6
7
|
/**
|
7
8
|
* Context for {@link CreateNodesFunction}
|
8
9
|
*/
|
@@ -15,7 +16,6 @@ export interface CreateNodesContext {
|
|
15
16
|
* Used for creating nodes for the {@link ProjectGraph}
|
16
17
|
*/
|
17
18
|
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
|
@@ -73,13 +73,47 @@ export type NxPluginV2<TOptions = unknown> = {
|
|
73
73
|
* Provides a file pattern and function that retrieves configuration info from
|
74
74
|
* those files. e.g. { '**\/*.csproj': buildProjectsFromCsProjFile }
|
75
75
|
*/
|
76
|
-
createNodes?: CreateNodes
|
76
|
+
createNodes?: CreateNodes;
|
77
77
|
/**
|
78
78
|
* Provides a function to analyze files to create dependencies for the {@link ProjectGraph}
|
79
79
|
*/
|
80
80
|
createDependencies?: CreateDependencies<TOptions>;
|
81
81
|
};
|
82
|
+
export * from './nx-plugin.deprecated';
|
82
83
|
/**
|
83
84
|
* A plugin for Nx
|
84
85
|
*/
|
85
86
|
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>>;
|
@@ -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 { LoadedNxPlugin } from './nx-plugin';
|
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,6 +28,4 @@ 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):
|
32
|
-
plugin: NxPluginV2;
|
33
|
-
}[];
|
31
|
+
export declare function getDefaultPluginsSync(root: string): LoadedNxPlugin[];
|
@@ -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 package_json_workspaces_1 = 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.TargetDefaultsPlugin,
|
18
|
+
(0, package_json_workspaces_1.getNxPackageJsonWorkspacesPlugin)(root),
|
19
|
+
project_json_1.ProjectJsonProjectsPlugin,
|
20
20
|
];
|
21
21
|
return plugins.map((p) => ({
|
22
22
|
plugin: p,
|
@@ -0,0 +1,293 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.getDefaultPlugins = exports.unregisterPluginTSTranspiler = exports.registerPluginTSTranspiler = exports.resolveLocalNxPlugin = exports.readPluginPackageJson = exports.isNxPluginV1 = exports.isNxPluginV2 = exports.ensurePluginIsV2 = exports.loadNxPlugins = exports.loadNxPluginAsync = exports.getPluginPathAndName = exports.nxPluginCache = void 0;
|
4
|
+
const tslib_1 = require("tslib");
|
5
|
+
const fs_1 = require("fs");
|
6
|
+
const path = require("path");
|
7
|
+
const workspaces_1 = require("../config/workspaces");
|
8
|
+
const workspace_root_1 = require("./workspace-root");
|
9
|
+
const fileutils_1 = require("../utils/fileutils");
|
10
|
+
const package_json_1 = require("./package-json");
|
11
|
+
const register_1 = require("../plugins/js/utils/register");
|
12
|
+
const logger_1 = require("./logger");
|
13
|
+
const find_project_for_path_1 = require("../project-graph/utils/find-project-for-path");
|
14
|
+
const path_1 = require("./path");
|
15
|
+
const path_2 = require("path");
|
16
|
+
const installation_directory_1 = require("./installation-directory");
|
17
|
+
const typescript_1 = require("../plugins/js/utils/typescript");
|
18
|
+
const nx_json_1 = require("../config/nx-json");
|
19
|
+
const globs_1 = require("./globs");
|
20
|
+
const angular_json_1 = require("../adapter/angular-json");
|
21
|
+
const package_json_workspaces_1 = require("../plugins/package-json-workspaces");
|
22
|
+
const project_json_1 = require("../plugins/project-json/build-nodes/project-json");
|
23
|
+
const package_json_next_to_project_json_1 = require("../plugins/project-json/build-nodes/package-json-next-to-project-json");
|
24
|
+
const retrieve_workspace_files_1 = require("../project-graph/utils/retrieve-workspace-files");
|
25
|
+
const target_defaults_plugin_1 = require("../plugins/target-defaults/target-defaults-plugin");
|
26
|
+
tslib_1.__exportStar(require("./nx-plugin.deprecated"), exports);
|
27
|
+
// Short lived cache (cleared between cmd runs)
|
28
|
+
// holding resolved nx plugin objects.
|
29
|
+
// Allows loadNxPlugins to be called multiple times w/o
|
30
|
+
// executing resolution mulitple times.
|
31
|
+
exports.nxPluginCache = new Map();
|
32
|
+
function getPluginPathAndName(moduleName, paths, projects, root) {
|
33
|
+
let pluginPath;
|
34
|
+
try {
|
35
|
+
pluginPath = require.resolve(moduleName, {
|
36
|
+
paths,
|
37
|
+
});
|
38
|
+
}
|
39
|
+
catch (e) {
|
40
|
+
if (e.code === 'MODULE_NOT_FOUND') {
|
41
|
+
const plugin = resolveLocalNxPlugin(moduleName, (0, nx_json_1.readNxJson)(root), projects, root);
|
42
|
+
if (plugin) {
|
43
|
+
const main = readPluginMainFromProjectConfiguration(plugin.projectConfig);
|
44
|
+
pluginPath = main ? path.join(root, main) : plugin.path;
|
45
|
+
}
|
46
|
+
else {
|
47
|
+
logger_1.logger.error(`Plugin listed in \`nx.json\` not found: ${moduleName}`);
|
48
|
+
throw e;
|
49
|
+
}
|
50
|
+
}
|
51
|
+
else {
|
52
|
+
throw e;
|
53
|
+
}
|
54
|
+
}
|
55
|
+
const packageJsonPath = path.join(pluginPath, 'package.json');
|
56
|
+
const extension = path.extname(pluginPath);
|
57
|
+
// Register the ts-transpiler if we are pointing to a
|
58
|
+
// plain ts file that's not part of a plugin project
|
59
|
+
if (extension === '.ts' && !tsNodeAndPathsUnregisterCallback) {
|
60
|
+
registerPluginTSTranspiler();
|
61
|
+
}
|
62
|
+
const { name } = !['.ts', '.js'].some((x) => x === extension) && // Not trying to point to a ts or js file
|
63
|
+
(0, fs_1.existsSync)(packageJsonPath) // plugin has a package.json
|
64
|
+
? (0, fileutils_1.readJsonFile)(packageJsonPath) // read name from package.json
|
65
|
+
: { name: moduleName };
|
66
|
+
return { pluginPath, name };
|
67
|
+
}
|
68
|
+
exports.getPluginPathAndName = getPluginPathAndName;
|
69
|
+
async function loadNxPluginAsync(pluginConfiguration, paths, projects, root) {
|
70
|
+
const { plugin: moduleName, options } = typeof pluginConfiguration === 'object'
|
71
|
+
? pluginConfiguration
|
72
|
+
: { plugin: pluginConfiguration, options: undefined };
|
73
|
+
let pluginModule = exports.nxPluginCache.get(moduleName);
|
74
|
+
if (pluginModule) {
|
75
|
+
return { plugin: pluginModule, options };
|
76
|
+
}
|
77
|
+
performance.mark(`Load Nx Plugin: ${moduleName} - start`);
|
78
|
+
let { pluginPath, name } = await getPluginPathAndName(moduleName, paths, projects, root);
|
79
|
+
const plugin = ensurePluginIsV2((await Promise.resolve(`${pluginPath}`).then(s => require(s))));
|
80
|
+
plugin.name ??= name;
|
81
|
+
exports.nxPluginCache.set(moduleName, plugin);
|
82
|
+
performance.mark(`Load Nx Plugin: ${moduleName} - end`);
|
83
|
+
performance.measure(`Load Nx Plugin: ${moduleName}`, `Load Nx Plugin: ${moduleName} - start`, `Load Nx Plugin: ${moduleName} - end`);
|
84
|
+
return { plugin, options };
|
85
|
+
}
|
86
|
+
exports.loadNxPluginAsync = loadNxPluginAsync;
|
87
|
+
async function loadNxPlugins(plugins, paths = (0, installation_directory_1.getNxRequirePaths)(), root = workspace_root_1.workspaceRoot, projects) {
|
88
|
+
const result = [
|
89
|
+
{ plugin: package_json_next_to_project_json_1.PackageJsonProjectsNextToProjectJsonPlugin },
|
90
|
+
];
|
91
|
+
plugins ??= [];
|
92
|
+
// When loading plugins for `createNodes`, we don't know what projects exist yet.
|
93
|
+
// Try resolving plugins
|
94
|
+
for (const plugin of plugins) {
|
95
|
+
try {
|
96
|
+
require.resolve(typeof plugin === 'string' ? plugin : plugin.plugin);
|
97
|
+
}
|
98
|
+
catch {
|
99
|
+
// If a plugin cannot be resolved, we will need projects to resolve it
|
100
|
+
projects ??= await (0, retrieve_workspace_files_1.retrieveProjectConfigurationsWithoutPluginInference)(root);
|
101
|
+
break;
|
102
|
+
}
|
103
|
+
}
|
104
|
+
for (const plugin of plugins) {
|
105
|
+
result.push(await loadNxPluginAsync(plugin, paths, projects, root));
|
106
|
+
}
|
107
|
+
// We push the nx core node plugins onto the end, s.t. it overwrites any other plugins
|
108
|
+
result.push(...(await getDefaultPlugins(root)));
|
109
|
+
return result;
|
110
|
+
}
|
111
|
+
exports.loadNxPlugins = loadNxPlugins;
|
112
|
+
function ensurePluginIsV2(plugin) {
|
113
|
+
if (isNxPluginV2(plugin)) {
|
114
|
+
return plugin;
|
115
|
+
}
|
116
|
+
if (isNxPluginV1(plugin) && plugin.projectFilePatterns) {
|
117
|
+
return {
|
118
|
+
...plugin,
|
119
|
+
createNodes: [
|
120
|
+
`*/**/${(0, globs_1.combineGlobPatterns)(plugin.projectFilePatterns)}`,
|
121
|
+
(configFilePath) => {
|
122
|
+
const root = (0, path_2.dirname)(configFilePath);
|
123
|
+
return {
|
124
|
+
projects: {
|
125
|
+
[root]: {
|
126
|
+
name: (0, workspaces_1.toProjectName)(configFilePath),
|
127
|
+
root,
|
128
|
+
targets: plugin.registerProjectTargets?.(configFilePath),
|
129
|
+
},
|
130
|
+
},
|
131
|
+
};
|
132
|
+
},
|
133
|
+
],
|
134
|
+
};
|
135
|
+
}
|
136
|
+
return plugin;
|
137
|
+
}
|
138
|
+
exports.ensurePluginIsV2 = ensurePluginIsV2;
|
139
|
+
function isNxPluginV2(plugin) {
|
140
|
+
return 'createNodes' in plugin || 'createDependencies' in plugin;
|
141
|
+
}
|
142
|
+
exports.isNxPluginV2 = isNxPluginV2;
|
143
|
+
function isNxPluginV1(plugin) {
|
144
|
+
return 'processProjectGraph' in plugin || 'projectFilePatterns' in plugin;
|
145
|
+
}
|
146
|
+
exports.isNxPluginV1 = isNxPluginV1;
|
147
|
+
function readPluginPackageJson(pluginName, projects, paths = (0, installation_directory_1.getNxRequirePaths)()) {
|
148
|
+
try {
|
149
|
+
const result = (0, package_json_1.readModulePackageJsonWithoutFallbacks)(pluginName, paths);
|
150
|
+
return {
|
151
|
+
json: result.packageJson,
|
152
|
+
path: result.path,
|
153
|
+
};
|
154
|
+
}
|
155
|
+
catch (e) {
|
156
|
+
if (e.code === 'MODULE_NOT_FOUND') {
|
157
|
+
const nxJson = (0, nx_json_1.readNxJson)();
|
158
|
+
const localPluginPath = resolveLocalNxPlugin(pluginName, nxJson, projects);
|
159
|
+
if (localPluginPath) {
|
160
|
+
const localPluginPackageJson = path.join(localPluginPath.path, 'package.json');
|
161
|
+
return {
|
162
|
+
path: localPluginPackageJson,
|
163
|
+
json: (0, fileutils_1.readJsonFile)(localPluginPackageJson),
|
164
|
+
};
|
165
|
+
}
|
166
|
+
}
|
167
|
+
throw e;
|
168
|
+
}
|
169
|
+
}
|
170
|
+
exports.readPluginPackageJson = readPluginPackageJson;
|
171
|
+
/**
|
172
|
+
* Builds a plugin package and returns the path to output
|
173
|
+
* @param importPath What is the import path that refers to a potential plugin?
|
174
|
+
* @returns The path to the built plugin, or null if it doesn't exist
|
175
|
+
*/
|
176
|
+
const localPluginCache = {};
|
177
|
+
function resolveLocalNxPlugin(importPath, nxJsonConfiguration, projects, root = workspace_root_1.workspaceRoot) {
|
178
|
+
localPluginCache[importPath] ??= lookupLocalPlugin(importPath, nxJsonConfiguration, projects, root);
|
179
|
+
return localPluginCache[importPath];
|
180
|
+
}
|
181
|
+
exports.resolveLocalNxPlugin = resolveLocalNxPlugin;
|
182
|
+
let tsNodeAndPathsUnregisterCallback = undefined;
|
183
|
+
/**
|
184
|
+
* Register swc-node or ts-node if they are not currently registered
|
185
|
+
* with some default settings which work well for Nx plugins.
|
186
|
+
*/
|
187
|
+
function registerPluginTSTranspiler() {
|
188
|
+
if (!tsNodeAndPathsUnregisterCallback) {
|
189
|
+
// nx-ignore-next-line
|
190
|
+
const ts = require('typescript');
|
191
|
+
// Get the first tsconfig that matches the allowed set
|
192
|
+
const tsConfigName = [
|
193
|
+
(0, path_2.join)(workspace_root_1.workspaceRoot, 'tsconfig.base.json'),
|
194
|
+
(0, path_2.join)(workspace_root_1.workspaceRoot, 'tsconfig.json'),
|
195
|
+
].find((x) => (0, fs_1.existsSync)(x));
|
196
|
+
const tsConfig = tsConfigName
|
197
|
+
? (0, typescript_1.readTsConfig)(tsConfigName)
|
198
|
+
: {};
|
199
|
+
const unregisterTsConfigPaths = (0, register_1.registerTsConfigPaths)(tsConfigName);
|
200
|
+
const unregisterTranspiler = (0, register_1.registerTranspiler)({
|
201
|
+
experimentalDecorators: true,
|
202
|
+
emitDecoratorMetadata: true,
|
203
|
+
...tsConfig.options,
|
204
|
+
});
|
205
|
+
tsNodeAndPathsUnregisterCallback = () => {
|
206
|
+
unregisterTsConfigPaths();
|
207
|
+
unregisterTranspiler();
|
208
|
+
};
|
209
|
+
}
|
210
|
+
}
|
211
|
+
exports.registerPluginTSTranspiler = registerPluginTSTranspiler;
|
212
|
+
/**
|
213
|
+
* Unregister the ts-node transpiler if it is registered
|
214
|
+
*/
|
215
|
+
function unregisterPluginTSTranspiler() {
|
216
|
+
if (tsNodeAndPathsUnregisterCallback) {
|
217
|
+
tsNodeAndPathsUnregisterCallback();
|
218
|
+
tsNodeAndPathsUnregisterCallback = undefined;
|
219
|
+
}
|
220
|
+
}
|
221
|
+
exports.unregisterPluginTSTranspiler = unregisterPluginTSTranspiler;
|
222
|
+
function lookupLocalPlugin(importPath, nxJsonConfiguration, projects, root = workspace_root_1.workspaceRoot) {
|
223
|
+
const plugin = findNxProjectForImportPath(importPath, projects, root);
|
224
|
+
if (!plugin) {
|
225
|
+
return null;
|
226
|
+
}
|
227
|
+
if (!tsNodeAndPathsUnregisterCallback) {
|
228
|
+
registerPluginTSTranspiler();
|
229
|
+
}
|
230
|
+
const projectConfig = projects[plugin];
|
231
|
+
return { path: path.join(root, projectConfig.root), projectConfig };
|
232
|
+
}
|
233
|
+
function findNxProjectForImportPath(importPath, projects, root = workspace_root_1.workspaceRoot) {
|
234
|
+
const tsConfigPaths = readTsConfigPaths(root);
|
235
|
+
const possiblePaths = tsConfigPaths[importPath]?.map((p) => (0, path_1.normalizePath)(path.relative(root, path.join(root, p))));
|
236
|
+
if (possiblePaths?.length) {
|
237
|
+
const projectRootMappings = (0, find_project_for_path_1.createProjectRootMappingsFromProjectConfigurations)(projects);
|
238
|
+
for (const tsConfigPath of possiblePaths) {
|
239
|
+
const nxProject = (0, find_project_for_path_1.findProjectForPath)(tsConfigPath, projectRootMappings);
|
240
|
+
if (nxProject) {
|
241
|
+
return nxProject;
|
242
|
+
}
|
243
|
+
}
|
244
|
+
if (process.env.NX_VERBOSE_LOGGING) {
|
245
|
+
console.log('Unable to find local plugin', possiblePaths, projectRootMappings);
|
246
|
+
}
|
247
|
+
throw new Error('Unable to resolve local plugin with import path ' + importPath);
|
248
|
+
}
|
249
|
+
}
|
250
|
+
let tsconfigPaths;
|
251
|
+
function readTsConfigPaths(root = workspace_root_1.workspaceRoot) {
|
252
|
+
if (!tsconfigPaths) {
|
253
|
+
const tsconfigPath = ['tsconfig.base.json', 'tsconfig.json']
|
254
|
+
.map((x) => path.join(root, x))
|
255
|
+
.filter((x) => (0, fs_1.existsSync)(x))[0];
|
256
|
+
if (!tsconfigPath) {
|
257
|
+
throw new Error('unable to find tsconfig.base.json or tsconfig.json');
|
258
|
+
}
|
259
|
+
const { compilerOptions } = (0, fileutils_1.readJsonFile)(tsconfigPath);
|
260
|
+
tsconfigPaths = compilerOptions?.paths;
|
261
|
+
}
|
262
|
+
return tsconfigPaths ?? {};
|
263
|
+
}
|
264
|
+
function readPluginMainFromProjectConfiguration(plugin) {
|
265
|
+
const { main } = Object.values(plugin.targets).find((x) => [
|
266
|
+
'@nx/js:tsc',
|
267
|
+
'@nrwl/js:tsc',
|
268
|
+
'@nx/js:swc',
|
269
|
+
'@nrwl/js:swc',
|
270
|
+
'@nx/node:package',
|
271
|
+
'@nrwl/node:package',
|
272
|
+
].includes(x.executor))?.options ||
|
273
|
+
plugin.targets?.build?.options ||
|
274
|
+
{};
|
275
|
+
return main;
|
276
|
+
}
|
277
|
+
async function getDefaultPlugins(root) {
|
278
|
+
const plugins = [
|
279
|
+
await Promise.resolve().then(() => require('../plugins/js')),
|
280
|
+
target_defaults_plugin_1.TargetDefaultsPlugin,
|
281
|
+
...((0, angular_json_1.shouldMergeAngularProjects)(root, false)
|
282
|
+
? [
|
283
|
+
await Promise.resolve().then(() => require('../adapter/angular-json')).then((m) => m.NxAngularJsonPlugin),
|
284
|
+
]
|
285
|
+
: []),
|
286
|
+
(0, package_json_workspaces_1.getNxPackageJsonWorkspacesPlugin)(root),
|
287
|
+
project_json_1.ProjectJsonProjectsPlugin,
|
288
|
+
];
|
289
|
+
return plugins.map((p) => ({
|
290
|
+
plugin: p,
|
291
|
+
}));
|
292
|
+
}
|
293
|
+
exports.getDefaultPlugins = getDefaultPlugins;
|
package/src/utils/output.js
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
import { ProjectConfiguration } from '../../config/workspace-json-project-json';
|
2
1
|
import type { PluginCapabilities } from './models';
|
2
|
+
import { ProjectConfiguration } from '../../config/workspace-json-project-json';
|
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>;
|
@@ -1,16 +1,15 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.listPluginCapabilities = exports.getPluginCapabilities = void 0;
|
4
|
+
const workspace_root_1 = require("../workspace-root");
|
4
5
|
const chalk = require("chalk");
|
5
6
|
const path_1 = require("path");
|
6
|
-
const plugins_1 = require("../../project-graph/plugins");
|
7
|
-
const internal_api_1 = require("../../project-graph/plugins/internal-api");
|
8
|
-
const fileutils_1 = require("../fileutils");
|
9
|
-
const installation_directory_1 = require("../installation-directory");
|
10
7
|
const output_1 = require("../output");
|
11
|
-
const package_manager_1 = require("../package-manager");
|
12
|
-
const workspace_root_1 = require("../workspace-root");
|
13
8
|
const shared_1 = require("./shared");
|
9
|
+
const fileutils_1 = require("../fileutils");
|
10
|
+
const package_manager_1 = require("../package-manager");
|
11
|
+
const nx_plugin_1 = require("../nx-plugin");
|
12
|
+
const installation_directory_1 = require("../installation-directory");
|
14
13
|
function tryGetCollection(packageJsonPath, collectionFile, propName) {
|
15
14
|
if (!collectionFile) {
|
16
15
|
return null;
|
@@ -25,9 +24,9 @@ function tryGetCollection(packageJsonPath, collectionFile, propName) {
|
|
25
24
|
}
|
26
25
|
async function getPluginCapabilities(workspaceRoot, pluginName, projects, includeRuntimeCapabilities = false) {
|
27
26
|
try {
|
28
|
-
const { json: packageJson, path: packageJsonPath } = await (0,
|
27
|
+
const { json: packageJson, path: packageJsonPath } = await (0, nx_plugin_1.readPluginPackageJson)(pluginName, projects, (0, installation_directory_1.getNxRequirePaths)(workspaceRoot));
|
29
28
|
const pluginModule = includeRuntimeCapabilities
|
30
|
-
? await tryGetModule(packageJson, workspaceRoot)
|
29
|
+
? await tryGetModule(packageJson, workspaceRoot, projects)
|
31
30
|
: {};
|
32
31
|
return {
|
33
32
|
name: pluginName,
|
@@ -57,14 +56,14 @@ async function getPluginCapabilities(workspaceRoot, pluginName, projects, includ
|
|
57
56
|
}
|
58
57
|
}
|
59
58
|
exports.getPluginCapabilities = getPluginCapabilities;
|
60
|
-
async function tryGetModule(packageJson, workspaceRoot) {
|
59
|
+
async function tryGetModule(packageJson, workspaceRoot, projects) {
|
61
60
|
try {
|
62
61
|
return (packageJson.generators ??
|
63
62
|
packageJson.executors ??
|
64
63
|
packageJson['nx-migrations'] ??
|
65
64
|
packageJson['schematics'] ??
|
66
65
|
packageJson['builders'])
|
67
|
-
? (await (0,
|
66
|
+
? (await (0, nx_plugin_1.loadNxPluginAsync)(packageJson.name, (0, installation_directory_1.getNxRequirePaths)(workspaceRoot), projects, workspaceRoot)).plugin
|
68
67
|
: {
|
69
68
|
name: packageJson.name,
|
70
69
|
};
|
@@ -1,22 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.cleanupPlugins = exports.getPlugins = void 0;
|
4
|
-
const nx_json_1 = require("../../config/nx-json");
|
5
|
-
const internal_api_1 = require("../../project-graph/plugins/internal-api");
|
6
|
-
const workspace_root_1 = require("../../utils/workspace-root");
|
7
|
-
let loadedPlugins;
|
8
|
-
let cleanup;
|
9
|
-
async function getPlugins() {
|
10
|
-
if (loadedPlugins) {
|
11
|
-
return loadedPlugins;
|
12
|
-
}
|
13
|
-
const pluginsConfiguration = (0, nx_json_1.readNxJson)().plugins ?? [];
|
14
|
-
const [result, cleanupFn] = await (0, internal_api_1.loadNxPluginsInIsolation)(pluginsConfiguration, workspace_root_1.workspaceRoot);
|
15
|
-
cleanup = cleanupFn;
|
16
|
-
return result;
|
17
|
-
}
|
18
|
-
exports.getPlugins = getPlugins;
|
19
|
-
function cleanupPlugins() {
|
20
|
-
cleanup();
|
21
|
-
}
|
22
|
-
exports.cleanupPlugins = cleanupPlugins;
|
@@ -1,8 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.registerPluginTSTranspiler = exports.readPluginPackageJson = void 0;
|
4
|
-
const tslib_1 = require("tslib");
|
5
|
-
tslib_1.__exportStar(require("./public-api"), exports);
|
6
|
-
var worker_api_1 = require("./worker-api");
|
7
|
-
Object.defineProperty(exports, "readPluginPackageJson", { enumerable: true, get: function () { return worker_api_1.readPluginPackageJson; } });
|
8
|
-
Object.defineProperty(exports, "registerPluginTSTranspiler", { enumerable: true, get: function () { return worker_api_1.registerPluginTSTranspiler; } });
|
@@ -1,22 +0,0 @@
|
|
1
|
-
import { PluginConfiguration } from '../../config/nx-json';
|
2
|
-
import { NxPluginV1 } from '../../utils/nx-plugin.deprecated';
|
3
|
-
import { CreateNodesContext, CreateNodesResult, NxPluginV2 } from './public-api';
|
4
|
-
export { loadPlugins, loadPlugin } from './worker-api';
|
5
|
-
export type CreateNodesResultWithContext = CreateNodesResult & {
|
6
|
-
file: string;
|
7
|
-
pluginName: string;
|
8
|
-
};
|
9
|
-
export type NormalizedPlugin = NxPluginV2 & Pick<NxPluginV1, 'processProjectGraph'>;
|
10
|
-
export type RemotePlugin = Omit<NormalizedPlugin, 'createNodes'> & {
|
11
|
-
createNodes: [
|
12
|
-
filePattern: string,
|
13
|
-
fn: (matchedFiles: string[], context: CreateNodesContext) => Promise<CreateNodesResultWithContext[]>
|
14
|
-
];
|
15
|
-
};
|
16
|
-
export declare const nxPluginCache: Map<unknown, [Promise<RemotePlugin>, () => void]>;
|
17
|
-
/**
|
18
|
-
* This loads plugins in isolation in their own worker so that they do not disturb other workers or the main process.
|
19
|
-
*/
|
20
|
-
export declare function loadNxPluginsInIsolation(plugins: PluginConfiguration[], root?: string): Promise<[RemotePlugin[], () => void]>;
|
21
|
-
export declare function loadNxPluginInIsolation(plugin: PluginConfiguration, root?: string): [Promise<RemotePlugin>, () => void];
|
22
|
-
export declare function getDefaultPlugins(root: string): Promise<string[]>;
|