@nx/react 0.0.0-pr-29464-ef5660f → 0.0.0-pr-29720-06f67e5

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 (51) hide show
  1. package/package.json +6 -6
  2. package/src/generators/application/application.js +9 -48
  3. package/src/generators/application/lib/add-e2e.js +24 -29
  4. package/src/generators/application/lib/add-linting.d.ts +0 -1
  5. package/src/generators/application/lib/add-linting.js +0 -38
  6. package/src/generators/application/lib/add-project.js +15 -31
  7. package/src/generators/application/lib/add-routing.js +1 -1
  8. package/src/generators/application/lib/bundlers/add-vite.js +6 -15
  9. package/src/generators/application/lib/create-application-files.js +4 -41
  10. package/src/generators/application/lib/install-common-dependencies.js +2 -13
  11. package/src/generators/application/lib/normalize-options.d.ts +2 -0
  12. package/src/generators/application/lib/normalize-options.js +20 -11
  13. package/src/generators/application/schema.d.ts +1 -5
  14. package/src/generators/application/schema.json +1 -10
  15. package/src/generators/host/host.js +3 -6
  16. package/src/generators/init/init.js +0 -23
  17. package/src/generators/init/schema.d.ts +0 -2
  18. package/src/generators/library/lib/add-rollup-build-target.d.ts +1 -3
  19. package/src/generators/library/lib/add-rollup-build-target.js +7 -6
  20. package/src/generators/library/lib/create-files.js +1 -2
  21. package/src/generators/library/lib/normalize-options.js +5 -8
  22. package/src/generators/library/library.js +15 -21
  23. package/src/generators/library/schema.d.ts +0 -2
  24. package/src/generators/library/schema.json +0 -4
  25. package/src/generators/remote/remote.js +9 -12
  26. package/src/utils/ast-utils.d.ts +1 -1
  27. package/src/utils/ast-utils.js +2 -2
  28. package/src/utils/versions.d.ts +1 -3
  29. package/src/utils/versions.js +3 -6
  30. package/router-plugin.d.ts +0 -1
  31. package/router-plugin.js +0 -5
  32. package/src/generators/application/files/react-router-ssr/common/app/app-nav.tsx__tmpl__ +0 -15
  33. package/src/generators/application/files/react-router-ssr/common/app/entry.client.tsx__tmpl__ +0 -18
  34. package/src/generators/application/files/react-router-ssr/common/app/entry.server.tsx__tmpl__ +0 -74
  35. package/src/generators/application/files/react-router-ssr/common/app/root.tsx__tmpl__ +0 -51
  36. package/src/generators/application/files/react-router-ssr/common/app/routes/about.tsx__tmpl__ +0 -7
  37. package/src/generators/application/files/react-router-ssr/common/app/routes.tsx__tmpl__ +0 -6
  38. package/src/generators/application/files/react-router-ssr/common/public/favicon.ico +0 -0
  39. package/src/generators/application/files/react-router-ssr/common/react-router.config.ts__tmpl__ +0 -5
  40. package/src/generators/application/files/react-router-ssr/common/tests/routes/_index.spec.tsx__tmpl__ +0 -16
  41. package/src/generators/application/files/react-router-ssr/common/tsconfig.app.json__tmpl__ +0 -23
  42. package/src/generators/application/files/react-router-ssr/common/tsconfig.json__tmpl__ +0 -27
  43. package/src/generators/application/files/react-router-ssr/non-root/.gitignore__tmpl__ +0 -5
  44. package/src/generators/application/files/react-router-ssr/non-root/package.json__tmpl__ +0 -24
  45. package/src/generators/application/files/react-router-ssr/nx-welcome/claimed/app/nx-welcome.tsx__tmpl__ +0 -866
  46. package/src/generators/application/files/react-router-ssr/nx-welcome/not-configured/app/nx-welcome.tsx__tmpl__ +0 -866
  47. package/src/generators/application/files/react-router-ssr/nx-welcome/unclaimed/app/nx-welcome.tsx__tmpl__ +0 -864
  48. package/src/generators/application/files/react-router-ssr/ts-solution/package.json__tmpl__ +0 -24
  49. package/src/generators/application/files/react-router-ssr/ts-solution/tsconfig.app.json__tmpl__ +0 -39
  50. package/src/plugins/router-plugin.d.ts +0 -10
  51. package/src/plugins/router-plugin.js +0 -219
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nx/react",
3
- "version": "0.0.0-pr-29464-ef5660f",
3
+ "version": "0.0.0-pr-29720-06f67e5",
4
4
  "private": false,
5
5
  "description": "The React plugin for Nx contains executors and generators for managing React applications and libraries within an Nx workspace. It provides:\n\n\n- Integration with libraries such as Jest, Vitest, Playwright, Cypress, and Storybook.\n\n- Generators for applications, libraries, components, hooks, and more.\n\n- Library build support for publishing packages to npm or other registries.\n\n- Utilities for automatic workspace refactoring.",
6
6
  "repository": {
@@ -38,11 +38,11 @@
38
38
  "minimatch": "9.0.3",
39
39
  "picocolors": "^1.1.0",
40
40
  "tslib": "^2.3.0",
41
- "@nx/devkit": "0.0.0-pr-29464-ef5660f",
42
- "@nx/js": "0.0.0-pr-29464-ef5660f",
43
- "@nx/eslint": "0.0.0-pr-29464-ef5660f",
44
- "@nx/web": "0.0.0-pr-29464-ef5660f",
45
- "@nx/module-federation": "0.0.0-pr-29464-ef5660f",
41
+ "@nx/devkit": "0.0.0-pr-29720-06f67e5",
42
+ "@nx/js": "0.0.0-pr-29720-06f67e5",
43
+ "@nx/eslint": "0.0.0-pr-29720-06f67e5",
44
+ "@nx/web": "0.0.0-pr-29720-06f67e5",
45
+ "@nx/module-federation": "0.0.0-pr-29720-06f67e5",
46
46
  "express": "^4.21.2",
47
47
  "http-proxy-middleware": "^3.0.3",
48
48
  "semver": "^7.6.3"
@@ -26,11 +26,9 @@ const add_rspack_1 = require("./lib/bundlers/add-rspack");
26
26
  const add_rsbuild_1 = require("./lib/bundlers/add-rsbuild");
27
27
  const add_vite_1 = require("./lib/bundlers/add-vite");
28
28
  const sort_fields_1 = require("@nx/js/src/utils/package-json/sort-fields");
29
- const prompt_1 = require("@nx/devkit/src/generators/prompt");
30
29
  async function applicationGenerator(tree, schema) {
31
30
  return await applicationGeneratorInternal(tree, {
32
31
  addPlugin: false,
33
- useProjectJson: true,
34
32
  ...schema,
35
33
  });
36
34
  }
@@ -46,25 +44,11 @@ async function applicationGeneratorInternal(tree, schema) {
46
44
  });
47
45
  tasks.push(jsInitTask);
48
46
  const options = await (0, normalize_options_1.normalizeOptions)(tree, schema);
49
- options.useReactRouter = options.routing
50
- ? options.useReactRouter ??
51
- (await (0, prompt_1.promptWhenInteractive)({
52
- name: 'response',
53
- message: 'Would you like to use react-router for server-side rendering?',
54
- type: 'autocomplete',
55
- choices: [
56
- {
57
- name: 'Yes',
58
- message: 'I want to use react-router [ https://reactrouter.com/start/framework/routing ]',
59
- },
60
- {
61
- name: 'No',
62
- message: 'I do not want to use react-router for server-side rendering',
63
- },
64
- ],
65
- initial: 0,
66
- }, { response: 'No' }).then((r) => r.response === 'Yes'))
67
- : false;
47
+ // If we are using the new TS solution
48
+ // We need to update the workspace file (package.json or pnpm-workspaces.yaml) to include the new project
49
+ if (options.isUsingTsSolutionConfig) {
50
+ (0, ts_solution_setup_1.addProjectToTsSolutionWorkspace)(tree, options.appProjectRoot);
51
+ }
68
52
  (0, show_possible_warnings_1.showPossibleWarnings)(tree, options);
69
53
  const initTask = await (0, init_1.default)(tree, {
70
54
  ...options,
@@ -99,11 +83,6 @@ async function applicationGeneratorInternal(tree, schema) {
99
83
  }
100
84
  await (0, create_application_files_1.createApplicationFiles)(tree, options);
101
85
  (0, add_project_1.addProject)(tree, options);
102
- // If we are using the new TS solution
103
- // We need to update the workspace file (package.json or pnpm-workspaces.yaml) to include the new project
104
- if (options.isUsingTsSolutionConfig) {
105
- await (0, ts_solution_setup_1.addProjectToTsSolutionWorkspace)(tree, options.appProjectRoot);
106
- }
107
86
  if (options.style === 'tailwind') {
108
87
  const twTask = await (0, setup_tailwind_1.setupTailwindGenerator)(tree, {
109
88
  project: options.projectName,
@@ -133,34 +112,16 @@ async function applicationGeneratorInternal(tree, schema) {
133
112
  }
134
113
  // Handle tsconfig.spec.json for jest or vitest
135
114
  (0, update_jest_config_1.updateSpecConfig)(tree, options);
136
- const commonDependencyTask = await (0, install_common_dependencies_1.installCommonDependencies)(tree, options);
137
- tasks.push(commonDependencyTask);
115
+ const stylePreprocessorTask = await (0, install_common_dependencies_1.installCommonDependencies)(tree, options);
116
+ tasks.push(stylePreprocessorTask);
138
117
  const styledTask = (0, add_styled_dependencies_1.addStyledModuleDependencies)(tree, options);
139
118
  tasks.push(styledTask);
140
- if (!options.useReactRouter) {
141
- const routingTask = (0, add_routing_1.addRouting)(tree, options);
142
- tasks.push(routingTask);
143
- }
119
+ const routingTask = (0, add_routing_1.addRouting)(tree, options);
120
+ tasks.push(routingTask);
144
121
  (0, set_defaults_1.setDefaults)(tree, options);
145
122
  if (options.bundler === 'rspack' && options.style === 'styled-jsx') {
146
123
  (0, add_rspack_1.handleStyledJsxForRspack)(tasks, tree, options);
147
124
  }
148
- if (options.useReactRouter) {
149
- (0, devkit_1.updateJson)(tree, (0, devkit_1.joinPathFragments)(options.appProjectRoot, 'tsconfig.json'), (json) => {
150
- const types = new Set(json.compilerOptions?.types || []);
151
- types.add('@react-router/node');
152
- return {
153
- ...json,
154
- compilerOptions: {
155
- ...json.compilerOptions,
156
- jsx: 'react-jsx',
157
- moduleResolution: 'bundler',
158
- types: Array.from(types),
159
- },
160
- };
161
- });
162
- }
163
- // Only for the new TS solution
164
125
  (0, ts_solution_setup_1.updateTsconfigFiles)(tree, options.appProjectRoot, 'tsconfig.app.json', {
165
126
  jsx: 'react-jsx',
166
127
  module: 'esnext',
@@ -28,10 +28,8 @@ async function addE2e(tree, options) {
28
28
  e2eWebServerInfo = await getWebpackE2EWebServerInfo(tree, options.projectName, (0, devkit_1.joinPathFragments)(options.appProjectRoot, `webpack.config.${options.js ? 'js' : 'ts'}`), options.addPlugin, options.devServerPort ?? 4200);
29
29
  }
30
30
  else if (options.bundler === 'vite') {
31
- const { getViteE2EWebServerInfo, getReactRouterE2EWebServerInfo } = (0, devkit_1.ensurePackage)('@nx/vite', versions_1.nxVersion);
32
- e2eWebServerInfo = options.useReactRouter
33
- ? await getReactRouterE2EWebServerInfo(tree, options.projectName, (0, devkit_1.joinPathFragments)(options.appProjectRoot, `vite.config.${options.js ? 'js' : 'ts'}`), options.addPlugin, options.devServerPort ?? 4200)
34
- : await getViteE2EWebServerInfo(tree, options.projectName, (0, devkit_1.joinPathFragments)(options.appProjectRoot, `vite.config.${options.js ? 'js' : 'ts'}`), options.addPlugin, options.devServerPort ?? 4200);
31
+ const { getViteE2EWebServerInfo } = (0, devkit_1.ensurePackage)('@nx/vite', versions_1.nxVersion);
32
+ e2eWebServerInfo = await getViteE2EWebServerInfo(tree, options.projectName, (0, devkit_1.joinPathFragments)(options.appProjectRoot, `vite.config.${options.js ? 'js' : 'ts'}`), options.addPlugin, options.devServerPort ?? 4200);
35
33
  }
36
34
  else if (options.bundler === 'rsbuild') {
37
35
  (0, devkit_1.ensurePackage)('@nx/rsbuild', versions_1.nxVersion);
@@ -48,15 +46,17 @@ async function addE2e(tree, options) {
48
46
  switch (options.e2eTestRunner) {
49
47
  case 'cypress': {
50
48
  const { configurationGenerator } = (0, devkit_1.ensurePackage)('@nx/cypress', versions_1.nxVersion);
51
- const packageJson = {
52
- name: options.e2eProjectName,
53
- version: '0.0.1',
54
- private: true,
55
- };
56
- if (!options.useProjectJson) {
57
- packageJson.nx = {
58
- implicitDependencies: [options.projectName],
59
- };
49
+ if (options.isUsingTsSolutionConfig) {
50
+ (0, devkit_1.writeJson)(tree, (0, devkit_1.joinPathFragments)(options.e2eProjectRoot, 'package.json'), {
51
+ name: options.e2eProjectName,
52
+ version: '0.0.1',
53
+ private: true,
54
+ nx: {
55
+ projectType: 'application',
56
+ sourceRoot: (0, devkit_1.joinPathFragments)(options.e2eProjectRoot, 'src'),
57
+ implicitDependencies: [options.projectName],
58
+ },
59
+ });
60
60
  }
61
61
  else {
62
62
  (0, devkit_1.addProjectConfiguration)(tree, options.e2eProjectName, {
@@ -68,9 +68,6 @@ async function addE2e(tree, options) {
68
68
  tags: [],
69
69
  });
70
70
  }
71
- if (!options.useProjectJson || options.isUsingTsSolutionConfig) {
72
- (0, devkit_1.writeJson)(tree, (0, devkit_1.joinPathFragments)(options.e2eProjectRoot, 'package.json'), packageJson);
73
- }
74
71
  const e2eTask = await configurationGenerator(tree, {
75
72
  ...options,
76
73
  project: options.e2eProjectName,
@@ -119,15 +116,17 @@ async function addE2e(tree, options) {
119
116
  }
120
117
  case 'playwright': {
121
118
  const { configurationGenerator } = (0, devkit_1.ensurePackage)('@nx/playwright', versions_1.nxVersion);
122
- const packageJson = {
123
- name: options.e2eProjectName,
124
- version: '0.0.1',
125
- private: true,
126
- };
127
- if (!options.useProjectJson) {
128
- packageJson.nx = {
129
- implicitDependencies: [options.projectName],
130
- };
119
+ if (options.isUsingTsSolutionConfig) {
120
+ (0, devkit_1.writeJson)(tree, (0, devkit_1.joinPathFragments)(options.e2eProjectRoot, 'package.json'), {
121
+ name: options.e2eProjectName,
122
+ version: '0.0.1',
123
+ private: true,
124
+ nx: {
125
+ projectType: 'application',
126
+ sourceRoot: (0, devkit_1.joinPathFragments)(options.e2eProjectRoot, 'src'),
127
+ implicitDependencies: [options.projectName],
128
+ },
129
+ });
131
130
  }
132
131
  else {
133
132
  (0, devkit_1.addProjectConfiguration)(tree, options.e2eProjectName, {
@@ -136,12 +135,8 @@ async function addE2e(tree, options) {
136
135
  sourceRoot: (0, devkit_1.joinPathFragments)(options.e2eProjectRoot, 'src'),
137
136
  targets: {},
138
137
  implicitDependencies: [options.projectName],
139
- tags: [],
140
138
  });
141
139
  }
142
- if (!options.useProjectJson || options.isUsingTsSolutionConfig) {
143
- (0, devkit_1.writeJson)(tree, (0, devkit_1.joinPathFragments)(options.e2eProjectRoot, 'package.json'), packageJson);
144
- }
145
140
  const e2eTask = await configurationGenerator(tree, {
146
141
  project: options.e2eProjectName,
147
142
  skipFormat: true,
@@ -1,4 +1,3 @@
1
1
  import { type Tree, type GeneratorCallback } from '@nx/devkit';
2
2
  import { NormalizedSchema } from '../schema';
3
3
  export declare function addLinting(host: Tree, options: NormalizedSchema): Promise<GeneratorCallback>;
4
- export declare function isEslintInstalled(tree: Tree): boolean;
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.addLinting = addLinting;
4
- exports.isEslintInstalled = isEslintInstalled;
5
4
  const devkit_1 = require("@nx/devkit");
6
5
  const eslint_1 = require("@nx/eslint");
7
6
  const eslint_file_1 = require("@nx/eslint/src/generators/utils/eslint-file");
@@ -9,7 +8,6 @@ const flat_config_1 = require("@nx/eslint/src/utils/flat-config");
9
8
  const devkit_2 = require("@nx/devkit");
10
9
  const add_swc_dependencies_1 = require("@nx/js/src/utils/swc/add-swc-dependencies");
11
10
  const lint_1 = require("../../../utils/lint");
12
- const versions_1 = require("../../../utils/versions");
13
11
  async function addLinting(host, options) {
14
12
  const tasks = [];
15
13
  if (options.linter === eslint_1.Linter.EsLint) {
@@ -45,42 +43,6 @@ async function addLinting(host, options) {
45
43
  const addSwcTask = (0, add_swc_dependencies_1.addSwcDependencies)(host);
46
44
  tasks.push(installTask, addSwcTask);
47
45
  }
48
- if (options.useReactRouter) {
49
- await ignoreReactRouterFilesInEslintConfig(host, options.appProjectRoot);
50
- }
51
46
  }
52
47
  return (0, devkit_2.runTasksInSerial)(...tasks);
53
48
  }
54
- async function ignoreReactRouterFilesInEslintConfig(tree, projectRoot) {
55
- if (!isEslintInstalled(tree)) {
56
- return;
57
- }
58
- (0, devkit_1.ensurePackage)('@nx/eslint', versions_1.nxVersion);
59
- const { addIgnoresToLintConfig, isEslintConfigSupported } = await Promise.resolve().then(() => require('@nx/eslint/src/generators/utils/eslint-file'));
60
- if (!isEslintConfigSupported(tree)) {
61
- return;
62
- }
63
- const { useFlatConfig } = await Promise.resolve().then(() => require('@nx/eslint/src/utils/flat-config'));
64
- const isUsingFlatConfig = useFlatConfig(tree);
65
- if (!projectRoot && !isUsingFlatConfig) {
66
- // root eslintrc files ignore all files and the root eslintrc files add
67
- // back all the project files, so we only add the ignores to the project
68
- // eslintrc files
69
- return;
70
- }
71
- // for flat config, we update the root config file
72
- const directory = isUsingFlatConfig ? '' : projectRoot ?? '';
73
- addIgnoresToLintConfig(tree, directory, ['**/build', '**/.react-router']);
74
- }
75
- function isEslintInstalled(tree) {
76
- try {
77
- require('eslint');
78
- return true;
79
- }
80
- catch { }
81
- // it might not be installed yet, but it might be in the tree pending install
82
- const { devDependencies, dependencies } = tree.exists('package.json')
83
- ? (0, devkit_1.readJson)(tree, 'package.json')
84
- : {};
85
- return !!devDependencies?.['eslint'] || !!dependencies?.['eslint'];
86
- }
@@ -28,42 +28,26 @@ function addProject(host, options) {
28
28
  serve: createRspackServeTarget(options),
29
29
  };
30
30
  }
31
- const packageJson = {
32
- name: options.importPath,
33
- version: '0.0.1',
34
- private: true,
35
- };
36
- if (!options.useProjectJson) {
37
- if (options.projectName !== options.importPath) {
38
- packageJson.nx = { name: options.projectName };
39
- }
40
- if (Object.keys(project.targets).length) {
41
- packageJson.nx ??= {};
42
- packageJson.nx.targets = project.targets;
43
- }
44
- if (options.parsedTags?.length) {
45
- packageJson.nx ??= {};
46
- packageJson.nx.tags = options.parsedTags;
47
- }
31
+ if (options.isUsingTsSolutionConfig) {
32
+ (0, devkit_1.writeJson)(host, (0, devkit_1.joinPathFragments)(options.appProjectRoot, 'package.json'), {
33
+ name: options.projectName,
34
+ version: '0.0.1',
35
+ private: true,
36
+ });
48
37
  }
49
- else {
38
+ if (!options.isUsingTsSolutionConfig || options.alwaysGenerateProjectJson) {
50
39
  (0, devkit_1.addProjectConfiguration)(host, options.projectName, {
51
40
  ...project,
52
41
  });
53
42
  }
54
- if (!options.useProjectJson || options.isUsingTsSolutionConfig) {
55
- // React Router already adds a package.json to the project root
56
- if (options.useReactRouter) {
57
- (0, devkit_1.updateJson)(host, (0, devkit_1.joinPathFragments)(options.appProjectRoot, 'package.json'), (json) => {
58
- return {
59
- name: packageJson.name,
60
- ...json,
61
- };
62
- });
63
- }
64
- else {
65
- (0, devkit_1.writeJson)(host, (0, devkit_1.joinPathFragments)(options.appProjectRoot, 'package.json'), packageJson);
66
- }
43
+ else if (options.parsedTags?.length ||
44
+ Object.keys(project.targets).length) {
45
+ const updatedProject = {
46
+ root: options.appProjectRoot,
47
+ targets: project.targets,
48
+ tags: options.parsedTags?.length ? options.parsedTags : undefined,
49
+ };
50
+ (0, devkit_1.updateProjectConfiguration)(host, options.projectName, updatedProject);
67
51
  }
68
52
  }
69
53
  function createRspackBuildTarget(options) {
@@ -20,7 +20,7 @@ function addRouting(host, options) {
20
20
  }, `src/app/${options.fileName}.tsx`));
21
21
  const appFileContent = host.read(appPath, 'utf-8');
22
22
  const appSource = tsModule.createSourceFile(appPath, appFileContent, tsModule.ScriptTarget.Latest, true);
23
- const changes = (0, devkit_1.applyChangesToString)(appFileContent, (0, ast_utils_1.addInitialRoutes)(appPath, appSource, options.inSourceTests));
23
+ const changes = (0, devkit_1.applyChangesToString)(appFileContent, (0, ast_utils_1.addInitialRoutes)(appPath, appSource));
24
24
  host.write(appPath, changes);
25
25
  if (!options.skipPackageJson) {
26
26
  return (0, devkit_1.addDependenciesToPackageJson)(host, { 'react-router-dom': versions_1.reactRouterDomVersion }, {});
@@ -11,18 +11,6 @@ async function setupViteConfiguration(tree, options, tasks) {
11
11
  if (tree.exists((0, devkit_1.joinPathFragments)(options.appProjectRoot, 'src/environments'))) {
12
12
  tree.delete((0, devkit_1.joinPathFragments)(options.appProjectRoot, 'src/environments'));
13
13
  }
14
- const reactRouterFrameworkConfig = {
15
- imports: [`import { reactRouter } from '@react-router/dev/vite'`],
16
- plugins: ['!process.env.VITEST && reactRouter()'],
17
- };
18
- const baseReactConfig = {
19
- imports: [
20
- options.compiler === 'swc'
21
- ? `import react from '@vitejs/plugin-react-swc'`
22
- : `import react from '@vitejs/plugin-react'`,
23
- ],
24
- plugins: ['react()'],
25
- };
26
14
  const viteTask = await viteConfigurationGenerator(tree, {
27
15
  uiFramework: 'react',
28
16
  project: options.projectName,
@@ -41,9 +29,12 @@ async function setupViteConfiguration(tree, options, tasks) {
41
29
  includeVitest: options.unitTestRunner === 'vitest',
42
30
  inSourceTests: options.inSourceTests,
43
31
  rollupOptionsExternal: ["'react'", "'react-dom'", "'react/jsx-runtime'"],
44
- ...(options.useReactRouter
45
- ? reactRouterFrameworkConfig
46
- : baseReactConfig),
32
+ imports: [
33
+ options.compiler === 'swc'
34
+ ? `import react from '@vitejs/plugin-react-swc'`
35
+ : `import react from '@vitejs/plugin-react'`,
36
+ ],
37
+ plugins: ['react()'],
47
38
  }, false);
48
39
  }
49
40
  async function setupVitestConfiguration(tree, options, tasks) {
@@ -12,7 +12,6 @@ const get_app_tests_1 = require("./get-app-tests");
12
12
  const onboarding_1 = require("nx/src/nx-cloud/utilities/onboarding");
13
13
  const has_rspack_plugin_1 = require("../../../utils/has-rspack-plugin");
14
14
  const ts_solution_setup_1 = require("@nx/js/src/utils/typescript/ts-solution-setup");
15
- const versions_1 = require("../../../utils/versions");
16
15
  async function createApplicationFiles(host, options) {
17
16
  let styleSolutionSpecificAppFiles;
18
17
  if (options.styledModule && options.style !== 'styled-jsx') {
@@ -40,15 +39,8 @@ async function createApplicationFiles(host, options) {
40
39
  const relativePathToRootTsConfig = (0, js_1.getRelativePathToRootTsConfig)(host, options.appProjectRoot);
41
40
  const appTests = (0, get_app_tests_1.getAppTests)(options);
42
41
  const templateVariables = {
43
- ...options.names,
42
+ ...(0, devkit_1.names)(options.name),
44
43
  ...options,
45
- typesNodeVersion: versions_1.typesNodeVersion,
46
- typesReactDomVersion: versions_1.typesReactDomVersion,
47
- reactRouterVersion: versions_1.reactRouterVersion,
48
- typesReactVersion: versions_1.typesReactVersion,
49
- reactDomVersion: versions_1.reactDomVersion,
50
- reactVersion: versions_1.reactVersion,
51
- reactRouterIsBotVersion: versions_1.reactRouterIsBotVersion,
52
44
  js: !!options.js, // Ensure this is defined in template
53
45
  tmpl: '',
54
46
  offsetFromRoot: (0, devkit_1.offsetFromRoot)(options.appProjectRoot),
@@ -58,12 +50,9 @@ async function createApplicationFiles(host, options) {
58
50
  hasStyleFile,
59
51
  isUsingTsSolutionSetup: (0, ts_solution_setup_1.isUsingTsSolutionSetup)(host),
60
52
  };
61
- if (options.bundler === 'vite' && !options.useReactRouter) {
53
+ if (options.bundler === 'vite') {
62
54
  (0, devkit_1.generateFiles)(host, (0, path_1.join)(__dirname, '../files/base-vite'), options.appProjectRoot, templateVariables);
63
55
  }
64
- else if (options.bundler === 'vite' && options.useReactRouter) {
65
- generateReactRouterFiles(host, options, templateVariables);
66
- }
67
56
  else if (options.bundler === 'webpack') {
68
57
  (0, devkit_1.generateFiles)(host, (0, path_1.join)(__dirname, '../files/base-webpack'), options.appProjectRoot, {
69
58
  ...templateVariables,
@@ -148,12 +137,9 @@ async function createApplicationFiles(host, options) {
148
137
  const tutorialUrl = options.rootProject
149
138
  ? 'https://nx.dev/getting-started/tutorials/react-standalone-tutorial'
150
139
  : 'https://nx.dev/react-tutorial/1-code-generation?utm_source=nx-project';
151
- const path = options.useReactRouter
152
- ? '../files/react-router-ssr/nx-welcome'
153
- : '../files/nx-welcome';
154
- (0, devkit_1.generateFiles)(host, (0, path_1.join)(__dirname, path, onBoardingStatus), options.appProjectRoot, { ...templateVariables, connectCloudUrl, tutorialUrl });
140
+ (0, devkit_1.generateFiles)(host, (0, path_1.join)(__dirname, '../files/nx-welcome', onBoardingStatus), options.appProjectRoot, { ...templateVariables, connectCloudUrl, tutorialUrl });
155
141
  }
156
- (0, devkit_1.generateFiles)(host, (0, path_1.join)(__dirname, styleSolutionSpecificAppFiles, options.useReactRouter ? 'src' : ''), options.appProjectRoot, templateVariables);
142
+ (0, devkit_1.generateFiles)(host, (0, path_1.join)(__dirname, styleSolutionSpecificAppFiles), options.appProjectRoot, templateVariables);
157
143
  if (options.js) {
158
144
  (0, devkit_1.toJS)(host, {
159
145
  useJsx: options.bundler === 'vite' || options.bundler === 'rspack',
@@ -208,26 +194,3 @@ function createNxRspackPluginOptions(options, rootOffset) {
208
194
  ],
209
195
  };
210
196
  }
211
- function generateReactRouterFiles(tree, options, templateVariables) {
212
- (0, devkit_1.generateFiles)(tree, (0, path_1.join)(__dirname, '../files/react-router-ssr/common'), options.appProjectRoot, templateVariables);
213
- if (options.rootProject) {
214
- const gitignore = tree.read('.gitignore', 'utf-8');
215
- tree.write('.gitignore', `${gitignore}\n.cache\nbuild\npublic/build\n.env\n\.react-router\n`);
216
- }
217
- else {
218
- (0, devkit_1.generateFiles)(tree, (0, devkit_1.joinPathFragments)(__dirname, '../files/react-router-ssr/non-root'), options.appProjectRoot, templateVariables);
219
- }
220
- if (options.isUsingTsSolutionConfig) {
221
- (0, devkit_1.generateFiles)(tree, (0, devkit_1.joinPathFragments)(__dirname, '../files/react-router-ssr/ts-solution'), options.appProjectRoot, templateVariables);
222
- (0, devkit_1.updateJson)(tree, (0, devkit_1.joinPathFragments)(options.appProjectRoot, 'package.json'), (json) => {
223
- if (options.projectName !== options.importPath) {
224
- json.nx = { name: options.projectName };
225
- }
226
- if (options.parsedTags?.length) {
227
- json.nx ??= {};
228
- json.nx.tags = options.parsedTags;
229
- }
230
- return json;
231
- });
232
- }
233
- }
@@ -11,24 +11,13 @@ async function installCommonDependencies(host, options) {
11
11
  const reactDeps = await (0, version_utils_1.getReactDependenciesVersionsToInstall)(host);
12
12
  const dependencies = {};
13
13
  const devDependencies = {
14
+ '@types/node': versions_1.typesNodeVersion,
14
15
  '@types/react': reactDeps['@types/react'],
15
16
  '@types/react-dom': reactDeps['@types/react-dom'],
16
- '@types/node': versions_1.typesNodeVersion,
17
- ...(options.useReactRouter
18
- ? {
19
- '@react-router/dev': versions_1.reactRouterVersion,
20
- }
21
- : {}),
22
17
  };
23
18
  if (options.bundler !== 'vite') {
24
19
  dependencies['tslib'] = versions_1.tsLibVersion;
25
20
  }
26
- if (options.useReactRouter) {
27
- dependencies['react-router'] = versions_1.reactRouterVersion;
28
- dependencies['@react-router/node'] = versions_1.reactRouterVersion;
29
- dependencies['@react-router/serve'] = versions_1.reactRouterVersion;
30
- dependencies['isbot'] = versions_1.reactRouterIsBotVersion;
31
- }
32
21
  // Vite requires style preprocessors to be installed manually.
33
22
  // `@nx/webpack` installs them automatically for now.
34
23
  if (options.bundler === 'vite' || options.unitTestRunner === 'vitest') {
@@ -56,5 +45,5 @@ async function installCommonDependencies(host, options) {
56
45
  devDependencies['@testing-library/react'] = versions_1.testingLibraryReactVersion;
57
46
  devDependencies['@testing-library/dom'] = versions_1.testingLibraryDomVersion;
58
47
  }
59
- return (0, devkit_1.addDependenciesToPackageJson)(host, dependencies, devDependencies);
48
+ return (0, devkit_1.addDependenciesToPackageJson)(host, {}, devDependencies);
60
49
  }
@@ -1,3 +1,5 @@
1
1
  import { Tree } from '@nx/devkit';
2
2
  import { NormalizedSchema, Schema } from '../schema';
3
+ export declare function normalizeDirectory(options: Schema): string;
4
+ export declare function normalizeProjectName(options: Schema): string;
3
5
  export declare function normalizeOptions<T extends Schema = Schema>(host: Tree, options: Schema): Promise<NormalizedSchema<T>>;
@@ -1,14 +1,27 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.normalizeDirectory = normalizeDirectory;
4
+ exports.normalizeProjectName = normalizeProjectName;
3
5
  exports.normalizeOptions = normalizeOptions;
4
6
  const devkit_1 = require("@nx/devkit");
5
7
  const project_name_and_root_utils_1 = require("@nx/devkit/src/generators/project-name-and-root-utils");
6
8
  const assertion_1 = require("../../../utils/assertion");
7
9
  const find_free_port_1 = require("./find-free-port");
8
10
  const ts_solution_setup_1 = require("@nx/js/src/utils/typescript/ts-solution-setup");
11
+ const get_import_path_1 = require("@nx/js/src/utils/get-import-path");
12
+ function normalizeDirectory(options) {
13
+ options.directory = options.directory?.replace(/\\{1,2}/g, '/');
14
+ const { projectDirectory } = (0, devkit_1.extractLayoutDirectory)(options.directory);
15
+ return projectDirectory
16
+ ? `${(0, devkit_1.names)(projectDirectory).fileName}/${(0, devkit_1.names)(options.name).fileName}`
17
+ : (0, devkit_1.names)(options.name).fileName;
18
+ }
19
+ function normalizeProjectName(options) {
20
+ return normalizeDirectory(options).replace(new RegExp('/', 'g'), '-');
21
+ }
9
22
  async function normalizeOptions(host, options) {
10
- await (0, project_name_and_root_utils_1.ensureRootProjectName)(options, 'application');
11
- const { projectName, names: projectNames, projectRoot: appProjectRoot, importPath, } = await (0, project_name_and_root_utils_1.determineProjectNameAndRootOptions)(host, {
23
+ await (0, project_name_and_root_utils_1.ensureProjectName)(host, options, 'application');
24
+ const { projectName: appProjectName, projectRoot: appProjectRoot } = await (0, project_name_and_root_utils_1.determineProjectNameAndRootOptions)(host, {
12
25
  name: options.name,
13
26
  projectType: 'application',
14
27
  directory: options.directory,
@@ -19,8 +32,6 @@ async function normalizeOptions(host, options) {
19
32
  nxJson.useInferencePlugins !== false;
20
33
  options.addPlugin ??= addPlugin;
21
34
  options.rootProject = appProjectRoot === '.';
22
- const isUsingTsSolutionConfig = (0, ts_solution_setup_1.isUsingTsSolutionSetup)(host);
23
- const appProjectName = !isUsingTsSolutionConfig || options.name ? projectName : importPath;
24
35
  const e2eProjectName = options.rootProject ? 'e2e' : `${appProjectName}-e2e`;
25
36
  const e2eProjectRoot = options.rootProject ? 'e2e' : `${appProjectRoot}-e2e`;
26
37
  const parsedTags = options.tags
@@ -31,25 +42,23 @@ async function normalizeOptions(host, options) {
31
42
  ? null
32
43
  : options.style;
33
44
  (0, assertion_1.assertValidStyle)(options.style);
34
- options.bundler = options.useReactRouter ? 'vite' : options.bundler;
35
- options.useReactRouter = options.routing ? options.useReactRouter : false;
45
+ const isUsingTsSolutionConfig = (0, ts_solution_setup_1.isUsingTsSolutionSetup)(host);
36
46
  const normalized = {
37
47
  ...options,
38
- projectName: appProjectName,
48
+ name: appProjectName,
49
+ projectName: isUsingTsSolutionConfig
50
+ ? (0, get_import_path_1.getImportPath)(host, appProjectName)
51
+ : appProjectName,
39
52
  appProjectRoot,
40
- importPath,
41
53
  e2eProjectName,
42
54
  e2eProjectRoot,
43
55
  parsedTags,
44
56
  fileName,
45
57
  styledModule,
46
58
  hasStyles: options.style !== 'none',
47
- names: (0, devkit_1.names)(projectNames.projectSimpleName),
48
59
  isUsingTsSolutionConfig,
49
- useProjectJson: options.useProjectJson ?? !isUsingTsSolutionConfig,
50
60
  };
51
61
  normalized.routing = normalized.routing ?? false;
52
- normalized.useReactRouter = normalized.useReactRouter ?? false;
53
62
  normalized.strict = normalized.strict ?? true;
54
63
  normalized.classComponent = normalized.classComponent ?? false;
55
64
  normalized.compiler = normalized.compiler ?? 'babel';
@@ -1,4 +1,3 @@
1
- import type { names } from '@nx/devkit';
2
1
  import type { Linter, LinterType } from '@nx/eslint';
3
2
  import type { SupportedStyles } from '../../../typings/style';
4
3
 
@@ -14,7 +13,6 @@ export interface Schema {
14
13
  linter: Linter | LinterType;
15
14
  classComponent?: boolean;
16
15
  routing?: boolean;
17
- useReactRouter?: boolean;
18
16
  skipNxJson?: boolean;
19
17
  js?: boolean;
20
18
  globalCss?: boolean;
@@ -32,7 +30,7 @@ export interface Schema {
32
30
  nxCloudToken?: string;
33
31
  useTsSolution?: boolean;
34
32
  formatter?: 'prettier' | 'none';
35
- useProjectJson?: boolean;
33
+ alwaysGenerateProjectJson?: boolean; // this is needed for MF currently
36
34
  }
37
35
 
38
36
  export interface NormalizedSchema<T extends Schema = Schema> extends T {
@@ -40,13 +38,11 @@ export interface NormalizedSchema<T extends Schema = Schema> extends T {
40
38
  appProjectRoot: string;
41
39
  e2eProjectName: string;
42
40
  e2eProjectRoot: string;
43
- importPath: string;
44
41
  parsedTags: string[];
45
42
  fileName: string;
46
43
  styledModule: null | SupportedStyles;
47
44
  hasStyles: boolean;
48
45
  unitTestRunner: 'jest' | 'vitest' | 'none';
49
46
  addPlugin?: boolean;
50
- names: ReturnType<typeof names>;
51
47
  isUsingTsSolutionConfig?: boolean;
52
48
  }
@@ -83,12 +83,7 @@
83
83
  "routing": {
84
84
  "type": "boolean",
85
85
  "description": "Generate application with routes.",
86
- "x-prompt": "Would you like to add routing to this application?",
87
- "default": false
88
- },
89
- "useReactRouter": {
90
- "description": "Use React Router for routing.",
91
- "type": "boolean",
86
+ "x-prompt": "Would you like to add React Router to this application?",
92
87
  "default": false
93
88
  },
94
89
  "skipFormat": {
@@ -192,10 +187,6 @@
192
187
  "description": "Generate a React app with a minimal setup, no separate test files.",
193
188
  "type": "boolean",
194
189
  "default": false
195
- },
196
- "useProjectJson": {
197
- "type": "boolean",
198
- "description": "Use a `project.json` configuration file instead of inlining the Nx configuration in the `package.json` file."
199
190
  }
200
191
  },
201
192
  "required": ["directory"],