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
@@ -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;
|
@@ -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[]>;
|
@@ -1,64 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
// This file contains the bits and bobs of the internal API for loading and interacting with Nx plugins.
|
3
|
-
// For the public API, used by plugin authors, see `./public-api.ts`.
|
4
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
5
|
-
exports.getDefaultPlugins = exports.loadNxPluginInIsolation = exports.loadNxPluginsInIsolation = exports.nxPluginCache = exports.loadPlugin = exports.loadPlugins = void 0;
|
6
|
-
const path_1 = require("path");
|
7
|
-
const workspace_root_1 = require("../../utils/workspace-root");
|
8
|
-
const angular_json_1 = require("../../adapter/angular-json");
|
9
|
-
const plugin_pool_1 = require("./plugin-pool");
|
10
|
-
var worker_api_1 = require("./worker-api");
|
11
|
-
Object.defineProperty(exports, "loadPlugins", { enumerable: true, get: function () { return worker_api_1.loadPlugins; } });
|
12
|
-
Object.defineProperty(exports, "loadPlugin", { enumerable: true, get: function () { return worker_api_1.loadPlugin; } });
|
13
|
-
// Short lived cache (cleared between cmd runs)
|
14
|
-
// holding resolved nx plugin objects.
|
15
|
-
// Allows loaded plugins to not be reloaded when
|
16
|
-
// referenced multiple times.
|
17
|
-
exports.nxPluginCache = new Map();
|
18
|
-
/**
|
19
|
-
* This loads plugins in isolation in their own worker so that they do not disturb other workers or the main process.
|
20
|
-
*/
|
21
|
-
async function loadNxPluginsInIsolation(plugins, root = workspace_root_1.workspaceRoot) {
|
22
|
-
const result = [];
|
23
|
-
plugins ??= [];
|
24
|
-
plugins.unshift((0, path_1.join)(__dirname, '../../plugins/project-json/build-nodes/package-json-next-to-project-json'));
|
25
|
-
// We push the nx core node plugins onto the end, s.t. it overwrites any other plugins
|
26
|
-
plugins.push(...(await getDefaultPlugins(root)));
|
27
|
-
const cleanupFunctions = [];
|
28
|
-
for (const plugin of plugins) {
|
29
|
-
const [loadedPluginPromise, cleanup] = loadNxPluginInIsolation(plugin, root);
|
30
|
-
result.push(loadedPluginPromise);
|
31
|
-
cleanupFunctions.push(cleanup);
|
32
|
-
}
|
33
|
-
return [
|
34
|
-
await Promise.all(result),
|
35
|
-
() => {
|
36
|
-
for (const fn of cleanupFunctions) {
|
37
|
-
fn();
|
38
|
-
}
|
39
|
-
},
|
40
|
-
];
|
41
|
-
}
|
42
|
-
exports.loadNxPluginsInIsolation = loadNxPluginsInIsolation;
|
43
|
-
function loadNxPluginInIsolation(plugin, root = workspace_root_1.workspaceRoot) {
|
44
|
-
const cacheKey = JSON.stringify(plugin);
|
45
|
-
if (exports.nxPluginCache.has(cacheKey)) {
|
46
|
-
return exports.nxPluginCache.get(cacheKey);
|
47
|
-
}
|
48
|
-
const [loadingPlugin, cleanup] = (0, plugin_pool_1.loadRemoteNxPlugin)(plugin, root);
|
49
|
-
exports.nxPluginCache.set(cacheKey, [loadingPlugin, cleanup]);
|
50
|
-
return [loadingPlugin, cleanup];
|
51
|
-
}
|
52
|
-
exports.loadNxPluginInIsolation = loadNxPluginInIsolation;
|
53
|
-
async function getDefaultPlugins(root) {
|
54
|
-
return [
|
55
|
-
(0, path_1.join)(__dirname, '../../plugins/js'),
|
56
|
-
(0, path_1.join)(__dirname, '../../plugins/target-defaults/target-defaults-plugin'),
|
57
|
-
...((0, angular_json_1.shouldMergeAngularProjects)(root, false)
|
58
|
-
? [(0, path_1.join)(__dirname, '../../adapter/angular-json')]
|
59
|
-
: []),
|
60
|
-
(0, path_1.join)(__dirname, '../../plugins/package-json-workspaces'),
|
61
|
-
(0, path_1.join)(__dirname, '../../plugins/project-json/build-nodes/project-json'),
|
62
|
-
];
|
63
|
-
}
|
64
|
-
exports.getDefaultPlugins = getDefaultPlugins;
|
@@ -1,94 +0,0 @@
|
|
1
|
-
import { ProjectGraph, ProjectGraphProcessorContext } from '../../config/project-graph';
|
2
|
-
import { PluginConfiguration } from '../../config/nx-json';
|
3
|
-
import { CreateDependenciesContext, CreateNodesContext } from './public-api';
|
4
|
-
import { RemotePlugin } from './internal-api';
|
5
|
-
export interface PluginWorkerLoadMessage {
|
6
|
-
type: 'load';
|
7
|
-
payload: {
|
8
|
-
plugin: PluginConfiguration;
|
9
|
-
root: string;
|
10
|
-
};
|
11
|
-
}
|
12
|
-
export interface PluginWorkerLoadResult {
|
13
|
-
type: 'load-result';
|
14
|
-
payload: {
|
15
|
-
name: string;
|
16
|
-
createNodesPattern: string;
|
17
|
-
hasCreateDependencies: boolean;
|
18
|
-
hasProcessProjectGraph: boolean;
|
19
|
-
success: true;
|
20
|
-
} | {
|
21
|
-
success: false;
|
22
|
-
error: string;
|
23
|
-
};
|
24
|
-
}
|
25
|
-
export interface PluginWorkerCreateNodesMessage {
|
26
|
-
type: 'createNodes';
|
27
|
-
payload: {
|
28
|
-
configFiles: string[];
|
29
|
-
context: CreateNodesContext;
|
30
|
-
tx: string;
|
31
|
-
};
|
32
|
-
}
|
33
|
-
export interface PluginWorkerCreateNodesResult {
|
34
|
-
type: 'createNodesResult';
|
35
|
-
payload: {
|
36
|
-
success: true;
|
37
|
-
result: Awaited<ReturnType<RemotePlugin['createNodes'][1]>>;
|
38
|
-
tx: string;
|
39
|
-
} | {
|
40
|
-
success: false;
|
41
|
-
error: string;
|
42
|
-
tx: string;
|
43
|
-
};
|
44
|
-
}
|
45
|
-
export interface PluginCreateDependenciesMessage {
|
46
|
-
type: 'createDependencies';
|
47
|
-
payload: {
|
48
|
-
context: CreateDependenciesContext;
|
49
|
-
tx: string;
|
50
|
-
};
|
51
|
-
}
|
52
|
-
export interface PluginCreateDependenciesResult {
|
53
|
-
type: 'createDependenciesResult';
|
54
|
-
payload: {
|
55
|
-
dependencies: ReturnType<RemotePlugin['createDependencies']>;
|
56
|
-
success: true;
|
57
|
-
tx: string;
|
58
|
-
} | {
|
59
|
-
success: false;
|
60
|
-
error: string;
|
61
|
-
tx: string;
|
62
|
-
};
|
63
|
-
}
|
64
|
-
export interface PluginWorkerProcessProjectGraphMessage {
|
65
|
-
type: 'processProjectGraph';
|
66
|
-
payload: {
|
67
|
-
graph: ProjectGraph;
|
68
|
-
ctx: ProjectGraphProcessorContext;
|
69
|
-
tx: string;
|
70
|
-
};
|
71
|
-
}
|
72
|
-
export interface PluginWorkerProcessProjectGraphResult {
|
73
|
-
type: 'processProjectGraphResult';
|
74
|
-
payload: {
|
75
|
-
graph: ProjectGraph;
|
76
|
-
success: true;
|
77
|
-
tx: string;
|
78
|
-
} | {
|
79
|
-
success: false;
|
80
|
-
error: string;
|
81
|
-
tx: string;
|
82
|
-
};
|
83
|
-
}
|
84
|
-
export type PluginWorkerMessage = PluginWorkerLoadMessage | PluginWorkerCreateNodesMessage | PluginCreateDependenciesMessage | PluginWorkerProcessProjectGraphMessage;
|
85
|
-
export type PluginWorkerResult = PluginWorkerLoadResult | PluginWorkerCreateNodesResult | PluginCreateDependenciesResult | PluginWorkerProcessProjectGraphResult;
|
86
|
-
type MaybePromise<T> = T | Promise<T>;
|
87
|
-
type MessageHandlerReturn<T extends PluginWorkerMessage | PluginWorkerResult> = T extends PluginWorkerResult ? MaybePromise<PluginWorkerMessage | void> : MaybePromise<PluginWorkerResult | void>;
|
88
|
-
export declare function consumeMessage<T extends PluginWorkerMessage | PluginWorkerResult>(raw: string | T, handlers: {
|
89
|
-
[K in T['type']]: (payload: Extract<T, {
|
90
|
-
type: K;
|
91
|
-
}>['payload']) => MessageHandlerReturn<T>;
|
92
|
-
}): Promise<void>;
|
93
|
-
export declare function createMessage(message: PluginWorkerMessage | PluginWorkerResult): string;
|
94
|
-
export {};
|
@@ -1,23 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.createMessage = exports.consumeMessage = void 0;
|
4
|
-
// Takes a message and a map of handlers and calls the appropriate handler
|
5
|
-
// type safe and requires all handlers to be handled
|
6
|
-
async function consumeMessage(raw, handlers) {
|
7
|
-
const message = typeof raw === 'string' ? JSON.parse(raw) : raw;
|
8
|
-
const handler = handlers[message.type];
|
9
|
-
if (handler) {
|
10
|
-
const response = await handler(message.payload);
|
11
|
-
if (response) {
|
12
|
-
process.send(createMessage(response));
|
13
|
-
}
|
14
|
-
}
|
15
|
-
else {
|
16
|
-
throw new Error(`Unhandled message type: ${message.type}`);
|
17
|
-
}
|
18
|
-
}
|
19
|
-
exports.consumeMessage = consumeMessage;
|
20
|
-
function createMessage(message) {
|
21
|
-
return JSON.stringify(message);
|
22
|
-
}
|
23
|
-
exports.createMessage = createMessage;
|