@nx/rspack 0.0.0-pr-28544-bc43ecf → 0.0.0-pr-28595-c849fba
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/generators.json +5 -0
- package/package.json +4 -4
- package/src/generators/convert-webpack/convert-webpack.d.ts +3 -0
- package/src/generators/convert-webpack/convert-webpack.js +88 -0
- package/src/generators/convert-webpack/lib/transform-cjs.d.ts +2 -0
- package/src/generators/convert-webpack/lib/transform-cjs.js +169 -0
- package/src/generators/convert-webpack/lib/transform-esm.d.ts +2 -0
- package/src/generators/convert-webpack/lib/transform-esm.js +169 -0
- package/src/generators/convert-webpack/schema.d.ts +4 -0
- package/src/generators/convert-webpack/schema.json +26 -0
- package/src/utils/versions.d.ts +1 -0
- package/src/utils/versions.js +2 -1
package/generators.json
CHANGED
|
@@ -26,6 +26,11 @@
|
|
|
26
26
|
"aliases": ["app"],
|
|
27
27
|
"x-type": "application",
|
|
28
28
|
"description": "React application generator."
|
|
29
|
+
},
|
|
30
|
+
"convert-webpack": {
|
|
31
|
+
"factory": "./src/generators/convert-webpack/convert-webpack",
|
|
32
|
+
"schema": "./src/generators/convert-webpack/schema.json",
|
|
33
|
+
"description": "Convert a webpack application to use rspack."
|
|
29
34
|
}
|
|
30
35
|
}
|
|
31
36
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nx/rspack",
|
|
3
3
|
"description": "The Nx Plugin for Rspack contains executors and generators that support building applications using Rspack.",
|
|
4
|
-
"version": "0.0.0-pr-
|
|
4
|
+
"version": "0.0.0-pr-28595-c849fba",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
@@ -24,9 +24,9 @@
|
|
|
24
24
|
"generators": "./generators.json",
|
|
25
25
|
"executors": "./executors.json",
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@nx/js": "0.0.0-pr-
|
|
28
|
-
"@nx/devkit": "0.0.0-pr-
|
|
29
|
-
"@nx/web": "0.0.0-pr-
|
|
27
|
+
"@nx/js": "0.0.0-pr-28595-c849fba",
|
|
28
|
+
"@nx/devkit": "0.0.0-pr-28595-c849fba",
|
|
29
|
+
"@nx/web": "0.0.0-pr-28595-c849fba",
|
|
30
30
|
"@phenomnomnominal/tsquery": "~5.0.1",
|
|
31
31
|
"enquirer": "~2.3.6",
|
|
32
32
|
"express": "^4.19.2",
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = default_1;
|
|
4
|
+
const devkit_1 = require("@nx/devkit");
|
|
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
|
+
async function default_1(tree, options) {
|
|
9
|
+
const projects = (0, devkit_1.getProjects)(tree);
|
|
10
|
+
if (!projects.has(options.project)) {
|
|
11
|
+
throw new Error(`Could not find project '${options.project}'. Ensure you have specified the project you'd like to convert correctly.`);
|
|
12
|
+
}
|
|
13
|
+
const project = projects.get(options.project);
|
|
14
|
+
const webpackConfigsToConvert = [];
|
|
15
|
+
for (const [targetName, target] of Object.entries(project.targets)) {
|
|
16
|
+
if (target.executor === '@nx/webpack:webpack') {
|
|
17
|
+
target.executor = '@nx/rspack:rspack';
|
|
18
|
+
if (!target.options.target) {
|
|
19
|
+
target.options.target = 'web';
|
|
20
|
+
}
|
|
21
|
+
const convertWebpackConfigOption = (options) => {
|
|
22
|
+
if (!options.webpackConfig) {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
const rspackConfigPath = options.webpackConfig.replace(/webpack(?!.*webpack)/, 'rspack');
|
|
26
|
+
webpackConfigsToConvert.push([options.webpackConfig, rspackConfigPath]);
|
|
27
|
+
options.rspackConfig = rspackConfigPath;
|
|
28
|
+
delete options.webpackConfig;
|
|
29
|
+
};
|
|
30
|
+
if (target.options.webpackConfig) {
|
|
31
|
+
convertWebpackConfigOption(target.options);
|
|
32
|
+
}
|
|
33
|
+
if (target.configurations) {
|
|
34
|
+
for (const [configurationName, configuration] of Object.entries(target.configurations)) {
|
|
35
|
+
convertWebpackConfigOption(configuration);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
else if (target.executor === '@nx/webpack:dev-server') {
|
|
40
|
+
target.executor = '@nx/rspack:dev-server';
|
|
41
|
+
}
|
|
42
|
+
else if (target.executor === '@nx/webpack:ssr-dev-server') {
|
|
43
|
+
target.executor = '@nx/rspack:dev-server';
|
|
44
|
+
}
|
|
45
|
+
else if (target.executor === '@nx/react:module-federation-dev-server') {
|
|
46
|
+
target.executor = '@nx/rspack:module-federation-dev-server';
|
|
47
|
+
}
|
|
48
|
+
else if (target.executor === '@nx/react:module-federation-ssr-dev-server') {
|
|
49
|
+
target.executor = '@nx/rspack:module-federation-ssr-dev-server';
|
|
50
|
+
}
|
|
51
|
+
else if (target.executor === '@nx/react:module-federation-static-server') {
|
|
52
|
+
target.executor = '@nx/rspack:module-federation-static-server';
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
for (const [webpackConfigPath, rspackConfigPath] of webpackConfigsToConvert) {
|
|
56
|
+
tree.rename(webpackConfigPath, rspackConfigPath);
|
|
57
|
+
transformConfigFile(tree, rspackConfigPath);
|
|
58
|
+
}
|
|
59
|
+
(0, devkit_1.updateProjectConfiguration)(tree, options.project, project);
|
|
60
|
+
const installTask = (0, devkit_1.addDependenciesToPackageJson)(tree, {}, {
|
|
61
|
+
'@rspack/core': versions_1.rspackCoreVersion,
|
|
62
|
+
'@rspack/dev-server': versions_1.rspackDevServerVersion,
|
|
63
|
+
});
|
|
64
|
+
if (!options.skipFormat) {
|
|
65
|
+
await (0, devkit_1.formatFiles)(tree);
|
|
66
|
+
}
|
|
67
|
+
return installTask;
|
|
68
|
+
}
|
|
69
|
+
function transformConfigFile(tree, configPath) {
|
|
70
|
+
(0, transform_esm_1.transformEsmConfigFile)(tree, configPath);
|
|
71
|
+
(0, transform_cjs_1.transformCjsConfigFile)(tree, configPath);
|
|
72
|
+
cleanupEmptyImports(tree, configPath);
|
|
73
|
+
replaceOfRequireOfLocalWebpackConfig(tree, configPath);
|
|
74
|
+
}
|
|
75
|
+
function replaceOfRequireOfLocalWebpackConfig(tree, configPath) {
|
|
76
|
+
const requireOfLocalWebpackConfig = /(?<=require\s*\(\s*['"][^'"]*)(webpack)(?!.*webpack)(?=[^'"]*['"]\s*\))/g;
|
|
77
|
+
const configContents = tree.read(configPath, 'utf-8');
|
|
78
|
+
const newContents = configContents.replace(requireOfLocalWebpackConfig, 'rspack');
|
|
79
|
+
tree.write(configPath, newContents);
|
|
80
|
+
}
|
|
81
|
+
function cleanupEmptyImports(tree, configPath) {
|
|
82
|
+
const emptyImportRegex = /import\s*\{\s*\}\s*from\s*['"][^'"]+['"];/g;
|
|
83
|
+
const emptyConstRequires = /(const|let)\s*\{\s*\}\s*=\s*require\s*\(\s*['"][^'"]+['"]\s*\);/g;
|
|
84
|
+
const configContents = tree.read(configPath, 'utf-8');
|
|
85
|
+
let newContents = configContents.replace(emptyImportRegex, '');
|
|
86
|
+
newContents = newContents.replace(emptyConstRequires, '');
|
|
87
|
+
tree.write(configPath, newContents);
|
|
88
|
+
}
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.transformCjsConfigFile = transformCjsConfigFile;
|
|
4
|
+
const tsquery_1 = require("@phenomnomnominal/tsquery");
|
|
5
|
+
function transformCjsConfigFile(tree, configPath) {
|
|
6
|
+
['@nx', '@nrwl'].forEach((scope) => {
|
|
7
|
+
transformComposePlugins(tree, configPath, scope);
|
|
8
|
+
transformWithNx(tree, configPath, scope);
|
|
9
|
+
transformWithWeb(tree, configPath, scope);
|
|
10
|
+
transformWithReact(tree, configPath, scope);
|
|
11
|
+
transformModuleFederationConfig(tree, configPath, scope);
|
|
12
|
+
transformWithModuleFederation(tree, configPath, scope);
|
|
13
|
+
transformWithModuleFederationSSR(tree, configPath, scope);
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
function transformComposePlugins(tree, configPath, scope) {
|
|
17
|
+
const configContents = tree.read(configPath, 'utf-8');
|
|
18
|
+
const ast = tsquery_1.tsquery.ast(configContents);
|
|
19
|
+
const HAS_COMPOSE_PLUGINS_FROM_NX_WEBPACK = `VariableDeclaration:has(Identifier[name=composePlugins]) > CallExpression:has(Identifier[name=require]) StringLiteral[value=${scope}/webpack]`;
|
|
20
|
+
const nodes = (0, tsquery_1.tsquery)(ast, HAS_COMPOSE_PLUGINS_FROM_NX_WEBPACK);
|
|
21
|
+
if (nodes.length === 0) {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
const COMPOSE_PLUGINS_IMPORT = 'VariableDeclaration:has(Identifier[name=composePlugins]) Identifier[name=composePlugins]';
|
|
25
|
+
const composePluginsNodes = (0, tsquery_1.tsquery)(ast, COMPOSE_PLUGINS_IMPORT);
|
|
26
|
+
if (nodes.length === 0) {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
const startIndex = composePluginsNodes[0].getStart();
|
|
30
|
+
let endIndex = composePluginsNodes[0].getEnd();
|
|
31
|
+
if (configContents.charAt(endIndex) === ',') {
|
|
32
|
+
endIndex++;
|
|
33
|
+
}
|
|
34
|
+
const newContents = `const { composePlugins } = require('@nx/rspack');
|
|
35
|
+
${configContents.slice(0, startIndex)}${configContents.slice(endIndex)}`;
|
|
36
|
+
tree.write(configPath, newContents);
|
|
37
|
+
}
|
|
38
|
+
function transformWithNx(tree, configPath, scope) {
|
|
39
|
+
const configContents = tree.read(configPath, 'utf-8');
|
|
40
|
+
const ast = tsquery_1.tsquery.ast(configContents);
|
|
41
|
+
const HAS_WITH_NX_FROM_NX_WEBPACK = `VariableDeclaration:has(Identifier[name=withNx]) > CallExpression:has(Identifier[name=require]) StringLiteral[value=${scope}/webpack]`;
|
|
42
|
+
const nodes = (0, tsquery_1.tsquery)(ast, HAS_WITH_NX_FROM_NX_WEBPACK);
|
|
43
|
+
if (nodes.length === 0) {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
const WITH_NX_IMPORT = 'VariableDeclaration:has(Identifier[name=withNx]) Identifier[name=withNx]';
|
|
47
|
+
const withNxNodes = (0, tsquery_1.tsquery)(ast, WITH_NX_IMPORT);
|
|
48
|
+
if (nodes.length === 0) {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
const startIndex = withNxNodes[0].getStart();
|
|
52
|
+
let endIndex = withNxNodes[0].getEnd();
|
|
53
|
+
if (configContents.charAt(endIndex) === ',') {
|
|
54
|
+
endIndex++;
|
|
55
|
+
}
|
|
56
|
+
const newContents = `const { withNx } = require('@nx/rspack');
|
|
57
|
+
${configContents.slice(0, startIndex)}${configContents.slice(endIndex)}`;
|
|
58
|
+
tree.write(configPath, newContents);
|
|
59
|
+
}
|
|
60
|
+
function transformWithWeb(tree, configPath, scope) {
|
|
61
|
+
const configContents = tree.read(configPath, 'utf-8');
|
|
62
|
+
const ast = tsquery_1.tsquery.ast(configContents);
|
|
63
|
+
const HAS_WITH_WEB_FROM_NX_WEBPACK = `VariableDeclaration:has(Identifier[name=withWeb]) > CallExpression:has(Identifier[name=require]) StringLiteral[value=${scope}/webpack]`;
|
|
64
|
+
const nodes = (0, tsquery_1.tsquery)(ast, HAS_WITH_WEB_FROM_NX_WEBPACK);
|
|
65
|
+
if (nodes.length === 0) {
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
const WITH_WEB_IMPORT = 'VariableDeclaration:has(Identifier[name=withWeb]) Identifier[name=withWeb]';
|
|
69
|
+
const withWebNodes = (0, tsquery_1.tsquery)(ast, WITH_WEB_IMPORT);
|
|
70
|
+
if (nodes.length === 0) {
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
const startIndex = withWebNodes[0].getStart();
|
|
74
|
+
let endIndex = withWebNodes[0].getEnd();
|
|
75
|
+
if (configContents.charAt(endIndex) === ',') {
|
|
76
|
+
endIndex++;
|
|
77
|
+
}
|
|
78
|
+
const newContents = `const { withWeb } = require('@nx/rspack');
|
|
79
|
+
${configContents.slice(0, startIndex)}${configContents.slice(endIndex)}`;
|
|
80
|
+
tree.write(configPath, newContents);
|
|
81
|
+
}
|
|
82
|
+
function transformWithReact(tree, configPath, scope) {
|
|
83
|
+
const configContents = tree.read(configPath, 'utf-8');
|
|
84
|
+
const ast = tsquery_1.tsquery.ast(configContents);
|
|
85
|
+
const HAS_WITH_REACT_FROM_NX_REACT = `VariableDeclaration:has(Identifier[name=withReact]) > CallExpression:has(Identifier[name=require]) StringLiteral[value=${scope}/react]`;
|
|
86
|
+
const nodes = (0, tsquery_1.tsquery)(ast, HAS_WITH_REACT_FROM_NX_REACT);
|
|
87
|
+
if (nodes.length === 0) {
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
const WITH_REACT_IMPORT = 'VariableDeclaration:has(Identifier[name=withReact]) Identifier[name=withReact]';
|
|
91
|
+
const withReactNodes = (0, tsquery_1.tsquery)(ast, WITH_REACT_IMPORT);
|
|
92
|
+
if (nodes.length === 0) {
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
const startIndex = withReactNodes[0].getStart();
|
|
96
|
+
let endIndex = withReactNodes[0].getEnd();
|
|
97
|
+
if (configContents.charAt(endIndex) === ',') {
|
|
98
|
+
endIndex++;
|
|
99
|
+
}
|
|
100
|
+
const newContents = `const { withReact } = require('@nx/rspack');
|
|
101
|
+
${configContents.slice(0, startIndex)}${configContents.slice(endIndex)}`;
|
|
102
|
+
tree.write(configPath, newContents);
|
|
103
|
+
}
|
|
104
|
+
function transformModuleFederationConfig(tree, configPath, scope) {
|
|
105
|
+
const configContents = tree.read(configPath, 'utf-8');
|
|
106
|
+
const ast = tsquery_1.tsquery.ast(configContents);
|
|
107
|
+
const HAS_WITH_MODULE_FEDERATION_FROM_NX_REACT = `VariableDeclaration:has(Identifier[name=ModuleFederationConfig]) > CallExpression:has(Identifier[name=require]) StringLiteral[value=${scope}/webpack]`;
|
|
108
|
+
const nodes = (0, tsquery_1.tsquery)(ast, HAS_WITH_MODULE_FEDERATION_FROM_NX_REACT);
|
|
109
|
+
if (nodes.length === 0) {
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
const WITH_MODULE_FEDERATION_IMPORT = 'VariableDeclaration:has(Identifier[name=ModuleFederationConfig]) Identifier[name=ModuleFederationConfig]';
|
|
113
|
+
const withModuleFederationNodes = (0, tsquery_1.tsquery)(ast, WITH_MODULE_FEDERATION_IMPORT);
|
|
114
|
+
if (nodes.length === 0) {
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
const startIndex = withModuleFederationNodes[0].getStart();
|
|
118
|
+
let endIndex = withModuleFederationNodes[0].getEnd();
|
|
119
|
+
if (configContents.charAt(endIndex) === ',') {
|
|
120
|
+
endIndex++;
|
|
121
|
+
}
|
|
122
|
+
const newContents = `const { ModuleFederationConfig } = require('@nx/rspack/module-federation');
|
|
123
|
+
${configContents.slice(0, startIndex)}${configContents.slice(endIndex)}`;
|
|
124
|
+
tree.write(configPath, newContents);
|
|
125
|
+
}
|
|
126
|
+
function transformWithModuleFederation(tree, configPath, scope) {
|
|
127
|
+
const configContents = tree.read(configPath, 'utf-8');
|
|
128
|
+
const ast = tsquery_1.tsquery.ast(configContents);
|
|
129
|
+
const HAS_WITH_MODULE_FEDERATION_FROM_NX_REACT = `VariableDeclaration:has(Identifier[name=withModuleFederation]) > CallExpression:has(Identifier[name=require]) StringLiteral[value=${scope}/react/module-federation]`;
|
|
130
|
+
const nodes = (0, tsquery_1.tsquery)(ast, HAS_WITH_MODULE_FEDERATION_FROM_NX_REACT);
|
|
131
|
+
if (nodes.length === 0) {
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
const WITH_MODULE_FEDERATION_IMPORT = 'VariableDeclaration:has(Identifier[name=withModuleFederation]) Identifier[name=withModuleFederation]';
|
|
135
|
+
const withModuleFederationNodes = (0, tsquery_1.tsquery)(ast, WITH_MODULE_FEDERATION_IMPORT);
|
|
136
|
+
if (nodes.length === 0) {
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
const startIndex = withModuleFederationNodes[0].getStart();
|
|
140
|
+
let endIndex = withModuleFederationNodes[0].getEnd();
|
|
141
|
+
if (configContents.charAt(endIndex) === ',') {
|
|
142
|
+
endIndex++;
|
|
143
|
+
}
|
|
144
|
+
const newContents = `const { withModuleFederation } = require('@nx/rspack/module-federation');
|
|
145
|
+
${configContents.slice(0, startIndex)}${configContents.slice(endIndex)}`;
|
|
146
|
+
tree.write(configPath, newContents);
|
|
147
|
+
}
|
|
148
|
+
function transformWithModuleFederationSSR(tree, configPath, scope) {
|
|
149
|
+
const configContents = tree.read(configPath, 'utf-8');
|
|
150
|
+
const ast = tsquery_1.tsquery.ast(configContents);
|
|
151
|
+
const HAS_WITH_MODULE_FEDERATION_FROM_NX_REACT = `VariableDeclaration:has(Identifier[name=withModuleFederationForSSR]) > CallExpression:has(Identifier[name=require]) StringLiteral[value=${scope}/react/module-federation]`;
|
|
152
|
+
const nodes = (0, tsquery_1.tsquery)(ast, HAS_WITH_MODULE_FEDERATION_FROM_NX_REACT);
|
|
153
|
+
if (nodes.length === 0) {
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
const WITH_MODULE_FEDERATION_IMPORT = 'VariableDeclaration:has(Identifier[name=withModuleFederationForSSR]) Identifier[name=withModuleFederationForSSR]';
|
|
157
|
+
const withModuleFederationNodes = (0, tsquery_1.tsquery)(ast, WITH_MODULE_FEDERATION_IMPORT);
|
|
158
|
+
if (nodes.length === 0) {
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
const startIndex = withModuleFederationNodes[0].getStart();
|
|
162
|
+
let endIndex = withModuleFederationNodes[0].getEnd();
|
|
163
|
+
if (configContents.charAt(endIndex) === ',') {
|
|
164
|
+
endIndex++;
|
|
165
|
+
}
|
|
166
|
+
const newContents = `const { withModuleFederationForSSR } = require('@nx/rspack/module-federation');
|
|
167
|
+
${configContents.slice(0, startIndex)}${configContents.slice(endIndex)}`;
|
|
168
|
+
tree.write(configPath, newContents);
|
|
169
|
+
}
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.transformEsmConfigFile = transformEsmConfigFile;
|
|
4
|
+
const tsquery_1 = require("@phenomnomnominal/tsquery");
|
|
5
|
+
function transformEsmConfigFile(tree, configPath) {
|
|
6
|
+
['@nx', '@nrwl'].forEach((scope) => {
|
|
7
|
+
transformComposePlugins(tree, configPath, scope);
|
|
8
|
+
transformWithNx(tree, configPath, scope);
|
|
9
|
+
transformWithWeb(tree, configPath, scope);
|
|
10
|
+
transformWithReact(tree, configPath, scope);
|
|
11
|
+
transformModuleFederationConfig(tree, configPath, scope);
|
|
12
|
+
transformWithModuleFederation(tree, configPath, scope);
|
|
13
|
+
transformWithModuleFederationSSR(tree, configPath, scope);
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
function transformComposePlugins(tree, configPath, scope) {
|
|
17
|
+
const configContents = tree.read(configPath, 'utf-8');
|
|
18
|
+
const ast = tsquery_1.tsquery.ast(configContents);
|
|
19
|
+
const HAS_COMPOSE_PLUGINS_FROM_NX_WEBPACK = `ImportDeclaration:has(Identifier[name=composePlugins]) > StringLiteral[value=${scope}/webpack]`;
|
|
20
|
+
const nodes = (0, tsquery_1.tsquery)(ast, HAS_COMPOSE_PLUGINS_FROM_NX_WEBPACK);
|
|
21
|
+
if (nodes.length === 0) {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
const COMPOSE_PLUGINS_IMPORT = 'ImportDeclaration:has(Identifier[name=composePlugins]) Identifier[name=composePlugins]';
|
|
25
|
+
const composePluginsNodes = (0, tsquery_1.tsquery)(ast, COMPOSE_PLUGINS_IMPORT);
|
|
26
|
+
if (nodes.length === 0) {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
const startIndex = composePluginsNodes[0].getStart();
|
|
30
|
+
let endIndex = composePluginsNodes[0].getEnd();
|
|
31
|
+
if (configContents.charAt(endIndex) === ',') {
|
|
32
|
+
endIndex++;
|
|
33
|
+
}
|
|
34
|
+
const newContents = `import { composePlugins } from '@nx/rspack';
|
|
35
|
+
${configContents.slice(0, startIndex)}${configContents.slice(endIndex)}`;
|
|
36
|
+
tree.write(configPath, newContents);
|
|
37
|
+
}
|
|
38
|
+
function transformWithNx(tree, configPath, scope) {
|
|
39
|
+
const configContents = tree.read(configPath, 'utf-8');
|
|
40
|
+
const ast = tsquery_1.tsquery.ast(configContents);
|
|
41
|
+
const HAS_WITH_NX_FROM_NX_WEBPACK = `ImportDeclaration:has(Identifier[name=withNx]) > StringLiteral[value=${scope}/webpack]`;
|
|
42
|
+
const nodes = (0, tsquery_1.tsquery)(ast, HAS_WITH_NX_FROM_NX_WEBPACK);
|
|
43
|
+
if (nodes.length === 0) {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
const WITH_NX_IMPORT = 'ImportDeclaration:has(Identifier[name=withNx]) Identifier[name=withNx]';
|
|
47
|
+
const withNxNodes = (0, tsquery_1.tsquery)(ast, WITH_NX_IMPORT);
|
|
48
|
+
if (nodes.length === 0) {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
const startIndex = withNxNodes[0].getStart();
|
|
52
|
+
let endIndex = withNxNodes[0].getEnd();
|
|
53
|
+
if (configContents.charAt(endIndex) === ',') {
|
|
54
|
+
endIndex++;
|
|
55
|
+
}
|
|
56
|
+
const newContents = `import { withNx } from '@nx/rspack';
|
|
57
|
+
${configContents.slice(0, startIndex)}${configContents.slice(endIndex)}`;
|
|
58
|
+
tree.write(configPath, newContents);
|
|
59
|
+
}
|
|
60
|
+
function transformWithWeb(tree, configPath, scope) {
|
|
61
|
+
const configContents = tree.read(configPath, 'utf-8');
|
|
62
|
+
const ast = tsquery_1.tsquery.ast(configContents);
|
|
63
|
+
const HAS_WITH_WEB_FROM_NX_WEBPACK = `ImportDeclaration:has(Identifier[name=withWeb]) > StringLiteral[value=${scope}/webpack]`;
|
|
64
|
+
const nodes = (0, tsquery_1.tsquery)(ast, HAS_WITH_WEB_FROM_NX_WEBPACK);
|
|
65
|
+
if (nodes.length === 0) {
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
const WITH_WEB_IMPORT = 'ImportDeclaration:has(Identifier[name=withWeb]) Identifier[name=withWeb]';
|
|
69
|
+
const withWebNodes = (0, tsquery_1.tsquery)(ast, WITH_WEB_IMPORT);
|
|
70
|
+
if (nodes.length === 0) {
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
const startIndex = withWebNodes[0].getStart();
|
|
74
|
+
let endIndex = withWebNodes[0].getEnd();
|
|
75
|
+
if (configContents.charAt(endIndex) === ',') {
|
|
76
|
+
endIndex++;
|
|
77
|
+
}
|
|
78
|
+
const newContents = `import { withWeb } from '@nx/rspack';
|
|
79
|
+
${configContents.slice(0, startIndex)}${configContents.slice(endIndex)}`;
|
|
80
|
+
tree.write(configPath, newContents);
|
|
81
|
+
}
|
|
82
|
+
function transformWithReact(tree, configPath, scope) {
|
|
83
|
+
const configContents = tree.read(configPath, 'utf-8');
|
|
84
|
+
const ast = tsquery_1.tsquery.ast(configContents);
|
|
85
|
+
const HAS_WITH_REACT_FROM_NX_REACT = `ImportDeclaration:has(Identifier[name=withReact]) > StringLiteral[value=${scope}/react]`;
|
|
86
|
+
const nodes = (0, tsquery_1.tsquery)(ast, HAS_WITH_REACT_FROM_NX_REACT);
|
|
87
|
+
if (nodes.length === 0) {
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
const WITH_REACT_IMPORT = 'ImportDeclaration:has(Identifier[name=withReact]) Identifier[name=withReact]';
|
|
91
|
+
const withReactNodes = (0, tsquery_1.tsquery)(ast, WITH_REACT_IMPORT);
|
|
92
|
+
if (nodes.length === 0) {
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
const startIndex = withReactNodes[0].getStart();
|
|
96
|
+
let endIndex = withReactNodes[0].getEnd();
|
|
97
|
+
if (configContents.charAt(endIndex) === ',') {
|
|
98
|
+
endIndex++;
|
|
99
|
+
}
|
|
100
|
+
const newContents = `import { withReact } from '@nx/rspack';
|
|
101
|
+
${configContents.slice(0, startIndex)}${configContents.slice(endIndex)}`;
|
|
102
|
+
tree.write(configPath, newContents);
|
|
103
|
+
}
|
|
104
|
+
function transformWithModuleFederation(tree, configPath, scope) {
|
|
105
|
+
const configContents = tree.read(configPath, 'utf-8');
|
|
106
|
+
const ast = tsquery_1.tsquery.ast(configContents);
|
|
107
|
+
const HAS_WITH_MODULE_FEDERATION_FROM_NX_REACT = `ImportDeclaration:has(Identifier[name=withModuleFederation]) > StringLiteral[value=${scope}/react/module-federation]`;
|
|
108
|
+
const nodes = (0, tsquery_1.tsquery)(ast, HAS_WITH_MODULE_FEDERATION_FROM_NX_REACT);
|
|
109
|
+
if (nodes.length === 0) {
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
const WITH_MODULE_FEDERATION_IMPORT = 'ImportDeclaration:has(Identifier[name=withModuleFederation]) Identifier[name=withModuleFederation]';
|
|
113
|
+
const withModuleFederationNodes = (0, tsquery_1.tsquery)(ast, WITH_MODULE_FEDERATION_IMPORT);
|
|
114
|
+
if (nodes.length === 0) {
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
const startIndex = withModuleFederationNodes[0].getStart();
|
|
118
|
+
let endIndex = withModuleFederationNodes[0].getEnd();
|
|
119
|
+
if (configContents.charAt(endIndex) === ',') {
|
|
120
|
+
endIndex++;
|
|
121
|
+
}
|
|
122
|
+
const newContents = `import { withModuleFederation } from '@nx/rspack/module-federation';
|
|
123
|
+
${configContents.slice(0, startIndex)}${configContents.slice(endIndex)}`;
|
|
124
|
+
tree.write(configPath, newContents);
|
|
125
|
+
}
|
|
126
|
+
function transformModuleFederationConfig(tree, configPath, scope) {
|
|
127
|
+
const configContents = tree.read(configPath, 'utf-8');
|
|
128
|
+
const ast = tsquery_1.tsquery.ast(configContents);
|
|
129
|
+
const HAS_WITH_MODULE_FEDERATION_FROM_NX_REACT = `ImportDeclaration:has(Identifier[name=ModuleFederationConfig]) > StringLiteral[value=${scope}/webpack]`;
|
|
130
|
+
const nodes = (0, tsquery_1.tsquery)(ast, HAS_WITH_MODULE_FEDERATION_FROM_NX_REACT);
|
|
131
|
+
if (nodes.length === 0) {
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
const WITH_MODULE_FEDERATION_IMPORT = 'ImportDeclaration:has(Identifier[name=ModuleFederationConfig]) Identifier[name=ModuleFederationConfig]';
|
|
135
|
+
const withModuleFederationNodes = (0, tsquery_1.tsquery)(ast, WITH_MODULE_FEDERATION_IMPORT);
|
|
136
|
+
if (nodes.length === 0) {
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
const startIndex = withModuleFederationNodes[0].getStart();
|
|
140
|
+
let endIndex = withModuleFederationNodes[0].getEnd();
|
|
141
|
+
if (configContents.charAt(endIndex) === ',') {
|
|
142
|
+
endIndex++;
|
|
143
|
+
}
|
|
144
|
+
const newContents = `import { ModuleFederationConfig } from '@nx/rspack/module-federation';
|
|
145
|
+
${configContents.slice(0, startIndex)}${configContents.slice(endIndex)}`;
|
|
146
|
+
tree.write(configPath, newContents);
|
|
147
|
+
}
|
|
148
|
+
function transformWithModuleFederationSSR(tree, configPath, scope) {
|
|
149
|
+
const configContents = tree.read(configPath, 'utf-8');
|
|
150
|
+
const ast = tsquery_1.tsquery.ast(configContents);
|
|
151
|
+
const HAS_WITH_MODULE_FEDERATION_FROM_NX_REACT = `ImportDeclaration:has(Identifier[name=withModuleFederationForSSR]) > StringLiteral[value=${scope}/react/module-federation]`;
|
|
152
|
+
const nodes = (0, tsquery_1.tsquery)(ast, HAS_WITH_MODULE_FEDERATION_FROM_NX_REACT);
|
|
153
|
+
if (nodes.length === 0) {
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
const WITH_MODULE_FEDERATION_IMPORT = 'ImportDeclaration:has(Identifier[name=withModuleFederationForSSR]) Identifier[name=withModuleFederationForSSR]';
|
|
157
|
+
const withModuleFederationNodes = (0, tsquery_1.tsquery)(ast, WITH_MODULE_FEDERATION_IMPORT);
|
|
158
|
+
if (nodes.length === 0) {
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
const startIndex = withModuleFederationNodes[0].getStart();
|
|
162
|
+
let endIndex = withModuleFederationNodes[0].getEnd();
|
|
163
|
+
if (configContents.charAt(endIndex) === ',') {
|
|
164
|
+
endIndex++;
|
|
165
|
+
}
|
|
166
|
+
const newContents = `import { withModuleFederationForSSR } from '@nx/rspack/module-federation';
|
|
167
|
+
${configContents.slice(0, startIndex)}${configContents.slice(endIndex)}`;
|
|
168
|
+
tree.write(configPath, newContents);
|
|
169
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "http://json-schema.org/schema",
|
|
3
|
+
"$id": "Rspack",
|
|
4
|
+
"title": "Nx Webpack to Rspack Generator",
|
|
5
|
+
"description": "Convert a Webpack project to Rspack.",
|
|
6
|
+
"type": "object",
|
|
7
|
+
"properties": {
|
|
8
|
+
"project": {
|
|
9
|
+
"type": "string",
|
|
10
|
+
"description": "The name of the project.",
|
|
11
|
+
"$default": {
|
|
12
|
+
"$source": "argv",
|
|
13
|
+
"index": 0
|
|
14
|
+
},
|
|
15
|
+
"x-dropdown": "project",
|
|
16
|
+
"x-prompt": "What is the name of the project to convert to rspack?",
|
|
17
|
+
"x-priority": "important"
|
|
18
|
+
},
|
|
19
|
+
"skipFormat": {
|
|
20
|
+
"description": "Skip formatting files.",
|
|
21
|
+
"type": "boolean",
|
|
22
|
+
"default": false,
|
|
23
|
+
"x-priority": "internal"
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
package/src/utils/versions.d.ts
CHANGED
package/src/utils/versions.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.eslintPluginReactHooksVersion = exports.eslintPluginReactVersion = exports.eslintPluginJsxA11yVersion = exports.eslintPluginImportVersion = exports.stylusVersion = exports.sassVersion = exports.lessVersion = exports.nestjsMicroservicesVersion = exports.nestjsPlatformExpressVersion = exports.nestjsCoreVersion = exports.nestjsCommonVersion = exports.typesReactDomVersion = exports.typesReactVersion = exports.reactDomVersion = exports.reactRefreshVersion = exports.reactVersion = exports.lessLoaderVersion = exports.rspackPluginReactRefreshVersion = exports.rspackPluginMinifyVersion = exports.rspackDevServerVersion = exports.rspackCoreVersion = void 0;
|
|
3
|
+
exports.eslintPluginReactHooksVersion = exports.eslintPluginReactVersion = exports.eslintPluginJsxA11yVersion = exports.eslintPluginImportVersion = exports.stylusVersion = exports.sassVersion = exports.lessVersion = exports.nestjsMicroservicesVersion = exports.nestjsPlatformExpressVersion = exports.nestjsCoreVersion = exports.nestjsCommonVersion = exports.typesReactDomVersion = exports.typesReactVersion = exports.reactDomVersion = exports.reactRefreshVersion = exports.reactVersion = exports.lessLoaderVersion = exports.rspackPluginReactRefreshVersion = exports.rspackPluginMinifyVersion = exports.rspackDevServerVersion = exports.rspackCoreVersion = exports.nxVersion = void 0;
|
|
4
|
+
exports.nxVersion = require('../../package.json').version;
|
|
4
5
|
exports.rspackCoreVersion = '1.0.5';
|
|
5
6
|
exports.rspackDevServerVersion = '1.0.5';
|
|
6
7
|
exports.rspackPluginMinifyVersion = '^0.7.5';
|