@nx/react 0.0.0-pr-29176-d3c6c29 → 0.0.0-pr-29314-bfd9d0c

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 (61) hide show
  1. package/generators.json +4 -2
  2. package/package.json +6 -6
  3. package/plugins/bundle-rollup.js +2 -2
  4. package/plugins/nx-react-webpack-plugin/lib/apply-react-config.js +3 -1
  5. package/src/executors/module-federation-dev-server/schema.json +14 -10
  6. package/src/executors/module-federation-ssr-dev-server/schema.json +13 -9
  7. package/src/executors/module-federation-static-server/module-federation-static-server.impl.js +5 -5
  8. package/src/executors/module-federation-static-server/schema.json +1 -1
  9. package/src/generators/application/application.d.ts +3 -3
  10. package/src/generators/application/application.js +59 -194
  11. package/src/generators/application/files/base-rsbuild/src/app/__fileName__.spec.tsx__tmpl__ +10 -0
  12. package/src/generators/application/files/base-rsbuild/src/assets/.gitkeep +0 -0
  13. package/src/generators/application/files/base-rsbuild/src/favicon.ico +0 -0
  14. package/src/generators/application/files/base-rsbuild/src/index.html +14 -0
  15. package/src/generators/application/files/base-rsbuild/src/main.tsx__tmpl__ +32 -0
  16. package/src/generators/application/files/base-rsbuild/tsconfig.app.json__tmpl__ +31 -0
  17. package/src/generators/application/files/style-tailwind/src/app/__fileName__.tsx__tmpl__ +1 -1
  18. package/src/generators/application/lib/add-e2e.js +12 -1
  19. package/src/generators/application/lib/add-linting.d.ts +3 -0
  20. package/src/generators/application/lib/add-linting.js +48 -0
  21. package/src/generators/application/lib/bundlers/add-rsbuild.d.ts +4 -0
  22. package/src/generators/application/lib/bundlers/add-rsbuild.js +63 -0
  23. package/src/generators/application/lib/bundlers/add-rspack.d.ts +5 -0
  24. package/src/generators/application/lib/bundlers/add-rspack.js +55 -0
  25. package/src/generators/application/lib/bundlers/add-vite.d.ts +4 -0
  26. package/src/generators/application/lib/bundlers/add-vite.js +67 -0
  27. package/src/generators/application/lib/bundlers/add-webpack.d.ts +3 -0
  28. package/src/generators/application/lib/bundlers/add-webpack.js +18 -0
  29. package/src/generators/application/lib/create-application-files.js +5 -0
  30. package/src/generators/application/schema.d.ts +1 -1
  31. package/src/generators/application/schema.json +4 -4
  32. package/src/generators/component/component.js +19 -32
  33. package/src/generators/component/files/{__fileName__.tsx__tmpl__ → __fileName__.__ext__} +5 -5
  34. package/src/generators/component/lib/normalize-options.js +7 -4
  35. package/src/generators/component/schema.d.ts +9 -3
  36. package/src/generators/component/schema.json +6 -6
  37. package/src/generators/component-story/component-story.js +1 -2
  38. package/src/generators/federate-module/schema.json +14 -8
  39. package/src/generators/hook/files/{__fileName__.ts__tmpl__ → __fileName__.__ext__} +3 -1
  40. package/src/generators/hook/hook.js +21 -22
  41. package/src/generators/hook/schema.d.ts +4 -0
  42. package/src/generators/hook/schema.json +8 -4
  43. package/src/generators/host/schema.json +9 -8
  44. package/src/generators/library/lib/add-rollup-build-target.js +30 -27
  45. package/src/generators/library/library.js +6 -1
  46. package/src/generators/library/schema.json +4 -0
  47. package/src/generators/redux/files/js/__fileName__.__ext__ +114 -0
  48. package/src/generators/redux/files/{__fileName__.slice.spec.ts__tmpl__ → js/__fileName__.spec.__ext__} +1 -1
  49. package/src/generators/redux/files/ts/__fileName__.spec.__ext__ +56 -0
  50. package/src/generators/redux/redux.js +19 -16
  51. package/src/generators/redux/schema.d.ts +10 -2
  52. package/src/generators/redux/schema.json +8 -4
  53. package/src/generators/remote/lib/update-host-with-remote.js +2 -2
  54. package/src/generators/remote/schema.json +9 -8
  55. package/src/generators/stories/stories.js +5 -2
  56. package/src/generators/storybook-configuration/configuration.js +2 -2
  57. package/src/utils/has-rsbuild-plugin.d.ts +2 -0
  58. package/src/utils/has-rsbuild-plugin.js +10 -0
  59. /package/src/generators/component/files/{__fileName__.spec.tsx__tmpl__ → __fileName__.spec.__ext__} +0 -0
  60. /package/src/generators/hook/files/{__fileName__.spec.tsx__tmpl__ → __fileName__.spec.__specExt__} +0 -0
  61. /package/src/generators/redux/files/{__fileName__.slice.ts__tmpl__ → ts/__fileName__.__ext__} +0 -0
package/generators.json CHANGED
@@ -64,13 +64,15 @@
64
64
  "factory": "./src/generators/host/host",
65
65
  "schema": "./src/generators/host/schema.json",
66
66
  "x-type": "application",
67
- "description": "Generate a host react application"
67
+ "description": "Generate a host react application",
68
+ "aliases": ["consumer"]
68
69
  },
69
70
  "remote": {
70
71
  "factory": "./src/generators/remote/remote",
71
72
  "schema": "./src/generators/remote/schema.json",
72
73
  "x-type": "application",
73
- "description": "Generate a remote react application"
74
+ "description": "Generate a remote react application",
75
+ "aliases": ["producer"]
74
76
  },
75
77
  "cypress-component-configuration": {
76
78
  "factory": "./src/generators/cypress-component-configuration/cypress-component-configuration#cypressComponentConfigGenerator",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nx/react",
3
- "version": "0.0.0-pr-29176-d3c6c29",
3
+ "version": "0.0.0-pr-29314-bfd9d0c",
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-29176-d3c6c29",
42
- "@nx/js": "0.0.0-pr-29176-d3c6c29",
43
- "@nx/eslint": "0.0.0-pr-29176-d3c6c29",
44
- "@nx/web": "0.0.0-pr-29176-d3c6c29",
45
- "@nx/module-federation": "0.0.0-pr-29176-d3c6c29",
41
+ "@nx/devkit": "0.0.0-pr-29314-bfd9d0c",
42
+ "@nx/js": "0.0.0-pr-29314-bfd9d0c",
43
+ "@nx/eslint": "0.0.0-pr-29314-bfd9d0c",
44
+ "@nx/web": "0.0.0-pr-29314-bfd9d0c",
45
+ "@nx/module-federation": "0.0.0-pr-29314-bfd9d0c",
46
46
  "express": "^4.19.2",
47
47
  "http-proxy-middleware": "^3.0.3"
48
48
  },
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- // TODO(v22): Remove this in Nx 22 and migrate to explicit rollup.config.js files.
3
+ // TODO(v22): Remove this in Nx 22 and migrate to explicit rollup.config.cjs files.
4
4
  /**
5
- * @deprecated Use `withNx` function from `@nx/rollup/with-nx` in your rollup.config.js file instead. Use `nx g @nx/rollup:convert-to-inferred` to generate the rollup.config.js file if it does not exist.
5
+ * @deprecated Use `withNx` function from `@nx/rollup/with-nx` in your rollup.config.cjs file instead. Use `nx g @nx/rollup:convert-to-inferred` to generate the rollup.config.cjs file if it does not exist.
6
6
  */
7
7
  function getRollupOptions(options) {
8
8
  const extraGlobals = {
@@ -80,7 +80,9 @@ function addHotReload(config) {
80
80
  // We remove potentially conflicting rules that target SVGs because we use @svgr/webpack loader
81
81
  // See https://github.com/nrwl/nx/issues/14383
82
82
  function removeSvgLoaderIfPresent(config) {
83
- const svgLoaderIdx = config.module.rules.findIndex((rule) => typeof rule === 'object' && rule.test.toString().includes('svg'));
83
+ const svgLoaderIdx = config.module.rules.findIndex((rule) => typeof rule === 'object' &&
84
+ typeof rule.test !== 'undefined' &&
85
+ rule.test.toString().includes('svg'));
84
86
  if (svgLoaderIdx === -1)
85
87
  return;
86
88
  config.module.rules.splice(svgLoaderIdx, 1);
@@ -28,16 +28,18 @@
28
28
  }
29
29
  ]
30
30
  },
31
- "description": "List of remote applications to run in development mode (i.e. using serve target).",
32
- "x-priority": "important"
31
+ "description": "List of Producer (remote) applications to run in development mode (i.e. using serve target).",
32
+ "x-priority": "important",
33
+ "alias": "devProducers"
33
34
  },
34
35
  "skipRemotes": {
35
36
  "type": "array",
36
37
  "items": {
37
38
  "type": "string"
38
39
  },
39
- "description": "List of remote applications to not automatically serve, either statically or in development mode. This will not remove the remotes from the `module-federation.config` file, and therefore the application may still try to fetch these remotes.\nThis option is useful if you have other means for serving the `remote` application(s).\n**NOTE:** Remotes that are not in the workspace will be skipped automatically.",
40
- "x-priority": "important"
40
+ "description": "List of Producer (remote) applications to not automatically serve, either statically or in development mode. This will not remove the Producers (remotes) from the `module-federation.config` file, and therefore the application may still try to fetch these Producers (remotes).\nThis option is useful if you have other means for serving the Producer (remote) application(s).\n**NOTE:** Producers (remotes) that are not in the workspace will be skipped automatically.",
41
+ "x-priority": "important",
42
+ "alias": "skipProducers"
41
43
  },
42
44
  "buildTarget": {
43
45
  "type": "string",
@@ -111,25 +113,27 @@
111
113
  },
112
114
  "static": {
113
115
  "type": "boolean",
114
- "description": "Whether to use a static file server instead of the webpack-dev-server. This should be used for remote applications that are also host applications."
116
+ "description": "Whether to use a static file server instead of the webpack-dev-server. This should be used for Producer (remote) applications that are also Consumer (host) applications."
115
117
  },
116
118
  "isInitialHost": {
117
119
  "type": "boolean",
118
- "description": "Whether the host that is running this executor is the first in the project tree to do so.",
120
+ "description": "Whether the Consumer (host) that is running this executor is the first in the project tree to do so.",
119
121
  "default": true,
120
- "x-priority": "internal"
122
+ "x-priority": "internal",
123
+ "alias": "isInitialConsumer"
121
124
  },
122
125
  "parallel": {
123
126
  "type": "number",
124
- "description": "Max number of parallel processes for building static remotes"
127
+ "description": "Max number of parallel processes for building static Producers (remotes)"
125
128
  },
126
129
  "staticRemotesPort": {
127
130
  "type": "number",
128
- "description": "The port at which to serve the file-server for the static remotes."
131
+ "description": "The port at which to serve the file-server for the static Producers (remotes).",
132
+ "alias": "staticProducersPort"
129
133
  },
130
134
  "pathToManifestFile": {
131
135
  "type": "string",
132
- "description": "Path to a Module Federation manifest file (e.g. `my/path/to/module-federation.manifest.json`) containing the dynamic remote applications relative to the workspace root."
136
+ "description": "Path to a Module Federation manifest file (e.g. `my/path/to/module-federation.manifest.json`) containing the dynamic Producer (remote) applications relative to the workspace root."
133
137
  }
134
138
  },
135
139
  "examplesFile": "../../../docs/module-federation-dev-server-examples.md"
@@ -2,7 +2,7 @@
2
2
  "version": 2,
3
3
  "outputCapture": "direct-nodejs",
4
4
  "title": "Module Federation SSR Dev Server",
5
- "description": "Serve a SSR host application along with its known remotes.",
5
+ "description": "Serve a SSR Consumer (host) application along with its known Producers (remotes).",
6
6
  "cli": "nx",
7
7
  "type": "object",
8
8
  "properties": {
@@ -27,16 +27,18 @@
27
27
  "items": {
28
28
  "type": "string"
29
29
  },
30
- "description": "List of remote applications to run in development mode (i.e. using serve target).",
31
- "x-priority": "important"
30
+ "description": "List of Producer (remote) applications to run in development mode (i.e. using serve target).",
31
+ "x-priority": "important",
32
+ "alias": "devProducers"
32
33
  },
33
34
  "skipRemotes": {
34
35
  "type": "array",
35
36
  "items": {
36
37
  "type": "string"
37
38
  },
38
- "description": "List of remote applications to not automatically serve, either statically or in development mode.",
39
- "x-priority": "important"
39
+ "description": "List of Producer (remote) applications to not automatically serve, either statically or in development mode.",
40
+ "x-priority": "important",
41
+ "alias": "skipProducers"
40
42
  },
41
43
  "host": {
42
44
  "type": "string",
@@ -45,11 +47,12 @@
45
47
  },
46
48
  "staticRemotesPort": {
47
49
  "type": "number",
48
- "description": "The port at which to serve the file-server for the static remotes."
50
+ "description": "The port at which to serve the file-server for the static Producers (remotes).",
51
+ "alias": "staticProducersPort"
49
52
  },
50
53
  "pathToManifestFile": {
51
54
  "type": "string",
52
- "description": "Path to a Module Federation manifest file (e.g. `my/path/to/module-federation.manifest.json`) containing the dynamic remote applications relative to the workspace root."
55
+ "description": "Path to a Module Federation manifest file (e.g. `my/path/to/module-federation.manifest.json`) containing the dynamic Producer (remote) applications relative to the workspace root."
53
56
  },
54
57
  "ssl": {
55
58
  "type": "boolean",
@@ -66,9 +69,10 @@
66
69
  },
67
70
  "isInitialHost": {
68
71
  "type": "boolean",
69
- "description": "Whether the host that is running this executor is the first in the project tree to do so.",
72
+ "description": "Whether the Consumer (host) that is running this executor is the first in the project tree to do so.",
70
73
  "default": true,
71
- "x-priority": "internal"
74
+ "x-priority": "internal",
75
+ "alias": "isInitialConsumer"
72
76
  }
73
77
  },
74
78
  "required": ["browserTarget", "serverTarget"]
@@ -58,7 +58,7 @@ async function buildHost(nxBin, buildTarget, context) {
58
58
  }
59
59
  if (stdoutString.includes('Successfully ran target build')) {
60
60
  staticProcess.stdout.removeAllListeners('data');
61
- devkit_1.logger.info(`NX Built host`);
61
+ devkit_1.logger.info(`NX Built Consumer (host)`);
62
62
  res();
63
63
  }
64
64
  });
@@ -67,7 +67,7 @@ async function buildHost(nxBin, buildTarget, context) {
67
67
  staticProcess.stdout.removeAllListeners('data');
68
68
  staticProcess.stderr.removeAllListeners('data');
69
69
  if (code !== 0) {
70
- rej(`Host failed to build. See above for details.`);
70
+ rej(`Consumer (host) failed to build. See above for details.`);
71
71
  }
72
72
  else {
73
73
  res();
@@ -132,8 +132,8 @@ function startProxies(staticRemotesConfig, hostServeOptions, mappedLocationOfHos
132
132
  process.on('SIGTERM', () => proxyServer.close());
133
133
  process.on('exit', () => proxyServer.close());
134
134
  }
135
- devkit_1.logger.info(`NX Static remotes proxies started successfully`);
136
- devkit_1.logger.info(`NX Starting static host proxy...`);
135
+ devkit_1.logger.info(`NX Static Producers (remotes) proxies started successfully`);
136
+ devkit_1.logger.info(`NX Starting static Consumer (host) proxy...`);
137
137
  const expressProxy = express();
138
138
  expressProxy.use(createProxyMiddleware({
139
139
  target: mappedLocationOfHost,
@@ -155,7 +155,7 @@ function startProxies(staticRemotesConfig, hostServeOptions, mappedLocationOfHos
155
155
  .listen(hostServeOptions.port);
156
156
  process.on('SIGTERM', () => proxyServer.close());
157
157
  process.on('exit', () => proxyServer.close());
158
- devkit_1.logger.info('NX Static host proxy started successfully');
158
+ devkit_1.logger.info('NX Static Consumer (host) proxy started successfully');
159
159
  }
160
160
  async function* moduleFederationStaticServer(schema, context) {
161
161
  // Force Node to resolve to look for the nx binary that is inside node_modules
@@ -2,7 +2,7 @@
2
2
  "version": 2,
3
3
  "outputCapture": "direct-nodejs",
4
4
  "title": "Module Federation Static Dev Server",
5
- "description": "Serve a host application statically along with it's remotes.",
5
+ "description": "Serve a Consumer (host) application statically along with its Producers (remotes).",
6
6
  "cli": "nx",
7
7
  "type": "object",
8
8
  "properties": {
@@ -1,5 +1,5 @@
1
- import { Schema } from './schema';
2
1
  import { GeneratorCallback, Tree } from '@nx/devkit';
3
- export declare function applicationGenerator(host: Tree, schema: Schema): Promise<GeneratorCallback>;
4
- export declare function applicationGeneratorInternal(host: Tree, schema: Schema): Promise<GeneratorCallback>;
2
+ import { Schema } from './schema';
3
+ export declare function applicationGenerator(tree: Tree, schema: Schema): Promise<GeneratorCallback>;
4
+ export declare function applicationGeneratorInternal(tree: Tree, schema: Schema): Promise<GeneratorCallback>;
5
5
  export default applicationGenerator;
@@ -2,7 +2,14 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.applicationGenerator = applicationGenerator;
4
4
  exports.applicationGeneratorInternal = applicationGeneratorInternal;
5
- const lint_1 = require("../../utils/lint");
5
+ const devkit_1 = require("@nx/devkit");
6
+ const js_1 = require("@nx/js");
7
+ const log_show_project_command_1 = require("@nx/devkit/src/utils/log-show-project-command");
8
+ const ts_solution_setup_1 = require("@nx/js/src/utils/typescript/ts-solution-setup");
9
+ const create_ts_config_1 = require("../../utils/create-ts-config");
10
+ const add_styled_dependencies_1 = require("../../rules/add-styled-dependencies");
11
+ const setup_tailwind_1 = require("../setup-tailwind/setup-tailwind");
12
+ const init_1 = require("../init/init");
6
13
  const create_application_files_1 = require("./lib/create-application-files");
7
14
  const update_jest_config_1 = require("./lib/update-jest-config");
8
15
  const normalize_options_1 = require("./lib/normalize-options");
@@ -10,71 +17,23 @@ const add_project_1 = require("./lib/add-project");
10
17
  const add_jest_1 = require("./lib/add-jest");
11
18
  const add_routing_1 = require("./lib/add-routing");
12
19
  const set_defaults_1 = require("./lib/set-defaults");
13
- const add_styled_dependencies_1 = require("../../rules/add-styled-dependencies");
14
- const devkit_1 = require("@nx/devkit");
15
- const init_1 = require("../init/init");
16
- const eslint_1 = require("@nx/eslint");
17
- const versions_1 = require("../../utils/versions");
18
- const maybe_js_1 = require("../../utils/maybe-js");
19
- const install_common_dependencies_1 = require("./lib/install-common-dependencies");
20
- const create_ts_config_1 = require("../../utils/create-ts-config");
21
- const add_swc_dependencies_1 = require("@nx/js/src/utils/swc/add-swc-dependencies");
22
- const pc = require("picocolors");
23
- const show_possible_warnings_1 = require("./lib/show-possible-warnings");
20
+ const add_linting_1 = require("./lib/add-linting");
24
21
  const add_e2e_1 = require("./lib/add-e2e");
25
- const eslint_file_1 = require("@nx/eslint/src/generators/utils/eslint-file");
26
- const js_1 = require("@nx/js");
27
- const log_show_project_command_1 = require("@nx/devkit/src/utils/log-show-project-command");
28
- const setup_tailwind_1 = require("../setup-tailwind/setup-tailwind");
29
- const flat_config_1 = require("@nx/eslint/src/utils/flat-config");
30
- const ts_solution_setup_1 = require("@nx/js/src/utils/typescript/ts-solution-setup");
31
- async function addLinting(host, options) {
32
- const tasks = [];
33
- if (options.linter === eslint_1.Linter.EsLint) {
34
- const lintTask = await (0, eslint_1.lintProjectGenerator)(host, {
35
- linter: options.linter,
36
- project: options.projectName,
37
- tsConfigPaths: [
38
- (0, devkit_1.joinPathFragments)(options.appProjectRoot, 'tsconfig.app.json'),
39
- ],
40
- unitTestRunner: options.unitTestRunner,
41
- skipFormat: true,
42
- rootProject: options.rootProject,
43
- skipPackageJson: options.skipPackageJson,
44
- addPlugin: options.addPlugin,
45
- });
46
- tasks.push(lintTask);
47
- if ((0, eslint_file_1.isEslintConfigSupported)(host)) {
48
- if ((0, flat_config_1.useFlatConfig)(host)) {
49
- (0, eslint_file_1.addPredefinedConfigToFlatLintConfig)(host, options.appProjectRoot, 'flat/react');
50
- // Add an empty rules object to users know how to add/override rules
51
- (0, eslint_file_1.addOverrideToLintConfig)(host, options.appProjectRoot, {
52
- files: ['*.ts', '*.tsx', '*.js', '*.jsx'],
53
- rules: {},
54
- });
55
- }
56
- else {
57
- const addExtendsTask = (0, eslint_file_1.addExtendsToLintConfig)(host, options.appProjectRoot, { name: 'plugin:@nx/react', needCompatFixup: true });
58
- tasks.push(addExtendsTask);
59
- }
60
- }
61
- if (!options.skipPackageJson) {
62
- const installTask = (0, devkit_1.addDependenciesToPackageJson)(host, lint_1.extraEslintDependencies.dependencies, lint_1.extraEslintDependencies.devDependencies);
63
- const addSwcTask = (0, add_swc_dependencies_1.addSwcDependencies)(host);
64
- tasks.push(installTask, addSwcTask);
65
- }
66
- }
67
- return (0, devkit_1.runTasksInSerial)(...tasks);
68
- }
69
- async function applicationGenerator(host, schema) {
70
- return await applicationGeneratorInternal(host, {
22
+ const show_possible_warnings_1 = require("./lib/show-possible-warnings");
23
+ const install_common_dependencies_1 = require("./lib/install-common-dependencies");
24
+ const add_webpack_1 = require("./lib/bundlers/add-webpack");
25
+ const add_rspack_1 = require("./lib/bundlers/add-rspack");
26
+ const add_rsbuild_1 = require("./lib/bundlers/add-rsbuild");
27
+ const add_vite_1 = require("./lib/bundlers/add-vite");
28
+ async function applicationGenerator(tree, schema) {
29
+ return await applicationGeneratorInternal(tree, {
71
30
  addPlugin: false,
72
31
  ...schema,
73
32
  });
74
33
  }
75
- async function applicationGeneratorInternal(host, schema) {
34
+ async function applicationGeneratorInternal(tree, schema) {
76
35
  const tasks = [];
77
- const jsInitTask = await (0, js_1.initGenerator)(host, {
36
+ const jsInitTask = await (0, js_1.initGenerator)(tree, {
78
37
  ...schema,
79
38
  tsConfigName: schema.rootProject ? 'tsconfig.json' : 'tsconfig.base.json',
80
39
  skipFormat: true,
@@ -82,15 +41,15 @@ async function applicationGeneratorInternal(host, schema) {
82
41
  formatter: schema.formatter,
83
42
  });
84
43
  tasks.push(jsInitTask);
85
- const options = await (0, normalize_options_1.normalizeOptions)(host, schema);
86
- (0, show_possible_warnings_1.showPossibleWarnings)(host, options);
87
- const initTask = await (0, init_1.default)(host, {
44
+ const options = await (0, normalize_options_1.normalizeOptions)(tree, schema);
45
+ (0, show_possible_warnings_1.showPossibleWarnings)(tree, options);
46
+ const initTask = await (0, init_1.default)(tree, {
88
47
  ...options,
89
48
  skipFormat: true,
90
49
  });
91
50
  tasks.push(initTask);
92
51
  if (!options.addPlugin) {
93
- const nxJson = (0, devkit_1.readNxJson)(host);
52
+ const nxJson = (0, devkit_1.readNxJson)(tree);
94
53
  nxJson.targetDefaults ??= {};
95
54
  if (!Object.keys(nxJson.targetDefaults).includes('build')) {
96
55
  nxJson.targetDefaults.build = {
@@ -101,172 +60,78 @@ async function applicationGeneratorInternal(host, schema) {
101
60
  else if (!nxJson.targetDefaults.build.dependsOn) {
102
61
  nxJson.targetDefaults.build.dependsOn = ['^build'];
103
62
  }
104
- (0, devkit_1.updateNxJson)(host, nxJson);
63
+ (0, devkit_1.updateNxJson)(tree, nxJson);
105
64
  }
106
65
  if (options.bundler === 'webpack') {
107
- const { webpackInitGenerator } = (0, devkit_1.ensurePackage)('@nx/webpack', versions_1.nxVersion);
108
- const webpackInitTask = await webpackInitGenerator(host, {
109
- skipPackageJson: options.skipPackageJson,
110
- skipFormat: true,
111
- addPlugin: options.addPlugin,
112
- });
113
- tasks.push(webpackInitTask);
114
- if (!options.skipPackageJson) {
115
- const { ensureDependencies } = await Promise.resolve().then(() => require('@nx/webpack/src/utils/ensure-dependencies'));
116
- tasks.push(ensureDependencies(host, { uiFramework: 'react' }));
117
- }
66
+ await (0, add_webpack_1.initWebpack)(tree, options, tasks);
118
67
  }
119
68
  else if (options.bundler === 'rspack') {
120
- const { rspackInitGenerator } = (0, devkit_1.ensurePackage)('@nx/rspack', versions_1.nxVersion);
121
- const rspackInitTask = await rspackInitGenerator(host, {
122
- ...options,
123
- addPlugin: false,
124
- skipFormat: true,
125
- });
126
- tasks.push(rspackInitTask);
69
+ await (0, add_rspack_1.initRspack)(tree, options, tasks);
70
+ }
71
+ else if (options.bundler === 'rsbuild') {
72
+ await (0, add_rsbuild_1.initRsbuild)(tree, options, tasks);
127
73
  }
128
74
  if (!options.rootProject) {
129
- (0, create_ts_config_1.extractTsConfigBase)(host);
75
+ (0, create_ts_config_1.extractTsConfigBase)(tree);
130
76
  }
131
- await (0, create_application_files_1.createApplicationFiles)(host, options);
132
- (0, add_project_1.addProject)(host, options);
77
+ await (0, create_application_files_1.createApplicationFiles)(tree, options);
78
+ (0, add_project_1.addProject)(tree, options);
133
79
  if (options.style === 'tailwind') {
134
- const twTask = await (0, setup_tailwind_1.setupTailwindGenerator)(host, {
80
+ const twTask = await (0, setup_tailwind_1.setupTailwindGenerator)(tree, {
135
81
  project: options.projectName,
136
82
  });
137
83
  tasks.push(twTask);
138
84
  }
139
85
  if (options.bundler === 'vite') {
140
- const { createOrEditViteConfig, viteConfigurationGenerator } = (0, devkit_1.ensurePackage)('@nx/vite', versions_1.nxVersion);
141
- // We recommend users use `import.meta.env.MODE` and other variables in their code to differentiate between production and development.
142
- // See: https://vitejs.dev/guide/env-and-mode.html
143
- if (host.exists((0, devkit_1.joinPathFragments)(options.appProjectRoot, 'src/environments'))) {
144
- host.delete((0, devkit_1.joinPathFragments)(options.appProjectRoot, 'src/environments'));
145
- }
146
- const viteTask = await viteConfigurationGenerator(host, {
147
- uiFramework: 'react',
148
- project: options.projectName,
149
- newProject: true,
150
- includeVitest: options.unitTestRunner === 'vitest',
151
- inSourceTests: options.inSourceTests,
152
- compiler: options.compiler,
153
- skipFormat: true,
154
- addPlugin: options.addPlugin,
155
- projectType: 'application',
156
- });
157
- tasks.push(viteTask);
158
- createOrEditViteConfig(host, {
159
- project: options.projectName,
160
- includeLib: false,
161
- includeVitest: options.unitTestRunner === 'vitest',
162
- inSourceTests: options.inSourceTests,
163
- rollupOptionsExternal: [
164
- "'react'",
165
- "'react-dom'",
166
- "'react/jsx-runtime'",
167
- ],
168
- imports: [
169
- options.compiler === 'swc'
170
- ? `import react from '@vitejs/plugin-react-swc'`
171
- : `import react from '@vitejs/plugin-react'`,
172
- ],
173
- plugins: ['react()'],
174
- }, false);
86
+ await (0, add_vite_1.setupViteConfiguration)(tree, options, tasks);
175
87
  }
176
88
  else if (options.bundler === 'rspack') {
177
- const { configurationGenerator } = (0, devkit_1.ensurePackage)('@nx/rspack', versions_1.nxVersion);
178
- const rspackTask = await configurationGenerator(host, {
179
- project: options.projectName,
180
- main: (0, devkit_1.joinPathFragments)(options.appProjectRoot, (0, maybe_js_1.maybeJs)({
181
- js: options.js,
182
- useJsx: true,
183
- }, `src/main.tsx`)),
184
- tsConfig: (0, devkit_1.joinPathFragments)(options.appProjectRoot, 'tsconfig.app.json'),
185
- target: 'web',
186
- newProject: true,
187
- framework: 'react',
188
- });
189
- tasks.push(rspackTask);
89
+ await (0, add_rspack_1.setupRspackConfiguration)(tree, options, tasks);
90
+ }
91
+ else if (options.bundler === 'rsbuild') {
92
+ await (0, add_rsbuild_1.setupRsbuildConfiguration)(tree, options, tasks);
190
93
  }
191
94
  if (options.bundler !== 'vite' && options.unitTestRunner === 'vitest') {
192
- const { createOrEditViteConfig, vitestGenerator } = (0, devkit_1.ensurePackage)('@nx/vite', versions_1.nxVersion);
193
- const vitestTask = await vitestGenerator(host, {
194
- uiFramework: 'react',
195
- coverageProvider: 'v8',
196
- project: options.projectName,
197
- inSourceTests: options.inSourceTests,
198
- skipFormat: true,
199
- addPlugin: options.addPlugin,
200
- });
201
- tasks.push(vitestTask);
202
- createOrEditViteConfig(host, {
203
- project: options.projectName,
204
- includeLib: false,
205
- includeVitest: true,
206
- inSourceTests: options.inSourceTests,
207
- rollupOptionsExternal: [
208
- "'react'",
209
- "'react-dom'",
210
- "'react/jsx-runtime'",
211
- ],
212
- imports: [
213
- options.compiler === 'swc'
214
- ? `import react from '@vitejs/plugin-react-swc'`
215
- : `import react from '@vitejs/plugin-react'`,
216
- ],
217
- plugins: ['react()'],
218
- }, true);
95
+ await (0, add_vite_1.setupVitestConfiguration)(tree, options, tasks);
219
96
  }
220
97
  if ((options.bundler === 'vite' || options.unitTestRunner === 'vitest') &&
221
98
  options.inSourceTests) {
222
- host.delete((0, devkit_1.joinPathFragments)(options.appProjectRoot, `src/app/${options.fileName}.spec.tsx`));
99
+ tree.delete((0, devkit_1.joinPathFragments)(options.appProjectRoot, `src/app/${options.fileName}.spec.tsx`));
223
100
  }
224
- const lintTask = await addLinting(host, options);
101
+ const lintTask = await (0, add_linting_1.addLinting)(tree, options);
225
102
  tasks.push(lintTask);
226
- const e2eTask = await (0, add_e2e_1.addE2e)(host, options);
103
+ const e2eTask = await (0, add_e2e_1.addE2e)(tree, options);
227
104
  tasks.push(e2eTask);
228
105
  if (options.unitTestRunner === 'jest') {
229
- const jestTask = await (0, add_jest_1.addJest)(host, options);
106
+ const jestTask = await (0, add_jest_1.addJest)(tree, options);
230
107
  tasks.push(jestTask);
231
108
  }
232
109
  // Handle tsconfig.spec.json for jest or vitest
233
- (0, update_jest_config_1.updateSpecConfig)(host, options);
234
- const stylePreprocessorTask = (0, install_common_dependencies_1.installCommonDependencies)(host, options);
110
+ (0, update_jest_config_1.updateSpecConfig)(tree, options);
111
+ const stylePreprocessorTask = (0, install_common_dependencies_1.installCommonDependencies)(tree, options);
235
112
  tasks.push(stylePreprocessorTask);
236
- const styledTask = (0, add_styled_dependencies_1.addStyledModuleDependencies)(host, options);
113
+ const styledTask = (0, add_styled_dependencies_1.addStyledModuleDependencies)(tree, options);
237
114
  tasks.push(styledTask);
238
- const routingTask = (0, add_routing_1.addRouting)(host, options);
115
+ const routingTask = (0, add_routing_1.addRouting)(tree, options);
239
116
  tasks.push(routingTask);
240
- (0, set_defaults_1.setDefaults)(host, options);
117
+ (0, set_defaults_1.setDefaults)(tree, options);
241
118
  if (options.bundler === 'rspack' && options.style === 'styled-jsx') {
242
- devkit_1.logger.warn(`${pc.bold('styled-jsx')} is not supported by ${pc.bold('Rspack')}. We've added ${pc.bold('babel-loader')} to your project, but using babel will slow down your build.`);
243
- tasks.push((0, devkit_1.addDependenciesToPackageJson)(host, {}, { 'babel-loader': versions_1.babelLoaderVersion }));
244
- host.write((0, devkit_1.joinPathFragments)(options.appProjectRoot, 'rspack.config.js'), (0, devkit_1.stripIndents) `
245
- const { composePlugins, withNx, withReact } = require('@nx/rspack');
246
- module.exports = composePlugins(withNx(), withReact(), (config) => {
247
- config.module.rules.push({
248
- test: /\\.[jt]sx$/i,
249
- use: [
250
- {
251
- loader: 'babel-loader',
252
- options: {
253
- presets: ['@babel/preset-typescript'],
254
- plugins: ['styled-jsx/babel'],
255
- },
256
- },
257
- ],
258
- });
259
- return config;
260
- });
261
- `);
119
+ (0, add_rspack_1.handleStyledJsxForRspack)(tasks, tree, options);
262
120
  }
263
- (0, ts_solution_setup_1.updateTsconfigFiles)(host, options.appProjectRoot, 'tsconfig.app.json', {
121
+ (0, ts_solution_setup_1.updateTsconfigFiles)(tree, options.appProjectRoot, 'tsconfig.app.json', {
264
122
  jsx: 'react-jsx',
265
123
  module: 'esnext',
266
124
  moduleResolution: 'bundler',
267
- });
125
+ }, options.linter === 'eslint'
126
+ ? ['eslint.config.js', 'eslint.config.cjs', 'eslint.config.mjs']
127
+ : undefined);
128
+ // If we are using the new TS solution
129
+ // We need to update the workspace file (package.json or pnpm-workspaces.yaml) to include the new project
130
+ if (options.isUsingTsSolutionConfig) {
131
+ (0, ts_solution_setup_1.addProjectToTsSolutionWorkspace)(tree, options.appProjectRoot);
132
+ }
268
133
  if (!options.skipFormat) {
269
- await (0, devkit_1.formatFiles)(host);
134
+ await (0, devkit_1.formatFiles)(tree);
270
135
  }
271
136
  tasks.push(() => {
272
137
  (0, log_show_project_command_1.logShowProjectCommand)(options.projectName);
@@ -0,0 +1,10 @@
1
+ import { render } from '@testing-library/react';
2
+ <%_ if (routing) { _%>
3
+ import { BrowserRouter } from 'react-router-dom';
4
+ <%_ } _%>
5
+
6
+ import App from './<%= fileName %>';
7
+
8
+ describe('App', () => {
9
+ <%- appTests _%>
10
+ });
@@ -0,0 +1,14 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="utf-8" />
5
+ <title><%= className %></title>
6
+ <base href="/" />
7
+
8
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
9
+ <link rel="icon" type="image/x-icon" href="favicon.ico" />
10
+ </head>
11
+ <body>
12
+ <div id="root"></div>
13
+ </body>
14
+ </html>
@@ -0,0 +1,32 @@
1
+ <%_ if (strict) { _%>import { StrictMode } from 'react';<%_ } _%>
2
+ import * as ReactDOM from 'react-dom/client';
3
+ <%_ if (routing) { _%>import { BrowserRouter } from 'react-router-dom';<%_ } _%>
4
+ import App from './app/<%= fileName %>';
5
+ <%_ if(hasStyleFile) { _%>
6
+ import './styles.<%= style %>'
7
+ <%_ } _%>
8
+
9
+ const root = ReactDOM.createRoot(document.getElementById('root') as HTMLElement);
10
+ <%_ if(strict && !routing) { _%>
11
+ root.render(
12
+ <StrictMode>
13
+ <App/>
14
+ </StrictMode>
15
+ )
16
+ <%_ } _%>
17
+ <%_ if(!strict && routing) { _%>
18
+ root.render(
19
+ <BrowserRouter>
20
+ <App/>
21
+ </BrowserRouter>
22
+ )
23
+ <%_ } _%>
24
+ <%_ if(strict && routing) { _%>
25
+ root.render(
26
+ <StrictMode>
27
+ <BrowserRouter>
28
+ <App/>
29
+ </BrowserRouter>
30
+ </StrictMode>
31
+ )
32
+ <%_ } _%>