@nx/rspack 22.4.0-canary.20260113-246d4fd → 22.4.0-canary.20260114-45f2ae3
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/package.json +8 -8
- package/src/generators/convert-config-to-rspack-plugin/lib/extract-rspack-options.d.ts.map +1 -1
- package/src/generators/convert-config-to-rspack-plugin/lib/extract-rspack-options.js +6 -6
- package/src/generators/convert-to-inferred/convert-to-inferred.js +3 -3
- package/src/generators/convert-to-inferred/utils/build-post-target-transformer.js +5 -5
- package/src/generators/convert-to-inferred/utils/serve-post-target-transformer.js +6 -6
- package/src/generators/convert-webpack/lib/transform-cjs.js +24 -24
- package/src/generators/convert-webpack/lib/transform-esm.js +24 -24
- package/src/generators/convert-webpack/lib/transform-plugin-config.d.ts.map +1 -1
- package/src/generators/convert-webpack/lib/transform-plugin-config.js +15 -27
- package/src/migrations/update-20-2-0/migrate-with-mf-import-to-new-package.js +2 -2
- package/src/utils/generator-utils.js +5 -5
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": "22.4.0-canary.
|
|
4
|
+
"version": "22.4.0-canary.20260114-45f2ae3",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
@@ -24,11 +24,11 @@
|
|
|
24
24
|
"generators": "./generators.json",
|
|
25
25
|
"executors": "./executors.json",
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@nx/devkit": "22.4.0-canary.
|
|
28
|
-
"@nx/js": "22.4.0-canary.
|
|
29
|
-
"@nx/module-federation": "22.4.0-canary.
|
|
30
|
-
"@nx/web": "22.4.0-canary.
|
|
31
|
-
"@phenomnomnominal/tsquery": "~
|
|
27
|
+
"@nx/devkit": "22.4.0-canary.20260114-45f2ae3",
|
|
28
|
+
"@nx/js": "22.4.0-canary.20260114-45f2ae3",
|
|
29
|
+
"@nx/module-federation": "22.4.0-canary.20260114-45f2ae3",
|
|
30
|
+
"@nx/web": "22.4.0-canary.20260114-45f2ae3",
|
|
31
|
+
"@phenomnomnominal/tsquery": "~6.1.4",
|
|
32
32
|
"@rspack/core": "1.6.8",
|
|
33
33
|
"@rspack/dev-server": "^1.1.4",
|
|
34
34
|
"@rspack/plugin-react-refresh": "^1.0.0",
|
|
@@ -57,8 +57,8 @@
|
|
|
57
57
|
"webpack-node-externals": "^3.0.0"
|
|
58
58
|
},
|
|
59
59
|
"devDependencies": {
|
|
60
|
-
"nx": "22.4.0-canary.
|
|
61
|
-
"@nx/nest": "22.4.0-canary.
|
|
60
|
+
"nx": "22.4.0-canary.20260114-45f2ae3",
|
|
61
|
+
"@nx/nest": "22.4.0-canary.20260114-45f2ae3"
|
|
62
62
|
},
|
|
63
63
|
"peerDependencies": {
|
|
64
64
|
"@module-federation/enhanced": "^0.21.2",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"extract-rspack-options.d.ts","sourceRoot":"","sources":["../../../../../../../packages/rspack/src/generators/convert-config-to-rspack-plugin/lib/extract-rspack-options.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAElC,OAAO,KAAK,EAAE,MAAM,YAAY,CAAC;AAEjC,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,IAAI,EAAE,gBAAgB,EAAE,MAAM;;;
|
|
1
|
+
{"version":3,"file":"extract-rspack-options.d.ts","sourceRoot":"","sources":["../../../../../../../packages/rspack/src/generators/convert-config-to-rspack-plugin/lib/extract-rspack-options.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAElC,OAAO,KAAK,EAAE,MAAM,YAAY,CAAC;AAEjC,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,IAAI,EAAE,gBAAgB,EAAE,MAAM;;;EA+DxE"}
|
|
@@ -6,13 +6,13 @@ const tsquery_1 = require("@phenomnomnominal/tsquery");
|
|
|
6
6
|
const ts = tslib_1.__importStar(require("typescript"));
|
|
7
7
|
function extractRspackOptions(tree, rspackConfigPath) {
|
|
8
8
|
const source = tree.read(rspackConfigPath).toString('utf-8');
|
|
9
|
-
const
|
|
9
|
+
const sourceFile = (0, tsquery_1.ast)(source);
|
|
10
10
|
const withNxQuery = 'CallExpression:has(Identifier[name="withNx"])';
|
|
11
11
|
const withReactQuery = 'CallExpression:has(Identifier[name="withReact"])';
|
|
12
12
|
const withWebQuery = 'CallExpression:has(Identifier[name="withWeb"])';
|
|
13
|
-
const withNxCall = (0, tsquery_1.
|
|
14
|
-
const withReactCall = (0, tsquery_1.
|
|
15
|
-
const withWebCall = (0, tsquery_1.
|
|
13
|
+
const withNxCall = (0, tsquery_1.query)(sourceFile, withNxQuery);
|
|
14
|
+
const withReactCall = (0, tsquery_1.query)(sourceFile, withReactQuery);
|
|
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
18
|
withWebCall.forEach((node) => {
|
|
@@ -45,14 +45,14 @@ function removeCallExpressions(source, functionNames) {
|
|
|
45
45
|
let modifiedSource = source;
|
|
46
46
|
functionNames.forEach((functionName) => {
|
|
47
47
|
const callExpressionQuery = `CallExpression:has(Identifier[name="composePlugins"]) > CallExpression:has(Identifier[name="${functionName}"])`;
|
|
48
|
-
modifiedSource = tsquery_1.
|
|
48
|
+
modifiedSource = (0, tsquery_1.replace)(modifiedSource, callExpressionQuery, () => {
|
|
49
49
|
return ''; // Removes the entire CallExpression
|
|
50
50
|
});
|
|
51
51
|
});
|
|
52
52
|
return modifiedSource;
|
|
53
53
|
}
|
|
54
54
|
function removeImportDeclarations(source, importName, moduleName) {
|
|
55
|
-
const sourceFile = tsquery_1.
|
|
55
|
+
const sourceFile = (0, tsquery_1.ast)(source);
|
|
56
56
|
const modifiedStatements = sourceFile.statements
|
|
57
57
|
.map((statement) => {
|
|
58
58
|
if (!ts.isVariableStatement(statement))
|
|
@@ -70,14 +70,14 @@ function skipProjectFilterFactory(tree) {
|
|
|
70
70
|
if (!rspackConfigPath) {
|
|
71
71
|
return `The rspack config path is missing in the project configuration (${projectConfiguration.root}).`;
|
|
72
72
|
}
|
|
73
|
-
const sourceFile = tsquery_1.
|
|
73
|
+
const sourceFile = (0, tsquery_1.ast)(tree.read(rspackConfigPath, 'utf-8'));
|
|
74
74
|
const composePluginsSelector = 'CallExpression:has(Identifier[name=composePlugins])';
|
|
75
|
-
const composePlugins = (0, tsquery_1.
|
|
75
|
+
const composePlugins = (0, tsquery_1.query)(sourceFile, composePluginsSelector)[0];
|
|
76
76
|
if (composePlugins) {
|
|
77
77
|
return `The rspack config (${rspackConfigPath}) can only work with the "@nx/rspack:rspack" executor. Run the "@nx/rspack:convert-config-to-rspack-plugin" generator first.`;
|
|
78
78
|
}
|
|
79
79
|
const nxAppRspackPluginSelector = 'PropertyAssignment:has(Identifier[name=plugins]) NewExpression:has(Identifier[name=NxAppRspackPlugin])';
|
|
80
|
-
const nxAppRspackPlugin = (0, tsquery_1.
|
|
80
|
+
const nxAppRspackPlugin = (0, tsquery_1.query)(sourceFile, nxAppRspackPluginSelector)[0];
|
|
81
81
|
if (!nxAppRspackPlugin) {
|
|
82
82
|
return `No "NxAppRspackPlugin" found in the rspack config (${rspackConfigPath}). Its usage is required for the migration to work.`;
|
|
83
83
|
}
|
|
@@ -105,7 +105,7 @@ function updateRspackConfig(tree, rspackConfig, pluginOptions) {
|
|
|
105
105
|
let rspackConfigText;
|
|
106
106
|
const updateSources = () => {
|
|
107
107
|
rspackConfigText = tree.read(rspackConfig, 'utf-8');
|
|
108
|
-
sourceFile = tsquery_1.
|
|
108
|
+
sourceFile = (0, tsquery_1.ast)(rspackConfigText);
|
|
109
109
|
};
|
|
110
110
|
updateSources();
|
|
111
111
|
setOptionsInRspackConfig(tree, rspackConfigText, sourceFile, rspackConfig, pluginOptions);
|
|
@@ -117,11 +117,11 @@ 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
|
-
const optionsVariable = (0, tsquery_1.
|
|
120
|
+
const optionsVariable = (0, tsquery_1.query)(sourceFile, optionsSelector)[0];
|
|
121
121
|
// This is assuming the `options` variable will be available since it's what the
|
|
122
122
|
// `convert-config-to-rspack-plugin` generates
|
|
123
123
|
let defaultOptionsObject;
|
|
124
|
-
const optionsObject = (0, tsquery_1.
|
|
124
|
+
const optionsObject = (0, tsquery_1.query)(optionsVariable, 'ObjectLiteralExpression')[0];
|
|
125
125
|
if (optionsObject.properties.length === 0) {
|
|
126
126
|
defaultOptionsObject = ts.factory.createObjectLiteralExpression(Object.entries(defaultOptions).map(([key, value]) => (0, ast_1.toPropertyAssignment)(key, value)));
|
|
127
127
|
}
|
|
@@ -176,7 +176,7 @@ function setOptionsInRspackConfig(tree, text, sourceFile, rspackConfig, pluginOp
|
|
|
176
176
|
}
|
|
177
177
|
function setOptionsInNxRspackPlugin(tree, text, sourceFile, rspackConfig) {
|
|
178
178
|
const nxAppRspackPluginSelector = 'PropertyAssignment:has(Identifier[name=plugins]) NewExpression:has(Identifier[name=NxAppRspackPlugin])';
|
|
179
|
-
const nxAppRspackPlugin = (0, tsquery_1.
|
|
179
|
+
const nxAppRspackPlugin = (0, tsquery_1.query)(sourceFile, nxAppRspackPluginSelector)[0];
|
|
180
180
|
// the NxAppRspackPlugin must exists, otherwise, the migration doesn't run and we wouldn't reach this point
|
|
181
181
|
const updatedNxAppRspackPlugin = ts.factory.updateNewExpression(nxAppRspackPlugin, nxAppRspackPlugin.expression, undefined, [ts.factory.createIdentifier('buildOptions')]);
|
|
182
182
|
text = `${text.slice(0, nxAppRspackPlugin.getStart())}${ts
|
|
@@ -186,7 +186,7 @@ function setOptionsInNxRspackPlugin(tree, text, sourceFile, rspackConfig) {
|
|
|
186
186
|
}
|
|
187
187
|
function setOptionsInLegacyNxPlugin(tree, text, sourceFile, rspackConfig) {
|
|
188
188
|
const legacyNxPluginSelector = 'AwaitExpression CallExpression:has(Identifier[name=useLegacyNxPlugin])';
|
|
189
|
-
const legacyNxPlugin = (0, tsquery_1.
|
|
189
|
+
const legacyNxPlugin = (0, tsquery_1.query)(sourceFile, legacyNxPluginSelector)[0];
|
|
190
190
|
// we're assuming the `useLegacyNxPlugin` function is being called since it's what the `convert-config-to-rspack-plugin` generates
|
|
191
191
|
// we've already "ensured" that the `convert-config-to-rspack-plugin` was run by checking for the `NxAppRspackPlugin` in the project validation
|
|
192
192
|
const updatedLegacyNxPlugin = ts.factory.updateCallExpression(legacyNxPlugin, legacyNxPlugin.expression, undefined, [legacyNxPlugin.arguments[0], ts.factory.createIdentifier('buildOptions')]);
|
|
@@ -134,7 +134,7 @@ function updateRspackConfig(tree, rspackConfigPath, devServerOptions, context) {
|
|
|
134
134
|
let rspackConfigText;
|
|
135
135
|
const updateSources = () => {
|
|
136
136
|
rspackConfigText = tree.read(rspackConfigPath, 'utf-8');
|
|
137
|
-
sourceFile = tsquery_1.
|
|
137
|
+
sourceFile = (0, tsquery_1.ast)(rspackConfigText);
|
|
138
138
|
};
|
|
139
139
|
updateSources();
|
|
140
140
|
setOptionsInRspackConfig(tree, rspackConfigText, sourceFile, rspackConfigPath, devServerOptions);
|
|
@@ -144,7 +144,7 @@ function updateRspackConfig(tree, rspackConfigPath, devServerOptions, context) {
|
|
|
144
144
|
function setOptionsInRspackConfig(tree, text, sourceFile, rspackConfigPath, devServerOptions) {
|
|
145
145
|
const { default: defaultOptions, ...configurationOptions } = devServerOptions;
|
|
146
146
|
const configValuesSelector = 'VariableDeclaration:has(Identifier[name=configValues]) ObjectLiteralExpression';
|
|
147
|
-
const configValuesObject = (0, tsquery_1.
|
|
147
|
+
const configValuesObject = (0, tsquery_1.query)(sourceFile, configValuesSelector)[0];
|
|
148
148
|
// configValues must exist at this point, we added it when processing the build target
|
|
149
149
|
/**
|
|
150
150
|
* const configValues = {
|
|
@@ -168,9 +168,9 @@ function setOptionsInRspackConfig(tree, text, sourceFile, rspackConfigPath, devS
|
|
|
168
168
|
.createPrinter()
|
|
169
169
|
.printNode(ts.EmitHint.Unspecified, updatedConfigValuesObject, sourceFile)}${text.slice(configValuesObject.getEnd())}`;
|
|
170
170
|
tree.write(rspackConfigPath, text);
|
|
171
|
-
sourceFile = tsquery_1.
|
|
171
|
+
sourceFile = (0, tsquery_1.ast)(text);
|
|
172
172
|
const buildOptionsSelector = 'VariableStatement:has(VariableDeclaration:has(Identifier[name=buildOptions]))';
|
|
173
|
-
const buildOptionsStatement = (0, tsquery_1.
|
|
173
|
+
const buildOptionsStatement = (0, tsquery_1.query)(sourceFile, buildOptionsSelector)[0];
|
|
174
174
|
text = `${text.slice(0, buildOptionsStatement.getEnd())}
|
|
175
175
|
const devServerOptions = {
|
|
176
176
|
...configValues.serve.default,
|
|
@@ -180,7 +180,7 @@ function setOptionsInRspackConfig(tree, text, sourceFile, rspackConfigPath, devS
|
|
|
180
180
|
}
|
|
181
181
|
function setDevServerOptionsInRspackConfig(tree, text, sourceFile, rspackConfigPath, context) {
|
|
182
182
|
const rspackConfigDevServerSelector = 'ObjectLiteralExpression > PropertyAssignment:has(Identifier[name=devServer])';
|
|
183
|
-
const rspackConfigDevServer = (0, tsquery_1.
|
|
183
|
+
const rspackConfigDevServer = (0, tsquery_1.query)(sourceFile, rspackConfigDevServerSelector)[0];
|
|
184
184
|
if (rspackConfigDevServer) {
|
|
185
185
|
context.logger.addLog({
|
|
186
186
|
executorName: '@nx/rspack:dev-server',
|
|
@@ -195,7 +195,7 @@ function setDevServerOptionsInRspackConfig(tree, text, sourceFile, rspackConfigP
|
|
|
195
195
|
return;
|
|
196
196
|
}
|
|
197
197
|
const rspackConfigSelector = 'ObjectLiteralExpression:has(PropertyAssignment:has(Identifier[name=plugins]))';
|
|
198
|
-
const rspackConfig = (0, tsquery_1.
|
|
198
|
+
const rspackConfig = (0, tsquery_1.query)(sourceFile, rspackConfigSelector)[0];
|
|
199
199
|
const updatedRspackConfig = ts.factory.updateObjectLiteralExpression(rspackConfig, [
|
|
200
200
|
ts.factory.createPropertyAssignment('devServer', ts.factory.createIdentifier('devServerOptions')),
|
|
201
201
|
...rspackConfig.properties,
|
|
@@ -24,9 +24,9 @@ function detectJsExtensions(configContents) {
|
|
|
24
24
|
}
|
|
25
25
|
function transformWithWebCalls(tree, configPath) {
|
|
26
26
|
const configContents = tree.read(configPath, 'utf-8');
|
|
27
|
-
const
|
|
27
|
+
const sourceFile = (0, tsquery_1.ast)(configContents);
|
|
28
28
|
// Find withWeb() calls
|
|
29
|
-
const withWebCallNodes = (0, tsquery_1.
|
|
29
|
+
const withWebCallNodes = (0, tsquery_1.query)(sourceFile, 'CallExpression > Identifier[name=withWeb]');
|
|
30
30
|
// If there are withWeb calls, update them
|
|
31
31
|
if (withWebCallNodes.length > 0) {
|
|
32
32
|
let newContents = configContents;
|
|
@@ -64,7 +64,7 @@ function transformWithWebCalls(tree, configPath) {
|
|
|
64
64
|
return;
|
|
65
65
|
}
|
|
66
66
|
// If no withWeb calls, check for withReact calls
|
|
67
|
-
const withReactCallNodes = (0, tsquery_1.
|
|
67
|
+
const withReactCallNodes = (0, tsquery_1.query)(sourceFile, 'CallExpression > Identifier[name=withReact]');
|
|
68
68
|
if (withReactCallNodes.length === 0) {
|
|
69
69
|
return;
|
|
70
70
|
}
|
|
@@ -103,14 +103,14 @@ function transformWithWebCalls(tree, configPath) {
|
|
|
103
103
|
}
|
|
104
104
|
function transformComposePlugins(tree, configPath, scope) {
|
|
105
105
|
const configContents = tree.read(configPath, 'utf-8');
|
|
106
|
-
const
|
|
106
|
+
const sourceFile = (0, tsquery_1.ast)(configContents);
|
|
107
107
|
const HAS_COMPOSE_PLUGINS_FROM_NX_WEBPACK = `VariableDeclaration:has(Identifier[name=composePlugins]) > CallExpression:has(Identifier[name=require]) StringLiteral[value=${scope}/webpack]`;
|
|
108
|
-
const nodes = (0, tsquery_1.
|
|
108
|
+
const nodes = (0, tsquery_1.query)(sourceFile, HAS_COMPOSE_PLUGINS_FROM_NX_WEBPACK);
|
|
109
109
|
if (nodes.length === 0) {
|
|
110
110
|
return;
|
|
111
111
|
}
|
|
112
112
|
const COMPOSE_PLUGINS_IMPORT = 'VariableDeclaration:has(Identifier[name=composePlugins]) Identifier[name=composePlugins]';
|
|
113
|
-
const composePluginsNodes = (0, tsquery_1.
|
|
113
|
+
const composePluginsNodes = (0, tsquery_1.query)(sourceFile, COMPOSE_PLUGINS_IMPORT);
|
|
114
114
|
if (nodes.length === 0) {
|
|
115
115
|
return;
|
|
116
116
|
}
|
|
@@ -125,14 +125,14 @@ function transformComposePlugins(tree, configPath, scope) {
|
|
|
125
125
|
}
|
|
126
126
|
function transformWithNx(tree, configPath, scope) {
|
|
127
127
|
const configContents = tree.read(configPath, 'utf-8');
|
|
128
|
-
const
|
|
128
|
+
const sourceFile = (0, tsquery_1.ast)(configContents);
|
|
129
129
|
const HAS_WITH_NX_FROM_NX_WEBPACK = `VariableDeclaration:has(Identifier[name=withNx]) > CallExpression:has(Identifier[name=require]) StringLiteral[value=${scope}/webpack]`;
|
|
130
|
-
const nodes = (0, tsquery_1.
|
|
130
|
+
const nodes = (0, tsquery_1.query)(sourceFile, HAS_WITH_NX_FROM_NX_WEBPACK);
|
|
131
131
|
if (nodes.length === 0) {
|
|
132
132
|
return;
|
|
133
133
|
}
|
|
134
134
|
const WITH_NX_IMPORT = 'VariableDeclaration:has(Identifier[name=withNx]) Identifier[name=withNx]';
|
|
135
|
-
const withNxNodes = (0, tsquery_1.
|
|
135
|
+
const withNxNodes = (0, tsquery_1.query)(sourceFile, WITH_NX_IMPORT);
|
|
136
136
|
if (nodes.length === 0) {
|
|
137
137
|
return;
|
|
138
138
|
}
|
|
@@ -147,14 +147,14 @@ function transformWithNx(tree, configPath, scope) {
|
|
|
147
147
|
}
|
|
148
148
|
function transformWithWeb(tree, configPath, scope) {
|
|
149
149
|
const configContents = tree.read(configPath, 'utf-8');
|
|
150
|
-
const
|
|
150
|
+
const sourceFile = (0, tsquery_1.ast)(configContents);
|
|
151
151
|
const HAS_WITH_WEB_FROM_NX_WEBPACK = `VariableDeclaration:has(Identifier[name=withWeb]) > CallExpression:has(Identifier[name=require]) StringLiteral[value=${scope}/webpack]`;
|
|
152
|
-
const nodes = (0, tsquery_1.
|
|
152
|
+
const nodes = (0, tsquery_1.query)(sourceFile, HAS_WITH_WEB_FROM_NX_WEBPACK);
|
|
153
153
|
if (nodes.length === 0) {
|
|
154
154
|
return;
|
|
155
155
|
}
|
|
156
156
|
const WITH_WEB_IMPORT = 'VariableDeclaration:has(Identifier[name=withWeb]) Identifier[name=withWeb]';
|
|
157
|
-
const withWebNodes = (0, tsquery_1.
|
|
157
|
+
const withWebNodes = (0, tsquery_1.query)(sourceFile, WITH_WEB_IMPORT);
|
|
158
158
|
if (nodes.length === 0) {
|
|
159
159
|
return;
|
|
160
160
|
}
|
|
@@ -169,14 +169,14 @@ function transformWithWeb(tree, configPath, scope) {
|
|
|
169
169
|
}
|
|
170
170
|
function transformWithReact(tree, configPath, scope) {
|
|
171
171
|
const configContents = tree.read(configPath, 'utf-8');
|
|
172
|
-
const
|
|
172
|
+
const sourceFile = (0, tsquery_1.ast)(configContents);
|
|
173
173
|
const HAS_WITH_REACT_FROM_NX_REACT = `VariableDeclaration:has(Identifier[name=withReact]) > CallExpression:has(Identifier[name=require]) StringLiteral[value=${scope}/react]`;
|
|
174
|
-
const nodes = (0, tsquery_1.
|
|
174
|
+
const nodes = (0, tsquery_1.query)(sourceFile, HAS_WITH_REACT_FROM_NX_REACT);
|
|
175
175
|
if (nodes.length === 0) {
|
|
176
176
|
return;
|
|
177
177
|
}
|
|
178
178
|
const WITH_REACT_IMPORT = 'VariableDeclaration:has(Identifier[name=withReact]) Identifier[name=withReact]';
|
|
179
|
-
const withReactNodes = (0, tsquery_1.
|
|
179
|
+
const withReactNodes = (0, tsquery_1.query)(sourceFile, WITH_REACT_IMPORT);
|
|
180
180
|
if (nodes.length === 0) {
|
|
181
181
|
return;
|
|
182
182
|
}
|
|
@@ -191,14 +191,14 @@ function transformWithReact(tree, configPath, scope) {
|
|
|
191
191
|
}
|
|
192
192
|
function transformModuleFederationConfig(tree, configPath, scope) {
|
|
193
193
|
const configContents = tree.read(configPath, 'utf-8');
|
|
194
|
-
const
|
|
194
|
+
const sourceFile = (0, tsquery_1.ast)(configContents);
|
|
195
195
|
const HAS_WITH_MODULE_FEDERATION_FROM_NX_REACT = `VariableDeclaration:has(Identifier[name=ModuleFederationConfig]) > CallExpression:has(Identifier[name=require]) StringLiteral[value=${scope}/webpack]`;
|
|
196
|
-
const nodes = (0, tsquery_1.
|
|
196
|
+
const nodes = (0, tsquery_1.query)(sourceFile, HAS_WITH_MODULE_FEDERATION_FROM_NX_REACT);
|
|
197
197
|
if (nodes.length === 0) {
|
|
198
198
|
return;
|
|
199
199
|
}
|
|
200
200
|
const WITH_MODULE_FEDERATION_IMPORT = 'VariableDeclaration:has(Identifier[name=ModuleFederationConfig]) Identifier[name=ModuleFederationConfig]';
|
|
201
|
-
const withModuleFederationNodes = (0, tsquery_1.
|
|
201
|
+
const withModuleFederationNodes = (0, tsquery_1.query)(sourceFile, WITH_MODULE_FEDERATION_IMPORT);
|
|
202
202
|
if (nodes.length === 0) {
|
|
203
203
|
return;
|
|
204
204
|
}
|
|
@@ -213,14 +213,14 @@ function transformModuleFederationConfig(tree, configPath, scope) {
|
|
|
213
213
|
}
|
|
214
214
|
function transformWithModuleFederation(tree, configPath, scope, usesJsExtensions) {
|
|
215
215
|
const configContents = tree.read(configPath, 'utf-8');
|
|
216
|
-
const
|
|
216
|
+
const sourceFile = (0, tsquery_1.ast)(configContents);
|
|
217
217
|
const HAS_WITH_MODULE_FEDERATION_FROM_NX_REACT = `VariableDeclaration:has(Identifier[name=withModuleFederation]) > CallExpression:has(Identifier[name=require]) StringLiteral[value="${scope}/module-federation/webpack${usesJsExtensions ? '.js' : ''}"]`;
|
|
218
|
-
const nodes = (0, tsquery_1.
|
|
218
|
+
const nodes = (0, tsquery_1.query)(sourceFile, HAS_WITH_MODULE_FEDERATION_FROM_NX_REACT);
|
|
219
219
|
if (nodes.length === 0) {
|
|
220
220
|
return;
|
|
221
221
|
}
|
|
222
222
|
const WITH_MODULE_FEDERATION_IMPORT = 'VariableDeclaration:has(Identifier[name=withModuleFederation]) Identifier[name=withModuleFederation]';
|
|
223
|
-
const withModuleFederationNodes = (0, tsquery_1.
|
|
223
|
+
const withModuleFederationNodes = (0, tsquery_1.query)(sourceFile, WITH_MODULE_FEDERATION_IMPORT);
|
|
224
224
|
if (nodes.length === 0) {
|
|
225
225
|
return;
|
|
226
226
|
}
|
|
@@ -238,14 +238,14 @@ function transformWithModuleFederation(tree, configPath, scope, usesJsExtensions
|
|
|
238
238
|
}
|
|
239
239
|
function transformWithModuleFederationSSR(tree, configPath, scope, usesJsExtensions) {
|
|
240
240
|
const configContents = tree.read(configPath, 'utf-8');
|
|
241
|
-
const
|
|
241
|
+
const sourceFile = (0, tsquery_1.ast)(configContents);
|
|
242
242
|
const HAS_WITH_MODULE_FEDERATION_FROM_NX_REACT = `VariableDeclaration:has(Identifier[name=withModuleFederationForSSR]) > CallExpression:has(Identifier[name=require]) StringLiteral[value="${scope}/module-federation/webpack${usesJsExtensions ? '.js' : ''}"]`;
|
|
243
|
-
const nodes = (0, tsquery_1.
|
|
243
|
+
const nodes = (0, tsquery_1.query)(sourceFile, HAS_WITH_MODULE_FEDERATION_FROM_NX_REACT);
|
|
244
244
|
if (nodes.length === 0) {
|
|
245
245
|
return;
|
|
246
246
|
}
|
|
247
247
|
const WITH_MODULE_FEDERATION_IMPORT = 'VariableDeclaration:has(Identifier[name=withModuleFederationForSSR]) Identifier[name=withModuleFederationForSSR]';
|
|
248
|
-
const withModuleFederationNodes = (0, tsquery_1.
|
|
248
|
+
const withModuleFederationNodes = (0, tsquery_1.query)(sourceFile, WITH_MODULE_FEDERATION_IMPORT);
|
|
249
249
|
if (nodes.length === 0) {
|
|
250
250
|
return;
|
|
251
251
|
}
|
|
@@ -24,9 +24,9 @@ function detectJsExtensions(configContents) {
|
|
|
24
24
|
}
|
|
25
25
|
function transformWithWebCalls(tree, configPath) {
|
|
26
26
|
const configContents = tree.read(configPath, 'utf-8');
|
|
27
|
-
const
|
|
27
|
+
const sourceFile = (0, tsquery_1.ast)(configContents);
|
|
28
28
|
// Find withWeb() calls
|
|
29
|
-
const withWebCallNodes = (0, tsquery_1.
|
|
29
|
+
const withWebCallNodes = (0, tsquery_1.query)(sourceFile, 'CallExpression > Identifier[name=withWeb]');
|
|
30
30
|
// If there are withWeb calls, update them
|
|
31
31
|
if (withWebCallNodes.length > 0) {
|
|
32
32
|
let newContents = configContents;
|
|
@@ -64,7 +64,7 @@ function transformWithWebCalls(tree, configPath) {
|
|
|
64
64
|
return;
|
|
65
65
|
}
|
|
66
66
|
// If no withWeb calls, check for withReact calls
|
|
67
|
-
const withReactCallNodes = (0, tsquery_1.
|
|
67
|
+
const withReactCallNodes = (0, tsquery_1.query)(sourceFile, 'CallExpression > Identifier[name=withReact]');
|
|
68
68
|
if (withReactCallNodes.length === 0) {
|
|
69
69
|
return;
|
|
70
70
|
}
|
|
@@ -103,14 +103,14 @@ function transformWithWebCalls(tree, configPath) {
|
|
|
103
103
|
}
|
|
104
104
|
function transformComposePlugins(tree, configPath, scope) {
|
|
105
105
|
const configContents = tree.read(configPath, 'utf-8');
|
|
106
|
-
const
|
|
106
|
+
const sourceFile = (0, tsquery_1.ast)(configContents);
|
|
107
107
|
const HAS_COMPOSE_PLUGINS_FROM_NX_WEBPACK = `ImportDeclaration:has(Identifier[name=composePlugins]) > StringLiteral[value=${scope}/webpack]`;
|
|
108
|
-
const nodes = (0, tsquery_1.
|
|
108
|
+
const nodes = (0, tsquery_1.query)(sourceFile, HAS_COMPOSE_PLUGINS_FROM_NX_WEBPACK);
|
|
109
109
|
if (nodes.length === 0) {
|
|
110
110
|
return;
|
|
111
111
|
}
|
|
112
112
|
const COMPOSE_PLUGINS_IMPORT = 'ImportDeclaration:has(Identifier[name=composePlugins]) Identifier[name=composePlugins]';
|
|
113
|
-
const composePluginsNodes = (0, tsquery_1.
|
|
113
|
+
const composePluginsNodes = (0, tsquery_1.query)(sourceFile, COMPOSE_PLUGINS_IMPORT);
|
|
114
114
|
if (nodes.length === 0) {
|
|
115
115
|
return;
|
|
116
116
|
}
|
|
@@ -125,14 +125,14 @@ function transformComposePlugins(tree, configPath, scope) {
|
|
|
125
125
|
}
|
|
126
126
|
function transformWithNx(tree, configPath, scope) {
|
|
127
127
|
const configContents = tree.read(configPath, 'utf-8');
|
|
128
|
-
const
|
|
128
|
+
const sourceFile = (0, tsquery_1.ast)(configContents);
|
|
129
129
|
const HAS_WITH_NX_FROM_NX_WEBPACK = `ImportDeclaration:has(Identifier[name=withNx]) > StringLiteral[value=${scope}/webpack]`;
|
|
130
|
-
const nodes = (0, tsquery_1.
|
|
130
|
+
const nodes = (0, tsquery_1.query)(sourceFile, HAS_WITH_NX_FROM_NX_WEBPACK);
|
|
131
131
|
if (nodes.length === 0) {
|
|
132
132
|
return;
|
|
133
133
|
}
|
|
134
134
|
const WITH_NX_IMPORT = 'ImportDeclaration:has(Identifier[name=withNx]) Identifier[name=withNx]';
|
|
135
|
-
const withNxNodes = (0, tsquery_1.
|
|
135
|
+
const withNxNodes = (0, tsquery_1.query)(sourceFile, WITH_NX_IMPORT);
|
|
136
136
|
if (nodes.length === 0) {
|
|
137
137
|
return;
|
|
138
138
|
}
|
|
@@ -147,14 +147,14 @@ function transformWithNx(tree, configPath, scope) {
|
|
|
147
147
|
}
|
|
148
148
|
function transformWithWeb(tree, configPath, scope) {
|
|
149
149
|
const configContents = tree.read(configPath, 'utf-8');
|
|
150
|
-
const
|
|
150
|
+
const sourceFile = (0, tsquery_1.ast)(configContents);
|
|
151
151
|
const HAS_WITH_WEB_FROM_NX_WEBPACK = `ImportDeclaration:has(Identifier[name=withWeb]) > StringLiteral[value=${scope}/webpack]`;
|
|
152
|
-
const nodes = (0, tsquery_1.
|
|
152
|
+
const nodes = (0, tsquery_1.query)(sourceFile, HAS_WITH_WEB_FROM_NX_WEBPACK);
|
|
153
153
|
if (nodes.length === 0) {
|
|
154
154
|
return;
|
|
155
155
|
}
|
|
156
156
|
const WITH_WEB_IMPORT = 'ImportDeclaration:has(Identifier[name=withWeb]) Identifier[name=withWeb]';
|
|
157
|
-
const withWebNodes = (0, tsquery_1.
|
|
157
|
+
const withWebNodes = (0, tsquery_1.query)(sourceFile, WITH_WEB_IMPORT);
|
|
158
158
|
if (nodes.length === 0) {
|
|
159
159
|
return;
|
|
160
160
|
}
|
|
@@ -169,14 +169,14 @@ function transformWithWeb(tree, configPath, scope) {
|
|
|
169
169
|
}
|
|
170
170
|
function transformWithReact(tree, configPath, scope) {
|
|
171
171
|
const configContents = tree.read(configPath, 'utf-8');
|
|
172
|
-
const
|
|
172
|
+
const sourceFile = (0, tsquery_1.ast)(configContents);
|
|
173
173
|
const HAS_WITH_REACT_FROM_NX_REACT = `ImportDeclaration:has(Identifier[name=withReact]) > StringLiteral[value=${scope}/react]`;
|
|
174
|
-
const nodes = (0, tsquery_1.
|
|
174
|
+
const nodes = (0, tsquery_1.query)(sourceFile, HAS_WITH_REACT_FROM_NX_REACT);
|
|
175
175
|
if (nodes.length === 0) {
|
|
176
176
|
return;
|
|
177
177
|
}
|
|
178
178
|
const WITH_REACT_IMPORT = 'ImportDeclaration:has(Identifier[name=withReact]) Identifier[name=withReact]';
|
|
179
|
-
const withReactNodes = (0, tsquery_1.
|
|
179
|
+
const withReactNodes = (0, tsquery_1.query)(sourceFile, WITH_REACT_IMPORT);
|
|
180
180
|
if (nodes.length === 0) {
|
|
181
181
|
return;
|
|
182
182
|
}
|
|
@@ -191,14 +191,14 @@ function transformWithReact(tree, configPath, scope) {
|
|
|
191
191
|
}
|
|
192
192
|
function transformWithModuleFederation(tree, configPath, scope, usesJsExtension) {
|
|
193
193
|
const configContents = tree.read(configPath, 'utf-8');
|
|
194
|
-
const
|
|
194
|
+
const sourceFile = (0, tsquery_1.ast)(configContents);
|
|
195
195
|
const HAS_WITH_MODULE_FEDERATION_FROM_NX_REACT = `ImportDeclaration:has(Identifier[name=withModuleFederation]) > StringLiteral[value="${scope}/module-federation/webpack${usesJsExtension ? '.js' : ''}"]`;
|
|
196
|
-
const nodes = (0, tsquery_1.
|
|
196
|
+
const nodes = (0, tsquery_1.query)(sourceFile, HAS_WITH_MODULE_FEDERATION_FROM_NX_REACT);
|
|
197
197
|
if (nodes.length === 0) {
|
|
198
198
|
return;
|
|
199
199
|
}
|
|
200
200
|
const WITH_MODULE_FEDERATION_IMPORT = 'ImportDeclaration:has(Identifier[name=withModuleFederation]) Identifier[name=withModuleFederation]';
|
|
201
|
-
const withModuleFederationNodes = (0, tsquery_1.
|
|
201
|
+
const withModuleFederationNodes = (0, tsquery_1.query)(sourceFile, WITH_MODULE_FEDERATION_IMPORT);
|
|
202
202
|
if (nodes.length === 0) {
|
|
203
203
|
return;
|
|
204
204
|
}
|
|
@@ -216,14 +216,14 @@ function transformWithModuleFederation(tree, configPath, scope, usesJsExtension)
|
|
|
216
216
|
}
|
|
217
217
|
function transformModuleFederationConfig(tree, configPath, scope) {
|
|
218
218
|
const configContents = tree.read(configPath, 'utf-8');
|
|
219
|
-
const
|
|
219
|
+
const sourceFile = (0, tsquery_1.ast)(configContents);
|
|
220
220
|
const HAS_WITH_MODULE_FEDERATION_FROM_NX_REACT = `ImportDeclaration:has(Identifier[name=ModuleFederationConfig]) > StringLiteral[value=${scope}/webpack]`;
|
|
221
|
-
const nodes = (0, tsquery_1.
|
|
221
|
+
const nodes = (0, tsquery_1.query)(sourceFile, HAS_WITH_MODULE_FEDERATION_FROM_NX_REACT);
|
|
222
222
|
if (nodes.length === 0) {
|
|
223
223
|
return;
|
|
224
224
|
}
|
|
225
225
|
const WITH_MODULE_FEDERATION_IMPORT = 'ImportDeclaration:has(Identifier[name=ModuleFederationConfig]) Identifier[name=ModuleFederationConfig]';
|
|
226
|
-
const withModuleFederationNodes = (0, tsquery_1.
|
|
226
|
+
const withModuleFederationNodes = (0, tsquery_1.query)(sourceFile, WITH_MODULE_FEDERATION_IMPORT);
|
|
227
227
|
if (nodes.length === 0) {
|
|
228
228
|
return;
|
|
229
229
|
}
|
|
@@ -238,14 +238,14 @@ function transformModuleFederationConfig(tree, configPath, scope) {
|
|
|
238
238
|
}
|
|
239
239
|
function transformWithModuleFederationSSR(tree, configPath, scope, usesJsExtensions) {
|
|
240
240
|
const configContents = tree.read(configPath, 'utf-8');
|
|
241
|
-
const
|
|
241
|
+
const sourceFile = (0, tsquery_1.ast)(configContents);
|
|
242
242
|
const HAS_WITH_MODULE_FEDERATION_FROM_NX_REACT = `ImportDeclaration:has(Identifier[name=withModuleFederationForSSR]) > StringLiteral[value="${scope}/module-federation/webpack${usesJsExtensions ? '.js' : ''}"]`;
|
|
243
|
-
const nodes = (0, tsquery_1.
|
|
243
|
+
const nodes = (0, tsquery_1.query)(sourceFile, HAS_WITH_MODULE_FEDERATION_FROM_NX_REACT);
|
|
244
244
|
if (nodes.length === 0) {
|
|
245
245
|
return;
|
|
246
246
|
}
|
|
247
247
|
const WITH_MODULE_FEDERATION_IMPORT = 'ImportDeclaration:has(Identifier[name=withModuleFederationForSSR]) Identifier[name=withModuleFederationForSSR]';
|
|
248
|
-
const withModuleFederationNodes = (0, tsquery_1.
|
|
248
|
+
const withModuleFederationNodes = (0, tsquery_1.query)(sourceFile, WITH_MODULE_FEDERATION_IMPORT);
|
|
249
249
|
if (nodes.length === 0) {
|
|
250
250
|
return;
|
|
251
251
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transform-plugin-config.d.ts","sourceRoot":"","sources":["../../../../../../../packages/rspack/src/generators/convert-webpack/lib/transform-plugin-config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,IAAI,EAAE,MAAM,YAAY,CAAC;AAIvC,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,IAAI,EAAE,iBAAiB,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"transform-plugin-config.d.ts","sourceRoot":"","sources":["../../../../../../../packages/rspack/src/generators/convert-webpack/lib/transform-plugin-config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,IAAI,EAAE,MAAM,YAAY,CAAC;AAIvC,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,IAAI,EAAE,iBAAiB,EAAE,MAAM,QAkB1E"}
|
|
@@ -4,44 +4,38 @@ exports.transformPluginConfig = transformPluginConfig;
|
|
|
4
4
|
const tsquery_1 = require("@phenomnomnominal/tsquery");
|
|
5
5
|
function transformPluginConfig(tree, webpackConfigPath) {
|
|
6
6
|
const webpackConfigContents = tree.read(webpackConfigPath, 'utf-8');
|
|
7
|
-
|
|
7
|
+
let sourceFile = (0, tsquery_1.ast)(webpackConfigContents);
|
|
8
8
|
let newConfigContents = webpackConfigContents;
|
|
9
9
|
if (webpackConfigContents.includes("require('@nx/webpack/app-plugin')")) {
|
|
10
|
-
newConfigContents = transformCjsConfig(tree, webpackConfigContents,
|
|
10
|
+
newConfigContents = transformCjsConfig(tree, webpackConfigContents, sourceFile);
|
|
11
11
|
}
|
|
12
12
|
else {
|
|
13
|
-
newConfigContents = transformEsmConfig(tree, webpackConfigContents,
|
|
13
|
+
newConfigContents = transformEsmConfig(tree, webpackConfigContents, sourceFile);
|
|
14
14
|
}
|
|
15
15
|
tree.write(webpackConfigPath, newConfigContents);
|
|
16
16
|
}
|
|
17
|
-
function transformCjsConfig(tree, webpackConfigContents,
|
|
17
|
+
function transformCjsConfig(tree, webpackConfigContents, sourceFile) {
|
|
18
18
|
// Convert require('@nx/webpack/app-plugin') to require('@nx/rspack/app-plugin')
|
|
19
19
|
const WEBPACK_APP_PLUGIN_REQUIRE_SELECTOR = 'CallExpression:has(Identifier[name=require]) > StringLiteral[value=@nx/webpack/app-plugin]';
|
|
20
|
-
let nodes = (0, tsquery_1.
|
|
21
|
-
visitAllChildren: true,
|
|
22
|
-
});
|
|
20
|
+
let nodes = (0, tsquery_1.query)(sourceFile, WEBPACK_APP_PLUGIN_REQUIRE_SELECTOR);
|
|
23
21
|
if (nodes.length === 0) {
|
|
24
22
|
return webpackConfigContents;
|
|
25
23
|
}
|
|
26
24
|
const requireNode = nodes[0];
|
|
27
25
|
webpackConfigContents = `${webpackConfigContents.slice(0, requireNode.getStart())}'@nx/rspack/app-plugin'${webpackConfigContents.slice(requireNode.getEnd())}`;
|
|
28
26
|
// Convert const { NxAppWebpackPlugin } to const { NxAppRspackPlugin }
|
|
29
|
-
|
|
27
|
+
sourceFile = (0, tsquery_1.ast)(webpackConfigContents);
|
|
30
28
|
const WEBPACK_APP_BINDING_ELEMENT_SELECTOR = 'BindingElement:has(Identifier[name=NxAppWebpackPlugin])';
|
|
31
|
-
nodes = (0, tsquery_1.
|
|
32
|
-
visitAllChildren: true,
|
|
33
|
-
});
|
|
29
|
+
nodes = (0, tsquery_1.query)(sourceFile, WEBPACK_APP_BINDING_ELEMENT_SELECTOR);
|
|
34
30
|
if (nodes.length === 0) {
|
|
35
31
|
return webpackConfigContents;
|
|
36
32
|
}
|
|
37
33
|
const bindingElement = nodes[0];
|
|
38
34
|
webpackConfigContents = `${webpackConfigContents.slice(0, bindingElement.getStart())}NxAppRspackPlugin${webpackConfigContents.slice(bindingElement.getEnd())}`;
|
|
39
35
|
// Convert new NxAppWebpackPlugin() to new NxAppRspackPlugin()
|
|
40
|
-
|
|
36
|
+
sourceFile = (0, tsquery_1.ast)(webpackConfigContents);
|
|
41
37
|
const WEBPACK_APP_INSTANTIATION_SELECTOR = 'NewExpression > Identifier[name=NxAppWebpackPlugin]';
|
|
42
|
-
nodes = (0, tsquery_1.
|
|
43
|
-
visitAllChildren: true,
|
|
44
|
-
});
|
|
38
|
+
nodes = (0, tsquery_1.query)(sourceFile, WEBPACK_APP_INSTANTIATION_SELECTOR);
|
|
45
39
|
if (nodes.length === 0) {
|
|
46
40
|
return webpackConfigContents;
|
|
47
41
|
}
|
|
@@ -49,34 +43,28 @@ function transformCjsConfig(tree, webpackConfigContents, ast) {
|
|
|
49
43
|
webpackConfigContents = `${webpackConfigContents.slice(0, instantiation.getStart())}NxAppRspackPlugin${webpackConfigContents.slice(instantiation.getEnd())}`;
|
|
50
44
|
return webpackConfigContents;
|
|
51
45
|
}
|
|
52
|
-
function transformEsmConfig(tree, webpackConfigContents,
|
|
46
|
+
function transformEsmConfig(tree, webpackConfigContents, sourceFile) {
|
|
53
47
|
// Convert from '@nx/webpack/app-plugin' to from '@nx/rspack/app-plugin'
|
|
54
48
|
const WEBPACK_APP_PLUGIN_IMPORT_SELECTOR = 'ImportClause ~ StringLiteral[value=@nx/webpack/app-plugin]';
|
|
55
|
-
let nodes = (0, tsquery_1.
|
|
56
|
-
visitAllChildren: true,
|
|
57
|
-
});
|
|
49
|
+
let nodes = (0, tsquery_1.query)(sourceFile, WEBPACK_APP_PLUGIN_IMPORT_SELECTOR);
|
|
58
50
|
if (nodes.length === 0) {
|
|
59
51
|
return webpackConfigContents;
|
|
60
52
|
}
|
|
61
53
|
const importNode = nodes[0];
|
|
62
54
|
webpackConfigContents = `${webpackConfigContents.slice(0, importNode.getStart())}'@nx/rspack/app-plugin'${webpackConfigContents.slice(importNode.getEnd())}`;
|
|
63
55
|
// Convert import { NxAppWebpackPlugin } to import { NxAppRspackPlugin }
|
|
64
|
-
|
|
56
|
+
sourceFile = (0, tsquery_1.ast)(webpackConfigContents);
|
|
65
57
|
const WEBPACK_APP_IMPORT_SPECIFIER_SELECTOR = 'ImportSpecifier > Identifier[name=NxAppWebpackPlugin]';
|
|
66
|
-
nodes = (0, tsquery_1.
|
|
67
|
-
visitAllChildren: true,
|
|
68
|
-
});
|
|
58
|
+
nodes = (0, tsquery_1.query)(sourceFile, WEBPACK_APP_IMPORT_SPECIFIER_SELECTOR);
|
|
69
59
|
if (nodes.length === 0) {
|
|
70
60
|
return webpackConfigContents;
|
|
71
61
|
}
|
|
72
62
|
const importSpecifier = nodes[0];
|
|
73
63
|
webpackConfigContents = `${webpackConfigContents.slice(0, importSpecifier.getStart())}NxAppRspackPlugin${webpackConfigContents.slice(importSpecifier.getEnd())}`;
|
|
74
64
|
// Convert new NxAppWebpackPlugin() to new NxAppRspackPlugin()
|
|
75
|
-
|
|
65
|
+
sourceFile = (0, tsquery_1.ast)(webpackConfigContents);
|
|
76
66
|
const WEBPACK_APP_INSTANTIATION_SELECTOR = 'NewExpression > Identifier[name=NxAppWebpackPlugin]';
|
|
77
|
-
nodes = (0, tsquery_1.
|
|
78
|
-
visitAllChildren: true,
|
|
79
|
-
});
|
|
67
|
+
nodes = (0, tsquery_1.query)(sourceFile, WEBPACK_APP_INSTANTIATION_SELECTOR);
|
|
80
68
|
if (nodes.length === 0) {
|
|
81
69
|
return webpackConfigContents;
|
|
82
70
|
}
|
|
@@ -22,8 +22,8 @@ async function migrateWithMfImport(tree) {
|
|
|
22
22
|
if (!contents.includes('@nx/rspack/module-federation')) {
|
|
23
23
|
return;
|
|
24
24
|
}
|
|
25
|
-
const
|
|
26
|
-
const importNodes = (0, tsquery_1.
|
|
25
|
+
const sourceFile = (0, tsquery_1.ast)(contents);
|
|
26
|
+
const importNodes = (0, tsquery_1.query)(sourceFile, NX_RSPACK_MODULE_FEDERATION_IMPORT_SELECTOR);
|
|
27
27
|
if (importNodes.length === 0) {
|
|
28
28
|
return;
|
|
29
29
|
}
|
|
@@ -490,7 +490,7 @@ async function handleUnknownExecutors(projectName) {
|
|
|
490
490
|
function determineFrameworkAndTarget(tree, options, projectRoot, targets) {
|
|
491
491
|
(0, ensure_typescript_1.ensureTypescript)();
|
|
492
492
|
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
493
|
-
const {
|
|
493
|
+
const { ast, query } = require('@phenomnomnominal/tsquery');
|
|
494
494
|
// First try to infer if the target is node
|
|
495
495
|
if (options.target !== 'node') {
|
|
496
496
|
// Try to infer from jest config if the env is node
|
|
@@ -506,16 +506,16 @@ function determineFrameworkAndTarget(tree, options, projectRoot, targets) {
|
|
|
506
506
|
return { target: options.target, framework: options.framework };
|
|
507
507
|
}
|
|
508
508
|
const appFileContent = tree.read(jestConfigPath, 'utf-8');
|
|
509
|
-
const file =
|
|
509
|
+
const file = ast(appFileContent);
|
|
510
510
|
// find testEnvironment: 'node' in jest config
|
|
511
|
-
const testEnvironment =
|
|
511
|
+
const testEnvironment = query(file, `PropertyAssignment:has(Identifier[name="testEnvironment"]) > StringLiteral[value="node"]`);
|
|
512
512
|
if (testEnvironment.length > 0) {
|
|
513
513
|
return { target: 'node', framework: options.framework };
|
|
514
514
|
}
|
|
515
515
|
if (tree.exists((0, devkit_1.joinPathFragments)(projectRoot, 'src/main.ts'))) {
|
|
516
516
|
const appFileContent = tree.read((0, devkit_1.joinPathFragments)(projectRoot, 'src/main.ts'), 'utf-8');
|
|
517
|
-
const file =
|
|
518
|
-
const hasNestJsDependency =
|
|
517
|
+
const file = ast(appFileContent);
|
|
518
|
+
const hasNestJsDependency = query(file, `ImportDeclaration:has(StringLiteral[value="@nestjs/common"])`);
|
|
519
519
|
if (hasNestJsDependency?.length > 0) {
|
|
520
520
|
return { target: 'node', framework: 'nest' };
|
|
521
521
|
}
|