nx 18.3.0-canary.20240409-32144bb → 18.3.0-canary.20240411-c8f179d
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 +7 -5
- 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/run/executor-utils.js +2 -2
- package/src/config/nx-json.d.ts +2 -1
- package/src/config/schema-utils.js +2 -2
- package/src/daemon/server/plugins.d.ts +3 -0
- package/src/daemon/server/plugins.js +22 -0
- package/src/daemon/server/project-graph-incremental-recomputation.js +10 -9
- package/src/daemon/server/shutdown-utils.js +2 -0
- package/src/devkit-exports.d.ts +3 -2
- package/src/executors/run-commands/run-commands.impl.js +1 -1
- package/src/executors/utils/convert-nx-executor.js +4 -1
- package/src/generators/utils/project-configuration.js +2 -2
- package/src/migrations/update-15-1-0/set-project-names.js +4 -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/symbols.d.ts +17 -0
- package/src/plugins/target-defaults/symbols.js +20 -0
- package/src/plugins/target-defaults/target-defaults-plugin.d.ts +2 -18
- package/src/plugins/target-defaults/target-defaults-plugin.js +5 -20
- package/src/project-graph/affected/locators/project-glob-changes.js +3 -3
- package/src/project-graph/build-project-graph.d.ts +2 -1
- package/src/project-graph/build-project-graph.js +11 -13
- package/src/project-graph/error-types.d.ts +34 -0
- package/src/project-graph/error-types.js +65 -0
- 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 +28 -0
- package/src/project-graph/plugins/internal-api.js +85 -0
- package/src/project-graph/plugins/isolation/index.d.ts +3 -0
- package/src/project-graph/plugins/isolation/index.js +16 -0
- package/src/project-graph/plugins/isolation/messaging.d.ts +94 -0
- package/src/project-graph/plugins/isolation/messaging.js +23 -0
- package/src/project-graph/plugins/isolation/plugin-pool.d.ts +3 -0
- package/src/project-graph/plugins/isolation/plugin-pool.js +189 -0
- package/src/project-graph/plugins/isolation/plugin-worker.d.ts +1 -0
- package/src/project-graph/plugins/isolation/plugin-worker.js +81 -0
- package/src/project-graph/plugins/loader.d.ts +24 -0
- package/src/project-graph/plugins/loader.js +206 -0
- package/src/{utils/nx-plugin.d.ts → project-graph/plugins/public-api.d.ts} +8 -44
- package/src/project-graph/plugins/public-api.js +4 -0
- package/src/project-graph/plugins/utils.d.ts +7 -0
- package/src/project-graph/plugins/utils.js +88 -0
- package/src/project-graph/project-graph-builder.d.ts +1 -1
- package/src/project-graph/project-graph.d.ts +3 -2
- package/src/project-graph/project-graph.js +9 -7
- package/src/project-graph/utils/normalize-project-nodes.d.ts +1 -1
- package/src/project-graph/utils/project-configuration-utils.d.ts +3 -26
- package/src/project-graph/utils/project-configuration-utils.js +29 -97
- package/src/project-graph/utils/retrieve-workspace-files.d.ts +8 -7
- package/src/project-graph/utils/retrieve-workspace-files.js +18 -21
- package/src/utils/logger.d.ts +1 -0
- package/src/utils/logger.js +5 -0
- package/src/utils/nx-plugin.deprecated.d.ts +2 -2
- package/src/utils/nx-plugin.deprecated.js +5 -7
- package/src/utils/plugins/plugin-capabilities.d.ts +1 -1
- package/src/utils/plugins/plugin-capabilities.js +18 -12
- package/src/utils/nx-plugin.js +0 -309
@@ -0,0 +1,189 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.loadRemoteNxPlugin = void 0;
|
4
|
+
const child_process_1 = require("child_process");
|
5
|
+
const path = require("path");
|
6
|
+
// TODO (@AgentEnder): After scoped verbose logging is implemented, re-add verbose logs here.
|
7
|
+
// import { logger } from '../../utils/logger';
|
8
|
+
const internal_api_1 = require("../internal-api");
|
9
|
+
const messaging_1 = require("./messaging");
|
10
|
+
const cleanupFunctions = new Set();
|
11
|
+
const pluginNames = new Map();
|
12
|
+
function loadRemoteNxPlugin(plugin, root) {
|
13
|
+
// this should only really be true when running unit tests within
|
14
|
+
// the Nx repo. We still need to start the worker in this case,
|
15
|
+
// but its typescript.
|
16
|
+
const isWorkerTypescript = path.extname(__filename) === '.ts';
|
17
|
+
const workerPath = path.join(__dirname, 'plugin-worker');
|
18
|
+
const worker = (0, child_process_1.fork)(workerPath, [], {
|
19
|
+
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
|
+
execArgv: [
|
30
|
+
...process.execArgv,
|
31
|
+
// If the worker is typescript, we need to register ts-node
|
32
|
+
...(isWorkerTypescript ? ['-r', 'ts-node/register'] : []),
|
33
|
+
],
|
34
|
+
});
|
35
|
+
worker.send((0, messaging_1.createMessage)({ type: 'load', payload: { plugin, root } }));
|
36
|
+
// logger.verbose(`[plugin-worker] started worker: ${worker.pid}`);
|
37
|
+
const pendingPromises = new Map();
|
38
|
+
const exitHandler = createWorkerExitHandler(worker, pendingPromises);
|
39
|
+
const cleanupFunction = () => {
|
40
|
+
worker.off('exit', exitHandler);
|
41
|
+
shutdownPluginWorker(worker, pendingPromises);
|
42
|
+
};
|
43
|
+
cleanupFunctions.add(cleanupFunction);
|
44
|
+
return [
|
45
|
+
new Promise((res, rej) => {
|
46
|
+
worker.on('message', createWorkerHandler(worker, pendingPromises, res, rej));
|
47
|
+
worker.on('exit', exitHandler);
|
48
|
+
}),
|
49
|
+
() => {
|
50
|
+
cleanupFunction();
|
51
|
+
cleanupFunctions.delete(cleanupFunction);
|
52
|
+
},
|
53
|
+
];
|
54
|
+
}
|
55
|
+
exports.loadRemoteNxPlugin = loadRemoteNxPlugin;
|
56
|
+
async function shutdownPluginWorker(worker, pendingPromises) {
|
57
|
+
// Clears the plugin cache so no refs to the workers are held
|
58
|
+
internal_api_1.nxPluginCache.clear();
|
59
|
+
// logger.verbose(`[plugin-pool] starting worker shutdown`);
|
60
|
+
// Other things may be interacting with the worker.
|
61
|
+
// Wait for all pending promises to be done before killing the worker
|
62
|
+
await Promise.all(Array.from(pendingPromises.values()).map(({ promise }) => promise));
|
63
|
+
worker.kill('SIGINT');
|
64
|
+
}
|
65
|
+
/**
|
66
|
+
* Creates a message handler for the given worker.
|
67
|
+
* @param worker Instance of plugin-worker
|
68
|
+
* @param pending Set of pending promises
|
69
|
+
* @param onload Resolver for RemotePlugin promise
|
70
|
+
* @param onloadError Rejecter for RemotePlugin promise
|
71
|
+
* @returns Function to handle messages from the worker
|
72
|
+
*/
|
73
|
+
function createWorkerHandler(worker, pending, onload, onloadError) {
|
74
|
+
let pluginName;
|
75
|
+
return function (message) {
|
76
|
+
const parsed = JSON.parse(message);
|
77
|
+
// logger.verbose(
|
78
|
+
// `[plugin-pool] received message: ${parsed.type} from ${
|
79
|
+
// pluginName ?? worker.pid
|
80
|
+
// }`
|
81
|
+
// );
|
82
|
+
(0, messaging_1.consumeMessage)(parsed, {
|
83
|
+
'load-result': (result) => {
|
84
|
+
if (result.success) {
|
85
|
+
const { name, createNodesPattern } = result;
|
86
|
+
pluginName = name;
|
87
|
+
pluginNames.set(worker, pluginName);
|
88
|
+
onload({
|
89
|
+
name,
|
90
|
+
createNodes: createNodesPattern
|
91
|
+
? [
|
92
|
+
createNodesPattern,
|
93
|
+
(configFiles, ctx) => {
|
94
|
+
const tx = pluginName + ':createNodes:' + performance.now();
|
95
|
+
return registerPendingPromise(tx, pending, () => {
|
96
|
+
worker.send((0, messaging_1.createMessage)({
|
97
|
+
type: 'createNodes',
|
98
|
+
payload: { configFiles, context: ctx, tx },
|
99
|
+
}));
|
100
|
+
});
|
101
|
+
},
|
102
|
+
]
|
103
|
+
: undefined,
|
104
|
+
createDependencies: result.hasCreateDependencies
|
105
|
+
? (ctx) => {
|
106
|
+
const tx = pluginName + ':createDependencies:' + performance.now();
|
107
|
+
return registerPendingPromise(tx, pending, () => {
|
108
|
+
worker.send((0, messaging_1.createMessage)({
|
109
|
+
type: 'createDependencies',
|
110
|
+
payload: { context: ctx, tx },
|
111
|
+
}));
|
112
|
+
});
|
113
|
+
}
|
114
|
+
: undefined,
|
115
|
+
processProjectGraph: result.hasProcessProjectGraph
|
116
|
+
? (graph, ctx) => {
|
117
|
+
const tx = pluginName + ':processProjectGraph:' + performance.now();
|
118
|
+
return registerPendingPromise(tx, pending, () => {
|
119
|
+
worker.send((0, messaging_1.createMessage)({
|
120
|
+
type: 'processProjectGraph',
|
121
|
+
payload: { graph, ctx, tx },
|
122
|
+
}));
|
123
|
+
});
|
124
|
+
}
|
125
|
+
: undefined,
|
126
|
+
});
|
127
|
+
}
|
128
|
+
else if (result.success === false) {
|
129
|
+
onloadError(result.error);
|
130
|
+
}
|
131
|
+
},
|
132
|
+
createDependenciesResult: ({ tx, ...result }) => {
|
133
|
+
const { resolver, rejector } = pending.get(tx);
|
134
|
+
if (result.success) {
|
135
|
+
resolver(result.dependencies);
|
136
|
+
}
|
137
|
+
else if (result.success === false) {
|
138
|
+
rejector(result.error);
|
139
|
+
}
|
140
|
+
},
|
141
|
+
createNodesResult: ({ tx, ...result }) => {
|
142
|
+
const { resolver, rejector } = pending.get(tx);
|
143
|
+
if (result.success) {
|
144
|
+
resolver(result.result);
|
145
|
+
}
|
146
|
+
else if (result.success === false) {
|
147
|
+
rejector(result.error);
|
148
|
+
}
|
149
|
+
},
|
150
|
+
processProjectGraphResult: ({ tx, ...result }) => {
|
151
|
+
const { resolver, rejector } = pending.get(tx);
|
152
|
+
if (result.success) {
|
153
|
+
resolver(result.graph);
|
154
|
+
}
|
155
|
+
else if (result.success === false) {
|
156
|
+
rejector(result.error);
|
157
|
+
}
|
158
|
+
},
|
159
|
+
});
|
160
|
+
};
|
161
|
+
}
|
162
|
+
function createWorkerExitHandler(worker, pendingPromises) {
|
163
|
+
return () => {
|
164
|
+
for (const [_, pendingPromise] of pendingPromises) {
|
165
|
+
pendingPromise.rejector(new Error(`Plugin worker ${pluginNames.get(worker) ?? worker.pid} exited unexpectedly with code ${worker.exitCode}`));
|
166
|
+
}
|
167
|
+
};
|
168
|
+
}
|
169
|
+
process.on('exit', () => {
|
170
|
+
for (const fn of cleanupFunctions) {
|
171
|
+
fn();
|
172
|
+
}
|
173
|
+
});
|
174
|
+
function registerPendingPromise(tx, pending, callback) {
|
175
|
+
let resolver, rejector;
|
176
|
+
const promise = new Promise((res, rej) => {
|
177
|
+
resolver = res;
|
178
|
+
rejector = rej;
|
179
|
+
callback();
|
180
|
+
}).finally(() => {
|
181
|
+
pending.delete(tx);
|
182
|
+
});
|
183
|
+
pending.set(tx, {
|
184
|
+
promise,
|
185
|
+
resolver,
|
186
|
+
rejector,
|
187
|
+
});
|
188
|
+
return promise;
|
189
|
+
}
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
@@ -0,0 +1,81 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
const messaging_1 = require("./messaging");
|
4
|
+
const loader_1 = require("../loader");
|
5
|
+
global.NX_GRAPH_CREATION = true;
|
6
|
+
let plugin;
|
7
|
+
process.on('message', async (message) => {
|
8
|
+
(0, messaging_1.consumeMessage)(message, {
|
9
|
+
load: async ({ plugin: pluginConfiguration, root }) => {
|
10
|
+
process.chdir(root);
|
11
|
+
try {
|
12
|
+
const [promise] = (0, loader_1.loadNxPlugin)(pluginConfiguration, root);
|
13
|
+
plugin = await promise;
|
14
|
+
return {
|
15
|
+
type: 'load-result',
|
16
|
+
payload: {
|
17
|
+
name: plugin.name,
|
18
|
+
createNodesPattern: plugin.createNodes?.[0],
|
19
|
+
hasCreateDependencies: 'createDependencies' in plugin && !!plugin.createDependencies,
|
20
|
+
hasProcessProjectGraph: 'processProjectGraph' in plugin && !!plugin.processProjectGraph,
|
21
|
+
success: true,
|
22
|
+
},
|
23
|
+
};
|
24
|
+
}
|
25
|
+
catch (e) {
|
26
|
+
return {
|
27
|
+
type: 'load-result',
|
28
|
+
payload: {
|
29
|
+
success: false,
|
30
|
+
error: `Could not load plugin ${plugin} \n ${e instanceof Error ? e.stack : ''}`,
|
31
|
+
},
|
32
|
+
};
|
33
|
+
}
|
34
|
+
},
|
35
|
+
createNodes: async ({ configFiles, context, tx }) => {
|
36
|
+
try {
|
37
|
+
const result = await plugin.createNodes[1](configFiles, context);
|
38
|
+
return {
|
39
|
+
type: 'createNodesResult',
|
40
|
+
payload: { result, success: true, tx },
|
41
|
+
};
|
42
|
+
}
|
43
|
+
catch (e) {
|
44
|
+
return {
|
45
|
+
type: 'createNodesResult',
|
46
|
+
payload: { success: false, error: e.stack, tx },
|
47
|
+
};
|
48
|
+
}
|
49
|
+
},
|
50
|
+
createDependencies: async ({ context, tx }) => {
|
51
|
+
try {
|
52
|
+
const result = await plugin.createDependencies(context);
|
53
|
+
return {
|
54
|
+
type: 'createDependenciesResult',
|
55
|
+
payload: { dependencies: result, success: true, tx },
|
56
|
+
};
|
57
|
+
}
|
58
|
+
catch (e) {
|
59
|
+
return {
|
60
|
+
type: 'createDependenciesResult',
|
61
|
+
payload: { success: false, error: e.stack, tx },
|
62
|
+
};
|
63
|
+
}
|
64
|
+
},
|
65
|
+
processProjectGraph: async ({ graph, ctx, tx }) => {
|
66
|
+
try {
|
67
|
+
const result = await plugin.processProjectGraph(graph, ctx);
|
68
|
+
return {
|
69
|
+
type: 'processProjectGraphResult',
|
70
|
+
payload: { graph: result, success: true, tx },
|
71
|
+
};
|
72
|
+
}
|
73
|
+
catch (e) {
|
74
|
+
return {
|
75
|
+
type: 'processProjectGraphResult',
|
76
|
+
payload: { success: false, error: e.stack, tx },
|
77
|
+
};
|
78
|
+
}
|
79
|
+
},
|
80
|
+
});
|
81
|
+
});
|
@@ -0,0 +1,24 @@
|
|
1
|
+
import { ProjectConfiguration } from '../../config/workspace-json-project-json';
|
2
|
+
import { PackageJson } from '../../utils/package-json';
|
3
|
+
import { PluginConfiguration } from '../../config/nx-json';
|
4
|
+
import { LoadedNxPlugin } from './internal-api';
|
5
|
+
export declare function readPluginPackageJson(pluginName: string, projects: Record<string, ProjectConfiguration>, paths?: string[]): {
|
6
|
+
path: string;
|
7
|
+
json: PackageJson;
|
8
|
+
};
|
9
|
+
export declare function resolveLocalNxPlugin(importPath: string, projects: Record<string, ProjectConfiguration>, root?: string): {
|
10
|
+
path: string;
|
11
|
+
projectConfig: ProjectConfiguration;
|
12
|
+
} | null;
|
13
|
+
export declare let unregisterPluginTSTranspiler: (() => void) | null;
|
14
|
+
/**
|
15
|
+
* Register swc-node or ts-node if they are not currently registered
|
16
|
+
* with some default settings which work well for Nx plugins.
|
17
|
+
*/
|
18
|
+
export declare function registerPluginTSTranspiler(): void;
|
19
|
+
export declare function getPluginPathAndName(moduleName: string, paths: string[], projects: Record<string, ProjectConfiguration>, root: string): {
|
20
|
+
pluginPath: string;
|
21
|
+
name: any;
|
22
|
+
};
|
23
|
+
export declare function loadNxPlugin(plugin: PluginConfiguration, root: string): readonly [Promise<LoadedNxPlugin>, () => void];
|
24
|
+
export declare function loadNxPluginAsync(pluginConfiguration: PluginConfiguration, paths: string[], root: string): Promise<LoadedNxPlugin>;
|
@@ -0,0 +1,206 @@
|
|
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.loadNxPluginAsync = exports.loadNxPlugin = exports.getPluginPathAndName = exports.registerPluginTSTranspiler = exports.unregisterPluginTSTranspiler = exports.resolveLocalNxPlugin = exports.readPluginPackageJson = 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 workspace_root_1 = require("../../utils/workspace-root");
|
10
|
+
const node_fs_1 = require("node:fs");
|
11
|
+
const typescript_1 = require("../../utils/typescript");
|
12
|
+
const register_1 = require("../../plugins/js/utils/register");
|
13
|
+
const find_project_for_path_1 = require("../utils/find-project-for-path");
|
14
|
+
const path_1 = require("../../utils/path");
|
15
|
+
const logger_1 = require("../../utils/logger");
|
16
|
+
const node_path_1 = require("node:path");
|
17
|
+
const path = require("node:path/posix");
|
18
|
+
const retrieve_workspace_files_1 = require("../utils/retrieve-workspace-files");
|
19
|
+
const utils_1 = require("./utils");
|
20
|
+
const internal_api_1 = require("./internal-api");
|
21
|
+
function readPluginPackageJson(pluginName, projects, paths = (0, installation_directory_1.getNxRequirePaths)()) {
|
22
|
+
try {
|
23
|
+
const result = (0, package_json_1.readModulePackageJsonWithoutFallbacks)(pluginName, paths);
|
24
|
+
return {
|
25
|
+
json: result.packageJson,
|
26
|
+
path: result.path,
|
27
|
+
};
|
28
|
+
}
|
29
|
+
catch (e) {
|
30
|
+
if (e.code === 'MODULE_NOT_FOUND') {
|
31
|
+
const localPluginPath = resolveLocalNxPlugin(pluginName, projects);
|
32
|
+
if (localPluginPath) {
|
33
|
+
const localPluginPackageJson = path.join(localPluginPath.path, 'package.json');
|
34
|
+
return {
|
35
|
+
path: localPluginPackageJson,
|
36
|
+
json: (0, fileutils_1.readJsonFile)(localPluginPackageJson),
|
37
|
+
};
|
38
|
+
}
|
39
|
+
}
|
40
|
+
throw e;
|
41
|
+
}
|
42
|
+
}
|
43
|
+
exports.readPluginPackageJson = readPluginPackageJson;
|
44
|
+
function resolveLocalNxPlugin(importPath, projects, root = workspace_root_1.workspaceRoot) {
|
45
|
+
return lookupLocalPlugin(importPath, projects, root);
|
46
|
+
}
|
47
|
+
exports.resolveLocalNxPlugin = resolveLocalNxPlugin;
|
48
|
+
exports.unregisterPluginTSTranspiler = null;
|
49
|
+
/**
|
50
|
+
* Register swc-node or ts-node if they are not currently registered
|
51
|
+
* with some default settings which work well for Nx plugins.
|
52
|
+
*/
|
53
|
+
function registerPluginTSTranspiler() {
|
54
|
+
// Get the first tsconfig that matches the allowed set
|
55
|
+
const tsConfigName = [
|
56
|
+
(0, posix_1.join)(workspace_root_1.workspaceRoot, 'tsconfig.base.json'),
|
57
|
+
(0, posix_1.join)(workspace_root_1.workspaceRoot, 'tsconfig.json'),
|
58
|
+
].find((x) => (0, node_fs_1.existsSync)(x));
|
59
|
+
if (!tsConfigName) {
|
60
|
+
return;
|
61
|
+
}
|
62
|
+
const tsConfig = tsConfigName
|
63
|
+
? (0, typescript_1.readTsConfig)(tsConfigName)
|
64
|
+
: {};
|
65
|
+
const cleanupFns = [
|
66
|
+
(0, register_1.registerTsConfigPaths)(tsConfigName),
|
67
|
+
(0, register_1.registerTranspiler)({
|
68
|
+
experimentalDecorators: true,
|
69
|
+
emitDecoratorMetadata: true,
|
70
|
+
...tsConfig.options,
|
71
|
+
}),
|
72
|
+
];
|
73
|
+
exports.unregisterPluginTSTranspiler = () => {
|
74
|
+
cleanupFns.forEach((fn) => fn?.());
|
75
|
+
};
|
76
|
+
}
|
77
|
+
exports.registerPluginTSTranspiler = registerPluginTSTranspiler;
|
78
|
+
function lookupLocalPlugin(importPath, projects, root = workspace_root_1.workspaceRoot) {
|
79
|
+
const plugin = findNxProjectForImportPath(importPath, projects, root);
|
80
|
+
if (!plugin) {
|
81
|
+
return null;
|
82
|
+
}
|
83
|
+
const projectConfig = projects[plugin];
|
84
|
+
return { path: path.join(root, projectConfig.root), projectConfig };
|
85
|
+
}
|
86
|
+
function findNxProjectForImportPath(importPath, projects, root = workspace_root_1.workspaceRoot) {
|
87
|
+
const tsConfigPaths = readTsConfigPaths(root);
|
88
|
+
const possiblePaths = tsConfigPaths[importPath]?.map((p) => (0, path_1.normalizePath)(path.relative(root, path.join(root, p))));
|
89
|
+
if (possiblePaths?.length) {
|
90
|
+
const projectRootMappings = (0, find_project_for_path_1.createProjectRootMappingsFromProjectConfigurations)(projects);
|
91
|
+
for (const tsConfigPath of possiblePaths) {
|
92
|
+
const nxProject = (0, find_project_for_path_1.findProjectForPath)(tsConfigPath, projectRootMappings);
|
93
|
+
if (nxProject) {
|
94
|
+
return nxProject;
|
95
|
+
}
|
96
|
+
}
|
97
|
+
logger_1.logger.verbose('Unable to find local plugin', possiblePaths, projectRootMappings);
|
98
|
+
throw new Error('Unable to resolve local plugin with import path ' + importPath);
|
99
|
+
}
|
100
|
+
}
|
101
|
+
let tsconfigPaths;
|
102
|
+
function readTsConfigPaths(root = workspace_root_1.workspaceRoot) {
|
103
|
+
if (!tsconfigPaths) {
|
104
|
+
const tsconfigPath = ['tsconfig.base.json', 'tsconfig.json']
|
105
|
+
.map((x) => path.join(root, x))
|
106
|
+
.filter((x) => (0, node_fs_1.existsSync)(x))[0];
|
107
|
+
if (!tsconfigPath) {
|
108
|
+
throw new Error('unable to find tsconfig.base.json or tsconfig.json');
|
109
|
+
}
|
110
|
+
const { compilerOptions } = (0, fileutils_1.readJsonFile)(tsconfigPath);
|
111
|
+
tsconfigPaths = compilerOptions?.paths;
|
112
|
+
}
|
113
|
+
return tsconfigPaths ?? {};
|
114
|
+
}
|
115
|
+
function readPluginMainFromProjectConfiguration(plugin) {
|
116
|
+
const { main } = Object.values(plugin.targets).find((x) => [
|
117
|
+
'@nx/js:tsc',
|
118
|
+
'@nrwl/js:tsc',
|
119
|
+
'@nx/js:swc',
|
120
|
+
'@nrwl/js:swc',
|
121
|
+
'@nx/node:package',
|
122
|
+
'@nrwl/node:package',
|
123
|
+
].includes(x.executor))?.options ||
|
124
|
+
plugin.targets?.build?.options ||
|
125
|
+
{};
|
126
|
+
return main;
|
127
|
+
}
|
128
|
+
function getPluginPathAndName(moduleName, paths, projects, root) {
|
129
|
+
let pluginPath;
|
130
|
+
let registerTSTranspiler = false;
|
131
|
+
try {
|
132
|
+
pluginPath = require.resolve(moduleName, {
|
133
|
+
paths,
|
134
|
+
});
|
135
|
+
const extension = path.extname(pluginPath);
|
136
|
+
registerTSTranspiler = extension === '.ts';
|
137
|
+
}
|
138
|
+
catch (e) {
|
139
|
+
if (e.code === 'MODULE_NOT_FOUND') {
|
140
|
+
const plugin = resolveLocalNxPlugin(moduleName, projects, root);
|
141
|
+
if (plugin) {
|
142
|
+
registerTSTranspiler = true;
|
143
|
+
const main = readPluginMainFromProjectConfiguration(plugin.projectConfig);
|
144
|
+
pluginPath = main ? path.join(root, main) : plugin.path;
|
145
|
+
}
|
146
|
+
else {
|
147
|
+
logger_1.logger.error(`Plugin listed in \`nx.json\` not found: ${moduleName}`);
|
148
|
+
throw e;
|
149
|
+
}
|
150
|
+
}
|
151
|
+
else {
|
152
|
+
throw e;
|
153
|
+
}
|
154
|
+
}
|
155
|
+
const packageJsonPath = path.join(pluginPath, 'package.json');
|
156
|
+
// Register the ts-transpiler if we are pointing to a
|
157
|
+
// plain ts file that's not part of a plugin project
|
158
|
+
if (registerTSTranspiler) {
|
159
|
+
registerPluginTSTranspiler();
|
160
|
+
}
|
161
|
+
const { name } = !['.ts', '.js'].some((x) => (0, node_path_1.extname)(moduleName) === x) && // Not trying to point to a ts or js file
|
162
|
+
(0, node_fs_1.existsSync)(packageJsonPath) // plugin has a package.json
|
163
|
+
? (0, fileutils_1.readJsonFile)(packageJsonPath) // read name from package.json
|
164
|
+
: { name: moduleName };
|
165
|
+
return { pluginPath, name };
|
166
|
+
}
|
167
|
+
exports.getPluginPathAndName = getPluginPathAndName;
|
168
|
+
let projectsWithoutInference;
|
169
|
+
function loadNxPlugin(plugin, root) {
|
170
|
+
return [
|
171
|
+
loadNxPluginAsync(plugin, (0, installation_directory_1.getNxRequirePaths)(root), root),
|
172
|
+
() => { },
|
173
|
+
];
|
174
|
+
}
|
175
|
+
exports.loadNxPlugin = loadNxPlugin;
|
176
|
+
async function loadNxPluginAsync(pluginConfiguration, paths, root) {
|
177
|
+
try {
|
178
|
+
require.resolve(typeof pluginConfiguration === 'string'
|
179
|
+
? pluginConfiguration
|
180
|
+
: pluginConfiguration.plugin);
|
181
|
+
}
|
182
|
+
catch {
|
183
|
+
// If a plugin cannot be resolved, we will need projects to resolve it
|
184
|
+
projectsWithoutInference ??=
|
185
|
+
await (0, retrieve_workspace_files_1.retrieveProjectConfigurationsWithoutPluginInference)(root);
|
186
|
+
}
|
187
|
+
const moduleName = typeof pluginConfiguration === 'string'
|
188
|
+
? pluginConfiguration
|
189
|
+
: pluginConfiguration.plugin;
|
190
|
+
performance.mark(`Load Nx Plugin: ${moduleName} - start`);
|
191
|
+
let { pluginPath, name } = await getPluginPathAndName(moduleName, paths, projectsWithoutInference, root);
|
192
|
+
const plugin = (0, utils_1.normalizeNxPlugin)(await importPluginModule(pluginPath));
|
193
|
+
plugin.name ??= name;
|
194
|
+
performance.mark(`Load Nx Plugin: ${moduleName} - end`);
|
195
|
+
performance.measure(`Load Nx Plugin: ${moduleName}`, `Load Nx Plugin: ${moduleName} - start`, `Load Nx Plugin: ${moduleName} - end`);
|
196
|
+
return new internal_api_1.LoadedNxPlugin(plugin, pluginConfiguration);
|
197
|
+
}
|
198
|
+
exports.loadNxPluginAsync = loadNxPluginAsync;
|
199
|
+
async function importPluginModule(pluginPath) {
|
200
|
+
const m = await Promise.resolve(`${pluginPath}`).then(s => require(s));
|
201
|
+
if (m.default &&
|
202
|
+
('createNodes' in m.default || 'createDependencies' in m.default)) {
|
203
|
+
return m.default;
|
204
|
+
}
|
205
|
+
return m;
|
206
|
+
}
|
@@ -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
|
*/
|
@@ -20,6 +19,7 @@ export interface CreateNodesContext {
|
|
20
19
|
* Used for creating nodes for the {@link ProjectGraph}
|
21
20
|
*/
|
22
21
|
export type CreateNodesFunction<T = unknown> = (projectConfigurationFile: string, options: T | undefined, context: CreateNodesContext) => CreateNodesResult | Promise<CreateNodesResult>;
|
22
|
+
export type Optional<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
|
23
23
|
export interface CreateNodesResult {
|
24
24
|
/**
|
25
25
|
* A map of project root -> project configuration
|
@@ -34,7 +34,7 @@ export interface CreateNodesResult {
|
|
34
34
|
* A pair of file patterns and {@link CreateNodesFunction}
|
35
35
|
*/
|
36
36
|
export type CreateNodes<T = unknown> = readonly [
|
37
|
-
|
37
|
+
projectFilePattern: string,
|
38
38
|
createNodesFunction: CreateNodesFunction<T>
|
39
39
|
];
|
40
40
|
/**
|
@@ -77,49 +77,13 @@ export type NxPluginV2<TOptions = unknown> = {
|
|
77
77
|
* Provides a file pattern and function that retrieves configuration info from
|
78
78
|
* those files. e.g. { '**\/*.csproj': buildProjectsFromCsProjFile }
|
79
79
|
*/
|
80
|
-
createNodes?: CreateNodes
|
80
|
+
createNodes?: CreateNodes<TOptions>;
|
81
81
|
/**
|
82
82
|
* Provides a function to analyze files to create dependencies for the {@link ProjectGraph}
|
83
83
|
*/
|
84
84
|
createDependencies?: CreateDependencies<TOptions>;
|
85
85
|
};
|
86
|
-
export * from './nx-plugin.deprecated';
|
87
86
|
/**
|
88
87
|
* A plugin for Nx
|
89
88
|
*/
|
90
89
|
export type NxPlugin = NxPluginV1 | NxPluginV2;
|
91
|
-
export type LoadedNxPlugin = {
|
92
|
-
plugin: NxPluginV2 & Pick<NxPluginV1, 'processProjectGraph'>;
|
93
|
-
options?: unknown;
|
94
|
-
include?: string[];
|
95
|
-
exclude?: string[];
|
96
|
-
};
|
97
|
-
export declare const nxPluginCache: Map<string, LoadedNxPlugin['plugin']>;
|
98
|
-
export declare function getPluginPathAndName(moduleName: string, paths: string[], projects: Record<string, ProjectConfiguration>, root: string): {
|
99
|
-
pluginPath: string;
|
100
|
-
name: any;
|
101
|
-
};
|
102
|
-
export declare function loadNxPluginAsync(pluginConfiguration: PluginConfiguration, paths: string[], projects: Record<string, ProjectConfiguration>, root: string): Promise<LoadedNxPlugin>;
|
103
|
-
export declare function loadNxPlugins(plugins: PluginConfiguration[], paths?: string[], root?: string, projects?: Record<string, ProjectConfiguration>): Promise<LoadedNxPlugin[]>;
|
104
|
-
export declare function ensurePluginIsV2(plugin: NxPlugin): NxPluginV2;
|
105
|
-
export declare function isNxPluginV2(plugin: NxPlugin): plugin is NxPluginV2;
|
106
|
-
export declare function isNxPluginV1(plugin: NxPlugin): plugin is NxPluginV1;
|
107
|
-
export declare function readPluginPackageJson(pluginName: string, projects: Record<string, ProjectConfiguration>, paths?: string[]): {
|
108
|
-
path: string;
|
109
|
-
json: PackageJson;
|
110
|
-
};
|
111
|
-
export declare function resolveLocalNxPlugin(importPath: string, nxJsonConfiguration: NxJsonConfiguration, projects: Record<string, ProjectConfiguration>, root?: string): {
|
112
|
-
path: string;
|
113
|
-
projectConfig: ProjectConfiguration;
|
114
|
-
} | null;
|
115
|
-
/**
|
116
|
-
* Register swc-node or ts-node if they are not currently registered
|
117
|
-
* with some default settings which work well for Nx plugins.
|
118
|
-
*/
|
119
|
-
export declare function registerPluginTSTranspiler(): void;
|
120
|
-
/**
|
121
|
-
* Unregister the ts-node transpiler if it is registered
|
122
|
-
*/
|
123
|
-
export declare function unregisterPluginTSTranspiler(): void;
|
124
|
-
export declare function getDefaultPlugins(root: string): Promise<LoadedNxPlugin[]>;
|
125
|
-
type Optional<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
|
@@ -0,0 +1,7 @@
|
|
1
|
+
import type { NxPluginV1 } from '../../utils/nx-plugin.deprecated';
|
2
|
+
import type { CreateNodesResultWithContext, LoadedNxPlugin, NormalizedPlugin } from './internal-api';
|
3
|
+
import type { CreateNodesContext, NxPlugin, NxPluginV2 } from './public-api';
|
4
|
+
export declare function isNxPluginV2(plugin: NxPlugin): plugin is NxPluginV2;
|
5
|
+
export declare function isNxPluginV1(plugin: NxPlugin | LoadedNxPlugin): plugin is NxPluginV1;
|
6
|
+
export declare function normalizeNxPlugin(plugin: NxPlugin): NormalizedPlugin;
|
7
|
+
export declare function runCreateNodesInParallel(configFiles: string[], plugin: NormalizedPlugin, options: unknown, context: CreateNodesContext): Promise<CreateNodesResultWithContext[]>;
|