@nx/react 20.2.0-beta.3 → 20.2.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 (43) hide show
  1. package/package.json +6 -6
  2. package/src/executors/module-federation-static-server/module-federation-static-server.impl.d.ts +1 -1
  3. package/src/generators/application/application.js +27 -4
  4. package/src/generators/application/files/base-rspack/tsconfig.app.json__tmpl__ +21 -4
  5. package/src/generators/application/files/base-vite/tsconfig.app.json__tmpl__ +19 -2
  6. package/src/generators/application/files/base-webpack/tsconfig.app.json__tmpl__ +20 -3
  7. package/src/generators/application/files/style-css-module/src/app/__fileName__.tsx__tmpl__ +2 -2
  8. package/src/generators/application/lib/add-e2e.d.ts +1 -1
  9. package/src/generators/application/lib/add-e2e.js +43 -15
  10. package/src/generators/application/lib/add-jest.js +1 -0
  11. package/src/generators/application/lib/add-project.js +19 -3
  12. package/src/generators/application/lib/create-application-files.js +2 -0
  13. package/src/generators/application/lib/normalize-options.js +2 -0
  14. package/src/generators/application/lib/update-jest-config.js +5 -0
  15. package/src/generators/application/schema.d.ts +5 -0
  16. package/src/generators/application/schema.json +19 -15
  17. package/src/generators/component/component.js +3 -1
  18. package/src/generators/component/lib/normalize-options.js +2 -1
  19. package/src/generators/component/schema.d.ts +1 -1
  20. package/src/generators/component/schema.json +3 -5
  21. package/src/generators/hook/hook.js +10 -25
  22. package/src/generators/hook/schema.d.ts +0 -2
  23. package/src/generators/hook/schema.json +10 -18
  24. package/src/generators/host/host.js +3 -2
  25. package/src/generators/host/lib/update-module-federation-tsconfig.d.ts +3 -0
  26. package/src/generators/host/lib/update-module-federation-tsconfig.js +39 -0
  27. package/src/generators/init/init.js +0 -2
  28. package/src/generators/library/lib/create-files.d.ts +1 -1
  29. package/src/generators/library/lib/create-files.js +22 -2
  30. package/src/generators/library/lib/normalize-options.js +3 -0
  31. package/src/generators/library/library.js +46 -16
  32. package/src/generators/library/schema.d.ts +1 -0
  33. package/src/generators/library/schema.json +14 -11
  34. package/src/generators/redux/schema.json +13 -4
  35. package/src/generators/remote/remote.js +1 -2
  36. package/src/migrations/update-20-2-0/migrate-mf-imports-to-new-package.js +3 -0
  37. package/src/rules/update-module-federation-project.js +6 -0
  38. package/src/utils/build-static.remotes.d.ts +1 -1
  39. package/src/utils/create-ts-config.js +57 -7
  40. package/src/utils/versions.d.ts +0 -1
  41. package/src/utils/versions.js +1 -3
  42. package/src/generators/library/files/common/package.json__tmpl__ +0 -4
  43. package/src/generators/library/files/vite/package.json__tmpl__ +0 -12
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nx/react",
3
- "version": "20.2.0-beta.3",
3
+ "version": "20.2.0-beta.5",
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": "20.2.0-beta.3",
42
- "@nx/js": "20.2.0-beta.3",
43
- "@nx/eslint": "20.2.0-beta.3",
44
- "@nx/web": "20.2.0-beta.3",
45
- "@nx/module-federation": "20.2.0-beta.3",
41
+ "@nx/devkit": "20.2.0-beta.5",
42
+ "@nx/js": "20.2.0-beta.5",
43
+ "@nx/eslint": "20.2.0-beta.5",
44
+ "@nx/web": "20.2.0-beta.5",
45
+ "@nx/module-federation": "20.2.0-beta.5",
46
46
  "express": "^4.19.2",
47
47
  "http-proxy-middleware": "^3.0.3"
48
48
  },
@@ -9,4 +9,4 @@ export declare function startProxies(staticRemotesConfig: StaticRemotesConfig, h
9
9
  export default function moduleFederationStaticServer(schema: ModuleFederationStaticServerSchema, context: ExecutorContext): AsyncGenerator<{
10
10
  success: boolean;
11
11
  baseUrl: string;
12
- }, any, unknown>;
12
+ }, any, any>;
@@ -15,6 +15,7 @@ const devkit_1 = require("@nx/devkit");
15
15
  const init_1 = require("../init/init");
16
16
  const eslint_1 = require("@nx/eslint");
17
17
  const versions_1 = require("../../utils/versions");
18
+ const maybe_js_1 = require("../../utils/maybe-js");
18
19
  const install_common_dependencies_1 = require("./lib/install-common-dependencies");
19
20
  const create_ts_config_1 = require("../../utils/create-ts-config");
20
21
  const add_swc_dependencies_1 = require("@nx/js/src/utils/swc/add-swc-dependencies");
@@ -72,16 +73,17 @@ async function applicationGenerator(host, schema) {
72
73
  });
73
74
  }
74
75
  async function applicationGeneratorInternal(host, schema) {
75
- (0, ts_solution_setup_1.assertNotUsingTsSolutionSetup)(host, 'react', 'application');
76
76
  const tasks = [];
77
- const options = await (0, normalize_options_1.normalizeOptions)(host, schema);
78
- (0, show_possible_warnings_1.showPossibleWarnings)(host, options);
79
77
  const jsInitTask = await (0, js_1.initGenerator)(host, {
80
78
  ...schema,
81
79
  tsConfigName: schema.rootProject ? 'tsconfig.json' : 'tsconfig.base.json',
82
80
  skipFormat: true,
81
+ addTsPlugin: schema.useTsSolution,
82
+ formatter: schema.formatter,
83
83
  });
84
84
  tasks.push(jsInitTask);
85
+ const options = await (0, normalize_options_1.normalizeOptions)(host, schema);
86
+ (0, show_possible_warnings_1.showPossibleWarnings)(host, options);
85
87
  const initTask = await (0, init_1.default)(host, {
86
88
  ...options,
87
89
  skipFormat: true,
@@ -115,7 +117,7 @@ async function applicationGeneratorInternal(host, schema) {
115
117
  }
116
118
  }
117
119
  else if (options.bundler === 'rspack') {
118
- const { rspackInitGenerator } = (0, devkit_1.ensurePackage)('@nx/rspack', versions_1.nxRspackVersion);
120
+ const { rspackInitGenerator } = (0, devkit_1.ensurePackage)('@nx/rspack', versions_1.nxVersion);
119
121
  const rspackInitTask = await rspackInitGenerator(host, {
120
122
  ...options,
121
123
  addPlugin: false,
@@ -150,6 +152,7 @@ async function applicationGeneratorInternal(host, schema) {
150
152
  compiler: options.compiler,
151
153
  skipFormat: true,
152
154
  addPlugin: options.addPlugin,
155
+ projectType: 'application',
153
156
  });
154
157
  tasks.push(viteTask);
155
158
  createOrEditViteConfig(host, {
@@ -170,6 +173,21 @@ async function applicationGeneratorInternal(host, schema) {
170
173
  plugins: ['react()'],
171
174
  }, false);
172
175
  }
176
+ 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);
190
+ }
173
191
  if (options.bundler !== 'vite' && options.unitTestRunner === 'vitest') {
174
192
  const { createOrEditViteConfig, vitestGenerator } = (0, devkit_1.ensurePackage)('@nx/vite', versions_1.nxVersion);
175
193
  const vitestTask = await vitestGenerator(host, {
@@ -242,6 +260,11 @@ async function applicationGeneratorInternal(host, schema) {
242
260
  });
243
261
  `);
244
262
  }
263
+ (0, ts_solution_setup_1.updateTsconfigFiles)(host, options.appProjectRoot, 'tsconfig.app.json', {
264
+ jsx: 'react-jsx',
265
+ module: 'esnext',
266
+ moduleResolution: 'bundler',
267
+ });
245
268
  if (!options.skipFormat) {
246
269
  await (0, devkit_1.formatFiles)(host);
247
270
  }
@@ -1,14 +1,31 @@
1
- {
1
+ <%_ if (isUsingTsSolutionSetup) { _%>{
2
+ "extends": "<%= offsetFromRoot%>tsconfig.base.json",
3
+ "compilerOptions": {
4
+ "outDir": "dist",
5
+ "tsBuildInfoFile": "dist/tsconfig.lib.tsbuildinfo",
6
+ "jsx": "react-jsx",
7
+ "lib": ["dom"],
8
+ "types": [
9
+ "node",
10
+ <%_ if (style === 'styled-jsx') { _%>"@nx/react/typings/styled-jsx.d.ts",<%_ } _%>
11
+ "@nx/react/typings/cssmodule.d.ts",
12
+ "@nx/react/typings/image.d.ts"
13
+ ]
14
+ },
15
+ "exclude": ["src/**/*.spec.ts", "src/**/*.test.ts", "src/**/*.spec.tsx", "src/**/*.test.tsx", "src/**/*.spec.js", "src/**/*.test.js", "src/**/*.spec.jsx", "src/**/*.test.jsx"],
16
+ "include": ["src/**/*.js", "src/**/*.jsx", "src/**/*.ts", "src/**/*.tsx"]
17
+ }<% } else { %>{
2
18
  "extends": "./tsconfig.json",
3
19
  "compilerOptions": {
4
20
  "outDir": "<%= offsetFromRoot %>dist/out-tsc",
5
21
  "types": [
6
22
  "node",
7
- <%_ if (style === 'styled-jsx') { %>"@nx/react/typings/styled-jsx.d.ts",<% } _%>
23
+ <%_ if (style === 'styled-jsx') { _%>"@nx/react/typings/styled-jsx.d.ts",<%_ } _%>
8
24
  "@nx/react/typings/cssmodule.d.ts",
9
25
  "@nx/react/typings/image.d.ts"
10
- ]
26
+ ]
11
27
  },
12
- "exclude": ["jest.config.ts","src/**/*.spec.ts", "src/**/*.test.ts", "src/**/*.spec.tsx", "src/**/*.test.tsx", "src/**/*.spec.js", "src/**/*.test.js", "src/**/*.spec.jsx", "src/**/*.test.jsx"],
28
+ "exclude": ["src/**/*.spec.ts", "src/**/*.test.ts", "src/**/*.spec.tsx", "src/**/*.test.tsx", "src/**/*.spec.js", "src/**/*.test.js", "src/**/*.spec.jsx", "src/**/*.test.jsx"],
13
29
  "include": ["src/**/*.js", "src/**/*.jsx", "src/**/*.ts", "src/**/*.tsx"]
14
30
  }
31
+ <% } %>
@@ -1,4 +1,20 @@
1
- {
1
+ <%_ if (isUsingTsSolutionSetup) { _%>{
2
+ "extends": "<%= offsetFromRoot%>tsconfig.base.json",
3
+ "compilerOptions": {
4
+ "outDir": "dist",
5
+ "tsBuildInfoFile": "dist/tsconfig.lib.tsbuildinfo",
6
+ "jsx": "react-jsx",
7
+ "lib": ["dom"],
8
+ "types": [
9
+ "node",
10
+ <%_ if (style === 'styled-jsx') { _%>"@nx/react/typings/styled-jsx.d.ts",<%_ } _%>
11
+ "@nx/react/typings/cssmodule.d.ts",
12
+ "@nx/react/typings/image.d.ts"
13
+ ]
14
+ },
15
+ "exclude": ["src/**/*.spec.ts", "src/**/*.test.ts", "src/**/*.spec.tsx", "src/**/*.test.tsx", "src/**/*.spec.js", "src/**/*.test.js", "src/**/*.spec.jsx", "src/**/*.test.jsx"],
16
+ "include": ["src/**/*.js", "src/**/*.jsx", "src/**/*.ts", "src/**/*.tsx"]
17
+ }<% } else { %>{
2
18
  "extends": "./tsconfig.json",
3
19
  "compilerOptions": {
4
20
  "outDir": "<%= offsetFromRoot %>dist/out-tsc",
@@ -7,8 +23,9 @@
7
23
  <%_ if (style === 'styled-jsx') { _%>"@nx/react/typings/styled-jsx.d.ts",<%_ } _%>
8
24
  "@nx/react/typings/cssmodule.d.ts",
9
25
  "@nx/react/typings/image.d.ts"
10
- ]
26
+ ]
11
27
  },
12
28
  "exclude": ["src/**/*.spec.ts", "src/**/*.test.ts", "src/**/*.spec.tsx", "src/**/*.test.tsx", "src/**/*.spec.js", "src/**/*.test.js", "src/**/*.spec.jsx", "src/**/*.test.jsx"],
13
29
  "include": ["src/**/*.js", "src/**/*.jsx", "src/**/*.ts", "src/**/*.tsx"]
14
30
  }
31
+ <% } %>
@@ -1,4 +1,20 @@
1
- {
1
+ <%_ if (isUsingTsSolutionSetup) { _%>{
2
+ "extends": "<%= offsetFromRoot%>tsconfig.base.json",
3
+ "compilerOptions": {
4
+ "outDir": "dist",
5
+ "tsBuildInfoFile": "dist/tsconfig.lib.tsbuildinfo",
6
+ "jsx": "react-jsx",
7
+ "lib": ["dom"],
8
+ "types": [
9
+ "node",
10
+ <%_ if (style === 'styled-jsx') { _%>"@nx/react/typings/styled-jsx.d.ts",<%_ } _%>
11
+ "@nx/react/typings/cssmodule.d.ts",
12
+ "@nx/react/typings/image.d.ts"
13
+ ]
14
+ },
15
+ "exclude": ["src/**/*.spec.ts", "src/**/*.test.ts", "src/**/*.spec.tsx", "src/**/*.test.tsx", "src/**/*.spec.js", "src/**/*.test.js", "src/**/*.spec.jsx", "src/**/*.test.jsx"],
16
+ "include": ["src/**/*.js", "src/**/*.jsx", "src/**/*.ts", "src/**/*.tsx"]
17
+ }<% } else { %>{
2
18
  "extends": "./tsconfig.json",
3
19
  "compilerOptions": {
4
20
  "outDir": "<%= offsetFromRoot %>dist/out-tsc",
@@ -7,8 +23,9 @@
7
23
  <%_ if (style === 'styled-jsx') { _%>"@nx/react/typings/styled-jsx.d.ts",<%_ } _%>
8
24
  "@nx/react/typings/cssmodule.d.ts",
9
25
  "@nx/react/typings/image.d.ts"
10
- ]
26
+ ]
11
27
  },
12
- "exclude": ["jest.config.ts","src/**/*.spec.ts", "src/**/*.test.ts", "src/**/*.spec.tsx", "src/**/*.test.tsx", "src/**/*.spec.js", "src/**/*.test.js", "src/**/*.spec.jsx", "src/**/*.test.jsx"],
28
+ "exclude": ["src/**/*.spec.ts", "src/**/*.test.ts", "src/**/*.spec.tsx", "src/**/*.test.tsx", "src/**/*.spec.js", "src/**/*.test.js", "src/**/*.spec.jsx", "src/**/*.test.jsx"],
13
29
  "include": ["src/**/*.js", "src/**/*.jsx", "src/**/*.ts", "src/**/*.tsx"]
14
30
  }
31
+ <% } %>
@@ -1,8 +1,8 @@
1
1
  <% if (classComponent) { %>
2
2
  import { Component } from 'react';
3
3
  <%_ } _%>
4
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
5
- import styles from './<%= fileName %>.module.<%= style %>';
4
+ // Uncomment this line to use CSS modules
5
+ // import styles from './<%= fileName %>.module.<%= style %>';
6
6
  <%_ if (!minimal) { _%>
7
7
  import NxWelcome from "./nx-welcome";
8
8
  <%_ } _%>
@@ -1,3 +1,3 @@
1
- import type { GeneratorCallback, Tree } from '@nx/devkit';
1
+ import { GeneratorCallback, Tree } from '@nx/devkit';
2
2
  import { NormalizedSchema } from '../schema';
3
3
  export declare function addE2e(tree: Tree, options: NormalizedSchema): Promise<GeneratorCallback>;
@@ -38,14 +38,28 @@ async function addE2e(tree, options) {
38
38
  switch (options.e2eTestRunner) {
39
39
  case 'cypress': {
40
40
  const { configurationGenerator } = (0, devkit_1.ensurePackage)('@nx/cypress', versions_1.nxVersion);
41
- (0, devkit_1.addProjectConfiguration)(tree, options.e2eProjectName, {
42
- projectType: 'application',
43
- root: options.e2eProjectRoot,
44
- sourceRoot: (0, devkit_1.joinPathFragments)(options.e2eProjectRoot, 'src'),
45
- targets: {},
46
- implicitDependencies: [options.projectName],
47
- tags: [],
48
- });
41
+ if (options.isUsingTsSolutionConfig) {
42
+ (0, devkit_1.writeJson)(tree, (0, devkit_1.joinPathFragments)(options.e2eProjectRoot, 'package.json'), {
43
+ name: options.e2eProjectName,
44
+ version: '0.0.1',
45
+ private: true,
46
+ nx: {
47
+ projectType: 'application',
48
+ sourceRoot: (0, devkit_1.joinPathFragments)(options.e2eProjectRoot, 'src'),
49
+ implicitDependencies: [options.projectName],
50
+ },
51
+ });
52
+ }
53
+ else {
54
+ (0, devkit_1.addProjectConfiguration)(tree, options.e2eProjectName, {
55
+ projectType: 'application',
56
+ root: options.e2eProjectRoot,
57
+ sourceRoot: (0, devkit_1.joinPathFragments)(options.e2eProjectRoot, 'src'),
58
+ targets: {},
59
+ implicitDependencies: [options.projectName],
60
+ tags: [],
61
+ });
62
+ }
49
63
  const e2eTask = await configurationGenerator(tree, {
50
64
  ...options,
51
65
  project: options.e2eProjectName,
@@ -90,13 +104,27 @@ async function addE2e(tree, options) {
90
104
  }
91
105
  case 'playwright': {
92
106
  const { configurationGenerator } = (0, devkit_1.ensurePackage)('@nx/playwright', versions_1.nxVersion);
93
- (0, devkit_1.addProjectConfiguration)(tree, options.e2eProjectName, {
94
- projectType: 'application',
95
- root: options.e2eProjectRoot,
96
- sourceRoot: (0, devkit_1.joinPathFragments)(options.e2eProjectRoot, 'src'),
97
- targets: {},
98
- implicitDependencies: [options.projectName],
99
- });
107
+ if (options.isUsingTsSolutionConfig) {
108
+ (0, devkit_1.writeJson)(tree, (0, devkit_1.joinPathFragments)(options.e2eProjectRoot, 'package.json'), {
109
+ name: options.e2eProjectName,
110
+ version: '0.0.1',
111
+ private: true,
112
+ nx: {
113
+ projectType: 'application',
114
+ sourceRoot: (0, devkit_1.joinPathFragments)(options.e2eProjectRoot, 'src'),
115
+ implicitDependencies: [options.projectName],
116
+ },
117
+ });
118
+ }
119
+ else {
120
+ (0, devkit_1.addProjectConfiguration)(tree, options.e2eProjectName, {
121
+ projectType: 'application',
122
+ root: options.e2eProjectRoot,
123
+ sourceRoot: (0, devkit_1.joinPathFragments)(options.e2eProjectRoot, 'src'),
124
+ targets: {},
125
+ implicitDependencies: [options.projectName],
126
+ });
127
+ }
100
128
  const e2eTask = await configurationGenerator(tree, {
101
129
  project: options.e2eProjectName,
102
130
  skipFormat: true,
@@ -16,5 +16,6 @@ async function addJest(host, options) {
16
16
  setupFile: 'none',
17
17
  compiler: options.compiler,
18
18
  skipFormat: true,
19
+ runtimeTsconfigFileName: 'tsconfig.app.json',
19
20
  });
20
21
  }
@@ -5,6 +5,7 @@ const devkit_1 = require("@nx/devkit");
5
5
  const has_webpack_plugin_1 = require("../../../utils/has-webpack-plugin");
6
6
  const maybe_js_1 = require("../../../utils/maybe-js");
7
7
  const has_rspack_plugin_1 = require("../../../utils/has-rspack-plugin");
8
+ const get_import_path_1 = require("@nx/js/src/utils/get-import-path");
8
9
  function addProject(host, options) {
9
10
  const project = {
10
11
  root: options.appProjectRoot,
@@ -28,9 +29,24 @@ function addProject(host, options) {
28
29
  serve: createRspackServeTarget(options),
29
30
  };
30
31
  }
31
- (0, devkit_1.addProjectConfiguration)(host, options.projectName, {
32
- ...project,
33
- });
32
+ if (options.isUsingTsSolutionConfig) {
33
+ (0, devkit_1.writeJson)(host, (0, devkit_1.joinPathFragments)(options.appProjectRoot, 'package.json'), {
34
+ name: (0, get_import_path_1.getImportPath)(host, options.name),
35
+ version: '0.0.1',
36
+ private: true,
37
+ nx: {
38
+ name: options.name,
39
+ projectType: 'application',
40
+ sourceRoot: `${options.appProjectRoot}/src`,
41
+ tags: options.parsedTags?.length ? options.parsedTags : undefined,
42
+ },
43
+ });
44
+ }
45
+ if (!options.isUsingTsSolutionConfig || options.alwaysGenerateProjectJson) {
46
+ (0, devkit_1.addProjectConfiguration)(host, options.projectName, {
47
+ ...project,
48
+ });
49
+ }
34
50
  }
35
51
  function createRspackBuildTarget(options) {
36
52
  return {
@@ -11,6 +11,7 @@ const has_webpack_plugin_1 = require("../../../utils/has-webpack-plugin");
11
11
  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
+ const ts_solution_setup_1 = require("@nx/js/src/utils/typescript/ts-solution-setup");
14
15
  async function createApplicationFiles(host, options) {
15
16
  let styleSolutionSpecificAppFiles;
16
17
  if (options.styledModule && options.style !== 'styled-jsx') {
@@ -47,6 +48,7 @@ async function createApplicationFiles(host, options) {
47
48
  inSourceVitestTests: (0, get_in_source_vitest_tests_template_1.getInSourceVitestTestsTemplate)(appTests),
48
49
  style: options.style === 'tailwind' ? 'css' : options.style,
49
50
  hasStyleFile,
51
+ isUsingTsSolutionSetup: (0, ts_solution_setup_1.isUsingTsSolutionSetup)(host),
50
52
  };
51
53
  if (options.bundler === 'vite') {
52
54
  (0, devkit_1.generateFiles)(host, (0, path_1.join)(__dirname, '../files/base-vite'), options.appProjectRoot, templateVariables);
@@ -7,6 +7,7 @@ const devkit_1 = require("@nx/devkit");
7
7
  const project_name_and_root_utils_1 = require("@nx/devkit/src/generators/project-name-and-root-utils");
8
8
  const assertion_1 = require("../../../utils/assertion");
9
9
  const find_free_port_1 = require("./find-free-port");
10
+ const ts_solution_setup_1 = require("@nx/js/src/utils/typescript/ts-solution-setup");
10
11
  function normalizeDirectory(options) {
11
12
  options.directory = options.directory?.replace(/\\{1,2}/g, '/');
12
13
  const { projectDirectory } = (0, devkit_1.extractLayoutDirectory)(options.directory);
@@ -51,6 +52,7 @@ async function normalizeOptions(host, options) {
51
52
  fileName,
52
53
  styledModule,
53
54
  hasStyles: options.style !== 'none',
55
+ isUsingTsSolutionConfig: (0, ts_solution_setup_1.isUsingTsSolutionSetup)(host),
54
56
  };
55
57
  normalized.routing = normalized.routing ?? false;
56
58
  normalized.strict = normalized.strict ?? true;
@@ -17,6 +17,11 @@ function updateSpecConfig(host, options) {
17
17
  types.push('@nx/react/typings/cssmodule.d.ts', '@nx/react/typings/image.d.ts');
18
18
  compilerOptions.types = types;
19
19
  json.compilerOptions = compilerOptions;
20
+ if (options.isUsingTsSolutionConfig) {
21
+ // add project reference to the runtime tsconfig.app.json file
22
+ json.references ??= [];
23
+ json.references.push({ path: './tsconfig.app.json' });
24
+ }
20
25
  return json;
21
26
  });
22
27
  if (options.unitTestRunner !== 'jest') {
@@ -25,8 +25,12 @@ export interface Schema {
25
25
  rootProject?: boolean;
26
26
  bundler?: 'webpack' | 'vite' | 'rspack';
27
27
  minimal?: boolean;
28
+ // Internal options
28
29
  addPlugin?: boolean;
29
30
  nxCloudToken?: string;
31
+ useTsSolution?: boolean;
32
+ formatter?: 'prettier' | 'none';
33
+ alwaysGenerateProjectJson?: boolean; // this is needed for MF currently
30
34
  }
31
35
 
32
36
  export interface NormalizedSchema<T extends Schema = Schema> extends T {
@@ -40,4 +44,5 @@ export interface NormalizedSchema<T extends Schema = Schema> extends T {
40
44
  hasStyles: boolean;
41
45
  unitTestRunner: 'jest' | 'vitest' | 'none';
42
46
  addPlugin?: boolean;
47
+ isUsingTsSolutionConfig?: boolean;
43
48
  }
@@ -80,12 +80,6 @@
80
80
  ]
81
81
  }
82
82
  },
83
- "linter": {
84
- "description": "The tool to use for running lint checks.",
85
- "type": "string",
86
- "enum": ["eslint", "none"],
87
- "default": "eslint"
88
- },
89
83
  "routing": {
90
84
  "type": "boolean",
91
85
  "description": "Generate application with routes.",
@@ -104,11 +98,29 @@
104
98
  "default": false,
105
99
  "x-priority": "internal"
106
100
  },
101
+ "bundler": {
102
+ "description": "The bundler to use.",
103
+ "type": "string",
104
+ "enum": ["vite", "webpack", "rspack"],
105
+ "x-prompt": "Which bundler do you want to use to build the application?",
106
+ "default": "vite",
107
+ "x-priority": "important"
108
+ },
109
+ "linter": {
110
+ "description": "The tool to use for running lint checks.",
111
+ "type": "string",
112
+ "enum": ["eslint", "none"],
113
+ "default": "none",
114
+ "x-prompt": "Which linter would you like to use?",
115
+ "x-priority": "important"
116
+ },
107
117
  "unitTestRunner": {
108
118
  "type": "string",
109
119
  "enum": ["vitest", "jest", "none"],
110
120
  "description": "Test runner to use for unit tests.",
111
- "default": "vitest"
121
+ "default": "none",
122
+ "x-prompt": "What unit test runner should be used?",
123
+ "x-priority": "important"
112
124
  },
113
125
  "inSourceTests": {
114
126
  "type": "boolean",
@@ -171,14 +183,6 @@
171
183
  "default": false,
172
184
  "hidden": true
173
185
  },
174
- "bundler": {
175
- "description": "The bundler to use.",
176
- "type": "string",
177
- "enum": ["vite", "webpack", "rspack"],
178
- "x-prompt": "Which bundler do you want to use to build the application?",
179
- "default": "vite",
180
- "x-priority": "important"
181
- },
182
186
  "minimal": {
183
187
  "description": "Generate a React app with a minimal setup, no separate test files.",
184
188
  "type": "boolean",
@@ -67,7 +67,9 @@ function addExportsToBarrel(host, options) {
67
67
  const workspace = (0, devkit_1.getProjects)(host);
68
68
  const isApp = workspace.get(options.projectName).projectType === 'application';
69
69
  if (options.export && !isApp) {
70
- const indexFilePath = (0, devkit_1.joinPathFragments)(options.projectSourceRoot, options.js ? 'index.js' : 'index.ts');
70
+ const indexFilePath = options.projectSourceRoot
71
+ ? (0, devkit_1.joinPathFragments)(options.projectSourceRoot, options.js ? 'index.js' : 'index.ts')
72
+ : (0, devkit_1.joinPathFragments)(options.projectRoot, 'src', options.js ? 'index.js' : 'index.ts');
71
73
  const indexSource = host.read(indexFilePath, 'utf-8');
72
74
  if (indexSource !== null) {
73
75
  const indexSourceFile = tsModule.createSourceFile(indexFilePath, indexSource, tsModule.ScriptTarget.Latest, true);
@@ -36,6 +36,7 @@ async function normalizeOptions(tree, options) {
36
36
  className,
37
37
  fileName,
38
38
  filePath,
39
- projectSourceRoot: projectSourceRoot ?? projectRoot,
39
+ projectRoot,
40
+ projectSourceRoot: projectSourceRoot,
40
41
  };
41
42
  }
@@ -1,4 +1,3 @@
1
- import type { NameAndDirectoryFormat } from '@nx/devkit/src/generators/artifact-name-and-directory-utils';
2
1
  import { SupportedStyles } from '../../../typings/style';
3
2
 
4
3
  export interface Schema {
@@ -20,6 +19,7 @@ export interface Schema {
20
19
 
21
20
  export interface NormalizedSchema extends Schema {
22
21
  directory: string;
22
+ projectRoot: string;
23
23
  projectSourceRoot: string;
24
24
  projectName: string;
25
25
  fileName: string;
@@ -8,19 +8,17 @@
8
8
  "properties": {
9
9
  "path": {
10
10
  "type": "string",
11
- "description": "Path where the component will be generated.",
11
+ "description": "The file path to the component without the file extension. Relative to the current working directory.",
12
12
  "$default": {
13
13
  "$source": "argv",
14
14
  "index": 0
15
15
  },
16
- "x-prompt": "Where should the component be generated?",
16
+ "x-prompt": "What is the component file path?",
17
17
  "x-priority": "important"
18
18
  },
19
19
  "name": {
20
20
  "type": "string",
21
- "description": "The name of the component.",
22
- "x-prompt": "What name would you like to use for the component?",
23
- "x-priority": "important"
21
+ "description": "The component symbol name. Defaults to the last segment of the file path."
24
22
  },
25
23
  "style": {
26
24
  "description": "The file extension to be used for style files.",
@@ -49,22 +49,20 @@ function addExportsToBarrel(host, options) {
49
49
  }
50
50
  }
51
51
  async function normalizeOptions(host, options) {
52
- assertValidOptions(options);
53
- const { directory, fileName: _fileName, project: projectName, } = await (0, artifact_name_and_directory_utils_1.determineArtifactNameAndDirectoryOptions)(host, {
52
+ const { artifactName, directory, fileName: hookFilename, project: projectName, } = await (0, artifact_name_and_directory_utils_1.determineArtifactNameAndDirectoryOptions)(host, {
54
53
  path: options.path,
55
54
  name: options.name,
56
55
  fileExtension: 'tsx',
57
56
  });
58
- const { className, fileName } = (0, devkit_1.names)(_fileName);
59
- // If using `as-provided` file and directory, then don't normalize.
60
- // Otherwise, support legacy behavior of prefixing filename with `use-`.
61
- const hookFilename = fileName;
62
- const hookName = className.toLocaleLowerCase().startsWith('use')
63
- ? className
64
- : 'use'.concat(className);
65
- const hookTypeName = className.toLocaleLowerCase().startsWith('use')
66
- ? className
67
- : 'Use'.concat(className);
57
+ const { className } = (0, devkit_1.names)(hookFilename);
58
+ // if name is provided, use it as is for the hook name, otherwise prepend
59
+ // `use` to the pascal-cased file name if it doesn't already start with `use`
60
+ const hookName = options.name
61
+ ? artifactName
62
+ : className.toLocaleLowerCase().startsWith('use')
63
+ ? className
64
+ : `use${className}`;
65
+ const hookTypeName = (0, devkit_1.names)(hookName).className;
68
66
  const project = (0, devkit_1.getProjects)(host).get(projectName);
69
67
  const { sourceRoot: projectSourceRoot, projectType } = project;
70
68
  if (options.export && projectType === 'application') {
@@ -80,17 +78,4 @@ async function normalizeOptions(host, options) {
80
78
  projectName,
81
79
  };
82
80
  }
83
- function assertValidOptions(options) {
84
- const slashes = ['/', '\\'];
85
- slashes.forEach((s) => {
86
- if (options.name.indexOf(s) !== -1) {
87
- const [name, ...rest] = options.name.split(s).reverse();
88
- let suggestion = rest.map((x) => x.toLowerCase()).join(s);
89
- if (options.directory) {
90
- suggestion = `${options.directory}${s}${suggestion}`;
91
- }
92
- throw new Error(`Found "${s}" in the hook name. Did you mean to use the --directory option (e.g. \`nx g c ${name} --directory ${suggestion}\`)?`);
93
- }
94
- });
95
- }
96
81
  exports.default = hookGenerator;
@@ -2,8 +2,6 @@ export interface Schema {
2
2
  path: string;
3
3
  name?: string;
4
4
  skipTests?: boolean;
5
- directory?: string;
6
5
  export?: boolean;
7
6
  js?: boolean;
8
- nameAndDirectoryFormat?: NameAndDirectoryFormat;
9
7
  }
@@ -7,26 +7,28 @@
7
7
  "type": "object",
8
8
  "examples": [
9
9
  {
10
- "command": "nx g hook mylib/my-hook",
11
- "description": "Generate a hook `my-hook` in the `mylib` library"
10
+ "description": "Generate a hook with the exported symbol matching the file name. It results in the hook `useFoo` at `mylib/src/lib/foo.ts`",
11
+ "command": "nx g @nx/react:hook mylib/src/lib/foo"
12
+ },
13
+ {
14
+ "description": "Generate a hook with the exported symbol different from the file name. It results in the hook `useCustom` at `mylib/src/lib/foo.ts`",
15
+ "command": "nx g @nx/react:hook mylib/src/lib/foo --name=useCustom"
12
16
  }
13
17
  ],
14
18
  "properties": {
15
19
  "path": {
16
20
  "type": "string",
17
- "description": "Path where the hook will be generated.",
21
+ "description": "The file path to the hook without the file extension. Relative to the current working directory.",
18
22
  "$default": {
19
23
  "$source": "argv",
20
24
  "index": 0
21
25
  },
22
- "x-prompt": "Where should the hook be generated?",
26
+ "x-prompt": "What is the hook file path?",
23
27
  "x-priority": "important"
24
28
  },
25
29
  "name": {
26
30
  "type": "string",
27
- "description": "The name of the hook.",
28
- "x-prompt": "What name would you like to use for the hook?",
29
- "x-priority": "important"
31
+ "description": "The hook symbol name. Defaults to the last segment of the file path."
30
32
  },
31
33
  "js": {
32
34
  "type": "boolean",
@@ -39,16 +41,6 @@
39
41
  "default": false,
40
42
  "x-priority": "internal"
41
43
  },
42
- "directory": {
43
- "type": "string",
44
- "description": "The directory at which to create the hook file. When `--nameAndDirectoryFormat=as-provided`, it will be relative to the current working directory. Otherwise, it will be relative to the project root.",
45
- "x-priority": "important"
46
- },
47
- "nameAndDirectoryFormat": {
48
- "description": "Whether to generate the component in the directory as provided, relative to the current working directory and ignoring the project (`as-provided`) or generate it using the project and directory relative to the workspace root (`derived`).",
49
- "type": "string",
50
- "enum": ["as-provided", "derived"]
51
- },
52
44
  "export": {
53
45
  "type": "boolean",
54
46
  "description": "When true, the hook is exported from the project `index.ts` (if it exists).",
@@ -57,5 +49,5 @@
57
49
  "x-prompt": "Should this hook be exported in the project?"
58
50
  }
59
51
  },
60
- "required": ["name"]
52
+ "required": ["path"]
61
53
  }
@@ -15,9 +15,8 @@ const add_mf_env_to_inputs_1 = require("../../utils/add-mf-env-to-inputs");
15
15
  const js_1 = require("@nx/js");
16
16
  const versions_1 = require("../../utils/versions");
17
17
  const project_name_and_root_utils_1 = require("@nx/devkit/src/generators/project-name-and-root-utils");
18
- const ts_solution_setup_1 = require("@nx/js/src/utils/typescript/ts-solution-setup");
18
+ const update_module_federation_tsconfig_1 = require("./lib/update-module-federation-tsconfig");
19
19
  async function hostGenerator(host, schema) {
20
- (0, ts_solution_setup_1.assertNotUsingTsSolutionSetup)(host, 'react', 'host');
21
20
  const tasks = [];
22
21
  const options = {
23
22
  ...(await (0, normalize_options_1.normalizeOptions)(host, schema)),
@@ -48,6 +47,7 @@ async function hostGenerator(host, schema) {
48
47
  // The target use-case is loading remotes as child routes, thus always enable routing.
49
48
  routing: true,
50
49
  skipFormat: true,
50
+ alwaysGenerateProjectJson: true,
51
51
  });
52
52
  tasks.push(initTask);
53
53
  const remotesWithPorts = [];
@@ -80,6 +80,7 @@ async function hostGenerator(host, schema) {
80
80
  (0, add_module_federation_files_1.addModuleFederationFiles)(host, options, remotesWithPorts);
81
81
  (0, update_module_federation_project_1.updateModuleFederationProject)(host, options);
82
82
  (0, update_module_federation_e2e_project_1.updateModuleFederationE2eProject)(host, options);
83
+ (0, update_module_federation_tsconfig_1.updateModuleFederationTsconfig)(host, options);
83
84
  if (options.ssr) {
84
85
  const setupSsrTask = await (0, setup_ssr_1.default)(host, {
85
86
  project: options.projectName,
@@ -0,0 +1,3 @@
1
+ import { type Tree } from '@nx/devkit';
2
+ import { NormalizedSchema } from '../schema';
3
+ export declare function updateModuleFederationTsconfig(host: Tree, options: NormalizedSchema): void;
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.updateModuleFederationTsconfig = updateModuleFederationTsconfig;
4
+ const devkit_1 = require("@nx/devkit");
5
+ const ts_solution_setup_1 = require("@nx/js/src/utils/typescript/ts-solution-setup");
6
+ function updateModuleFederationTsconfig(host, options) {
7
+ const tsconfigPath = (0, devkit_1.joinPathFragments)(options.appProjectRoot, 'tsconfig.json');
8
+ const tsconfigRuntimePath = (0, devkit_1.joinPathFragments)(options.appProjectRoot, 'tsconfig.app.json');
9
+ if (!host.exists(tsconfigPath) || !host.exists(tsconfigRuntimePath))
10
+ return;
11
+ // Not setting `baseUrl` does not work with MF.
12
+ if ((0, ts_solution_setup_1.isUsingTsSolutionSetup)(host)) {
13
+ (0, devkit_1.updateJson)(host, 'tsconfig.base.json', (json) => {
14
+ json.compilerOptions.baseUrl = '.';
15
+ return json;
16
+ });
17
+ // Update references to match what `nx sync` does.
18
+ if (options.remotes?.length) {
19
+ (0, devkit_1.updateJson)(host, tsconfigPath, (json) => {
20
+ json.references ??= [];
21
+ for (const remote of options.remotes) {
22
+ const remotePath = `../${remote}`;
23
+ if (!json.references.some((ref) => ref.path === remotePath))
24
+ json.references.push({ path: remotePath });
25
+ }
26
+ return json;
27
+ });
28
+ (0, devkit_1.updateJson)(host, tsconfigRuntimePath, (json) => {
29
+ json.references ??= [];
30
+ for (const remote of options.remotes) {
31
+ const remotePath = `../${remote}/tsconfig.app.json`;
32
+ if (!json.references.some((ref) => ref.path === remotePath))
33
+ json.references.push({ path: remotePath });
34
+ }
35
+ return json;
36
+ });
37
+ }
38
+ }
39
+ }
@@ -2,10 +2,8 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.reactInitGenerator = reactInitGenerator;
4
4
  const devkit_1 = require("@nx/devkit");
5
- const ts_solution_setup_1 = require("@nx/js/src/utils/typescript/ts-solution-setup");
6
5
  const versions_1 = require("../../utils/versions");
7
6
  async function reactInitGenerator(host, schema) {
8
- (0, ts_solution_setup_1.assertNotUsingTsSolutionSetup)(host, 'react', 'init');
9
7
  const tasks = [];
10
8
  if (!schema.skipPackageJson) {
11
9
  tasks.push((0, devkit_1.removeDependenciesFromPackageJson)(host, ['@nx/react'], []));
@@ -1,3 +1,3 @@
1
- import type { Tree } from '@nx/devkit';
1
+ import { Tree } from '@nx/devkit';
2
2
  import { NormalizedSchema } from '../schema';
3
3
  export declare function createFiles(host: Tree, options: NormalizedSchema): void;
@@ -42,8 +42,28 @@ function createFiles(host, options) {
42
42
  ].filter(Boolean),
43
43
  });
44
44
  }
45
- if (!options.publishable && !options.buildable) {
46
- host.delete(`${options.projectRoot}/package.json`);
45
+ if ((options.publishable || options.buildable) &&
46
+ !options.isUsingTsSolutionConfig) {
47
+ if (options.bundler === 'vite') {
48
+ (0, devkit_1.writeJson)(host, `${options.projectRoot}/package.json`, {
49
+ name: options.importPath,
50
+ version: '0.0.1',
51
+ main: './index.js',
52
+ types: './index.d.ts',
53
+ exports: {
54
+ '.': {
55
+ import: './index.mjs',
56
+ require: './index.js',
57
+ },
58
+ },
59
+ });
60
+ }
61
+ else {
62
+ (0, devkit_1.writeJson)(host, `${options.projectRoot}/package.json`, {
63
+ name: options.importPath,
64
+ version: '0.0.1',
65
+ });
66
+ }
47
67
  }
48
68
  if (options.js) {
49
69
  (0, devkit_1.toJS)(host);
@@ -4,7 +4,9 @@ exports.normalizeOptions = normalizeOptions;
4
4
  const devkit_1 = require("@nx/devkit");
5
5
  const project_name_and_root_utils_1 = require("@nx/devkit/src/generators/project-name-and-root-utils");
6
6
  const assertion_1 = require("../../../utils/assertion");
7
+ const ts_solution_setup_1 = require("@nx/js/src/utils/typescript/ts-solution-setup");
7
8
  async function normalizeOptions(host, options) {
9
+ const isUsingTsSolutionConfig = (0, ts_solution_setup_1.isUsingTsSolutionSetup)(host);
8
10
  await (0, project_name_and_root_utils_1.ensureProjectName)(host, options, 'library');
9
11
  const { projectName, names: projectNames, projectRoot, importPath, } = await (0, project_name_and_root_utils_1.determineProjectNameAndRootOptions)(host, {
10
12
  name: options.name,
@@ -62,6 +64,7 @@ async function normalizeOptions(host, options) {
62
64
  }
63
65
  }
64
66
  (0, assertion_1.assertValidStyle)(normalized.style);
67
+ normalized.isUsingTsSolutionConfig = isUsingTsSolutionConfig;
65
68
  return normalized;
66
69
  }
67
70
  function findMainEntry(tree, projectRoot) {
@@ -7,7 +7,6 @@ const devkit_1 = require("@nx/devkit");
7
7
  const artifact_name_and_directory_utils_1 = require("@nx/devkit/src/generators/artifact-name-and-directory-utils");
8
8
  const log_show_project_command_1 = require("@nx/devkit/src/utils/log-show-project-command");
9
9
  const js_1 = require("@nx/js");
10
- const ts_solution_setup_1 = require("@nx/js/src/utils/typescript/ts-solution-setup");
11
10
  const versions_1 = require("../../utils/versions");
12
11
  const maybe_js_1 = require("../../utils/maybe-js");
13
12
  const component_1 = require("../component/component");
@@ -21,6 +20,7 @@ const create_files_1 = require("./lib/create-files");
21
20
  const create_ts_config_1 = require("../../utils/create-ts-config");
22
21
  const install_common_dependencies_1 = require("./lib/install-common-dependencies");
23
22
  const set_defaults_1 = require("./lib/set-defaults");
23
+ const ts_solution_setup_1 = require("@nx/js/src/utils/typescript/ts-solution-setup");
24
24
  async function libraryGenerator(host, schema) {
25
25
  return await libraryGeneratorInternal(host, {
26
26
  addPlugin: false,
@@ -28,8 +28,12 @@ async function libraryGenerator(host, schema) {
28
28
  });
29
29
  }
30
30
  async function libraryGeneratorInternal(host, schema) {
31
- (0, ts_solution_setup_1.assertNotUsingTsSolutionSetup)(host, 'react', 'library');
32
31
  const tasks = [];
32
+ const jsInitTask = await (0, js_1.initGenerator)(host, {
33
+ ...schema,
34
+ skipFormat: true,
35
+ });
36
+ tasks.push(jsInitTask);
33
37
  const options = await (0, normalize_options_1.normalizeOptions)(host, schema);
34
38
  if (options.publishable === true && !schema.importPath) {
35
39
  throw new Error(`For publishable libs you have to provide a proper "--importPath" which needs to be a valid npm package name (e.g. my-awesome-lib or @myorg/my-lib)`);
@@ -37,26 +41,41 @@ async function libraryGeneratorInternal(host, schema) {
37
41
  if (!options.component) {
38
42
  options.style = 'none';
39
43
  }
40
- const jsInitTask = await (0, js_1.initGenerator)(host, {
41
- ...schema,
42
- skipFormat: true,
43
- });
44
- tasks.push(jsInitTask);
45
44
  const initTask = await (0, init_1.default)(host, {
46
45
  ...options,
47
46
  skipFormat: true,
48
47
  });
49
48
  tasks.push(initTask);
50
- (0, devkit_1.addProjectConfiguration)(host, options.name, {
51
- root: options.projectRoot,
52
- sourceRoot: (0, devkit_1.joinPathFragments)(options.projectRoot, 'src'),
53
- projectType: 'library',
54
- tags: options.parsedTags,
55
- targets: {},
56
- });
49
+ if (options.isUsingTsSolutionConfig) {
50
+ const sourceEntry = options.bundler === 'none'
51
+ ? options.js
52
+ ? './src/index.js'
53
+ : './src/index.ts'
54
+ : undefined;
55
+ (0, devkit_1.writeJson)(host, `${options.projectRoot}/package.json`, {
56
+ name: options.importPath,
57
+ main: sourceEntry,
58
+ types: sourceEntry,
59
+ nx: {
60
+ name: options.importPath === options.name ? undefined : options.name,
61
+ projectType: 'library',
62
+ sourceRoot: `${options.projectRoot}/src`,
63
+ tags: options.parsedTags?.length ? options.parsedTags : undefined,
64
+ },
65
+ });
66
+ }
67
+ else {
68
+ (0, devkit_1.addProjectConfiguration)(host, options.name, {
69
+ root: options.projectRoot,
70
+ sourceRoot: (0, devkit_1.joinPathFragments)(options.projectRoot, 'src'),
71
+ projectType: 'library',
72
+ tags: options.parsedTags,
73
+ targets: {},
74
+ });
75
+ }
76
+ (0, create_files_1.createFiles)(host, options);
57
77
  const lintTask = await (0, add_linting_1.addLinting)(host, options);
58
78
  tasks.push(lintTask);
59
- (0, create_files_1.createFiles)(host, options);
60
79
  // Set up build target
61
80
  if (options.buildable && options.bundler === 'vite') {
62
81
  const { viteConfigurationGenerator, createOrEditViteConfig } = (0, devkit_1.ensurePackage)('@nx/vite', versions_1.nxVersion);
@@ -178,14 +197,25 @@ async function libraryGeneratorInternal(host, schema) {
178
197
  tasks.push(routeTask);
179
198
  (0, set_defaults_1.setDefaults)(host, options);
180
199
  (0, create_ts_config_1.extractTsConfigBase)(host);
181
- if (!options.skipTsConfig) {
200
+ if (!options.skipTsConfig && !options.isUsingTsSolutionConfig) {
182
201
  (0, js_1.addTsConfigPath)(host, options.importPath, [
183
202
  (0, maybe_js_1.maybeJs)(options, (0, devkit_1.joinPathFragments)(options.projectRoot, './src/index.ts')),
184
203
  ]);
185
204
  }
205
+ (0, ts_solution_setup_1.updateTsconfigFiles)(host, options.projectRoot, 'tsconfig.lib.json', {
206
+ jsx: 'react-jsx',
207
+ module: 'esnext',
208
+ moduleResolution: 'bundler',
209
+ }, options.linter === 'eslint'
210
+ ? ['eslint.config.js', 'eslint.config.cjs', 'eslint.config.mjs']
211
+ : undefined);
186
212
  if (!options.skipFormat) {
187
213
  await (0, devkit_1.formatFiles)(host);
188
214
  }
215
+ // Always run install to link packages.
216
+ if (options.isUsingTsSolutionConfig) {
217
+ tasks.push(() => (0, devkit_1.installPackagesTask)(host));
218
+ }
189
219
  tasks.push(() => {
190
220
  (0, log_show_project_command_1.logShowProjectCommand)(options.name);
191
221
  });
@@ -39,4 +39,5 @@ export interface NormalizedSchema extends Schema {
39
39
  appMain?: string;
40
40
  appSourceRoot?: string;
41
41
  unitTestRunner: 'jest' | 'vitest' | 'none';
42
+ isUsingTsSolutionConfig?: boolean;
42
43
  }
@@ -71,18 +71,29 @@
71
71
  ]
72
72
  }
73
73
  },
74
+ "bundler": {
75
+ "type": "string",
76
+ "description": "The bundler to use. Choosing 'none' means this library is not buildable.",
77
+ "enum": ["none", "vite", "rollup"],
78
+ "default": "none",
79
+ "x-prompt": "Which bundler would you like to use to build the library? Choose 'none' to skip build setup.",
80
+ "x-priority": "important"
81
+ },
74
82
  "linter": {
75
83
  "description": "The tool to use for running lint checks.",
76
84
  "type": "string",
77
85
  "enum": ["eslint", "none"],
78
- "default": "eslint"
86
+ "default": "none",
87
+ "x-prompt": "Which linter would you like to use?",
88
+ "x-priority": "important"
79
89
  },
80
90
  "unitTestRunner": {
81
91
  "type": "string",
82
92
  "enum": ["vitest", "jest", "none"],
83
- "default": "vitest",
93
+ "default": "none",
84
94
  "description": "Test runner to use for unit tests.",
85
- "x-prompt": "What unit test runner should be used?"
95
+ "x-prompt": "What unit test runner should be used?",
96
+ "x-priority": "important"
86
97
  },
87
98
  "inSourceTests": {
88
99
  "type": "boolean",
@@ -154,14 +165,6 @@
154
165
  "description": "Whether or not to configure the ESLint `parserOptions.project` option. We do not do this by default for lint performance reasons.",
155
166
  "default": false
156
167
  },
157
- "bundler": {
158
- "type": "string",
159
- "description": "The bundler to use. Choosing 'none' means this library is not buildable.",
160
- "enum": ["none", "vite", "rollup"],
161
- "default": "none",
162
- "x-prompt": "Which bundler would you like to use to build the library? Choose 'none' to skip build setup.",
163
- "x-priority": "important"
164
- },
165
168
  "compiler": {
166
169
  "type": "string",
167
170
  "enum": ["babel", "swc"],
@@ -5,21 +5,30 @@
5
5
  "title": "Create Redux state",
6
6
  "description": "Create a Redux state slice for a React project.",
7
7
  "type": "object",
8
+ "examples": [
9
+ {
10
+ "description": "Generate a Redux state slice with the exported symbol matching the file name. It results in the slice `fooSlice` at `mylib/src/lib/foo.slice.ts`",
11
+ "command": "nx g @nx/react:redux mylib/src/lib/foo"
12
+ },
13
+ {
14
+ "description": "Generate a Redux state slice with the exported symbol different from the file name. It results in the slice `customSlice` at `mylib/src/lib/foo.slice.ts`",
15
+ "command": "nx g @nx/react:redux mylib/src/lib/foo --name=custom"
16
+ }
17
+ ],
8
18
  "properties": {
9
19
  "path": {
10
20
  "type": "string",
11
- "description": "Path where the Redux slice will be generated.",
21
+ "description": "The file path to the Redux state slice without the file extension. Relative to the current working directory.",
12
22
  "$default": {
13
23
  "$source": "argv",
14
24
  "index": 0
15
25
  },
16
- "x-prompt": "Where should the Redux slice be generated?",
26
+ "x-prompt": "What is the Redux stateslice file path?",
17
27
  "x-priority": "important"
18
28
  },
19
29
  "name": {
20
30
  "type": "string",
21
- "description": "Redux slice name.",
22
- "x-priority": "important"
31
+ "description": "The Redux state slice symbol name. Defaults to the last segment of the file path."
23
32
  },
24
33
  "appProject": {
25
34
  "type": "string",
@@ -17,7 +17,6 @@ const maybe_js_1 = require("../../utils/maybe-js");
17
17
  const js_1 = require("@nx/js");
18
18
  const versions_1 = require("../../utils/versions");
19
19
  const project_name_and_root_utils_1 = require("@nx/devkit/src/generators/project-name-and-root-utils");
20
- const ts_solution_setup_1 = require("@nx/js/src/utils/typescript/ts-solution-setup");
21
20
  function addModuleFederationFiles(host, options) {
22
21
  const templateVariables = {
23
22
  ...(0, devkit_1.names)(options.projectName),
@@ -47,7 +46,6 @@ function addModuleFederationFiles(host, options) {
47
46
  }
48
47
  }
49
48
  async function remoteGenerator(host, schema) {
50
- (0, ts_solution_setup_1.assertNotUsingTsSolutionSetup)(host, 'react', 'remote');
51
49
  const tasks = [];
52
50
  const options = {
53
51
  ...(await (0, normalize_options_1.normalizeOptions)(host, schema)),
@@ -82,6 +80,7 @@ async function remoteGenerator(host, schema) {
82
80
  ...options,
83
81
  name: options.projectName,
84
82
  skipFormat: true,
83
+ alwaysGenerateProjectJson: true,
85
84
  });
86
85
  tasks.push(initAppTask);
87
86
  if (schema.host) {
@@ -14,6 +14,9 @@ async function migrateMfImportsToNewPackage(tree) {
14
14
  const rootsToCheck = new Set();
15
15
  const graph = await (0, devkit_1.createProjectGraphAsync)();
16
16
  for (const [project, dependencies] of Object.entries(graph.dependencies)) {
17
+ if (!graph.nodes[project]) {
18
+ continue;
19
+ }
17
20
  const usesNxWebpackOrRspack = dependencies.some((dep) => dep.target === 'npm:@nx/webpack' || dep.target === 'npm:@nx/rspack');
18
21
  if (usesNxWebpackOrRspack) {
19
22
  const root = graph.nodes[project].data.root;
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.updateModuleFederationProject = updateModuleFederationProject;
4
4
  const devkit_1 = require("@nx/devkit");
5
5
  const maybe_js_1 = require("../utils/maybe-js");
6
+ const ts_solution_setup_1 = require("@nx/js/src/utils/typescript/ts-solution-setup");
6
7
  function updateModuleFederationProject(host, options) {
7
8
  const projectConfig = (0, devkit_1.readProjectConfiguration)(host, options.projectName);
8
9
  if (options.bundler === 'rspack') {
@@ -78,5 +79,10 @@ function updateModuleFederationProject(host, options) {
78
79
  },
79
80
  },
80
81
  };
82
+ // Typechecks must be performed first before build and serve to generate remote d.ts files.
83
+ if ((0, ts_solution_setup_1.isUsingTsSolutionSetup)(host)) {
84
+ projectConfig.targets.build.dependsOn = ['^build', 'typecheck'];
85
+ projectConfig.targets.serve.dependsOn = ['typecheck'];
86
+ }
81
87
  (0, devkit_1.updateProjectConfiguration)(host, options.projectName, projectConfig);
82
88
  }
@@ -1,4 +1,4 @@
1
- import type { StaticRemotesConfig } from '@nx/webpack/src/utils/module-federation/parse-static-remotes-config';
1
+ import { StaticRemotesConfig } from '@nx/module-federation/src/utils';
2
2
  import { ExecutorContext } from '@nx/devkit';
3
3
  import { ModuleFederationDevServerOptions } from '../executors/module-federation-dev-server/schema';
4
4
  export declare function buildStaticRemotes(staticRemotesConfig: StaticRemotesConfig, nxBin: any, context: ExecutorContext, options: ModuleFederationDevServerOptions): Promise<Record<string, string>>;
@@ -4,7 +4,64 @@ exports.createTsConfig = createTsConfig;
4
4
  exports.extractTsConfigBase = extractTsConfigBase;
5
5
  const shared = require("@nx/js/src/utils/typescript/create-ts-config");
6
6
  const json_1 = require("nx/src/generators/utils/json");
7
+ const ts_solution_setup_1 = require("@nx/js/src/utils/typescript/ts-solution-setup");
7
8
  function createTsConfig(host, projectRoot, type, options, relativePathToRootTsConfig) {
9
+ if ((0, ts_solution_setup_1.isUsingTsSolutionSetup)(host)) {
10
+ createTsConfigForTsSolution(host, projectRoot, type, options, relativePathToRootTsConfig);
11
+ }
12
+ else {
13
+ createTsConfigForNonTsSolution(host, projectRoot, type, options, relativePathToRootTsConfig);
14
+ }
15
+ }
16
+ function extractTsConfigBase(host) {
17
+ shared.extractTsConfigBase(host);
18
+ if (host.exists('vite.config.ts')) {
19
+ const vite = host.read('vite.config.ts').toString();
20
+ host.write('vite.config.ts', vite.replace(`projects: []`, `projects: ['tsconfig.base.json']`));
21
+ }
22
+ }
23
+ function createTsConfigForTsSolution(host, projectRoot, type, options, relativePathToRootTsConfig) {
24
+ const json = {
25
+ files: [],
26
+ include: [],
27
+ references: [
28
+ {
29
+ path: type === 'app' ? './tsconfig.app.json' : './tsconfig.lib.json',
30
+ },
31
+ ],
32
+ };
33
+ // inline tsconfig.base.json into the project
34
+ if (options.rootProject) {
35
+ json.compileOnSave = false;
36
+ json.compilerOptions = {
37
+ ...shared.tsConfigBaseOptions,
38
+ ...json.compilerOptions,
39
+ };
40
+ json.exclude = ['node_modules', 'tmp'];
41
+ }
42
+ else {
43
+ json.extends = relativePathToRootTsConfig;
44
+ }
45
+ (0, json_1.writeJson)(host, `${projectRoot}/tsconfig.json`, json);
46
+ const tsconfigProjectPath = `${projectRoot}/tsconfig.${type}.json`;
47
+ if (host.exists(tsconfigProjectPath)) {
48
+ (0, json_1.updateJson)(host, tsconfigProjectPath, (json) => {
49
+ if (options.bundler === 'vite') {
50
+ json.compilerOptions ??= {};
51
+ const types = new Set(json.compilerOptions.types ?? []);
52
+ types.add('node');
53
+ types.add('vite/client');
54
+ json.compilerOptions.types = Array.from(types);
55
+ }
56
+ if (options.style === '@emotion/styled') {
57
+ json.compilerOptions ??= {};
58
+ json.compilerOptions.jsxImportSource = '@emotion/react';
59
+ }
60
+ return json;
61
+ });
62
+ }
63
+ }
64
+ function createTsConfigForNonTsSolution(host, projectRoot, type, options, relativePathToRootTsConfig) {
8
65
  const json = {
9
66
  compilerOptions: {
10
67
  jsx: 'react-jsx',
@@ -55,10 +112,3 @@ function createTsConfig(host, projectRoot, type, options, relativePathToRootTsCo
55
112
  });
56
113
  }
57
114
  }
58
- function extractTsConfigBase(host) {
59
- shared.extractTsConfigBase(host);
60
- if (host.exists('vite.config.ts')) {
61
- const vite = host.read('vite.config.ts').toString();
62
- host.write('vite.config.ts', vite.replace(`projects: []`, `projects: ['tsconfig.base.json']`));
63
- }
64
- }
@@ -1,5 +1,4 @@
1
1
  export declare const nxVersion: any;
2
- export declare const nxRspackVersion = "*";
3
2
  export declare const reactVersion = "18.3.1";
4
3
  export declare const reactDomVersion = "18.3.1";
5
4
  export declare const reactIsVersion = "18.3.1";
@@ -1,9 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.swcPluginStyledComponentsVersion = exports.swcPluginEmotionVersion = exports.swcPluginStyledJsxVersion = exports.svgrRollupVersion = exports.rollupPluginUrlVersion = exports.sassVersion = exports.lessVersion = exports.moduleFederationEnhancedVersion = exports.moduleFederationNodeVersion = exports.typesCorsVersion = exports.corsVersion = exports.isbotVersion = exports.typesExpressVersion = exports.expressVersion = exports.autoprefixerVersion = exports.tailwindcssVersion = exports.postcssVersion = exports.tsLibVersion = exports.babelPluginStyledComponentsVersion = exports.eslintPluginReactHooksVersion = exports.eslintPluginReactVersion = exports.eslintPluginJsxA11yVersion = exports.eslintPluginImportVersion = exports.reactReduxVersion = exports.reduxjsToolkitVersion = exports.testingLibraryReactVersion = exports.reactRouterDomVersion = exports.styledJsxVersion = exports.emotionBabelPlugin = exports.emotionReactVersion = exports.emotionStyledVersion = exports.typesStyledComponentsVersion = exports.styledComponentsVersion = exports.babelCoreVersion = exports.babelPresetReactVersion = exports.typesNodeVersion = exports.reactViteVersion = exports.typesReactIsVersion = exports.typesReactDomVersion = exports.typesReactVersion = exports.babelLoaderVersion = exports.swcLoaderVersion = exports.reactIsVersion = exports.reactDomVersion = exports.reactVersion = exports.nxRspackVersion = exports.nxVersion = void 0;
3
+ exports.swcPluginStyledComponentsVersion = exports.swcPluginEmotionVersion = exports.swcPluginStyledJsxVersion = exports.svgrRollupVersion = exports.rollupPluginUrlVersion = exports.sassVersion = exports.lessVersion = exports.moduleFederationEnhancedVersion = exports.moduleFederationNodeVersion = exports.typesCorsVersion = exports.corsVersion = exports.isbotVersion = exports.typesExpressVersion = exports.expressVersion = exports.autoprefixerVersion = exports.tailwindcssVersion = exports.postcssVersion = exports.tsLibVersion = exports.babelPluginStyledComponentsVersion = exports.eslintPluginReactHooksVersion = exports.eslintPluginReactVersion = exports.eslintPluginJsxA11yVersion = exports.eslintPluginImportVersion = exports.reactReduxVersion = exports.reduxjsToolkitVersion = exports.testingLibraryReactVersion = exports.reactRouterDomVersion = exports.styledJsxVersion = exports.emotionBabelPlugin = exports.emotionReactVersion = exports.emotionStyledVersion = exports.typesStyledComponentsVersion = exports.styledComponentsVersion = exports.babelCoreVersion = exports.babelPresetReactVersion = exports.typesNodeVersion = exports.reactViteVersion = exports.typesReactIsVersion = exports.typesReactDomVersion = exports.typesReactVersion = exports.babelLoaderVersion = exports.swcLoaderVersion = exports.reactIsVersion = exports.reactDomVersion = exports.reactVersion = exports.nxVersion = void 0;
4
4
  exports.nxVersion = require('../../package.json').version;
5
- // Always pull the latest version until we merge rspack plugin into the repo.
6
- exports.nxRspackVersion = '*';
7
5
  exports.reactVersion = '18.3.1';
8
6
  exports.reactDomVersion = '18.3.1';
9
7
  exports.reactIsVersion = '18.3.1';
@@ -1,4 +0,0 @@
1
- {
2
- "name": "<%= name %>",
3
- "version": "0.0.1"
4
- }
@@ -1,12 +0,0 @@
1
- {
2
- "name": "<%= name %>",
3
- "version": "0.0.1",
4
- "main": "./index.js",
5
- "types": "./index.d.ts",
6
- "exports": {
7
- ".": {
8
- "import": "./index.mjs",
9
- "require": "./index.js"
10
- }
11
- }
12
- }