@nx/react 19.7.0-canary.20240816-ce2dff3 → 19.7.0-canary.20240820-0853690

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.
package/README.md CHANGED
@@ -22,7 +22,7 @@
22
22
 
23
23
  # Nx: Smart Monorepos · Fast CI
24
24
 
25
- Nx is a build system with built-in tooling and advanced CI capabilities. It helps you maintain and scale monorepos, both locally and on CI.
25
+ Nx is a build system, optimized for monorepos, with plugins for popular frameworks and tools and advanced CI capabilities including caching and distribution.
26
26
 
27
27
  This package is a [React plugin for Nx](https://nx.dev/nx-api/react).
28
28
 
package/migrations.json CHANGED
@@ -53,6 +53,12 @@
53
53
  "version": "19.6.0-beta.4",
54
54
  "description": "Update the server file for Module Federation SSR port value to be the same as the 'serve' target port value.",
55
55
  "factory": "./src/migrations/update-19-6-0/update-ssr-server-port"
56
+ },
57
+ "update-19-6-1-ensure-module-federation-target-defaults": {
58
+ "cli": "nx",
59
+ "version": "19.6.1-beta.0",
60
+ "description": "Ensure Target Defaults are set correctly for Module Federation.",
61
+ "factory": "./src/migrations/update-19-6-1/ensure-depends-on-for-mf"
56
62
  }
57
63
  },
58
64
  "packageJsonUpdates": {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nx/react",
3
- "version": "19.7.0-canary.20240816-ce2dff3",
3
+ "version": "19.7.0-canary.20240820-0853690",
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": {
@@ -39,11 +39,11 @@
39
39
  "minimatch": "9.0.3",
40
40
  "tslib": "^2.3.0",
41
41
  "@module-federation/enhanced": "~0.2.3",
42
- "@nx/devkit": "19.7.0-canary.20240816-ce2dff3",
43
- "@nx/js": "19.7.0-canary.20240816-ce2dff3",
44
- "@nx/eslint": "19.7.0-canary.20240816-ce2dff3",
45
- "@nx/web": "19.7.0-canary.20240816-ce2dff3",
46
- "@nrwl/react": "19.7.0-canary.20240816-ce2dff3"
42
+ "@nx/devkit": "19.7.0-canary.20240820-0853690",
43
+ "@nx/js": "19.7.0-canary.20240820-0853690",
44
+ "@nx/eslint": "19.7.0-canary.20240820-0853690",
45
+ "@nx/web": "19.7.0-canary.20240820-0853690",
46
+ "@nrwl/react": "19.7.0-canary.20240820-0853690"
47
47
  },
48
48
  "publishConfig": {
49
49
  "access": "public"
@@ -187,7 +187,10 @@ async function* moduleFederationDevServer(options, context) {
187
187
  }, pathToManifestFile);
188
188
  options.staticRemotesPort ??= remotes.staticRemotePort;
189
189
  // Set NX_MF_DEV_REMOTES for the Nx Runtime Library Control Plugin
190
- process.env.NX_MF_DEV_REMOTES = JSON.stringify(remotes.devRemotes.map((r) => (typeof r === 'string' ? r : r.remoteName)));
190
+ process.env.NX_MF_DEV_REMOTES = JSON.stringify([
191
+ ...(remotes.devRemotes.map((r) => typeof r === 'string' ? r : r.remoteName) ?? []),
192
+ p.name,
193
+ ]);
191
194
  const staticRemotesConfig = (0, parse_static_remotes_config_1.parseStaticRemotesConfig)([...remotes.staticRemotes, ...remotes.dynamicRemotes], context);
192
195
  const mappedLocationsOfStaticRemotes = await buildStaticRemotes(staticRemotesConfig, nxBin, context, options);
193
196
  const devRemoteIters = await startRemotes(remotes.devRemotes, context, options, 'serve');
@@ -162,7 +162,10 @@ async function* moduleFederationSsrDevServer(ssrDevServerOptions, context) {
162
162
  root: context.root,
163
163
  }, pathToManifestFile);
164
164
  options.staticRemotesPort ??= remotes.staticRemotePort;
165
- process.env.NX_MF_DEV_REMOTES = JSON.stringify(remotes.devRemotes.map((r) => (typeof r === 'string' ? r : r.remoteName)));
165
+ process.env.NX_MF_DEV_REMOTES = JSON.stringify([
166
+ ...(remotes.devRemotes.map((r) => typeof r === 'string' ? r : r.remoteName) ?? []),
167
+ projectConfig.name,
168
+ ]);
166
169
  const staticRemotesConfig = (0, parse_static_remotes_config_1.parseStaticSsrRemotesConfig)([...remotes.staticRemotes, ...remotes.dynamicRemotes], context);
167
170
  const mappedLocationsOfStaticRemotes = await buildSsrStaticRemotes(staticRemotesConfig, nxBin, context, options);
168
171
  const devRemoteIters = await startRemotes(remotes.devRemotes, context, options);
@@ -1,5 +1,5 @@
1
1
  import type { ProjectNameAndRootFormat } from '@nx/devkit/src/generators/project-name-and-root-utils';
2
- import type { Linter } from '@nx/eslint';
2
+ import type { Linter, LinterType } from '@nx/eslint';
3
3
  import type { SupportedStyles } from '../../../typings/style';
4
4
 
5
5
  export interface Schema {
@@ -12,7 +12,7 @@ export interface Schema {
12
12
  unitTestRunner?: 'jest' | 'vitest' | 'none';
13
13
  inSourceTests?: boolean;
14
14
  e2eTestRunner: 'cypress' | 'playwright' | 'none';
15
- linter: Linter;
15
+ linter: Linter | LinterType;
16
16
  pascalCaseFiles?: boolean;
17
17
  classComponent?: boolean;
18
18
  routing?: boolean;
@@ -1,3 +1,5 @@
1
+ import { Linter, LinterType } from '@nx/eslint';
2
+
1
3
  export interface Schema {
2
4
  name: string;
3
5
  path: string;
@@ -6,7 +8,7 @@ export interface Schema {
6
8
  projectNameAndRootFormat?: ProjectNameAndRootFormat;
7
9
  e2eTestRunner?: 'cypress' | 'playwright' | 'none';
8
10
  host?: string;
9
- linter?: Linter;
11
+ linter?: Linter | LinterType;
10
12
  skipFormat?: boolean;
11
13
  style?: SupportedStyles;
12
14
  unitTestRunner?: 'jest' | 'vitest' | 'none';
@@ -1,5 +1,5 @@
1
1
  import type { ProjectNameAndRootFormat } from '@nx/devkit/src/generators/project-name-and-root-utils';
2
- import type { Linter } from '@nx/eslint';
2
+ import type { Linter, LinterType } from '@nx/eslint';
3
3
  import type { SupportedStyles } from '../../../typings/style';
4
4
 
5
5
  export interface Schema {
@@ -11,7 +11,7 @@ export interface Schema {
11
11
  e2eTestRunner: 'cypress' | 'playwright' | 'none';
12
12
  globalCss?: boolean;
13
13
  js?: boolean;
14
- linter: Linter;
14
+ linter: Linter | LinterType;
15
15
  name: string;
16
16
  pascalCaseFiles?: boolean;
17
17
  remotes?: string[];
@@ -137,7 +137,11 @@ async function libraryGeneratorInternal(host, schema) {
137
137
  "'react-dom'",
138
138
  "'react/jsx-runtime'",
139
139
  ],
140
- imports: [`import react from '@vitejs/plugin-react'`],
140
+ imports: [
141
+ options.compiler === 'swc'
142
+ ? `import react from '@vitejs/plugin-react-swc'`
143
+ : `import react from '@vitejs/plugin-react'`,
144
+ ],
141
145
  plugins: ['react()'],
142
146
  }, true);
143
147
  }
@@ -1,5 +1,5 @@
1
1
  import type { ProjectNameAndRootFormat } from '@nx/devkit/src/generators/project-name-and-root-utils';
2
- import type { Linter } from '@nx/eslint';
2
+ import type { Linter, LinterType } from '@nx/eslint';
3
3
  import type { SupportedStyles } from '../../../typings/style';
4
4
 
5
5
  export interface Schema {
@@ -14,7 +14,7 @@ export interface Schema {
14
14
  importPath?: string;
15
15
  inSourceTests?: boolean;
16
16
  js?: boolean;
17
- linter: Linter;
17
+ linter: Linter | LinterType;
18
18
  name: string;
19
19
  pascalCaseFiles?: boolean;
20
20
  publishable?: boolean;
@@ -1,5 +1,5 @@
1
1
  import type { ProjectNameAndRootFormat } from '@nx/devkit/src/generators/project-name-and-root-utils';
2
- import type { Linter } from '@nx/eslint';
2
+ import type { Linter, LinterType } from '@nx/eslint';
3
3
  import type { SupportedStyles } from '../../../typings/style';
4
4
  import type { NormalizedSchema as ApplicationNormalizedSchema } from '../application/schema';
5
5
 
@@ -13,7 +13,7 @@ export interface Schema {
13
13
  globalCss?: boolean;
14
14
  host?: string;
15
15
  js?: boolean;
16
- linter: Linter;
16
+ linter: Linter | LinterType;
17
17
  name: string;
18
18
  pascalCaseFiles?: boolean;
19
19
  routing?: boolean;
@@ -1,4 +1,4 @@
1
- import { Linter } from '@nx/eslint';
1
+ import { Linter, LinterType } from '@nx/eslint';
2
2
 
3
3
  export interface StorybookConfigureSchema {
4
4
  project: string;
@@ -6,7 +6,7 @@ export interface StorybookConfigureSchema {
6
6
  generateStories?: boolean;
7
7
  js?: boolean;
8
8
  tsConfiguration?: boolean;
9
- linter?: Linter;
9
+ linter?: Linter | LinterType;
10
10
  ignorePaths?: string[];
11
11
  configureStaticServe?: boolean;
12
12
  configureCypress?: boolean;
@@ -0,0 +1,2 @@
1
+ import { type Tree } from '@nx/devkit';
2
+ export default function (tree: Tree): Promise<void>;
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = default_1;
4
+ const devkit_1 = require("@nx/devkit");
5
+ const executor_options_utils_1 = require("@nx/devkit/src/generators/executor-options-utils");
6
+ async function default_1(tree) {
7
+ let usesModuleFederation = false;
8
+ (0, executor_options_utils_1.forEachExecutorOptions)(tree, '@nx/webpack:webpack', (options, projectName, targetName) => {
9
+ const webpackConfig = options.webpackConfig;
10
+ if (!webpackConfig) {
11
+ return;
12
+ }
13
+ const webpackContents = tree.read(webpackConfig, 'utf-8');
14
+ if (['withModuleFederation', 'withModuleFederationForSSR'].some((p) => webpackContents.includes(p))) {
15
+ usesModuleFederation = true;
16
+ }
17
+ });
18
+ if (!usesModuleFederation) {
19
+ return;
20
+ }
21
+ const nxJson = (0, devkit_1.readNxJson)(tree);
22
+ const nxMFDevRemotesEnvVar = 'NX_MF_DEV_REMOTES';
23
+ if (!nxJson.targetDefaults ||
24
+ !nxJson.targetDefaults?.['@nx/webpack:webpack']) {
25
+ nxJson.targetDefaults ??= {};
26
+ nxJson.targetDefaults['@nx/webpack:webpack'] = {
27
+ cache: true,
28
+ inputs: ['production', '^production', { env: nxMFDevRemotesEnvVar }],
29
+ dependsOn: ['^build'],
30
+ };
31
+ }
32
+ else {
33
+ nxJson.targetDefaults['@nx/webpack:webpack'].dependsOn ??= [];
34
+ if (!nxJson.targetDefaults['@nx/webpack:webpack'].dependsOn.includes('^build')) {
35
+ nxJson.targetDefaults['@nx/webpack:webpack'].dependsOn.push('^build');
36
+ }
37
+ nxJson.targetDefaults['@nx/webpack:webpack'].inputs ??= [];
38
+ if (!nxJson.targetDefaults['@nx/webpack:webpack'].inputs.find((i) => typeof i === 'string' ? false : i['env'] === nxMFDevRemotesEnvVar)) {
39
+ nxJson.targetDefaults['@nx/webpack:webpack'].inputs.push({
40
+ env: nxMFDevRemotesEnvVar,
41
+ });
42
+ }
43
+ }
44
+ (0, devkit_1.updateNxJson)(tree, nxJson);
45
+ await (0, devkit_1.formatFiles)(tree);
46
+ }
@@ -12,6 +12,7 @@ function addMfEnvToTargetDefaultInputs(tree) {
12
12
  'production',
13
13
  '^production',
14
14
  ];
15
+ nxJson.targetDefaults[webpackExecutor].dependsOn ??= ['^build'];
15
16
  let mfEnvVarExists = false;
16
17
  for (const input of nxJson.targetDefaults[webpackExecutor].inputs) {
17
18
  if (typeof input === 'object' && input['env'] === mfEnvVar) {