nx 20.4.2 → 20.4.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +11 -11
- package/src/adapter/compat.d.ts +1 -1
- package/src/adapter/compat.js +1 -0
- package/src/command-line/add/add.js +6 -16
- package/src/command-line/init/command-object.js +13 -6
- package/src/command-line/init/configure-plugins.d.ts +5 -6
- package/src/command-line/init/configure-plugins.js +13 -22
- package/src/command-line/init/implementation/add-nx-to-turborepo.d.ts +4 -0
- package/src/command-line/init/implementation/add-nx-to-turborepo.js +49 -0
- package/src/command-line/init/implementation/deduce-default-base.d.ts +1 -0
- package/src/command-line/init/implementation/deduce-default-base.js +53 -0
- package/src/command-line/init/implementation/utils.d.ts +3 -1
- package/src/command-line/init/implementation/utils.js +91 -42
- package/src/command-line/init/init-v2.js +34 -14
- package/src/config/nx-json.d.ts +1 -0
- package/src/daemon/client/client.d.ts +1 -0
- package/src/daemon/client/client.js +8 -0
- package/src/daemon/message-types/glob.d.ts +7 -0
- package/src/daemon/message-types/glob.js +9 -1
- package/src/daemon/server/handle-glob.d.ts +1 -0
- package/src/daemon/server/handle-glob.js +8 -0
- package/src/daemon/server/server.js +3 -0
- package/src/native/index.d.ts +7 -0
- package/src/native/nx.wasi.cjs +7 -7
- package/src/native/nx.wasm32-wasi.wasm +0 -0
- package/src/project-graph/affected/locators/project-glob-changes.js +2 -2
- package/src/project-graph/error-types.js +4 -1
- package/src/project-graph/plugins/get-plugins.js +2 -1
- package/src/project-graph/plugins/loaded-nx-plugin.d.ts +1 -0
- package/src/project-graph/project-graph.js +1 -1
- package/src/project-graph/utils/project-configuration-utils.d.ts +1 -1
- package/src/project-graph/utils/project-configuration-utils.js +11 -9
- package/src/project-graph/utils/retrieve-workspace-files.d.ts +1 -1
- package/src/project-graph/utils/retrieve-workspace-files.js +14 -18
- package/src/utils/workspace-context.d.ts +1 -0
- package/src/utils/workspace-context.js +8 -0
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "nx",
|
3
|
-
"version": "20.4.
|
3
|
+
"version": "20.4.4",
|
4
4
|
"private": false,
|
5
5
|
"description": "The core Nx plugin contains the core functionality of Nx like the project graph, nx commands and task orchestration.",
|
6
6
|
"repository": {
|
@@ -82,16 +82,16 @@
|
|
82
82
|
}
|
83
83
|
},
|
84
84
|
"optionalDependencies": {
|
85
|
-
"@nx/nx-darwin-arm64": "20.4.
|
86
|
-
"@nx/nx-darwin-x64": "20.4.
|
87
|
-
"@nx/nx-freebsd-x64": "20.4.
|
88
|
-
"@nx/nx-linux-arm-gnueabihf": "20.4.
|
89
|
-
"@nx/nx-linux-arm64-gnu": "20.4.
|
90
|
-
"@nx/nx-linux-arm64-musl": "20.4.
|
91
|
-
"@nx/nx-linux-x64-gnu": "20.4.
|
92
|
-
"@nx/nx-linux-x64-musl": "20.4.
|
93
|
-
"@nx/nx-win32-arm64-msvc": "20.4.
|
94
|
-
"@nx/nx-win32-x64-msvc": "20.4.
|
85
|
+
"@nx/nx-darwin-arm64": "20.4.4",
|
86
|
+
"@nx/nx-darwin-x64": "20.4.4",
|
87
|
+
"@nx/nx-freebsd-x64": "20.4.4",
|
88
|
+
"@nx/nx-linux-arm-gnueabihf": "20.4.4",
|
89
|
+
"@nx/nx-linux-arm64-gnu": "20.4.4",
|
90
|
+
"@nx/nx-linux-arm64-musl": "20.4.4",
|
91
|
+
"@nx/nx-linux-x64-gnu": "20.4.4",
|
92
|
+
"@nx/nx-linux-x64-musl": "20.4.4",
|
93
|
+
"@nx/nx-win32-arm64-msvc": "20.4.4",
|
94
|
+
"@nx/nx-win32-x64-msvc": "20.4.4"
|
95
95
|
},
|
96
96
|
"nx-migrations": {
|
97
97
|
"migrations": "./migrations.json",
|
package/src/adapter/compat.d.ts
CHANGED
@@ -1,2 +1,2 @@
|
|
1
1
|
export declare const allowedProjectExtensions: readonly ["tags", "implicitDependencies", "configFilePath", "$schema", "generators", "namedInputs", "name", "files", "root", "sourceRoot", "projectType", "release", "includedScripts", "metadata"];
|
2
|
-
export declare const allowedWorkspaceExtensions: readonly ["implicitDependencies", "affected", "defaultBase", "tasksRunnerOptions", "workspaceLayout", "plugins", "targetDefaults", "files", "generators", "namedInputs", "extends", "cli", "pluginsConfig", "defaultProject", "installation", "release", "nxCloudAccessToken", "nxCloudId", "nxCloudUrl", "nxCloudEncryptionKey", "parallel", "cacheDirectory", "useDaemonProcess", "useInferencePlugins", "neverConnectToCloud", "sync", "useLegacyCache"];
|
2
|
+
export declare const allowedWorkspaceExtensions: readonly ["$schema", "implicitDependencies", "affected", "defaultBase", "tasksRunnerOptions", "workspaceLayout", "plugins", "targetDefaults", "files", "generators", "namedInputs", "extends", "cli", "pluginsConfig", "defaultProject", "installation", "release", "nxCloudAccessToken", "nxCloudId", "nxCloudUrl", "nxCloudEncryptionKey", "parallel", "cacheDirectory", "useDaemonProcess", "useInferencePlugins", "neverConnectToCloud", "sync", "useLegacyCache"];
|
package/src/adapter/compat.js
CHANGED
@@ -37,6 +37,7 @@ exports.allowedProjectExtensions = [
|
|
37
37
|
// There are some props in here (root) that angular already knows about,
|
38
38
|
// but it doesn't hurt to have them in here as well to help static analysis.
|
39
39
|
exports.allowedWorkspaceExtensions = [
|
40
|
+
'$schema',
|
40
41
|
'implicitDependencies',
|
41
42
|
'affected',
|
42
43
|
'defaultBase',
|
@@ -5,7 +5,6 @@ exports.addHandler = addHandler;
|
|
5
5
|
const child_process_1 = require("child_process");
|
6
6
|
const fs_1 = require("fs");
|
7
7
|
const ora = require("ora");
|
8
|
-
const yargsParser = require("yargs-parser");
|
9
8
|
const nx_json_1 = require("../../config/nx-json");
|
10
9
|
const child_process_2 = require("../../utils/child-process");
|
11
10
|
const fileutils_1 = require("../../utils/fileutils");
|
@@ -79,27 +78,18 @@ async function installPackage(pkgName, version, nxJson) {
|
|
79
78
|
spinner.succeed();
|
80
79
|
}
|
81
80
|
async function initializePlugin(pkgName, options, nxJson) {
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
'parse-positional-numbers': false,
|
86
|
-
'dot-notation': false,
|
87
|
-
'camel-case-expansion': false,
|
88
|
-
},
|
89
|
-
});
|
90
|
-
if (exports.coreNxPluginVersions.has(pkgName)) {
|
91
|
-
parsedCommandArgs.keepExistingVersions = true;
|
92
|
-
if (options.updatePackageScripts ||
|
81
|
+
let updatePackageScripts = false;
|
82
|
+
if (exports.coreNxPluginVersions.has(pkgName) &&
|
83
|
+
(options.updatePackageScripts ||
|
93
84
|
(options.updatePackageScripts === undefined &&
|
94
85
|
nxJson.useInferencePlugins !== false &&
|
95
|
-
process.env.NX_ADD_PLUGINS !== 'false')) {
|
96
|
-
|
97
|
-
}
|
86
|
+
process.env.NX_ADD_PLUGINS !== 'false'))) {
|
87
|
+
updatePackageScripts = true;
|
98
88
|
}
|
99
89
|
const spinner = ora(`Initializing ${pkgName}...`);
|
100
90
|
spinner.start();
|
101
91
|
try {
|
102
|
-
await (0, configure_plugins_1.installPlugin)(pkgName, workspace_root_1.workspaceRoot, options.verbose
|
92
|
+
await (0, configure_plugins_1.installPlugin)(pkgName, workspace_root_1.workspaceRoot, updatePackageScripts, options.verbose);
|
103
93
|
}
|
104
94
|
catch (e) {
|
105
95
|
spinner.fail();
|
@@ -7,14 +7,21 @@ exports.yargsInitCommand = {
|
|
7
7
|
describe: 'Adds Nx to any type of workspace. It installs nx, creates an nx.json configuration file and optionally sets up remote caching. For more info, check https://nx.dev/recipes/adopting-nx.',
|
8
8
|
builder: (yargs) => withInitOptions(yargs),
|
9
9
|
handler: async (args) => {
|
10
|
-
|
11
|
-
|
12
|
-
|
10
|
+
try {
|
11
|
+
const useV2 = await isInitV2();
|
12
|
+
if (useV2) {
|
13
|
+
await require('./init-v2').initHandler(args);
|
14
|
+
}
|
15
|
+
else {
|
16
|
+
await require('./init-v1').initHandler(args);
|
17
|
+
}
|
18
|
+
process.exit(0);
|
13
19
|
}
|
14
|
-
|
15
|
-
|
20
|
+
catch {
|
21
|
+
// Ensure the cursor is always restored just in case the user has bailed during interactive prompts
|
22
|
+
process.stdout.write('\x1b[?25h');
|
23
|
+
process.exit(1);
|
16
24
|
}
|
17
|
-
process.exit(0);
|
18
25
|
},
|
19
26
|
};
|
20
27
|
async function isInitV2() {
|
@@ -4,19 +4,18 @@ export declare function runPackageManagerInstallPlugins(repoRoot: string, pmc: P
|
|
4
4
|
* Installs a plugin by running its init generator. It will change the file system tree passed in.
|
5
5
|
* @param plugin The name of the plugin to install
|
6
6
|
* @param repoRoot repo root
|
7
|
-
* @param
|
8
|
-
* @param
|
7
|
+
* @param pmc package manager commands
|
8
|
+
* @param updatePackageScripts whether to update package scripts
|
9
|
+
* @param verbose whether to run in verbose mode
|
9
10
|
* @returns void
|
10
11
|
*/
|
11
|
-
export declare function installPlugin(plugin: string, repoRoot
|
12
|
-
[k: string]: any;
|
13
|
-
}): Promise<void>;
|
12
|
+
export declare function installPlugin(plugin: string, repoRoot?: string, updatePackageScripts?: boolean, verbose?: boolean, pmc?: PackageManagerCommands): Promise<void>;
|
14
13
|
/**
|
15
14
|
* Install plugins
|
16
15
|
* Get the implementation of the plugin's init generator and run it
|
17
16
|
* @returns a list of succeeded plugins and a map of failed plugins to errors
|
18
17
|
*/
|
19
|
-
export declare function installPlugins(plugins: string[], updatePackageScripts: boolean, repoRoot?: string, verbose?: boolean): Promise<{
|
18
|
+
export declare function installPlugins(plugins: string[], updatePackageScripts: boolean, pmc: PackageManagerCommands, repoRoot?: string, verbose?: boolean): Promise<{
|
20
19
|
succeededPlugins: string[];
|
21
20
|
failedPlugins: {
|
22
21
|
[plugin: string]: Error;
|
@@ -7,10 +7,9 @@ exports.configurePlugins = configurePlugins;
|
|
7
7
|
exports.getFailedToInstallPluginErrorMessages = getFailedToInstallPluginErrorMessages;
|
8
8
|
const createSpinner = require("ora");
|
9
9
|
const chalk_1 = require("chalk");
|
10
|
+
const child_process_1 = require("child_process");
|
10
11
|
const package_manager_1 = require("../../utils/package-manager");
|
11
12
|
const output_1 = require("../../utils/output");
|
12
|
-
const tree_1 = require("../../generators/tree");
|
13
|
-
const generator_utils_1 = require("../generate/generator-utils");
|
14
13
|
const workspace_root_1 = require("../../utils/workspace-root");
|
15
14
|
const utils_1 = require("./implementation/utils");
|
16
15
|
const plugins_1 = require("../../utils/plugins");
|
@@ -27,12 +26,12 @@ function runPackageManagerInstallPlugins(repoRoot, pmc = (0, package_manager_1.g
|
|
27
26
|
* Installs a plugin by running its init generator. It will change the file system tree passed in.
|
28
27
|
* @param plugin The name of the plugin to install
|
29
28
|
* @param repoRoot repo root
|
30
|
-
* @param
|
31
|
-
* @param
|
29
|
+
* @param pmc package manager commands
|
30
|
+
* @param updatePackageScripts whether to update package scripts
|
31
|
+
* @param verbose whether to run in verbose mode
|
32
32
|
* @returns void
|
33
33
|
*/
|
34
|
-
async function installPlugin(plugin, repoRoot = workspace_root_1.workspaceRoot, verbose = false,
|
35
|
-
const host = new tree_1.FsTree(repoRoot, verbose, `install ${plugin}`);
|
34
|
+
async function installPlugin(plugin, repoRoot = workspace_root_1.workspaceRoot, updatePackageScripts = false, verbose = false, pmc = (0, package_manager_1.getPackageManagerCommand)()) {
|
36
35
|
const capabilities = await (0, plugins_1.getPluginCapabilities)(repoRoot, plugin, {});
|
37
36
|
const generators = capabilities?.generators;
|
38
37
|
if (!generators) {
|
@@ -45,20 +44,18 @@ async function installPlugin(plugin, repoRoot = workspace_root_1.workspaceRoot,
|
|
45
44
|
});
|
46
45
|
return;
|
47
46
|
}
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
await task();
|
54
|
-
}
|
47
|
+
(0, child_process_1.execSync)(`${pmc.exec} nx g ${plugin}:init --keepExistingVersions ${updatePackageScripts ? '--updatePackageScripts' : ''} ${verbose ? '--verbose' : ''}`, {
|
48
|
+
stdio: [0, 1, 2],
|
49
|
+
cwd: repoRoot,
|
50
|
+
windowsHide: false,
|
51
|
+
});
|
55
52
|
}
|
56
53
|
/**
|
57
54
|
* Install plugins
|
58
55
|
* Get the implementation of the plugin's init generator and run it
|
59
56
|
* @returns a list of succeeded plugins and a map of failed plugins to errors
|
60
57
|
*/
|
61
|
-
async function installPlugins(plugins, updatePackageScripts, repoRoot = workspace_root_1.workspaceRoot, verbose = false) {
|
58
|
+
async function installPlugins(plugins, updatePackageScripts, pmc, repoRoot = workspace_root_1.workspaceRoot, verbose = false) {
|
62
59
|
if (plugins.length === 0) {
|
63
60
|
return {
|
64
61
|
succeededPlugins: [],
|
@@ -71,13 +68,7 @@ async function installPlugins(plugins, updatePackageScripts, repoRoot = workspac
|
|
71
68
|
for (const plugin of plugins) {
|
72
69
|
try {
|
73
70
|
spinner.start('Installing plugin ' + plugin);
|
74
|
-
await installPlugin(plugin, repoRoot, verbose,
|
75
|
-
keepExistingVersions: true,
|
76
|
-
updatePackageScripts,
|
77
|
-
addPlugin: true,
|
78
|
-
skipFormat: false,
|
79
|
-
skipPackageJson: false,
|
80
|
-
});
|
71
|
+
await installPlugin(plugin, repoRoot, updatePackageScripts, verbose, pmc);
|
81
72
|
succeededPlugins.push(plugin);
|
82
73
|
spinner.succeed('Installed plugin ' + plugin);
|
83
74
|
}
|
@@ -103,7 +94,7 @@ async function configurePlugins(plugins, updatePackageScripts, pmc, repoRoot = w
|
|
103
94
|
};
|
104
95
|
}
|
105
96
|
output_1.output.log({ title: '🔨 Configuring plugins' });
|
106
|
-
let { succeededPlugins, failedPlugins } = await installPlugins(plugins, updatePackageScripts, repoRoot, verbose);
|
97
|
+
let { succeededPlugins, failedPlugins } = await installPlugins(plugins, updatePackageScripts, pmc, repoRoot, verbose);
|
107
98
|
if (succeededPlugins.length > 0) {
|
108
99
|
output_1.output.success({
|
109
100
|
title: 'Installed Plugins',
|
@@ -0,0 +1,49 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.addNxToTurborepo = addNxToTurborepo;
|
4
|
+
const node_fs_1 = require("node:fs");
|
5
|
+
const node_path_1 = require("node:path");
|
6
|
+
const fileutils_1 = require("../../../utils/fileutils");
|
7
|
+
const output_1 = require("../../../utils/output");
|
8
|
+
const package_manager_1 = require("../../../utils/package-manager");
|
9
|
+
const utils_1 = require("./utils");
|
10
|
+
async function addNxToTurborepo(_options) {
|
11
|
+
const repoRoot = process.cwd();
|
12
|
+
output_1.output.log({
|
13
|
+
title: 'Initializing Nx based on your old Turborepo configuration',
|
14
|
+
});
|
15
|
+
output_1.output.log({
|
16
|
+
title: '💡 Did you know?',
|
17
|
+
bodyLines: [
|
18
|
+
'- Turborepo requires you to maintain all your common scripts like "build", "lint", "test" in all your packages, as well as their applicable cache inputs and outputs.',
|
19
|
+
`- Nx is extensible and has plugins for the tools you use to infer all of this for you purely based on that tool's configuration file within your packages.`,
|
20
|
+
'',
|
21
|
+
' - E.g. the `@nx/vite` plugin will infer the "build" script based on the existence of a vite.config.js file.',
|
22
|
+
' - Therefore with zero package level config, `nx build my-app` knows to run the `vite build` CLI directly, with all Nx cache inputs and outputs automatically inferred.',
|
23
|
+
'',
|
24
|
+
`NOTE: None of your existing package.json scripts will be modified as part of this initialization process, you can already use them as-is with Nx, but you can learn more about the benefits of Nx's inferred tasks at https://nx.dev/concepts/inferred-tasks`,
|
25
|
+
],
|
26
|
+
});
|
27
|
+
let nxJson = (0, utils_1.createNxJsonFromTurboJson)((0, fileutils_1.readJsonFile)('turbo.json'));
|
28
|
+
const nxJsonPath = (0, node_path_1.join)(repoRoot, 'nx.json');
|
29
|
+
// Turborepo workspaces usually have prettier installed, so try and match the formatting before writing the file
|
30
|
+
try {
|
31
|
+
const prettier = await Promise.resolve().then(() => require('prettier'));
|
32
|
+
const config = await prettier.resolveConfig(repoRoot);
|
33
|
+
(0, node_fs_1.writeFileSync)(nxJsonPath,
|
34
|
+
// @ts-ignore - Always await prettier.format, in modern versions it's async
|
35
|
+
await prettier.format(JSON.stringify(nxJson, null, 2), {
|
36
|
+
...(config ?? {}),
|
37
|
+
parser: 'json',
|
38
|
+
}));
|
39
|
+
}
|
40
|
+
catch (err) {
|
41
|
+
// Apply fallback JSON write
|
42
|
+
(0, fileutils_1.writeJsonFile)(nxJsonPath, nxJson);
|
43
|
+
}
|
44
|
+
const pmc = (0, package_manager_1.getPackageManagerCommand)();
|
45
|
+
(0, utils_1.updateGitIgnore)(repoRoot);
|
46
|
+
(0, utils_1.addDepsToPackageJson)(repoRoot);
|
47
|
+
output_1.output.log({ title: '📦 Installing dependencies' });
|
48
|
+
(0, utils_1.runInstall)(repoRoot, pmc);
|
49
|
+
}
|
@@ -0,0 +1 @@
|
|
1
|
+
export declare function deduceDefaultBase(): string;
|
@@ -0,0 +1,53 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.deduceDefaultBase = deduceDefaultBase;
|
4
|
+
const node_child_process_1 = require("node:child_process");
|
5
|
+
const default_base_1 = require("../../../utils/default-base");
|
6
|
+
function deduceDefaultBase() {
|
7
|
+
try {
|
8
|
+
(0, node_child_process_1.execSync)(`git rev-parse --verify main`, {
|
9
|
+
stdio: ['ignore', 'ignore', 'ignore'],
|
10
|
+
windowsHide: false,
|
11
|
+
});
|
12
|
+
return 'main';
|
13
|
+
}
|
14
|
+
catch {
|
15
|
+
try {
|
16
|
+
(0, node_child_process_1.execSync)(`git rev-parse --verify dev`, {
|
17
|
+
stdio: ['ignore', 'ignore', 'ignore'],
|
18
|
+
windowsHide: false,
|
19
|
+
});
|
20
|
+
return 'dev';
|
21
|
+
}
|
22
|
+
catch {
|
23
|
+
try {
|
24
|
+
(0, node_child_process_1.execSync)(`git rev-parse --verify develop`, {
|
25
|
+
stdio: ['ignore', 'ignore', 'ignore'],
|
26
|
+
windowsHide: false,
|
27
|
+
});
|
28
|
+
return 'develop';
|
29
|
+
}
|
30
|
+
catch {
|
31
|
+
try {
|
32
|
+
(0, node_child_process_1.execSync)(`git rev-parse --verify next`, {
|
33
|
+
stdio: ['ignore', 'ignore', 'ignore'],
|
34
|
+
windowsHide: false,
|
35
|
+
});
|
36
|
+
return 'next';
|
37
|
+
}
|
38
|
+
catch {
|
39
|
+
try {
|
40
|
+
(0, node_child_process_1.execSync)(`git rev-parse --verify master`, {
|
41
|
+
stdio: ['ignore', 'ignore', 'ignore'],
|
42
|
+
windowsHide: false,
|
43
|
+
});
|
44
|
+
return 'master';
|
45
|
+
}
|
46
|
+
catch {
|
47
|
+
return (0, default_base_1.deduceDefaultBase)();
|
48
|
+
}
|
49
|
+
}
|
50
|
+
}
|
51
|
+
}
|
52
|
+
}
|
53
|
+
}
|
@@ -1,12 +1,14 @@
|
|
1
|
+
import { NxJsonConfiguration } from '../../../config/nx-json';
|
1
2
|
import { PackageJson } from '../../../utils/package-json';
|
2
3
|
import { PackageManagerCommands } from '../../../utils/package-manager';
|
3
4
|
export declare function createNxJsonFile(repoRoot: string, topologicalTargets: string[], cacheableOperations: string[], scriptOutputs: {
|
4
5
|
[name: string]: string;
|
5
6
|
}): void;
|
7
|
+
export declare function createNxJsonFromTurboJson(turboJson: Record<string, any>): NxJsonConfiguration;
|
6
8
|
export declare function addDepsToPackageJson(repoRoot: string, additionalPackages?: string[]): void;
|
7
9
|
export declare function updateGitIgnore(root: string): void;
|
8
10
|
export declare function runInstall(repoRoot: string, pmc?: PackageManagerCommands): void;
|
9
|
-
export declare function initCloud(installationSource: 'nx-init' | 'nx-init-angular' | 'nx-init-cra' | 'nx-init-monorepo' | 'nx-init-nest' | 'nx-init-npm-repo'): Promise<void>;
|
11
|
+
export declare function initCloud(installationSource: 'nx-init' | 'nx-init-angular' | 'nx-init-cra' | 'nx-init-monorepo' | 'nx-init-nest' | 'nx-init-npm-repo' | 'nx-init-turborepo'): Promise<void>;
|
10
12
|
export declare function addVsCodeRecommendedExtensions(repoRoot: string, extensions: string[]): void;
|
11
13
|
export declare function markRootPackageJsonAsNxProjectLegacy(repoRoot: string, cacheableScripts: string[], pmc: PackageManagerCommands): void;
|
12
14
|
export declare function markPackageJsonAsNxProject(packageJsonPath: string): void;
|
@@ -1,6 +1,7 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.createNxJsonFile = createNxJsonFile;
|
4
|
+
exports.createNxJsonFromTurboJson = createNxJsonFromTurboJson;
|
4
5
|
exports.addDepsToPackageJson = addDepsToPackageJson;
|
5
6
|
exports.updateGitIgnore = updateGitIgnore;
|
6
7
|
exports.runInstall = runInstall;
|
@@ -21,7 +22,7 @@ const fs_1 = require("fs");
|
|
21
22
|
const connect_to_nx_cloud_1 = require("../../../nx-cloud/generators/connect-to-nx-cloud/connect-to-nx-cloud");
|
22
23
|
const url_shorten_1 = require("../../../nx-cloud/utilities/url-shorten");
|
23
24
|
const connect_to_nx_cloud_2 = require("../../connect/connect-to-nx-cloud");
|
24
|
-
const
|
25
|
+
const deduce_default_base_1 = require("./deduce-default-base");
|
25
26
|
function createNxJsonFile(repoRoot, topologicalTargets, cacheableOperations, scriptOutputs) {
|
26
27
|
const nxJsonPath = (0, path_2.joinPathFragments)(repoRoot, 'nx.json');
|
27
28
|
let nxJson = {};
|
@@ -53,56 +54,104 @@ function createNxJsonFile(repoRoot, topologicalTargets, cacheableOperations, scr
|
|
53
54
|
if (Object.keys(nxJson.targetDefaults).length === 0) {
|
54
55
|
delete nxJson.targetDefaults;
|
55
56
|
}
|
56
|
-
|
57
|
+
const defaultBase = (0, deduce_default_base_1.deduceDefaultBase)();
|
58
|
+
// Do not add defaultBase if it is inferred to be the Nx default value of main
|
59
|
+
if (defaultBase !== 'main') {
|
60
|
+
nxJson.defaultBase ??= defaultBase;
|
61
|
+
}
|
57
62
|
(0, fileutils_1.writeJsonFile)(nxJsonPath, nxJson);
|
58
63
|
}
|
59
|
-
function
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
64
|
+
function createNxJsonFromTurboJson(turboJson) {
|
65
|
+
const nxJson = {
|
66
|
+
$schema: './node_modules/nx/schemas/nx-schema.json',
|
67
|
+
};
|
68
|
+
// Handle global dependencies
|
69
|
+
if (turboJson.globalDependencies?.length > 0) {
|
70
|
+
nxJson.namedInputs = {
|
71
|
+
sharedGlobals: turboJson.globalDependencies.map((dep) => `{workspaceRoot}/${dep}`),
|
72
|
+
default: ['{projectRoot}/**/*', 'sharedGlobals'],
|
73
|
+
};
|
74
|
+
}
|
75
|
+
// Handle global env vars
|
76
|
+
if (turboJson.globalEnv?.length > 0) {
|
77
|
+
nxJson.namedInputs = nxJson.namedInputs || {};
|
78
|
+
nxJson.namedInputs.sharedGlobals = nxJson.namedInputs.sharedGlobals || [];
|
79
|
+
nxJson.namedInputs.sharedGlobals.push(...turboJson.globalEnv.map((env) => ({ env })));
|
80
|
+
nxJson.namedInputs.default = nxJson.namedInputs.default || [];
|
81
|
+
if (!nxJson.namedInputs.default.includes('{projectRoot}/**/*')) {
|
82
|
+
nxJson.namedInputs.default.push('{projectRoot}/**/*');
|
74
83
|
}
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
84
|
+
if (!nxJson.namedInputs.default.includes('sharedGlobals')) {
|
85
|
+
nxJson.namedInputs.default.push('sharedGlobals');
|
86
|
+
}
|
87
|
+
}
|
88
|
+
// Handle task configurations
|
89
|
+
if (turboJson.tasks) {
|
90
|
+
nxJson.targetDefaults = {};
|
91
|
+
for (const [taskName, taskConfig] of Object.entries(turboJson.tasks)) {
|
92
|
+
// Skip project-specific tasks (containing #)
|
93
|
+
if (taskName.includes('#'))
|
94
|
+
continue;
|
95
|
+
const config = taskConfig;
|
96
|
+
nxJson.targetDefaults[taskName] = {};
|
97
|
+
// Handle dependsOn
|
98
|
+
if (config.dependsOn?.length > 0) {
|
99
|
+
nxJson.targetDefaults[taskName].dependsOn = config.dependsOn;
|
82
100
|
}
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
return 'next';
|
90
|
-
}
|
91
|
-
catch {
|
92
|
-
try {
|
93
|
-
(0, child_process_1.execSync)(`git rev-parse --verify master`, {
|
94
|
-
stdio: ['ignore', 'ignore', 'ignore'],
|
95
|
-
windowsHide: false,
|
96
|
-
});
|
97
|
-
return 'master';
|
101
|
+
// Handle inputs
|
102
|
+
if (config.inputs?.length > 0) {
|
103
|
+
nxJson.targetDefaults[taskName].inputs = config.inputs
|
104
|
+
.map((input) => {
|
105
|
+
if (input === '$TURBO_DEFAULT$') {
|
106
|
+
return '{projectRoot}/**/*';
|
98
107
|
}
|
99
|
-
|
100
|
-
|
108
|
+
// Don't add projectRoot if it's already there or if it's an env var
|
109
|
+
if (input.startsWith('{projectRoot}/') ||
|
110
|
+
input.startsWith('{env.') ||
|
111
|
+
input.startsWith('$'))
|
112
|
+
return input;
|
113
|
+
return `{projectRoot}/${input}`;
|
114
|
+
})
|
115
|
+
.map((input) => {
|
116
|
+
// Don't add projectRoot if it's already there or if it's an env var
|
117
|
+
if (input.startsWith('{projectRoot}/') ||
|
118
|
+
input.startsWith('{env.') ||
|
119
|
+
input.startsWith('$'))
|
120
|
+
return input;
|
121
|
+
return `{projectRoot}/${input}`;
|
122
|
+
});
|
123
|
+
}
|
124
|
+
// Handle outputs
|
125
|
+
if (config.outputs?.length > 0) {
|
126
|
+
nxJson.targetDefaults[taskName].outputs = config.outputs.map((output) => {
|
127
|
+
// Don't add projectRoot if it's already there
|
128
|
+
if (output.startsWith('{projectRoot}/'))
|
129
|
+
return output;
|
130
|
+
// Handle negated patterns by adding projectRoot after the !
|
131
|
+
if (output.startsWith('!')) {
|
132
|
+
return `!{projectRoot}/${output.slice(1)}`;
|
101
133
|
}
|
102
|
-
|
134
|
+
return `{projectRoot}/${output}`;
|
135
|
+
});
|
103
136
|
}
|
137
|
+
// Handle cache setting - true by default in Turbo
|
138
|
+
nxJson.targetDefaults[taskName].cache = config.cache !== false;
|
104
139
|
}
|
105
140
|
}
|
141
|
+
/**
|
142
|
+
* The fact that cacheDir was in use suggests the user had a reason for deviating from the default.
|
143
|
+
* We can't know what that reason was, nor if it would still be applicable in Nx, but we can at least
|
144
|
+
* improve discoverability of the relevant Nx option by explicitly including it with its default value.
|
145
|
+
*/
|
146
|
+
if (turboJson.cacheDir) {
|
147
|
+
nxJson.cacheDirectory = '.nx/cache';
|
148
|
+
}
|
149
|
+
const defaultBase = (0, deduce_default_base_1.deduceDefaultBase)();
|
150
|
+
// Do not add defaultBase if it is inferred to be the Nx default value of main
|
151
|
+
if (defaultBase !== 'main') {
|
152
|
+
nxJson.defaultBase ??= defaultBase;
|
153
|
+
}
|
154
|
+
return nxJson;
|
106
155
|
}
|
107
156
|
function addDepsToPackageJson(repoRoot, additionalPackages) {
|
108
157
|
const path = (0, path_2.joinPathFragments)(repoRoot, `package.json`);
|
@@ -3,23 +3,24 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.initHandler = initHandler;
|
4
4
|
exports.detectPlugins = detectPlugins;
|
5
5
|
const fs_1 = require("fs");
|
6
|
+
const enquirer_1 = require("enquirer");
|
6
7
|
const semver_1 = require("semver");
|
7
|
-
const
|
8
|
-
const package_manager_1 = require("../../utils/package-manager");
|
9
|
-
const add_nx_scripts_1 = require("./implementation/dot-nx/add-nx-scripts");
|
8
|
+
const nx_json_1 = require("../../config/nx-json");
|
10
9
|
const child_process_1 = require("../../utils/child-process");
|
11
10
|
const fileutils_1 = require("../../utils/fileutils");
|
11
|
+
const get_package_name_from_import_path_1 = require("../../utils/get-package-name-from-import-path");
|
12
|
+
const output_1 = require("../../utils/output");
|
13
|
+
const package_manager_1 = require("../../utils/package-manager");
|
12
14
|
const versions_1 = require("../../utils/versions");
|
13
|
-
const utils_1 = require("./implementation/utils");
|
14
|
-
const enquirer_1 = require("enquirer");
|
15
|
-
const angular_1 = require("./implementation/angular");
|
16
15
|
const workspace_context_1 = require("../../utils/workspace-context");
|
17
16
|
const connect_to_nx_cloud_1 = require("../connect/connect-to-nx-cloud");
|
18
|
-
const add_nx_to_npm_repo_1 = require("./implementation/add-nx-to-npm-repo");
|
19
|
-
const add_nx_to_monorepo_1 = require("./implementation/add-nx-to-monorepo");
|
20
|
-
const nx_json_1 = require("../../config/nx-json");
|
21
|
-
const get_package_name_from_import_path_1 = require("../../utils/get-package-name-from-import-path");
|
22
17
|
const configure_plugins_1 = require("./configure-plugins");
|
18
|
+
const add_nx_to_monorepo_1 = require("./implementation/add-nx-to-monorepo");
|
19
|
+
const add_nx_to_npm_repo_1 = require("./implementation/add-nx-to-npm-repo");
|
20
|
+
const add_nx_to_turborepo_1 = require("./implementation/add-nx-to-turborepo");
|
21
|
+
const angular_1 = require("./implementation/angular");
|
22
|
+
const add_nx_scripts_1 = require("./implementation/dot-nx/add-nx-scripts");
|
23
|
+
const utils_1 = require("./implementation/utils");
|
23
24
|
async function initHandler(options) {
|
24
25
|
process.env.NX_RUNNING_NX_INIT = 'true';
|
25
26
|
const version = process.env.NX_VERSION ?? ((0, semver_1.prerelease)(versions_1.nxVersion) ? 'next' : 'latest');
|
@@ -57,7 +58,29 @@ async function initHandler(options) {
|
|
57
58
|
return;
|
58
59
|
}
|
59
60
|
const packageJson = (0, fileutils_1.readJsonFile)('package.json');
|
60
|
-
|
61
|
+
const _isTurborepo = (0, fs_1.existsSync)('turbo.json');
|
62
|
+
const _isMonorepo = (0, utils_1.isMonorepo)(packageJson);
|
63
|
+
const learnMoreLink = _isTurborepo
|
64
|
+
? 'https://nx.dev/recipes/adopting-nx/from-turborepo'
|
65
|
+
: _isMonorepo
|
66
|
+
? 'https://nx.dev/getting-started/tutorials/npm-workspaces-tutorial'
|
67
|
+
: 'https://nx.dev/recipes/adopting-nx/adding-to-existing-project';
|
68
|
+
/**
|
69
|
+
* Turborepo users must have set up individual scripts already, and we keep the transition as minimal as possible.
|
70
|
+
* We log a message during the conversion process in addNxToTurborepo about how they can learn more about the power
|
71
|
+
* of Nx plugins and how it would allow them to infer all the relevant scripts automatically, including all cache
|
72
|
+
* inputs and outputs.
|
73
|
+
*/
|
74
|
+
if (_isTurborepo) {
|
75
|
+
await (0, add_nx_to_turborepo_1.addNxToTurborepo)({
|
76
|
+
interactive: options.interactive,
|
77
|
+
});
|
78
|
+
(0, utils_1.printFinalMessage)({
|
79
|
+
learnMoreLink,
|
80
|
+
});
|
81
|
+
return;
|
82
|
+
}
|
83
|
+
if (_isMonorepo) {
|
61
84
|
await (0, add_nx_to_monorepo_1.addNxToMonorepo)({
|
62
85
|
interactive: options.interactive,
|
63
86
|
nxCloud: false,
|
@@ -69,9 +92,6 @@ async function initHandler(options) {
|
|
69
92
|
nxCloud: false,
|
70
93
|
});
|
71
94
|
}
|
72
|
-
const learnMoreLink = (0, utils_1.isMonorepo)(packageJson)
|
73
|
-
? 'https://nx.dev/getting-started/tutorials/npm-workspaces-tutorial'
|
74
|
-
: 'https://nx.dev/recipes/adopting-nx/adding-to-existing-project';
|
75
95
|
const useNxCloud = options.nxCloud ??
|
76
96
|
(options.interactive ? await (0, connect_to_nx_cloud_1.connectExistingRepoToNxCloudPrompt)() : false);
|
77
97
|
const repoRoot = process.cwd();
|
package/src/config/nx-json.d.ts
CHANGED
@@ -321,6 +321,7 @@ export interface NxSyncConfiguration {
|
|
321
321
|
* @note: when adding properties here add them to `allowedWorkspaceExtensions` in adapter/compat.ts
|
322
322
|
*/
|
323
323
|
export interface NxJsonConfiguration<T = '*' | string[]> {
|
324
|
+
$schema?: string;
|
324
325
|
/**
|
325
326
|
* Optional (additional) Nx.json configuration file which becomes a base for this one
|
326
327
|
*/
|
@@ -47,6 +47,7 @@ export declare class DaemonClient {
|
|
47
47
|
recordOutputsHash(outputs: string[], hash: string): Promise<any>;
|
48
48
|
outputsHashesMatch(outputs: string[], hash: string): Promise<any>;
|
49
49
|
glob(globs: string[], exclude?: string[]): Promise<string[]>;
|
50
|
+
multiGlob(globs: string[], exclude?: string[]): Promise<string[][]>;
|
50
51
|
getWorkspaceContextFileData(): Promise<FileData[]>;
|
51
52
|
getWorkspaceFiles(projectRootMap: Record<string, string>): Promise<NxWorkspaceFiles>;
|
52
53
|
getFilesInDirectory(dir: string): Promise<string[]>;
|
@@ -215,6 +215,14 @@ class DaemonClient {
|
|
215
215
|
};
|
216
216
|
return this.sendToDaemonViaQueue(message);
|
217
217
|
}
|
218
|
+
multiGlob(globs, exclude) {
|
219
|
+
const message = {
|
220
|
+
type: 'MULTI_GLOB',
|
221
|
+
globs,
|
222
|
+
exclude,
|
223
|
+
};
|
224
|
+
return this.sendToDaemonViaQueue(message);
|
225
|
+
}
|
218
226
|
getWorkspaceContextFileData() {
|
219
227
|
const message = {
|
220
228
|
type: get_context_file_data_1.GET_CONTEXT_FILE_DATA,
|
@@ -5,3 +5,10 @@ export type HandleGlobMessage = {
|
|
5
5
|
exclude?: string[];
|
6
6
|
};
|
7
7
|
export declare function isHandleGlobMessage(message: unknown): message is HandleGlobMessage;
|
8
|
+
export declare const MULTI_GLOB: "MULTI_GLOB";
|
9
|
+
export type HandleMultiGlobMessage = {
|
10
|
+
type: typeof MULTI_GLOB;
|
11
|
+
globs: string[];
|
12
|
+
exclude?: string[];
|
13
|
+
};
|
14
|
+
export declare function isHandleMultiGlobMessage(message: unknown): message is HandleMultiGlobMessage;
|
@@ -1,7 +1,8 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.GLOB = void 0;
|
3
|
+
exports.MULTI_GLOB = exports.GLOB = void 0;
|
4
4
|
exports.isHandleGlobMessage = isHandleGlobMessage;
|
5
|
+
exports.isHandleMultiGlobMessage = isHandleMultiGlobMessage;
|
5
6
|
exports.GLOB = 'GLOB';
|
6
7
|
function isHandleGlobMessage(message) {
|
7
8
|
return (typeof message === 'object' &&
|
@@ -9,3 +10,10 @@ function isHandleGlobMessage(message) {
|
|
9
10
|
'type' in message &&
|
10
11
|
message['type'] === exports.GLOB);
|
11
12
|
}
|
13
|
+
exports.MULTI_GLOB = 'MULTI_GLOB';
|
14
|
+
function isHandleMultiGlobMessage(message) {
|
15
|
+
return (typeof message === 'object' &&
|
16
|
+
message !== null &&
|
17
|
+
'type' in message &&
|
18
|
+
message['type'] === exports.MULTI_GLOB);
|
19
|
+
}
|
@@ -1,6 +1,7 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.handleGlob = handleGlob;
|
4
|
+
exports.handleMultiGlob = handleMultiGlob;
|
4
5
|
const workspace_root_1 = require("../../utils/workspace-root");
|
5
6
|
const workspace_context_1 = require("../../utils/workspace-context");
|
6
7
|
async function handleGlob(globs, exclude) {
|
@@ -10,3 +11,10 @@ async function handleGlob(globs, exclude) {
|
|
10
11
|
description: 'handleGlob',
|
11
12
|
};
|
12
13
|
}
|
14
|
+
async function handleMultiGlob(globs, exclude) {
|
15
|
+
const files = await (0, workspace_context_1.multiGlobWithWorkspaceContext)(workspace_root_1.workspaceRoot, globs, exclude);
|
16
|
+
return {
|
17
|
+
response: JSON.stringify(files),
|
18
|
+
description: 'handleMultiGlob',
|
19
|
+
};
|
20
|
+
}
|
@@ -129,6 +129,9 @@ async function handleMessage(socket, data) {
|
|
129
129
|
else if ((0, glob_1.isHandleGlobMessage)(payload)) {
|
130
130
|
await handleResult(socket, glob_1.GLOB, () => (0, handle_glob_1.handleGlob)(payload.globs, payload.exclude));
|
131
131
|
}
|
132
|
+
else if ((0, glob_1.isHandleMultiGlobMessage)(payload)) {
|
133
|
+
await handleResult(socket, glob_1.MULTI_GLOB, () => (0, handle_glob_1.handleMultiGlob)(payload.globs, payload.exclude));
|
134
|
+
}
|
132
135
|
else if ((0, get_nx_workspace_files_1.isHandleNxWorkspaceFilesMessage)(payload)) {
|
133
136
|
await handleResult(socket, get_nx_workspace_files_1.GET_NX_WORKSPACE_FILES, () => (0, handle_nx_workspace_files_1.handleNxWorkspaceFiles)(payload.projectRootMap));
|
134
137
|
}
|
package/src/native/index.d.ts
CHANGED
@@ -93,6 +93,13 @@ export declare class WorkspaceContext {
|
|
93
93
|
constructor(workspaceRoot: string, cacheDir: string)
|
94
94
|
getWorkspaceFiles(projectRootMap: Record<string, string>): NxWorkspaceFiles
|
95
95
|
glob(globs: Array<string>, exclude?: Array<string> | undefined | null): Array<string>
|
96
|
+
/**
|
97
|
+
* Performs multiple glob pattern matches against workspace files in parallel
|
98
|
+
* @returns An array of arrays, where each inner array contains the file paths
|
99
|
+
* that matched the corresponding glob pattern in the input. The outer array maintains the same order
|
100
|
+
* as the input globs.
|
101
|
+
*/
|
102
|
+
multiGlob(globs: Array<string>, exclude?: Array<string> | undefined | null): Array<Array<string>>
|
96
103
|
hashFilesMatchingGlob(globs: Array<string>, exclude?: Array<string> | undefined | null): string
|
97
104
|
incrementalUpdate(updatedFiles: Array<string>, deletedFiles: Array<string>): Record<string, string>
|
98
105
|
updateProjectFiles(projectRootMappings: ProjectRootMappings, projectFiles: ExternalObject<ProjectFiles>, globalFiles: ExternalObject<Array<FileData>>, updatedFiles: Record<string, string>, deletedFiles: Array<string>): UpdatedWorkspaceFiles
|
package/src/native/nx.wasi.cjs
CHANGED
@@ -119,13 +119,13 @@ function __napi_rs_initialize_modules(__napiInstance) {
|
|
119
119
|
__napiInstance.exports['__napi_register__FileLock_struct_39']?.()
|
120
120
|
__napiInstance.exports['__napi_register__FileLock_impl_41']?.()
|
121
121
|
__napiInstance.exports['__napi_register__WorkspaceContext_struct_42']?.()
|
122
|
-
__napiInstance.exports['
|
123
|
-
__napiInstance.exports['
|
124
|
-
__napiInstance.exports['
|
125
|
-
__napiInstance.exports['
|
126
|
-
__napiInstance.exports['
|
127
|
-
__napiInstance.exports['
|
128
|
-
__napiInstance.exports['
|
122
|
+
__napiInstance.exports['__napi_register__WorkspaceContext_impl_52']?.()
|
123
|
+
__napiInstance.exports['__napi_register__WorkspaceErrors_53']?.()
|
124
|
+
__napiInstance.exports['__napi_register__NxWorkspaceFiles_struct_54']?.()
|
125
|
+
__napiInstance.exports['__napi_register__NxWorkspaceFilesExternals_struct_55']?.()
|
126
|
+
__napiInstance.exports['__napi_register__UpdatedWorkspaceFiles_struct_56']?.()
|
127
|
+
__napiInstance.exports['__napi_register__FileMap_struct_57']?.()
|
128
|
+
__napiInstance.exports['__napi_register____test_only_transfer_file_map_58']?.()
|
129
129
|
}
|
130
130
|
module.exports.FileLock = __napiModule.exports.FileLock
|
131
131
|
module.exports.HashPlanner = __napiModule.exports.HashPlanner
|
Binary file
|
@@ -20,8 +20,8 @@ const getTouchedProjectsFromProjectGlobChanges = async (touchedFiles, projectGra
|
|
20
20
|
'package.json',
|
21
21
|
]);
|
22
22
|
}
|
23
|
-
const plugins = await (0, get_plugins_1.getPlugins)();
|
24
|
-
return (0, globs_1.combineGlobPatterns)((0, retrieve_workspace_files_1.
|
23
|
+
const plugins = (await (0, get_plugins_1.getPlugins)()).filter((p) => !!p.createNodes);
|
24
|
+
return (0, globs_1.combineGlobPatterns)((0, retrieve_workspace_files_1.getGlobPatternsOfPlugins)(plugins));
|
25
25
|
})();
|
26
26
|
const touchedProjects = new Set();
|
27
27
|
for (const touchedFile of touchedFiles) {
|
@@ -216,7 +216,10 @@ class AggregateCreateNodesError extends Error {
|
|
216
216
|
exports.AggregateCreateNodesError = AggregateCreateNodesError;
|
217
217
|
function formatAggregateCreateNodesError(error, pluginName) {
|
218
218
|
const errorBodyLines = [
|
219
|
-
`${error.errors.length > 1 ? `${error.errors.length} errors` : 'An error'} occurred while processing files for the ${pluginName} plugin
|
219
|
+
`${error.errors.length > 1 ? `${error.errors.length} errors` : 'An error'} occurred while processing files for the ${pluginName} plugin${error.pluginIndex
|
220
|
+
? ` (Defined at nx.json#plugins[${error.pluginIndex}])`
|
221
|
+
: ''}`,
|
222
|
+
`.`,
|
220
223
|
];
|
221
224
|
const errorStackLines = [];
|
222
225
|
const innerErrors = error.errors;
|
@@ -108,12 +108,13 @@ async function loadSpecifiedNxPlugins(plugins, root = workspace_root_1.workspace
|
|
108
108
|
plugins ??= [];
|
109
109
|
const cleanupFunctions = [];
|
110
110
|
const ret = [
|
111
|
-
await Promise.all(plugins.map(async (plugin) => {
|
111
|
+
await Promise.all(plugins.map(async (plugin, index) => {
|
112
112
|
const pluginPath = typeof plugin === 'string' ? plugin : plugin.plugin;
|
113
113
|
performance.mark(`Load Nx Plugin: ${pluginPath} - start`);
|
114
114
|
const [loadedPluginPromise, cleanup] = await loadingMethod(plugin, root);
|
115
115
|
cleanupFunctions.push(cleanup);
|
116
116
|
const res = await loadedPluginPromise;
|
117
|
+
res.index = index;
|
117
118
|
performance.mark(`Load Nx Plugin: ${pluginPath} - end`);
|
118
119
|
performance.measure(`Load Nx Plugin: ${pluginPath}`, `Load Nx Plugin: ${pluginPath} - start`, `Load Nx Plugin: ${pluginPath} - end`);
|
119
120
|
return res;
|
@@ -3,6 +3,7 @@ import type { PluginConfiguration } from '../../config/nx-json';
|
|
3
3
|
import type { RawProjectGraphDependency } from '../project-graph-builder';
|
4
4
|
import type { CreateDependenciesContext, CreateMetadataContext, CreateNodesContextV2, CreateNodesResult, NxPluginV2, PostTasksExecutionContext, PreTasksExecutionContext, ProjectsMetadata } from './public-api';
|
5
5
|
export declare class LoadedNxPlugin {
|
6
|
+
index?: number;
|
6
7
|
readonly name: string;
|
7
8
|
readonly createNodes?: [
|
8
9
|
filePattern: string,
|
@@ -35,7 +35,7 @@ export type ConfigurationResult = {
|
|
35
35
|
* @param workspaceFiles A list of non-ignored workspace files
|
36
36
|
* @param plugins The plugins that should be used to infer project configuration
|
37
37
|
*/
|
38
|
-
export declare function
|
38
|
+
export declare function createProjectConfigurationsWithPlugins(root: string, nxJson: NxJsonConfiguration, projectFiles: string[][], // making this parameter allows devkit to pick up newly created projects
|
39
39
|
plugins: LoadedNxPlugin[]): Promise<ConfigurationResult>;
|
40
40
|
export declare function findMatchingConfigFiles(projectFiles: string[], pattern: string, include: string[], exclude: string[]): string[];
|
41
41
|
export declare function readProjectConfigurationsFromRootMap(projectRootMap: Record<string, ProjectConfiguration>): Record<string, ProjectConfiguration>;
|
@@ -2,7 +2,7 @@
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.mergeProjectConfigurationIntoRootMap = mergeProjectConfigurationIntoRootMap;
|
4
4
|
exports.mergeMetadata = mergeMetadata;
|
5
|
-
exports.
|
5
|
+
exports.createProjectConfigurationsWithPlugins = createProjectConfigurationsWithPlugins;
|
6
6
|
exports.findMatchingConfigFiles = findMatchingConfigFiles;
|
7
7
|
exports.readProjectConfigurationsFromRootMap = readProjectConfigurationsFromRootMap;
|
8
8
|
exports.validateProject = validateProject;
|
@@ -222,7 +222,7 @@ function mergeMetadata(sourceMap, sourceInformation, baseSourceMapPath, metadata
|
|
222
222
|
* @param workspaceFiles A list of non-ignored workspace files
|
223
223
|
* @param plugins The plugins that should be used to infer project configuration
|
224
224
|
*/
|
225
|
-
async function
|
225
|
+
async function createProjectConfigurationsWithPlugins(root = workspace_root_1.workspaceRoot, nxJson, projectFiles, // making this parameter allows devkit to pick up newly created projects
|
226
226
|
plugins) {
|
227
227
|
perf_hooks_1.performance.mark('build-project-configs:start');
|
228
228
|
let spinner;
|
@@ -248,12 +248,12 @@ plugins) {
|
|
248
248
|
const results = [];
|
249
249
|
const errors = [];
|
250
250
|
// We iterate over plugins first - this ensures that plugins specified first take precedence.
|
251
|
-
for (const [index, { createNodes: createNodesTuple, include, exclude, name: pluginName },] of plugins.entries()) {
|
251
|
+
for (const [index, { index: pluginIndex, createNodes: createNodesTuple, include, exclude, name: pluginName, },] of plugins.entries()) {
|
252
252
|
const [pattern, createNodes] = createNodesTuple ?? [];
|
253
253
|
if (!pattern) {
|
254
254
|
continue;
|
255
255
|
}
|
256
|
-
const matchingConfigFiles = findMatchingConfigFiles(projectFiles, pattern, include, exclude);
|
256
|
+
const matchingConfigFiles = findMatchingConfigFiles(projectFiles[index], pattern, include, exclude);
|
257
257
|
inProgressPlugins.add(pluginName);
|
258
258
|
let r = createNodes(matchingConfigFiles, {
|
259
259
|
nxJsonConfiguration: nxJson,
|
@@ -265,8 +265,10 @@ plugins) {
|
|
265
265
|
e
|
266
266
|
: // This represents a single plugin erroring out with a hard error.
|
267
267
|
new error_types_1.AggregateCreateNodesError([[null, e]], []);
|
268
|
+
if (pluginIndex) {
|
269
|
+
error.pluginIndex = pluginIndex;
|
270
|
+
}
|
268
271
|
(0, error_types_1.formatAggregateCreateNodesError)(error, pluginName);
|
269
|
-
error.pluginIndex = index;
|
270
272
|
// This represents a single plugin erroring out with a hard error.
|
271
273
|
errors.push(error);
|
272
274
|
// The plugin didn't return partial results, so we return an empty array.
|
@@ -289,7 +291,7 @@ plugins) {
|
|
289
291
|
externalNodes,
|
290
292
|
projectRootMap: rootMap,
|
291
293
|
sourceMaps: configurationSourceMaps,
|
292
|
-
matchingProjectFiles: projectFiles,
|
294
|
+
matchingProjectFiles: projectFiles.flat(),
|
293
295
|
};
|
294
296
|
}
|
295
297
|
else {
|
@@ -298,7 +300,7 @@ plugins) {
|
|
298
300
|
externalNodes,
|
299
301
|
projectRootMap: rootMap,
|
300
302
|
sourceMaps: configurationSourceMaps,
|
301
|
-
matchingProjectFiles: projectFiles,
|
303
|
+
matchingProjectFiles: projectFiles.flat(),
|
302
304
|
});
|
303
305
|
}
|
304
306
|
});
|
@@ -309,7 +311,7 @@ function mergeCreateNodesResults(results, nxJsonConfiguration, errors) {
|
|
309
311
|
const externalNodes = {};
|
310
312
|
const configurationSourceMaps = {};
|
311
313
|
for (const result of results.flat()) {
|
312
|
-
const [pluginName, file, nodes,
|
314
|
+
const [pluginName, file, nodes, pluginIndex] = result;
|
313
315
|
const { projects: projectNodes, externalNodes: pluginExternalNodes } = nodes;
|
314
316
|
const sourceInfo = [file, pluginName];
|
315
317
|
for (const node in projectNodes) {
|
@@ -329,7 +331,7 @@ function mergeCreateNodesResults(results, nxJsonConfiguration, errors) {
|
|
329
331
|
file,
|
330
332
|
pluginName,
|
331
333
|
error,
|
332
|
-
pluginIndex
|
334
|
+
pluginIndex,
|
333
335
|
}));
|
334
336
|
}
|
335
337
|
}
|
@@ -23,4 +23,4 @@ export declare function retrieveProjectConfigurations(plugins: LoadedNxPlugin[],
|
|
23
23
|
export declare function retrieveProjectConfigurationsWithAngularProjects(workspaceRoot: string, nxJson: NxJsonConfiguration): Promise<ConfigurationResult>;
|
24
24
|
export declare function retrieveProjectConfigurationPaths(root: string, plugins: Array<LoadedNxPlugin>): Promise<string[]>;
|
25
25
|
export declare function retrieveProjectConfigurationsWithoutPluginInference(root: string): Promise<Record<string, ProjectConfiguration>>;
|
26
|
-
export declare function
|
26
|
+
export declare function getGlobPatternsOfPlugins(plugins: Array<LoadedNxPlugin>): string[];
|
@@ -5,7 +5,7 @@ exports.retrieveProjectConfigurations = retrieveProjectConfigurations;
|
|
5
5
|
exports.retrieveProjectConfigurationsWithAngularProjects = retrieveProjectConfigurationsWithAngularProjects;
|
6
6
|
exports.retrieveProjectConfigurationPaths = retrieveProjectConfigurationPaths;
|
7
7
|
exports.retrieveProjectConfigurationsWithoutPluginInference = retrieveProjectConfigurationsWithoutPluginInference;
|
8
|
-
exports.
|
8
|
+
exports.getGlobPatternsOfPlugins = getGlobPatternsOfPlugins;
|
9
9
|
const perf_hooks_1 = require("perf_hooks");
|
10
10
|
const angular_json_1 = require("../../adapter/angular-json");
|
11
11
|
const nx_json_1 = require("../../config/nx-json");
|
@@ -41,9 +41,10 @@ async function retrieveWorkspaceFiles(workspaceRoot, projectRootMap) {
|
|
41
41
|
* Walk through the workspace and return `ProjectConfigurations`. Only use this if the projectFileMap is not needed.
|
42
42
|
*/
|
43
43
|
async function retrieveProjectConfigurations(plugins, workspaceRoot, nxJson) {
|
44
|
-
const
|
45
|
-
const
|
46
|
-
|
44
|
+
const pluginsWithCreateNodes = plugins.filter((p) => !!p.createNodes);
|
45
|
+
const globPatterns = getGlobPatternsOfPlugins(pluginsWithCreateNodes);
|
46
|
+
const pluginConfigFiles = await (0, workspace_context_1.multiGlobWithWorkspaceContext)(workspaceRoot, globPatterns);
|
47
|
+
return (0, project_configuration_utils_1.createProjectConfigurationsWithPlugins)(workspaceRoot, nxJson, pluginConfigFiles, pluginsWithCreateNodes);
|
47
48
|
}
|
48
49
|
async function retrieveProjectConfigurationsWithAngularProjects(workspaceRoot, nxJson) {
|
49
50
|
const pluginsToLoad = nxJson?.plugins ?? [];
|
@@ -56,31 +57,26 @@ async function retrieveProjectConfigurationsWithAngularProjects(workspaceRoot, n
|
|
56
57
|
const res = await retrieveProjectConfigurations(plugins, workspaceRoot, nxJson);
|
57
58
|
return res;
|
58
59
|
}
|
59
|
-
function retrieveProjectConfigurationPaths(root, plugins) {
|
60
|
-
const projectGlobPatterns =
|
61
|
-
|
60
|
+
async function retrieveProjectConfigurationPaths(root, plugins) {
|
61
|
+
const projectGlobPatterns = getGlobPatternsOfPlugins(plugins);
|
62
|
+
const pluginConfigFiles = await (0, workspace_context_1.multiGlobWithWorkspaceContext)(root, projectGlobPatterns);
|
63
|
+
return pluginConfigFiles.flat();
|
62
64
|
}
|
63
65
|
const projectsWithoutPluginCache = new Map();
|
64
66
|
// TODO: This function is called way too often, it should be optimized without this cache
|
65
67
|
async function retrieveProjectConfigurationsWithoutPluginInference(root) {
|
66
68
|
const nxJson = (0, nx_json_1.readNxJson)(root);
|
67
69
|
const plugins = await (0, get_plugins_1.getOnlyDefaultPlugins)(); // only load default plugins
|
68
|
-
const projectGlobPatterns =
|
70
|
+
const projectGlobPatterns = getGlobPatternsOfPlugins(plugins);
|
69
71
|
const cacheKey = root + ',' + projectGlobPatterns.join(',');
|
70
72
|
if (projectsWithoutPluginCache.has(cacheKey)) {
|
71
73
|
return projectsWithoutPluginCache.get(cacheKey);
|
72
74
|
}
|
73
|
-
const projectFiles = (await (0, workspace_context_1.
|
74
|
-
const { projects } = await (0, project_configuration_utils_1.
|
75
|
+
const projectFiles = (await (0, workspace_context_1.multiGlobWithWorkspaceContext)(root, projectGlobPatterns)) ?? [];
|
76
|
+
const { projects } = await (0, project_configuration_utils_1.createProjectConfigurationsWithPlugins)(root, nxJson, projectFiles, plugins);
|
75
77
|
projectsWithoutPluginCache.set(cacheKey, projects);
|
76
78
|
return projects;
|
77
79
|
}
|
78
|
-
function
|
79
|
-
|
80
|
-
for (const plugin of plugins) {
|
81
|
-
if ('createNodes' in plugin && plugin.createNodes) {
|
82
|
-
globPatterns.push(plugin.createNodes[0]);
|
83
|
-
}
|
84
|
-
}
|
85
|
-
return globPatterns;
|
80
|
+
function getGlobPatternsOfPlugins(plugins) {
|
81
|
+
return plugins.map((p) => p.createNodes[0]);
|
86
82
|
}
|
@@ -10,6 +10,7 @@ export declare function getNxWorkspaceFilesFromContext(workspaceRoot: string, pr
|
|
10
10
|
*/
|
11
11
|
export declare function globWithWorkspaceContextSync(workspaceRoot: string, globs: string[], exclude?: string[]): string[];
|
12
12
|
export declare function globWithWorkspaceContext(workspaceRoot: string, globs: string[], exclude?: string[]): Promise<string[]>;
|
13
|
+
export declare function multiGlobWithWorkspaceContext(workspaceRoot: string, globs: string[], exclude?: string[]): Promise<string[][]>;
|
13
14
|
export declare function hashWithWorkspaceContext(workspaceRoot: string, globs: string[], exclude?: string[]): Promise<string>;
|
14
15
|
export declare function updateContextWithChangedFiles(workspaceRoot: string, createdFiles: string[], updatedFiles: string[], deletedFiles: string[]): Promise<void>;
|
15
16
|
export declare function updateFilesInContext(workspaceRoot: string, updatedFiles: string[], deletedFiles: string[]): Record<string, string>;
|
@@ -4,6 +4,7 @@ exports.setupWorkspaceContext = setupWorkspaceContext;
|
|
4
4
|
exports.getNxWorkspaceFilesFromContext = getNxWorkspaceFilesFromContext;
|
5
5
|
exports.globWithWorkspaceContextSync = globWithWorkspaceContextSync;
|
6
6
|
exports.globWithWorkspaceContext = globWithWorkspaceContext;
|
7
|
+
exports.multiGlobWithWorkspaceContext = multiGlobWithWorkspaceContext;
|
7
8
|
exports.hashWithWorkspaceContext = hashWithWorkspaceContext;
|
8
9
|
exports.updateContextWithChangedFiles = updateContextWithChangedFiles;
|
9
10
|
exports.updateFilesInContext = updateFilesInContext;
|
@@ -50,6 +51,13 @@ async function globWithWorkspaceContext(workspaceRoot, globs, exclude) {
|
|
50
51
|
return client_1.daemonClient.glob(globs, exclude);
|
51
52
|
}
|
52
53
|
}
|
54
|
+
async function multiGlobWithWorkspaceContext(workspaceRoot, globs, exclude) {
|
55
|
+
if ((0, is_on_daemon_1.isOnDaemon)() || !client_1.daemonClient.enabled()) {
|
56
|
+
ensureContextAvailable(workspaceRoot);
|
57
|
+
return workspaceContext.multiGlob(globs, exclude);
|
58
|
+
}
|
59
|
+
return client_1.daemonClient.multiGlob(globs, exclude);
|
60
|
+
}
|
53
61
|
async function hashWithWorkspaceContext(workspaceRoot, globs, exclude) {
|
54
62
|
if ((0, is_on_daemon_1.isOnDaemon)() || !client_1.daemonClient.enabled()) {
|
55
63
|
ensureContextAvailable(workspaceRoot);
|