@nx/react 23.1.0 → 23.1.2
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/dist/internal.d.ts +1 -0
- package/dist/internal.js +3 -1
- package/dist/module-federation.d.ts +1 -2
- package/dist/module-federation.js +2 -3
- package/dist/plugins/component-testing/webpack-fallback.js +5 -0
- package/dist/src/executors/module-federation-dev-server/module-federation-dev-server.impl.js +11 -7
- package/dist/src/executors/module-federation-ssr-dev-server/module-federation-ssr-dev-server.impl.js +10 -6
- package/dist/src/executors/module-federation-static-server/module-federation-static-server.impl.d.ts +2 -2
- package/dist/src/executors/module-federation-static-server/module-federation-static-server.impl.js +14 -9
- package/dist/src/generators/application/application.js +7 -8
- package/dist/src/generators/application/files/react-router-ssr/common/app/entry.server.tsx__tmpl__ +1 -1
- package/dist/src/generators/application/files/react-router-ssr/common/tests/routes/_index.spec.tsx__tmpl__ +2 -2
- package/dist/src/generators/application/lib/add-e2e.js +3 -1
- package/dist/src/generators/application/lib/add-linting.js +3 -3
- package/dist/src/generators/application/lib/create-application-files.d.ts +1 -0
- package/dist/src/generators/application/lib/create-application-files.js +3 -3
- package/dist/src/generators/application/lib/find-free-port.d.ts +1 -1
- package/dist/src/generators/application/schema.d.ts +4 -0
- package/dist/src/generators/application/schema.json +8 -2
- package/dist/src/generators/cypress-component-configuration/lib/add-files.js +3 -3
- package/dist/src/generators/host/host.js +13 -4
- package/dist/src/generators/host/lib/setup-ssr-for-host.js +7 -8
- package/dist/src/generators/host/schema.d.ts +4 -0
- package/dist/src/generators/host/schema.json +8 -2
- package/dist/src/generators/library/lib/add-linting.d.ts +1 -2
- package/dist/src/generators/library/lib/add-linting.js +2 -3
- package/dist/src/generators/library/lib/add-rollup-build-target.d.ts +1 -2
- package/dist/src/generators/library/lib/determine-entry-fields.d.ts +1 -1
- package/dist/src/generators/library/lib/update-app-routes.js +1 -2
- package/dist/src/generators/library/schema.d.ts +4 -0
- package/dist/src/generators/library/schema.json +8 -2
- package/dist/src/generators/remote/lib/setup-ssr-for-remote.js +8 -9
- package/dist/src/generators/remote/lib/setup-tspath-for-remote.js +3 -2
- package/dist/src/generators/remote/remote.js +15 -6
- package/dist/src/generators/remote/schema.d.ts +4 -0
- package/dist/src/generators/remote/schema.json +8 -2
- package/dist/src/migrations/update-23-2-0/add-optional-module-federation-packages.d.ts +2 -0
- package/dist/src/migrations/update-23-2-0/add-optional-module-federation-packages.js +61 -0
- package/dist/src/migrations/update-23-2-0/add-optional-module-federation-packages.md +37 -0
- package/dist/src/migrations/update-23-2-0/add-svgr-webpack-if-used.d.ts +2 -0
- package/dist/src/migrations/update-23-2-0/add-svgr-webpack-if-used.js +55 -0
- package/dist/src/migrations/update-23-2-0/add-svgr-webpack-if-used.md +28 -0
- package/dist/src/plugins/router-plugin.js +2 -4
- package/dist/src/utils/assert-package.d.ts +1 -0
- package/dist/src/utils/assert-package.js +17 -0
- package/dist/src/utils/create-ts-config.d.ts +1 -1
- package/dist/src/utils/create-ts-config.js +5 -5
- package/dist/src/utils/versions.d.ts +2 -0
- package/dist/src/utils/versions.js +3 -1
- package/migrations.json +12 -0
- package/package.json +32 -20
|
@@ -109,11 +109,17 @@
|
|
|
109
109
|
"description": "Creates an application with strict mode and strict type checking",
|
|
110
110
|
"default": true
|
|
111
111
|
},
|
|
112
|
-
"
|
|
112
|
+
"enableTypedLinting": {
|
|
113
113
|
"type": "boolean",
|
|
114
|
-
"description": "Whether
|
|
114
|
+
"description": "Whether to enable typed linting. For flat configs, this configures the recommended `parserOptions.projectService` and `tsconfigRootDir`. For legacy `.eslintrc` configs, this configures `parserOptions.project`. We do not enable this by default for lint performance reasons.",
|
|
115
115
|
"default": false
|
|
116
116
|
},
|
|
117
|
+
"setParserOptionsProject": {
|
|
118
|
+
"type": "boolean",
|
|
119
|
+
"description": "Deprecated alias for `enableTypedLinting`.",
|
|
120
|
+
"default": false,
|
|
121
|
+
"x-deprecated": "Use `enableTypedLinting` instead. This option will be removed in Nx v24."
|
|
122
|
+
},
|
|
117
123
|
"compiler": {
|
|
118
124
|
"type": "string",
|
|
119
125
|
"description": "The compiler to use",
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { Tree } from 'nx/
|
|
2
|
-
import { GeneratorCallback } from '@nx/devkit';
|
|
1
|
+
import { GeneratorCallback, Tree } from '@nx/devkit';
|
|
3
2
|
import { NormalizedSchema } from '../schema';
|
|
4
3
|
export declare function addLinting(host: Tree, options: NormalizedSchema): Promise<GeneratorCallback>;
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.addLinting = addLinting;
|
|
4
4
|
const eslint_1 = require("@nx/eslint");
|
|
5
|
-
const path_1 = require("nx/src/utils/path");
|
|
6
5
|
const devkit_1 = require("@nx/devkit");
|
|
7
6
|
const lint_1 = require("../../../utils/lint");
|
|
8
7
|
const internal_1 = require("@nx/eslint/internal");
|
|
@@ -13,12 +12,12 @@ async function addLinting(host, options) {
|
|
|
13
12
|
linter: options.linter,
|
|
14
13
|
project: options.name,
|
|
15
14
|
tsConfigPaths: [
|
|
16
|
-
(0,
|
|
15
|
+
(0, devkit_1.joinPathFragments)(options.projectRoot, 'tsconfig.lib.json'),
|
|
17
16
|
],
|
|
18
17
|
unitTestRunner: options.unitTestRunner,
|
|
19
18
|
skipFormat: true,
|
|
20
19
|
skipPackageJson: options.skipPackageJson,
|
|
21
|
-
|
|
20
|
+
enableTypedLinting: (0, internal_1.isTypedLintingEnabled)(options),
|
|
22
21
|
addPlugin: options.addPlugin,
|
|
23
22
|
});
|
|
24
23
|
tasks.push(lintTask);
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { Tree } from 'nx/
|
|
2
|
-
import { GeneratorCallback } from '@nx/devkit';
|
|
1
|
+
import { GeneratorCallback, Tree } from '@nx/devkit';
|
|
3
2
|
import { NormalizedSchema } from '../schema';
|
|
4
3
|
export declare function addRollupBuildTarget(host: Tree, options: NormalizedSchema & {
|
|
5
4
|
format?: Array<'esm' | 'cjs'>;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type { PackageJson } from 'nx/src/utils/package-json';
|
|
2
1
|
import type { NormalizedSchema } from '../schema';
|
|
2
|
+
import { type PackageJson } from '@nx/devkit/internal';
|
|
3
3
|
export declare function determineEntryFields(options: NormalizedSchema): Pick<PackageJson, 'main' | 'types' | 'exports'>;
|
|
@@ -3,7 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.updateAppRoutes = updateAppRoutes;
|
|
4
4
|
const devkit_1 = require("@nx/devkit");
|
|
5
5
|
const ast_utils_1 = require("../../../utils/ast-utils");
|
|
6
|
-
const ast_utils_2 = require("../../../utils/ast-utils");
|
|
7
6
|
const maybe_js_1 = require("../../../utils/maybe-js");
|
|
8
7
|
const versions_1 = require("../../../utils/versions");
|
|
9
8
|
const internal_1 = require("@nx/js/internal");
|
|
@@ -32,7 +31,7 @@ function updateAppRoutes(host, options) {
|
|
|
32
31
|
const { content: componentContent, source: componentSource } = readComponent(host, appComponentPath);
|
|
33
32
|
const isComponentRouterPresent = componentContent.match(/react-router-dom/);
|
|
34
33
|
if (!isComponentRouterPresent) {
|
|
35
|
-
const changes = (0, devkit_1.applyChangesToString)(componentContent, (0,
|
|
34
|
+
const changes = (0, devkit_1.applyChangesToString)(componentContent, (0, ast_utils_1.addInitialRoutes)(appComponentPath, componentSource));
|
|
36
35
|
host.write(appComponentPath, changes);
|
|
37
36
|
}
|
|
38
37
|
}
|
|
@@ -16,6 +16,10 @@ export interface Schema {
|
|
|
16
16
|
name?: string;
|
|
17
17
|
publishable?: boolean;
|
|
18
18
|
routing?: boolean;
|
|
19
|
+
enableTypedLinting?: boolean;
|
|
20
|
+
/**
|
|
21
|
+
* @deprecated Use `enableTypedLinting` instead. This option will be removed in Nx v24.
|
|
22
|
+
*/
|
|
19
23
|
setParserOptionsProject?: boolean;
|
|
20
24
|
skipFormat?: boolean;
|
|
21
25
|
skipPackageJson?: boolean;
|
|
@@ -145,11 +145,17 @@
|
|
|
145
145
|
"description": "Whether to enable tsconfig strict mode or not.",
|
|
146
146
|
"default": true
|
|
147
147
|
},
|
|
148
|
-
"
|
|
148
|
+
"enableTypedLinting": {
|
|
149
149
|
"type": "boolean",
|
|
150
|
-
"description": "Whether
|
|
150
|
+
"description": "Whether to enable typed linting. For flat configs, this configures the recommended `parserOptions.projectService` and `tsconfigRootDir`. For legacy `.eslintrc` configs, this configures `parserOptions.project`. We do not enable this by default for lint performance reasons.",
|
|
151
151
|
"default": false
|
|
152
152
|
},
|
|
153
|
+
"setParserOptionsProject": {
|
|
154
|
+
"type": "boolean",
|
|
155
|
+
"description": "Deprecated alias for `enableTypedLinting`.",
|
|
156
|
+
"default": false,
|
|
157
|
+
"x-deprecated": "Use `enableTypedLinting` instead. This option will be removed in Nx v24."
|
|
158
|
+
},
|
|
153
159
|
"compiler": {
|
|
154
160
|
"type": "string",
|
|
155
161
|
"enum": ["babel", "swc"],
|
|
@@ -2,12 +2,11 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.setupSsrForRemote = setupSsrForRemote;
|
|
4
4
|
const devkit_1 = require("@nx/devkit");
|
|
5
|
-
const devkit_2 = require("@nx/devkit");
|
|
6
5
|
const versions_1 = require("../../../utils/versions");
|
|
7
6
|
const create_application_files_1 = require("../../application/lib/create-application-files");
|
|
8
7
|
async function setupSsrForRemote(tree, options, appName) {
|
|
9
8
|
const tasks = [];
|
|
10
|
-
const project = (0,
|
|
9
|
+
const project = (0, devkit_1.readProjectConfiguration)(tree, appName);
|
|
11
10
|
const pathToModuleFederationSsrFiles = options.typescriptConfiguration
|
|
12
11
|
? `${options.bundler === 'rspack' ? 'rspack-' : 'webpack-'}module-federation-ssr-ts`
|
|
13
12
|
: `${options.bundler === 'rspack' ? 'rspack-' : 'webpack-'}module-federation-ssr`;
|
|
@@ -29,28 +28,28 @@ async function setupSsrForRemote(tree, options, appName) {
|
|
|
29
28
|
browserBuildOutputPath: project.targets.build?.options?.outputPath,
|
|
30
29
|
serverBuildOutputPath: project.targets.server?.options?.outputPath,
|
|
31
30
|
};
|
|
32
|
-
(0,
|
|
31
|
+
(0, devkit_1.generateFiles)(tree, (0, devkit_1.joinPathFragments)(__dirname, `../files/${pathToModuleFederationSsrFiles}`), project.root, templateVariables);
|
|
33
32
|
// For hosts to use when running remotes in static mode.
|
|
34
33
|
const originalOutputPath = (project.targets.build?.options?.outputPath ??
|
|
35
34
|
options.isUsingTsSolutionConfig)
|
|
36
35
|
? 'dist'
|
|
37
|
-
: (0,
|
|
36
|
+
: (0, devkit_1.joinPathFragments)((0, devkit_1.offsetFromRoot)(options.appProjectRoot), 'dist', options.appProjectRoot != '.'
|
|
38
37
|
? options.appProjectRoot
|
|
39
38
|
: options.projectName);
|
|
40
39
|
const serverOptions = project.targets.server?.options;
|
|
41
40
|
const serverOutputPath = serverOptions?.outputPath ??
|
|
42
|
-
(0,
|
|
41
|
+
(0, devkit_1.joinPathFragments)(originalOutputPath, 'server');
|
|
43
42
|
const serverOutputName = serverOptions?.outputFileName ?? 'main.js';
|
|
44
43
|
project.targets['serve-static'] = {
|
|
45
44
|
dependsOn: ['build', 'server'],
|
|
46
45
|
executor: 'nx:run-commands',
|
|
47
46
|
defaultConfiguration: 'development',
|
|
48
47
|
options: {
|
|
49
|
-
command: `PORT=${options.devServerPort ?? 4200} node ${(0,
|
|
48
|
+
command: `PORT=${options.devServerPort ?? 4200} node ${(0, devkit_1.joinPathFragments)(serverOutputPath, serverOutputName)}`,
|
|
50
49
|
},
|
|
51
50
|
};
|
|
52
|
-
(0,
|
|
53
|
-
const installTask = (0,
|
|
51
|
+
(0, devkit_1.updateProjectConfiguration)(tree, appName, project);
|
|
52
|
+
const installTask = (0, devkit_1.addDependenciesToPackageJson)(tree, {
|
|
54
53
|
'@module-federation/node': versions_1.moduleFederationNodeVersion,
|
|
55
54
|
cors: versions_1.corsVersion,
|
|
56
55
|
isbot: versions_1.isbotVersion,
|
|
@@ -58,5 +57,5 @@ async function setupSsrForRemote(tree, options, appName) {
|
|
|
58
57
|
'@types/express': versions_1.typesExpressVersion,
|
|
59
58
|
}, {}, undefined, true);
|
|
60
59
|
tasks.push(installTask);
|
|
61
|
-
return (0,
|
|
60
|
+
return (0, devkit_1.runTasksInSerial)(...tasks);
|
|
62
61
|
}
|
|
@@ -4,10 +4,11 @@ exports.setupTspathForRemote = setupTspathForRemote;
|
|
|
4
4
|
const devkit_1 = require("@nx/devkit");
|
|
5
5
|
const js_1 = require("@nx/js");
|
|
6
6
|
const maybe_js_1 = require("../../../utils/maybe-js");
|
|
7
|
-
const
|
|
7
|
+
const versions_1 = require("../../../utils/versions");
|
|
8
8
|
function setupTspathForRemote(tree, options) {
|
|
9
|
+
const { normalizeProjectName } = (0, devkit_1.ensurePackage)('@nx/module-federation', versions_1.nxVersion);
|
|
9
10
|
const project = (0, devkit_1.readProjectConfiguration)(tree, options.projectName);
|
|
10
11
|
const exportPath = (0, maybe_js_1.maybeJs)(options, './src/remote-entry.ts');
|
|
11
12
|
const exportName = 'Module';
|
|
12
|
-
(0, js_1.addTsConfigPath)(tree, `${
|
|
13
|
+
(0, js_1.addTsConfigPath)(tree, `${normalizeProjectName(options.projectName)}/${exportName}`, [(0, devkit_1.joinPathFragments)(project.root, exportPath)]);
|
|
13
14
|
}
|
|
@@ -5,10 +5,11 @@ exports.remoteGenerator = remoteGenerator;
|
|
|
5
5
|
const tslib_1 = require("tslib");
|
|
6
6
|
const internal_1 = require("@nx/devkit/internal");
|
|
7
7
|
const assert_supported_react_version_1 = require("../../utils/assert-supported-react-version");
|
|
8
|
+
const internal_2 = require("@nx/eslint/internal");
|
|
8
9
|
const devkit_1 = require("@nx/devkit");
|
|
9
10
|
const path_1 = require("path");
|
|
10
11
|
const js_1 = require("@nx/js");
|
|
11
|
-
const
|
|
12
|
+
const internal_3 = require("@nx/js/internal");
|
|
12
13
|
const update_module_federation_project_1 = require("../../rules/update-module-federation-project");
|
|
13
14
|
const add_mf_env_to_inputs_1 = require("../../utils/add-mf-env-to-inputs");
|
|
14
15
|
const normalize_remote_1 = require("../../utils/normalize-remote");
|
|
@@ -59,7 +60,7 @@ function addModuleFederationFiles(host, options) {
|
|
|
59
60
|
host.delete(pathToWebpackProdConfig);
|
|
60
61
|
}
|
|
61
62
|
// Delete TypeScript prod config in TS solution setup - not needed in Crystal
|
|
62
|
-
if ((0,
|
|
63
|
+
if ((0, internal_3.isUsingTsSolutionSetup)(host)) {
|
|
63
64
|
const pathToTsProdConfig = (0, devkit_1.joinPathFragments)(options.appProjectRoot, options.bundler === 'rspack'
|
|
64
65
|
? 'rspack.config.prod.ts'
|
|
65
66
|
: 'webpack.config.prod.ts');
|
|
@@ -109,7 +110,7 @@ async function remoteGenerator(host, schema) {
|
|
|
109
110
|
});
|
|
110
111
|
tasks.push(initAppTask);
|
|
111
112
|
// In TS solution setup, update package.json to use simple name instead of scoped name
|
|
112
|
-
if ((0,
|
|
113
|
+
if ((0, internal_3.isUsingTsSolutionSetup)(host)) {
|
|
113
114
|
const remotePackageJsonPath = (0, devkit_1.joinPathFragments)(options.appProjectRoot, 'package.json');
|
|
114
115
|
if (host.exists(remotePackageJsonPath)) {
|
|
115
116
|
(0, devkit_1.updateJson)(host, remotePackageJsonPath, (json) => {
|
|
@@ -128,7 +129,7 @@ async function remoteGenerator(host, schema) {
|
|
|
128
129
|
addModuleFederationFiles(host, options);
|
|
129
130
|
(0, update_module_federation_project_1.updateModuleFederationProject)(host, options);
|
|
130
131
|
// Conditionally setup TS path or package.json exports based on TS solution setup
|
|
131
|
-
if ((0,
|
|
132
|
+
if ((0, internal_3.isUsingTsSolutionSetup)(host)) {
|
|
132
133
|
(0, setup_package_json_exports_for_remote_1.setupPackageJsonExportsForRemote)(host, options);
|
|
133
134
|
}
|
|
134
135
|
else {
|
|
@@ -152,7 +153,7 @@ async function remoteGenerator(host, schema) {
|
|
|
152
153
|
(0, devkit_1.updateProjectConfiguration)(host, options.projectName, projectConfig);
|
|
153
154
|
}
|
|
154
155
|
}
|
|
155
|
-
if (!
|
|
156
|
+
if (!(0, internal_2.isTypedLintingEnabled)(options)) {
|
|
156
157
|
host.delete((0, devkit_1.joinPathFragments)(options.appProjectRoot, 'tsconfig.lint.json'));
|
|
157
158
|
}
|
|
158
159
|
if (options.host && options.bundler === 'rspack') {
|
|
@@ -164,7 +165,7 @@ async function remoteGenerator(host, schema) {
|
|
|
164
165
|
}
|
|
165
166
|
if (options.host && options.dynamic) {
|
|
166
167
|
const hostConfig = (0, devkit_1.readProjectConfiguration)(host, schema.host);
|
|
167
|
-
const pathToMFManifest = (0, devkit_1.joinPathFragments)((0,
|
|
168
|
+
const pathToMFManifest = (0, devkit_1.joinPathFragments)((0, internal_3.getProjectSourceRoot)(hostConfig, host), 'assets/module-federation.manifest.json');
|
|
168
169
|
(0, add_remote_to_dynamic_host_1.addRemoteToDynamicHost)(host, options.projectName, options.devServerPort, pathToMFManifest);
|
|
169
170
|
}
|
|
170
171
|
(0, add_mf_env_to_inputs_1.addMfEnvToTargetDefaultInputs)(host, options.bundler);
|
|
@@ -172,6 +173,14 @@ async function remoteGenerator(host, schema) {
|
|
|
172
173
|
'@module-federation/enhanced': versions_1.moduleFederationEnhancedVersion,
|
|
173
174
|
'@nx/web': versions_1.nxVersion,
|
|
174
175
|
'@nx/module-federation': versions_1.nxVersion,
|
|
176
|
+
// The webpack path also generates a `serve-static` target running the
|
|
177
|
+
// `module-federation-static-server` executor, which proxies via express.
|
|
178
|
+
...(options.bundler !== 'rspack'
|
|
179
|
+
? {
|
|
180
|
+
express: versions_1.expressVersion,
|
|
181
|
+
'http-proxy-middleware': versions_1.httpProxyMiddlewareVersion,
|
|
182
|
+
}
|
|
183
|
+
: {}),
|
|
175
184
|
}, undefined, true);
|
|
176
185
|
tasks.push(installTask);
|
|
177
186
|
if (!options.skipFormat) {
|
|
@@ -14,6 +14,10 @@ export interface Schema {
|
|
|
14
14
|
linter: Linter | LinterType;
|
|
15
15
|
name?: string;
|
|
16
16
|
routing?: boolean;
|
|
17
|
+
enableTypedLinting?: boolean;
|
|
18
|
+
/**
|
|
19
|
+
* @deprecated Use `enableTypedLinting` instead. This option will be removed in Nx v24.
|
|
20
|
+
*/
|
|
17
21
|
setParserOptionsProject?: boolean;
|
|
18
22
|
skipFormat: boolean;
|
|
19
23
|
skipNxJson?: boolean;
|
|
@@ -115,11 +115,17 @@
|
|
|
115
115
|
"description": "Creates an application with strict mode and strict type checking.",
|
|
116
116
|
"default": true
|
|
117
117
|
},
|
|
118
|
-
"
|
|
118
|
+
"enableTypedLinting": {
|
|
119
119
|
"type": "boolean",
|
|
120
|
-
"description": "Whether
|
|
120
|
+
"description": "Whether to enable typed linting. For flat configs, this configures the recommended `parserOptions.projectService` and `tsconfigRootDir`. For legacy `.eslintrc` configs, this configures `parserOptions.project`. We do not enable this by default for lint performance reasons.",
|
|
121
121
|
"default": false
|
|
122
122
|
},
|
|
123
|
+
"setParserOptionsProject": {
|
|
124
|
+
"type": "boolean",
|
|
125
|
+
"description": "Deprecated alias for `enableTypedLinting`.",
|
|
126
|
+
"default": false,
|
|
127
|
+
"x-deprecated": "Use `enableTypedLinting` instead. This option will be removed in Nx v24."
|
|
128
|
+
},
|
|
123
129
|
"compiler": {
|
|
124
130
|
"type": "string",
|
|
125
131
|
"description": "The compiler to use.",
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = addOptionalModuleFederationPackages;
|
|
4
|
+
const devkit_1 = require("@nx/devkit");
|
|
5
|
+
const versions_1 = require("../../utils/versions");
|
|
6
|
+
const moduleFederationExecutors = new Set([
|
|
7
|
+
'@nx/react:module-federation-dev-server',
|
|
8
|
+
'@nx/react:module-federation-ssr-dev-server',
|
|
9
|
+
'@nx/react:module-federation-static-server',
|
|
10
|
+
]);
|
|
11
|
+
const staticServerExecutor = '@nx/react:module-federation-static-server';
|
|
12
|
+
function collectExecutors(targetDefaults) {
|
|
13
|
+
// targetDefaults are keyed by target name or executor, and a default can set
|
|
14
|
+
// an executor that an empty project target inherits, so scan the keys and any
|
|
15
|
+
// executor on the default (both the object and array forms).
|
|
16
|
+
const executors = [];
|
|
17
|
+
for (const [targetOrExecutor, config] of Object.entries(targetDefaults ?? {})) {
|
|
18
|
+
executors.push(targetOrExecutor);
|
|
19
|
+
for (const entry of Array.isArray(config) ? config : [config]) {
|
|
20
|
+
if (entry.executor != null) {
|
|
21
|
+
executors.push(entry.executor);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return executors;
|
|
26
|
+
}
|
|
27
|
+
async function addOptionalModuleFederationPackages(tree) {
|
|
28
|
+
const projects = (0, devkit_1.getProjects)(tree);
|
|
29
|
+
const nxJson = (0, devkit_1.readNxJson)(tree);
|
|
30
|
+
let needsModuleFederation = false;
|
|
31
|
+
let needsStaticServer = false;
|
|
32
|
+
for (const [, project] of projects) {
|
|
33
|
+
for (const target of Object.values(project.targets ?? {})) {
|
|
34
|
+
needsModuleFederation ||= moduleFederationExecutors.has(target.executor);
|
|
35
|
+
needsStaticServer ||= target.executor === staticServerExecutor;
|
|
36
|
+
}
|
|
37
|
+
// Remotes get a plain dev-server (no Module Federation executor) but still
|
|
38
|
+
// generate a module-federation.config that requires @nx/module-federation
|
|
39
|
+
// at build time, so detect them by that config file too. This covers
|
|
40
|
+
// remotes whose host lives in a different workspace.
|
|
41
|
+
needsModuleFederation ||=
|
|
42
|
+
tree.exists((0, devkit_1.joinPathFragments)(project.root, 'module-federation.config.ts')) ||
|
|
43
|
+
tree.exists((0, devkit_1.joinPathFragments)(project.root, 'module-federation.config.js'));
|
|
44
|
+
}
|
|
45
|
+
for (const executor of collectExecutors(nxJson?.targetDefaults)) {
|
|
46
|
+
needsModuleFederation ||= moduleFederationExecutors.has(executor);
|
|
47
|
+
needsStaticServer ||= executor === staticServerExecutor;
|
|
48
|
+
}
|
|
49
|
+
if (!needsModuleFederation && !needsStaticServer) {
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
return (0, devkit_1.addDependenciesToPackageJson)(tree, {}, {
|
|
53
|
+
...(needsModuleFederation ? { '@nx/module-federation': versions_1.nxVersion } : {}),
|
|
54
|
+
...(needsStaticServer
|
|
55
|
+
? {
|
|
56
|
+
express: versions_1.expressVersion,
|
|
57
|
+
'http-proxy-middleware': versions_1.httpProxyMiddlewareVersion,
|
|
58
|
+
}
|
|
59
|
+
: {}),
|
|
60
|
+
}, undefined, true);
|
|
61
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
#### Add Optional Module Federation Packages
|
|
2
|
+
|
|
3
|
+
Adds `@nx/module-federation`, `express`, and `http-proxy-middleware` to the workspace when existing targets require them.
|
|
4
|
+
|
|
5
|
+
These packages are no longer direct dependencies of `@nx/react`; they are now optional peer dependencies, so installing `@nx/react` no longer pulls the Module Federation toolchain into workspaces that never use it. This migration backfills them for workspaces that already use Module Federation so those builds keep working after upgrading. Packages that are already present are left untouched.
|
|
6
|
+
|
|
7
|
+
A package is added only when a matching target exists:
|
|
8
|
+
|
|
9
|
+
- `@nx/module-federation`: an `@nx/react:module-federation-dev-server`, `@nx/react:module-federation-ssr-dev-server`, or `@nx/react:module-federation-static-server` target, or a project with a `module-federation.config.{js,ts}` file (covers remotes whose host lives in another workspace).
|
|
10
|
+
- `express` and `http-proxy-middleware`: an `@nx/react:module-federation-static-server` target, which proxies the static remotes.
|
|
11
|
+
|
|
12
|
+
Targets that inherit their executor from an `nx.json` `targetDefaults` entry are detected too.
|
|
13
|
+
|
|
14
|
+
#### Examples
|
|
15
|
+
|
|
16
|
+
For a workspace with an `@nx/react:module-federation-dev-server` serve target, the migration adds the Module Federation packages to `devDependencies`.
|
|
17
|
+
|
|
18
|
+
##### Before
|
|
19
|
+
|
|
20
|
+
```jsonc title="package.json"
|
|
21
|
+
{
|
|
22
|
+
"devDependencies": {
|
|
23
|
+
"@nx/react": "23.1.0",
|
|
24
|
+
},
|
|
25
|
+
}
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
##### After
|
|
29
|
+
|
|
30
|
+
```jsonc title="package.json"
|
|
31
|
+
{
|
|
32
|
+
"devDependencies": {
|
|
33
|
+
"@nx/module-federation": "23.2.0",
|
|
34
|
+
"@nx/react": "23.1.0",
|
|
35
|
+
},
|
|
36
|
+
}
|
|
37
|
+
```
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = addSvgrWebpackIfUsed;
|
|
4
|
+
const devkit_1 = require("@nx/devkit");
|
|
5
|
+
const versions_1 = require("../../utils/versions");
|
|
6
|
+
// The Nx 22 `add-svgr-to-webpack-config` migration inlined a `withSvgr` helper
|
|
7
|
+
// that resolves `@svgr/webpack` into user webpack configs, but never added the
|
|
8
|
+
// package to the workspace - it only resolved transitively through `@nx/react`.
|
|
9
|
+
// Now that `@nx/react` no longer depends on it, backfill it where a webpack
|
|
10
|
+
// config actually references it.
|
|
11
|
+
const webpackConfigFileNames = [
|
|
12
|
+
'webpack.config.js',
|
|
13
|
+
'webpack.config.ts',
|
|
14
|
+
'webpack.config.cjs',
|
|
15
|
+
'webpack.config.mjs',
|
|
16
|
+
'webpack.config.prod.js',
|
|
17
|
+
'webpack.config.prod.ts',
|
|
18
|
+
'webpack.server.config.js',
|
|
19
|
+
'webpack.server.config.ts',
|
|
20
|
+
];
|
|
21
|
+
async function addSvgrWebpackIfUsed(tree) {
|
|
22
|
+
let needsSvgr = false;
|
|
23
|
+
for (const [, project] of (0, devkit_1.getProjects)(tree)) {
|
|
24
|
+
// Configs referenced by executor targets can live anywhere.
|
|
25
|
+
for (const target of Object.values(project.targets ?? {})) {
|
|
26
|
+
for (const options of [
|
|
27
|
+
target.options,
|
|
28
|
+
...Object.values(target.configurations ?? {}),
|
|
29
|
+
]) {
|
|
30
|
+
const webpackConfig = options?.webpackConfig;
|
|
31
|
+
if (typeof webpackConfig === 'string') {
|
|
32
|
+
needsSvgr ||= referencesSvgrWebpack(tree, webpackConfig);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
// Inferred setups have no executor options pointing at a config, so also
|
|
37
|
+
// check the conventional config file names at the project root.
|
|
38
|
+
for (const fileName of webpackConfigFileNames) {
|
|
39
|
+
needsSvgr ||= referencesSvgrWebpack(tree, (0, devkit_1.joinPathFragments)(project.root, fileName));
|
|
40
|
+
}
|
|
41
|
+
if (needsSvgr) {
|
|
42
|
+
break;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
if (!needsSvgr) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
return (0, devkit_1.addDependenciesToPackageJson)(tree, {}, { '@svgr/webpack': versions_1.svgrWebpackVersion }, undefined, true);
|
|
49
|
+
}
|
|
50
|
+
function referencesSvgrWebpack(tree, path) {
|
|
51
|
+
if (!tree.exists(path)) {
|
|
52
|
+
return false;
|
|
53
|
+
}
|
|
54
|
+
return tree.read(path, 'utf-8').includes('@svgr/webpack');
|
|
55
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
#### Add `@svgr/webpack` If Used
|
|
2
|
+
|
|
3
|
+
Adds `@svgr/webpack` to the workspace when a webpack config references it.
|
|
4
|
+
|
|
5
|
+
`@svgr/webpack` is no longer a dependency of `@nx/react`, so workspaces whose webpack configs resolve it - which is what the Nx 22 `add-svgr-to-webpack-config` migration inlined - must declare it themselves. This migration backfills it for those workspaces. Configs referenced by executor targets are checked, as well as the conventional config file names at each project root. Workspaces that already have `@svgr/webpack` are left untouched.
|
|
6
|
+
|
|
7
|
+
#### Examples
|
|
8
|
+
|
|
9
|
+
##### Before
|
|
10
|
+
|
|
11
|
+
```jsonc title="package.json"
|
|
12
|
+
{
|
|
13
|
+
"devDependencies": {
|
|
14
|
+
"@nx/react": "23.1.0",
|
|
15
|
+
},
|
|
16
|
+
}
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
##### After
|
|
20
|
+
|
|
21
|
+
```jsonc title="package.json"
|
|
22
|
+
{
|
|
23
|
+
"devDependencies": {
|
|
24
|
+
"@nx/react": "23.1.0",
|
|
25
|
+
"@svgr/webpack": "^8.0.1",
|
|
26
|
+
},
|
|
27
|
+
}
|
|
28
|
+
```
|
|
@@ -5,18 +5,16 @@ const internal_1 = require("@nx/devkit/internal");
|
|
|
5
5
|
const devkit_1 = require("@nx/devkit");
|
|
6
6
|
const path_1 = require("path");
|
|
7
7
|
const fs_1 = require("fs");
|
|
8
|
-
const cache_directory_1 = require("nx/src/utils/cache-directory");
|
|
9
8
|
const js_1 = require("@nx/js");
|
|
10
|
-
const devkit_internals_1 = require("nx/src/devkit-internals");
|
|
11
9
|
const internal_2 = require("@nx/js/internal");
|
|
12
10
|
const pmCommand = (0, devkit_1.getPackageManagerCommand)();
|
|
13
11
|
const reactRouterConfigBlob = '**/react-router.config.{ts,js,cjs,cts,mjs,mts}';
|
|
14
12
|
exports.createNodes = [
|
|
15
13
|
reactRouterConfigBlob,
|
|
16
14
|
async (configFiles, options, context) => {
|
|
17
|
-
const optionsHash = (0,
|
|
15
|
+
const optionsHash = (0, internal_1.hashObject)(options);
|
|
18
16
|
const normalizedOptions = normalizeOptions(options);
|
|
19
|
-
const cachePath = (0, path_1.join)(
|
|
17
|
+
const cachePath = (0, path_1.join)(internal_1.workspaceDataDirectory, `react-router-${optionsHash}.hash`);
|
|
20
18
|
const targetsCache = new internal_1.PluginCache(cachePath);
|
|
21
19
|
const isUsingTsSolutionSetup = (0, internal_2.isUsingTsSolutionSetup)();
|
|
22
20
|
const { roots: projectRoots, configFiles: validConfigFiles } = configFiles.reduce((acc, configFile) => {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function assertPackageIsInstalled(packageName: string, requiredBy: string): void;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.assertPackageIsInstalled = assertPackageIsInstalled;
|
|
4
|
+
function assertPackageIsInstalled(packageName, requiredBy) {
|
|
5
|
+
try {
|
|
6
|
+
require.resolve(packageName);
|
|
7
|
+
}
|
|
8
|
+
catch (e) {
|
|
9
|
+
// Only a missing module means "not installed"; surface other resolution
|
|
10
|
+
// errors (e.g. a malformed package's exports) as-is instead of mislabeling.
|
|
11
|
+
const code = e.code;
|
|
12
|
+
if (code !== 'MODULE_NOT_FOUND' && code !== 'ERR_MODULE_NOT_FOUND') {
|
|
13
|
+
throw e;
|
|
14
|
+
}
|
|
15
|
+
throw new Error(`The "${packageName}" package is required by "${requiredBy}" but is not installed. Please install it and try again.`);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -4,8 +4,8 @@ exports.createTsConfig = createTsConfig;
|
|
|
4
4
|
exports.extractTsConfigBase = extractTsConfigBase;
|
|
5
5
|
const tslib_1 = require("tslib");
|
|
6
6
|
const shared = tslib_1.__importStar(require("@nx/js"));
|
|
7
|
-
const json_1 = require("nx/src/generators/utils/json");
|
|
8
7
|
const internal_1 = require("@nx/js/internal");
|
|
8
|
+
const devkit_1 = require("@nx/devkit");
|
|
9
9
|
function createTsConfig(host, projectRoot, type, options, relativePathToRootTsConfig) {
|
|
10
10
|
if ((0, internal_1.isUsingTsSolutionSetup)(host)) {
|
|
11
11
|
createTsConfigForTsSolution(host, projectRoot, type, options, relativePathToRootTsConfig);
|
|
@@ -43,10 +43,10 @@ function createTsConfigForTsSolution(host, projectRoot, type, options, relativeP
|
|
|
43
43
|
else {
|
|
44
44
|
json.extends = relativePathToRootTsConfig;
|
|
45
45
|
}
|
|
46
|
-
(0,
|
|
46
|
+
(0, devkit_1.writeJson)(host, `${projectRoot}/tsconfig.json`, json);
|
|
47
47
|
const tsconfigProjectPath = `${projectRoot}/tsconfig.${type}.json`;
|
|
48
48
|
if (host.exists(tsconfigProjectPath)) {
|
|
49
|
-
(0,
|
|
49
|
+
(0, devkit_1.updateJson)(host, tsconfigProjectPath, (json) => {
|
|
50
50
|
if (options.bundler === 'vite') {
|
|
51
51
|
json.compilerOptions ??= {};
|
|
52
52
|
const types = new Set(json.compilerOptions.types ?? []);
|
|
@@ -92,10 +92,10 @@ function createTsConfigForNonTsSolution(host, projectRoot, type, options, relati
|
|
|
92
92
|
else {
|
|
93
93
|
json.extends = relativePathToRootTsConfig;
|
|
94
94
|
}
|
|
95
|
-
(0,
|
|
95
|
+
(0, devkit_1.writeJson)(host, `${projectRoot}/tsconfig.json`, json);
|
|
96
96
|
const tsconfigProjectPath = `${projectRoot}/tsconfig.${type}.json`;
|
|
97
97
|
if (options.bundler === 'vite' && host.exists(tsconfigProjectPath)) {
|
|
98
|
-
(0,
|
|
98
|
+
(0, devkit_1.updateJson)(host, tsconfigProjectPath, (json) => {
|
|
99
99
|
json.compilerOptions ??= {};
|
|
100
100
|
const types = new Set(json.compilerOptions.types ?? []);
|
|
101
101
|
types.add('node');
|
|
@@ -33,6 +33,7 @@ export declare const postcssVersion = "8.4.38";
|
|
|
33
33
|
export declare const autoprefixerVersion = "10.4.13";
|
|
34
34
|
export declare const expressVersion = "^4.21.2";
|
|
35
35
|
export declare const typesExpressVersion = "^4.17.21";
|
|
36
|
+
export declare const httpProxyMiddlewareVersion = "^3.0.5";
|
|
36
37
|
export declare const isbotVersion = "^3.6.5";
|
|
37
38
|
export declare const corsVersion = "~2.8.5";
|
|
38
39
|
export declare const typesCorsVersion = "~2.8.12";
|
|
@@ -41,3 +42,4 @@ export declare const moduleFederationEnhancedVersion = "^2.1.0";
|
|
|
41
42
|
export declare const sassVersion = "^1.97.2";
|
|
42
43
|
export declare const rollupPluginUrlVersion = "^8.0.2";
|
|
43
44
|
export declare const svgrRollupVersion = "^8.1.0";
|
|
45
|
+
export declare const svgrWebpackVersion = "^8.0.1";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.svgrRollupVersion = exports.rollupPluginUrlVersion = exports.sassVersion = exports.moduleFederationEnhancedVersion = exports.moduleFederationNodeVersion = exports.typesCorsVersion = exports.corsVersion = exports.isbotVersion = exports.typesExpressVersion = exports.expressVersion = exports.autoprefixerVersion = exports.postcssVersion = exports.tsLibVersion = exports.eslintPluginReactHooksVersion = exports.eslintPluginReactVersion = exports.eslintPluginJsxA11yVersion = exports.eslintPluginImportVersion = exports.reactReduxVersion = exports.reduxjsToolkitVersion = exports.testingLibraryDomVersion = exports.testingLibraryReactVersion = exports.reactRouterIsBotVersion = exports.reactRouterVersion = exports.reactRouterDomVersion = exports.babelCoreVersion = exports.babelPresetReactVersion = exports.typesNodeVersion = exports.reactViteVersion = exports.typesReactIsVersion = exports.typesReactIsV18Version = exports.typesReactDomVersion = exports.typesReactDomV18Version = exports.typesReactVersion = exports.typesReactV18Version = exports.swcLoaderVersion = exports.reactIsV18Version = exports.reactIsVersion = exports.reactDomV18Version = exports.reactDomVersion = exports.reactV18Version = exports.reactVersion = exports.minSupportedReactVersion = exports.nxVersion = void 0;
|
|
3
|
+
exports.svgrWebpackVersion = exports.svgrRollupVersion = exports.rollupPluginUrlVersion = exports.sassVersion = exports.moduleFederationEnhancedVersion = exports.moduleFederationNodeVersion = exports.typesCorsVersion = exports.corsVersion = exports.isbotVersion = exports.httpProxyMiddlewareVersion = exports.typesExpressVersion = exports.expressVersion = exports.autoprefixerVersion = exports.postcssVersion = exports.tsLibVersion = exports.eslintPluginReactHooksVersion = exports.eslintPluginReactVersion = exports.eslintPluginJsxA11yVersion = exports.eslintPluginImportVersion = exports.reactReduxVersion = exports.reduxjsToolkitVersion = exports.testingLibraryDomVersion = exports.testingLibraryReactVersion = exports.reactRouterIsBotVersion = exports.reactRouterVersion = exports.reactRouterDomVersion = exports.babelCoreVersion = exports.babelPresetReactVersion = exports.typesNodeVersion = exports.reactViteVersion = exports.typesReactIsVersion = exports.typesReactIsV18Version = exports.typesReactDomVersion = exports.typesReactDomV18Version = exports.typesReactVersion = exports.typesReactV18Version = exports.swcLoaderVersion = exports.reactIsV18Version = exports.reactIsVersion = exports.reactDomV18Version = exports.reactDomVersion = exports.reactV18Version = exports.reactVersion = exports.minSupportedReactVersion = exports.nxVersion = void 0;
|
|
4
4
|
const path_1 = require("path");
|
|
5
5
|
exports.nxVersion = require((0, path_1.join)('@nx/react', 'package.json')).version;
|
|
6
6
|
exports.minSupportedReactVersion = '18.0.0';
|
|
@@ -41,6 +41,7 @@ exports.autoprefixerVersion = '10.4.13';
|
|
|
41
41
|
// SSR and Module Federation
|
|
42
42
|
exports.expressVersion = '^4.21.2';
|
|
43
43
|
exports.typesExpressVersion = '^4.17.21';
|
|
44
|
+
exports.httpProxyMiddlewareVersion = '^3.0.5';
|
|
44
45
|
exports.isbotVersion = '^3.6.5';
|
|
45
46
|
exports.corsVersion = '~2.8.5';
|
|
46
47
|
exports.typesCorsVersion = '~2.8.12';
|
|
@@ -51,3 +52,4 @@ exports.sassVersion = '^1.97.2';
|
|
|
51
52
|
// rollup plugins (if needed)
|
|
52
53
|
exports.rollupPluginUrlVersion = '^8.0.2';
|
|
53
54
|
exports.svgrRollupVersion = '^8.1.0';
|
|
55
|
+
exports.svgrWebpackVersion = '^8.0.1';
|
package/migrations.json
CHANGED
|
@@ -39,6 +39,18 @@
|
|
|
39
39
|
"description": "Create AI instructions to help migrate workspaces from React 18 to 19.",
|
|
40
40
|
"prompt": "./dist/src/migrations/update-23-1-0/ai-instructions-for-react-19.md",
|
|
41
41
|
"documentation": "./dist/src/migrations/update-23-1-0/upgrade-to-react-19.md"
|
|
42
|
+
},
|
|
43
|
+
"update-23-2-0-add-optional-module-federation-packages": {
|
|
44
|
+
"version": "23.2.0-beta.4",
|
|
45
|
+
"description": "Add optional Module Federation packages when existing targets require them.",
|
|
46
|
+
"implementation": "./dist/src/migrations/update-23-2-0/add-optional-module-federation-packages",
|
|
47
|
+
"documentation": "./dist/src/migrations/update-23-2-0/add-optional-module-federation-packages.md"
|
|
48
|
+
},
|
|
49
|
+
"update-23-2-0-add-svgr-webpack-if-used": {
|
|
50
|
+
"version": "23.2.0-beta.4",
|
|
51
|
+
"description": "Add `@svgr/webpack` when a webpack config references it.",
|
|
52
|
+
"implementation": "./dist/src/migrations/update-23-2-0/add-svgr-webpack-if-used",
|
|
53
|
+
"documentation": "./dist/src/migrations/update-23-2-0/add-svgr-webpack-if-used.md"
|
|
42
54
|
}
|
|
43
55
|
},
|
|
44
56
|
"packageJsonUpdates": {
|