nx 21.0.0-beta.0 โ†’ 21.0.0-beta.2

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 (201) hide show
  1. package/.eslintrc.json +5 -1
  2. package/package.json +12 -12
  3. package/release/index.d.ts +1 -1
  4. package/release/index.js +2 -1
  5. package/schemas/nx-schema.json +186 -35
  6. package/src/adapter/compat.d.ts +1 -1
  7. package/src/adapter/compat.js +3 -0
  8. package/src/command-line/add/add.js +6 -16
  9. package/src/command-line/affected/command-object.js +6 -6
  10. package/src/command-line/examples.js +0 -4
  11. package/src/command-line/exec/command-object.js +1 -1
  12. package/src/command-line/generate/generator-utils.js +8 -3
  13. package/src/command-line/import/import.js +1 -1
  14. package/src/command-line/init/command-object.js +18 -6
  15. package/src/command-line/init/configure-plugins.d.ts +6 -7
  16. package/src/command-line/init/configure-plugins.js +47 -35
  17. package/src/command-line/init/implementation/add-nx-to-turborepo.d.ts +4 -0
  18. package/src/command-line/init/implementation/add-nx-to-turborepo.js +49 -0
  19. package/src/command-line/init/implementation/check-compatible-with-plugins.js +7 -1
  20. package/src/command-line/init/implementation/deduce-default-base.d.ts +1 -0
  21. package/src/command-line/init/implementation/deduce-default-base.js +53 -0
  22. package/src/command-line/init/implementation/react/add-vite-commands-to-package-scripts.js +6 -4
  23. package/src/command-line/init/implementation/react/index.d.ts +1 -1
  24. package/src/command-line/init/implementation/react/index.js +32 -185
  25. package/src/command-line/init/implementation/react/write-vite-config.js +19 -3
  26. package/src/command-line/init/implementation/utils.d.ts +4 -1
  27. package/src/command-line/init/implementation/utils.js +108 -44
  28. package/src/command-line/init/init-v1.js +1 -1
  29. package/src/command-line/init/init-v2.d.ts +1 -0
  30. package/src/command-line/init/init-v2.js +68 -38
  31. package/src/command-line/migrate/migrate.js +21 -18
  32. package/src/command-line/nx-commands.js +19 -5
  33. package/src/command-line/register/command-object.d.ts +6 -0
  34. package/src/command-line/{activate-powerpack โ†’ register}/command-object.js +9 -9
  35. package/src/command-line/register/register.d.ts +2 -0
  36. package/src/command-line/register/register.js +9 -0
  37. package/src/command-line/release/changelog.js +18 -15
  38. package/src/command-line/release/command-object.d.ts +2 -0
  39. package/src/command-line/release/command-object.js +9 -0
  40. package/src/command-line/release/config/config.d.ts +8 -7
  41. package/src/command-line/release/config/config.js +129 -42
  42. package/src/command-line/release/config/use-legacy-versioning.d.ts +2 -0
  43. package/src/command-line/release/config/use-legacy-versioning.js +9 -0
  44. package/src/command-line/release/index.d.ts +4 -0
  45. package/src/command-line/release/index.js +6 -1
  46. package/src/command-line/release/plan-check.js +6 -3
  47. package/src/command-line/release/plan.js +7 -3
  48. package/src/command-line/release/publish.js +7 -3
  49. package/src/command-line/release/release.js +8 -3
  50. package/src/command-line/release/utils/batch-projects-by-generator-config.js +6 -3
  51. package/src/command-line/release/utils/git.d.ts +3 -2
  52. package/src/command-line/release/utils/git.js +65 -9
  53. package/src/command-line/release/utils/github.js +3 -1
  54. package/src/command-line/release/utils/resolve-semver-specifier.d.ts +2 -1
  55. package/src/command-line/release/utils/resolve-semver-specifier.js +2 -1
  56. package/src/command-line/release/utils/semver.d.ts +8 -0
  57. package/src/command-line/release/utils/semver.js +8 -0
  58. package/src/command-line/release/utils/shared-legacy.d.ts +25 -0
  59. package/src/command-line/release/utils/shared-legacy.js +2 -0
  60. package/src/command-line/release/utils/shared.d.ts +11 -17
  61. package/src/command-line/release/version/derive-specifier-from-conventional-commits.d.ts +7 -0
  62. package/src/command-line/release/version/derive-specifier-from-conventional-commits.js +47 -0
  63. package/src/command-line/release/version/deriver-specifier-from-version-plans.d.ts +8 -0
  64. package/src/command-line/release/version/deriver-specifier-from-version-plans.js +59 -0
  65. package/src/command-line/release/version/project-logger.d.ts +8 -0
  66. package/src/command-line/release/version/project-logger.js +45 -0
  67. package/src/command-line/release/version/release-group-processor.d.ts +251 -0
  68. package/src/command-line/release/version/release-group-processor.js +1040 -0
  69. package/src/command-line/release/version/resolve-current-version.d.ts +32 -0
  70. package/src/command-line/release/version/resolve-current-version.js +241 -0
  71. package/src/command-line/release/version/test-utils.d.ts +95 -0
  72. package/src/command-line/release/version/test-utils.js +416 -0
  73. package/src/command-line/release/version/topological-sort.d.ts +9 -0
  74. package/src/command-line/release/version/topological-sort.js +41 -0
  75. package/src/command-line/release/version/version-actions.d.ts +170 -0
  76. package/src/command-line/release/version/version-actions.js +183 -0
  77. package/src/command-line/release/version-legacy.d.ts +46 -0
  78. package/src/command-line/release/version-legacy.js +453 -0
  79. package/src/command-line/release/version.d.ts +0 -40
  80. package/src/command-line/release/version.js +80 -262
  81. package/src/command-line/report/report.d.ts +7 -3
  82. package/src/command-line/report/report.js +52 -18
  83. package/src/command-line/run/command-object.js +2 -2
  84. package/src/command-line/run/run.js +1 -1
  85. package/src/command-line/run-many/command-object.js +2 -2
  86. package/src/command-line/yargs-utils/shared-options.d.ts +4 -0
  87. package/src/command-line/yargs-utils/shared-options.js +20 -0
  88. package/src/config/nx-json.d.ts +153 -15
  89. package/src/config/project-graph.d.ts +4 -2
  90. package/src/config/project-graph.js +8 -0
  91. package/src/config/workspace-json-project-json.d.ts +2 -2
  92. package/src/core/graph/main.js +1 -1
  93. package/src/core/graph/runtime.js +1 -1
  94. package/src/core/graph/styles.css +2 -2
  95. package/src/core/graph/styles.js +1 -1
  96. package/src/daemon/client/client.d.ts +2 -0
  97. package/src/daemon/client/client.js +15 -0
  98. package/src/daemon/message-types/glob.d.ts +7 -0
  99. package/src/daemon/message-types/glob.js +9 -1
  100. package/src/daemon/message-types/hash-glob.d.ts +6 -0
  101. package/src/daemon/message-types/hash-glob.js +9 -1
  102. package/src/daemon/server/handle-glob.d.ts +1 -0
  103. package/src/daemon/server/handle-glob.js +8 -0
  104. package/src/daemon/server/handle-hash-glob.d.ts +1 -0
  105. package/src/daemon/server/handle-hash-glob.js +8 -0
  106. package/src/daemon/server/logger.js +2 -1
  107. package/src/daemon/server/server.js +7 -0
  108. package/src/devkit-internals.d.ts +2 -1
  109. package/src/devkit-internals.js +4 -1
  110. package/src/executors/run-commands/run-commands.impl.d.ts +3 -5
  111. package/src/executors/run-commands/run-commands.impl.js +14 -42
  112. package/src/executors/run-commands/running-tasks.d.ts +7 -5
  113. package/src/executors/run-commands/running-tasks.js +64 -27
  114. package/src/executors/run-script/run-script.impl.js +3 -3
  115. package/src/generators/internal-utils/format-changed-files-with-prettier-if-available.js +8 -0
  116. package/src/generators/testing-utils/create-tree.js +5 -1
  117. package/src/native/index.d.ts +93 -19
  118. package/src/native/native-bindings.js +6 -0
  119. package/src/native/nx.wasi-browser.js +20 -19
  120. package/src/native/nx.wasi.cjs +20 -19
  121. package/src/native/nx.wasm32-wasi.wasm +0 -0
  122. package/src/nx-cloud/nx-cloud-tasks-runner-shell.js +3 -3
  123. package/src/plugins/js/lock-file/lock-file.js +28 -13
  124. package/src/plugins/js/lock-file/utils/package-json.d.ts +1 -1
  125. package/src/plugins/js/lock-file/utils/package-json.js +2 -1
  126. package/src/plugins/js/lock-file/yarn-parser.js +85 -39
  127. package/src/plugins/js/project-graph/affected/lock-file-changes.js +1 -0
  128. package/src/plugins/js/project-graph/build-dependencies/explicit-project-dependencies.js +1 -1
  129. package/src/plugins/js/project-graph/build-dependencies/target-project-locator.d.ts +10 -1
  130. package/src/plugins/js/project-graph/build-dependencies/target-project-locator.js +59 -6
  131. package/src/plugins/js/utils/packages.js +22 -3
  132. package/src/plugins/js/utils/register.js +1 -0
  133. package/src/plugins/js/utils/typescript.js +3 -3
  134. package/src/plugins/package-json/create-nodes.js +3 -1
  135. package/src/project-graph/affected/locators/project-glob-changes.js +2 -2
  136. package/src/project-graph/error-types.js +32 -2
  137. package/src/project-graph/nx-deps-cache.js +7 -2
  138. package/src/project-graph/plugins/get-plugins.js +2 -1
  139. package/src/project-graph/plugins/in-process-loader.js +1 -1
  140. package/src/project-graph/plugins/isolation/plugin-worker.js +12 -6
  141. package/src/project-graph/plugins/loaded-nx-plugin.d.ts +2 -1
  142. package/src/project-graph/plugins/loaded-nx-plugin.js +3 -7
  143. package/src/project-graph/plugins/utils.d.ts +2 -2
  144. package/src/project-graph/plugins/utils.js +2 -2
  145. package/src/project-graph/project-graph.js +5 -2
  146. package/src/project-graph/utils/project-configuration-utils.d.ts +1 -1
  147. package/src/project-graph/utils/project-configuration-utils.js +25 -11
  148. package/src/project-graph/utils/retrieve-workspace-files.d.ts +1 -1
  149. package/src/project-graph/utils/retrieve-workspace-files.js +14 -18
  150. package/src/tasks-runner/batch/batch-messages.d.ts +2 -0
  151. package/src/tasks-runner/batch/run-batch.js +2 -3
  152. package/src/tasks-runner/cache.d.ts +20 -6
  153. package/src/tasks-runner/cache.js +104 -20
  154. package/src/tasks-runner/create-task-graph.d.ts +1 -1
  155. package/src/tasks-runner/create-task-graph.js +12 -11
  156. package/src/tasks-runner/default-tasks-runner.js +4 -13
  157. package/src/tasks-runner/forked-process-task-runner.d.ts +6 -3
  158. package/src/tasks-runner/forked-process-task-runner.js +29 -28
  159. package/src/tasks-runner/init-tasks-runner.d.ts +15 -1
  160. package/src/tasks-runner/init-tasks-runner.js +55 -2
  161. package/src/tasks-runner/is-tui-enabled.d.ts +2 -0
  162. package/src/tasks-runner/is-tui-enabled.js +58 -0
  163. package/src/tasks-runner/life-cycle.d.ts +10 -3
  164. package/src/tasks-runner/life-cycle.js +23 -2
  165. package/src/tasks-runner/life-cycles/task-history-life-cycle-old.js +7 -2
  166. package/src/tasks-runner/life-cycles/task-history-life-cycle.js +6 -1
  167. package/src/tasks-runner/life-cycles/tui-summary-life-cycle.d.ts +17 -0
  168. package/src/tasks-runner/life-cycles/tui-summary-life-cycle.js +221 -0
  169. package/src/tasks-runner/pseudo-terminal.d.ts +10 -7
  170. package/src/tasks-runner/pseudo-terminal.js +37 -35
  171. package/src/tasks-runner/run-command.d.ts +1 -0
  172. package/src/tasks-runner/run-command.js +180 -23
  173. package/src/tasks-runner/task-env.d.ts +1 -4
  174. package/src/tasks-runner/task-env.js +2 -0
  175. package/src/tasks-runner/task-orchestrator.d.ts +21 -9
  176. package/src/tasks-runner/task-orchestrator.js +126 -44
  177. package/src/tasks-runner/utils.d.ts +2 -2
  178. package/src/tasks-runner/utils.js +15 -11
  179. package/src/utils/child-process.d.ts +4 -0
  180. package/src/utils/child-process.js +23 -30
  181. package/src/utils/command-line-utils.d.ts +1 -1
  182. package/src/utils/find-matching-projects.js +2 -2
  183. package/src/utils/handle-errors.js +15 -0
  184. package/src/utils/is-ci.js +4 -1
  185. package/src/utils/is-using-prettier.d.ts +3 -0
  186. package/src/utils/is-using-prettier.js +62 -0
  187. package/src/utils/nx-key.d.ts +7 -0
  188. package/src/utils/nx-key.js +52 -0
  189. package/src/utils/package-manager.js +2 -2
  190. package/src/utils/path.js +1 -1
  191. package/src/utils/require-nx-key.d.ts +1 -0
  192. package/src/utils/require-nx-key.js +22 -0
  193. package/src/utils/workspace-context.d.ts +2 -0
  194. package/src/utils/workspace-context.js +16 -0
  195. package/src/command-line/activate-powerpack/activate-powerpack.d.ts +0 -2
  196. package/src/command-line/activate-powerpack/activate-powerpack.js +0 -34
  197. package/src/command-line/activate-powerpack/command-object.d.ts +0 -6
  198. package/src/command-line/init/implementation/react/write-craco-config.d.ts +0 -1
  199. package/src/command-line/init/implementation/react/write-craco-config.js +0 -61
  200. package/src/utils/powerpack.d.ts +0 -5
  201. package/src/utils/powerpack.js +0 -33
@@ -1,64 +1,82 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.runPackageManagerInstallPlugins = runPackageManagerInstallPlugins;
4
- exports.installPlugin = installPlugin;
5
- exports.installPlugins = installPlugins;
3
+ exports.installPluginPackages = installPluginPackages;
4
+ exports.runPluginInitGenerator = runPluginInitGenerator;
5
+ exports.runPluginInitGenerators = runPluginInitGenerators;
6
6
  exports.configurePlugins = configurePlugins;
7
7
  exports.getFailedToInstallPluginErrorMessages = getFailedToInstallPluginErrorMessages;
8
8
  const createSpinner = require("ora");
9
9
  const chalk_1 = require("chalk");
10
10
  const package_manager_1 = require("../../utils/package-manager");
11
11
  const output_1 = require("../../utils/output");
12
- const tree_1 = require("../../generators/tree");
13
- const generator_utils_1 = require("../generate/generator-utils");
14
12
  const workspace_root_1 = require("../../utils/workspace-root");
15
13
  const utils_1 = require("./implementation/utils");
16
- const plugins_1 = require("../../utils/plugins");
17
14
  const angular_json_1 = require("../../adapter/angular-json");
18
15
  const error_types_1 = require("../../project-graph/error-types");
19
- function runPackageManagerInstallPlugins(repoRoot, pmc = (0, package_manager_1.getPackageManagerCommand)(), plugins) {
16
+ const generator_utils_1 = require("../generate/generator-utils");
17
+ const path_1 = require("path");
18
+ const fs_1 = require("fs");
19
+ const configuration_1 = require("../../config/configuration");
20
+ const versions_1 = require("../../utils/versions");
21
+ const child_process_1 = require("../../utils/child-process");
22
+ function installPluginPackages(repoRoot, pmc = (0, package_manager_1.getPackageManagerCommand)(), plugins) {
20
23
  if (plugins.length === 0) {
21
24
  return;
22
25
  }
23
- (0, utils_1.addDepsToPackageJson)(repoRoot, plugins);
24
- (0, utils_1.runInstall)(repoRoot, pmc);
26
+ if ((0, fs_1.existsSync)((0, path_1.join)(repoRoot, 'package.json'))) {
27
+ (0, utils_1.addDepsToPackageJson)(repoRoot, plugins);
28
+ (0, utils_1.runInstall)(repoRoot, pmc);
29
+ }
30
+ else {
31
+ const nxJson = (0, configuration_1.readNxJson)(repoRoot);
32
+ nxJson.installation.plugins ??= {};
33
+ for (const plugin of plugins) {
34
+ nxJson.installation.plugins[plugin] = versions_1.nxVersion;
35
+ }
36
+ // Invoking nx wrapper to install plugins.
37
+ (0, child_process_1.runNxSync)('--version', { stdio: 'ignore' });
38
+ }
25
39
  }
26
40
  /**
27
41
  * Installs a plugin by running its init generator. It will change the file system tree passed in.
28
42
  * @param plugin The name of the plugin to install
29
43
  * @param repoRoot repo root
30
- * @param verbose verbose
31
- * @param options options passed to init generator
44
+ * @param pmc package manager commands
45
+ * @param updatePackageScripts whether to update package scripts
46
+ * @param verbose whether to run in verbose mode
32
47
  * @returns void
33
48
  */
34
- async function installPlugin(plugin, repoRoot = workspace_root_1.workspaceRoot, verbose = false, options) {
35
- const host = new tree_1.FsTree(repoRoot, verbose, `install ${plugin}`);
36
- const capabilities = await (0, plugins_1.getPluginCapabilities)(repoRoot, plugin, {});
37
- const generators = capabilities?.generators;
38
- if (!generators) {
39
- throw new Error(`No generators found in ${plugin}.`);
49
+ async function runPluginInitGenerator(plugin, repoRoot = workspace_root_1.workspaceRoot, updatePackageScripts = false, verbose = false, pmc = (0, package_manager_1.getPackageManagerCommand)()) {
50
+ try {
51
+ const { schema } = (0, generator_utils_1.getGeneratorInformation)(plugin, 'init', workspace_root_1.workspaceRoot, {});
52
+ let command = `g ${plugin}:init ${verbose ? '--verbose' : ''}`;
53
+ if (!!schema.properties['keepExistingVersions']) {
54
+ command += ` --keepExistingVersions`;
55
+ }
56
+ if (updatePackageScripts && !!schema.properties['updatePackageScripts']) {
57
+ command += ` --updatePackageScripts`;
58
+ }
59
+ (0, child_process_1.runNxSync)(command, {
60
+ stdio: [0, 1, 2],
61
+ cwd: repoRoot,
62
+ windowsHide: false,
63
+ packageManagerCommand: pmc,
64
+ });
40
65
  }
41
- const initGenerator = findInitGenerator(generators);
42
- if (!initGenerator) {
66
+ catch {
67
+ // init generator does not exist, so this function should noop
43
68
  output_1.output.log({
44
69
  title: `No "init" generator found in ${plugin}. Skipping initialization.`,
45
70
  });
46
71
  return;
47
72
  }
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
- }
55
73
  }
56
74
  /**
57
75
  * Install plugins
58
76
  * Get the implementation of the plugin's init generator and run it
59
77
  * @returns a list of succeeded plugins and a map of failed plugins to errors
60
78
  */
61
- async function installPlugins(plugins, updatePackageScripts, repoRoot = workspace_root_1.workspaceRoot, verbose = false) {
79
+ async function runPluginInitGenerators(plugins, updatePackageScripts, pmc, repoRoot = workspace_root_1.workspaceRoot, verbose = false) {
62
80
  if (plugins.length === 0) {
63
81
  return {
64
82
  succeededPlugins: [],
@@ -71,13 +89,7 @@ async function installPlugins(plugins, updatePackageScripts, repoRoot = workspac
71
89
  for (const plugin of plugins) {
72
90
  try {
73
91
  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
- });
92
+ await runPluginInitGenerator(plugin, repoRoot, updatePackageScripts, verbose, pmc);
81
93
  succeededPlugins.push(plugin);
82
94
  spinner.succeed('Installed plugin ' + plugin);
83
95
  }
@@ -103,7 +115,7 @@ async function configurePlugins(plugins, updatePackageScripts, pmc, repoRoot = w
103
115
  };
104
116
  }
105
117
  output_1.output.log({ title: '๐Ÿ”จ Configuring plugins' });
106
- let { succeededPlugins, failedPlugins } = await installPlugins(plugins, updatePackageScripts, repoRoot, verbose);
118
+ let { succeededPlugins, failedPlugins } = await runPluginInitGenerators(plugins, updatePackageScripts, pmc, repoRoot, verbose);
107
119
  if (succeededPlugins.length > 0) {
108
120
  output_1.output.success({
109
121
  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
+ }
@@ -72,7 +72,13 @@ function findPluginAndFilesWithError(error) {
72
72
  },
73
73
  ];
74
74
  }
75
- excludeFiles = excludeFiles.filter(Boolean);
75
+ excludeFiles = excludeFiles.filter(Boolean).map((excludeFile) => {
76
+ const file = excludeFile.file;
77
+ excludeFile.file = file.startsWith(workspace_root_1.workspaceRoot)
78
+ ? (0, node_path_1.relative)(workspace_root_1.workspaceRoot, file)
79
+ : file;
80
+ return excludeFile;
81
+ });
76
82
  return {
77
83
  pluginIndex,
78
84
  excludeFiles,
@@ -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
+ }
@@ -9,10 +9,12 @@ function addViteCommandsToPackageScripts(appName, isStandalone) {
9
9
  const packageJson = (0, fileutils_1.readJsonFile)(packageJsonPath);
10
10
  packageJson.scripts = {
11
11
  ...packageJson.scripts,
12
- start: 'nx exec -- vite',
13
- serve: 'nx exec -- vite',
14
- build: `nx exec -- vite build`,
15
- test: 'nx exec -- vitest',
12
+ // These should be replaced by the vite init generator later.
13
+ start: 'vite',
14
+ test: 'vitest',
15
+ dev: 'vite',
16
+ build: 'vite build',
17
+ eject: undefined,
16
18
  };
17
19
  (0, fileutils_1.writeJsonFile)(packageJsonPath, packageJson, { spaces: 2 });
18
20
  }
@@ -1,4 +1,4 @@
1
1
  import { InitArgs } from '../../init-v1';
2
2
  type Options = InitArgs;
3
- export declare function addNxToCraRepo(options: Options): Promise<void>;
3
+ export declare function addNxToCraRepo(_options: Options): Promise<void>;
4
4
  export {};
@@ -2,43 +2,52 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.addNxToCraRepo = addNxToCraRepo;
4
4
  const child_process_1 = require("child_process");
5
- const node_fs_1 = require("node:fs");
6
5
  const path_1 = require("path");
6
+ const fs_1 = require("fs");
7
7
  const fileutils_1 = require("../../../../utils/fileutils");
8
8
  const output_1 = require("../../../../utils/output");
9
9
  const package_manager_1 = require("../../../../utils/package-manager");
10
10
  const check_for_custom_webpack_setup_1 = require("./check-for-custom-webpack-setup");
11
- const check_for_uncommitted_changes_1 = require("./check-for-uncommitted-changes");
12
- const clean_up_files_1 = require("./clean-up-files");
13
11
  const read_name_from_package_json_1 = require("./read-name-from-package-json");
14
12
  const rename_js_to_jsx_1 = require("./rename-js-to-jsx");
15
- const tsconfig_setup_1 = require("./tsconfig-setup");
16
- const write_craco_config_1 = require("./write-craco-config");
17
13
  const write_vite_config_1 = require("./write-vite-config");
18
14
  const write_vite_index_html_1 = require("./write-vite-index-html");
19
- const connect_to_nx_cloud_1 = require("../../../connect/connect-to-nx-cloud");
20
- async function addNxToCraRepo(options) {
21
- if (!options.force) {
22
- (0, check_for_uncommitted_changes_1.checkForUncommittedChanges)();
15
+ async function addNxToCraRepo(_options) {
16
+ if (!_options.force) {
23
17
  (0, check_for_custom_webpack_setup_1.checkForCustomWebpackSetup)();
24
18
  }
25
- output_1.output.log({ title: '๐Ÿณ Nx initialization' });
26
- const normalizedOptions = await normalizeOptions(options);
27
- await reorgnizeWorkspaceStructure(normalizedOptions);
19
+ const options = await normalizeOptions(_options);
20
+ await addBundler(options);
21
+ (0, fs_1.appendFileSync)(`.gitignore`, '\nnode_modules');
22
+ (0, fs_1.appendFileSync)(`.gitignore`, '\ndist');
23
+ installDependencies(options);
24
+ // Vite expects index.html to be in the root as the main entry point.
25
+ const indexPath = options.isStandalone
26
+ ? 'index.html'
27
+ : (0, path_1.join)('apps', options.reactAppName, 'index.html');
28
+ const oldIndexPath = options.isStandalone
29
+ ? (0, path_1.join)('public', 'index.html')
30
+ : (0, path_1.join)('apps', options.reactAppName, 'public', 'index.html');
31
+ output_1.output.note({
32
+ title: `A new ${indexPath} has been created. Compare it to the previous ${oldIndexPath} file and make any changes needed, then delete the previous file.`,
33
+ });
34
+ if (_options.force) {
35
+ output_1.output.note({
36
+ title: `Using --force converts projects with custom Webpack setup. You will need to manually update your vite.config.js file to match the plugins used in your old Webpack configuration.`,
37
+ });
38
+ }
28
39
  }
29
40
  function installDependencies(options) {
30
41
  const dependencies = [
42
+ '@rollup/plugin-replace',
31
43
  '@testing-library/jest-dom',
44
+ '@vitejs/plugin-react',
32
45
  'eslint-config-react-app',
33
46
  'web-vitals',
34
47
  'jest-watch-typeahead',
48
+ 'vite',
49
+ 'vitest',
35
50
  ];
36
- if (options.isVite) {
37
- dependencies.push('vite', 'vitest', '@vitejs/plugin-react');
38
- }
39
- else {
40
- dependencies.push('@craco/craco', 'cross-env', 'react-scripts', 'tsconfig-paths-webpack-plugin');
41
- }
42
51
  (0, child_process_1.execSync)(`${options.pmc.addDev} ${dependencies.join(' ')}`, {
43
52
  stdio: [0, 1, 2],
44
53
  windowsHide: false,
@@ -49,182 +58,20 @@ async function normalizeOptions(options) {
49
58
  const pmc = (0, package_manager_1.getPackageManagerCommand)(packageManager);
50
59
  const appIsJs = !(0, fileutils_1.fileExists)(`tsconfig.json`);
51
60
  const reactAppName = (0, read_name_from_package_json_1.readNameFromPackageJson)();
52
- const packageJson = (0, fileutils_1.readJsonFile)((0, path_1.join)(process.cwd(), 'package.json'));
53
- const deps = {
54
- ...packageJson.dependencies,
55
- ...packageJson.devDependencies,
56
- };
57
- const isCRA5 = /^[^~]?5/.test(deps['react-scripts']);
58
- const npmVersion = (0, child_process_1.execSync)('npm -v', {
59
- windowsHide: false,
60
- }).toString();
61
- // Should remove this check 04/2023 once Node 14 & npm 6 reach EOL
62
- const npxYesFlagNeeded = !npmVersion.startsWith('6'); // npm 7 added -y flag to npx
63
- const isVite = options.vite;
64
61
  const isStandalone = !options.integrated;
65
- const nxCloud = options.nxCloud ??
66
- (options.interactive ? await (0, connect_to_nx_cloud_1.connectExistingRepoToNxCloudPrompt)() : false);
67
62
  return {
68
63
  ...options,
69
- nxCloud,
70
64
  packageManager,
71
65
  pmc,
72
66
  appIsJs,
73
67
  reactAppName,
74
- isCRA5,
75
- npxYesFlagNeeded,
76
- isVite,
77
68
  isStandalone,
78
69
  };
79
70
  }
80
- /**
81
- * - Create a temp workspace
82
- * - Move all files to temp workspace
83
- * - Add bundler to temp workspace
84
- * - Move files back to root
85
- * - Clean up unused files
86
- */
87
- async function reorgnizeWorkspaceStructure(options) {
88
- createTempWorkspace(options);
89
- moveFilesToTempWorkspace(options);
90
- await addBundler(options);
91
- output_1.output.log({ title: '๐Ÿงถ Updating .gitignore file' });
92
- (0, child_process_1.execSync)(`echo "node_modules" >> .gitignore`, {
93
- stdio: [0, 1, 2],
94
- windowsHide: false,
95
- });
96
- (0, child_process_1.execSync)(`echo "dist" >> .gitignore`, {
97
- stdio: [0, 1, 2],
98
- windowsHide: false,
99
- });
100
- process.chdir('..');
101
- copyFromTempWorkspaceToRoot();
102
- cleanUpUnusedFilesAndAddConfigFiles(options);
103
- output_1.output.log({ title: '๐Ÿ™‚ Please be patient, one final step remaining!' });
104
- output_1.output.log({ title: '๐Ÿ“ฆ Installing dependencies' });
105
- installDependencies(options);
106
- if (options.isVite) {
107
- const indexPath = options.isStandalone
108
- ? 'index.html'
109
- : (0, path_1.join)('apps', options.reactAppName, 'index.html');
110
- const oldIndexPath = options.isStandalone
111
- ? (0, path_1.join)('public', 'index.html')
112
- : (0, path_1.join)('apps', options.reactAppName, 'public', 'index.html');
113
- output_1.output.note({
114
- title: `A new ${indexPath} has been created. Compare it to the previous ${oldIndexPath} file and make any changes needed, then delete the previous file.`,
115
- });
116
- }
117
- }
118
- function createTempWorkspace(options) {
119
- (0, node_fs_1.rmSync)('temp-workspace', { recursive: true, force: true });
120
- (0, child_process_1.execSync)(`npx ${options.npxYesFlagNeeded ? '-y' : ''} create-nx-workspace@latest temp-workspace --appName=${options.reactAppName} --preset=react-monorepo --style=css --bundler=${options.isVite ? 'vite' : 'webpack'} --packageManager=${options.packageManager} ${options.nxCloud ? '--nxCloud=yes' : '--nxCloud=skip'} ${options.addE2e ? '--e2eTestRunner=playwright' : '--e2eTestRunner=none'}`, { stdio: [0, 1, 2], windowsHide: false });
121
- output_1.output.log({ title: '๐Ÿ‘‹ Welcome to Nx!' });
122
- output_1.output.log({ title: '๐Ÿงน Clearing unused files' });
123
- (0, node_fs_1.cpSync)((0, path_1.join)('temp-workspace', 'apps', options.reactAppName, 'project.json'), 'project.json', { recursive: true });
124
- (0, node_fs_1.rmSync)((0, path_1.join)('temp-workspace', 'apps', options.reactAppName), {
125
- recursive: true,
126
- force: true,
127
- });
128
- (0, node_fs_1.rmSync)('node_modules', { recursive: true, force: true });
129
- }
130
- function copyPackageJsonDepsFromTempWorkspace() {
131
- const repoRoot = process.cwd();
132
- let rootPackageJson = (0, fileutils_1.readJsonFile)((0, path_1.join)(repoRoot, 'package.json'));
133
- const tempWorkspacePackageJson = (0, fileutils_1.readJsonFile)((0, path_1.join)(repoRoot, 'temp-workspace', 'package.json'));
134
- rootPackageJson = overridePackageDeps('dependencies', rootPackageJson, tempWorkspacePackageJson);
135
- rootPackageJson = overridePackageDeps('devDependencies', rootPackageJson, tempWorkspacePackageJson);
136
- rootPackageJson.scripts = {}; // remove existing scripts
137
- (0, fileutils_1.writeJsonFile)((0, path_1.join)(repoRoot, 'package.json'), rootPackageJson);
138
- (0, fileutils_1.writeJsonFile)((0, path_1.join)(repoRoot, 'temp-workspace', 'package.json'), rootPackageJson);
139
- }
140
- function overridePackageDeps(depConfigName, base, override) {
141
- if (!base[depConfigName]) {
142
- base[depConfigName] = override[depConfigName];
143
- return base;
144
- }
145
- const deps = override[depConfigName];
146
- Object.keys(deps).forEach((dep) => {
147
- if (base.dependencies?.[dep]) {
148
- delete base.dependencies[dep];
149
- }
150
- if (base.devDependencies?.[dep]) {
151
- delete base.devDependencies[dep];
152
- }
153
- base[depConfigName][dep] = deps[dep];
154
- });
155
- return base;
156
- }
157
- function moveSync(src, dest) {
158
- const destParentDir = (0, path_1.dirname)(dest);
159
- (0, node_fs_1.mkdirSync)(destParentDir, { recursive: true });
160
- (0, node_fs_1.rmSync)(dest, { recursive: true, force: true });
161
- return (0, node_fs_1.renameSync)(src, dest);
162
- }
163
- function moveFilesToTempWorkspace(options) {
164
- output_1.output.log({ title: '๐Ÿšš Moving your React app in your new Nx workspace' });
165
- copyPackageJsonDepsFromTempWorkspace();
166
- const requiredCraFiles = [
167
- 'project.json',
168
- 'package.json',
169
- 'src',
170
- 'public',
171
- options.appIsJs ? null : 'tsconfig.json',
172
- options.packageManager === 'yarn' ? 'yarn.lock' : null,
173
- options.packageManager === 'pnpm' ? 'pnpm-lock.yaml' : null,
174
- options.packageManager === 'npm' ? 'package-lock.json' : null,
175
- options.packageManager === 'bun' ? 'bun.lockb' : null,
176
- ];
177
- const optionalCraFiles = ['README.md'];
178
- const filesToMove = [...requiredCraFiles, ...optionalCraFiles].filter(Boolean);
179
- filesToMove.forEach((f) => {
180
- try {
181
- moveSync(f, options.isStandalone
182
- ? (0, path_1.join)('temp-workspace', f)
183
- : (0, path_1.join)('temp-workspace', 'apps', options.reactAppName, f));
184
- }
185
- catch (error) {
186
- if (requiredCraFiles.includes(f)) {
187
- throw error;
188
- }
189
- }
190
- });
191
- process.chdir('temp-workspace');
192
- }
193
71
  async function addBundler(options) {
194
- if (options.isVite) {
195
- output_1.output.log({ title: '๐Ÿง‘โ€๐Ÿ”ง Setting up Vite' });
196
- const { addViteCommandsToPackageScripts } = await Promise.resolve().then(() => require('./add-vite-commands-to-package-scripts'));
197
- addViteCommandsToPackageScripts(options.reactAppName, options.isStandalone);
198
- (0, write_vite_config_1.writeViteConfig)(options.reactAppName, options.isStandalone, options.appIsJs);
199
- (0, write_vite_index_html_1.writeViteIndexHtml)(options.reactAppName, options.isStandalone, options.appIsJs);
200
- await (0, rename_js_to_jsx_1.renameJsToJsx)(options.reactAppName, options.isStandalone);
201
- }
202
- else {
203
- output_1.output.log({ title: '๐Ÿง‘โ€๐Ÿ”ง Setting up craco + Webpack' });
204
- const { addCracoCommandsToPackageScripts } = await Promise.resolve().then(() => require('./add-craco-commands-to-package-scripts'));
205
- addCracoCommandsToPackageScripts(options.reactAppName, options.isStandalone);
206
- (0, write_craco_config_1.writeCracoConfig)(options.reactAppName, options.isCRA5, options.isStandalone);
207
- output_1.output.log({
208
- title: '๐Ÿ›ฌ Skip CRA preflight check since Nx manages the monorepo',
209
- });
210
- (0, child_process_1.execSync)(`echo "SKIP_PREFLIGHT_CHECK=true" > .env`, {
211
- stdio: [0, 1, 2],
212
- windowsHide: false,
213
- });
214
- }
215
- }
216
- function copyFromTempWorkspaceToRoot() {
217
- output_1.output.log({ title: '๐Ÿšš Folder restructuring.' });
218
- (0, node_fs_1.readdirSync)('temp-workspace').forEach((f) => {
219
- moveSync((0, path_1.join)('temp-workspace', f), f);
220
- });
221
- }
222
- function cleanUpUnusedFilesAndAddConfigFiles(options) {
223
- output_1.output.log({ title: '๐Ÿงน Cleaning up.' });
224
- (0, clean_up_files_1.cleanUpFiles)(options.reactAppName, options.isStandalone);
225
- output_1.output.log({ title: "๐Ÿ“ƒ Extend the app's tsconfig.json from the base" });
226
- (0, tsconfig_setup_1.setupTsConfig)(options.reactAppName, options.isStandalone);
227
- if (options.isStandalone) {
228
- (0, node_fs_1.rmSync)('apps', { recursive: true, force: true });
229
- }
72
+ const { addViteCommandsToPackageScripts } = await Promise.resolve().then(() => require('./add-vite-commands-to-package-scripts'));
73
+ addViteCommandsToPackageScripts(options.reactAppName, options.isStandalone);
74
+ (0, write_vite_config_1.writeViteConfig)(options.reactAppName, options.isStandalone, options.appIsJs);
75
+ (0, write_vite_index_html_1.writeViteIndexHtml)(options.reactAppName, options.isStandalone, options.appIsJs);
76
+ await (0, rename_js_to_jsx_1.renameJsToJsx)(options.reactAppName, options.isStandalone);
230
77
  }
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.writeViteConfig = writeViteConfig;
4
4
  const fs_1 = require("fs");
5
5
  function writeViteConfig(appName, isStandalone, isJs) {
6
- let port = 4200;
6
+ let port = 3000;
7
7
  // Use PORT from .env file if it exists in project.
8
8
  if ((0, fs_1.existsSync)(`../.env`)) {
9
9
  const envFile = (0, fs_1.readFileSync)(`../.env`).toString();
@@ -13,8 +13,20 @@ function writeViteConfig(appName, isStandalone, isJs) {
13
13
  port = portCandidate;
14
14
  }
15
15
  }
16
- (0, fs_1.writeFileSync)(isStandalone ? 'vite.config.js' : `apps/${appName}/vite.config.js`, `import { defineConfig } from 'vite'
16
+ (0, fs_1.writeFileSync)(isStandalone ? 'vite.config.mjs' : `apps/${appName}/vite.config.mjs`, `import { defineConfig } from 'vite'
17
17
  import react from '@vitejs/plugin-react'
18
+ import replace from '@rollup/plugin-replace';
19
+ import { nxViteTsPaths } from '@nx/vite/plugins/nx-tsconfig-paths.plugin';
20
+
21
+ // Match CRA's environment variables.
22
+ // TODO: Replace these with VITE_ prefixed environment variables, and using import.meta.env.VITE_* instead of process.env.REACT_APP_*.
23
+ const craEnvVarRegex = /^REACT_APP/i;
24
+ const craEnvVars = Object.keys(process.env)
25
+ .filter((key) => craEnvVarRegex.test(key))
26
+ .reduce((env, key) => {
27
+ env[\`process.env.\${key}\`] = JSON.stringify(process.env[key]);
28
+ return env;
29
+ }, {});
18
30
 
19
31
  // https://vitejs.dev/config/
20
32
  export default defineConfig({
@@ -31,7 +43,11 @@ export default defineConfig({
31
43
  setupFiles: 'src/setupTests.${isJs ? 'js' : 'ts'}',
32
44
  css: true,
33
45
  },
34
- plugins: [react()],
46
+ plugins: [
47
+ react(),
48
+ replace({ values: craEnvVars, preventAssignment: true }),
49
+ nxViteTsPaths(),
50
+ ],
35
51
  });
36
52
  `);
37
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;
@@ -14,3 +16,4 @@ export declare function printFinalMessage({ learnMoreLink, }: {
14
16
  learnMoreLink?: string;
15
17
  }): void;
16
18
  export declare function isMonorepo(packageJson: PackageJson): boolean;
19
+ export declare function isCRA(packageJson: PackageJson): boolean;