nx 20.5.0-beta.3 โ†’ 20.5.0-beta.5

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 (38) hide show
  1. package/package.json +11 -11
  2. package/schemas/nx-schema.json +36 -2
  3. package/src/command-line/add/add.js +6 -16
  4. package/src/command-line/init/command-object.js +5 -0
  5. package/src/command-line/init/configure-plugins.d.ts +5 -6
  6. package/src/command-line/init/configure-plugins.js +13 -22
  7. package/src/command-line/init/implementation/react/add-vite-commands-to-package-scripts.js +6 -4
  8. package/src/command-line/init/implementation/react/index.d.ts +1 -1
  9. package/src/command-line/init/implementation/react/index.js +32 -185
  10. package/src/command-line/init/implementation/react/write-vite-config.js +19 -3
  11. package/src/command-line/init/implementation/utils.d.ts +1 -0
  12. package/src/command-line/init/implementation/utils.js +14 -0
  13. package/src/command-line/init/init-v2.d.ts +1 -0
  14. package/src/command-line/init/init-v2.js +25 -3
  15. package/src/command-line/release/changelog.js +3 -5
  16. package/src/command-line/release/command-object.d.ts +1 -0
  17. package/src/command-line/release/command-object.js +5 -0
  18. package/src/command-line/release/config/config.js +7 -0
  19. package/src/command-line/release/utils/git.d.ts +1 -1
  20. package/src/command-line/release/utils/git.js +55 -7
  21. package/src/config/nx-json.d.ts +19 -1
  22. package/src/core/graph/main.js +1 -1
  23. package/src/core/graph/styles.js +1 -1
  24. package/src/daemon/server/server.js +1 -0
  25. package/src/native/index.d.ts +1 -1
  26. package/src/native/nx.wasm32-wasi.wasm +0 -0
  27. package/src/plugins/js/lock-file/lock-file.js +28 -13
  28. package/src/plugins/js/lock-file/yarn-parser.js +10 -10
  29. package/src/plugins/js/project-graph/affected/lock-file-changes.js +1 -0
  30. package/src/plugins/js/project-graph/build-dependencies/explicit-project-dependencies.js +1 -1
  31. package/src/plugins/js/utils/typescript.js +3 -3
  32. package/src/project-graph/plugins/isolation/plugin-worker.js +8 -6
  33. package/src/tasks-runner/run-command.js +2 -3
  34. package/src/utils/command-line-utils.d.ts +1 -1
  35. package/src/utils/find-matching-projects.js +2 -2
  36. package/src/utils/package-manager.js +2 -2
  37. package/src/command-line/init/implementation/react/write-craco-config.d.ts +0 -1
  38. package/src/command-line/init/implementation/react/write-craco-config.js +0 -61
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nx",
3
- "version": "20.5.0-beta.3",
3
+ "version": "20.5.0-beta.5",
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.3",
86
- "@nx/nx-darwin-x64": "20.5.0-beta.3",
87
- "@nx/nx-freebsd-x64": "20.5.0-beta.3",
88
- "@nx/nx-linux-arm-gnueabihf": "20.5.0-beta.3",
89
- "@nx/nx-linux-arm64-gnu": "20.5.0-beta.3",
90
- "@nx/nx-linux-arm64-musl": "20.5.0-beta.3",
91
- "@nx/nx-linux-x64-gnu": "20.5.0-beta.3",
92
- "@nx/nx-linux-x64-musl": "20.5.0-beta.3",
93
- "@nx/nx-win32-arm64-msvc": "20.5.0-beta.3",
94
- "@nx/nx-win32-x64-msvc": "20.5.0-beta.3"
85
+ "@nx/nx-darwin-arm64": "20.5.0-beta.5",
86
+ "@nx/nx-darwin-x64": "20.5.0-beta.5",
87
+ "@nx/nx-freebsd-x64": "20.5.0-beta.5",
88
+ "@nx/nx-linux-arm-gnueabihf": "20.5.0-beta.5",
89
+ "@nx/nx-linux-arm64-gnu": "20.5.0-beta.5",
90
+ "@nx/nx-linux-arm64-musl": "20.5.0-beta.5",
91
+ "@nx/nx-linux-x64-gnu": "20.5.0-beta.5",
92
+ "@nx/nx-linux-x64-musl": "20.5.0-beta.5",
93
+ "@nx/nx-win32-arm64-msvc": "20.5.0-beta.5",
94
+ "@nx/nx-win32-x64-msvc": "20.5.0-beta.5"
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
  },
@@ -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();
@@ -46,6 +46,11 @@ async function withInitOptions(yargs) {
46
46
  type: 'boolean',
47
47
  description: 'Initialize an Nx workspace setup in the .nx directory of the current repository.',
48
48
  default: false,
49
+ })
50
+ .option('force', {
51
+ describe: 'Force the migration to continue and ignore custom webpack setup or uncommitted changes. Only for CRA projects.',
52
+ type: 'boolean',
53
+ default: false,
49
54
  });
50
55
  }
51
56
  else {
@@ -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',
@@ -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
  }
@@ -16,3 +16,4 @@ export declare function printFinalMessage({ learnMoreLink, }: {
16
16
  learnMoreLink?: string;
17
17
  }): void;
18
18
  export declare function isMonorepo(packageJson: PackageJson): boolean;
19
+ export declare function isCRA(packageJson: PackageJson): boolean;
@@ -11,6 +11,7 @@ exports.markRootPackageJsonAsNxProjectLegacy = markRootPackageJsonAsNxProjectLeg
11
11
  exports.markPackageJsonAsNxProject = markPackageJsonAsNxProject;
12
12
  exports.printFinalMessage = printFinalMessage;
13
13
  exports.isMonorepo = isMonorepo;
14
+ exports.isCRA = isCRA;
14
15
  const child_process_1 = require("child_process");
15
16
  const path_1 = require("path");
16
17
  const fileutils_1 = require("../../../utils/fileutils");
@@ -266,3 +267,16 @@ function isMonorepo(packageJson) {
266
267
  return true;
267
268
  return false;
268
269
  }
270
+ function isCRA(packageJson) {
271
+ const combinedDependencies = {
272
+ ...packageJson.dependencies,
273
+ ...packageJson.devDependencies,
274
+ };
275
+ return (
276
+ // Required dependencies for CRA projects
277
+ combinedDependencies['react'] &&
278
+ combinedDependencies['react-dom'] &&
279
+ combinedDependencies['react-scripts'] &&
280
+ (0, fileutils_1.directoryExists)('src') &&
281
+ (0, fileutils_1.directoryExists)('public'));
282
+ }
@@ -5,6 +5,7 @@ export interface InitArgs {
5
5
  useDotNxInstallation?: boolean;
6
6
  integrated?: boolean;
7
7
  verbose?: boolean;
8
+ force?: boolean;
8
9
  }
9
10
  export declare function initHandler(options: InitArgs): Promise<void>;
10
11
  export declare function detectPlugins(nxJson: NxJsonConfiguration, interactive: boolean, includeAngularCli?: boolean): Promise<{