nx 20.3.1 → 20.4.0-beta.0
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/LICENSE +1 -1
- package/package.json +11 -11
- package/src/command-line/release/version.js +8 -0
- package/src/command-line/run/run-one.js +37 -13
- package/src/command-line/show/project.js +21 -3
- package/src/command-line/yargs-utils/shared-options.d.ts +1 -0
- package/src/command-line/yargs-utils/shared-options.js +7 -0
- package/src/core/graph/main.js +1 -1
- package/src/daemon/server/server.js +2 -2
- package/src/devkit-internals.d.ts +1 -1
- package/src/devkit-internals.js +2 -2
- package/src/native/nx.wasm32-wasi.wasm +0 -0
- package/src/nx-cloud/update-manager.js +13 -1
- package/src/plugins/js/project-graph/build-dependencies/target-project-locator.js +4 -1
- package/src/plugins/js/utils/packages.js +16 -2
- package/src/project-graph/build-project-graph.d.ts +1 -1
- package/src/project-graph/error-types.d.ts +2 -0
- package/src/project-graph/error-types.js +66 -8
- package/src/project-graph/plugins/get-plugins.d.ts +3 -3
- package/src/project-graph/plugins/get-plugins.js +112 -12
- package/src/project-graph/plugins/in-process-loader.d.ts +10 -0
- package/src/project-graph/plugins/in-process-loader.js +60 -0
- package/src/project-graph/plugins/index.d.ts +2 -1
- package/src/project-graph/plugins/index.js +4 -3
- package/src/project-graph/plugins/isolation/index.d.ts +2 -2
- package/src/project-graph/plugins/isolation/messaging.d.ts +1 -1
- package/src/project-graph/plugins/isolation/plugin-pool.d.ts +1 -1
- package/src/project-graph/plugins/isolation/plugin-pool.js +2 -2
- package/src/project-graph/plugins/isolation/plugin-worker.js +1 -2
- package/src/project-graph/plugins/load-resolved-plugin.d.ts +1 -1
- package/src/project-graph/plugins/load-resolved-plugin.js +2 -2
- package/src/project-graph/plugins/{internal-api.d.ts → loaded-nx-plugin.d.ts} +4 -10
- package/src/project-graph/plugins/loaded-nx-plugin.js +57 -0
- package/src/project-graph/plugins/resolve-plugin.d.ts +15 -0
- package/src/project-graph/plugins/{loader.js → resolve-plugin.js} +60 -149
- package/src/project-graph/plugins/transpiler.d.ts +8 -0
- package/src/project-graph/plugins/transpiler.js +47 -0
- package/src/project-graph/project-graph.js +0 -3
- package/src/project-graph/utils/project-configuration-utils.d.ts +1 -1
- package/src/project-graph/utils/project-configuration-utils.js +1 -17
- package/src/project-graph/utils/retrieve-workspace-files.d.ts +1 -1
- package/src/tasks-runner/cache.d.ts +1 -0
- package/src/tasks-runner/cache.js +20 -2
- package/src/tasks-runner/default-tasks-runner.d.ts +1 -0
- package/src/utils/command-line-utils.d.ts +1 -0
- package/src/utils/command-line-utils.js +8 -1
- package/src/utils/find-matching-projects.js +11 -0
- package/src/utils/handle-errors.js +7 -11
- package/src/utils/package-json.d.ts +1 -0
- package/src/utils/plugins/plugin-capabilities.js +2 -2
- package/src/project-graph/plugins/internal-api.js +0 -135
- package/src/project-graph/plugins/loader.d.ts +0 -30
@@ -181,8 +181,8 @@ async function handleResult(socket, type, hrFn) {
|
|
181
181
|
logger_1.serverLogger.log(`Handled ${type}. Handling time: ${doneHandlingMark.getTime() - startMark.getTime()}. Response time: ${endMark.getTime() - doneHandlingMark.getTime()}.`);
|
182
182
|
}
|
183
183
|
function handleInactivityTimeout() {
|
184
|
-
if (
|
185
|
-
logger_1.serverLogger.log(`There are
|
184
|
+
if ((0, file_watcher_sockets_1.hasRegisteredFileWatcherSockets)()) {
|
185
|
+
logger_1.serverLogger.log(`There are open file watchers. Resetting inactivity timer.`);
|
186
186
|
(0, shutdown_utils_1.resetInactivityTimeout)(handleInactivityTimeout);
|
187
187
|
}
|
188
188
|
else {
|
@@ -20,7 +20,7 @@ export { hashObject } from './hasher/file-hasher';
|
|
20
20
|
export { hashWithWorkspaceContext } from './utils/workspace-context';
|
21
21
|
export { createProjectRootMappingsFromProjectConfigurations, findProjectForPath, } from './project-graph/utils/find-project-for-path';
|
22
22
|
export { retrieveProjectConfigurations } from './project-graph/utils/retrieve-workspace-files';
|
23
|
-
export { LoadedNxPlugin } from './project-graph/plugins/
|
23
|
+
export { LoadedNxPlugin } from './project-graph/plugins/loaded-nx-plugin';
|
24
24
|
export * from './project-graph/error-types';
|
25
25
|
export { registerTsProject } from './plugins/js/utils/register';
|
26
26
|
export { interpolate } from './tasks-runner/utils';
|
package/src/devkit-internals.js
CHANGED
@@ -43,8 +43,8 @@ Object.defineProperty(exports, "createProjectRootMappingsFromProjectConfiguratio
|
|
43
43
|
Object.defineProperty(exports, "findProjectForPath", { enumerable: true, get: function () { return find_project_for_path_1.findProjectForPath; } });
|
44
44
|
var retrieve_workspace_files_2 = require("./project-graph/utils/retrieve-workspace-files");
|
45
45
|
Object.defineProperty(exports, "retrieveProjectConfigurations", { enumerable: true, get: function () { return retrieve_workspace_files_2.retrieveProjectConfigurations; } });
|
46
|
-
var
|
47
|
-
Object.defineProperty(exports, "LoadedNxPlugin", { enumerable: true, get: function () { return
|
46
|
+
var loaded_nx_plugin_1 = require("./project-graph/plugins/loaded-nx-plugin");
|
47
|
+
Object.defineProperty(exports, "LoadedNxPlugin", { enumerable: true, get: function () { return loaded_nx_plugin_1.LoadedNxPlugin; } });
|
48
48
|
tslib_1.__exportStar(require("./project-graph/error-types"), exports);
|
49
49
|
var register_1 = require("./plugins/js/utils/register");
|
50
50
|
Object.defineProperty(exports, "registerTsProject", { enumerable: true, get: function () { return register_1.registerTsProject; } });
|
Binary file
|
@@ -10,6 +10,7 @@ const debug_logger_1 = require("./debug-logger");
|
|
10
10
|
const tar = require("tar-stream");
|
11
11
|
const cache_directory_1 = require("../utils/cache-directory");
|
12
12
|
const crypto_1 = require("crypto");
|
13
|
+
const workspace_root_1 = require("../utils/workspace-root");
|
13
14
|
class NxCloudEnterpriseOutdatedError extends Error {
|
14
15
|
constructor(url) {
|
15
16
|
super(`Nx Cloud instance hosted at ${url} is outdated`);
|
@@ -83,7 +84,18 @@ async function verifyOrUpdateNxCloudClient(options) {
|
|
83
84
|
nxCloudClient: require(currentBundle.fullPath),
|
84
85
|
};
|
85
86
|
}
|
86
|
-
|
87
|
+
function getBundleInstallDefaultLocation() {
|
88
|
+
const legacyPath = (0, path_1.join)(workspace_root_1.workspaceRoot, 'node_modules', '.cache', 'nx', 'cloud');
|
89
|
+
// this legacy path is used when the nx-cloud package is installed.
|
90
|
+
// make sure to reuse it so that we don't `require` different the client bundles
|
91
|
+
if ((0, fs_1.existsSync)(legacyPath)) {
|
92
|
+
return legacyPath;
|
93
|
+
}
|
94
|
+
else {
|
95
|
+
return (0, path_1.join)(cache_directory_1.cacheDir, 'cloud');
|
96
|
+
}
|
97
|
+
}
|
98
|
+
const runnerBundleInstallDirectory = getBundleInstallDefaultLocation();
|
87
99
|
function getLatestInstalledRunnerBundle() {
|
88
100
|
if (!(0, fs_1.existsSync)(runnerBundleInstallDirectory)) {
|
89
101
|
(0, fs_1.mkdirSync)(runnerBundleInstallDirectory, { recursive: true });
|
@@ -191,7 +191,10 @@ class TargetProjectLocator {
|
|
191
191
|
}
|
192
192
|
findDependencyInWorkspaceProjects(dep) {
|
193
193
|
this.packageEntryPointsToProjectMap ??= (0, packages_1.getPackageEntryPointsToProjectMap)(this.nodes);
|
194
|
-
return this.packageEntryPointsToProjectMap[dep]?.name ??
|
194
|
+
return (this.packageEntryPointsToProjectMap[dep]?.name ??
|
195
|
+
// if the package exports do not include ".", look for subpath exports
|
196
|
+
Object.entries(this.packageEntryPointsToProjectMap).find(([entryPoint]) => dep.startsWith(`${entryPoint}/`))?.[1]?.name ??
|
197
|
+
null);
|
195
198
|
}
|
196
199
|
resolveImportWithTypescript(normalizedImportExpr, filePath) {
|
197
200
|
let resolvedModule;
|
@@ -10,14 +10,28 @@ function getPackageEntryPointsToProjectMap(projects) {
|
|
10
10
|
continue;
|
11
11
|
}
|
12
12
|
const { packageName, packageExports } = metadata.js;
|
13
|
-
if (!packageExports ||
|
13
|
+
if (!packageExports ||
|
14
|
+
typeof packageExports === 'string' ||
|
15
|
+
!Object.keys(packageExports).length) {
|
14
16
|
// no `exports` or it points to a file, which would be the equivalent of
|
15
17
|
// an '.' export, in which case the package name is the entry point
|
16
18
|
result[packageName] = project;
|
17
19
|
}
|
18
20
|
else {
|
19
21
|
for (const entryPoint of Object.keys(packageExports)) {
|
20
|
-
|
22
|
+
// if entrypoint begins with '.', it is a relative subpath export
|
23
|
+
// otherwise, it is a conditional export
|
24
|
+
// https://nodejs.org/api/packages.html#conditional-exports
|
25
|
+
if (entryPoint.startsWith('.')) {
|
26
|
+
result[(0, posix_1.join)(packageName, entryPoint)] = project;
|
27
|
+
}
|
28
|
+
else {
|
29
|
+
result[packageName] = project;
|
30
|
+
}
|
31
|
+
}
|
32
|
+
// if there was no '.' entrypoint, ensure the package name is matched with the project
|
33
|
+
if (!result[packageName]) {
|
34
|
+
result[packageName] = project;
|
21
35
|
}
|
22
36
|
}
|
23
37
|
}
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import { FileData } from './file-utils';
|
2
2
|
import { FileMapCache } from './nx-deps-cache';
|
3
|
-
import { LoadedNxPlugin } from './plugins/
|
3
|
+
import type { LoadedNxPlugin } from './plugins/loaded-nx-plugin';
|
4
4
|
import { CreateMetadataContext } from './plugins';
|
5
5
|
import { FileMap, ProjectGraph, ProjectGraphExternalNode } from '../config/project-graph';
|
6
6
|
import { ProjectConfiguration } from '../config/workspace-json-project-json';
|
@@ -4,6 +4,7 @@ import { ProjectGraph } from '../config/project-graph';
|
|
4
4
|
import { CreateNodesFunctionV2 } from './plugins/public-api';
|
5
5
|
export declare class ProjectGraphError extends Error {
|
6
6
|
#private;
|
7
|
+
private readonly errors;
|
7
8
|
constructor(errors: Array<AggregateCreateNodesError | MergeNodesError | ProjectsWithNoNameError | MultipleProjectsWithSameNameError | ProcessDependenciesError | CreateMetadataError | WorkspaceValidityError>, partialProjectGraph: ProjectGraph, partialSourceMaps: ConfigurationSourceMaps);
|
8
9
|
/**
|
9
10
|
* The daemon cannot throw errors which contain methods as they are not serializable.
|
@@ -83,6 +84,7 @@ export declare class AggregateCreateNodesError extends Error {
|
|
83
84
|
*/
|
84
85
|
constructor(errors: Array<[file: string | null, error: Error]>, partialResults: Awaited<ReturnType<CreateNodesFunctionV2>>);
|
85
86
|
}
|
87
|
+
export declare function formatAggregateCreateNodesError(error: AggregateCreateNodesError, pluginName: string): void;
|
86
88
|
export declare class MergeNodesError extends Error {
|
87
89
|
file: string;
|
88
90
|
pluginName: string;
|
@@ -1,5 +1,5 @@
|
|
1
1
|
"use strict";
|
2
|
-
var
|
2
|
+
var _ProjectGraphError_partialProjectGraph, _ProjectGraphError_partialSourceMaps;
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
4
4
|
exports.LoadPluginError = exports.DaemonProjectGraphError = exports.AggregateProjectGraphError = exports.WorkspaceValidityError = exports.ProcessDependenciesError = exports.CreateMetadataError = exports.MergeNodesError = exports.AggregateCreateNodesError = exports.ProjectConfigurationsError = exports.ProjectWithNoNameError = exports.ProjectsWithNoNameError = exports.ProjectWithExistingNameError = exports.MultipleProjectsWithSameNameError = exports.ProjectGraphError = void 0;
|
5
5
|
exports.isProjectWithExistingNameError = isProjectWithExistingNameError;
|
@@ -7,6 +7,7 @@ exports.isMultipleProjectsWithSameNameError = isMultipleProjectsWithSameNameErro
|
|
7
7
|
exports.isProjectsWithNoNameError = isProjectsWithNoNameError;
|
8
8
|
exports.isProjectWithNoNameError = isProjectWithNoNameError;
|
9
9
|
exports.isProjectConfigurationsError = isProjectConfigurationsError;
|
10
|
+
exports.formatAggregateCreateNodesError = formatAggregateCreateNodesError;
|
10
11
|
exports.isWorkspaceValidityError = isWorkspaceValidityError;
|
11
12
|
exports.isAggregateProjectGraphError = isAggregateProjectGraphError;
|
12
13
|
exports.isCreateMetadataError = isCreateMetadataError;
|
@@ -15,17 +16,45 @@ exports.isMergeNodesError = isMergeNodesError;
|
|
15
16
|
const tslib_1 = require("tslib");
|
16
17
|
class ProjectGraphError extends Error {
|
17
18
|
constructor(errors, partialProjectGraph, partialSourceMaps) {
|
18
|
-
|
19
|
-
|
19
|
+
const messageFragments = ['Failed to process project graph.'];
|
20
|
+
const mergeNodesErrors = [];
|
21
|
+
const unknownErrors = [];
|
22
|
+
for (const e of errors) {
|
23
|
+
if (
|
24
|
+
// Known errors that are self-explanatory
|
25
|
+
isAggregateCreateNodesError(e) ||
|
26
|
+
isCreateMetadataError(e) ||
|
27
|
+
isProcessDependenciesError(e) ||
|
28
|
+
isProjectsWithNoNameError(e) ||
|
29
|
+
isMultipleProjectsWithSameNameError(e) ||
|
30
|
+
isWorkspaceValidityError(e)) {
|
31
|
+
}
|
32
|
+
else if (
|
33
|
+
// Known error type, but unlikely to be caused by the user
|
34
|
+
isMergeNodesError(e)) {
|
35
|
+
mergeNodesErrors.push(e);
|
36
|
+
}
|
37
|
+
else {
|
38
|
+
unknownErrors.push(e);
|
39
|
+
}
|
40
|
+
}
|
41
|
+
if (mergeNodesErrors.length > 0) {
|
42
|
+
messageFragments.push(`This type of error most likely points to an issue within Nx. Please report it.`);
|
43
|
+
}
|
44
|
+
if (unknownErrors.length > 0) {
|
45
|
+
messageFragments.push(`If the error cause is not obvious from the below error messages, running "nx reset" may fix it. Please report the issue if you keep seeing it.`);
|
46
|
+
}
|
47
|
+
super(messageFragments.join(' '));
|
48
|
+
this.errors = errors;
|
20
49
|
_ProjectGraphError_partialProjectGraph.set(this, void 0);
|
21
50
|
_ProjectGraphError_partialSourceMaps.set(this, void 0);
|
22
51
|
this.name = this.constructor.name;
|
23
|
-
|
52
|
+
this.errors = errors;
|
24
53
|
tslib_1.__classPrivateFieldSet(this, _ProjectGraphError_partialProjectGraph, partialProjectGraph, "f");
|
25
54
|
tslib_1.__classPrivateFieldSet(this, _ProjectGraphError_partialSourceMaps, partialSourceMaps, "f");
|
26
|
-
this.stack =
|
55
|
+
this.stack = errors
|
27
56
|
.map((error) => indentString(formatErrorStackAndCause(error), 2))
|
28
|
-
.join('\n')
|
57
|
+
.join('\n');
|
29
58
|
}
|
30
59
|
/**
|
31
60
|
* The daemon cannot throw errors which contain methods as they are not serializable.
|
@@ -47,11 +76,11 @@ class ProjectGraphError extends Error {
|
|
47
76
|
return tslib_1.__classPrivateFieldGet(this, _ProjectGraphError_partialSourceMaps, "f");
|
48
77
|
}
|
49
78
|
getErrors() {
|
50
|
-
return
|
79
|
+
return this.errors;
|
51
80
|
}
|
52
81
|
}
|
53
82
|
exports.ProjectGraphError = ProjectGraphError;
|
54
|
-
|
83
|
+
_ProjectGraphError_partialProjectGraph = new WeakMap(), _ProjectGraphError_partialSourceMaps = new WeakMap();
|
55
84
|
class MultipleProjectsWithSameNameError extends Error {
|
56
85
|
constructor(conflicts, projects) {
|
57
86
|
super([
|
@@ -179,6 +208,29 @@ class AggregateCreateNodesError extends Error {
|
|
179
208
|
}
|
180
209
|
}
|
181
210
|
exports.AggregateCreateNodesError = AggregateCreateNodesError;
|
211
|
+
function formatAggregateCreateNodesError(error, pluginName) {
|
212
|
+
const errorBodyLines = [
|
213
|
+
`${error.errors.length > 1 ? `${error.errors.length} errors` : 'An error'} occurred while processing files for the ${pluginName} plugin.`,
|
214
|
+
];
|
215
|
+
const errorStackLines = [];
|
216
|
+
const innerErrors = error.errors;
|
217
|
+
for (const [file, e] of innerErrors) {
|
218
|
+
if (file) {
|
219
|
+
errorBodyLines.push(` - ${file}: ${e.message}`);
|
220
|
+
errorStackLines.push(` - ${file}: ${e.stack}`);
|
221
|
+
}
|
222
|
+
else {
|
223
|
+
errorBodyLines.push(` - ${e.message}`);
|
224
|
+
errorStackLines.push(` - ${e.stack}`);
|
225
|
+
}
|
226
|
+
if (e.stack && process.env.NX_VERBOSE_LOGGING === 'true') {
|
227
|
+
const innerStackTrace = ' ' + e.stack.split('\n')?.join('\n ');
|
228
|
+
errorStackLines.push(innerStackTrace);
|
229
|
+
}
|
230
|
+
}
|
231
|
+
error.stack = errorStackLines.join('\n');
|
232
|
+
error.message = errorBodyLines.join('\n');
|
233
|
+
}
|
182
234
|
class MergeNodesError extends Error {
|
183
235
|
constructor({ file, pluginName, error, }) {
|
184
236
|
const msg = `The nodes created from ${file} by the "${pluginName}" could not be merged into the project graph:`;
|
@@ -212,6 +264,12 @@ class ProcessDependenciesError extends Error {
|
|
212
264
|
}
|
213
265
|
}
|
214
266
|
exports.ProcessDependenciesError = ProcessDependenciesError;
|
267
|
+
function isProcessDependenciesError(e) {
|
268
|
+
return (e instanceof ProcessDependenciesError ||
|
269
|
+
(typeof e === 'object' &&
|
270
|
+
'name' in e &&
|
271
|
+
e?.name === ProcessDependenciesError.name));
|
272
|
+
}
|
215
273
|
class WorkspaceValidityError extends Error {
|
216
274
|
constructor(message) {
|
217
275
|
message = `Configuration Error\n${message}`;
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import { LoadedNxPlugin } from './
|
2
|
-
export declare function getPlugins(): Promise<LoadedNxPlugin[]>;
|
3
|
-
export declare function getOnlyDefaultPlugins(): Promise<LoadedNxPlugin[]>;
|
1
|
+
import type { LoadedNxPlugin } from './loaded-nx-plugin';
|
2
|
+
export declare function getPlugins(root?: string): Promise<LoadedNxPlugin[]>;
|
3
|
+
export declare function getOnlyDefaultPlugins(root?: string): Promise<LoadedNxPlugin[]>;
|
4
4
|
export declare function cleanupPlugins(): void;
|
@@ -3,16 +3,24 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getPlugins = getPlugins;
|
4
4
|
exports.getOnlyDefaultPlugins = getOnlyDefaultPlugins;
|
5
5
|
exports.cleanupPlugins = cleanupPlugins;
|
6
|
-
const
|
6
|
+
const node_path_1 = require("node:path");
|
7
|
+
const angular_json_1 = require("../../adapter/angular-json");
|
7
8
|
const nx_json_1 = require("../../config/nx-json");
|
8
|
-
const
|
9
|
+
const file_hasher_1 = require("../../hasher/file-hasher");
|
10
|
+
const native_1 = require("../../native");
|
9
11
|
const workspace_root_1 = require("../../utils/workspace-root");
|
12
|
+
const isolation_1 = require("./isolation");
|
13
|
+
const in_process_loader_1 = require("./in-process-loader");
|
14
|
+
const transpiler_1 = require("./transpiler");
|
15
|
+
/**
|
16
|
+
* Stuff for specified NX Plugins.
|
17
|
+
*/
|
10
18
|
let currentPluginsConfigurationHash;
|
11
19
|
let loadedPlugins;
|
12
20
|
let pendingPluginsPromise;
|
13
21
|
let cleanup;
|
14
|
-
async function getPlugins() {
|
15
|
-
const pluginsConfiguration = (0, nx_json_1.readNxJson)().plugins ?? [];
|
22
|
+
async function getPlugins(root = workspace_root_1.workspaceRoot) {
|
23
|
+
const pluginsConfiguration = (0, nx_json_1.readNxJson)(root).plugins ?? [];
|
16
24
|
const pluginsConfigurationHash = (0, file_hasher_1.hashObject)(pluginsConfiguration);
|
17
25
|
// If the plugins configuration has not changed, reuse the current plugins
|
18
26
|
if (loadedPlugins &&
|
@@ -24,17 +32,23 @@ async function getPlugins() {
|
|
24
32
|
pendingPluginsPromise = undefined;
|
25
33
|
cleanup();
|
26
34
|
}
|
27
|
-
pendingPluginsPromise ??= (
|
35
|
+
pendingPluginsPromise ??= loadSpecifiedNxPlugins(pluginsConfiguration, root);
|
28
36
|
currentPluginsConfigurationHash = pluginsConfigurationHash;
|
29
|
-
const [result, cleanupFn] = await
|
37
|
+
const [[result, cleanupFn], defaultPlugins] = await Promise.all([
|
38
|
+
pendingPluginsPromise,
|
39
|
+
getOnlyDefaultPlugins(root),
|
40
|
+
]);
|
30
41
|
cleanup = cleanupFn;
|
31
|
-
loadedPlugins = result;
|
32
|
-
return
|
42
|
+
loadedPlugins = result.concat(defaultPlugins);
|
43
|
+
return loadedPlugins;
|
33
44
|
}
|
45
|
+
/**
|
46
|
+
* Stuff for default NX Plugins.
|
47
|
+
*/
|
34
48
|
let loadedDefaultPlugins;
|
35
49
|
let cleanupDefaultPlugins;
|
36
50
|
let pendingDefaultPluginPromise;
|
37
|
-
async function getOnlyDefaultPlugins() {
|
51
|
+
async function getOnlyDefaultPlugins(root = workspace_root_1.workspaceRoot) {
|
38
52
|
// If the plugins configuration has not changed, reuse the current plugins
|
39
53
|
if (loadedDefaultPlugins) {
|
40
54
|
return loadedPlugins;
|
@@ -44,7 +58,7 @@ async function getOnlyDefaultPlugins() {
|
|
44
58
|
pendingDefaultPluginPromise = undefined;
|
45
59
|
cleanupDefaultPlugins();
|
46
60
|
}
|
47
|
-
pendingDefaultPluginPromise ??= (
|
61
|
+
pendingDefaultPluginPromise ??= loadDefaultNxPlugins(workspace_root_1.workspaceRoot);
|
48
62
|
const [result, cleanupFn] = await pendingDefaultPluginPromise;
|
49
63
|
cleanupDefaultPlugins = cleanupFn;
|
50
64
|
loadedPlugins = result;
|
@@ -53,6 +67,92 @@ async function getOnlyDefaultPlugins() {
|
|
53
67
|
function cleanupPlugins() {
|
54
68
|
pendingPluginsPromise = undefined;
|
55
69
|
pendingDefaultPluginPromise = undefined;
|
56
|
-
cleanup();
|
57
|
-
cleanupDefaultPlugins();
|
70
|
+
cleanup?.();
|
71
|
+
cleanupDefaultPlugins?.();
|
72
|
+
}
|
73
|
+
/**
|
74
|
+
* Stuff for generic loading
|
75
|
+
*/
|
76
|
+
function isIsolationEnabled() {
|
77
|
+
// Explicitly enabled, regardless of further conditions
|
78
|
+
if (process.env.NX_ISOLATE_PLUGINS === 'true') {
|
79
|
+
return true;
|
80
|
+
}
|
81
|
+
if (
|
82
|
+
// Explicitly disabled
|
83
|
+
process.env.NX_ISOLATE_PLUGINS === 'false' ||
|
84
|
+
// Isolation is disabled on WASM builds currently.
|
85
|
+
native_1.IS_WASM) {
|
86
|
+
return false;
|
87
|
+
}
|
88
|
+
// Default value
|
89
|
+
return true;
|
90
|
+
}
|
91
|
+
const loadingMethod = isIsolationEnabled()
|
92
|
+
? isolation_1.loadNxPluginInIsolation
|
93
|
+
: in_process_loader_1.loadNxPlugin;
|
94
|
+
async function loadDefaultNxPlugins(root = workspace_root_1.workspaceRoot) {
|
95
|
+
performance.mark('loadDefaultNxPlugins:start');
|
96
|
+
const plugins = getDefaultPlugins(root);
|
97
|
+
const cleanupFunctions = [];
|
98
|
+
const ret = [
|
99
|
+
await Promise.all(plugins.map(async (plugin) => {
|
100
|
+
performance.mark(`Load Nx Plugin: ${plugin} - start`);
|
101
|
+
const [loadedPluginPromise, cleanup] = await loadingMethod(plugin, root);
|
102
|
+
cleanupFunctions.push(cleanup);
|
103
|
+
const res = await loadedPluginPromise;
|
104
|
+
performance.mark(`Load Nx Plugin: ${plugin} - end`);
|
105
|
+
performance.measure(`Load Nx Plugin: ${plugin}`, `Load Nx Plugin: ${plugin} - start`, `Load Nx Plugin: ${plugin} - end`);
|
106
|
+
return res;
|
107
|
+
})),
|
108
|
+
() => {
|
109
|
+
for (const fn of cleanupFunctions) {
|
110
|
+
fn();
|
111
|
+
}
|
112
|
+
if ((0, transpiler_1.pluginTranspilerIsRegistered)()) {
|
113
|
+
(0, transpiler_1.cleanupPluginTSTranspiler)();
|
114
|
+
}
|
115
|
+
},
|
116
|
+
];
|
117
|
+
performance.mark('loadDefaultNxPlugins:end');
|
118
|
+
performance.measure('loadDefaultNxPlugins', 'loadDefaultNxPlugins:start', 'loadDefaultNxPlugins:end');
|
119
|
+
return ret;
|
120
|
+
}
|
121
|
+
async function loadSpecifiedNxPlugins(plugins, root = workspace_root_1.workspaceRoot) {
|
122
|
+
performance.mark('loadSpecifiedNxPlugins:start');
|
123
|
+
plugins ??= [];
|
124
|
+
const cleanupFunctions = [];
|
125
|
+
const ret = [
|
126
|
+
await Promise.all(plugins.map(async (plugin) => {
|
127
|
+
const pluginPath = typeof plugin === 'string' ? plugin : plugin.plugin;
|
128
|
+
performance.mark(`Load Nx Plugin: ${pluginPath} - start`);
|
129
|
+
const [loadedPluginPromise, cleanup] = await loadingMethod(plugin, root);
|
130
|
+
cleanupFunctions.push(cleanup);
|
131
|
+
const res = await loadedPluginPromise;
|
132
|
+
performance.mark(`Load Nx Plugin: ${pluginPath} - end`);
|
133
|
+
performance.measure(`Load Nx Plugin: ${pluginPath}`, `Load Nx Plugin: ${pluginPath} - start`, `Load Nx Plugin: ${pluginPath} - end`);
|
134
|
+
return res;
|
135
|
+
})),
|
136
|
+
() => {
|
137
|
+
for (const fn of cleanupFunctions) {
|
138
|
+
fn();
|
139
|
+
}
|
140
|
+
if ((0, transpiler_1.pluginTranspilerIsRegistered)()) {
|
141
|
+
(0, transpiler_1.cleanupPluginTSTranspiler)();
|
142
|
+
}
|
143
|
+
},
|
144
|
+
];
|
145
|
+
performance.mark('loadSpecifiedNxPlugins:end');
|
146
|
+
performance.measure('loadSpecifiedNxPlugins', 'loadSpecifiedNxPlugins:start', 'loadSpecifiedNxPlugins:end');
|
147
|
+
return ret;
|
148
|
+
}
|
149
|
+
function getDefaultPlugins(root) {
|
150
|
+
return [
|
151
|
+
(0, node_path_1.join)(__dirname, '../../plugins/js'),
|
152
|
+
...((0, angular_json_1.shouldMergeAngularProjects)(root, false)
|
153
|
+
? [(0, node_path_1.join)(__dirname, '../../adapter/angular-json')]
|
154
|
+
: []),
|
155
|
+
(0, node_path_1.join)(__dirname, '../../plugins/package-json'),
|
156
|
+
(0, node_path_1.join)(__dirname, '../../plugins/project-json/build-nodes/project-json'),
|
157
|
+
];
|
58
158
|
}
|
@@ -0,0 +1,10 @@
|
|
1
|
+
import { ProjectConfiguration } from '../../config/workspace-json-project-json';
|
2
|
+
import { PackageJson } from '../../utils/package-json';
|
3
|
+
import type { PluginConfiguration } from '../../config/nx-json';
|
4
|
+
import type { LoadedNxPlugin } from './loaded-nx-plugin';
|
5
|
+
export declare function readPluginPackageJson(pluginName: string, projects: Record<string, ProjectConfiguration>, paths?: string[]): {
|
6
|
+
path: string;
|
7
|
+
json: PackageJson;
|
8
|
+
};
|
9
|
+
export declare function loadNxPlugin(plugin: PluginConfiguration, root: string): readonly [Promise<LoadedNxPlugin>, () => void];
|
10
|
+
export declare function loadNxPluginAsync(pluginConfiguration: PluginConfiguration, paths: string[], root: string): Promise<LoadedNxPlugin>;
|
@@ -0,0 +1,60 @@
|
|
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.readPluginPackageJson = readPluginPackageJson;
|
5
|
+
exports.loadNxPlugin = loadNxPlugin;
|
6
|
+
exports.loadNxPluginAsync = loadNxPluginAsync;
|
7
|
+
const installation_directory_1 = require("../../utils/installation-directory");
|
8
|
+
const package_json_1 = require("../../utils/package-json");
|
9
|
+
const fileutils_1 = require("../../utils/fileutils");
|
10
|
+
const error_types_1 = require("../error-types");
|
11
|
+
const path = require("node:path/posix");
|
12
|
+
const load_resolved_plugin_1 = require("./load-resolved-plugin");
|
13
|
+
const resolve_plugin_1 = require("./resolve-plugin");
|
14
|
+
const transpiler_1 = require("./transpiler");
|
15
|
+
function readPluginPackageJson(pluginName, projects, paths = (0, installation_directory_1.getNxRequirePaths)()) {
|
16
|
+
try {
|
17
|
+
const result = (0, package_json_1.readModulePackageJsonWithoutFallbacks)(pluginName, paths);
|
18
|
+
return {
|
19
|
+
json: result.packageJson,
|
20
|
+
path: result.path,
|
21
|
+
};
|
22
|
+
}
|
23
|
+
catch (e) {
|
24
|
+
if (e.code === 'MODULE_NOT_FOUND') {
|
25
|
+
const localPluginPath = (0, resolve_plugin_1.resolveLocalNxPlugin)(pluginName, projects);
|
26
|
+
if (localPluginPath) {
|
27
|
+
const localPluginPackageJson = path.join(localPluginPath.path, 'package.json');
|
28
|
+
if ((0, transpiler_1.pluginTranspilerIsRegistered)()) {
|
29
|
+
(0, transpiler_1.registerPluginTSTranspiler)();
|
30
|
+
}
|
31
|
+
return {
|
32
|
+
path: localPluginPackageJson,
|
33
|
+
json: (0, fileutils_1.readJsonFile)(localPluginPackageJson),
|
34
|
+
};
|
35
|
+
}
|
36
|
+
}
|
37
|
+
throw e;
|
38
|
+
}
|
39
|
+
}
|
40
|
+
function loadNxPlugin(plugin, root) {
|
41
|
+
return [
|
42
|
+
loadNxPluginAsync(plugin, (0, installation_directory_1.getNxRequirePaths)(root), root),
|
43
|
+
() => { },
|
44
|
+
];
|
45
|
+
}
|
46
|
+
async function loadNxPluginAsync(pluginConfiguration, paths, root) {
|
47
|
+
const moduleName = typeof pluginConfiguration === 'string'
|
48
|
+
? pluginConfiguration
|
49
|
+
: pluginConfiguration.plugin;
|
50
|
+
try {
|
51
|
+
const { pluginPath, name, shouldRegisterTSTranspiler } = await (0, resolve_plugin_1.resolveNxPlugin)(moduleName, root, paths);
|
52
|
+
if (shouldRegisterTSTranspiler) {
|
53
|
+
(0, transpiler_1.registerPluginTSTranspiler)();
|
54
|
+
}
|
55
|
+
return (0, load_resolved_plugin_1.loadResolvedNxPluginAsync)(pluginConfiguration, pluginPath, name);
|
56
|
+
}
|
57
|
+
catch (e) {
|
58
|
+
throw new error_types_1.LoadPluginError(moduleName, e);
|
59
|
+
}
|
60
|
+
}
|
@@ -1,3 +1,4 @@
|
|
1
1
|
export * from './public-api';
|
2
|
-
export { readPluginPackageJson
|
2
|
+
export { readPluginPackageJson } from './in-process-loader';
|
3
|
+
export { registerPluginTSTranspiler } from './transpiler';
|
3
4
|
export { createNodesFromFiles } from './utils';
|
@@ -4,8 +4,9 @@ exports.createNodesFromFiles = exports.registerPluginTSTranspiler = exports.read
|
|
4
4
|
const tslib_1 = require("tslib");
|
5
5
|
tslib_1.__exportStar(require("./public-api"), exports);
|
6
6
|
// export * from './get-plugins';
|
7
|
-
var
|
8
|
-
Object.defineProperty(exports, "readPluginPackageJson", { enumerable: true, get: function () { return
|
9
|
-
|
7
|
+
var in_process_loader_1 = require("./in-process-loader");
|
8
|
+
Object.defineProperty(exports, "readPluginPackageJson", { enumerable: true, get: function () { return in_process_loader_1.readPluginPackageJson; } });
|
9
|
+
var transpiler_1 = require("./transpiler");
|
10
|
+
Object.defineProperty(exports, "registerPluginTSTranspiler", { enumerable: true, get: function () { return transpiler_1.registerPluginTSTranspiler; } });
|
10
11
|
var utils_1 = require("./utils");
|
11
12
|
Object.defineProperty(exports, "createNodesFromFiles", { enumerable: true, get: function () { return utils_1.createNodesFromFiles; } });
|
@@ -1,3 +1,3 @@
|
|
1
|
-
import { PluginConfiguration } from '../../../config/nx-json';
|
2
|
-
import { LoadedNxPlugin } from '../
|
1
|
+
import type { PluginConfiguration } from '../../../config/nx-json';
|
2
|
+
import type { LoadedNxPlugin } from '../loaded-nx-plugin';
|
3
3
|
export declare function loadNxPluginInIsolation(plugin: PluginConfiguration, root?: string): Promise<readonly [Promise<LoadedNxPlugin>, () => void]>;
|
@@ -1,7 +1,7 @@
|
|
1
1
|
import { ProjectGraph } from '../../../config/project-graph';
|
2
2
|
import { PluginConfiguration } from '../../../config/nx-json';
|
3
3
|
import { CreateDependenciesContext, CreateMetadataContext, CreateNodesContextV2 } from '../public-api';
|
4
|
-
import { LoadedNxPlugin } from '../
|
4
|
+
import type { LoadedNxPlugin } from '../loaded-nx-plugin';
|
5
5
|
import { Serializable } from 'child_process';
|
6
6
|
import { Socket } from 'net';
|
7
7
|
export interface PluginWorkerLoadMessage {
|
@@ -1,3 +1,3 @@
|
|
1
1
|
import { PluginConfiguration } from '../../../config/nx-json';
|
2
|
-
import { LoadedNxPlugin } from '../
|
2
|
+
import type { LoadedNxPlugin } from '../loaded-nx-plugin';
|
3
3
|
export declare function loadRemoteNxPlugin(plugin: PluginConfiguration, root: string): Promise<[Promise<LoadedNxPlugin>, () => void]>;
|
@@ -8,7 +8,7 @@ const socket_utils_1 = require("../../../daemon/socket-utils");
|
|
8
8
|
const consume_messages_from_socket_1 = require("../../../utils/consume-messages-from-socket");
|
9
9
|
const messaging_1 = require("./messaging");
|
10
10
|
const installation_directory_1 = require("../../../utils/installation-directory");
|
11
|
-
const
|
11
|
+
const resolve_plugin_1 = require("../resolve-plugin");
|
12
12
|
const cleanupFunctions = new Set();
|
13
13
|
const pluginNames = new Map();
|
14
14
|
const PLUGIN_TIMEOUT_HINT_TEXT = 'As a last resort, you can set NX_PLUGIN_NO_TIMEOUTS=true to bypass this timeout.';
|
@@ -31,7 +31,7 @@ async function loadRemoteNxPlugin(plugin, root) {
|
|
31
31
|
return [nxPluginWorkerCache.get(cacheKey), () => { }];
|
32
32
|
}
|
33
33
|
const moduleName = typeof plugin === 'string' ? plugin : plugin.plugin;
|
34
|
-
const { name, pluginPath, shouldRegisterTSTranspiler } = await (0,
|
34
|
+
const { name, pluginPath, shouldRegisterTSTranspiler } = await (0, resolve_plugin_1.resolveNxPlugin)(moduleName, root, (0, installation_directory_1.getNxRequirePaths)(root));
|
35
35
|
const { worker, socket } = await startPluginWorker();
|
36
36
|
const pendingPromises = new Map();
|
37
37
|
const exitHandler = createWorkerExitHandler(worker, pendingPromises);
|
@@ -5,7 +5,6 @@ const serializable_error_1 = require("../../../utils/serializable-error");
|
|
5
5
|
const consume_messages_from_socket_1 = require("../../../utils/consume-messages-from-socket");
|
6
6
|
const net_1 = require("net");
|
7
7
|
const fs_1 = require("fs");
|
8
|
-
const loader_1 = require("../loader");
|
9
8
|
if (process.env.NX_PERF_LOGGING === 'true') {
|
10
9
|
require('../../../utils/perf-logging');
|
11
10
|
}
|
@@ -38,7 +37,7 @@ const server = (0, net_1.createServer)((socket) => {
|
|
38
37
|
// Register the ts-transpiler if we are pointing to a
|
39
38
|
// plain ts file that's not part of a plugin project
|
40
39
|
if (shouldRegisterTSTranspiler) {
|
41
|
-
(
|
40
|
+
require('../transpiler').registerPluginTSTranspiler();
|
42
41
|
}
|
43
42
|
plugin = await loadResolvedNxPluginAsync(pluginConfiguration, pluginPath, name);
|
44
43
|
return {
|
@@ -1,3 +1,3 @@
|
|
1
1
|
import type { PluginConfiguration } from '../../config/nx-json';
|
2
|
-
import { LoadedNxPlugin } from './
|
2
|
+
import { LoadedNxPlugin } from './loaded-nx-plugin';
|
3
3
|
export declare function loadResolvedNxPluginAsync(pluginConfiguration: PluginConfiguration, pluginPath: string, name: string): Promise<LoadedNxPlugin>;
|
@@ -1,11 +1,11 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.loadResolvedNxPluginAsync = loadResolvedNxPluginAsync;
|
4
|
-
const
|
4
|
+
const loaded_nx_plugin_1 = require("./loaded-nx-plugin");
|
5
5
|
async function loadResolvedNxPluginAsync(pluginConfiguration, pluginPath, name) {
|
6
6
|
const plugin = await importPluginModule(pluginPath);
|
7
7
|
plugin.name ??= name;
|
8
|
-
return new
|
8
|
+
return new loaded_nx_plugin_1.LoadedNxPlugin(plugin, pluginConfiguration);
|
9
9
|
}
|
10
10
|
async function importPluginModule(pluginPath) {
|
11
11
|
const m = await Promise.resolve(`${pluginPath}`).then(s => require(s));
|
@@ -1,7 +1,7 @@
|
|
1
|
-
import {
|
2
|
-
import {
|
3
|
-
import {
|
4
|
-
import {
|
1
|
+
import type { ProjectGraph } from '../../config/project-graph';
|
2
|
+
import type { PluginConfiguration } from '../../config/nx-json';
|
3
|
+
import type { RawProjectGraphDependency } from '../project-graph-builder';
|
4
|
+
import type { CreateDependenciesContext, CreateMetadataContext, CreateNodesContextV2, CreateNodesResult, NxPluginV2, ProjectsMetadata } from './public-api';
|
5
5
|
export declare class LoadedNxPlugin {
|
6
6
|
readonly name: string;
|
7
7
|
readonly createNodes?: [
|
@@ -19,9 +19,3 @@ export type CreateNodesResultWithContext = CreateNodesResult & {
|
|
19
19
|
file: string;
|
20
20
|
pluginName: string;
|
21
21
|
};
|
22
|
-
/**
|
23
|
-
* Use `getPlugins` instead.
|
24
|
-
* @deprecated Do not use this. Use `getPlugins` instead.
|
25
|
-
*/
|
26
|
-
export declare function loadNxPlugins(plugins: PluginConfiguration[], root?: string): Promise<readonly [LoadedNxPlugin[], () => void]>;
|
27
|
-
export declare function getDefaultPlugins(root: string): Promise<string[]>;
|