nx 18.1.0-canary.20240308-46592d7 → 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/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 +1 -0
- package/src/devkit-exports.d.ts +1 -2
- package/src/devkit-internals.d.ts +0 -1
- package/src/devkit-internals.js +1 -3
- package/src/generators/utils/project-configuration.js +2 -2
- package/src/migrations/update-15-1-0/set-project-names.js +2 -4
- package/src/migrations/update-17-2-0/move-default-base.d.ts +1 -1
- package/src/migrations/update-17-2-0/move-default-base.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 -2
- package/src/project-graph/build-project-graph.js +8 -11
- 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 +3 -0
- 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 +54 -13
- package/src/project-graph/utils/retrieve-workspace-files.d.ts +4 -8
- package/src/project-graph/utils/retrieve-workspace-files.js +15 -17
- 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 +7 -8
- 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 -18
- package/src/project-graph/plugins/internal-api.js +0 -48
- 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 -4
- package/src/project-graph/plugins/plugin-pool.js +0 -213
- package/src/project-graph/plugins/plugin-worker.d.ts +0 -1
- package/src/project-graph/plugins/plugin-worker.js +0 -115
- 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 -26
- package/src/project-graph/plugins/worker-api.js +0 -177
@@ -1,213 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.shutdownPluginWorkers = 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 pool = new Set();
|
11
|
-
const pidMap = new Map();
|
12
|
-
// transaction id (tx) -> Promise, Resolver, Rejecter
|
13
|
-
// Makes sure that we can resolve the correct promise when the worker sends back the result
|
14
|
-
const promiseBank = new Map();
|
15
|
-
function loadRemoteNxPlugin(plugin, root) {
|
16
|
-
// this should only really be true when running unit tests within
|
17
|
-
// the Nx repo. We still need to start the worker in this case,
|
18
|
-
// but its typescript.
|
19
|
-
const isWorkerTypescript = path.extname(__filename) === '.ts';
|
20
|
-
const workerPath = path.join(__dirname, 'plugin-worker');
|
21
|
-
const worker = (0, child_process_1.fork)(workerPath, [], {
|
22
|
-
stdio: ['ignore', 'inherit', 'inherit', 'ipc'],
|
23
|
-
env: {
|
24
|
-
...process.env,
|
25
|
-
...(isWorkerTypescript
|
26
|
-
? {
|
27
|
-
// Ensures that the worker uses the same tsconfig as the main process
|
28
|
-
TS_NODE_PROJECT: path.join(__dirname, '../../../tsconfig.lib.json'),
|
29
|
-
}
|
30
|
-
: {}),
|
31
|
-
},
|
32
|
-
execArgv: [
|
33
|
-
...process.execArgv,
|
34
|
-
// If the worker is typescript, we need to register ts-node
|
35
|
-
...(isWorkerTypescript ? ['-r', 'ts-node/register'] : []),
|
36
|
-
],
|
37
|
-
});
|
38
|
-
worker.send((0, messaging_1.createMessage)({ type: 'load', payload: { plugin, root } }));
|
39
|
-
pool.add(worker);
|
40
|
-
// logger.verbose(`[plugin-worker] started worker: ${worker.pid}`);
|
41
|
-
return new Promise((res, rej) => {
|
42
|
-
worker.on('message', createWorkerHandler(worker, res, rej));
|
43
|
-
worker.on('exit', createWorkerExitHandler(worker));
|
44
|
-
});
|
45
|
-
}
|
46
|
-
exports.loadRemoteNxPlugin = loadRemoteNxPlugin;
|
47
|
-
let pluginWorkersShutdown = false;
|
48
|
-
async function shutdownPluginWorkers() {
|
49
|
-
// Clears the plugin cache so no refs to the workers are held
|
50
|
-
internal_api_1.nxPluginCache.clear();
|
51
|
-
// Marks the workers as shutdown so that we don't report unexpected exits
|
52
|
-
pluginWorkersShutdown = true;
|
53
|
-
// logger.verbose(`[plugin-pool] starting worker shutdown`);
|
54
|
-
const pending = getPendingPromises(pool, pidMap);
|
55
|
-
for (const pendingPromise of pending) {
|
56
|
-
pendingPromise.rejector(new Error('Shutting down'));
|
57
|
-
}
|
58
|
-
// logger.verbose(`[plugin-pool] all pending operations completed`);
|
59
|
-
for (const childProcess of pool) {
|
60
|
-
childProcess.kill('SIGINT');
|
61
|
-
}
|
62
|
-
// logger.verbose(`[plugin-pool] all workers killed`);
|
63
|
-
}
|
64
|
-
exports.shutdownPluginWorkers = shutdownPluginWorkers;
|
65
|
-
/**
|
66
|
-
* Creates a message handler for the given worker.
|
67
|
-
* @param worker Instance of plugin-worker
|
68
|
-
* @param onload Resolver for RemotePlugin promise
|
69
|
-
* @param onloadError Rejecter for RemotePlugin promise
|
70
|
-
* @returns Function to handle messages from the worker
|
71
|
-
*/
|
72
|
-
function createWorkerHandler(worker, onload, onloadError) {
|
73
|
-
let pluginName;
|
74
|
-
return function (message) {
|
75
|
-
const parsed = JSON.parse(message);
|
76
|
-
// logger.verbose(
|
77
|
-
// `[plugin-pool] received message: ${parsed.type} from ${
|
78
|
-
// pluginName ?? worker.pid
|
79
|
-
// }`
|
80
|
-
// );
|
81
|
-
(0, messaging_1.consumeMessage)(parsed, {
|
82
|
-
'load-result': (result) => {
|
83
|
-
if (result.success) {
|
84
|
-
const { name, createNodesPattern } = result;
|
85
|
-
pluginName = name;
|
86
|
-
const pending = new Set();
|
87
|
-
pidMap.set(worker.pid, { name, pending });
|
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 } = promiseBank.get(tx);
|
134
|
-
if (result.success) {
|
135
|
-
resolver(result.dependencies);
|
136
|
-
}
|
137
|
-
else if (result.success === false) {
|
138
|
-
rejector(result.error);
|
139
|
-
}
|
140
|
-
pidMap.get(worker.pid)?.pending.delete(tx);
|
141
|
-
promiseBank.delete(tx);
|
142
|
-
},
|
143
|
-
createNodesResult: ({ tx, ...result }) => {
|
144
|
-
const { resolver, rejector } = promiseBank.get(tx);
|
145
|
-
if (result.success) {
|
146
|
-
resolver(result.result);
|
147
|
-
}
|
148
|
-
else if (result.success === false) {
|
149
|
-
rejector(result.error);
|
150
|
-
}
|
151
|
-
pidMap.get(worker.pid)?.pending.delete(tx);
|
152
|
-
promiseBank.delete(tx);
|
153
|
-
},
|
154
|
-
processProjectGraphResult: ({ tx, ...result }) => {
|
155
|
-
const { resolver, rejector } = promiseBank.get(tx);
|
156
|
-
if (result.success) {
|
157
|
-
resolver(result.graph);
|
158
|
-
}
|
159
|
-
else if (result.success === false) {
|
160
|
-
rejector(result.error);
|
161
|
-
}
|
162
|
-
pidMap.get(worker.pid)?.pending.delete(tx);
|
163
|
-
promiseBank.delete(tx);
|
164
|
-
},
|
165
|
-
});
|
166
|
-
};
|
167
|
-
}
|
168
|
-
function createWorkerExitHandler(worker) {
|
169
|
-
return () => {
|
170
|
-
if (!pluginWorkersShutdown) {
|
171
|
-
pidMap.get(worker.pid)?.pending.forEach((tx) => {
|
172
|
-
const { rejector } = promiseBank.get(tx);
|
173
|
-
rejector(new Error(`Plugin worker ${pidMap.get(worker.pid).name ?? worker.pid} exited unexpectedly with code ${worker.exitCode}`));
|
174
|
-
});
|
175
|
-
shutdownPluginWorkers();
|
176
|
-
}
|
177
|
-
};
|
178
|
-
}
|
179
|
-
process.on('exit', () => {
|
180
|
-
if (pool.size) {
|
181
|
-
shutdownPluginWorkers();
|
182
|
-
}
|
183
|
-
});
|
184
|
-
function getPendingPromises(pool, pidMap) {
|
185
|
-
const pendingTxs = [];
|
186
|
-
for (const p of pool) {
|
187
|
-
const { pending } = pidMap.get(p.pid) ?? { pending: new Set() };
|
188
|
-
for (const tx of pending) {
|
189
|
-
pendingTxs.push(promiseBank.get(tx));
|
190
|
-
}
|
191
|
-
}
|
192
|
-
return pendingTxs;
|
193
|
-
}
|
194
|
-
function registerPendingPromise(tx, pending, callback) {
|
195
|
-
let resolver, rejector;
|
196
|
-
const promise = new Promise((res, rej) => {
|
197
|
-
resolver = res;
|
198
|
-
rejector = rej;
|
199
|
-
callback();
|
200
|
-
}).then((val) => {
|
201
|
-
// Remove the promise from the pending set
|
202
|
-
pending.delete(tx);
|
203
|
-
// Return the original value
|
204
|
-
return val;
|
205
|
-
});
|
206
|
-
pending.add(tx);
|
207
|
-
promiseBank.set(tx, {
|
208
|
-
promise,
|
209
|
-
resolver,
|
210
|
-
rejector,
|
211
|
-
});
|
212
|
-
return promise;
|
213
|
-
}
|
@@ -1 +0,0 @@
|
|
1
|
-
export {};
|
@@ -1,115 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
const installation_directory_1 = require("../../utils/installation-directory");
|
4
|
-
const worker_api_1 = require("./worker-api");
|
5
|
-
const messaging_1 = require("./messaging");
|
6
|
-
const retrieve_workspace_files_1 = require("../utils/retrieve-workspace-files");
|
7
|
-
const utils_1 = require("./utils");
|
8
|
-
global.NX_GRAPH_CREATION = true;
|
9
|
-
let plugin;
|
10
|
-
let pluginOptions;
|
11
|
-
process.on('message', async (message) => {
|
12
|
-
(0, messaging_1.consumeMessage)(message, {
|
13
|
-
load: async ({ plugin: pluginConfiguration, root }) => {
|
14
|
-
process.chdir(root);
|
15
|
-
try {
|
16
|
-
({ plugin, options: pluginOptions } = await loadPluginFromWorker(pluginConfiguration, root));
|
17
|
-
return {
|
18
|
-
type: 'load-result',
|
19
|
-
payload: {
|
20
|
-
name: plugin.name,
|
21
|
-
createNodesPattern: plugin.createNodes?.[0],
|
22
|
-
hasCreateDependencies: 'createDependencies' in plugin && !!plugin.createDependencies,
|
23
|
-
hasProcessProjectGraph: 'processProjectGraph' in plugin && !!plugin.processProjectGraph,
|
24
|
-
success: true,
|
25
|
-
},
|
26
|
-
};
|
27
|
-
}
|
28
|
-
catch (e) {
|
29
|
-
return {
|
30
|
-
type: 'load-result',
|
31
|
-
payload: {
|
32
|
-
success: false,
|
33
|
-
error: `Could not load plugin ${plugin} \n ${e instanceof Error ? e.stack : ''}`,
|
34
|
-
},
|
35
|
-
};
|
36
|
-
}
|
37
|
-
},
|
38
|
-
createNodes: async ({ configFiles, context, tx }) => {
|
39
|
-
try {
|
40
|
-
const result = await runCreateNodesInParallel(configFiles, context);
|
41
|
-
return {
|
42
|
-
type: 'createNodesResult',
|
43
|
-
payload: { result, success: true, tx },
|
44
|
-
};
|
45
|
-
}
|
46
|
-
catch (e) {
|
47
|
-
return {
|
48
|
-
type: 'createNodesResult',
|
49
|
-
payload: { success: false, error: e.stack, tx },
|
50
|
-
};
|
51
|
-
}
|
52
|
-
},
|
53
|
-
createDependencies: async ({ context, tx }) => {
|
54
|
-
try {
|
55
|
-
const result = await plugin.createDependencies(pluginOptions, context);
|
56
|
-
return {
|
57
|
-
type: 'createDependenciesResult',
|
58
|
-
payload: { dependencies: result, success: true, tx },
|
59
|
-
};
|
60
|
-
}
|
61
|
-
catch (e) {
|
62
|
-
return {
|
63
|
-
type: 'createDependenciesResult',
|
64
|
-
payload: { success: false, error: e.stack, tx },
|
65
|
-
};
|
66
|
-
}
|
67
|
-
},
|
68
|
-
processProjectGraph: async ({ graph, ctx, tx }) => {
|
69
|
-
try {
|
70
|
-
const result = await plugin.processProjectGraph(graph, ctx);
|
71
|
-
return {
|
72
|
-
type: 'processProjectGraphResult',
|
73
|
-
payload: { graph: result, success: true, tx },
|
74
|
-
};
|
75
|
-
}
|
76
|
-
catch (e) {
|
77
|
-
return {
|
78
|
-
type: 'processProjectGraphResult',
|
79
|
-
payload: { success: false, error: e.stack, tx },
|
80
|
-
};
|
81
|
-
}
|
82
|
-
},
|
83
|
-
});
|
84
|
-
});
|
85
|
-
let projectsWithoutInference;
|
86
|
-
async function loadPluginFromWorker(plugin, root) {
|
87
|
-
try {
|
88
|
-
require.resolve(typeof plugin === 'string' ? plugin : plugin.plugin);
|
89
|
-
}
|
90
|
-
catch {
|
91
|
-
// If a plugin cannot be resolved, we will need projects to resolve it
|
92
|
-
projectsWithoutInference ??=
|
93
|
-
await (0, retrieve_workspace_files_1.retrieveProjectConfigurationsWithoutPluginInference)(root);
|
94
|
-
}
|
95
|
-
return await (0, worker_api_1.loadNxPluginAsync)(plugin, (0, installation_directory_1.getNxRequirePaths)(root), projectsWithoutInference, root);
|
96
|
-
}
|
97
|
-
function runCreateNodesInParallel(configFiles, context) {
|
98
|
-
const promises = configFiles.map((file) => {
|
99
|
-
performance.mark(`${plugin.name}:createNodes:${file} - start`);
|
100
|
-
// Result is either static or a promise, using Promise.resolve lets us
|
101
|
-
// handle both cases with same logic
|
102
|
-
const value = Promise.resolve(plugin.createNodes[1](file, pluginOptions, context));
|
103
|
-
return value
|
104
|
-
.catch((e) => {
|
105
|
-
performance.mark(`${plugin.name}:createNodes:${file} - end`);
|
106
|
-
throw new utils_1.CreateNodesError(`Unable to create nodes for ${file} using plugin ${plugin.name}.`, e);
|
107
|
-
})
|
108
|
-
.then((r) => {
|
109
|
-
performance.mark(`${plugin.name}:createNodes:${file} - end`);
|
110
|
-
performance.measure(`${plugin.name}:createNodes:${file}`, `${plugin.name}:createNodes:${file} - start`, `${plugin.name}:createNodes:${file} - end`);
|
111
|
-
return { ...r, pluginName: plugin.name, file };
|
112
|
-
});
|
113
|
-
});
|
114
|
-
return Promise.all(promises);
|
115
|
-
}
|
@@ -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,26 +0,0 @@
|
|
1
|
-
import { ProjectConfiguration } from '../../config/workspace-json-project-json';
|
2
|
-
import { PluginConfiguration } from '../../config/nx-json';
|
3
|
-
import { PackageJson } from '../../utils/package-json';
|
4
|
-
import { NxPlugin } from './public-api';
|
5
|
-
export type LoadedNxPlugin = {
|
6
|
-
plugin: NxPlugin;
|
7
|
-
options?: unknown;
|
8
|
-
};
|
9
|
-
export declare function loadNxPluginAsync(pluginConfiguration: PluginConfiguration, paths: string[], projects: Record<string, ProjectConfiguration>, root: string): Promise<LoadedNxPlugin>;
|
10
|
-
export declare function readPluginPackageJson(pluginName: string, projects: Record<string, ProjectConfiguration>, paths?: string[]): {
|
11
|
-
path: string;
|
12
|
-
json: PackageJson;
|
13
|
-
};
|
14
|
-
export declare function resolveLocalNxPlugin(importPath: string, projects: Record<string, ProjectConfiguration>, root?: string): {
|
15
|
-
path: string;
|
16
|
-
projectConfig: ProjectConfiguration;
|
17
|
-
} | null;
|
18
|
-
/**
|
19
|
-
* Register swc-node or ts-node if they are not currently registered
|
20
|
-
* with some default settings which work well for Nx plugins.
|
21
|
-
*/
|
22
|
-
export declare function registerPluginTSTranspiler(): void;
|
23
|
-
export declare function getPluginPathAndName(moduleName: string, paths: string[], projects: Record<string, ProjectConfiguration>, root: string): {
|
24
|
-
pluginPath: string;
|
25
|
-
name: any;
|
26
|
-
};
|
@@ -1,177 +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.getPluginPathAndName = exports.registerPluginTSTranspiler = exports.resolveLocalNxPlugin = exports.readPluginPackageJson = exports.loadNxPluginAsync = void 0;
|
5
|
-
const posix_1 = require("node:path/posix");
|
6
|
-
const installation_directory_1 = require("../../utils/installation-directory");
|
7
|
-
const package_json_1 = require("../../utils/package-json");
|
8
|
-
const fileutils_1 = require("../../utils/fileutils");
|
9
|
-
const path = require("node:path/posix");
|
10
|
-
const workspace_root_1 = require("../../utils/workspace-root");
|
11
|
-
const node_fs_1 = require("node:fs");
|
12
|
-
const typescript_1 = require("../../utils/typescript");
|
13
|
-
const register_1 = require("../../plugins/js/utils/register");
|
14
|
-
const find_project_for_path_1 = require("../utils/find-project-for-path");
|
15
|
-
const path_1 = require("../../utils/path");
|
16
|
-
const logger_1 = require("../../utils/logger");
|
17
|
-
const node_path_1 = require("node:path");
|
18
|
-
const utils_1 = require("./utils");
|
19
|
-
async function loadNxPluginAsync(pluginConfiguration, paths, projects, root) {
|
20
|
-
const { plugin: moduleName, options } = typeof pluginConfiguration === 'object'
|
21
|
-
? pluginConfiguration
|
22
|
-
: { plugin: pluginConfiguration, options: undefined };
|
23
|
-
performance.mark(`Load Nx Plugin: ${moduleName} - start`);
|
24
|
-
let { pluginPath, name } = await getPluginPathAndName(moduleName, paths, projects, root);
|
25
|
-
const plugin = (0, utils_1.normalizeNxPlugin)(await importPluginModule(pluginPath));
|
26
|
-
plugin.name ??= name;
|
27
|
-
performance.mark(`Load Nx Plugin: ${moduleName} - end`);
|
28
|
-
performance.measure(`Load Nx Plugin: ${moduleName}`, `Load Nx Plugin: ${moduleName} - start`, `Load Nx Plugin: ${moduleName} - end`);
|
29
|
-
return { plugin, options };
|
30
|
-
}
|
31
|
-
exports.loadNxPluginAsync = loadNxPluginAsync;
|
32
|
-
function readPluginPackageJson(pluginName, projects, paths = (0, installation_directory_1.getNxRequirePaths)()) {
|
33
|
-
try {
|
34
|
-
const result = (0, package_json_1.readModulePackageJsonWithoutFallbacks)(pluginName, paths);
|
35
|
-
return {
|
36
|
-
json: result.packageJson,
|
37
|
-
path: result.path,
|
38
|
-
};
|
39
|
-
}
|
40
|
-
catch (e) {
|
41
|
-
if (e.code === 'MODULE_NOT_FOUND') {
|
42
|
-
const localPluginPath = resolveLocalNxPlugin(pluginName, projects);
|
43
|
-
if (localPluginPath) {
|
44
|
-
const localPluginPackageJson = path.join(localPluginPath.path, 'package.json');
|
45
|
-
return {
|
46
|
-
path: localPluginPackageJson,
|
47
|
-
json: (0, fileutils_1.readJsonFile)(localPluginPackageJson),
|
48
|
-
};
|
49
|
-
}
|
50
|
-
}
|
51
|
-
throw e;
|
52
|
-
}
|
53
|
-
}
|
54
|
-
exports.readPluginPackageJson = readPluginPackageJson;
|
55
|
-
function resolveLocalNxPlugin(importPath, projects, root = workspace_root_1.workspaceRoot) {
|
56
|
-
return lookupLocalPlugin(importPath, projects, root);
|
57
|
-
}
|
58
|
-
exports.resolveLocalNxPlugin = resolveLocalNxPlugin;
|
59
|
-
/**
|
60
|
-
* Register swc-node or ts-node if they are not currently registered
|
61
|
-
* with some default settings which work well for Nx plugins.
|
62
|
-
*/
|
63
|
-
function registerPluginTSTranspiler() {
|
64
|
-
// Get the first tsconfig that matches the allowed set
|
65
|
-
const tsConfigName = [
|
66
|
-
(0, posix_1.join)(workspace_root_1.workspaceRoot, 'tsconfig.base.json'),
|
67
|
-
(0, posix_1.join)(workspace_root_1.workspaceRoot, 'tsconfig.json'),
|
68
|
-
].find((x) => (0, node_fs_1.existsSync)(x));
|
69
|
-
const tsConfig = tsConfigName
|
70
|
-
? (0, typescript_1.readTsConfig)(tsConfigName)
|
71
|
-
: {};
|
72
|
-
(0, register_1.registerTsConfigPaths)(tsConfigName);
|
73
|
-
(0, register_1.registerTranspiler)({
|
74
|
-
experimentalDecorators: true,
|
75
|
-
emitDecoratorMetadata: true,
|
76
|
-
...tsConfig.options,
|
77
|
-
});
|
78
|
-
}
|
79
|
-
exports.registerPluginTSTranspiler = registerPluginTSTranspiler;
|
80
|
-
function lookupLocalPlugin(importPath, projects, root = workspace_root_1.workspaceRoot) {
|
81
|
-
const plugin = findNxProjectForImportPath(importPath, projects, root);
|
82
|
-
if (!plugin) {
|
83
|
-
return null;
|
84
|
-
}
|
85
|
-
const projectConfig = projects[plugin];
|
86
|
-
return { path: path.join(root, projectConfig.root), projectConfig };
|
87
|
-
}
|
88
|
-
function findNxProjectForImportPath(importPath, projects, root = workspace_root_1.workspaceRoot) {
|
89
|
-
const tsConfigPaths = readTsConfigPaths(root);
|
90
|
-
const possiblePaths = tsConfigPaths[importPath]?.map((p) => (0, path_1.normalizePath)(path.relative(root, path.join(root, p))));
|
91
|
-
if (possiblePaths?.length) {
|
92
|
-
const projectRootMappings = (0, find_project_for_path_1.createProjectRootMappingsFromProjectConfigurations)(projects);
|
93
|
-
for (const tsConfigPath of possiblePaths) {
|
94
|
-
const nxProject = (0, find_project_for_path_1.findProjectForPath)(tsConfigPath, projectRootMappings);
|
95
|
-
if (nxProject) {
|
96
|
-
return nxProject;
|
97
|
-
}
|
98
|
-
}
|
99
|
-
logger_1.logger.verbose('Unable to find local plugin', possiblePaths, projectRootMappings);
|
100
|
-
throw new Error('Unable to resolve local plugin with import path ' + importPath);
|
101
|
-
}
|
102
|
-
}
|
103
|
-
let tsconfigPaths;
|
104
|
-
function readTsConfigPaths(root = workspace_root_1.workspaceRoot) {
|
105
|
-
if (!tsconfigPaths) {
|
106
|
-
const tsconfigPath = ['tsconfig.base.json', 'tsconfig.json']
|
107
|
-
.map((x) => path.join(root, x))
|
108
|
-
.filter((x) => (0, node_fs_1.existsSync)(x))[0];
|
109
|
-
if (!tsconfigPath) {
|
110
|
-
throw new Error('unable to find tsconfig.base.json or tsconfig.json');
|
111
|
-
}
|
112
|
-
const { compilerOptions } = (0, fileutils_1.readJsonFile)(tsconfigPath);
|
113
|
-
tsconfigPaths = compilerOptions?.paths;
|
114
|
-
}
|
115
|
-
return tsconfigPaths ?? {};
|
116
|
-
}
|
117
|
-
function readPluginMainFromProjectConfiguration(plugin) {
|
118
|
-
const { main } = Object.values(plugin.targets).find((x) => [
|
119
|
-
'@nx/js:tsc',
|
120
|
-
'@nrwl/js:tsc',
|
121
|
-
'@nx/js:swc',
|
122
|
-
'@nrwl/js:swc',
|
123
|
-
'@nx/node:package',
|
124
|
-
'@nrwl/node:package',
|
125
|
-
].includes(x.executor))?.options ||
|
126
|
-
plugin.targets?.build?.options ||
|
127
|
-
{};
|
128
|
-
return main;
|
129
|
-
}
|
130
|
-
function getPluginPathAndName(moduleName, paths, projects, root) {
|
131
|
-
let pluginPath;
|
132
|
-
let registerTSTranspiler = false;
|
133
|
-
try {
|
134
|
-
pluginPath = require.resolve(moduleName, {
|
135
|
-
paths,
|
136
|
-
});
|
137
|
-
const extension = path.extname(pluginPath);
|
138
|
-
registerTSTranspiler = extension === '.ts';
|
139
|
-
}
|
140
|
-
catch (e) {
|
141
|
-
if (e.code === 'MODULE_NOT_FOUND') {
|
142
|
-
const plugin = resolveLocalNxPlugin(moduleName, projects, root);
|
143
|
-
if (plugin) {
|
144
|
-
registerTSTranspiler = true;
|
145
|
-
const main = readPluginMainFromProjectConfiguration(plugin.projectConfig);
|
146
|
-
pluginPath = main ? path.join(root, main) : plugin.path;
|
147
|
-
}
|
148
|
-
else {
|
149
|
-
logger_1.logger.error(`Plugin listed in \`nx.json\` not found: ${moduleName}`);
|
150
|
-
throw e;
|
151
|
-
}
|
152
|
-
}
|
153
|
-
else {
|
154
|
-
throw e;
|
155
|
-
}
|
156
|
-
}
|
157
|
-
const packageJsonPath = path.join(pluginPath, 'package.json');
|
158
|
-
// Register the ts-transpiler if we are pointing to a
|
159
|
-
// plain ts file that's not part of a plugin project
|
160
|
-
if (registerTSTranspiler) {
|
161
|
-
registerPluginTSTranspiler();
|
162
|
-
}
|
163
|
-
const { name } = !['.ts', '.js'].some((x) => (0, node_path_1.extname)(moduleName) === x) && // Not trying to point to a ts or js file
|
164
|
-
(0, node_fs_1.existsSync)(packageJsonPath) // plugin has a package.json
|
165
|
-
? (0, fileutils_1.readJsonFile)(packageJsonPath) // read name from package.json
|
166
|
-
: { name: moduleName };
|
167
|
-
return { pluginPath, name };
|
168
|
-
}
|
169
|
-
exports.getPluginPathAndName = getPluginPathAndName;
|
170
|
-
async function importPluginModule(pluginPath) {
|
171
|
-
const m = await Promise.resolve(`${pluginPath}`).then(s => require(s));
|
172
|
-
if (m.default &&
|
173
|
-
('createNodes' in m.default || 'createDependencies' in m.default)) {
|
174
|
-
return m.default;
|
175
|
-
}
|
176
|
-
return m;
|
177
|
-
}
|