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.
Files changed (69) hide show
  1. package/package.json +11 -11
  2. package/schemas/nx-schema.json +36 -2
  3. package/src/adapter/compat.d.ts +1 -1
  4. package/src/adapter/compat.js +1 -0
  5. package/src/command-line/add/add.js +6 -16
  6. package/src/command-line/init/command-object.js +13 -6
  7. package/src/command-line/init/configure-plugins.d.ts +5 -6
  8. package/src/command-line/init/configure-plugins.js +13 -22
  9. package/src/command-line/init/implementation/add-nx-to-turborepo.d.ts +4 -0
  10. package/src/command-line/init/implementation/add-nx-to-turborepo.js +49 -0
  11. package/src/command-line/init/implementation/deduce-default-base.d.ts +1 -0
  12. package/src/command-line/init/implementation/deduce-default-base.js +53 -0
  13. package/src/command-line/init/implementation/utils.d.ts +3 -1
  14. package/src/command-line/init/implementation/utils.js +91 -42
  15. package/src/command-line/init/init-v2.js +34 -14
  16. package/src/command-line/release/changelog.js +3 -5
  17. package/src/command-line/release/command-object.d.ts +1 -0
  18. package/src/command-line/release/command-object.js +5 -0
  19. package/src/command-line/release/config/config.js +6 -0
  20. package/src/command-line/release/utils/git.d.ts +1 -1
  21. package/src/command-line/release/utils/git.js +55 -7
  22. package/src/config/nx-json.d.ts +22 -3
  23. package/src/core/graph/main.js +1 -1
  24. package/src/core/graph/runtime.js +1 -1
  25. package/src/core/graph/styles.css +2 -2
  26. package/src/core/graph/styles.js +1 -1
  27. package/src/daemon/client/client.d.ts +2 -1
  28. package/src/daemon/client/client.js +17 -60
  29. package/src/daemon/client/enabled.d.ts +2 -0
  30. package/src/daemon/client/enabled.js +64 -0
  31. package/src/daemon/message-types/glob.d.ts +7 -0
  32. package/src/daemon/message-types/glob.js +9 -1
  33. package/src/daemon/message-types/hash-glob.d.ts +6 -0
  34. package/src/daemon/message-types/hash-glob.js +9 -1
  35. package/src/daemon/server/handle-glob.d.ts +1 -0
  36. package/src/daemon/server/handle-glob.js +8 -0
  37. package/src/daemon/server/handle-hash-glob.d.ts +1 -0
  38. package/src/daemon/server/handle-hash-glob.js +8 -0
  39. package/src/daemon/server/server.js +7 -0
  40. package/src/devkit-exports.d.ts +1 -1
  41. package/src/devkit-exports.js +2 -2
  42. package/src/devkit-internals.d.ts +1 -1
  43. package/src/devkit-internals.js +2 -1
  44. package/src/native/index.d.ts +9 -1
  45. package/src/native/nx.wasi.cjs +7 -7
  46. package/src/native/nx.wasm32-wasi.wasm +0 -0
  47. package/src/plugins/js/lock-file/lock-file.js +28 -13
  48. package/src/plugins/js/project-graph/affected/lock-file-changes.js +1 -0
  49. package/src/plugins/js/project-graph/build-dependencies/explicit-project-dependencies.js +1 -1
  50. package/src/plugins/js/utils/typescript.js +3 -3
  51. package/src/project-graph/affected/locators/project-glob-changes.js +2 -2
  52. package/src/project-graph/error-types.js +4 -1
  53. package/src/project-graph/plugins/get-plugins.js +2 -1
  54. package/src/project-graph/plugins/isolation/plugin-worker.js +12 -6
  55. package/src/project-graph/plugins/loaded-nx-plugin.d.ts +2 -1
  56. package/src/project-graph/plugins/loaded-nx-plugin.js +3 -2
  57. package/src/project-graph/plugins/tasks-execution-hooks.js +4 -3
  58. package/src/project-graph/plugins/utils.d.ts +2 -2
  59. package/src/project-graph/plugins/utils.js +2 -2
  60. package/src/project-graph/project-graph.js +1 -1
  61. package/src/project-graph/utils/project-configuration-utils.d.ts +1 -1
  62. package/src/project-graph/utils/project-configuration-utils.js +11 -9
  63. package/src/project-graph/utils/retrieve-workspace-files.d.ts +1 -1
  64. package/src/project-graph/utils/retrieve-workspace-files.js +14 -18
  65. package/src/tasks-runner/run-command.js +2 -3
  66. package/src/utils/command-line-utils.d.ts +1 -1
  67. package/src/utils/package-manager.js +2 -2
  68. package/src/utils/workspace-context.d.ts +2 -0
  69. 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.2",
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.2",
86
- "@nx/nx-darwin-x64": "20.5.0-beta.2",
87
- "@nx/nx-freebsd-x64": "20.5.0-beta.2",
88
- "@nx/nx-linux-arm-gnueabihf": "20.5.0-beta.2",
89
- "@nx/nx-linux-arm64-gnu": "20.5.0-beta.2",
90
- "@nx/nx-linux-arm64-musl": "20.5.0-beta.2",
91
- "@nx/nx-linux-x64-gnu": "20.5.0-beta.2",
92
- "@nx/nx-linux-x64-musl": "20.5.0-beta.2",
93
- "@nx/nx-win32-arm64-msvc": "20.5.0-beta.2",
94
- "@nx/nx-win32-x64-msvc": "20.5.0-beta.2"
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",
@@ -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
  },
@@ -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"];
@@ -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
- const parsedCommandArgs = yargsParser(options.__overrides_unparsed__, {
83
- configuration: {
84
- 'parse-numbers': false,
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
- parsedCommandArgs.updatePackageScripts = true;
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, parsedCommandArgs);
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
- const useV2 = await isInitV2();
11
- if (useV2) {
12
- await require('./init-v2').initHandler(args);
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
- else {
15
- await require('./init-v1').initHandler(args);
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 verbose verbose
8
- * @param options options passed to init generator
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: string, verbose: boolean, options: {
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 verbose verbose
31
- * @param options options passed to init generator
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, options) {
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
- const { implementationFactory } = (0, generator_utils_1.getGeneratorInformation)(plugin, initGenerator, repoRoot, {});
49
- const implementation = implementationFactory();
50
- const task = await implementation(host, options);
51
- (0, tree_1.flushChanges)(repoRoot, host.listChanges());
52
- if (task) {
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,4 @@
1
+ import { InitArgs } from '../init-v1';
2
+ type Options = Pick<InitArgs, 'nxCloud' | 'interactive'>;
3
+ export declare function addNxToTurborepo(_options: Options): Promise<void>;
4
+ export {};
@@ -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 default_base_1 = require("../../../utils/default-base");
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
- nxJson.defaultBase ??= deduceDefaultBase();
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 deduceDefaultBase() {
60
- try {
61
- (0, child_process_1.execSync)(`git rev-parse --verify main`, {
62
- stdio: ['ignore', 'ignore', 'ignore'],
63
- windowsHide: false,
64
- });
65
- return 'main';
66
- }
67
- catch {
68
- try {
69
- (0, child_process_1.execSync)(`git rev-parse --verify dev`, {
70
- stdio: ['ignore', 'ignore', 'ignore'],
71
- windowsHide: false,
72
- });
73
- return 'dev';
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
- catch {
76
- try {
77
- (0, child_process_1.execSync)(`git rev-parse --verify develop`, {
78
- stdio: ['ignore', 'ignore', 'ignore'],
79
- windowsHide: false,
80
- });
81
- return 'develop';
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
- catch {
84
- try {
85
- (0, child_process_1.execSync)(`git rev-parse --verify next`, {
86
- stdio: ['ignore', 'ignore', 'ignore'],
87
- windowsHide: false,
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
- catch {
100
- return (0, default_base_1.deduceDefaultBase)();
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`);