@nx/rspack 20.2.0-beta.2 → 20.2.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/app-plugin.d.ts +2 -0
- package/app-plugin.js +5 -0
- package/generators.json +10 -0
- package/migrations.json +21 -1
- package/module-federation.d.ts +4 -1
- package/module-federation.js +7 -2
- package/package.json +10 -8
- package/react-plugin.d.ts +1 -0
- package/react-plugin.js +5 -0
- package/src/executors/module-federation-dev-server/module-federation-dev-server.impl.js +5 -7
- package/src/executors/module-federation-ssr-dev-server/module-federation-ssr-dev-server.impl.js +5 -7
- package/src/executors/module-federation-static-server/module-federation-static-server.impl.d.ts +1 -1
- package/src/executors/module-federation-static-server/module-federation-static-server.impl.js +4 -5
- package/src/executors/rspack/schema.d.ts +1 -1
- package/src/executors/rspack/schema.json +1 -1
- package/src/generators/application/application.js +0 -2
- package/src/generators/configuration/configuration.js +0 -2
- package/src/generators/convert-config-to-rspack-plugin/convert-config-to-rspack-plugin.d.ts +7 -0
- package/src/generators/convert-config-to-rspack-plugin/convert-config-to-rspack-plugin.js +92 -0
- package/src/generators/convert-config-to-rspack-plugin/lib/extract-rspack-options.d.ts +6 -0
- package/src/generators/convert-config-to-rspack-plugin/lib/extract-rspack-options.js +106 -0
- package/src/generators/convert-config-to-rspack-plugin/lib/normalize-path-options.d.ts +2 -0
- package/src/generators/convert-config-to-rspack-plugin/lib/normalize-path-options.js +73 -0
- package/src/generators/convert-config-to-rspack-plugin/lib/utils.d.ts +1 -0
- package/src/generators/convert-config-to-rspack-plugin/lib/utils.js +13 -0
- package/src/generators/convert-config-to-rspack-plugin/lib/validate-project.d.ts +9 -0
- package/src/generators/convert-config-to-rspack-plugin/lib/validate-project.js +40 -0
- package/src/generators/convert-config-to-rspack-plugin/schema.json +19 -0
- package/src/generators/convert-to-inferred/__snapshots__/convert-to-inferred.spec.ts.snap +268 -0
- package/src/generators/convert-to-inferred/convert-to-inferred.d.ts +12 -0
- package/src/generators/convert-to-inferred/convert-to-inferred.js +114 -0
- package/src/generators/convert-to-inferred/schema.json +19 -0
- package/src/generators/convert-to-inferred/utils/ast.d.ts +3 -0
- package/src/generators/convert-to-inferred/utils/ast.js +40 -0
- package/src/generators/convert-to-inferred/utils/build-post-target-transformer.d.ts +6 -0
- package/src/generators/convert-to-inferred/utils/build-post-target-transformer.js +210 -0
- package/src/generators/convert-to-inferred/utils/index.d.ts +3 -0
- package/src/generators/convert-to-inferred/utils/index.js +6 -0
- package/src/generators/convert-to-inferred/utils/serve-post-target-transformer.d.ts +6 -0
- package/src/generators/convert-to-inferred/utils/serve-post-target-transformer.js +207 -0
- package/src/generators/convert-to-inferred/utils/types.d.ts +11 -0
- package/src/generators/convert-webpack/lib/transform-cjs.js +5 -5
- package/src/generators/convert-webpack/lib/transform-esm.js +5 -5
- package/src/generators/init/init.js +0 -2
- package/src/index.d.ts +1 -0
- package/src/index.js +1 -0
- package/src/migrations/update-20-2-0/migrate-with-mf-import-to-new-package.d.ts +2 -0
- package/src/migrations/update-20-2-0/migrate-with-mf-import-to-new-package.js +35 -0
- package/src/plugins/nx-app-rspack-plugin/nx-app-rspack-plugin.d.ts +16 -0
- package/src/plugins/nx-app-rspack-plugin/nx-app-rspack-plugin.js +43 -0
- package/src/plugins/nx-react-rspack-plugin/nx-react-rspack-plugin.d.ts +8 -0
- package/src/plugins/nx-react-rspack-plugin/nx-react-rspack-plugin.js +13 -0
- package/src/plugins/use-legacy-nx-plugin/use-legacy-nx-plugin.d.ts +31 -0
- package/src/plugins/use-legacy-nx-plugin/use-legacy-nx-plugin.js +73 -0
- package/src/plugins/utils/apply-base-config.js +3 -0
- package/src/plugins/utils/apply-web-config.d.ts +2 -2
- package/src/plugins/utils/apply-web-config.js +1 -1
- package/src/plugins/utils/plugins/normalize-options.js +1 -1
- package/src/plugins/utils/plugins/nx-tsconfig-paths-rspack-plugin.js +3 -2
- package/src/utils/create-compiler.js +3 -1
- package/src/utils/generator-utils.d.ts +2 -2
- package/src/utils/generator-utils.js +134 -67
- package/src/utils/has-plugin.d.ts +2 -0
- package/src/utils/has-plugin.js +10 -0
- package/src/utils/module-federation/build-static.remotes.d.ts +1 -1
- package/src/utils/versions.d.ts +2 -2
- package/src/utils/versions.js +2 -2
- package/src/utils/module-federation/dependencies.d.ts +0 -6
- package/src/utils/module-federation/dependencies.js +0 -56
- package/src/utils/module-federation/get-remotes-for-host.d.ts +0 -16
- package/src/utils/module-federation/get-remotes-for-host.js +0 -99
- package/src/utils/module-federation/index.d.ts +0 -6
- package/src/utils/module-federation/index.js +0 -9
- package/src/utils/module-federation/models/index.d.ts +0 -47
- package/src/utils/module-federation/package-json.d.ts +0 -8
- package/src/utils/module-federation/package-json.js +0 -12
- package/src/utils/module-federation/parse-static-remotes-config.d.ts +0 -13
- package/src/utils/module-federation/parse-static-remotes-config.js +0 -34
- package/src/utils/module-federation/plugins/runtime-library-control.plugin.d.ts +0 -3
- package/src/utils/module-federation/plugins/runtime-library-control.plugin.js +0 -54
- package/src/utils/module-federation/public-api.d.ts +0 -8
- package/src/utils/module-federation/public-api.js +0 -20
- package/src/utils/module-federation/remotes.d.ts +0 -19
- package/src/utils/module-federation/remotes.js +0 -85
- package/src/utils/module-federation/secondary-entry-points.d.ts +0 -12
- package/src/utils/module-federation/secondary-entry-points.js +0 -104
- package/src/utils/module-federation/share.d.ts +0 -48
- package/src/utils/module-federation/share.js +0 -235
- package/src/utils/module-federation/start-remote-proxies.d.ts +0 -5
- package/src/utils/module-federation/start-remote-proxies.js +0 -45
- package/src/utils/module-federation/start-ssr-remote-proxies.d.ts +0 -5
- package/src/utils/module-federation/start-ssr-remote-proxies.js +0 -59
- package/src/utils/module-federation/typescript.d.ts +0 -4
- package/src/utils/module-federation/typescript.js +0 -53
- package/src/utils/module-federation/with-module-federation/package-json.d.ts +0 -8
- package/src/utils/module-federation/with-module-federation/package-json.js +0 -12
- package/src/utils/module-federation/with-module-federation/utils.d.ts +0 -12
- package/src/utils/module-federation/with-module-federation/utils.js +0 -76
- package/src/utils/module-federation/with-module-federation/with-module-federation-ssr.d.ts +0 -3
- package/src/utils/module-federation/with-module-federation/with-module-federation-ssr.js +0 -62
- package/src/utils/module-federation/with-module-federation/with-module-federation.d.ts +0 -8
- package/src/utils/module-federation/with-module-federation/with-module-federation.js +0 -70
- /package/src/{utils/module-federation/models/index.js → generators/convert-to-inferred/utils/types.js} +0 -0
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.buildPostTargetTransformerFactory = buildPostTargetTransformerFactory;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const plugin_migration_utils_1 = require("@nx/devkit/src/generators/plugin-migrations/plugin-migration-utils");
|
|
6
|
+
const tsquery_1 = require("@phenomnomnominal/tsquery");
|
|
7
|
+
const ts = tslib_1.__importStar(require("typescript"));
|
|
8
|
+
const ast_1 = require("./ast");
|
|
9
|
+
function buildPostTargetTransformerFactory(migrationContext) {
|
|
10
|
+
return function buildPostTargetTransformer(target, tree, projectDetails, inferredTarget) {
|
|
11
|
+
const context = {
|
|
12
|
+
...migrationContext,
|
|
13
|
+
projectName: projectDetails.projectName,
|
|
14
|
+
projectRoot: projectDetails.root,
|
|
15
|
+
};
|
|
16
|
+
const { pluginOptions, rspackConfigPath } = processOptions(target, context);
|
|
17
|
+
updateRspackConfig(tree, rspackConfigPath, pluginOptions);
|
|
18
|
+
if (target.outputs) {
|
|
19
|
+
(0, plugin_migration_utils_1.processTargetOutputs)(target, [], inferredTarget, {
|
|
20
|
+
projectName: projectDetails.projectName,
|
|
21
|
+
projectRoot: projectDetails.root,
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
return target;
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
function processOptions(target, context) {
|
|
28
|
+
const rspackConfig = target.options.rspackConfig;
|
|
29
|
+
delete target.options.rspackConfig;
|
|
30
|
+
const pluginOptions = {
|
|
31
|
+
default: extractPluginOptions(target.options, context),
|
|
32
|
+
};
|
|
33
|
+
if (target.configurations && Object.keys(target.configurations).length) {
|
|
34
|
+
for (const [configName, config] of Object.entries(target.configurations)) {
|
|
35
|
+
pluginOptions[configName] = extractPluginOptions(config, context, configName);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return { pluginOptions, rspackConfigPath: rspackConfig };
|
|
39
|
+
}
|
|
40
|
+
const pathOptions = new Set([
|
|
41
|
+
'index',
|
|
42
|
+
'main',
|
|
43
|
+
'outputPath',
|
|
44
|
+
'polyfills',
|
|
45
|
+
'postcssConfig',
|
|
46
|
+
'tsConfig',
|
|
47
|
+
]);
|
|
48
|
+
const assetsOptions = new Set(['assets', 'scripts', 'styles']);
|
|
49
|
+
function extractPluginOptions(options, context, configName) {
|
|
50
|
+
const pluginOptions = {};
|
|
51
|
+
for (const [key, value] of Object.entries(options)) {
|
|
52
|
+
if (pathOptions.has(key)) {
|
|
53
|
+
pluginOptions[key] = (0, plugin_migration_utils_1.toProjectRelativePath)(value, context.projectRoot);
|
|
54
|
+
delete options[key];
|
|
55
|
+
}
|
|
56
|
+
else if (assetsOptions.has(key)) {
|
|
57
|
+
pluginOptions[key] = value.map((asset) => {
|
|
58
|
+
if (typeof asset === 'string') {
|
|
59
|
+
return (0, plugin_migration_utils_1.toProjectRelativePath)(asset, context.projectRoot);
|
|
60
|
+
}
|
|
61
|
+
asset.input = (0, plugin_migration_utils_1.toProjectRelativePath)(asset.input, context.projectRoot);
|
|
62
|
+
return asset;
|
|
63
|
+
});
|
|
64
|
+
delete options[key];
|
|
65
|
+
}
|
|
66
|
+
else if (key === 'fileReplacements') {
|
|
67
|
+
pluginOptions.fileReplacements = value.map((replacement) => ({
|
|
68
|
+
replace: (0, plugin_migration_utils_1.toProjectRelativePath)(replacement.replace, context.projectRoot),
|
|
69
|
+
with: (0, plugin_migration_utils_1.toProjectRelativePath)(replacement.with, context.projectRoot),
|
|
70
|
+
}));
|
|
71
|
+
delete options.fileReplacements;
|
|
72
|
+
}
|
|
73
|
+
else if (key === 'additionalEntryPoints') {
|
|
74
|
+
pluginOptions.additionalEntryPoints = value.map((entryPoint) => {
|
|
75
|
+
entryPoint.entryPath = (0, plugin_migration_utils_1.toProjectRelativePath)(entryPoint.entryPath, context.projectRoot);
|
|
76
|
+
return entryPoint;
|
|
77
|
+
});
|
|
78
|
+
delete options.additionalEntryPoints;
|
|
79
|
+
}
|
|
80
|
+
else if (key === 'memoryLimit') {
|
|
81
|
+
pluginOptions.memoryLimit = value;
|
|
82
|
+
const serveMemoryLimit = getMemoryLimitFromServeTarget(context, configName);
|
|
83
|
+
if (serveMemoryLimit) {
|
|
84
|
+
pluginOptions.memoryLimit = Math.max(serveMemoryLimit, value);
|
|
85
|
+
context.logger.addLog({
|
|
86
|
+
executorName: '@nx/rspack:rspack',
|
|
87
|
+
log: `The "memoryLimit" option was set in both the serve and build configurations. The migration set the higher value to the build configuration and removed the option from the serve configuration.`,
|
|
88
|
+
project: context.projectName,
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
delete options.memoryLimit;
|
|
92
|
+
}
|
|
93
|
+
else if (key === 'standardRspackConfigFunction') {
|
|
94
|
+
delete options.standardRspackConfigFunction;
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
pluginOptions[key] = value;
|
|
98
|
+
delete options[key];
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
return pluginOptions;
|
|
102
|
+
}
|
|
103
|
+
function updateRspackConfig(tree, rspackConfig, pluginOptions) {
|
|
104
|
+
let sourceFile;
|
|
105
|
+
let rspackConfigText;
|
|
106
|
+
const updateSources = () => {
|
|
107
|
+
rspackConfigText = tree.read(rspackConfig, 'utf-8');
|
|
108
|
+
sourceFile = tsquery_1.tsquery.ast(rspackConfigText);
|
|
109
|
+
};
|
|
110
|
+
updateSources();
|
|
111
|
+
setOptionsInRspackConfig(tree, rspackConfigText, sourceFile, rspackConfig, pluginOptions);
|
|
112
|
+
updateSources();
|
|
113
|
+
setOptionsInNxRspackPlugin(tree, rspackConfigText, sourceFile, rspackConfig);
|
|
114
|
+
updateSources();
|
|
115
|
+
setOptionsInLegacyNxPlugin(tree, rspackConfigText, sourceFile, rspackConfig);
|
|
116
|
+
}
|
|
117
|
+
function setOptionsInRspackConfig(tree, text, sourceFile, rspackConfig, pluginOptions) {
|
|
118
|
+
const { default: defaultOptions, ...configurationOptions } = pluginOptions;
|
|
119
|
+
const optionsSelector = 'VariableStatement:has(VariableDeclaration:has(Identifier[name=options]))';
|
|
120
|
+
const optionsVariable = (0, tsquery_1.tsquery)(sourceFile, optionsSelector)[0];
|
|
121
|
+
// This is assuming the `options` variable will be available since it's what the
|
|
122
|
+
// `convert-config-to-rspack-plugin` generates
|
|
123
|
+
let defaultOptionsObject;
|
|
124
|
+
const optionsObject = (0, tsquery_1.tsquery)(optionsVariable, 'ObjectLiteralExpression')[0];
|
|
125
|
+
if (optionsObject.properties.length === 0) {
|
|
126
|
+
defaultOptionsObject = ts.factory.createObjectLiteralExpression(Object.entries(defaultOptions).map(([key, value]) => (0, ast_1.toPropertyAssignment)(key, value)));
|
|
127
|
+
}
|
|
128
|
+
else {
|
|
129
|
+
// filter out the default options that are already in the options object
|
|
130
|
+
// the existing options override the options from the project.json file
|
|
131
|
+
const filteredDefaultOptions = Object.entries(defaultOptions).filter(([key]) => !optionsObject.properties.some((property) => ts.isPropertyAssignment(property) &&
|
|
132
|
+
ts.isIdentifier(property.name) &&
|
|
133
|
+
property.name.text === key));
|
|
134
|
+
defaultOptionsObject = ts.factory.createObjectLiteralExpression([
|
|
135
|
+
...optionsObject.properties,
|
|
136
|
+
...filteredDefaultOptions.map(([key, value]) => (0, ast_1.toPropertyAssignment)(key, value)),
|
|
137
|
+
]);
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* const configValues = {
|
|
141
|
+
* build: {
|
|
142
|
+
* default: { ... },
|
|
143
|
+
* configuration1: { ... },
|
|
144
|
+
* configuration2: { ... },
|
|
145
|
+
* }
|
|
146
|
+
*/
|
|
147
|
+
const configValuesVariable = ts.factory.createVariableStatement(undefined, ts.factory.createVariableDeclarationList([
|
|
148
|
+
ts.factory.createVariableDeclaration('configValues', undefined, undefined, ts.factory.createObjectLiteralExpression([
|
|
149
|
+
ts.factory.createPropertyAssignment('build', ts.factory.createObjectLiteralExpression([
|
|
150
|
+
ts.factory.createPropertyAssignment('default', defaultOptionsObject),
|
|
151
|
+
...(configurationOptions
|
|
152
|
+
? Object.entries(configurationOptions).map(([key, value]) => ts.factory.createPropertyAssignment(key, ts.factory.createObjectLiteralExpression(Object.entries(value).map(([key, value]) => (0, ast_1.toPropertyAssignment)(key, value)))))
|
|
153
|
+
: []),
|
|
154
|
+
])),
|
|
155
|
+
], true)),
|
|
156
|
+
], ts.NodeFlags.Const));
|
|
157
|
+
text = `${text.slice(0, optionsVariable.getStart())}
|
|
158
|
+
// These options were migrated by @nx/rspack:convert-to-inferred from
|
|
159
|
+
// the project.json file and merged with the options in this file
|
|
160
|
+
${ts
|
|
161
|
+
.createPrinter()
|
|
162
|
+
.printNode(ts.EmitHint.Unspecified, configValuesVariable, sourceFile)}
|
|
163
|
+
|
|
164
|
+
// Determine the correct configValue to use based on the configuration
|
|
165
|
+
const configuration = process.env.NX_TASK_TARGET_CONFIGURATION || 'default';
|
|
166
|
+
|
|
167
|
+
const buildOptions = {
|
|
168
|
+
...configValues.build.default,
|
|
169
|
+
...configValues.build[configuration],
|
|
170
|
+
};${text.slice(optionsVariable.getEnd())}`;
|
|
171
|
+
// These are comments written by the `convert-config-to-rspack-plugin` that are no longer needed
|
|
172
|
+
text = text
|
|
173
|
+
.replace(`// This file was migrated using @nx/rspack:convert-config-to-rspack-plugin from your './rspack.config.old.js'`, '')
|
|
174
|
+
.replace('// Please check that the options here are correct as they were moved from the old rspack.config.js to this file.', '');
|
|
175
|
+
tree.write(rspackConfig, text);
|
|
176
|
+
}
|
|
177
|
+
function setOptionsInNxRspackPlugin(tree, text, sourceFile, rspackConfig) {
|
|
178
|
+
const nxAppRspackPluginSelector = 'PropertyAssignment:has(Identifier[name=plugins]) NewExpression:has(Identifier[name=NxAppRspackPlugin])';
|
|
179
|
+
const nxAppRspackPlugin = (0, tsquery_1.tsquery)(sourceFile, nxAppRspackPluginSelector)[0];
|
|
180
|
+
// the NxAppRspackPlugin must exists, otherwise, the migration doesn't run and we wouldn't reach this point
|
|
181
|
+
const updatedNxAppRspackPlugin = ts.factory.updateNewExpression(nxAppRspackPlugin, nxAppRspackPlugin.expression, undefined, [ts.factory.createIdentifier('buildOptions')]);
|
|
182
|
+
text = `${text.slice(0, nxAppRspackPlugin.getStart())}${ts
|
|
183
|
+
.createPrinter()
|
|
184
|
+
.printNode(ts.EmitHint.Unspecified, updatedNxAppRspackPlugin, sourceFile)}${text.slice(nxAppRspackPlugin.getEnd())}`;
|
|
185
|
+
tree.write(rspackConfig, text);
|
|
186
|
+
}
|
|
187
|
+
function setOptionsInLegacyNxPlugin(tree, text, sourceFile, rspackConfig) {
|
|
188
|
+
const legacyNxPluginSelector = 'AwaitExpression CallExpression:has(Identifier[name=useLegacyNxPlugin])';
|
|
189
|
+
const legacyNxPlugin = (0, tsquery_1.tsquery)(sourceFile, legacyNxPluginSelector)[0];
|
|
190
|
+
// we're assuming the `useLegacyNxPlugin` function is being called since it's what the `convert-config-to-rspack-plugin` generates
|
|
191
|
+
// we've already "ensured" that the `convert-config-to-rspack-plugin` was run by checking for the `NxAppRspackPlugin` in the project validation
|
|
192
|
+
const updatedLegacyNxPlugin = ts.factory.updateCallExpression(legacyNxPlugin, legacyNxPlugin.expression, undefined, [legacyNxPlugin.arguments[0], ts.factory.createIdentifier('buildOptions')]);
|
|
193
|
+
text = `${text.slice(0, legacyNxPlugin.getStart())}${ts
|
|
194
|
+
.createPrinter()
|
|
195
|
+
.printNode(ts.EmitHint.Unspecified, updatedLegacyNxPlugin, sourceFile)}${text.slice(legacyNxPlugin.getEnd())}`;
|
|
196
|
+
tree.write(rspackConfig, text);
|
|
197
|
+
}
|
|
198
|
+
function getMemoryLimitFromServeTarget(context, configName) {
|
|
199
|
+
const { targets } = context.projectGraph.nodes[context.projectName].data;
|
|
200
|
+
const serveTarget = Object.values(targets).find((target) => target.executor === '@nx/rspack:dev-server' ||
|
|
201
|
+
target.executor === '@nrwl/web:dev-server');
|
|
202
|
+
if (!serveTarget) {
|
|
203
|
+
return undefined;
|
|
204
|
+
}
|
|
205
|
+
if (configName && serveTarget.configurations?.[configName]) {
|
|
206
|
+
return (serveTarget.configurations[configName].options?.memoryLimit ??
|
|
207
|
+
serveTarget.options?.memoryLimit);
|
|
208
|
+
}
|
|
209
|
+
return serveTarget.options?.memoryLimit;
|
|
210
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
tslib_1.__exportStar(require("./build-post-target-transformer"), exports);
|
|
5
|
+
tslib_1.__exportStar(require("./serve-post-target-transformer"), exports);
|
|
6
|
+
tslib_1.__exportStar(require("./types"), exports);
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { type TargetConfiguration, type Tree } from '@nx/devkit';
|
|
2
|
+
import type { MigrationContext } from './types';
|
|
3
|
+
export declare function servePostTargetTransformerFactory(migrationContext: MigrationContext): (target: TargetConfiguration, tree: Tree, projectDetails: {
|
|
4
|
+
projectName: string;
|
|
5
|
+
root: string;
|
|
6
|
+
}, inferredTarget: TargetConfiguration) => Promise<TargetConfiguration>;
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.servePostTargetTransformerFactory = servePostTargetTransformerFactory;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const devkit_1 = require("@nx/devkit");
|
|
6
|
+
const plugin_migration_utils_1 = require("@nx/devkit/src/generators/plugin-migrations/plugin-migration-utils");
|
|
7
|
+
const tsquery_1 = require("@phenomnomnominal/tsquery");
|
|
8
|
+
const path_1 = require("path");
|
|
9
|
+
const ts = tslib_1.__importStar(require("typescript"));
|
|
10
|
+
const serve_path_1 = require("../../../executors/dev-server/lib/serve-path");
|
|
11
|
+
const ast_1 = require("./ast");
|
|
12
|
+
function servePostTargetTransformerFactory(migrationContext) {
|
|
13
|
+
return async function servePostTargetTransformer(target, tree, projectDetails, inferredTarget) {
|
|
14
|
+
const context = {
|
|
15
|
+
...migrationContext,
|
|
16
|
+
projectName: projectDetails.projectName,
|
|
17
|
+
projectRoot: projectDetails.root,
|
|
18
|
+
};
|
|
19
|
+
const { devServerOptions, rspackConfigPath } = await processOptions(tree, target, context);
|
|
20
|
+
updateRspackConfig(tree, rspackConfigPath, devServerOptions, context);
|
|
21
|
+
if (target.outputs) {
|
|
22
|
+
(0, plugin_migration_utils_1.processTargetOutputs)(target, [], inferredTarget, {
|
|
23
|
+
projectName: projectDetails.projectName,
|
|
24
|
+
projectRoot: projectDetails.root,
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
return target;
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
async function processOptions(tree, target, context) {
|
|
31
|
+
const executorContext = {
|
|
32
|
+
cwd: process.cwd(),
|
|
33
|
+
nxJsonConfiguration: (0, devkit_1.readJson)(tree, 'nx.json'),
|
|
34
|
+
projectGraph: context.projectGraph,
|
|
35
|
+
projectName: context.projectName,
|
|
36
|
+
projectsConfigurations: Object.entries(context.projectGraph.nodes).reduce((acc, [projectName, project]) => {
|
|
37
|
+
acc.projects[projectName] = project.data;
|
|
38
|
+
return acc;
|
|
39
|
+
}, { version: 1, projects: {} }),
|
|
40
|
+
root: context.workspaceRoot,
|
|
41
|
+
};
|
|
42
|
+
const buildTarget = (0, devkit_1.parseTargetString)(target.options.buildTarget, executorContext);
|
|
43
|
+
const buildOptions = (0, devkit_1.readTargetOptions)(buildTarget, executorContext);
|
|
44
|
+
// it must exist, we validated it in the project filter
|
|
45
|
+
const rspackConfigPath = buildOptions.rspackConfig;
|
|
46
|
+
const defaultOptions = extractDevServerOptions(target.options, context);
|
|
47
|
+
applyDefaults(defaultOptions, buildOptions);
|
|
48
|
+
const devServerOptions = {
|
|
49
|
+
default: defaultOptions,
|
|
50
|
+
};
|
|
51
|
+
if (target.configurations && Object.keys(target.configurations).length) {
|
|
52
|
+
for (const [configName, config] of Object.entries(target.configurations)) {
|
|
53
|
+
devServerOptions[configName] = extractDevServerOptions(config, context);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return { devServerOptions, rspackConfigPath: rspackConfigPath };
|
|
57
|
+
}
|
|
58
|
+
function extractDevServerOptions(options, context) {
|
|
59
|
+
const devServerOptions = {};
|
|
60
|
+
for (const [key, value] of Object.entries(options)) {
|
|
61
|
+
if (key === 'ssl' || key === 'sslCert' || key === 'sslKey') {
|
|
62
|
+
if (key === 'ssl' || 'ssl' in options) {
|
|
63
|
+
if (options.ssl) {
|
|
64
|
+
devServerOptions.server = { type: 'https' };
|
|
65
|
+
if (options.sslCert && options.sslKey) {
|
|
66
|
+
devServerOptions.server.options = {};
|
|
67
|
+
devServerOptions.server.options.cert = (0, plugin_migration_utils_1.toProjectRelativePath)(options.sslCert, context.projectRoot);
|
|
68
|
+
devServerOptions.server.options.key = (0, plugin_migration_utils_1.toProjectRelativePath)(options.sslKey, context.projectRoot);
|
|
69
|
+
}
|
|
70
|
+
else if (options.sslCert) {
|
|
71
|
+
context.logger.addLog({
|
|
72
|
+
executorName: '@nx/rspack:dev-server',
|
|
73
|
+
log: 'The "sslCert" option was set but "sslKey" was missing and "ssl" was set to "true". This means that "sslCert" was ignored by the executor. It has been removed from the options.',
|
|
74
|
+
project: context.projectName,
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
else if (options.sslKey) {
|
|
78
|
+
context.logger.addLog({
|
|
79
|
+
executorName: '@nx/rspack:dev-server',
|
|
80
|
+
log: 'The "sslKey" option was set but "sslCert" was missing and "ssl" was set to "true". This means that "sslKey" was ignored by the executor. It has been removed from the options.',
|
|
81
|
+
project: context.projectName,
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
else if (options.sslCert || options.sslKey) {
|
|
86
|
+
context.logger.addLog({
|
|
87
|
+
executorName: '@nx/rspack:dev-server',
|
|
88
|
+
log: 'The "sslCert" and/or "sslKey" were set with "ssl" set to "false". This means they were ignored by the executor. They have been removed from the options.',
|
|
89
|
+
project: context.projectName,
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
delete options.ssl;
|
|
93
|
+
delete options.sslCert;
|
|
94
|
+
delete options.sslKey;
|
|
95
|
+
}
|
|
96
|
+
else if (options.sslCert || options.sslKey) {
|
|
97
|
+
context.logger.addLog({
|
|
98
|
+
executorName: '@nx/rspack:dev-server',
|
|
99
|
+
log: 'The "sslCert" and/or "sslKey" were set but the "ssl" was not set. This means they were ignored by the executor. They have been removed from the options.',
|
|
100
|
+
project: context.projectName,
|
|
101
|
+
});
|
|
102
|
+
delete options.sslCert;
|
|
103
|
+
delete options.sslKey;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
else if (key === 'buildTarget') {
|
|
107
|
+
delete options.buildTarget;
|
|
108
|
+
}
|
|
109
|
+
else {
|
|
110
|
+
devServerOptions[key] = value;
|
|
111
|
+
delete options[key];
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
return devServerOptions;
|
|
115
|
+
}
|
|
116
|
+
function applyDefaults(options, buildOptions) {
|
|
117
|
+
if (options.port === undefined) {
|
|
118
|
+
options.port = 4200;
|
|
119
|
+
}
|
|
120
|
+
options.headers = { 'Access-Control-Allow-Origin': '*' };
|
|
121
|
+
const servePath = (0, serve_path_1.buildServePath)(buildOptions);
|
|
122
|
+
options.historyApiFallback = {
|
|
123
|
+
index: buildOptions.index && `${servePath}${(0, path_1.basename)(buildOptions.index)}`,
|
|
124
|
+
disableDotRule: true,
|
|
125
|
+
htmlAcceptHeaders: ['text/html', 'application/xhtml+xml'],
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
function getProxyConfig(root, proxyConfig) {
|
|
129
|
+
const proxyPath = (0, path_1.resolve)(root, proxyConfig);
|
|
130
|
+
return require(proxyPath);
|
|
131
|
+
}
|
|
132
|
+
function updateRspackConfig(tree, rspackConfigPath, devServerOptions, context) {
|
|
133
|
+
let sourceFile;
|
|
134
|
+
let rspackConfigText;
|
|
135
|
+
const updateSources = () => {
|
|
136
|
+
rspackConfigText = tree.read(rspackConfigPath, 'utf-8');
|
|
137
|
+
sourceFile = tsquery_1.tsquery.ast(rspackConfigText);
|
|
138
|
+
};
|
|
139
|
+
updateSources();
|
|
140
|
+
setOptionsInRspackConfig(tree, rspackConfigText, sourceFile, rspackConfigPath, devServerOptions);
|
|
141
|
+
updateSources();
|
|
142
|
+
setDevServerOptionsInRspackConfig(tree, rspackConfigText, sourceFile, rspackConfigPath, context);
|
|
143
|
+
}
|
|
144
|
+
function setOptionsInRspackConfig(tree, text, sourceFile, rspackConfigPath, devServerOptions) {
|
|
145
|
+
const { default: defaultOptions, ...configurationOptions } = devServerOptions;
|
|
146
|
+
const configValuesSelector = 'VariableDeclaration:has(Identifier[name=configValues]) ObjectLiteralExpression';
|
|
147
|
+
const configValuesObject = (0, tsquery_1.tsquery)(sourceFile, configValuesSelector)[0];
|
|
148
|
+
// configValues must exist at this point, we added it when processing the build target
|
|
149
|
+
/**
|
|
150
|
+
* const configValues = {
|
|
151
|
+
* ...
|
|
152
|
+
* serve: {
|
|
153
|
+
* default: { ... },
|
|
154
|
+
* configuration1: { ... },
|
|
155
|
+
* ...
|
|
156
|
+
* },
|
|
157
|
+
*/
|
|
158
|
+
const updatedConfigValuesObject = ts.factory.updateObjectLiteralExpression(configValuesObject, [
|
|
159
|
+
...configValuesObject.properties,
|
|
160
|
+
ts.factory.createPropertyAssignment('serve', ts.factory.createObjectLiteralExpression([
|
|
161
|
+
ts.factory.createPropertyAssignment('default', ts.factory.createObjectLiteralExpression(Object.entries(defaultOptions).map(([key, value]) => (0, ast_1.toPropertyAssignment)(key, value)))),
|
|
162
|
+
...(configurationOptions
|
|
163
|
+
? Object.entries(configurationOptions).map(([key, value]) => ts.factory.createPropertyAssignment(key, ts.factory.createObjectLiteralExpression(Object.entries(value).map(([key, value]) => (0, ast_1.toPropertyAssignment)(key, value)))))
|
|
164
|
+
: []),
|
|
165
|
+
])),
|
|
166
|
+
]);
|
|
167
|
+
text = `${text.slice(0, configValuesObject.getStart())}${ts
|
|
168
|
+
.createPrinter()
|
|
169
|
+
.printNode(ts.EmitHint.Unspecified, updatedConfigValuesObject, sourceFile)}${text.slice(configValuesObject.getEnd())}`;
|
|
170
|
+
tree.write(rspackConfigPath, text);
|
|
171
|
+
sourceFile = tsquery_1.tsquery.ast(text);
|
|
172
|
+
const buildOptionsSelector = 'VariableStatement:has(VariableDeclaration:has(Identifier[name=buildOptions]))';
|
|
173
|
+
const buildOptionsStatement = (0, tsquery_1.tsquery)(sourceFile, buildOptionsSelector)[0];
|
|
174
|
+
text = `${text.slice(0, buildOptionsStatement.getEnd())}
|
|
175
|
+
const devServerOptions = {
|
|
176
|
+
...configValues.serve.default,
|
|
177
|
+
...configValues.serve[configuration],
|
|
178
|
+
};${text.slice(buildOptionsStatement.getEnd())}`;
|
|
179
|
+
tree.write(rspackConfigPath, text);
|
|
180
|
+
}
|
|
181
|
+
function setDevServerOptionsInRspackConfig(tree, text, sourceFile, rspackConfigPath, context) {
|
|
182
|
+
const rspackConfigDevServerSelector = 'ObjectLiteralExpression > PropertyAssignment:has(Identifier[name=devServer])';
|
|
183
|
+
const rspackConfigDevServer = (0, tsquery_1.tsquery)(sourceFile, rspackConfigDevServerSelector)[0];
|
|
184
|
+
if (rspackConfigDevServer) {
|
|
185
|
+
context.logger.addLog({
|
|
186
|
+
executorName: '@nx/rspack:dev-server',
|
|
187
|
+
log: `The "devServer" option is already set in the rspack config. The migration doesn't support updating it. Please review it and make any necessary changes manually.`,
|
|
188
|
+
project: context.projectName,
|
|
189
|
+
});
|
|
190
|
+
text = `${text.slice(0, rspackConfigDevServer.getStart())}// This is the untouched "devServer" option from the original rspack config. Please review it and make any necessary changes manually.
|
|
191
|
+
${text.slice(rspackConfigDevServer.getStart())}`;
|
|
192
|
+
tree.write(rspackConfigPath, text);
|
|
193
|
+
// If the devServer property already exists, we don't know how to merge the
|
|
194
|
+
// options, so we leave it as is.
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
const rspackConfigSelector = 'ObjectLiteralExpression:has(PropertyAssignment:has(Identifier[name=plugins]))';
|
|
198
|
+
const rspackConfig = (0, tsquery_1.tsquery)(sourceFile, rspackConfigSelector)[0];
|
|
199
|
+
const updatedRspackConfig = ts.factory.updateObjectLiteralExpression(rspackConfig, [
|
|
200
|
+
ts.factory.createPropertyAssignment('devServer', ts.factory.createIdentifier('devServerOptions')),
|
|
201
|
+
...rspackConfig.properties,
|
|
202
|
+
]);
|
|
203
|
+
text = `${text.slice(0, rspackConfig.getStart())}${ts
|
|
204
|
+
.createPrinter()
|
|
205
|
+
.printNode(ts.EmitHint.Unspecified, updatedRspackConfig, sourceFile)}${text.slice(rspackConfig.getEnd())}`;
|
|
206
|
+
tree.write(rspackConfigPath, text);
|
|
207
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { ProjectGraph } from '@nx/devkit';
|
|
2
|
+
import type { AggregatedLog } from '@nx/devkit/src/generators/plugin-migrations/aggregate-log-util';
|
|
3
|
+
export type MigrationContext = {
|
|
4
|
+
logger: AggregatedLog;
|
|
5
|
+
projectGraph: ProjectGraph;
|
|
6
|
+
workspaceRoot: string;
|
|
7
|
+
};
|
|
8
|
+
export type TransformerContext = MigrationContext & {
|
|
9
|
+
projectName: string;
|
|
10
|
+
projectRoot: string;
|
|
11
|
+
};
|
|
@@ -119,14 +119,14 @@ function transformModuleFederationConfig(tree, configPath, scope) {
|
|
|
119
119
|
if (configContents.charAt(endIndex) === ',') {
|
|
120
120
|
endIndex++;
|
|
121
121
|
}
|
|
122
|
-
const newContents = `const { ModuleFederationConfig } = require('@nx/
|
|
122
|
+
const newContents = `const { ModuleFederationConfig } = require('@nx/module-federation');
|
|
123
123
|
${configContents.slice(0, startIndex)}${configContents.slice(endIndex)}`;
|
|
124
124
|
tree.write(configPath, newContents);
|
|
125
125
|
}
|
|
126
126
|
function transformWithModuleFederation(tree, configPath, scope) {
|
|
127
127
|
const configContents = tree.read(configPath, 'utf-8');
|
|
128
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}/
|
|
129
|
+
const HAS_WITH_MODULE_FEDERATION_FROM_NX_REACT = `VariableDeclaration:has(Identifier[name=withModuleFederation]) > CallExpression:has(Identifier[name=require]) StringLiteral[value=${scope}/module-federation/webpack]`;
|
|
130
130
|
const nodes = (0, tsquery_1.tsquery)(ast, HAS_WITH_MODULE_FEDERATION_FROM_NX_REACT);
|
|
131
131
|
if (nodes.length === 0) {
|
|
132
132
|
return;
|
|
@@ -141,14 +141,14 @@ function transformWithModuleFederation(tree, configPath, scope) {
|
|
|
141
141
|
if (configContents.charAt(endIndex) === ',') {
|
|
142
142
|
endIndex++;
|
|
143
143
|
}
|
|
144
|
-
const newContents = `const { withModuleFederation } = require('@nx/
|
|
144
|
+
const newContents = `const { withModuleFederation } = require('@nx/module-federation/rspack');
|
|
145
145
|
${configContents.slice(0, startIndex)}${configContents.slice(endIndex)}`;
|
|
146
146
|
tree.write(configPath, newContents);
|
|
147
147
|
}
|
|
148
148
|
function transformWithModuleFederationSSR(tree, configPath, scope) {
|
|
149
149
|
const configContents = tree.read(configPath, 'utf-8');
|
|
150
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}/
|
|
151
|
+
const HAS_WITH_MODULE_FEDERATION_FROM_NX_REACT = `VariableDeclaration:has(Identifier[name=withModuleFederationForSSR]) > CallExpression:has(Identifier[name=require]) StringLiteral[value=${scope}/module-federation/webpack]`;
|
|
152
152
|
const nodes = (0, tsquery_1.tsquery)(ast, HAS_WITH_MODULE_FEDERATION_FROM_NX_REACT);
|
|
153
153
|
if (nodes.length === 0) {
|
|
154
154
|
return;
|
|
@@ -163,7 +163,7 @@ function transformWithModuleFederationSSR(tree, configPath, scope) {
|
|
|
163
163
|
if (configContents.charAt(endIndex) === ',') {
|
|
164
164
|
endIndex++;
|
|
165
165
|
}
|
|
166
|
-
const newContents = `const { withModuleFederationForSSR } = require('@nx/
|
|
166
|
+
const newContents = `const { withModuleFederationForSSR } = require('@nx/module-federation/rspack');
|
|
167
167
|
${configContents.slice(0, startIndex)}${configContents.slice(endIndex)}`;
|
|
168
168
|
tree.write(configPath, newContents);
|
|
169
169
|
}
|
|
@@ -104,7 +104,7 @@ function transformWithReact(tree, configPath, scope) {
|
|
|
104
104
|
function transformWithModuleFederation(tree, configPath, scope) {
|
|
105
105
|
const configContents = tree.read(configPath, 'utf-8');
|
|
106
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}/
|
|
107
|
+
const HAS_WITH_MODULE_FEDERATION_FROM_NX_REACT = `ImportDeclaration:has(Identifier[name=withModuleFederation]) > StringLiteral[value=${scope}/module-federation/webpack]`;
|
|
108
108
|
const nodes = (0, tsquery_1.tsquery)(ast, HAS_WITH_MODULE_FEDERATION_FROM_NX_REACT);
|
|
109
109
|
if (nodes.length === 0) {
|
|
110
110
|
return;
|
|
@@ -119,7 +119,7 @@ function transformWithModuleFederation(tree, configPath, scope) {
|
|
|
119
119
|
if (configContents.charAt(endIndex) === ',') {
|
|
120
120
|
endIndex++;
|
|
121
121
|
}
|
|
122
|
-
const newContents = `import { withModuleFederation } from '@nx/
|
|
122
|
+
const newContents = `import { withModuleFederation } from '@nx/module-federation/rspack';
|
|
123
123
|
${configContents.slice(0, startIndex)}${configContents.slice(endIndex)}`;
|
|
124
124
|
tree.write(configPath, newContents);
|
|
125
125
|
}
|
|
@@ -141,14 +141,14 @@ function transformModuleFederationConfig(tree, configPath, scope) {
|
|
|
141
141
|
if (configContents.charAt(endIndex) === ',') {
|
|
142
142
|
endIndex++;
|
|
143
143
|
}
|
|
144
|
-
const newContents = `import { ModuleFederationConfig } from '@nx/
|
|
144
|
+
const newContents = `import { ModuleFederationConfig } from '@nx/module-federation';
|
|
145
145
|
${configContents.slice(0, startIndex)}${configContents.slice(endIndex)}`;
|
|
146
146
|
tree.write(configPath, newContents);
|
|
147
147
|
}
|
|
148
148
|
function transformWithModuleFederationSSR(tree, configPath, scope) {
|
|
149
149
|
const configContents = tree.read(configPath, 'utf-8');
|
|
150
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}/
|
|
151
|
+
const HAS_WITH_MODULE_FEDERATION_FROM_NX_REACT = `ImportDeclaration:has(Identifier[name=withModuleFederationForSSR]) > StringLiteral[value=${scope}/module-federation/webpack]`;
|
|
152
152
|
const nodes = (0, tsquery_1.tsquery)(ast, HAS_WITH_MODULE_FEDERATION_FROM_NX_REACT);
|
|
153
153
|
if (nodes.length === 0) {
|
|
154
154
|
return;
|
|
@@ -163,7 +163,7 @@ function transformWithModuleFederationSSR(tree, configPath, scope) {
|
|
|
163
163
|
if (configContents.charAt(endIndex) === ',') {
|
|
164
164
|
endIndex++;
|
|
165
165
|
}
|
|
166
|
-
const newContents = `import { withModuleFederationForSSR } from '@nx/
|
|
166
|
+
const newContents = `import { withModuleFederationForSSR } from '@nx/module-federation/rspack';
|
|
167
167
|
${configContents.slice(0, startIndex)}${configContents.slice(endIndex)}`;
|
|
168
168
|
tree.write(configPath, newContents);
|
|
169
169
|
}
|
|
@@ -5,11 +5,9 @@ exports.rspackInitGenerator = rspackInitGenerator;
|
|
|
5
5
|
const devkit_1 = require("@nx/devkit");
|
|
6
6
|
const add_plugin_1 = require("@nx/devkit/src/utils/add-plugin");
|
|
7
7
|
const js_1 = require("@nx/js");
|
|
8
|
-
const ts_solution_setup_1 = require("@nx/js/src/utils/typescript/ts-solution-setup");
|
|
9
8
|
const plugin_1 = require("../../../plugin");
|
|
10
9
|
const versions_1 = require("../../utils/versions");
|
|
11
10
|
async function rspackInitGenerator(tree, schema) {
|
|
12
|
-
(0, ts_solution_setup_1.assertNotUsingTsSolutionSetup)(tree, 'rspack', 'init');
|
|
13
11
|
const tasks = [];
|
|
14
12
|
const nxJson = (0, devkit_1.readNxJson)(tree);
|
|
15
13
|
const addPluginDefault = process.env.NX_ADD_PLUGINS !== 'false' &&
|
package/src/index.d.ts
CHANGED
package/src/index.js
CHANGED
|
@@ -7,3 +7,4 @@ tslib_1.__exportStar(require("./utils/config"), exports);
|
|
|
7
7
|
tslib_1.__exportStar(require("./utils/with-nx"), exports);
|
|
8
8
|
tslib_1.__exportStar(require("./utils/with-react"), exports);
|
|
9
9
|
tslib_1.__exportStar(require("./utils/with-web"), exports);
|
|
10
|
+
tslib_1.__exportStar(require("./plugins/use-legacy-nx-plugin/use-legacy-nx-plugin"), exports);
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = migrateWithMfImport;
|
|
4
|
+
const devkit_1 = require("@nx/devkit");
|
|
5
|
+
const executor_options_utils_1 = require("@nx/devkit/src/generators/executor-options-utils");
|
|
6
|
+
const tsquery_1 = require("@phenomnomnominal/tsquery");
|
|
7
|
+
const NX_RSPACK_MODULE_FEDERATION_IMPORT_SELECTOR = 'ImportDeclaration > StringLiteral[value=@nx/rspack/module-federation], VariableStatement CallExpression:has(Identifier[name=require]) > StringLiteral[value=@nx/rspack/module-federation]';
|
|
8
|
+
const NEW_IMPORT_PATH = `'@nx/module-federation/rspack'`;
|
|
9
|
+
async function migrateWithMfImport(tree) {
|
|
10
|
+
const projects = new Set();
|
|
11
|
+
(0, executor_options_utils_1.forEachExecutorOptions)(tree, '@nx/rspack:module-federation-dev-server', (options, project, target) => {
|
|
12
|
+
const projectConfig = (0, devkit_1.readProjectConfiguration)(tree, project);
|
|
13
|
+
projects.add(projectConfig.root);
|
|
14
|
+
});
|
|
15
|
+
for (const projectRoot of projects) {
|
|
16
|
+
(0, devkit_1.visitNotIgnoredFiles)(tree, projectRoot, (filePath) => {
|
|
17
|
+
if (!filePath.endsWith('.ts') && !filePath.endsWith('.js')) {
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
let contents = tree.read(filePath, 'utf-8');
|
|
21
|
+
if (!contents.includes('@nx/rspack/module-federation')) {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
const ast = tsquery_1.tsquery.ast(contents);
|
|
25
|
+
const importNodes = (0, tsquery_1.tsquery)(ast, NX_RSPACK_MODULE_FEDERATION_IMPORT_SELECTOR);
|
|
26
|
+
if (importNodes.length === 0) {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
const importPathNode = importNodes[0];
|
|
30
|
+
contents = `${contents.slice(0, importPathNode.getStart())}${NEW_IMPORT_PATH}${contents.slice(importPathNode.getEnd())}`;
|
|
31
|
+
tree.write(filePath, contents);
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
await (0, devkit_1.formatFiles)(tree);
|
|
35
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Compiler } from '@rspack/core';
|
|
2
|
+
import type { NxAppRspackPluginOptions } from '../utils/models';
|
|
3
|
+
/**
|
|
4
|
+
* This plugin provides features to build Node and Web applications.
|
|
5
|
+
* - TS Support (including tsconfig paths
|
|
6
|
+
* - Assets handling
|
|
7
|
+
* - Stylesheets handling
|
|
8
|
+
* - index.html and package.json generation
|
|
9
|
+
*
|
|
10
|
+
* Web-only features, such as stylesheets and images, are only supported when `target` is `web` or `webworker`.
|
|
11
|
+
*/
|
|
12
|
+
export declare class NxAppRspackPlugin {
|
|
13
|
+
private readonly options;
|
|
14
|
+
constructor(options?: NxAppRspackPluginOptions);
|
|
15
|
+
apply(compiler: Compiler): void;
|
|
16
|
+
}
|