nx 20.5.0-beta.2 → 20.5.0-beta.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/schemas/nx-schema.json +36 -2
- 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/command-line/release/changelog.js +3 -5
- package/src/command-line/release/command-object.d.ts +1 -0
- package/src/command-line/release/command-object.js +5 -0
- package/src/command-line/release/config/config.js +6 -0
- package/src/command-line/release/utils/git.d.ts +1 -1
- package/src/command-line/release/utils/git.js +55 -7
- package/src/config/nx-json.d.ts +22 -3
- package/src/core/graph/main.js +1 -1
- package/src/core/graph/runtime.js +1 -1
- package/src/core/graph/styles.css +2 -2
- package/src/core/graph/styles.js +1 -1
- package/src/daemon/client/client.d.ts +2 -1
- package/src/daemon/client/client.js +17 -60
- package/src/daemon/client/enabled.d.ts +2 -0
- package/src/daemon/client/enabled.js +64 -0
- package/src/daemon/message-types/glob.d.ts +7 -0
- package/src/daemon/message-types/glob.js +9 -1
- package/src/daemon/message-types/hash-glob.d.ts +6 -0
- package/src/daemon/message-types/hash-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/handle-hash-glob.d.ts +1 -0
- package/src/daemon/server/handle-hash-glob.js +8 -0
- package/src/daemon/server/server.js +7 -0
- package/src/devkit-exports.d.ts +1 -1
- package/src/devkit-exports.js +2 -2
- package/src/devkit-internals.d.ts +1 -1
- package/src/devkit-internals.js +2 -1
- package/src/native/index.d.ts +9 -1
- package/src/native/nx.wasi.cjs +7 -7
- package/src/native/nx.wasm32-wasi.wasm +0 -0
- package/src/plugins/js/lock-file/lock-file.js +28 -13
- package/src/plugins/js/project-graph/affected/lock-file-changes.js +1 -0
- package/src/plugins/js/project-graph/build-dependencies/explicit-project-dependencies.js +1 -1
- package/src/plugins/js/utils/typescript.js +3 -3
- 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/isolation/plugin-worker.js +12 -6
- package/src/project-graph/plugins/loaded-nx-plugin.d.ts +2 -1
- package/src/project-graph/plugins/loaded-nx-plugin.js +3 -2
- package/src/project-graph/plugins/tasks-execution-hooks.js +4 -3
- package/src/project-graph/plugins/utils.d.ts +2 -2
- package/src/project-graph/plugins/utils.js +2 -2
- 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/tasks-runner/run-command.js +2 -3
- package/src/utils/command-line-utils.d.ts +1 -1
- package/src/utils/package-manager.js +2 -2
- package/src/utils/workspace-context.d.ts +2 -0
- package/src/utils/workspace-context.js +16 -0
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "nx",
|
3
|
-
"version": "20.5.0-beta.
|
3
|
+
"version": "20.5.0-beta.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.5.0-beta.
|
86
|
-
"@nx/nx-darwin-x64": "20.5.0-beta.
|
87
|
-
"@nx/nx-freebsd-x64": "20.5.0-beta.
|
88
|
-
"@nx/nx-linux-arm-gnueabihf": "20.5.0-beta.
|
89
|
-
"@nx/nx-linux-arm64-gnu": "20.5.0-beta.
|
90
|
-
"@nx/nx-linux-arm64-musl": "20.5.0-beta.
|
91
|
-
"@nx/nx-linux-x64-gnu": "20.5.0-beta.
|
92
|
-
"@nx/nx-linux-x64-musl": "20.5.0-beta.
|
93
|
-
"@nx/nx-win32-arm64-msvc": "20.5.0-beta.
|
94
|
-
"@nx/nx-win32-x64-msvc": "20.5.0-beta.
|
85
|
+
"@nx/nx-darwin-arm64": "20.5.0-beta.4",
|
86
|
+
"@nx/nx-darwin-x64": "20.5.0-beta.4",
|
87
|
+
"@nx/nx-freebsd-x64": "20.5.0-beta.4",
|
88
|
+
"@nx/nx-linux-arm-gnueabihf": "20.5.0-beta.4",
|
89
|
+
"@nx/nx-linux-arm64-gnu": "20.5.0-beta.4",
|
90
|
+
"@nx/nx-linux-arm64-musl": "20.5.0-beta.4",
|
91
|
+
"@nx/nx-linux-x64-gnu": "20.5.0-beta.4",
|
92
|
+
"@nx/nx-linux-x64-musl": "20.5.0-beta.4",
|
93
|
+
"@nx/nx-win32-arm64-msvc": "20.5.0-beta.4",
|
94
|
+
"@nx/nx-win32-x64-msvc": "20.5.0-beta.4"
|
95
95
|
},
|
96
96
|
"nx-migrations": {
|
97
97
|
"migrations": "./migrations.json",
|
package/schemas/nx-schema.json
CHANGED
@@ -21,6 +21,10 @@
|
|
21
21
|
"additionalProperties": false,
|
22
22
|
"deprecated": "Use `defaultBase` instead. Support for setting `defaultBase` in `affected` will be removed in Nx 20."
|
23
23
|
},
|
24
|
+
"extends": {
|
25
|
+
"type": "string",
|
26
|
+
"description": "Specifies the base config to extend."
|
27
|
+
},
|
24
28
|
"defaultBase": {
|
25
29
|
"type": "string",
|
26
30
|
"description": "Default --base used by affected logic."
|
@@ -169,7 +173,22 @@
|
|
169
173
|
]
|
170
174
|
},
|
171
175
|
"releaseTagPattern": {
|
172
|
-
"type": "string"
|
176
|
+
"type": "string",
|
177
|
+
"description": "Optionally override the git/release tag pattern to use for this group."
|
178
|
+
},
|
179
|
+
"releaseTagPatternCheckAllBranchesWhen": {
|
180
|
+
"oneOf": [
|
181
|
+
{
|
182
|
+
"type": "boolean"
|
183
|
+
},
|
184
|
+
{
|
185
|
+
"type": "array",
|
186
|
+
"items": {
|
187
|
+
"type": "string"
|
188
|
+
}
|
189
|
+
}
|
190
|
+
],
|
191
|
+
"description": "By default, we will try and resolve the latest match for the releaseTagPattern from the current branch, falling back to all branches if no match is found on the current branch. Setting this to true will cause us to ALWAYS check all branches for the latest match. Setting it to false will cause us to ONLY check the current branch for the latest match. Setting it to an array of strings will cause us to check all branches WHEN the current branch is one of the strings in the array. Glob patterns are supported."
|
173
192
|
},
|
174
193
|
"versionPlans": {
|
175
194
|
"oneOf": [
|
@@ -243,7 +262,22 @@
|
|
243
262
|
]
|
244
263
|
},
|
245
264
|
"releaseTagPattern": {
|
246
|
-
"type": "string"
|
265
|
+
"type": "string",
|
266
|
+
"description": "Optionally override the git/release tag pattern to use. This field is the source of truth for changelog generation and release tagging, as well as for conventional commits parsing. It supports interpolating the version as {version} and (if releasing independently or forcing project level version control system releases) the project name as {projectName} within the string. The default releaseTagPattern for fixed/unified releases is: \"v{version}\". The default releaseTagPattern for independent releases at the project level is: \"{projectName}@{version}\""
|
267
|
+
},
|
268
|
+
"releaseTagPatternCheckAllBranchesWhen": {
|
269
|
+
"oneOf": [
|
270
|
+
{
|
271
|
+
"type": "boolean"
|
272
|
+
},
|
273
|
+
{
|
274
|
+
"type": "array",
|
275
|
+
"items": {
|
276
|
+
"type": "string"
|
277
|
+
}
|
278
|
+
}
|
279
|
+
],
|
280
|
+
"description": "By default, we will try and resolve the latest match for the releaseTagPattern from the current branch, falling back to all branches if no match is found on the current branch. Setting this to true will cause us to ALWAYS check all branches for the latest match. Setting it to false will cause us to ONLY check the current branch for the latest match. Setting it to an array of strings will cause us to check all branches WHEN the current branch is one of the strings in the array. Glob patterns are supported."
|
247
281
|
}
|
248
282
|
}
|
249
283
|
},
|
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`);
|