nx 18.3.0-beta.0 → 18.3.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/post-install.js +7 -5
- package/package.json +12 -12
- package/src/adapter/angular-json.d.ts +2 -1
- package/src/adapter/angular-json.js +1 -0
- package/src/adapter/ngcli-adapter.js +3 -3
- package/src/command-line/generate/generator-utils.js +2 -2
- package/src/command-line/init/implementation/react/index.js +1 -1
- package/src/command-line/run/executor-utils.js +2 -2
- package/src/config/nx-json.d.ts +2 -1
- package/src/config/schema-utils.js +2 -2
- package/src/daemon/server/plugins.d.ts +3 -0
- package/src/daemon/server/plugins.js +22 -0
- package/src/daemon/server/project-graph-incremental-recomputation.js +11 -10
- package/src/daemon/server/shutdown-utils.js +2 -0
- package/src/devkit-exports.d.ts +3 -2
- package/src/executors/run-commands/run-commands.impl.d.ts +4 -1
- package/src/executors/run-commands/run-commands.impl.js +51 -4
- package/src/executors/utils/convert-nx-executor.js +4 -1
- package/src/generators/utils/project-configuration.js +2 -2
- package/src/migrations/update-15-1-0/set-project-names.js +4 -2
- package/src/native/assert-supported-platform.js +1 -1
- package/src/plugins/js/index.d.ts +1 -1
- package/src/plugins/js/lock-file/lock-file.d.ts +1 -1
- package/src/plugins/js/lock-file/npm-parser.d.ts +1 -1
- package/src/plugins/js/lock-file/pnpm-parser.d.ts +1 -1
- package/src/plugins/js/lock-file/yarn-parser.d.ts +1 -1
- package/src/plugins/js/project-graph/build-dependencies/build-dependencies.d.ts +1 -1
- package/src/plugins/js/project-graph/build-dependencies/explicit-package-json-dependencies.d.ts +1 -1
- package/src/plugins/js/project-graph/build-dependencies/explicit-project-dependencies.d.ts +1 -1
- package/src/plugins/package-json-workspaces/create-nodes.d.ts +2 -2
- package/src/plugins/package-json-workspaces/create-nodes.js +24 -31
- package/src/plugins/package-json-workspaces/index.d.ts +1 -0
- package/src/plugins/package-json-workspaces/index.js +2 -0
- package/src/plugins/project-json/build-nodes/package-json-next-to-project-json.d.ts +2 -1
- package/src/plugins/project-json/build-nodes/package-json-next-to-project-json.js +1 -0
- package/src/plugins/project-json/build-nodes/project-json.d.ts +2 -1
- package/src/plugins/project-json/build-nodes/project-json.js +1 -0
- package/src/plugins/target-defaults/symbols.d.ts +17 -0
- package/src/plugins/target-defaults/symbols.js +20 -0
- package/src/plugins/target-defaults/target-defaults-plugin.d.ts +2 -18
- package/src/plugins/target-defaults/target-defaults-plugin.js +5 -20
- package/src/project-graph/affected/locators/project-glob-changes.js +3 -3
- package/src/project-graph/build-project-graph.d.ts +2 -1
- package/src/project-graph/build-project-graph.js +11 -13
- package/src/project-graph/error-types.d.ts +34 -0
- package/src/project-graph/error-types.js +65 -0
- package/src/project-graph/file-utils.js +3 -3
- package/src/project-graph/plugins/index.d.ts +2 -0
- package/src/project-graph/plugins/index.js +8 -0
- package/src/project-graph/plugins/internal-api.d.ts +28 -0
- package/src/project-graph/plugins/internal-api.js +85 -0
- package/src/project-graph/plugins/isolation/index.d.ts +3 -0
- package/src/project-graph/plugins/isolation/index.js +16 -0
- package/src/project-graph/plugins/isolation/messaging.d.ts +94 -0
- package/src/project-graph/plugins/isolation/messaging.js +23 -0
- package/src/project-graph/plugins/isolation/plugin-pool.d.ts +3 -0
- package/src/project-graph/plugins/isolation/plugin-pool.js +189 -0
- package/src/project-graph/plugins/isolation/plugin-worker.d.ts +1 -0
- package/src/project-graph/plugins/isolation/plugin-worker.js +81 -0
- package/src/project-graph/plugins/loader.d.ts +24 -0
- package/src/project-graph/plugins/loader.js +206 -0
- package/src/{utils/nx-plugin.d.ts → project-graph/plugins/public-api.d.ts} +8 -44
- package/src/project-graph/plugins/public-api.js +4 -0
- package/src/project-graph/plugins/utils.d.ts +7 -0
- package/src/project-graph/plugins/utils.js +88 -0
- package/src/project-graph/project-graph-builder.d.ts +1 -1
- package/src/project-graph/project-graph.d.ts +3 -2
- package/src/project-graph/project-graph.js +9 -7
- package/src/project-graph/utils/normalize-project-nodes.d.ts +1 -1
- package/src/project-graph/utils/project-configuration-utils.d.ts +3 -26
- package/src/project-graph/utils/project-configuration-utils.js +29 -97
- package/src/project-graph/utils/retrieve-workspace-files.d.ts +11 -10
- package/src/project-graph/utils/retrieve-workspace-files.js +18 -21
- package/src/tasks-runner/cache.js +1 -1
- package/src/utils/logger.d.ts +1 -0
- package/src/utils/logger.js +5 -0
- package/src/utils/nx-plugin.deprecated.d.ts +2 -2
- package/src/utils/nx-plugin.deprecated.js +5 -7
- package/src/utils/plugins/plugin-capabilities.d.ts +1 -1
- package/src/utils/plugins/plugin-capabilities.js +18 -12
- package/src/utils/nx-plugin.js +0 -309
@@ -2,15 +2,13 @@
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.configurationGlobs = exports.retrieveProjectConfigurationsWithoutPluginInference = exports.retrieveProjectConfigurationPaths = exports.retrieveProjectConfigurationsWithAngularProjects = exports.retrieveProjectConfigurations = exports.retrieveWorkspaceFiles = void 0;
|
4
4
|
const perf_hooks_1 = require("perf_hooks");
|
5
|
-
const installation_directory_1 = require("../../utils/installation-directory");
|
6
5
|
const angular_json_1 = require("../../adapter/angular-json");
|
7
6
|
const nx_json_1 = require("../../config/nx-json");
|
8
|
-
const package_json_workspaces_1 = require("../../plugins/package-json-workspaces");
|
9
7
|
const project_configuration_utils_1 = require("./project-configuration-utils");
|
10
|
-
const
|
11
|
-
const project_json_1 = require("../../plugins/project-json/build-nodes/project-json");
|
8
|
+
const internal_api_1 = require("../plugins/internal-api");
|
12
9
|
const workspace_context_1 = require("../../utils/workspace-context");
|
13
10
|
const build_all_workspace_files_1 = require("./build-all-workspace-files");
|
11
|
+
const path_1 = require("path");
|
14
12
|
/**
|
15
13
|
* Walks the workspace directory to create the `projectFileMap`, `ProjectConfigurations` and `allWorkspaceFiles`
|
16
14
|
* @throws
|
@@ -37,22 +35,23 @@ async function retrieveWorkspaceFiles(workspaceRoot, projectRootMap) {
|
|
37
35
|
exports.retrieveWorkspaceFiles = retrieveWorkspaceFiles;
|
38
36
|
/**
|
39
37
|
* Walk through the workspace and return `ProjectConfigurations`. Only use this if the projectFileMap is not needed.
|
40
|
-
*
|
41
|
-
* @param workspaceRoot
|
42
|
-
* @param nxJson
|
43
38
|
*/
|
44
|
-
async function retrieveProjectConfigurations(workspaceRoot, nxJson) {
|
45
|
-
const
|
46
|
-
return
|
39
|
+
async function retrieveProjectConfigurations(plugins, workspaceRoot, nxJson) {
|
40
|
+
const projects = await _retrieveProjectConfigurations(workspaceRoot, nxJson, plugins);
|
41
|
+
return projects;
|
47
42
|
}
|
48
43
|
exports.retrieveProjectConfigurations = retrieveProjectConfigurations;
|
49
44
|
async function retrieveProjectConfigurationsWithAngularProjects(workspaceRoot, nxJson) {
|
50
|
-
const
|
45
|
+
const pluginsToLoad = nxJson?.plugins ?? [];
|
51
46
|
if ((0, angular_json_1.shouldMergeAngularProjects)(workspaceRoot, true) &&
|
52
|
-
!
|
53
|
-
|
47
|
+
!pluginsToLoad.some((p) => p === angular_json_1.NX_ANGULAR_JSON_PLUGIN_NAME ||
|
48
|
+
(typeof p === 'object' && p.plugin === angular_json_1.NX_ANGULAR_JSON_PLUGIN_NAME))) {
|
49
|
+
pluginsToLoad.push((0, path_1.join)(__dirname, '../../adapter/angular-json'));
|
54
50
|
}
|
55
|
-
|
51
|
+
const [plugins, cleanup] = await (0, internal_api_1.loadNxPlugins)(nxJson?.plugins ?? [], workspaceRoot);
|
52
|
+
const res = _retrieveProjectConfigurations(workspaceRoot, nxJson, plugins);
|
53
|
+
cleanup();
|
54
|
+
return res;
|
56
55
|
}
|
57
56
|
exports.retrieveProjectConfigurationsWithAngularProjects = retrieveProjectConfigurationsWithAngularProjects;
|
58
57
|
function _retrieveProjectConfigurations(workspaceRoot, nxJson, plugins) {
|
@@ -69,25 +68,23 @@ const projectsWithoutPluginCache = new Map();
|
|
69
68
|
// TODO: This function is called way too often, it should be optimized without this cache
|
70
69
|
async function retrieveProjectConfigurationsWithoutPluginInference(root) {
|
71
70
|
const nxJson = (0, nx_json_1.readNxJson)(root);
|
72
|
-
const plugins = await (0,
|
71
|
+
const [plugins, cleanup] = await (0, internal_api_1.loadNxPlugins)([]); // only load default plugins
|
73
72
|
const projectGlobPatterns = retrieveProjectConfigurationPaths(root, plugins);
|
74
73
|
const cacheKey = root + ',' + projectGlobPatterns.join(',');
|
75
74
|
if (projectsWithoutPluginCache.has(cacheKey)) {
|
76
75
|
return projectsWithoutPluginCache.get(cacheKey);
|
77
76
|
}
|
78
77
|
const projectFiles = (0, workspace_context_1.globWithWorkspaceContext)(root, projectGlobPatterns) ?? [];
|
79
|
-
const { projects } = await (0, project_configuration_utils_1.createProjectConfigurations)(root, nxJson, projectFiles,
|
80
|
-
{ plugin: (0, package_json_workspaces_1.getNxPackageJsonWorkspacesPlugin)(root) },
|
81
|
-
{ plugin: project_json_1.ProjectJsonProjectsPlugin },
|
82
|
-
]);
|
78
|
+
const { projects } = await (0, project_configuration_utils_1.createProjectConfigurations)(root, nxJson, projectFiles, plugins);
|
83
79
|
projectsWithoutPluginCache.set(cacheKey, projects);
|
80
|
+
cleanup();
|
84
81
|
return projects;
|
85
82
|
}
|
86
83
|
exports.retrieveProjectConfigurationsWithoutPluginInference = retrieveProjectConfigurationsWithoutPluginInference;
|
87
84
|
function configurationGlobs(plugins) {
|
88
85
|
const globPatterns = [];
|
89
|
-
for (const
|
90
|
-
if (plugin.createNodes) {
|
86
|
+
for (const plugin of plugins) {
|
87
|
+
if ('createNodes' in plugin && plugin.createNodes) {
|
91
88
|
globPatterns.push(plugin.createNodes[0]);
|
92
89
|
}
|
93
90
|
}
|
@@ -197,7 +197,7 @@ class Cache {
|
|
197
197
|
`The local cache artifact in "${td}" was not generated on this machine.`,
|
198
198
|
`As a result, the cache's content integrity cannot be confirmed, which may make cache restoration potentially unsafe.`,
|
199
199
|
`If your machine ID has changed since the artifact was cached, run "nx reset" to fix this issue.`,
|
200
|
-
`Read about the error and how to address it here: https://nx.dev/
|
200
|
+
`Read about the error and how to address it here: https://nx.dev/troubleshooting/unknown-local-cache`,
|
201
201
|
``,
|
202
202
|
].join('\n');
|
203
203
|
throw new Error(error);
|
package/src/utils/logger.d.ts
CHANGED
package/src/utils/logger.js
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
import { ProjectGraphProcessor } from '../config/project-graph';
|
2
2
|
import { TargetConfiguration } from '../config/workspace-json-project-json';
|
3
|
-
import {
|
3
|
+
import { NxPluginV2 } from '../project-graph/plugins';
|
4
4
|
/**
|
5
5
|
* @deprecated Add targets to the projects in a {@link CreateNodes} function instead. This will be removed in Nx 19
|
6
6
|
*/
|
@@ -28,4 +28,4 @@ export type NxPluginV1 = {
|
|
28
28
|
/**
|
29
29
|
* @todo(@agentender) v19: Remove this fn when we remove readWorkspaceConfig
|
30
30
|
*/
|
31
|
-
export declare function getDefaultPluginsSync(root: string):
|
31
|
+
export declare function getDefaultPluginsSync(root: string): NxPluginV2[];
|
@@ -4,7 +4,7 @@ exports.getDefaultPluginsSync = void 0;
|
|
4
4
|
const angular_json_1 = require("../adapter/angular-json");
|
5
5
|
const project_json_1 = require("../plugins/project-json/build-nodes/project-json");
|
6
6
|
const target_defaults_plugin_1 = require("../plugins/target-defaults/target-defaults-plugin");
|
7
|
-
const
|
7
|
+
const PackageJsonWorkspacesPlugin = require("../plugins/package-json-workspaces");
|
8
8
|
/**
|
9
9
|
* @todo(@agentender) v19: Remove this fn when we remove readWorkspaceConfig
|
10
10
|
*/
|
@@ -14,12 +14,10 @@ function getDefaultPluginsSync(root) {
|
|
14
14
|
...((0, angular_json_1.shouldMergeAngularProjects)(root, false)
|
15
15
|
? [require('../adapter/angular-json').NxAngularJsonPlugin]
|
16
16
|
: []),
|
17
|
-
target_defaults_plugin_1.
|
18
|
-
|
19
|
-
project_json_1.
|
17
|
+
target_defaults_plugin_1.default,
|
18
|
+
PackageJsonWorkspacesPlugin,
|
19
|
+
project_json_1.default,
|
20
20
|
];
|
21
|
-
return plugins
|
22
|
-
plugin: p,
|
23
|
-
}));
|
21
|
+
return plugins;
|
24
22
|
}
|
25
23
|
exports.getDefaultPluginsSync = getDefaultPluginsSync;
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import type { PluginCapabilities } from './models';
|
2
1
|
import { ProjectConfiguration } from '../../config/workspace-json-project-json';
|
2
|
+
import type { PluginCapabilities } from './models';
|
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,15 +1,16 @@
|
|
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");
|
5
4
|
const chalk = require("chalk");
|
6
5
|
const path_1 = require("path");
|
7
|
-
const
|
8
|
-
const
|
6
|
+
const plugins_1 = require("../../project-graph/plugins");
|
7
|
+
const loader_1 = require("../../project-graph/plugins/loader");
|
9
8
|
const fileutils_1 = require("../fileutils");
|
10
|
-
const package_manager_1 = require("../package-manager");
|
11
|
-
const nx_plugin_1 = require("../nx-plugin");
|
12
9
|
const installation_directory_1 = require("../installation-directory");
|
10
|
+
const output_1 = require("../output");
|
11
|
+
const package_manager_1 = require("../package-manager");
|
12
|
+
const workspace_root_1 = require("../workspace-root");
|
13
|
+
const shared_1 = require("./shared");
|
13
14
|
function tryGetCollection(packageJsonPath, collectionFile, propName) {
|
14
15
|
if (!collectionFile) {
|
15
16
|
return null;
|
@@ -24,9 +25,9 @@ function tryGetCollection(packageJsonPath, collectionFile, propName) {
|
|
24
25
|
}
|
25
26
|
async function getPluginCapabilities(workspaceRoot, pluginName, projects, includeRuntimeCapabilities = false) {
|
26
27
|
try {
|
27
|
-
const { json: packageJson, path: packageJsonPath } = await (0,
|
28
|
+
const { json: packageJson, path: packageJsonPath } = await (0, plugins_1.readPluginPackageJson)(pluginName, projects, (0, installation_directory_1.getNxRequirePaths)(workspaceRoot));
|
28
29
|
const pluginModule = includeRuntimeCapabilities
|
29
|
-
? await tryGetModule(packageJson, workspaceRoot
|
30
|
+
? await tryGetModule(packageJson, workspaceRoot)
|
30
31
|
: {};
|
31
32
|
return {
|
32
33
|
name: pluginName,
|
@@ -56,17 +57,22 @@ async function getPluginCapabilities(workspaceRoot, pluginName, projects, includ
|
|
56
57
|
}
|
57
58
|
}
|
58
59
|
exports.getPluginCapabilities = getPluginCapabilities;
|
59
|
-
async function tryGetModule(packageJson, workspaceRoot
|
60
|
+
async function tryGetModule(packageJson, workspaceRoot) {
|
60
61
|
try {
|
61
|
-
|
62
|
+
if (packageJson.generators ??
|
62
63
|
packageJson.executors ??
|
63
64
|
packageJson['nx-migrations'] ??
|
64
65
|
packageJson['schematics'] ??
|
65
|
-
packageJson['builders'])
|
66
|
-
|
67
|
-
|
66
|
+
packageJson['builders']) {
|
67
|
+
const [pluginPromise] = (0, loader_1.loadNxPlugin)(packageJson.name, workspaceRoot);
|
68
|
+
const plugin = await pluginPromise;
|
69
|
+
return plugin;
|
70
|
+
}
|
71
|
+
else {
|
72
|
+
return {
|
68
73
|
name: packageJson.name,
|
69
74
|
};
|
75
|
+
}
|
70
76
|
}
|
71
77
|
catch {
|
72
78
|
return null;
|
package/src/utils/nx-plugin.js
DELETED
@@ -1,309 +0,0 @@
|
|
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
|
-
const include = typeof pluginConfiguration === 'object'
|
75
|
-
? pluginConfiguration.include
|
76
|
-
: undefined;
|
77
|
-
const exclude = typeof pluginConfiguration === 'object'
|
78
|
-
? pluginConfiguration.exclude
|
79
|
-
: undefined;
|
80
|
-
if (pluginModule) {
|
81
|
-
return {
|
82
|
-
plugin: pluginModule,
|
83
|
-
options,
|
84
|
-
include,
|
85
|
-
exclude,
|
86
|
-
};
|
87
|
-
}
|
88
|
-
performance.mark(`Load Nx Plugin: ${moduleName} - start`);
|
89
|
-
let { pluginPath, name } = await getPluginPathAndName(moduleName, paths, projects, root);
|
90
|
-
const plugin = ensurePluginIsV2((await Promise.resolve(`${pluginPath}`).then(s => require(s))));
|
91
|
-
plugin.name ??= name;
|
92
|
-
exports.nxPluginCache.set(moduleName, plugin);
|
93
|
-
performance.mark(`Load Nx Plugin: ${moduleName} - end`);
|
94
|
-
performance.measure(`Load Nx Plugin: ${moduleName}`, `Load Nx Plugin: ${moduleName} - start`, `Load Nx Plugin: ${moduleName} - end`);
|
95
|
-
return {
|
96
|
-
plugin,
|
97
|
-
options,
|
98
|
-
include,
|
99
|
-
exclude,
|
100
|
-
};
|
101
|
-
}
|
102
|
-
exports.loadNxPluginAsync = loadNxPluginAsync;
|
103
|
-
async function loadNxPlugins(plugins, paths = (0, installation_directory_1.getNxRequirePaths)(), root = workspace_root_1.workspaceRoot, projects) {
|
104
|
-
const result = [
|
105
|
-
{ plugin: package_json_next_to_project_json_1.PackageJsonProjectsNextToProjectJsonPlugin },
|
106
|
-
];
|
107
|
-
plugins ??= [];
|
108
|
-
// When loading plugins for `createNodes`, we don't know what projects exist yet.
|
109
|
-
// Try resolving plugins
|
110
|
-
for (const plugin of plugins) {
|
111
|
-
try {
|
112
|
-
require.resolve(typeof plugin === 'string' ? plugin : plugin.plugin);
|
113
|
-
}
|
114
|
-
catch {
|
115
|
-
// If a plugin cannot be resolved, we will need projects to resolve it
|
116
|
-
projects ??= await (0, retrieve_workspace_files_1.retrieveProjectConfigurationsWithoutPluginInference)(root);
|
117
|
-
break;
|
118
|
-
}
|
119
|
-
}
|
120
|
-
for (const plugin of plugins) {
|
121
|
-
result.push(await loadNxPluginAsync(plugin, paths, projects, root));
|
122
|
-
}
|
123
|
-
// We push the nx core node plugins onto the end, s.t. it overwrites any other plugins
|
124
|
-
result.push(...(await getDefaultPlugins(root)));
|
125
|
-
return result;
|
126
|
-
}
|
127
|
-
exports.loadNxPlugins = loadNxPlugins;
|
128
|
-
function ensurePluginIsV2(plugin) {
|
129
|
-
if (isNxPluginV2(plugin)) {
|
130
|
-
return plugin;
|
131
|
-
}
|
132
|
-
if (isNxPluginV1(plugin) && plugin.projectFilePatterns) {
|
133
|
-
return {
|
134
|
-
...plugin,
|
135
|
-
createNodes: [
|
136
|
-
`*/**/${(0, globs_1.combineGlobPatterns)(plugin.projectFilePatterns)}`,
|
137
|
-
(configFilePath) => {
|
138
|
-
const root = (0, path_2.dirname)(configFilePath);
|
139
|
-
return {
|
140
|
-
projects: {
|
141
|
-
[root]: {
|
142
|
-
name: (0, workspaces_1.toProjectName)(configFilePath),
|
143
|
-
root,
|
144
|
-
targets: plugin.registerProjectTargets?.(configFilePath),
|
145
|
-
},
|
146
|
-
},
|
147
|
-
};
|
148
|
-
},
|
149
|
-
],
|
150
|
-
};
|
151
|
-
}
|
152
|
-
return plugin;
|
153
|
-
}
|
154
|
-
exports.ensurePluginIsV2 = ensurePluginIsV2;
|
155
|
-
function isNxPluginV2(plugin) {
|
156
|
-
return 'createNodes' in plugin || 'createDependencies' in plugin;
|
157
|
-
}
|
158
|
-
exports.isNxPluginV2 = isNxPluginV2;
|
159
|
-
function isNxPluginV1(plugin) {
|
160
|
-
return 'processProjectGraph' in plugin || 'projectFilePatterns' in plugin;
|
161
|
-
}
|
162
|
-
exports.isNxPluginV1 = isNxPluginV1;
|
163
|
-
function readPluginPackageJson(pluginName, projects, paths = (0, installation_directory_1.getNxRequirePaths)()) {
|
164
|
-
try {
|
165
|
-
const result = (0, package_json_1.readModulePackageJsonWithoutFallbacks)(pluginName, paths);
|
166
|
-
return {
|
167
|
-
json: result.packageJson,
|
168
|
-
path: result.path,
|
169
|
-
};
|
170
|
-
}
|
171
|
-
catch (e) {
|
172
|
-
if (e.code === 'MODULE_NOT_FOUND') {
|
173
|
-
const nxJson = (0, nx_json_1.readNxJson)();
|
174
|
-
const localPluginPath = resolveLocalNxPlugin(pluginName, nxJson, projects);
|
175
|
-
if (localPluginPath) {
|
176
|
-
const localPluginPackageJson = path.join(localPluginPath.path, 'package.json');
|
177
|
-
return {
|
178
|
-
path: localPluginPackageJson,
|
179
|
-
json: (0, fileutils_1.readJsonFile)(localPluginPackageJson),
|
180
|
-
};
|
181
|
-
}
|
182
|
-
}
|
183
|
-
throw e;
|
184
|
-
}
|
185
|
-
}
|
186
|
-
exports.readPluginPackageJson = readPluginPackageJson;
|
187
|
-
/**
|
188
|
-
* Builds a plugin package and returns the path to output
|
189
|
-
* @param importPath What is the import path that refers to a potential plugin?
|
190
|
-
* @returns The path to the built plugin, or null if it doesn't exist
|
191
|
-
*/
|
192
|
-
const localPluginCache = {};
|
193
|
-
function resolveLocalNxPlugin(importPath, nxJsonConfiguration, projects, root = workspace_root_1.workspaceRoot) {
|
194
|
-
localPluginCache[importPath] ??= lookupLocalPlugin(importPath, nxJsonConfiguration, projects, root);
|
195
|
-
return localPluginCache[importPath];
|
196
|
-
}
|
197
|
-
exports.resolveLocalNxPlugin = resolveLocalNxPlugin;
|
198
|
-
let tsNodeAndPathsUnregisterCallback = undefined;
|
199
|
-
/**
|
200
|
-
* Register swc-node or ts-node if they are not currently registered
|
201
|
-
* with some default settings which work well for Nx plugins.
|
202
|
-
*/
|
203
|
-
function registerPluginTSTranspiler() {
|
204
|
-
if (!tsNodeAndPathsUnregisterCallback) {
|
205
|
-
// nx-ignore-next-line
|
206
|
-
const ts = require('typescript');
|
207
|
-
// Get the first tsconfig that matches the allowed set
|
208
|
-
const tsConfigName = [
|
209
|
-
(0, path_2.join)(workspace_root_1.workspaceRoot, 'tsconfig.base.json'),
|
210
|
-
(0, path_2.join)(workspace_root_1.workspaceRoot, 'tsconfig.json'),
|
211
|
-
].find((x) => (0, fs_1.existsSync)(x));
|
212
|
-
const tsConfig = tsConfigName
|
213
|
-
? (0, typescript_1.readTsConfig)(tsConfigName)
|
214
|
-
: {};
|
215
|
-
const unregisterTsConfigPaths = (0, register_1.registerTsConfigPaths)(tsConfigName);
|
216
|
-
const unregisterTranspiler = (0, register_1.registerTranspiler)({
|
217
|
-
experimentalDecorators: true,
|
218
|
-
emitDecoratorMetadata: true,
|
219
|
-
...tsConfig.options,
|
220
|
-
});
|
221
|
-
tsNodeAndPathsUnregisterCallback = () => {
|
222
|
-
unregisterTsConfigPaths();
|
223
|
-
unregisterTranspiler();
|
224
|
-
};
|
225
|
-
}
|
226
|
-
}
|
227
|
-
exports.registerPluginTSTranspiler = registerPluginTSTranspiler;
|
228
|
-
/**
|
229
|
-
* Unregister the ts-node transpiler if it is registered
|
230
|
-
*/
|
231
|
-
function unregisterPluginTSTranspiler() {
|
232
|
-
if (tsNodeAndPathsUnregisterCallback) {
|
233
|
-
tsNodeAndPathsUnregisterCallback();
|
234
|
-
tsNodeAndPathsUnregisterCallback = undefined;
|
235
|
-
}
|
236
|
-
}
|
237
|
-
exports.unregisterPluginTSTranspiler = unregisterPluginTSTranspiler;
|
238
|
-
function lookupLocalPlugin(importPath, nxJsonConfiguration, projects, root = workspace_root_1.workspaceRoot) {
|
239
|
-
const plugin = findNxProjectForImportPath(importPath, projects, root);
|
240
|
-
if (!plugin) {
|
241
|
-
return null;
|
242
|
-
}
|
243
|
-
if (!tsNodeAndPathsUnregisterCallback) {
|
244
|
-
registerPluginTSTranspiler();
|
245
|
-
}
|
246
|
-
const projectConfig = projects[plugin];
|
247
|
-
return { path: path.join(root, projectConfig.root), projectConfig };
|
248
|
-
}
|
249
|
-
function findNxProjectForImportPath(importPath, projects, root = workspace_root_1.workspaceRoot) {
|
250
|
-
const tsConfigPaths = readTsConfigPaths(root);
|
251
|
-
const possiblePaths = tsConfigPaths[importPath]?.map((p) => (0, path_1.normalizePath)(path.relative(root, path.join(root, p))));
|
252
|
-
if (possiblePaths?.length) {
|
253
|
-
const projectRootMappings = (0, find_project_for_path_1.createProjectRootMappingsFromProjectConfigurations)(projects);
|
254
|
-
for (const tsConfigPath of possiblePaths) {
|
255
|
-
const nxProject = (0, find_project_for_path_1.findProjectForPath)(tsConfigPath, projectRootMappings);
|
256
|
-
if (nxProject) {
|
257
|
-
return nxProject;
|
258
|
-
}
|
259
|
-
}
|
260
|
-
if (process.env.NX_VERBOSE_LOGGING) {
|
261
|
-
console.log('Unable to find local plugin', possiblePaths, projectRootMappings);
|
262
|
-
}
|
263
|
-
throw new Error('Unable to resolve local plugin with import path ' + importPath);
|
264
|
-
}
|
265
|
-
}
|
266
|
-
let tsconfigPaths;
|
267
|
-
function readTsConfigPaths(root = workspace_root_1.workspaceRoot) {
|
268
|
-
if (!tsconfigPaths) {
|
269
|
-
const tsconfigPath = ['tsconfig.base.json', 'tsconfig.json']
|
270
|
-
.map((x) => path.join(root, x))
|
271
|
-
.filter((x) => (0, fs_1.existsSync)(x))[0];
|
272
|
-
if (!tsconfigPath) {
|
273
|
-
throw new Error('unable to find tsconfig.base.json or tsconfig.json');
|
274
|
-
}
|
275
|
-
const { compilerOptions } = (0, fileutils_1.readJsonFile)(tsconfigPath);
|
276
|
-
tsconfigPaths = compilerOptions?.paths;
|
277
|
-
}
|
278
|
-
return tsconfigPaths ?? {};
|
279
|
-
}
|
280
|
-
function readPluginMainFromProjectConfiguration(plugin) {
|
281
|
-
const { main } = Object.values(plugin.targets).find((x) => [
|
282
|
-
'@nx/js:tsc',
|
283
|
-
'@nrwl/js:tsc',
|
284
|
-
'@nx/js:swc',
|
285
|
-
'@nrwl/js:swc',
|
286
|
-
'@nx/node:package',
|
287
|
-
'@nrwl/node:package',
|
288
|
-
].includes(x.executor))?.options ||
|
289
|
-
plugin.targets?.build?.options ||
|
290
|
-
{};
|
291
|
-
return main;
|
292
|
-
}
|
293
|
-
async function getDefaultPlugins(root) {
|
294
|
-
const plugins = [
|
295
|
-
await Promise.resolve().then(() => require('../plugins/js')),
|
296
|
-
target_defaults_plugin_1.TargetDefaultsPlugin,
|
297
|
-
...((0, angular_json_1.shouldMergeAngularProjects)(root, false)
|
298
|
-
? [
|
299
|
-
await Promise.resolve().then(() => require('../adapter/angular-json')).then((m) => m.NxAngularJsonPlugin),
|
300
|
-
]
|
301
|
-
: []),
|
302
|
-
(0, package_json_workspaces_1.getNxPackageJsonWorkspacesPlugin)(root),
|
303
|
-
project_json_1.ProjectJsonProjectsPlugin,
|
304
|
-
];
|
305
|
-
return plugins.map((p) => ({
|
306
|
-
plugin: p,
|
307
|
-
}));
|
308
|
-
}
|
309
|
-
exports.getDefaultPlugins = getDefaultPlugins;
|