@nx/react 20.2.0-beta.2 → 20.2.0-beta.4

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 (99) hide show
  1. package/migrations.json +33 -0
  2. package/module-federation.d.ts +6 -4
  3. package/module-federation.js +16 -7
  4. package/package.json +6 -6
  5. package/src/executors/module-federation-dev-server/module-federation-dev-server.impl.js +5 -7
  6. package/src/executors/module-federation-ssr-dev-server/module-federation-ssr-dev-server.impl.js +5 -7
  7. package/src/executors/module-federation-static-server/module-federation-static-server.impl.d.ts +1 -1
  8. package/src/executors/module-federation-static-server/module-federation-static-server.impl.js +4 -5
  9. package/src/generators/application/application.js +20 -6
  10. package/src/generators/application/files/base-rspack/rspack.config.js__tmpl__ +53 -0
  11. package/src/generators/application/files/base-rspack/tsconfig.app.json__tmpl__ +21 -4
  12. package/src/generators/application/files/base-vite/tsconfig.app.json__tmpl__ +19 -2
  13. package/src/generators/application/files/base-webpack/tsconfig.app.json__tmpl__ +20 -3
  14. package/src/generators/application/files/style-css-module/src/app/__fileName__.tsx__tmpl__ +2 -2
  15. package/src/generators/application/lib/add-e2e.d.ts +1 -1
  16. package/src/generators/application/lib/add-e2e.js +45 -15
  17. package/src/generators/application/lib/add-jest.js +1 -0
  18. package/src/generators/application/lib/add-project.js +85 -3
  19. package/src/generators/application/lib/create-application-files.js +30 -1
  20. package/src/generators/application/lib/normalize-options.js +2 -0
  21. package/src/generators/application/lib/update-jest-config.js +5 -0
  22. package/src/generators/application/schema.d.ts +5 -0
  23. package/src/generators/application/schema.json +19 -15
  24. package/src/generators/component/component.js +3 -1
  25. package/src/generators/component/lib/normalize-options.js +2 -1
  26. package/src/generators/component/schema.d.ts +1 -1
  27. package/src/generators/component/schema.json +3 -5
  28. package/src/generators/hook/hook.js +10 -25
  29. package/src/generators/hook/schema.d.ts +0 -2
  30. package/src/generators/hook/schema.json +10 -18
  31. package/src/generators/host/files/rspack-module-federation/rspack.config.js__tmpl__ +1 -1
  32. package/src/generators/host/files/rspack-module-federation/rspack.config.prod.js__tmpl__ +1 -1
  33. package/src/generators/host/files/rspack-module-federation-ssr/module-federation.server.config.js__tmpl__ +1 -1
  34. package/src/generators/host/files/rspack-module-federation-ssr/rspack.server.config.js__tmpl__ +1 -1
  35. package/src/generators/host/files/rspack-module-federation-ssr-ts/module-federation.server.config.ts__tmpl__ +1 -1
  36. package/src/generators/host/files/rspack-module-federation-ssr-ts/rspack.server.config.ts__tmpl__ +1 -1
  37. package/src/generators/host/files/rspack-module-federation-ts/module-federation.config.ts__tmpl__ +1 -1
  38. package/src/generators/host/files/rspack-module-federation-ts/rspack.config.prod.ts__tmpl__ +2 -1
  39. package/src/generators/host/files/rspack-module-federation-ts/rspack.config.ts__tmpl__ +2 -1
  40. package/src/generators/host/files/webpack-module-federation/webpack.config.js__tmpl__ +1 -1
  41. package/src/generators/host/files/webpack-module-federation/webpack.config.prod.js__tmpl__ +1 -1
  42. package/src/generators/host/files/webpack-module-federation-ssr/module-federation.server.config.js__tmpl__ +1 -1
  43. package/src/generators/host/files/webpack-module-federation-ssr/webpack.server.config.js__tmpl__ +1 -1
  44. package/src/generators/host/files/webpack-module-federation-ssr-ts/module-federation.server.config.ts__tmpl__ +1 -1
  45. package/src/generators/host/files/webpack-module-federation-ssr-ts/webpack.server.config.ts__tmpl__ +1 -1
  46. package/src/generators/host/files/webpack-module-federation-ts/module-federation.config.ts__tmpl__ +1 -1
  47. package/src/generators/host/files/webpack-module-federation-ts/webpack.config.prod.ts__tmpl__ +2 -2
  48. package/src/generators/host/files/webpack-module-federation-ts/webpack.config.ts__tmpl__ +3 -2
  49. package/src/generators/host/host.js +3 -2
  50. package/src/generators/host/lib/update-module-federation-tsconfig.d.ts +3 -0
  51. package/src/generators/host/lib/update-module-federation-tsconfig.js +39 -0
  52. package/src/generators/init/init.js +0 -2
  53. package/src/generators/library/lib/create-files.d.ts +1 -1
  54. package/src/generators/library/lib/create-files.js +22 -2
  55. package/src/generators/library/lib/normalize-options.js +3 -0
  56. package/src/generators/library/library.js +46 -16
  57. package/src/generators/library/schema.d.ts +1 -0
  58. package/src/generators/library/schema.json +14 -11
  59. package/src/generators/redux/schema.json +13 -4
  60. package/src/generators/remote/files/rspack-module-federation/rspack.config.js__tmpl__ +1 -1
  61. package/src/generators/remote/files/rspack-module-federation-ssr/rspack.server.config.js__tmpl__ +1 -1
  62. package/src/generators/remote/files/rspack-module-federation-ssr-ts/module-federation.server.config.ts__tmpl__ +1 -1
  63. package/src/generators/remote/files/rspack-module-federation-ssr-ts/rspack.server.config.ts__tmpl__ +1 -1
  64. package/src/generators/remote/files/rspack-module-federation-ts/module-federation.config.ts__tmpl__ +1 -1
  65. package/src/generators/remote/files/rspack-module-federation-ts/rspack.config.ts__tmpl__ +1 -1
  66. package/src/generators/remote/files/webpack-module-federation/webpack.config.js__tmpl__ +1 -1
  67. package/src/generators/remote/files/webpack-module-federation-ssr/webpack.server.config.js__tmpl__ +1 -1
  68. package/src/generators/remote/files/webpack-module-federation-ssr-ts/module-federation.server.config.ts__tmpl__ +1 -1
  69. package/src/generators/remote/files/webpack-module-federation-ssr-ts/webpack.server.config.ts__tmpl__ +1 -1
  70. package/src/generators/remote/files/webpack-module-federation-ts/module-federation.config.ts__tmpl__ +1 -1
  71. package/src/generators/remote/files/webpack-module-federation-ts/webpack.config.ts__tmpl__ +1 -1
  72. package/src/generators/remote/remote.js +1 -2
  73. package/src/migrations/update-20-2-0/migrate-mf-imports-to-new-package.d.ts +2 -0
  74. package/src/migrations/update-20-2-0/migrate-mf-imports-to-new-package.js +66 -0
  75. package/src/migrations/update-20-2-0/migrate-with-mf-import-to-new-package.d.ts +2 -0
  76. package/src/migrations/update-20-2-0/migrate-with-mf-import-to-new-package.js +35 -0
  77. package/src/rules/update-module-federation-project.js +12 -4
  78. package/src/utils/build-static.remotes.d.ts +1 -1
  79. package/src/utils/create-ts-config.js +57 -7
  80. package/src/utils/has-rspack-plugin.d.ts +2 -0
  81. package/src/utils/has-rspack-plugin.js +10 -0
  82. package/src/utils/versions.d.ts +2 -3
  83. package/src/utils/versions.js +3 -5
  84. package/src/generators/application/lib/add-project-root-to-rspack-plugin-excludes.d.ts +0 -2
  85. package/src/generators/application/lib/add-project-root-to-rspack-plugin-excludes.js +0 -31
  86. package/src/generators/library/files/common/package.json__tmpl__ +0 -4
  87. package/src/generators/library/files/vite/package.json__tmpl__ +0 -12
  88. package/src/module-federation/load-config.d.ts +0 -3
  89. package/src/module-federation/load-config.js +0 -15
  90. package/src/module-federation/models.d.ts +0 -24
  91. package/src/module-federation/models.js +0 -2
  92. package/src/module-federation/package-json.d.ts +0 -8
  93. package/src/module-federation/package-json.js +0 -12
  94. package/src/module-federation/utils.d.ts +0 -12
  95. package/src/module-federation/utils.js +0 -75
  96. package/src/module-federation/with-module-federation-ssr.d.ts +0 -2
  97. package/src/module-federation/with-module-federation-ssr.js +0 -50
  98. package/src/module-federation/with-module-federation.d.ts +0 -7
  99. package/src/module-federation/with-module-federation.js +0 -63
@@ -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",
@@ -1,5 +1,5 @@
1
1
  const { composePlugins, withNx, withReact } = require('@nx/rspack');
2
- const { withModuleFederation } = require('@nx/rspack/module-federation');
2
+ const { withModuleFederation } = require('@nx/module-federation/rspack');
3
3
 
4
4
  const baseConfig = require('./module-federation.config');
5
5
 
@@ -1,5 +1,5 @@
1
1
  const {composePlugins, withNx, withReact} = require('@nx/rspack');
2
- const {withModuleFederationForSSR} = require('@nx/rspack/module-federation');
2
+ const {withModuleFederationForSSR} = require('@nx/module-federation/rspack');
3
3
 
4
4
  const baseConfig = require("./module-federation.server.config");
5
5
 
@@ -1,4 +1,4 @@
1
- import {ModuleFederationConfig} from '@nx/rspack/module-federation';
1
+ import {ModuleFederationConfig} from '@nx/module-federation';
2
2
 
3
3
  const config: ModuleFederationConfig = {
4
4
  name: '<%= projectName %>',
@@ -1,5 +1,5 @@
1
1
  import {composePlugins, withNx, withReact} from '@nx/rspack';
2
- import {withModuleFederationForSSR} from '@nx/rspack/module-federation';
2
+ import {withModuleFederationForSSR} from '@nx/module-federation/rspack';
3
3
 
4
4
  import baseConfig from "./module-federation.server.config";
5
5
 
@@ -1,4 +1,4 @@
1
- import {ModuleFederationConfig} from '@nx/rspack/module-federation';
1
+ import {ModuleFederationConfig} from '@nx/module-federation';
2
2
 
3
3
  const config: ModuleFederationConfig = {
4
4
  name: '<%= projectName %>',
@@ -1,5 +1,5 @@
1
1
  import {composePlugins, withNx, withReact} from '@nx/rspack';
2
- import {withModuleFederation} from '@nx/rspack/module-federation';
2
+ import {withModuleFederation} from '@nx/module-federation/rspack';
3
3
 
4
4
  import baseConfig from './module-federation.config';
5
5
 
@@ -1,6 +1,6 @@
1
1
  const { composePlugins, withNx } = require('@nx/webpack');
2
2
  const { withReact } = require('@nx/react');
3
- const { withModuleFederation } = require('@nx/react/module-federation');
3
+ const { withModuleFederation } = require('@nx/module-federation/webpack');
4
4
 
5
5
  const baseConfig = require('./module-federation.config');
6
6
 
@@ -1,6 +1,6 @@
1
1
  const {composePlugins, withNx} = require('@nx/webpack');
2
2
  const {withReact} = require('@nx/react');
3
- const {withModuleFederationForSSR} = require('@nx/react/module-federation');
3
+ const {withModuleFederationForSSR} = require('@nx/module-federation/webpack');
4
4
 
5
5
  const baseConfig = require("./module-federation.server.config");
6
6
 
@@ -1,4 +1,4 @@
1
- import {ModuleFederationConfig} from '@nx/webpack';
1
+ import {ModuleFederationConfig} from '@nx/module-federation';
2
2
 
3
3
  const config: ModuleFederationConfig = {
4
4
  name: '<%= projectName %>',
@@ -1,6 +1,6 @@
1
1
  import {composePlugins, withNx} from '@nx/webpack';
2
2
  import {withReact} from '@nx/react';
3
- import {withModuleFederationForSSR} from '@nx/react/module-federation';
3
+ import {withModuleFederationForSSR} from '@nx/module-federation/webpack';
4
4
 
5
5
  import baseConfig from "./module-federation.server.config";
6
6
 
@@ -1,4 +1,4 @@
1
- import {ModuleFederationConfig} from '@nx/webpack';
1
+ import {ModuleFederationConfig} from '@nx/module-federation';
2
2
 
3
3
  const config: ModuleFederationConfig = {
4
4
  name: '<%= projectName %>',
@@ -1,6 +1,6 @@
1
1
  import {composePlugins, withNx} from '@nx/webpack';
2
2
  import {withReact} from '@nx/react';
3
- import {withModuleFederation} from '@nx/react/module-federation';
3
+ import {withModuleFederation} from '@nx/module-federation/webpack';
4
4
 
5
5
  import baseConfig from './module-federation.config';
6
6
 
@@ -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) {
@@ -0,0 +1,2 @@
1
+ import { Tree } from '@nx/devkit';
2
+ export default function migrateMfImportsToNewPackage(tree: Tree): Promise<void>;
@@ -0,0 +1,66 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = migrateMfImportsToNewPackage;
4
+ const devkit_1 = require("@nx/devkit");
5
+ const devkit_2 = require("@nx/devkit");
6
+ const tsquery_1 = require("@phenomnomnominal/tsquery");
7
+ const MF_IMPORT_TO_UPDATE = 'ModuleFederationConfig';
8
+ const MF_CONFIG_IMPORT_SELECTOR = `ImportDeclaration:has(StringLiteral[value=@nx/webpack]):has(Identifier[name=ModuleFederationConfig]),ImportDeclaration:has(StringLiteral[value=@nx/rspack/module-federation]):has(Identifier[name=ModuleFederationConfig])`;
9
+ const IMPORT_TOKENS_SELECTOR = `ImportClause ImportSpecifier`;
10
+ const MF_CONFIG_IMPORT_SPECIFIER_SELECTOR = `ImportClause ImportSpecifier > Identifier[name=ModuleFederationConfig]`;
11
+ const WEBPACK_IMPORT_SELECTOR = `ImportDeclaration > StringLiteral[value=@nx/webpack]`;
12
+ const RSPACK_IMPORT_SELECTOR = `ImportDeclaration > StringLiteral[value=@nx/rspack/module-federation]`;
13
+ async function migrateMfImportsToNewPackage(tree) {
14
+ const rootsToCheck = new Set();
15
+ const graph = await (0, devkit_1.createProjectGraphAsync)();
16
+ for (const [project, dependencies] of Object.entries(graph.dependencies)) {
17
+ if (!graph.nodes[project]) {
18
+ continue;
19
+ }
20
+ const usesNxWebpackOrRspack = dependencies.some((dep) => dep.target === 'npm:@nx/webpack' || dep.target === 'npm:@nx/rspack');
21
+ if (usesNxWebpackOrRspack) {
22
+ const root = graph.nodes[project].data.root;
23
+ rootsToCheck.add(root);
24
+ }
25
+ }
26
+ for (const root of rootsToCheck) {
27
+ (0, devkit_2.visitNotIgnoredFiles)(tree, root, (filePath) => {
28
+ if (!filePath.endsWith('.ts') && !filePath.endsWith('.js')) {
29
+ return;
30
+ }
31
+ let contents = tree.read(filePath, 'utf-8');
32
+ if (!contents.includes(MF_IMPORT_TO_UPDATE)) {
33
+ return;
34
+ }
35
+ const ast = tsquery_1.tsquery.ast(contents);
36
+ const importNodes = (0, tsquery_1.tsquery)(ast, MF_CONFIG_IMPORT_SELECTOR);
37
+ if (importNodes.length === 0) {
38
+ return;
39
+ }
40
+ const importNode = importNodes[0];
41
+ const importSpecifiers = (0, tsquery_1.tsquery)(importNode, IMPORT_TOKENS_SELECTOR);
42
+ if (importSpecifiers.length > 1) {
43
+ const mfConfigImportSpecifierNode = (0, tsquery_1.tsquery)(importNode, MF_CONFIG_IMPORT_SPECIFIER_SELECTOR)[0];
44
+ const end = contents.charAt(mfConfigImportSpecifierNode.getEnd()) === ','
45
+ ? mfConfigImportSpecifierNode.getEnd() + 1
46
+ : mfConfigImportSpecifierNode.getEnd();
47
+ contents = `import { ${MF_IMPORT_TO_UPDATE} } from '@nx/module-federation';
48
+ ${contents.slice(0, mfConfigImportSpecifierNode.getStart())}${contents.slice(end)}`;
49
+ }
50
+ else {
51
+ const nxWebpackImportStringNodes = (0, tsquery_1.tsquery)(importNode, WEBPACK_IMPORT_SELECTOR);
52
+ const nxRspackImportStringNodes = (0, tsquery_1.tsquery)(importNode, RSPACK_IMPORT_SELECTOR);
53
+ if (nxWebpackImportStringNodes.length === 0 &&
54
+ nxRspackImportStringNodes.length === 0) {
55
+ return;
56
+ }
57
+ const bundlerImportStringNode = nxWebpackImportStringNodes.length
58
+ ? nxWebpackImportStringNodes[0]
59
+ : nxRspackImportStringNodes[0];
60
+ contents = `${contents.slice(0, bundlerImportStringNode.getStart())}'@nx/module-federation'${contents.slice(bundlerImportStringNode.getEnd())}`;
61
+ }
62
+ tree.write(filePath, contents);
63
+ });
64
+ }
65
+ await (0, devkit_2.formatFiles)(tree);
66
+ }
@@ -0,0 +1,2 @@
1
+ import { type Tree } from '@nx/devkit';
2
+ export default function migrateWithMfImport(tree: Tree): Promise<void>;
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = migrateWithMfImport;
4
+ const devkit_1 = require("@nx/devkit");
5
+ const executor_options_utils_1 = require("@nx/devkit/src/generators/executor-options-utils");
6
+ const tsquery_1 = require("@phenomnomnominal/tsquery");
7
+ const NX_RSPACK_MODULE_FEDERATION_IMPORT_SELECTOR = 'ImportDeclaration > StringLiteral[value=@nx/react/module-federation], VariableStatement CallExpression:has(Identifier[name=require]) > StringLiteral[value=@nx/react/module-federation]';
8
+ const NEW_IMPORT_PATH = `'@nx/module-federation/webpack'`;
9
+ async function migrateWithMfImport(tree) {
10
+ const projects = new Set();
11
+ (0, executor_options_utils_1.forEachExecutorOptions)(tree, '@nx/react:module-federation-dev-server', (options, project, target) => {
12
+ const projectConfig = (0, devkit_1.readProjectConfiguration)(tree, project);
13
+ projects.add(projectConfig.root);
14
+ });
15
+ for (const projectRoot of projects) {
16
+ (0, devkit_1.visitNotIgnoredFiles)(tree, projectRoot, (filePath) => {
17
+ if (!filePath.endsWith('.ts') && !filePath.endsWith('.js')) {
18
+ return;
19
+ }
20
+ let contents = tree.read(filePath, 'utf-8');
21
+ if (!contents.includes('@nx/react/module-federation')) {
22
+ return;
23
+ }
24
+ const ast = tsquery_1.tsquery.ast(contents);
25
+ const importNodes = (0, tsquery_1.tsquery)(ast, NX_RSPACK_MODULE_FEDERATION_IMPORT_SELECTOR);
26
+ if (importNodes.length === 0) {
27
+ return;
28
+ }
29
+ const importPathNode = importNodes[0];
30
+ contents = `${contents.slice(0, importPathNode.getStart())}${NEW_IMPORT_PATH}${contents.slice(importPathNode.getEnd())}`;
31
+ tree.write(filePath, contents);
32
+ });
33
+ }
34
+ await (0, devkit_1.formatFiles)(tree);
35
+ }
@@ -3,29 +3,32 @@ 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') {
9
10
  projectConfig.targets.build.executor = '@nx/rspack:rspack';
10
11
  projectConfig.targets.build.options = {
11
- ...projectConfig.targets.build.options,
12
+ ...(projectConfig.targets.build.options ?? {}),
12
13
  main: (0, maybe_js_1.maybeJs)({ js: options.js, useJsx: true }, `${options.appProjectRoot}/src/main.ts`),
13
14
  rspackConfig: `${options.appProjectRoot}/rspack.config.${options.typescriptConfiguration && !options.js ? 'ts' : 'js'}`,
14
15
  target: 'web',
15
16
  };
17
+ projectConfig.targets.build.configurations ??= {};
16
18
  projectConfig.targets.build.configurations.production = {
17
- ...projectConfig.targets.build.configurations.production,
19
+ ...(projectConfig.targets.build.configurations?.production ?? {}),
18
20
  rspackConfig: `${options.appProjectRoot}/rspack.config.prod.${options.typescriptConfiguration && !options.js ? 'ts' : 'js'}`,
19
21
  };
20
22
  }
21
23
  else {
22
24
  projectConfig.targets.build.options = {
23
- ...projectConfig.targets.build.options,
25
+ ...(projectConfig.targets.build.options ?? {}),
24
26
  main: (0, maybe_js_1.maybeJs)(options, `${options.appProjectRoot}/src/main.ts`),
25
27
  webpackConfig: `${options.appProjectRoot}/webpack.config.${options.typescriptConfiguration && !options.js ? 'ts' : 'js'}`,
26
28
  };
29
+ projectConfig.targets.build.configurations ??= {};
27
30
  projectConfig.targets.build.configurations.production = {
28
- ...projectConfig.targets.build.configurations.production,
31
+ ...(projectConfig.targets.build.configurations?.production ?? {}),
29
32
  webpackConfig: `${options.appProjectRoot}/webpack.config.prod.${options.typescriptConfiguration && !options.js ? 'ts' : 'js'}`,
30
33
  };
31
34
  }
@@ -76,5 +79,10 @@ function updateModuleFederationProject(host, options) {
76
79
  },
77
80
  },
78
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
+ }
79
87
  (0, devkit_1.updateProjectConfiguration)(host, options.projectName, projectConfig);
80
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>>;