@nx/rspack 24.0.0-beta.2 → 24.0.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.
- package/dist/ready-check.d.ts +1 -0
- package/dist/ready-check.js +9 -0
- package/dist/ready-signal.d.ts +1 -0
- package/dist/ready-signal.js +5 -0
- package/dist/src/executors/dev-server/dev-server.impl.js +0 -2
- package/dist/src/executors/rspack/lib/config.js +18 -8
- package/dist/src/generators/configuration/configuration.js +5 -29
- package/dist/src/generators/configuration/schema.json +2 -2
- package/dist/src/generators/convert-config-to-rspack-plugin/convert-config-to-rspack-plugin.js +78 -45
- package/dist/src/generators/convert-config-to-rspack-plugin/lib/extract-rspack-options.d.ts +1 -0
- package/dist/src/generators/convert-config-to-rspack-plugin/lib/extract-rspack-options.js +31 -2
- package/dist/src/generators/convert-config-to-rspack-plugin/schema.json +2 -2
- package/dist/src/generators/convert-to-inferred/convert-to-inferred.js +5 -4
- package/dist/src/generators/convert-to-inferred/utils/build-post-target-transformer.js +13 -5
- package/dist/src/generators/convert-to-inferred/utils/serve-post-target-transformer.js +8 -14
- package/dist/src/generators/convert-webpack/convert-webpack.js +20 -74
- package/dist/src/generators/convert-webpack/lib/transform-plugin-config.d.ts +1 -1
- package/dist/src/generators/convert-webpack/lib/transform-plugin-config.js +47 -69
- package/dist/src/generators/init/init.js +38 -44
- package/dist/src/generators/init/schema.d.ts +0 -1
- package/dist/src/migrations/update-24-0-0/finish-inferred-conversion.md +11 -0
- package/dist/src/migrations/update-24-0-0/inventory.d.ts +9 -0
- package/dist/src/migrations/update-24-0-0/inventory.js +53 -0
- package/dist/src/migrations/update-24-0-0/migrate-compose-plugins.d.ts +10 -0
- package/dist/src/migrations/update-24-0-0/migrate-compose-plugins.js +60 -0
- package/dist/src/migrations/update-24-0-0/migrate-compose-plugins.md +95 -0
- package/dist/src/migrations/update-24-0-0/remove-deprecated-executors.d.ts +6 -0
- package/dist/src/migrations/update-24-0-0/remove-deprecated-executors.js +36 -0
- package/dist/src/migrations/update-24-0-0/remove-deprecated-executors.md +90 -0
- package/dist/src/plugins/nx-app-rspack-plugin/nx-app-rspack-plugin.d.ts +2 -0
- package/dist/src/plugins/nx-app-rspack-plugin/nx-app-rspack-plugin.js +10 -1
- package/dist/src/plugins/plugin.js +21 -0
- package/dist/src/utils/config.d.ts +10 -14
- package/dist/src/utils/config.js +17 -70
- package/dist/src/utils/deprecation.d.ts +1 -6
- package/dist/src/utils/deprecation.js +4 -23
- package/dist/src/utils/dev-server-ready-check.d.ts +48 -0
- package/dist/src/utils/dev-server-ready-check.js +339 -0
- package/dist/src/utils/dev-server-ready-signal.d.ts +29 -0
- package/dist/src/utils/dev-server-ready-signal.js +60 -0
- package/dist/src/utils/e2e-web-server-info-utils.d.ts +1 -1
- package/dist/src/utils/e2e-web-server-info-utils.js +2 -2
- package/dist/src/utils/generator-utils.d.ts +1 -2
- package/dist/src/utils/generator-utils.js +69 -185
- package/dist/src/utils/read-rspack-options.d.ts +1 -1
- package/dist/src/utils/read-rspack-options.js +4 -4
- package/dist/src/utils/with-nx.d.ts +5 -9
- package/dist/src/utils/with-nx.js +5 -32
- package/dist/src/utils/with-react.d.ts +5 -8
- package/dist/src/utils/with-react.js +5 -15
- package/dist/src/utils/with-web.d.ts +5 -8
- package/dist/src/utils/with-web.js +5 -44
- package/executors.json +0 -25
- package/migrations.json +13 -0
- package/package.json +39 -26
- package/dist/module-federation.d.ts +0 -4
- package/dist/module-federation.js +0 -9
- package/dist/src/executors/module-federation-dev-server/lib/index.d.ts +0 -2
- package/dist/src/executors/module-federation-dev-server/lib/index.js +0 -5
- package/dist/src/executors/module-federation-dev-server/lib/normalize-options.d.ts +0 -4
- package/dist/src/executors/module-federation-dev-server/lib/normalize-options.js +0 -19
- package/dist/src/executors/module-federation-dev-server/lib/start-remotes.d.ts +0 -5
- package/dist/src/executors/module-federation-dev-server/lib/start-remotes.js +0 -33
- package/dist/src/executors/module-federation-dev-server/module-federation-dev-server.impl.d.ts +0 -6
- package/dist/src/executors/module-federation-dev-server/module-federation-dev-server.impl.js +0 -74
- package/dist/src/executors/module-federation-dev-server/schema.d.ts +0 -25
- package/dist/src/executors/module-federation-dev-server/schema.json +0 -104
- package/dist/src/executors/module-federation-ssr-dev-server/lib/index.d.ts +0 -2
- package/dist/src/executors/module-federation-ssr-dev-server/lib/index.js +0 -5
- package/dist/src/executors/module-federation-ssr-dev-server/lib/normalize-options.d.ts +0 -4
- package/dist/src/executors/module-federation-ssr-dev-server/lib/normalize-options.js +0 -23
- package/dist/src/executors/module-federation-ssr-dev-server/lib/start-remotes.d.ts +0 -5
- package/dist/src/executors/module-federation-ssr-dev-server/lib/start-remotes.js +0 -34
- package/dist/src/executors/module-federation-ssr-dev-server/module-federation-ssr-dev-server.impl.d.ts +0 -5
- package/dist/src/executors/module-federation-ssr-dev-server/module-federation-ssr-dev-server.impl.js +0 -65
- package/dist/src/executors/module-federation-ssr-dev-server/schema.d.ts +0 -29
- package/dist/src/executors/module-federation-ssr-dev-server/schema.json +0 -85
- package/dist/src/executors/module-federation-static-server/module-federation-static-server.impl.d.ts +0 -12
- package/dist/src/executors/module-federation-static-server/module-federation-static-server.impl.js +0 -237
- package/dist/src/executors/module-federation-static-server/schema.d.ts +0 -3
- package/dist/src/executors/module-federation-static-server/schema.json +0 -16
- package/dist/src/executors/rspack/rspack.impl.d.ts +0 -7
- package/dist/src/executors/rspack/rspack.impl.js +0 -127
- package/dist/src/executors/rspack/schema.json +0 -410
- package/dist/src/generators/convert-webpack/lib/transform-cjs.d.ts +0 -2
- package/dist/src/generators/convert-webpack/lib/transform-cjs.js +0 -263
- package/dist/src/generators/convert-webpack/lib/transform-esm.d.ts +0 -2
- package/dist/src/generators/convert-webpack/lib/transform-esm.js +0 -263
- package/dist/src/utils/has-plugin.d.ts +0 -2
- package/dist/src/utils/has-plugin.js +0 -10
- package/dist/src/utils/module-federation-deprecation.d.ts +0 -6
- package/dist/src/utils/module-federation-deprecation.js +0 -30
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function waitForDevServer(configPath: string): Promise<void>;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.waitForDevServer = waitForDevServer;
|
|
4
|
+
const dev_server_ready_check_1 = require("./src/utils/dev-server-ready-check");
|
|
5
|
+
async function waitForDevServer(configPath) {
|
|
6
|
+
await (0, dev_server_ready_check_1.waitForRspackDevServer)(configPath);
|
|
7
|
+
// A config can leave handles open that would keep the check running
|
|
8
|
+
process.exit(0);
|
|
9
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { NxReadySignalPlugin } from './src/utils/dev-server-ready-signal';
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NxReadySignalPlugin = void 0;
|
|
4
|
+
var dev_server_ready_signal_1 = require("./src/utils/dev-server-ready-signal");
|
|
5
|
+
Object.defineProperty(exports, "NxReadySignalPlugin", { enumerable: true, get: function () { return dev_server_ready_signal_1.NxReadySignalPlugin; } });
|
|
@@ -9,9 +9,7 @@ const create_compiler_1 = require("../../utils/create-compiler");
|
|
|
9
9
|
const mode_utils_1 = require("../../utils/mode-utils");
|
|
10
10
|
const normalize_options_1 = require("../rspack/lib/normalize-options");
|
|
11
11
|
const get_dev_server_config_1 = require("./lib/get-dev-server-config");
|
|
12
|
-
const deprecation_1 = require("../../utils/deprecation");
|
|
13
12
|
async function* runExecutor(options, context) {
|
|
14
|
-
(0, deprecation_1.warnRspackDevServerExecutorDeprecation)();
|
|
15
13
|
process.env.NODE_ENV ??= options.mode ?? 'development';
|
|
16
14
|
if ((0, mode_utils_1.isMode)(process.env.NODE_ENV)) {
|
|
17
15
|
options.mode = process.env.NODE_ENV;
|
|
@@ -2,10 +2,9 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getRspackConfigs = getRspackConfigs;
|
|
4
4
|
const config_1 = require("../../../utils/config");
|
|
5
|
-
const deprecation_1 = require("../../../utils/deprecation");
|
|
6
5
|
const resolve_user_defined_rspack_config_1 = require("../../../utils/resolve-user-defined-rspack-config");
|
|
7
|
-
const
|
|
8
|
-
const
|
|
6
|
+
const apply_base_config_1 = require("../../../plugins/utils/apply-base-config");
|
|
7
|
+
const apply_web_config_1 = require("../../../plugins/utils/apply-web-config");
|
|
9
8
|
async function getRspackConfigs(options, context) {
|
|
10
9
|
let maybeUserDefinedConfig = await (0, resolve_user_defined_rspack_config_1.resolveUserDefinedRspackConfig)(options.rspackConfig, options.tsConfig);
|
|
11
10
|
let userDefinedConfig = 'default' in maybeUserDefinedConfig
|
|
@@ -16,11 +15,22 @@ async function getRspackConfigs(options, context) {
|
|
|
16
15
|
if (typeof userDefinedConfig.then === 'function') {
|
|
17
16
|
userDefinedConfig = await userDefinedConfig;
|
|
18
17
|
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
:
|
|
18
|
+
const config = {};
|
|
19
|
+
const configOptions = {
|
|
20
|
+
...options,
|
|
21
|
+
target: options.target ?? 'web',
|
|
22
|
+
assets: options.assets ?? [],
|
|
23
|
+
root: context.root,
|
|
24
|
+
projectName: context.projectName,
|
|
25
|
+
targetName: context.targetName,
|
|
26
|
+
configurationName: context.configurationName,
|
|
27
|
+
projectGraph: context.projectGraph,
|
|
28
|
+
useLegacyHtmlPlugin: false,
|
|
29
|
+
};
|
|
30
|
+
(0, apply_base_config_1.applyBaseConfig)(configOptions, config);
|
|
31
|
+
if (options.target === 'web') {
|
|
32
|
+
(0, apply_web_config_1.applyWebConfig)(configOptions, config);
|
|
33
|
+
}
|
|
24
34
|
if (typeof userDefinedConfig === 'function' &&
|
|
25
35
|
((0, config_1.isNxRspackComposablePlugin)(userDefinedConfig) ||
|
|
26
36
|
!options.standardRspackConfigFunction)) {
|
|
@@ -7,7 +7,6 @@ const path_1 = require("path");
|
|
|
7
7
|
const generator_utils_1 = require("../../utils/generator-utils");
|
|
8
8
|
const init_1 = tslib_1.__importDefault(require("../init/init"));
|
|
9
9
|
const internal_1 = require("@nx/js/internal");
|
|
10
|
-
const deprecation_1 = require("../../utils/deprecation");
|
|
11
10
|
const assert_supported_rspack_version_1 = require("../../utils/assert-supported-rspack-version");
|
|
12
11
|
function projectIsRootProjectInStandaloneWorkspace(projectRoot) {
|
|
13
12
|
return (0, path_1.relative)(devkit_1.workspaceRoot, projectRoot).length === 0;
|
|
@@ -49,36 +48,28 @@ async function configurationGenerator(tree, options) {
|
|
|
49
48
|
const task = await (0, init_1.default)(tree, {
|
|
50
49
|
...options,
|
|
51
50
|
});
|
|
52
|
-
const { targets, root
|
|
51
|
+
const { targets, root } = (0, devkit_1.readProjectConfiguration)(tree, options.project);
|
|
53
52
|
const { target, framework } = (0, generator_utils_1.determineFrameworkAndTarget)(tree, options, root, targets);
|
|
54
53
|
options.framework = framework;
|
|
55
54
|
options.target = target;
|
|
56
55
|
let foundStylePreprocessorOptions;
|
|
57
56
|
let buildTargetName = 'build';
|
|
58
57
|
let serveTargetName = 'serve';
|
|
59
|
-
/**
|
|
60
|
-
* This is for when we are converting an existing project
|
|
61
|
-
* to use the vite executors.
|
|
62
|
-
*/
|
|
63
|
-
let projectAlreadyHasRspackTargets = {};
|
|
64
58
|
if (!options.newProject) {
|
|
65
59
|
const userProvidedTargetName = {
|
|
66
60
|
build: options.buildTarget,
|
|
67
61
|
serve: options.serveTarget,
|
|
68
62
|
};
|
|
69
63
|
const { validFoundTargetName, projectContainsUnsupportedExecutor, userProvidedTargetIsUnsupported, alreadyHasNxRspackTargets, } = (0, generator_utils_1.findExistingTargetsInProject)(targets, userProvidedTargetName);
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
(alreadyHasNxRspackTargets.serve ||
|
|
73
|
-
(0, internal_1.getProjectType)(tree, options.project, projectType) === 'library' ||
|
|
74
|
-
options.framework === 'nest')) {
|
|
75
|
-
throw new Error(`The project ${options.project} is already configured to use the @nx/rspack executors.
|
|
64
|
+
if (alreadyHasNxRspackTargets.build || alreadyHasNxRspackTargets.serve) {
|
|
65
|
+
throw new Error(`The project ${options.project} has targets using the removed @nx/rspack executors.
|
|
76
66
|
Please try a different project, or remove the existing targets
|
|
77
67
|
and re-run this generator to reset the existing Rspack Configuration.
|
|
78
68
|
`);
|
|
79
69
|
}
|
|
70
|
+
(0, generator_utils_1.assertNoRemovedExecutorTargets)(options.project, targets);
|
|
80
71
|
if (!validFoundTargetName.build && projectContainsUnsupportedExecutor) {
|
|
81
|
-
throw new Error(`The project ${options.project} cannot be converted to use
|
|
72
|
+
throw new Error(`The project ${options.project} cannot be converted to use Rspack.`);
|
|
82
73
|
}
|
|
83
74
|
if (!projectContainsUnsupportedExecutor &&
|
|
84
75
|
!validFoundTargetName.build &&
|
|
@@ -100,21 +91,6 @@ async function configurationGenerator(tree, options) {
|
|
|
100
91
|
(0, generator_utils_1.deleteWebpackConfig)(tree, root, targets?.[buildTargetName]?.options?.webpackConfig);
|
|
101
92
|
editTsConfig(tree, root, options.framework, (0, devkit_1.joinPathFragments)((0, devkit_1.offsetFromRoot)(root), 'tsconfig.base.json'));
|
|
102
93
|
}
|
|
103
|
-
const willScaffoldExecutorTargets = !projectAlreadyHasRspackTargets.build ||
|
|
104
|
-
((options.framework !== 'none' || options.devServer) &&
|
|
105
|
-
options.framework !== 'nest' &&
|
|
106
|
-
!projectAlreadyHasRspackTargets.serve);
|
|
107
|
-
if (willScaffoldExecutorTargets) {
|
|
108
|
-
(0, deprecation_1.warnRspackExecutorGenerating)();
|
|
109
|
-
}
|
|
110
|
-
if (!projectAlreadyHasRspackTargets.build) {
|
|
111
|
-
(0, generator_utils_1.addOrChangeBuildTarget)(tree, options, buildTargetName);
|
|
112
|
-
}
|
|
113
|
-
if ((options.framework !== 'none' || options.devServer) &&
|
|
114
|
-
options.framework !== 'nest' &&
|
|
115
|
-
!projectAlreadyHasRspackTargets.serve) {
|
|
116
|
-
(0, generator_utils_1.addOrChangeServeTarget)(tree, options, serveTargetName);
|
|
117
|
-
}
|
|
118
94
|
(0, generator_utils_1.writeRspackConfigFile)(tree, options, foundStylePreprocessorOptions);
|
|
119
95
|
await (0, devkit_1.formatFiles)(tree);
|
|
120
96
|
return task;
|
|
@@ -58,11 +58,11 @@
|
|
|
58
58
|
},
|
|
59
59
|
"buildTarget": {
|
|
60
60
|
"type": "string",
|
|
61
|
-
"description": "The build target of the project to
|
|
61
|
+
"description": "The existing build target of the project to convert to Rspack."
|
|
62
62
|
},
|
|
63
63
|
"serveTarget": {
|
|
64
64
|
"type": "string",
|
|
65
|
-
"description": "The serve target of the project to
|
|
65
|
+
"description": "The existing serve target of the project, used to check that it can be converted to Rspack."
|
|
66
66
|
},
|
|
67
67
|
"rootProject": {
|
|
68
68
|
"type": "boolean",
|
package/dist/src/generators/convert-config-to-rspack-plugin/convert-config-to-rspack-plugin.js
CHANGED
|
@@ -32,54 +32,30 @@ async function convertConfigToRspackPluginGenerator(tree, options) {
|
|
|
32
32
|
throw new Error(hasError);
|
|
33
33
|
}
|
|
34
34
|
const rspackConfigPath = currentTargetOptions?.rspackConfig || '';
|
|
35
|
-
if (rspackConfigPath &&
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
if (rspackOptions) {
|
|
42
|
-
parsedOptions = JSON.parse(preprocessText(rspackOptions.getText()));
|
|
43
|
-
parsedOptions = (0, normalize_path_options_1.normalizePathOptions)(project.root, parsedOptions);
|
|
44
|
-
}
|
|
45
|
-
target.options.standardRspackConfigFunction = true;
|
|
46
|
-
(0, devkit_1.updateProjectConfiguration)(tree, projectName, project);
|
|
47
|
-
const { dir, name, ext } = (0, path_1.parse)(rspackConfigPath);
|
|
48
|
-
tree.rename(rspackConfigPath, `${(0, devkit_1.joinPathFragments)(dir, `${name}.old${ext}`)}`);
|
|
49
|
-
tree.write(rspackConfigPath, (0, devkit_1.stripIndents) `
|
|
50
|
-
const { NxAppRspackPlugin } = require('@nx/rspack/app-plugin');
|
|
51
|
-
const { NxReactRspackPlugin } = require('@nx/rspack/react-plugin');
|
|
52
|
-
const { useLegacyNxPlugin } = require('@nx/rspack');
|
|
53
|
-
|
|
54
|
-
// This file was migrated using @nx/rspack:convert-config-to-rspack-plugin from your './rspack.config.old.js'
|
|
55
|
-
// Please check that the options here are correct as they were moved from the old rspack.config.js to this file.
|
|
56
|
-
const options = ${rspackOptions ? JSON.stringify(parsedOptions, null, 2) : '{}'};
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* @type{import('@rspack/core').RspackOptionsNormalized}
|
|
60
|
-
*/
|
|
61
|
-
module.exports = async () => ({
|
|
62
|
-
plugins: [
|
|
63
|
-
${rspackOptions
|
|
64
|
-
? 'new NxAppRspackPlugin(options)'
|
|
65
|
-
: 'new NxAppRspackPlugin()'},
|
|
66
|
-
${withReactConfig
|
|
67
|
-
? `new NxReactRspackPlugin(${withReactConfig.getText()})`
|
|
68
|
-
: `new NxReactRspackPlugin()`},
|
|
69
|
-
// NOTE: useLegacyNxPlugin ensures that the non-standard Rspack configuration file previously used still works.
|
|
70
|
-
// To remove its usage, move options such as "plugins" into this file as standard Rspack configuration options.
|
|
71
|
-
// To enhance configurations after Nx plugins have applied, you can add a new plugin with the \`apply\` method.
|
|
72
|
-
// e.g. \`{ apply: (compiler) => { /* modify compiler.options */ }\`
|
|
73
|
-
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
74
|
-
await useLegacyNxPlugin(require('./rspack.config.old'), options),
|
|
75
|
-
],
|
|
76
|
-
});
|
|
77
|
-
`);
|
|
78
|
-
migrated++;
|
|
79
|
-
}
|
|
35
|
+
if (rspackConfigPath &&
|
|
36
|
+
tree.exists(rspackConfigPath) &&
|
|
37
|
+
convertConfigFile(tree, project.root, rspackConfigPath)) {
|
|
38
|
+
target.options.standardRspackConfigFunction = true;
|
|
39
|
+
(0, devkit_1.updateProjectConfiguration)(tree, projectName, project);
|
|
40
|
+
migrated++;
|
|
80
41
|
}
|
|
81
42
|
}
|
|
82
43
|
});
|
|
44
|
+
// Projects already on the inference plugin keep their options in the config,
|
|
45
|
+
// so only the config needs converting.
|
|
46
|
+
for (const [projectName, project] of projects) {
|
|
47
|
+
if (options.project && projectName !== options.project) {
|
|
48
|
+
continue;
|
|
49
|
+
}
|
|
50
|
+
if (Object.values(project.targets ?? {}).some((target) => target.executor === '@nx/rspack:rspack')) {
|
|
51
|
+
continue;
|
|
52
|
+
}
|
|
53
|
+
const rspackConfigPath = (0, devkit_1.joinPathFragments)(project.root, 'rspack.config.js');
|
|
54
|
+
if (tree.exists(rspackConfigPath) &&
|
|
55
|
+
convertConfigFile(tree, project.root, rspackConfigPath)) {
|
|
56
|
+
migrated++;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
83
59
|
if (migrated === 0) {
|
|
84
60
|
throw new Error('Could not find any projects to migrate.');
|
|
85
61
|
}
|
|
@@ -87,4 +63,61 @@ async function convertConfigToRspackPluginGenerator(tree, options) {
|
|
|
87
63
|
await (0, devkit_1.formatFiles)(tree);
|
|
88
64
|
}
|
|
89
65
|
}
|
|
66
|
+
/** Returns whether the config used `withNx` and was converted. */
|
|
67
|
+
function convertConfigFile(tree, projectRoot, rspackConfigPath) {
|
|
68
|
+
let { withNxConfig: rspackOptions, withReactConfig, strippedSource, } = (0, extract_rspack_options_1.extractRspackOptions)(tree, rspackConfigPath);
|
|
69
|
+
// if rspackOptions === undefined
|
|
70
|
+
// withNx was not found in the rspack.config.js file so we should skip this project
|
|
71
|
+
if (rspackOptions !== undefined) {
|
|
72
|
+
let parsedOptions = {};
|
|
73
|
+
if (rspackOptions) {
|
|
74
|
+
// Parse before writing anything: a non-literal option value leaves the
|
|
75
|
+
// project untouched for the migration prompt instead of a config whose
|
|
76
|
+
// helper calls are gone and whose options never made it across.
|
|
77
|
+
try {
|
|
78
|
+
parsedOptions = JSON.parse(preprocessText(rspackOptions.getText()));
|
|
79
|
+
}
|
|
80
|
+
catch {
|
|
81
|
+
throw new Error(`Could not read the \`withNx\` options in ${rspackConfigPath}. They must be a plain object literal; spreads, variables and function calls are not supported.`);
|
|
82
|
+
}
|
|
83
|
+
parsedOptions = (0, normalize_path_options_1.normalizePathOptions)(projectRoot, parsedOptions);
|
|
84
|
+
}
|
|
85
|
+
if (strippedSource !== undefined) {
|
|
86
|
+
tree.write(rspackConfigPath, strippedSource);
|
|
87
|
+
}
|
|
88
|
+
const { dir, name, ext } = (0, path_1.parse)(rspackConfigPath);
|
|
89
|
+
tree.rename(rspackConfigPath, `${(0, devkit_1.joinPathFragments)(dir, `${name}.old${ext}`)}`);
|
|
90
|
+
tree.write(rspackConfigPath, (0, devkit_1.stripIndents) `
|
|
91
|
+
const { NxAppRspackPlugin } = require('@nx/rspack/app-plugin');
|
|
92
|
+
const { NxReactRspackPlugin } = require('@nx/rspack/react-plugin');
|
|
93
|
+
const { useLegacyNxPlugin } = require('@nx/rspack');
|
|
94
|
+
|
|
95
|
+
// This file was migrated using @nx/rspack:convert-config-to-rspack-plugin from your './rspack.config.old.js'
|
|
96
|
+
// Please check that the options here are correct as they were moved from the old rspack.config.js to this file.
|
|
97
|
+
const options = ${rspackOptions ? JSON.stringify(parsedOptions, null, 2) : '{}'};
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* @type{import('@rspack/core').RspackOptionsNormalized}
|
|
101
|
+
*/
|
|
102
|
+
module.exports = async () => ({
|
|
103
|
+
plugins: [
|
|
104
|
+
${rspackOptions
|
|
105
|
+
? 'new NxAppRspackPlugin(options)'
|
|
106
|
+
: 'new NxAppRspackPlugin()'},
|
|
107
|
+
${withReactConfig
|
|
108
|
+
? `new NxReactRspackPlugin(${withReactConfig.getText()})`
|
|
109
|
+
: `new NxReactRspackPlugin()`},
|
|
110
|
+
// NOTE: useLegacyNxPlugin ensures that the non-standard Rspack configuration file previously used still works.
|
|
111
|
+
// To remove its usage, move options such as "plugins" into this file as standard Rspack configuration options.
|
|
112
|
+
// To enhance configurations after Nx plugins have applied, you can add a new plugin with the \`apply\` method.
|
|
113
|
+
// e.g. \`{ apply: (compiler) => { /* modify compiler.options */ }\`
|
|
114
|
+
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
115
|
+
await useLegacyNxPlugin(require('./rspack.config.old'), options),
|
|
116
|
+
],
|
|
117
|
+
});
|
|
118
|
+
`);
|
|
119
|
+
return true;
|
|
120
|
+
}
|
|
121
|
+
return false;
|
|
122
|
+
}
|
|
90
123
|
exports.default = convertConfigToRspackPluginGenerator;
|
|
@@ -15,6 +15,9 @@ function extractRspackOptions(tree, rspackConfigPath) {
|
|
|
15
15
|
const withWebCall = (0, tsquery_1.query)(sourceFile, withWebQuery);
|
|
16
16
|
// If the config is empty set to empty string to avoid undefined. Undefined is used to check if the withNx exists inside of the config file.
|
|
17
17
|
let withNxConfig, withReactConfig;
|
|
18
|
+
// Returned rather than written here so the caller can reject configs whose
|
|
19
|
+
// options are not a plain literal before touching the file.
|
|
20
|
+
let strippedSource;
|
|
18
21
|
withWebCall.forEach((node) => {
|
|
19
22
|
const argument = node.arguments[0] || '';
|
|
20
23
|
withNxConfig = argument; // Since withWeb and withNx use the same config object and both should not exist in the same file, we can reuse the withNxConfig variable.
|
|
@@ -37,9 +40,35 @@ function extractRspackOptions(tree, rspackConfigPath) {
|
|
|
37
40
|
updatedSource = removeImportDeclarations(updatedSource, 'withNx', '@nx/rspack');
|
|
38
41
|
updatedSource = removeImportDeclarations(updatedSource, 'withWeb', '@nx/rspack');
|
|
39
42
|
updatedSource = removeImportDeclarations(updatedSource, 'withReact', '@nx/rspack');
|
|
40
|
-
|
|
43
|
+
updatedSource = inlineComposePlugins(updatedSource);
|
|
44
|
+
updatedSource = removeImportDeclarations(updatedSource, 'composePlugins', '@nx/rspack');
|
|
45
|
+
strippedSource = updatedSource;
|
|
41
46
|
}
|
|
42
|
-
return { withNxConfig, withReactConfig };
|
|
47
|
+
return { withNxConfig, withReactConfig, strippedSource };
|
|
48
|
+
}
|
|
49
|
+
// `composePlugins` is an inert stub since Nx v24, so the old config composes its
|
|
50
|
+
// remaining callbacks with a local copy.
|
|
51
|
+
function inlineComposePlugins(source) {
|
|
52
|
+
let found = false;
|
|
53
|
+
const updatedSource = (0, tsquery_1.replace)(source, 'CallExpression > Identifier[name="composePlugins"]', (node) => {
|
|
54
|
+
if (node.parent.expression !== node) {
|
|
55
|
+
return node.getText();
|
|
56
|
+
}
|
|
57
|
+
found = true;
|
|
58
|
+
return 'composeLegacyPlugins';
|
|
59
|
+
});
|
|
60
|
+
if (!found)
|
|
61
|
+
return source;
|
|
62
|
+
return `${updatedSource}
|
|
63
|
+
function composeLegacyPlugins(...plugins) {
|
|
64
|
+
return async (config, ctx) => {
|
|
65
|
+
for (const plugin of plugins) {
|
|
66
|
+
config = await (await plugin)(config, ctx);
|
|
67
|
+
}
|
|
68
|
+
return config;
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
`;
|
|
43
72
|
}
|
|
44
73
|
function removeCallExpressions(source, functionNames) {
|
|
45
74
|
let modifiedSource = source;
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://json-schema.org/schema",
|
|
3
3
|
"$id": "NxRspackConvertConfigToRspackPlugin",
|
|
4
|
-
"description": "Convert existing Rspack
|
|
4
|
+
"description": "Convert existing Rspack config(s) that use `withNx` to use `NxAppRspackPlugin`, for projects on the `@nx/rspack:rspack` executor or the `@nx/rspack/plugin` inference plugin. Defaults to migrating all projects. Pass '--project' to migrate only one target.",
|
|
5
5
|
"title": "Convert Rspack project using withNx to NxAppRspackPlugin",
|
|
6
6
|
"type": "object",
|
|
7
7
|
"properties": {
|
|
8
8
|
"project": {
|
|
9
9
|
"type": "string",
|
|
10
|
-
"description": "The project to convert from
|
|
10
|
+
"description": "The project whose rspack config to convert from the `withNx` plugin to `NxAppRspackPlugin`.",
|
|
11
11
|
"x-priority": "important"
|
|
12
12
|
},
|
|
13
13
|
"skipFormat": {
|
|
@@ -41,7 +41,7 @@ async function convertToInferred(tree, options) {
|
|
|
41
41
|
const convertMessage = [...logger.loggedMessages.values()]
|
|
42
42
|
.flat()
|
|
43
43
|
.find((v) => v.includes('@nx/rspack:convert-config-to-rspack-plugin'));
|
|
44
|
-
if (convertMessage
|
|
44
|
+
if (convertMessage?.length > 0) {
|
|
45
45
|
logger.flushLogs((message) => !convertMessage.includes(message));
|
|
46
46
|
throw new Error(convertMessage);
|
|
47
47
|
}
|
|
@@ -63,9 +63,10 @@ async function convertToInferred(tree, options) {
|
|
|
63
63
|
if (!options.skipFormat) {
|
|
64
64
|
await (0, devkit_1.formatFiles)(tree);
|
|
65
65
|
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
66
|
+
// Flushed now rather than in the callback so remove-deprecated-executors, which
|
|
67
|
+
// skips the install callback, still prints these.
|
|
68
|
+
migrationContext.logger.flushLogs();
|
|
69
|
+
return installCallback;
|
|
69
70
|
}
|
|
70
71
|
function skipProjectFilterFactory(tree) {
|
|
71
72
|
return function skipProjectFilter(projectConfiguration) {
|
|
@@ -117,9 +117,17 @@ function updateRspackConfig(tree, rspackConfig, pluginOptions) {
|
|
|
117
117
|
function setOptionsInRspackConfig(tree, text, sourceFile, rspackConfig, pluginOptions) {
|
|
118
118
|
const { default: defaultOptions, ...configurationOptions } = pluginOptions;
|
|
119
119
|
const optionsSelector = 'VariableStatement:has(VariableDeclaration:has(Identifier[name=options]))';
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
120
|
+
let optionsVariable = (0, tsquery_1.query)(sourceFile, optionsSelector)[0];
|
|
121
|
+
if (!optionsVariable) {
|
|
122
|
+
const plugin = (0, tsquery_1.query)(sourceFile, 'NewExpression:has(Identifier[name=NxAppRspackPlugin])')[0];
|
|
123
|
+
const argument = plugin.arguments?.[0];
|
|
124
|
+
if (argument && !ts.isObjectLiteralExpression(argument)) {
|
|
125
|
+
throw new Error('Move NxAppRspackPlugin options into an object literal before converting this config.');
|
|
126
|
+
}
|
|
127
|
+
text = `const options = ${argument?.getText(sourceFile) ?? '{}'};\n${text}`;
|
|
128
|
+
sourceFile = (0, tsquery_1.ast)(text);
|
|
129
|
+
optionsVariable = (0, tsquery_1.query)(sourceFile, optionsSelector)[0];
|
|
130
|
+
}
|
|
123
131
|
let defaultOptionsObject;
|
|
124
132
|
const optionsObject = (0, tsquery_1.query)(optionsVariable, 'ObjectLiteralExpression')[0];
|
|
125
133
|
if (optionsObject.properties.length === 0) {
|
|
@@ -187,8 +195,8 @@ function setOptionsInNxRspackPlugin(tree, text, sourceFile, rspackConfig) {
|
|
|
187
195
|
function setOptionsInLegacyNxPlugin(tree, text, sourceFile, rspackConfig) {
|
|
188
196
|
const legacyNxPluginSelector = 'AwaitExpression CallExpression:has(Identifier[name=useLegacyNxPlugin])';
|
|
189
197
|
const legacyNxPlugin = (0, tsquery_1.query)(sourceFile, legacyNxPluginSelector)[0];
|
|
190
|
-
|
|
191
|
-
|
|
198
|
+
if (!legacyNxPlugin)
|
|
199
|
+
return;
|
|
192
200
|
const updatedLegacyNxPlugin = ts.factory.updateCallExpression(legacyNxPlugin, legacyNxPlugin.expression, undefined, [legacyNxPlugin.arguments[0], ts.factory.createIdentifier('buildOptions')]);
|
|
193
201
|
text = `${text.slice(0, legacyNxPlugin.getStart())}${ts
|
|
194
202
|
.createPrinter()
|
|
@@ -16,7 +16,7 @@ function servePostTargetTransformerFactory(migrationContext) {
|
|
|
16
16
|
projectName: projectDetails.projectName,
|
|
17
17
|
projectRoot: projectDetails.root,
|
|
18
18
|
};
|
|
19
|
-
const { devServerOptions, rspackConfigPath } = await processOptions(
|
|
19
|
+
const { devServerOptions, rspackConfigPath } = await processOptions(target, context);
|
|
20
20
|
updateRspackConfig(tree, rspackConfigPath, devServerOptions, context);
|
|
21
21
|
if (target.outputs) {
|
|
22
22
|
(0, internal_1.processTargetOutputs)(target, [], inferredTarget, {
|
|
@@ -27,20 +27,14 @@ function servePostTargetTransformerFactory(migrationContext) {
|
|
|
27
27
|
return target;
|
|
28
28
|
};
|
|
29
29
|
}
|
|
30
|
-
async function processOptions(
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
acc.projects[projectName] = project.data;
|
|
38
|
-
return acc;
|
|
39
|
-
}, { version: 1, projects: {} }),
|
|
40
|
-
root: context.workspaceRoot,
|
|
30
|
+
async function processOptions(target, context) {
|
|
31
|
+
const buildTarget = (0, devkit_1.parseTargetString)(target.options.buildTarget, context.projectGraph);
|
|
32
|
+
const buildConfiguration = context.projectGraph.nodes[buildTarget.project].data.targets[buildTarget.target];
|
|
33
|
+
// The build executor is removed in v24; do not resolve its schema.
|
|
34
|
+
const buildOptions = {
|
|
35
|
+
...buildConfiguration.options,
|
|
36
|
+
...buildConfiguration.configurations?.[buildTarget.configuration ?? buildConfiguration.defaultConfiguration],
|
|
41
37
|
};
|
|
42
|
-
const buildTarget = (0, devkit_1.parseTargetString)(target.options.buildTarget, executorContext);
|
|
43
|
-
const buildOptions = (0, devkit_1.readTargetOptions)(buildTarget, executorContext);
|
|
44
38
|
// it must exist, we validated it in the project filter
|
|
45
39
|
const rspackConfigPath = buildOptions.rspackConfig;
|
|
46
40
|
const defaultOptions = extractDevServerOptions(target.options, context);
|
|
@@ -3,8 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.default = default_1;
|
|
4
4
|
const devkit_1 = require("@nx/devkit");
|
|
5
5
|
const versions_1 = require("../../utils/versions");
|
|
6
|
-
const transform_esm_1 = require("./lib/transform-esm");
|
|
7
|
-
const transform_cjs_1 = require("./lib/transform-cjs");
|
|
8
6
|
const transform_plugin_config_1 = require("./lib/transform-plugin-config");
|
|
9
7
|
const assert_supported_rspack_version_1 = require("../../utils/assert-supported-rspack-version");
|
|
10
8
|
async function default_1(tree, options) {
|
|
@@ -14,36 +12,19 @@ async function default_1(tree, options) {
|
|
|
14
12
|
throw new Error(`Could not find project '${options.project}'. Ensure you have specified the project you'd like to convert correctly.`);
|
|
15
13
|
}
|
|
16
14
|
const project = projects.get(options.project);
|
|
17
|
-
|
|
15
|
+
if (usesModuleFederation(tree, project)) {
|
|
16
|
+
throw new Error(`The project ${options.project} is using Module Federation. At the moment, we don't support migrating projects that use Module Federation. See https://nx.dev/docs/kb/migrate-from-nx-module-federation to move it to the official Module Federation plugins.`);
|
|
17
|
+
}
|
|
18
|
+
if (Object.values(project.targets ?? {}).some((target) => [
|
|
19
|
+
'@nx/webpack:webpack',
|
|
20
|
+
'@nx/webpack:dev-server',
|
|
21
|
+
'@nx/webpack:ssr-dev-server',
|
|
22
|
+
].includes(target.executor))) {
|
|
23
|
+
throw new Error('Migrate this project to @nx/webpack/plugin before converting it to Rspack.');
|
|
24
|
+
}
|
|
18
25
|
const webpackConfigsWithPluginsToConvert = [];
|
|
19
|
-
for (const
|
|
20
|
-
if (target.executor === '
|
|
21
|
-
target.executor = '@nx/rspack:rspack';
|
|
22
|
-
if (!target.options.target) {
|
|
23
|
-
target.options.target = 'web';
|
|
24
|
-
}
|
|
25
|
-
const convertWebpackConfigOption = (options) => {
|
|
26
|
-
if (!options.webpackConfig) {
|
|
27
|
-
return;
|
|
28
|
-
}
|
|
29
|
-
const rspackConfigPath = options.webpackConfig.replace(/webpack(?!.*webpack)/, 'rspack');
|
|
30
|
-
webpackConfigsWithHelpersToConvert.push([
|
|
31
|
-
options.webpackConfig,
|
|
32
|
-
rspackConfigPath,
|
|
33
|
-
]);
|
|
34
|
-
options.rspackConfig = rspackConfigPath;
|
|
35
|
-
delete options.webpackConfig;
|
|
36
|
-
};
|
|
37
|
-
if (target.options.webpackConfig) {
|
|
38
|
-
convertWebpackConfigOption(target.options);
|
|
39
|
-
}
|
|
40
|
-
if (target.configurations) {
|
|
41
|
-
for (const [configurationName, configuration] of Object.entries(target.configurations)) {
|
|
42
|
-
convertWebpackConfigOption(configuration);
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
else if ((target.executor === 'nx:run-commands' && target.options.command) ||
|
|
26
|
+
for (const target of Object.values(project.targets ?? {})) {
|
|
27
|
+
if ((target.executor === 'nx:run-commands' && target.options.command) ||
|
|
47
28
|
target.command === 'webpack-cli build') {
|
|
48
29
|
if (target.options?.command) {
|
|
49
30
|
target.options.command = 'rspack build';
|
|
@@ -59,24 +40,8 @@ async function default_1(tree, options) {
|
|
|
59
40
|
]);
|
|
60
41
|
}
|
|
61
42
|
}
|
|
62
|
-
else if (target.executor === '@nx/webpack:dev-server') {
|
|
63
|
-
target.executor = '@nx/rspack:dev-server';
|
|
64
|
-
}
|
|
65
|
-
else if (target.executor === '@nx/webpack:ssr-dev-server') {
|
|
66
|
-
target.executor = '@nx/rspack:dev-server';
|
|
67
|
-
}
|
|
68
|
-
else if (target.executor === '@nx/react:module-federation-dev-server') {
|
|
69
|
-
target.executor = '@nx/rspack:module-federation-dev-server';
|
|
70
|
-
}
|
|
71
|
-
else if (target.executor === '@nx/react:module-federation-ssr-dev-server') {
|
|
72
|
-
target.executor = '@nx/rspack:module-federation-ssr-dev-server';
|
|
73
|
-
}
|
|
74
|
-
else if (target.executor === '@nx/react:module-federation-static-server') {
|
|
75
|
-
target.executor = '@nx/rspack:module-federation-static-server';
|
|
76
|
-
}
|
|
77
43
|
}
|
|
78
|
-
if (
|
|
79
|
-
webpackConfigsWithPluginsToConvert.length === 0) {
|
|
44
|
+
if (webpackConfigsWithPluginsToConvert.length === 0) {
|
|
80
45
|
// Projects built by the inferred @nx/webpack/plugin target have no
|
|
81
46
|
// explicit webpack target to match, only a config file.
|
|
82
47
|
const webpackConfigPath = findWebpackConfigPath(tree, project.root);
|
|
@@ -87,15 +52,10 @@ async function default_1(tree, options) {
|
|
|
87
52
|
]);
|
|
88
53
|
}
|
|
89
54
|
}
|
|
90
|
-
if (
|
|
91
|
-
webpackConfigsWithPluginsToConvert.length === 0) {
|
|
55
|
+
if (webpackConfigsWithPluginsToConvert.length === 0) {
|
|
92
56
|
console.error(`Project '${options.project}' does not have any webpack targets to convert.`);
|
|
93
57
|
return;
|
|
94
58
|
}
|
|
95
|
-
for (const [webpackConfigPath, rspackConfigPath,] of webpackConfigsWithHelpersToConvert) {
|
|
96
|
-
tree.rename(webpackConfigPath, rspackConfigPath);
|
|
97
|
-
transformConfigFileWithHelpers(tree, rspackConfigPath);
|
|
98
|
-
}
|
|
99
59
|
for (const [webpackConfigPath, rspackConfigPath,] of webpackConfigsWithPluginsToConvert) {
|
|
100
60
|
tree.rename(webpackConfigPath, rspackConfigPath);
|
|
101
61
|
transformConfigFileWithPlugins(tree, rspackConfigPath);
|
|
@@ -141,26 +101,6 @@ async function default_1(tree, options) {
|
|
|
141
101
|
function transformConfigFileWithPlugins(tree, configPath) {
|
|
142
102
|
(0, transform_plugin_config_1.transformPluginConfig)(tree, configPath);
|
|
143
103
|
}
|
|
144
|
-
function transformConfigFileWithHelpers(tree, configPath) {
|
|
145
|
-
(0, transform_esm_1.transformEsmConfigFile)(tree, configPath);
|
|
146
|
-
(0, transform_cjs_1.transformCjsConfigFile)(tree, configPath);
|
|
147
|
-
cleanupEmptyImports(tree, configPath);
|
|
148
|
-
replaceOfRequireOfLocalWebpackConfig(tree, configPath);
|
|
149
|
-
}
|
|
150
|
-
function replaceOfRequireOfLocalWebpackConfig(tree, configPath) {
|
|
151
|
-
const requireOfLocalWebpackConfig = /(?<=require\s*\(\s*['"][^'"]*)(webpack)(?!.*webpack)(?=[^'"]*['"]\s*\))/g;
|
|
152
|
-
const configContents = tree.read(configPath, 'utf-8');
|
|
153
|
-
const newContents = configContents.replace(requireOfLocalWebpackConfig, 'rspack');
|
|
154
|
-
tree.write(configPath, newContents);
|
|
155
|
-
}
|
|
156
|
-
function cleanupEmptyImports(tree, configPath) {
|
|
157
|
-
const emptyImportRegex = /import\s*\{\s*\}\s*from\s*['"][^'"]+['"];/g;
|
|
158
|
-
const emptyConstRequires = /(const|let)\s*\{\s*\}\s*=\s*require\s*\(\s*['"][^'"]+['"]\s*\);/g;
|
|
159
|
-
const configContents = tree.read(configPath, 'utf-8');
|
|
160
|
-
let newContents = configContents.replace(emptyImportRegex, '');
|
|
161
|
-
newContents = newContents.replace(emptyConstRequires, '');
|
|
162
|
-
tree.write(configPath, newContents);
|
|
163
|
-
}
|
|
164
104
|
function findWebpackConfigPath(tree, projectRoot) {
|
|
165
105
|
const possibleConfigPaths = [
|
|
166
106
|
'webpack.config.js',
|
|
@@ -177,3 +117,9 @@ function findWebpackConfigPath(tree, projectRoot) {
|
|
|
177
117
|
}
|
|
178
118
|
}
|
|
179
119
|
}
|
|
120
|
+
function usesModuleFederation(tree, project) {
|
|
121
|
+
if (Object.values(project.targets ?? {}).some((target) => target.executor?.includes(':module-federation-'))) {
|
|
122
|
+
return true;
|
|
123
|
+
}
|
|
124
|
+
return ['ts', 'js', 'mjs', 'cjs', 'mts', 'cts'].some((ext) => tree.exists((0, devkit_1.joinPathFragments)(project.root, `module-federation.config.${ext}`)));
|
|
125
|
+
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { type Tree } from '@nx/devkit';
|
|
2
|
-
export declare function transformPluginConfig(tree: Tree,
|
|
2
|
+
export declare function transformPluginConfig(tree: Tree, configPath: string): void;
|