@nx/rspack 20.2.0-beta.1 → 20.2.0-beta.3
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/lib/config.d.ts +6 -0
- package/src/executors/rspack/lib/config.js +39 -0
- package/src/executors/rspack/rspack.impl.js +11 -12
- package/src/executors/rspack/schema.d.ts +39 -18
- package/src/executors/rspack/schema.json +191 -0
- 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/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 +2 -5
- package/src/plugins/utils/apply-web-config.d.ts +2 -2
- package/src/plugins/utils/apply-web-config.js +1 -8
- package/src/plugins/utils/models.d.ts +2 -2
- 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.d.ts +2 -2
- package/src/utils/create-compiler.js +12 -49
- 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 -55
- 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,114 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.convertToInferred = convertToInferred;
|
|
4
|
+
exports.createCollectingLogger = createCollectingLogger;
|
|
5
|
+
const devkit_1 = require("@nx/devkit");
|
|
6
|
+
const aggregate_log_util_1 = require("@nx/devkit/src/generators/plugin-migrations/aggregate-log-util");
|
|
7
|
+
const executor_to_plugin_migrator_1 = require("@nx/devkit/src/generators/plugin-migrations/executor-to-plugin-migrator");
|
|
8
|
+
const tsquery_1 = require("@phenomnomnominal/tsquery");
|
|
9
|
+
const plugin_1 = require("../../plugins/plugin");
|
|
10
|
+
const versions_1 = require("../../utils/versions");
|
|
11
|
+
const utils_1 = require("./utils");
|
|
12
|
+
const devkit_exports_1 = require("nx/src/devkit-exports");
|
|
13
|
+
async function convertToInferred(tree, options) {
|
|
14
|
+
const projectGraph = await (0, devkit_1.createProjectGraphAsync)();
|
|
15
|
+
const migrationContext = {
|
|
16
|
+
logger: new aggregate_log_util_1.AggregatedLog(),
|
|
17
|
+
projectGraph,
|
|
18
|
+
workspaceRoot: tree.root,
|
|
19
|
+
};
|
|
20
|
+
const logger = createCollectingLogger();
|
|
21
|
+
const migratedProjects = await (0, executor_to_plugin_migrator_1.migrateProjectExecutorsToPlugin)(tree, projectGraph, '@nx/rspack/plugin', plugin_1.createNodesV2, {
|
|
22
|
+
buildTargetName: 'build',
|
|
23
|
+
previewTargetName: 'preview',
|
|
24
|
+
serveStaticTargetName: 'serve-static',
|
|
25
|
+
serveTargetName: 'serve',
|
|
26
|
+
}, [
|
|
27
|
+
{
|
|
28
|
+
executors: ['@nx/rspack:rspack', '@nrwl/rspack:rspack'],
|
|
29
|
+
postTargetTransformer: (0, utils_1.buildPostTargetTransformerFactory)(migrationContext),
|
|
30
|
+
targetPluginOptionMapper: (target) => ({ buildTargetName: target }),
|
|
31
|
+
skipProjectFilter: skipProjectFilterFactory(tree),
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
executors: ['@nx/rspack:dev-server', '@nrwl/rspack:dev-server'],
|
|
35
|
+
postTargetTransformer: (0, utils_1.servePostTargetTransformerFactory)(migrationContext),
|
|
36
|
+
targetPluginOptionMapper: (target) => ({ serveTargetName: target }),
|
|
37
|
+
skipProjectFilter: skipProjectFilterFactory(tree),
|
|
38
|
+
},
|
|
39
|
+
], options.project, logger);
|
|
40
|
+
if (migratedProjects.size === 0) {
|
|
41
|
+
const convertMessage = [...logger.loggedMessages.values()]
|
|
42
|
+
.flat()
|
|
43
|
+
.find((v) => v.includes('@nx/rspack:convert-config-to-rspack-plugin'));
|
|
44
|
+
if (convertMessage.length > 0) {
|
|
45
|
+
logger.flushLogs((message) => !convertMessage.includes(message));
|
|
46
|
+
throw new Error(convertMessage);
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
logger.flushLogs();
|
|
50
|
+
throw new executor_to_plugin_migrator_1.NoTargetsToMigrateError();
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
logger.flushLogs();
|
|
55
|
+
}
|
|
56
|
+
const installCallback = (0, devkit_1.addDependenciesToPackageJson)(tree, {}, { '@rspack/core': versions_1.rspackCoreVersion }, undefined, true);
|
|
57
|
+
if (!options.skipFormat) {
|
|
58
|
+
await (0, devkit_1.formatFiles)(tree);
|
|
59
|
+
}
|
|
60
|
+
return (0, devkit_1.runTasksInSerial)(installCallback, () => {
|
|
61
|
+
migrationContext.logger.flushLogs();
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
function skipProjectFilterFactory(tree) {
|
|
65
|
+
return function skipProjectFilter(projectConfiguration) {
|
|
66
|
+
const buildTarget = Object.values(projectConfiguration.targets).find((target) => target.executor === '@nx/rspack:rspack' ||
|
|
67
|
+
target.executor === '@nrwl/rspack:rspack');
|
|
68
|
+
// the projects for which this is called are guaranteed to have a build target
|
|
69
|
+
const rspackConfigPath = buildTarget.options.rspackConfig;
|
|
70
|
+
if (!rspackConfigPath) {
|
|
71
|
+
return `The rspack config path is missing in the project configuration (${projectConfiguration.root}).`;
|
|
72
|
+
}
|
|
73
|
+
const sourceFile = tsquery_1.tsquery.ast(tree.read(rspackConfigPath, 'utf-8'));
|
|
74
|
+
const composePluginsSelector = 'CallExpression:has(Identifier[name=composePlugins])';
|
|
75
|
+
const composePlugins = (0, tsquery_1.tsquery)(sourceFile, composePluginsSelector)[0];
|
|
76
|
+
if (composePlugins) {
|
|
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
|
+
}
|
|
79
|
+
const nxAppRspackPluginSelector = 'PropertyAssignment:has(Identifier[name=plugins]) NewExpression:has(Identifier[name=NxAppRspackPlugin])';
|
|
80
|
+
const nxAppRspackPlugin = (0, tsquery_1.tsquery)(sourceFile, nxAppRspackPluginSelector)[0];
|
|
81
|
+
if (!nxAppRspackPlugin) {
|
|
82
|
+
return `No "NxAppRspackPlugin" found in the rspack config (${rspackConfigPath}). Its usage is required for the migration to work.`;
|
|
83
|
+
}
|
|
84
|
+
return false;
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
function createCollectingLogger() {
|
|
88
|
+
const loggedMessages = new Map();
|
|
89
|
+
const flushLogs = (filter) => {
|
|
90
|
+
loggedMessages.forEach((messages, method) => {
|
|
91
|
+
messages.forEach((message) => {
|
|
92
|
+
if (!filter || filter(message)) {
|
|
93
|
+
devkit_exports_1.logger[method](message);
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
};
|
|
98
|
+
return new Proxy({ ...devkit_exports_1.logger, loggedMessages, flushLogs }, {
|
|
99
|
+
get(target, property) {
|
|
100
|
+
const originalMethod = target[property];
|
|
101
|
+
if (typeof originalMethod === 'function') {
|
|
102
|
+
return (...args) => {
|
|
103
|
+
const message = args.join(' ');
|
|
104
|
+
const propertyString = String(property);
|
|
105
|
+
if (!loggedMessages.has(message)) {
|
|
106
|
+
loggedMessages.set(propertyString, []);
|
|
107
|
+
}
|
|
108
|
+
loggedMessages.get(propertyString).push(message);
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
return originalMethod;
|
|
112
|
+
},
|
|
113
|
+
});
|
|
114
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/schema",
|
|
3
|
+
"$id": "NxWebpackConvertToInferred",
|
|
4
|
+
"description": "Convert existing Webpack project(s) using `@nx/webpack:wepack` executor to use `@nx/webpack/plugin`.",
|
|
5
|
+
"title": "Convert a Webpack project from executor to plugin",
|
|
6
|
+
"type": "object",
|
|
7
|
+
"properties": {
|
|
8
|
+
"project": {
|
|
9
|
+
"type": "string",
|
|
10
|
+
"description": "The project to convert from using the `@nx/webpack:webpack` executor to use `@nx/webpack/plugin`. If not provided, all projects using the `@nx/webpack:webpack` executor will be converted.",
|
|
11
|
+
"x-priority": "important"
|
|
12
|
+
},
|
|
13
|
+
"skipFormat": {
|
|
14
|
+
"type": "boolean",
|
|
15
|
+
"description": "Whether to format files.",
|
|
16
|
+
"default": false
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.toPropertyAssignment = toPropertyAssignment;
|
|
4
|
+
exports.toExpression = toExpression;
|
|
5
|
+
const tslib_1 = require("tslib");
|
|
6
|
+
const ts = tslib_1.__importStar(require("typescript"));
|
|
7
|
+
function toPropertyAssignment(key, value) {
|
|
8
|
+
if (typeof value === 'string') {
|
|
9
|
+
return ts.factory.createPropertyAssignment(ts.factory.createStringLiteral(key), ts.factory.createStringLiteral(value));
|
|
10
|
+
}
|
|
11
|
+
else if (typeof value === 'number') {
|
|
12
|
+
return ts.factory.createPropertyAssignment(ts.factory.createStringLiteral(key), ts.factory.createNumericLiteral(value));
|
|
13
|
+
}
|
|
14
|
+
else if (typeof value === 'boolean') {
|
|
15
|
+
return ts.factory.createPropertyAssignment(ts.factory.createStringLiteral(key), value ? ts.factory.createTrue() : ts.factory.createFalse());
|
|
16
|
+
}
|
|
17
|
+
else if (Array.isArray(value)) {
|
|
18
|
+
return ts.factory.createPropertyAssignment(ts.factory.createStringLiteral(key), ts.factory.createArrayLiteralExpression(value.map((item) => toExpression(item))));
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
return ts.factory.createPropertyAssignment(ts.factory.createStringLiteral(key), ts.factory.createObjectLiteralExpression(Object.entries(value).map(([key, value]) => toPropertyAssignment(key, value))));
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
function toExpression(value) {
|
|
25
|
+
if (typeof value === 'string') {
|
|
26
|
+
return ts.factory.createStringLiteral(value);
|
|
27
|
+
}
|
|
28
|
+
else if (typeof value === 'number') {
|
|
29
|
+
return ts.factory.createNumericLiteral(value);
|
|
30
|
+
}
|
|
31
|
+
else if (typeof value === 'boolean') {
|
|
32
|
+
return value ? ts.factory.createTrue() : ts.factory.createFalse();
|
|
33
|
+
}
|
|
34
|
+
else if (Array.isArray(value)) {
|
|
35
|
+
return ts.factory.createArrayLiteralExpression(value.map((item) => toExpression(item)));
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
return ts.factory.createObjectLiteralExpression(Object.entries(value).map(([key, value]) => toPropertyAssignment(key, value)));
|
|
39
|
+
}
|
|
40
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { TargetConfiguration, Tree } from '@nx/devkit';
|
|
2
|
+
import type { MigrationContext } from './types';
|
|
3
|
+
export declare function buildPostTargetTransformerFactory(migrationContext: MigrationContext): (target: TargetConfiguration, tree: Tree, projectDetails: {
|
|
4
|
+
projectName: string;
|
|
5
|
+
root: string;
|
|
6
|
+
}, inferredTarget: TargetConfiguration) => TargetConfiguration;
|
|
@@ -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
|
+
};
|