nx 18.1.0-canary.20240309-235ca8c → 18.1.0-canary.20240312-9520aa2
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/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/utils/convert-nx-executor.js +1 -4
- 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/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/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/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,189 +0,0 @@
|
|
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
|
-
? (opts, 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
|
-
}
|
@@ -1 +0,0 @@
|
|
1
|
-
export {};
|
@@ -1,101 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
const messaging_1 = require("./messaging");
|
4
|
-
const utils_1 = require("./utils");
|
5
|
-
const worker_api_1 = require("./worker-api");
|
6
|
-
global.NX_GRAPH_CREATION = true;
|
7
|
-
let plugin;
|
8
|
-
let pluginOptions;
|
9
|
-
process.on('message', async (message) => {
|
10
|
-
(0, messaging_1.consumeMessage)(message, {
|
11
|
-
load: async ({ plugin: pluginConfiguration, root }) => {
|
12
|
-
process.chdir(root);
|
13
|
-
try {
|
14
|
-
({ plugin, options: pluginOptions } = await (0, worker_api_1.loadPlugin)(pluginConfiguration, root));
|
15
|
-
return {
|
16
|
-
type: 'load-result',
|
17
|
-
payload: {
|
18
|
-
name: plugin.name,
|
19
|
-
createNodesPattern: plugin.createNodes?.[0],
|
20
|
-
hasCreateDependencies: 'createDependencies' in plugin && !!plugin.createDependencies,
|
21
|
-
hasProcessProjectGraph: 'processProjectGraph' in plugin && !!plugin.processProjectGraph,
|
22
|
-
success: true,
|
23
|
-
},
|
24
|
-
};
|
25
|
-
}
|
26
|
-
catch (e) {
|
27
|
-
return {
|
28
|
-
type: 'load-result',
|
29
|
-
payload: {
|
30
|
-
success: false,
|
31
|
-
error: `Could not load plugin ${plugin} \n ${e instanceof Error ? e.stack : ''}`,
|
32
|
-
},
|
33
|
-
};
|
34
|
-
}
|
35
|
-
},
|
36
|
-
createNodes: async ({ configFiles, context, tx }) => {
|
37
|
-
try {
|
38
|
-
const result = await runCreateNodesInParallel(configFiles, context);
|
39
|
-
return {
|
40
|
-
type: 'createNodesResult',
|
41
|
-
payload: { result, success: true, tx },
|
42
|
-
};
|
43
|
-
}
|
44
|
-
catch (e) {
|
45
|
-
return {
|
46
|
-
type: 'createNodesResult',
|
47
|
-
payload: { success: false, error: e.stack, tx },
|
48
|
-
};
|
49
|
-
}
|
50
|
-
},
|
51
|
-
createDependencies: async ({ context, tx }) => {
|
52
|
-
try {
|
53
|
-
const result = await plugin.createDependencies(pluginOptions, context);
|
54
|
-
return {
|
55
|
-
type: 'createDependenciesResult',
|
56
|
-
payload: { dependencies: result, success: true, tx },
|
57
|
-
};
|
58
|
-
}
|
59
|
-
catch (e) {
|
60
|
-
return {
|
61
|
-
type: 'createDependenciesResult',
|
62
|
-
payload: { success: false, error: e.stack, tx },
|
63
|
-
};
|
64
|
-
}
|
65
|
-
},
|
66
|
-
processProjectGraph: async ({ graph, ctx, tx }) => {
|
67
|
-
try {
|
68
|
-
const result = await plugin.processProjectGraph(graph, ctx);
|
69
|
-
return {
|
70
|
-
type: 'processProjectGraphResult',
|
71
|
-
payload: { graph: result, success: true, tx },
|
72
|
-
};
|
73
|
-
}
|
74
|
-
catch (e) {
|
75
|
-
return {
|
76
|
-
type: 'processProjectGraphResult',
|
77
|
-
payload: { success: false, error: e.stack, tx },
|
78
|
-
};
|
79
|
-
}
|
80
|
-
},
|
81
|
-
});
|
82
|
-
});
|
83
|
-
function runCreateNodesInParallel(configFiles, context) {
|
84
|
-
const promises = configFiles.map((file) => {
|
85
|
-
performance.mark(`${plugin.name}:createNodes:${file} - start`);
|
86
|
-
// Result is either static or a promise, using Promise.resolve lets us
|
87
|
-
// handle both cases with same logic
|
88
|
-
const value = Promise.resolve(plugin.createNodes[1](file, pluginOptions, context));
|
89
|
-
return value
|
90
|
-
.catch((e) => {
|
91
|
-
performance.mark(`${plugin.name}:createNodes:${file} - end`);
|
92
|
-
throw new utils_1.CreateNodesError(`Unable to create nodes for ${file} using plugin ${plugin.name}.`, e);
|
93
|
-
})
|
94
|
-
.then((r) => {
|
95
|
-
performance.mark(`${plugin.name}:createNodes:${file} - end`);
|
96
|
-
performance.measure(`${plugin.name}:createNodes:${file}`, `${plugin.name}:createNodes:${file} - start`, `${plugin.name}:createNodes:${file} - end`);
|
97
|
-
return { ...r, pluginName: plugin.name, file };
|
98
|
-
});
|
99
|
-
});
|
100
|
-
return Promise.all(promises);
|
101
|
-
}
|
@@ -1,9 +0,0 @@
|
|
1
|
-
import type { NxPluginV1 } from '../../utils/nx-plugin.deprecated';
|
2
|
-
import type { NormalizedPlugin, RemotePlugin } from './internal-api';
|
3
|
-
import type { NxPlugin, NxPluginV2 } from './public-api';
|
4
|
-
export declare function isNxPluginV2(plugin: NxPlugin): plugin is NxPluginV2;
|
5
|
-
export declare function isNxPluginV1(plugin: NxPlugin | RemotePlugin): plugin is NxPluginV1;
|
6
|
-
export declare function normalizeNxPlugin(plugin: NxPlugin): NormalizedPlugin;
|
7
|
-
export declare class CreateNodesError extends Error {
|
8
|
-
constructor(msg: any, cause: Error | unknown);
|
9
|
-
}
|
@@ -1,55 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.CreateNodesError = exports.normalizeNxPlugin = exports.isNxPluginV1 = exports.isNxPluginV2 = void 0;
|
4
|
-
const node_path_1 = require("node:path");
|
5
|
-
const workspaces_1 = require("../../config/workspaces");
|
6
|
-
const globs_1 = require("../../utils/globs");
|
7
|
-
function isNxPluginV2(plugin) {
|
8
|
-
return 'createNodes' in plugin || 'createDependencies' in plugin;
|
9
|
-
}
|
10
|
-
exports.isNxPluginV2 = isNxPluginV2;
|
11
|
-
function isNxPluginV1(plugin) {
|
12
|
-
return 'processProjectGraph' in plugin || 'projectFilePatterns' in plugin;
|
13
|
-
}
|
14
|
-
exports.isNxPluginV1 = isNxPluginV1;
|
15
|
-
function normalizeNxPlugin(plugin) {
|
16
|
-
if (isNxPluginV2(plugin)) {
|
17
|
-
return plugin;
|
18
|
-
}
|
19
|
-
if (isNxPluginV1(plugin) && plugin.projectFilePatterns) {
|
20
|
-
return {
|
21
|
-
...plugin,
|
22
|
-
createNodes: [
|
23
|
-
`*/**/${(0, globs_1.combineGlobPatterns)(plugin.projectFilePatterns)}`,
|
24
|
-
(configFilePath) => {
|
25
|
-
const root = (0, node_path_1.dirname)(configFilePath);
|
26
|
-
return {
|
27
|
-
projects: {
|
28
|
-
[root]: {
|
29
|
-
name: (0, workspaces_1.toProjectName)(configFilePath),
|
30
|
-
targets: plugin.registerProjectTargets?.(configFilePath),
|
31
|
-
},
|
32
|
-
},
|
33
|
-
};
|
34
|
-
},
|
35
|
-
],
|
36
|
-
};
|
37
|
-
}
|
38
|
-
return plugin;
|
39
|
-
}
|
40
|
-
exports.normalizeNxPlugin = normalizeNxPlugin;
|
41
|
-
class CreateNodesError extends Error {
|
42
|
-
constructor(msg, cause) {
|
43
|
-
const message = `${msg} ${!cause
|
44
|
-
? ''
|
45
|
-
: cause instanceof Error
|
46
|
-
? `\n\n\t Inner Error: ${cause.stack}`
|
47
|
-
: cause}`;
|
48
|
-
// These errors are thrown during a JS callback which is invoked via rust.
|
49
|
-
// The errors messaging gets lost in the rust -> js -> rust transition, but
|
50
|
-
// logging the error here will ensure that it is visible in the console.
|
51
|
-
console.error(message);
|
52
|
-
super(message, { cause });
|
53
|
-
}
|
54
|
-
}
|
55
|
-
exports.CreateNodesError = CreateNodesError;
|
@@ -1,28 +0,0 @@
|
|
1
|
-
import { ProjectConfiguration } from '../../config/workspace-json-project-json';
|
2
|
-
import { PackageJson } from '../../utils/package-json';
|
3
|
-
import { NxPlugin } from './public-api';
|
4
|
-
import { PluginConfiguration } from '../../config/nx-json';
|
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
|
-
/**
|
14
|
-
* Register swc-node or ts-node if they are not currently registered
|
15
|
-
* with some default settings which work well for Nx plugins.
|
16
|
-
*/
|
17
|
-
export declare function registerPluginTSTranspiler(): void;
|
18
|
-
export declare function getPluginPathAndName(moduleName: string, paths: string[], projects: Record<string, ProjectConfiguration>, root: string): {
|
19
|
-
pluginPath: string;
|
20
|
-
name: any;
|
21
|
-
};
|
22
|
-
export declare function loadPlugins(plugins: PluginConfiguration[], root: string): Promise<LoadedNxPlugin[]>;
|
23
|
-
export declare function loadPlugin(plugin: PluginConfiguration, root: string): Promise<LoadedNxPlugin>;
|
24
|
-
export type LoadedNxPlugin = {
|
25
|
-
plugin: NxPlugin;
|
26
|
-
options?: unknown;
|
27
|
-
};
|
28
|
-
export declare function loadNxPluginAsync(pluginConfiguration: PluginConfiguration, paths: string[], projects: Record<string, ProjectConfiguration>, root: string): Promise<LoadedNxPlugin>;
|
@@ -1,195 +0,0 @@
|
|
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.loadPlugin = exports.loadPlugins = exports.getPluginPathAndName = exports.registerPluginTSTranspiler = 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
|
-
function readPluginPackageJson(pluginName, projects, paths = (0, installation_directory_1.getNxRequirePaths)()) {
|
21
|
-
try {
|
22
|
-
const result = (0, package_json_1.readModulePackageJsonWithoutFallbacks)(pluginName, paths);
|
23
|
-
return {
|
24
|
-
json: result.packageJson,
|
25
|
-
path: result.path,
|
26
|
-
};
|
27
|
-
}
|
28
|
-
catch (e) {
|
29
|
-
if (e.code === 'MODULE_NOT_FOUND') {
|
30
|
-
const localPluginPath = resolveLocalNxPlugin(pluginName, projects);
|
31
|
-
if (localPluginPath) {
|
32
|
-
const localPluginPackageJson = path.join(localPluginPath.path, 'package.json');
|
33
|
-
return {
|
34
|
-
path: localPluginPackageJson,
|
35
|
-
json: (0, fileutils_1.readJsonFile)(localPluginPackageJson),
|
36
|
-
};
|
37
|
-
}
|
38
|
-
}
|
39
|
-
throw e;
|
40
|
-
}
|
41
|
-
}
|
42
|
-
exports.readPluginPackageJson = readPluginPackageJson;
|
43
|
-
function resolveLocalNxPlugin(importPath, projects, root = workspace_root_1.workspaceRoot) {
|
44
|
-
return lookupLocalPlugin(importPath, projects, root);
|
45
|
-
}
|
46
|
-
exports.resolveLocalNxPlugin = resolveLocalNxPlugin;
|
47
|
-
/**
|
48
|
-
* Register swc-node or ts-node if they are not currently registered
|
49
|
-
* with some default settings which work well for Nx plugins.
|
50
|
-
*/
|
51
|
-
function registerPluginTSTranspiler() {
|
52
|
-
// Get the first tsconfig that matches the allowed set
|
53
|
-
const tsConfigName = [
|
54
|
-
(0, posix_1.join)(workspace_root_1.workspaceRoot, 'tsconfig.base.json'),
|
55
|
-
(0, posix_1.join)(workspace_root_1.workspaceRoot, 'tsconfig.json'),
|
56
|
-
].find((x) => (0, node_fs_1.existsSync)(x));
|
57
|
-
const tsConfig = tsConfigName
|
58
|
-
? (0, typescript_1.readTsConfig)(tsConfigName)
|
59
|
-
: {};
|
60
|
-
(0, register_1.registerTsConfigPaths)(tsConfigName);
|
61
|
-
(0, register_1.registerTranspiler)({
|
62
|
-
experimentalDecorators: true,
|
63
|
-
emitDecoratorMetadata: true,
|
64
|
-
...tsConfig.options,
|
65
|
-
});
|
66
|
-
}
|
67
|
-
exports.registerPluginTSTranspiler = registerPluginTSTranspiler;
|
68
|
-
function lookupLocalPlugin(importPath, projects, root = workspace_root_1.workspaceRoot) {
|
69
|
-
const plugin = findNxProjectForImportPath(importPath, projects, root);
|
70
|
-
if (!plugin) {
|
71
|
-
return null;
|
72
|
-
}
|
73
|
-
const projectConfig = projects[plugin];
|
74
|
-
return { path: path.join(root, projectConfig.root), projectConfig };
|
75
|
-
}
|
76
|
-
function findNxProjectForImportPath(importPath, projects, root = workspace_root_1.workspaceRoot) {
|
77
|
-
const tsConfigPaths = readTsConfigPaths(root);
|
78
|
-
const possiblePaths = tsConfigPaths[importPath]?.map((p) => (0, path_1.normalizePath)(path.relative(root, path.join(root, p))));
|
79
|
-
if (possiblePaths?.length) {
|
80
|
-
const projectRootMappings = (0, find_project_for_path_1.createProjectRootMappingsFromProjectConfigurations)(projects);
|
81
|
-
for (const tsConfigPath of possiblePaths) {
|
82
|
-
const nxProject = (0, find_project_for_path_1.findProjectForPath)(tsConfigPath, projectRootMappings);
|
83
|
-
if (nxProject) {
|
84
|
-
return nxProject;
|
85
|
-
}
|
86
|
-
}
|
87
|
-
logger_1.logger.verbose('Unable to find local plugin', possiblePaths, projectRootMappings);
|
88
|
-
throw new Error('Unable to resolve local plugin with import path ' + importPath);
|
89
|
-
}
|
90
|
-
}
|
91
|
-
let tsconfigPaths;
|
92
|
-
function readTsConfigPaths(root = workspace_root_1.workspaceRoot) {
|
93
|
-
if (!tsconfigPaths) {
|
94
|
-
const tsconfigPath = ['tsconfig.base.json', 'tsconfig.json']
|
95
|
-
.map((x) => path.join(root, x))
|
96
|
-
.filter((x) => (0, node_fs_1.existsSync)(x))[0];
|
97
|
-
if (!tsconfigPath) {
|
98
|
-
throw new Error('unable to find tsconfig.base.json or tsconfig.json');
|
99
|
-
}
|
100
|
-
const { compilerOptions } = (0, fileutils_1.readJsonFile)(tsconfigPath);
|
101
|
-
tsconfigPaths = compilerOptions?.paths;
|
102
|
-
}
|
103
|
-
return tsconfigPaths ?? {};
|
104
|
-
}
|
105
|
-
function readPluginMainFromProjectConfiguration(plugin) {
|
106
|
-
const { main } = Object.values(plugin.targets).find((x) => [
|
107
|
-
'@nx/js:tsc',
|
108
|
-
'@nrwl/js:tsc',
|
109
|
-
'@nx/js:swc',
|
110
|
-
'@nrwl/js:swc',
|
111
|
-
'@nx/node:package',
|
112
|
-
'@nrwl/node:package',
|
113
|
-
].includes(x.executor))?.options ||
|
114
|
-
plugin.targets?.build?.options ||
|
115
|
-
{};
|
116
|
-
return main;
|
117
|
-
}
|
118
|
-
function getPluginPathAndName(moduleName, paths, projects, root) {
|
119
|
-
let pluginPath;
|
120
|
-
let registerTSTranspiler = false;
|
121
|
-
try {
|
122
|
-
pluginPath = require.resolve(moduleName, {
|
123
|
-
paths,
|
124
|
-
});
|
125
|
-
const extension = path.extname(pluginPath);
|
126
|
-
registerTSTranspiler = extension === '.ts';
|
127
|
-
}
|
128
|
-
catch (e) {
|
129
|
-
if (e.code === 'MODULE_NOT_FOUND') {
|
130
|
-
const plugin = resolveLocalNxPlugin(moduleName, projects, root);
|
131
|
-
if (plugin) {
|
132
|
-
registerTSTranspiler = true;
|
133
|
-
const main = readPluginMainFromProjectConfiguration(plugin.projectConfig);
|
134
|
-
pluginPath = main ? path.join(root, main) : plugin.path;
|
135
|
-
}
|
136
|
-
else {
|
137
|
-
logger_1.logger.error(`Plugin listed in \`nx.json\` not found: ${moduleName}`);
|
138
|
-
throw e;
|
139
|
-
}
|
140
|
-
}
|
141
|
-
else {
|
142
|
-
throw e;
|
143
|
-
}
|
144
|
-
}
|
145
|
-
const packageJsonPath = path.join(pluginPath, 'package.json');
|
146
|
-
// Register the ts-transpiler if we are pointing to a
|
147
|
-
// plain ts file that's not part of a plugin project
|
148
|
-
if (registerTSTranspiler) {
|
149
|
-
registerPluginTSTranspiler();
|
150
|
-
}
|
151
|
-
const { name } = !['.ts', '.js'].some((x) => (0, node_path_1.extname)(moduleName) === x) && // Not trying to point to a ts or js file
|
152
|
-
(0, node_fs_1.existsSync)(packageJsonPath) // plugin has a package.json
|
153
|
-
? (0, fileutils_1.readJsonFile)(packageJsonPath) // read name from package.json
|
154
|
-
: { name: moduleName };
|
155
|
-
return { pluginPath, name };
|
156
|
-
}
|
157
|
-
exports.getPluginPathAndName = getPluginPathAndName;
|
158
|
-
let projectsWithoutInference;
|
159
|
-
async function loadPlugins(plugins, root) {
|
160
|
-
return await Promise.all(plugins.map((p) => loadPlugin(p, root)));
|
161
|
-
}
|
162
|
-
exports.loadPlugins = loadPlugins;
|
163
|
-
async function loadPlugin(plugin, root) {
|
164
|
-
try {
|
165
|
-
require.resolve(typeof plugin === 'string' ? plugin : plugin.plugin);
|
166
|
-
}
|
167
|
-
catch {
|
168
|
-
// If a plugin cannot be resolved, we will need projects to resolve it
|
169
|
-
projectsWithoutInference ??=
|
170
|
-
await (0, retrieve_workspace_files_1.retrieveProjectConfigurationsWithoutPluginInference)(root);
|
171
|
-
}
|
172
|
-
return await loadNxPluginAsync(plugin, (0, installation_directory_1.getNxRequirePaths)(root), projectsWithoutInference, root);
|
173
|
-
}
|
174
|
-
exports.loadPlugin = loadPlugin;
|
175
|
-
async function loadNxPluginAsync(pluginConfiguration, paths, projects, root) {
|
176
|
-
const { plugin: moduleName, options } = typeof pluginConfiguration === 'object'
|
177
|
-
? pluginConfiguration
|
178
|
-
: { plugin: pluginConfiguration, options: undefined };
|
179
|
-
performance.mark(`Load Nx Plugin: ${moduleName} - start`);
|
180
|
-
let { pluginPath, name } = await getPluginPathAndName(moduleName, paths, projects, root);
|
181
|
-
const plugin = (0, utils_1.normalizeNxPlugin)(await importPluginModule(pluginPath));
|
182
|
-
plugin.name ??= name;
|
183
|
-
performance.mark(`Load Nx Plugin: ${moduleName} - end`);
|
184
|
-
performance.measure(`Load Nx Plugin: ${moduleName}`, `Load Nx Plugin: ${moduleName} - start`, `Load Nx Plugin: ${moduleName} - end`);
|
185
|
-
return { plugin, options };
|
186
|
-
}
|
187
|
-
exports.loadNxPluginAsync = loadNxPluginAsync;
|
188
|
-
async function importPluginModule(pluginPath) {
|
189
|
-
const m = await Promise.resolve(`${pluginPath}`).then(s => require(s));
|
190
|
-
if (m.default &&
|
191
|
-
('createNodes' in m.default || 'createDependencies' in m.default)) {
|
192
|
-
return m.default;
|
193
|
-
}
|
194
|
-
return m;
|
195
|
-
}
|