@nx/rspack 23.0.0-beta.2 → 23.0.0-beta.20
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/migrations.json +52 -8
- package/package.json +27 -13
- package/src/executors/dev-server/dev-server.impl.d.ts.map +1 -1
- package/src/executors/dev-server/dev-server.impl.js +6 -4
- package/src/executors/dev-server/schema.json +1 -0
- package/src/executors/module-federation-dev-server/module-federation-dev-server.impl.js +4 -4
- package/src/executors/module-federation-ssr-dev-server/module-federation-ssr-dev-server.impl.js +4 -4
- package/src/executors/module-federation-static-server/module-federation-static-server.impl.js +4 -4
- package/src/executors/rspack/lib/normalize-options.js +2 -2
- package/src/executors/rspack/rspack.impl.d.ts.map +1 -1
- package/src/executors/rspack/rspack.impl.js +6 -4
- package/src/executors/rspack/schema.json +1 -0
- package/src/executors/ssr-dev-server/ssr-dev-server.impl.d.ts.map +1 -1
- package/src/executors/ssr-dev-server/ssr-dev-server.impl.js +2 -2
- package/src/generators/configuration/configuration.d.ts.map +1 -1
- package/src/generators/configuration/configuration.js +13 -10
- package/src/generators/convert-config-to-rspack-plugin/convert-config-to-rspack-plugin.d.ts.map +1 -1
- package/src/generators/convert-config-to-rspack-plugin/convert-config-to-rspack-plugin.js +5 -7
- package/src/generators/convert-to-inferred/convert-to-inferred.d.ts.map +1 -1
- package/src/generators/convert-to-inferred/convert-to-inferred.js +13 -6
- package/src/generators/convert-to-inferred/utils/build-post-target-transformer.js +8 -8
- package/src/generators/convert-to-inferred/utils/serve-post-target-transformer.d.ts.map +1 -1
- package/src/generators/convert-to-inferred/utils/serve-post-target-transformer.js +4 -4
- package/src/generators/convert-to-inferred/utils/types.d.ts +1 -1
- package/src/generators/convert-to-inferred/utils/types.d.ts.map +1 -1
- package/src/generators/convert-webpack/convert-webpack.d.ts.map +1 -1
- package/src/generators/convert-webpack/convert-webpack.js +8 -1
- package/src/generators/init/init.d.ts.map +1 -1
- package/src/generators/init/init.js +14 -7
- package/src/generators/init/schema.json +1 -1
- package/src/migrations/update-20-2-0/migrate-with-mf-import-to-new-package.d.ts.map +1 -1
- package/src/migrations/update-20-2-0/migrate-with-mf-import-to-new-package.js +2 -2
- package/src/migrations/update-20-3-0/ensure-nx-module-federation-package.d.ts.map +1 -1
- package/src/migrations/update-20-3-0/ensure-nx-module-federation-package.js +2 -2
- package/src/migrations/update-22-0-0/remove-deprecated-options.d.ts.map +1 -1
- package/src/migrations/update-22-0-0/remove-deprecated-options.js +3 -3
- package/src/migrations/update-23-0-0/add-svgr-to-rspack-config.d.ts +3 -0
- package/src/migrations/update-23-0-0/add-svgr-to-rspack-config.d.ts.map +1 -0
- package/src/migrations/update-23-0-0/add-svgr-to-rspack-config.js +413 -0
- package/src/migrations/update-23-0-0/add-svgr-to-rspack-config.md +84 -0
- package/src/plugins/nx-react-rspack-plugin/nx-react-rspack-plugin.d.ts +1 -7
- package/src/plugins/nx-react-rspack-plugin/nx-react-rspack-plugin.d.ts.map +1 -1
- package/src/plugins/plugin.d.ts.map +1 -1
- package/src/plugins/plugin.js +17 -27
- package/src/plugins/utils/apply-base-config.js +2 -2
- package/src/plugins/utils/apply-react-config.d.ts +1 -4
- package/src/plugins/utils/apply-react-config.d.ts.map +1 -1
- package/src/plugins/utils/apply-react-config.js +1 -32
- package/src/plugins/utils/apply-web-config.d.ts.map +1 -1
- package/src/plugins/utils/apply-web-config.js +4 -14
- package/src/plugins/utils/models.d.ts +1 -10
- package/src/plugins/utils/models.d.ts.map +1 -1
- package/src/plugins/utils/plugins/normalize-options.js +2 -2
- package/src/plugins/utils/plugins/nx-tsconfig-paths-rspack-plugin.js +3 -3
- package/src/utils/assert-supported-rspack-version.d.ts +3 -0
- package/src/utils/assert-supported-rspack-version.d.ts.map +1 -0
- package/src/utils/assert-supported-rspack-version.js +8 -0
- package/src/utils/config.js +2 -2
- package/src/utils/deprecation.d.ts +6 -0
- package/src/utils/deprecation.d.ts.map +1 -0
- package/src/utils/deprecation.js +21 -0
- package/src/utils/e2e-web-server-info-utils.d.ts +1 -1
- package/src/utils/e2e-web-server-info-utils.d.ts.map +1 -1
- package/src/utils/e2e-web-server-info-utils.js +6 -5
- package/src/utils/generator-utils.d.ts.map +1 -1
- package/src/utils/generator-utils.js +3 -4
- package/src/utils/resolve-user-defined-rspack-config.js +2 -2
- package/src/utils/version-utils.d.ts +27 -0
- package/src/utils/version-utils.d.ts.map +1 -0
- package/src/utils/version-utils.js +53 -0
- package/src/utils/versions.d.ts +18 -3
- package/src/utils/versions.d.ts.map +1 -1
- package/src/utils/versions.js +21 -4
- package/src/utils/with-react.d.ts +1 -7
- package/src/utils/with-react.d.ts.map +1 -1
- package/src/utils/with-react.js +1 -1
- package/src/utils/with-web.d.ts +1 -1
- package/src/utils/with-web.d.ts.map +1 -1
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.servePostTargetTransformerFactory = servePostTargetTransformerFactory;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
+
const internal_1 = require("@nx/devkit/internal");
|
|
5
6
|
const devkit_1 = require("@nx/devkit");
|
|
6
|
-
const plugin_migration_utils_1 = require("@nx/devkit/src/generators/plugin-migrations/plugin-migration-utils");
|
|
7
7
|
const tsquery_1 = require("@phenomnomnominal/tsquery");
|
|
8
8
|
const path_1 = require("path");
|
|
9
9
|
const ts = tslib_1.__importStar(require("typescript"));
|
|
@@ -19,7 +19,7 @@ function servePostTargetTransformerFactory(migrationContext) {
|
|
|
19
19
|
const { devServerOptions, rspackConfigPath } = await processOptions(tree, target, context);
|
|
20
20
|
updateRspackConfig(tree, rspackConfigPath, devServerOptions, context);
|
|
21
21
|
if (target.outputs) {
|
|
22
|
-
(0,
|
|
22
|
+
(0, internal_1.processTargetOutputs)(target, [], inferredTarget, {
|
|
23
23
|
projectName: projectDetails.projectName,
|
|
24
24
|
projectRoot: projectDetails.root,
|
|
25
25
|
});
|
|
@@ -64,8 +64,8 @@ function extractDevServerOptions(options, context) {
|
|
|
64
64
|
devServerOptions.server = { type: 'https' };
|
|
65
65
|
if (options.sslCert && options.sslKey) {
|
|
66
66
|
devServerOptions.server.options = {};
|
|
67
|
-
devServerOptions.server.options.cert = (0,
|
|
68
|
-
devServerOptions.server.options.key = (0,
|
|
67
|
+
devServerOptions.server.options.cert = (0, internal_1.toProjectRelativePath)(options.sslCert, context.projectRoot);
|
|
68
|
+
devServerOptions.server.options.key = (0, internal_1.toProjectRelativePath)(options.sslKey, context.projectRoot);
|
|
69
69
|
}
|
|
70
70
|
else if (options.sslCert) {
|
|
71
71
|
context.logger.addLog({
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ProjectGraph } from '@nx/devkit';
|
|
2
|
-
import type { AggregatedLog } from '@nx/devkit/
|
|
2
|
+
import type { AggregatedLog } from '@nx/devkit/internal';
|
|
3
3
|
export type MigrationContext = {
|
|
4
4
|
logger: AggregatedLog;
|
|
5
5
|
projectGraph: ProjectGraph;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../../../../packages/rspack/src/generators/convert-to-inferred/utils/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC/C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../../../../packages/rspack/src/generators/convert-to-inferred/utils/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC/C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEzD,MAAM,MAAM,gBAAgB,GAAG;IAC7B,MAAM,EAAE,aAAa,CAAC;IACtB,YAAY,EAAE,YAAY,CAAC;IAC3B,aAAa,EAAE,MAAM,CAAC;CACvB,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAAG,gBAAgB,GAAG;IAClD,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC;CACrB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"convert-webpack.d.ts","sourceRoot":"","sources":["../../../../../../packages/rspack/src/generators/convert-webpack/convert-webpack.ts"],"names":[],"mappings":"AAAA,OAAO,EAML,KAAK,IAAI,EAGV,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"convert-webpack.d.ts","sourceRoot":"","sources":["../../../../../../packages/rspack/src/generators/convert-webpack/convert-webpack.ts"],"names":[],"mappings":"AAAA,OAAO,EAML,KAAK,IAAI,EAGV,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAWlC,yBAA+B,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,mDAiKzD"}
|
|
@@ -6,7 +6,9 @@ const versions_1 = require("../../utils/versions");
|
|
|
6
6
|
const transform_esm_1 = require("./lib/transform-esm");
|
|
7
7
|
const transform_cjs_1 = require("./lib/transform-cjs");
|
|
8
8
|
const transform_plugin_config_1 = require("./lib/transform-plugin-config");
|
|
9
|
+
const assert_supported_rspack_version_1 = require("../../utils/assert-supported-rspack-version");
|
|
9
10
|
async function default_1(tree, options) {
|
|
11
|
+
(0, assert_supported_rspack_version_1.assertSupportedRspackVersion)(tree);
|
|
10
12
|
const projects = (0, devkit_1.getProjects)(tree);
|
|
11
13
|
if (!projects.has(options.project)) {
|
|
12
14
|
throw new Error(`Could not find project '${options.project}'. Ensure you have specified the project you'd like to convert correctly.`);
|
|
@@ -113,7 +115,12 @@ async function default_1(tree, options) {
|
|
|
113
115
|
const installTask = (0, devkit_1.addDependenciesToPackageJson)(tree, {}, {
|
|
114
116
|
'@rspack/core': versions_1.rspackCoreVersion,
|
|
115
117
|
'@rspack/dev-server': versions_1.rspackDevServerVersion,
|
|
116
|
-
|
|
118
|
+
// @rspack/plugin-react-refresh is required at runtime by
|
|
119
|
+
// apply-react-config when building a React project. Since it is an
|
|
120
|
+
// optional peer dependency of @nx/rspack, the convert generator must
|
|
121
|
+
// install it explicitly.
|
|
122
|
+
'@rspack/plugin-react-refresh': versions_1.rspackPluginReactRefreshVersion,
|
|
123
|
+
}, undefined, true);
|
|
117
124
|
if (!options.skipFormat) {
|
|
118
125
|
await (0, devkit_1.formatFiles)(tree);
|
|
119
126
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../../../../../../packages/rspack/src/generators/init/init.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../../../../../../packages/rspack/src/generators/init/init.ts"],"names":[],"mappings":"AACA,OAAO,EAIL,iBAAiB,EAGjB,IAAI,EACL,MAAM,YAAY,CAAC;AAWpB,OAAO,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AAE/C,wBAAsB,mBAAmB,CACvC,IAAI,EAAE,IAAI,EACV,MAAM,EAAE,mBAAmB,8BAiH5B;AAED,eAAe,mBAAmB,CAAC;AAEnC,eAAO,MAAM,mBAAmB,sFAA0C,CAAC"}
|
|
@@ -2,19 +2,22 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.rspackInitSchematic = void 0;
|
|
4
4
|
exports.rspackInitGenerator = rspackInitGenerator;
|
|
5
|
+
const internal_1 = require("@nx/devkit/internal");
|
|
5
6
|
const devkit_1 = require("@nx/devkit");
|
|
6
|
-
const add_plugin_1 = require("@nx/devkit/src/utils/add-plugin");
|
|
7
7
|
const js_1 = require("@nx/js");
|
|
8
8
|
const plugin_1 = require("../../../plugin");
|
|
9
9
|
const versions_1 = require("../../utils/versions");
|
|
10
|
+
const version_utils_1 = require("../../utils/version-utils");
|
|
11
|
+
const assert_supported_rspack_version_1 = require("../../utils/assert-supported-rspack-version");
|
|
10
12
|
async function rspackInitGenerator(tree, schema) {
|
|
13
|
+
(0, assert_supported_rspack_version_1.assertSupportedRspackVersion)(tree);
|
|
11
14
|
const tasks = [];
|
|
12
15
|
const nxJson = (0, devkit_1.readNxJson)(tree);
|
|
13
16
|
const addPluginDefault = process.env.NX_ADD_PLUGINS !== 'false' &&
|
|
14
17
|
nxJson.useInferencePlugins !== false;
|
|
15
18
|
schema.addPlugin ??= addPluginDefault;
|
|
16
19
|
if (schema.addPlugin) {
|
|
17
|
-
await (0,
|
|
20
|
+
await (0, internal_1.addPlugin)(tree, await (0, devkit_1.createProjectGraphAsync)(), '@nx/rspack/plugin', plugin_1.createNodesV2, {
|
|
18
21
|
buildTargetName: [
|
|
19
22
|
'build',
|
|
20
23
|
'rspack:build',
|
|
@@ -59,12 +62,15 @@ async function rspackInitGenerator(tree, schema) {
|
|
|
59
62
|
skipFormat: true,
|
|
60
63
|
});
|
|
61
64
|
tasks.push(jsInitTask);
|
|
65
|
+
const rspackVersions = (0, version_utils_1.getRspackVersionsForInstalledMajor)(tree);
|
|
66
|
+
const keepExistingVersions = schema.keepExistingVersions ?? true;
|
|
62
67
|
const devDependencies = {
|
|
63
|
-
'@rspack/core':
|
|
64
|
-
'@rspack/cli':
|
|
68
|
+
'@rspack/core': rspackVersions.rspackCoreVersion,
|
|
69
|
+
'@rspack/cli': rspackVersions.rspackCoreVersion,
|
|
70
|
+
'@rspack/dev-server': rspackVersions.rspackDevServerVersion,
|
|
65
71
|
...(!schema.framework || schema.framework === 'react'
|
|
66
72
|
? {
|
|
67
|
-
'@rspack/plugin-react-refresh':
|
|
73
|
+
'@rspack/plugin-react-refresh': rspackVersions.rspackPluginReactRefreshVersion,
|
|
68
74
|
'react-refresh': versions_1.reactRefreshVersion,
|
|
69
75
|
}
|
|
70
76
|
: {}),
|
|
@@ -82,9 +88,10 @@ async function rspackInitGenerator(tree, schema) {
|
|
|
82
88
|
devDependencies['sass-embedded'] = versions_1.sassEmbeddedVersion;
|
|
83
89
|
}
|
|
84
90
|
if (schema.framework !== 'none' || schema.devServer) {
|
|
85
|
-
devDependencies['@rspack/dev-server'] =
|
|
91
|
+
devDependencies['@rspack/dev-server'] =
|
|
92
|
+
rspackVersions.rspackDevServerVersion;
|
|
86
93
|
}
|
|
87
|
-
const installTask = (0, devkit_1.addDependenciesToPackageJson)(tree, {}, devDependencies, undefined,
|
|
94
|
+
const installTask = (0, devkit_1.addDependenciesToPackageJson)(tree, {}, devDependencies, undefined, keepExistingVersions);
|
|
88
95
|
tasks.push(installTask);
|
|
89
96
|
return (0, devkit_1.runTasksInSerial)(...tasks);
|
|
90
97
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"migrate-with-mf-import-to-new-package.d.ts","sourceRoot":"","sources":["../../../../../../packages/rspack/src/migrations/update-20-2-0/migrate-with-mf-import-to-new-package.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"migrate-with-mf-import-to-new-package.d.ts","sourceRoot":"","sources":["../../../../../../packages/rspack/src/migrations/update-20-2-0/migrate-with-mf-import-to-new-package.ts"],"names":[],"mappings":"AACA,OAAO,EACL,KAAK,IAAI,EAKV,MAAM,YAAY,CAAC;AAQpB,wBAA8B,mBAAmB,CAAC,IAAI,EAAE,IAAI,iBAqD3D"}
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.default = migrateWithMfImport;
|
|
4
|
+
const internal_1 = require("@nx/devkit/internal");
|
|
4
5
|
const devkit_1 = require("@nx/devkit");
|
|
5
|
-
const executor_options_utils_1 = require("@nx/devkit/src/generators/executor-options-utils");
|
|
6
6
|
const tsquery_1 = require("@phenomnomnominal/tsquery");
|
|
7
7
|
const versions_1 = require("../../utils/versions");
|
|
8
8
|
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]';
|
|
9
9
|
const NEW_IMPORT_PATH = `'@nx/module-federation/rspack'`;
|
|
10
10
|
async function migrateWithMfImport(tree) {
|
|
11
11
|
const projects = new Set();
|
|
12
|
-
(0,
|
|
12
|
+
(0, internal_1.forEachExecutorOptions)(tree, '@nx/rspack:module-federation-dev-server', (options, project, target) => {
|
|
13
13
|
const projectConfig = (0, devkit_1.readProjectConfiguration)(tree, project);
|
|
14
14
|
projects.add(projectConfig.root);
|
|
15
15
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ensure-nx-module-federation-package.d.ts","sourceRoot":"","sources":["../../../../../../packages/rspack/src/migrations/update-20-3-0/ensure-nx-module-federation-package.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ensure-nx-module-federation-package.d.ts","sourceRoot":"","sources":["../../../../../../packages/rspack/src/migrations/update-20-3-0/ensure-nx-module-federation-package.ts"],"names":[],"mappings":"AACA,OAAO,EACL,KAAK,IAAI,EAGV,MAAM,YAAY,CAAC;AAGpB,wBAA8B,eAAe,CAAC,IAAI,EAAE,IAAI,iBAqBvD"}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.default = ensureMfPackage;
|
|
4
|
+
const internal_1 = require("@nx/devkit/internal");
|
|
4
5
|
const devkit_1 = require("@nx/devkit");
|
|
5
|
-
const executor_options_utils_1 = require("@nx/devkit/src/generators/executor-options-utils");
|
|
6
6
|
const versions_1 = require("../../utils/versions");
|
|
7
7
|
async function ensureMfPackage(tree) {
|
|
8
8
|
const projects = new Set();
|
|
9
|
-
(0,
|
|
9
|
+
(0, internal_1.forEachExecutorOptions)(tree, '@nx/rspack:module-federation-dev-server', (options, project, target) => {
|
|
10
10
|
const projectConfig = (0, devkit_1.readProjectConfiguration)(tree, project);
|
|
11
11
|
projects.add(projectConfig.root);
|
|
12
12
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"remove-deprecated-options.d.ts","sourceRoot":"","sources":["../../../../../../packages/rspack/src/migrations/update-22-0-0/remove-deprecated-options.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"remove-deprecated-options.d.ts","sourceRoot":"","sources":["../../../../../../packages/rspack/src/migrations/update-22-0-0/remove-deprecated-options.ts"],"names":[],"mappings":"AACA,OAAO,EACL,KAAK,IAAI,EAKV,MAAM,YAAY,CAAC;AAEpB,wBAA8B,uBAAuB,CAAC,IAAI,EAAE,IAAI,iBAwH/D"}
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.default = removeDeprecatedOptions;
|
|
4
|
+
const internal_1 = require("@nx/devkit/internal");
|
|
4
5
|
const devkit_1 = require("@nx/devkit");
|
|
5
|
-
const executor_options_utils_1 = require("@nx/devkit/src/generators/executor-options-utils");
|
|
6
6
|
async function removeDeprecatedOptions(tree) {
|
|
7
7
|
const projects = new Set();
|
|
8
8
|
// Find all projects using @nx/rspack:rspack or @nx/rspack:dev-server executors
|
|
9
|
-
(0,
|
|
9
|
+
(0, internal_1.forEachExecutorOptions)(tree, '@nx/rspack:rspack', (options, project) => {
|
|
10
10
|
projects.add(project);
|
|
11
11
|
});
|
|
12
|
-
(0,
|
|
12
|
+
(0, internal_1.forEachExecutorOptions)(tree, '@nx/rspack:dev-server', (options, project) => {
|
|
13
13
|
projects.add(project);
|
|
14
14
|
});
|
|
15
15
|
// Update project configurations to remove deprecated options
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"add-svgr-to-rspack-config.d.ts","sourceRoot":"","sources":["../../../../../../packages/rspack/src/migrations/update-23-0-0/add-svgr-to-rspack-config.ts"],"names":[],"mappings":"AACA,OAAO,EACL,KAAK,IAAI,EAKV,MAAM,YAAY,CAAC;AA8FpB,wBAA8B,qBAAqB,CAAC,IAAI,EAAE,IAAI,iBA+Y7D"}
|
|
@@ -0,0 +1,413 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = addSvgrToRspackConfig;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const internal_1 = require("@nx/devkit/internal");
|
|
6
|
+
const devkit_1 = require("@nx/devkit");
|
|
7
|
+
const tsquery_1 = require("@phenomnomnominal/tsquery");
|
|
8
|
+
const ts = tslib_1.__importStar(require("typescript"));
|
|
9
|
+
const withSvgrFunctionForWithReact = `
|
|
10
|
+
|
|
11
|
+
// SVGR support function (migrated from svgr option in withReact/NxReactRspackPlugin)
|
|
12
|
+
function withSvgr(svgrOptions = {}) {
|
|
13
|
+
const defaultOptions = {
|
|
14
|
+
svgo: false,
|
|
15
|
+
titleProp: true,
|
|
16
|
+
ref: true,
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
const options = { ...defaultOptions, ...svgrOptions };
|
|
20
|
+
|
|
21
|
+
return function configure(config) {
|
|
22
|
+
// Remove existing SVG loader if present
|
|
23
|
+
const svgLoaderIdx = config.module.rules.findIndex(
|
|
24
|
+
(rule) =>
|
|
25
|
+
typeof rule === 'object' &&
|
|
26
|
+
typeof rule.test !== 'undefined' &&
|
|
27
|
+
rule.test.toString().includes('svg')
|
|
28
|
+
);
|
|
29
|
+
|
|
30
|
+
if (svgLoaderIdx !== -1) {
|
|
31
|
+
config.module.rules.splice(svgLoaderIdx, 1);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
config.module.rules.push(
|
|
35
|
+
{
|
|
36
|
+
test: /\\.svg$/i,
|
|
37
|
+
type: 'asset',
|
|
38
|
+
resourceQuery: /url/, // *.svg?url
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
test: /\\.svg$/i,
|
|
42
|
+
issuer: /\\.[jt]sx?$/,
|
|
43
|
+
resourceQuery: { not: [/url/] },
|
|
44
|
+
use: [{ loader: '@svgr/webpack', options }],
|
|
45
|
+
}
|
|
46
|
+
);
|
|
47
|
+
|
|
48
|
+
return config;
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
`;
|
|
52
|
+
const withSvgrFunctionForNxReactRspackPlugin = `
|
|
53
|
+
|
|
54
|
+
// SVGR support function (migrated from svgr option in withReact/NxReactRspackPlugin)
|
|
55
|
+
function withSvgr(svgrOptions = {}) {
|
|
56
|
+
const defaultOptions = {
|
|
57
|
+
svgo: false,
|
|
58
|
+
titleProp: true,
|
|
59
|
+
ref: true,
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
const options = { ...defaultOptions, ...svgrOptions };
|
|
63
|
+
|
|
64
|
+
return (config) => {
|
|
65
|
+
config.plugins.push({
|
|
66
|
+
apply: (compiler) => {
|
|
67
|
+
// Remove ALL existing SVG loaders
|
|
68
|
+
compiler.options.module.rules = compiler.options.module.rules.filter(
|
|
69
|
+
(rule) =>
|
|
70
|
+
!(
|
|
71
|
+
rule &&
|
|
72
|
+
typeof rule === 'object' &&
|
|
73
|
+
rule.test &&
|
|
74
|
+
rule.test.toString().includes('svg')
|
|
75
|
+
)
|
|
76
|
+
);
|
|
77
|
+
|
|
78
|
+
compiler.options.module.rules.push(
|
|
79
|
+
{
|
|
80
|
+
test: /\\.svg$/i,
|
|
81
|
+
type: 'asset',
|
|
82
|
+
resourceQuery: /url/,
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
test: /\\.svg$/i,
|
|
86
|
+
issuer: /\\.[jt]sx?$/,
|
|
87
|
+
resourceQuery: { not: [/url/] },
|
|
88
|
+
use: [{ loader: '@svgr/webpack', options }],
|
|
89
|
+
}
|
|
90
|
+
);
|
|
91
|
+
},
|
|
92
|
+
});
|
|
93
|
+
return config;
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
`;
|
|
97
|
+
async function addSvgrToRspackConfig(tree) {
|
|
98
|
+
const projects = new Map();
|
|
99
|
+
// Find all React rspack projects using either withReact OR NxReactRspackPlugin
|
|
100
|
+
(0, internal_1.forEachExecutorOptions)(tree, '@nx/rspack:rspack', (options, project, target) => {
|
|
101
|
+
if (!options.rspackConfig)
|
|
102
|
+
return;
|
|
103
|
+
const rspackConfigPath = options.rspackConfig;
|
|
104
|
+
if (!tree.exists(rspackConfigPath))
|
|
105
|
+
return;
|
|
106
|
+
const content = tree.read(rspackConfigPath, 'utf-8');
|
|
107
|
+
const sourceFile = (0, tsquery_1.ast)(content);
|
|
108
|
+
// Check if this is a withReact setup
|
|
109
|
+
if (content.includes('withReact')) {
|
|
110
|
+
const withReactCalls = (0, tsquery_1.query)(sourceFile, 'CallExpression[expression.name=withReact]');
|
|
111
|
+
if (withReactCalls.length > 0) {
|
|
112
|
+
const callExpr = withReactCalls[0];
|
|
113
|
+
if (callExpr.arguments.length === 0)
|
|
114
|
+
return;
|
|
115
|
+
const arg = callExpr.arguments[0];
|
|
116
|
+
if (!ts.isObjectLiteralExpression(arg))
|
|
117
|
+
return;
|
|
118
|
+
const svgrProp = arg.properties.find((prop) => ts.isPropertyAssignment(prop) &&
|
|
119
|
+
ts.isIdentifier(prop.name) &&
|
|
120
|
+
prop.name.text === 'svgr');
|
|
121
|
+
if (svgrProp) {
|
|
122
|
+
let svgrValue;
|
|
123
|
+
if (ts.isObjectLiteralExpression(svgrProp.initializer)) {
|
|
124
|
+
svgrValue = {};
|
|
125
|
+
for (const prop of svgrProp.initializer.properties) {
|
|
126
|
+
if (!ts.isPropertyAssignment(prop))
|
|
127
|
+
continue;
|
|
128
|
+
if (!ts.isIdentifier(prop.name))
|
|
129
|
+
continue;
|
|
130
|
+
const key = prop.name.text;
|
|
131
|
+
if (prop.initializer.kind === ts.SyntaxKind.TrueKeyword) {
|
|
132
|
+
svgrValue[key] = true;
|
|
133
|
+
}
|
|
134
|
+
else if (prop.initializer.kind === ts.SyntaxKind.FalseKeyword) {
|
|
135
|
+
svgrValue[key] = false;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
else {
|
|
140
|
+
svgrValue =
|
|
141
|
+
svgrProp.initializer.kind === ts.SyntaxKind.TrueKeyword;
|
|
142
|
+
}
|
|
143
|
+
projects.set(rspackConfigPath, {
|
|
144
|
+
svgrOptions: svgrValue,
|
|
145
|
+
isWithReact: true,
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
// Otherwise check if this is NxReactRspackPlugin setup
|
|
151
|
+
else if (content.includes('NxReactRspackPlugin')) {
|
|
152
|
+
const pluginCalls = (0, tsquery_1.query)(sourceFile, 'NewExpression[expression.name=NxReactRspackPlugin]');
|
|
153
|
+
if (pluginCalls.length > 0) {
|
|
154
|
+
const newExpr = pluginCalls[0];
|
|
155
|
+
if (!newExpr.arguments || newExpr.arguments.length === 0)
|
|
156
|
+
return;
|
|
157
|
+
const arg = newExpr.arguments[0];
|
|
158
|
+
if (!ts.isObjectLiteralExpression(arg))
|
|
159
|
+
return;
|
|
160
|
+
const svgrProp = arg.properties.find((prop) => ts.isPropertyAssignment(prop) &&
|
|
161
|
+
ts.isIdentifier(prop.name) &&
|
|
162
|
+
prop.name.text === 'svgr');
|
|
163
|
+
if (svgrProp) {
|
|
164
|
+
let svgrValue;
|
|
165
|
+
if (ts.isObjectLiteralExpression(svgrProp.initializer)) {
|
|
166
|
+
svgrValue = {};
|
|
167
|
+
for (const prop of svgrProp.initializer.properties) {
|
|
168
|
+
if (!ts.isPropertyAssignment(prop))
|
|
169
|
+
continue;
|
|
170
|
+
if (!ts.isIdentifier(prop.name))
|
|
171
|
+
continue;
|
|
172
|
+
const key = prop.name.text;
|
|
173
|
+
if (prop.initializer.kind === ts.SyntaxKind.TrueKeyword) {
|
|
174
|
+
svgrValue[key] = true;
|
|
175
|
+
}
|
|
176
|
+
else if (prop.initializer.kind === ts.SyntaxKind.FalseKeyword) {
|
|
177
|
+
svgrValue[key] = false;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
else if (svgrProp.initializer.kind === ts.SyntaxKind.TrueKeyword) {
|
|
182
|
+
svgrValue = true;
|
|
183
|
+
}
|
|
184
|
+
else if (svgrProp.initializer.kind === ts.SyntaxKind.FalseKeyword) {
|
|
185
|
+
svgrValue = false;
|
|
186
|
+
}
|
|
187
|
+
// Add to projects if svgr is explicitly set
|
|
188
|
+
if (svgrValue !== undefined) {
|
|
189
|
+
projects.set(rspackConfigPath, {
|
|
190
|
+
svgrOptions: svgrValue,
|
|
191
|
+
isWithReact: false,
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
});
|
|
198
|
+
if (projects.size === 0)
|
|
199
|
+
return;
|
|
200
|
+
// Update rspack configs to add withSvgr function inline
|
|
201
|
+
for (const [rspackConfigPath, config] of projects.entries()) {
|
|
202
|
+
let content = tree.read(rspackConfigPath, 'utf-8');
|
|
203
|
+
const sourceFile = (0, tsquery_1.ast)(content);
|
|
204
|
+
const changes = [];
|
|
205
|
+
// Build the svgr options for this specific config
|
|
206
|
+
let svgrOptionsStr = '';
|
|
207
|
+
if (config.svgrOptions) {
|
|
208
|
+
const importStatements = (0, tsquery_1.query)(sourceFile, 'ImportDeclaration');
|
|
209
|
+
const requireStatements = (0, tsquery_1.query)(sourceFile, 'VariableStatement:has(CallExpression[expression.name=require])');
|
|
210
|
+
const allImportRequires = [
|
|
211
|
+
...importStatements,
|
|
212
|
+
...requireStatements,
|
|
213
|
+
].sort((a, b) => a.getEnd() - b.getEnd());
|
|
214
|
+
const lastImportOrRequire = allImportRequires[allImportRequires.length - 1];
|
|
215
|
+
if (config.svgrOptions === true || config.svgrOptions === undefined) {
|
|
216
|
+
svgrOptionsStr = '';
|
|
217
|
+
}
|
|
218
|
+
else if (typeof config.svgrOptions === 'object') {
|
|
219
|
+
const options = Object.entries(config.svgrOptions)
|
|
220
|
+
.map(([key, value]) => ` ${key}: ${value}`)
|
|
221
|
+
.join(',\n');
|
|
222
|
+
svgrOptionsStr = `{\n${options}\n}`;
|
|
223
|
+
}
|
|
224
|
+
if (lastImportOrRequire) {
|
|
225
|
+
changes.push({
|
|
226
|
+
type: devkit_1.ChangeType.Insert,
|
|
227
|
+
index: lastImportOrRequire.getEnd(),
|
|
228
|
+
text: config.isWithReact
|
|
229
|
+
? withSvgrFunctionForWithReact
|
|
230
|
+
: withSvgrFunctionForNxReactRspackPlugin,
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
|
+
else {
|
|
234
|
+
changes.push({
|
|
235
|
+
type: devkit_1.ChangeType.Insert,
|
|
236
|
+
index: 0,
|
|
237
|
+
text: (config.isWithReact
|
|
238
|
+
? withSvgrFunctionForWithReact
|
|
239
|
+
: withSvgrFunctionForNxReactRspackPlugin) + '\n',
|
|
240
|
+
});
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
// Remove svgr option based on the style (withReact OR NxReactRspackPlugin)
|
|
244
|
+
if (config.isWithReact) {
|
|
245
|
+
const withReactCalls = (0, tsquery_1.query)(sourceFile, 'CallExpression[expression.name=withReact]');
|
|
246
|
+
if (withReactCalls.length > 0) {
|
|
247
|
+
const callExpr = withReactCalls[0];
|
|
248
|
+
if (callExpr.arguments.length > 0) {
|
|
249
|
+
const arg = callExpr.arguments[0];
|
|
250
|
+
if (ts.isObjectLiteralExpression(arg)) {
|
|
251
|
+
const svgrProp = arg.properties.find((prop) => ts.isPropertyAssignment(prop) &&
|
|
252
|
+
ts.isIdentifier(prop.name) &&
|
|
253
|
+
prop.name.text === 'svgr');
|
|
254
|
+
if (svgrProp) {
|
|
255
|
+
const hasOnlySvgrProperty = arg.properties.length === 1;
|
|
256
|
+
if (hasOnlySvgrProperty) {
|
|
257
|
+
changes.push({
|
|
258
|
+
type: devkit_1.ChangeType.Delete,
|
|
259
|
+
start: arg.getStart(),
|
|
260
|
+
length: arg.getEnd() - arg.getStart(),
|
|
261
|
+
});
|
|
262
|
+
}
|
|
263
|
+
else {
|
|
264
|
+
const propIndex = arg.properties.indexOf(svgrProp);
|
|
265
|
+
const isLastProp = propIndex === arg.properties.length - 1;
|
|
266
|
+
const isFirstProp = propIndex === 0;
|
|
267
|
+
let removeStart = svgrProp.getFullStart();
|
|
268
|
+
let removeEnd = svgrProp.getEnd();
|
|
269
|
+
if (!isLastProp) {
|
|
270
|
+
const nextProp = arg.properties[propIndex + 1];
|
|
271
|
+
removeEnd = nextProp.getFullStart();
|
|
272
|
+
}
|
|
273
|
+
else if (!isFirstProp) {
|
|
274
|
+
const prevProp = arg.properties[propIndex - 1];
|
|
275
|
+
const textBetween = content.substring(prevProp.getEnd(), svgrProp.getFullStart());
|
|
276
|
+
const commaIndex = textBetween.indexOf(',');
|
|
277
|
+
if (commaIndex !== -1) {
|
|
278
|
+
removeStart = prevProp.getEnd() + commaIndex;
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
changes.push({
|
|
282
|
+
type: devkit_1.ChangeType.Delete,
|
|
283
|
+
start: removeStart,
|
|
284
|
+
length: removeEnd - removeStart,
|
|
285
|
+
});
|
|
286
|
+
}
|
|
287
|
+
if (config.svgrOptions) {
|
|
288
|
+
const composePluginsCalls = (0, tsquery_1.query)(sourceFile, 'CallExpression[expression.name=composePlugins]');
|
|
289
|
+
if (composePluginsCalls.length > 0) {
|
|
290
|
+
const composeCall = composePluginsCalls[0];
|
|
291
|
+
let svgrCallStr = '';
|
|
292
|
+
if (config.svgrOptions === true ||
|
|
293
|
+
config.svgrOptions === undefined) {
|
|
294
|
+
svgrCallStr = 'withSvgr()';
|
|
295
|
+
}
|
|
296
|
+
else if (typeof config.svgrOptions === 'object') {
|
|
297
|
+
svgrCallStr = `withSvgr(${svgrOptionsStr})`;
|
|
298
|
+
}
|
|
299
|
+
const withReactIdx = composeCall.arguments.findIndex((arg) => arg.getText().includes('withReact'));
|
|
300
|
+
// Insert withSvgr as the last argument before the closing paren
|
|
301
|
+
const argToInsertAfter = composeCall.arguments[withReactIdx];
|
|
302
|
+
if (argToInsertAfter) {
|
|
303
|
+
changes.push({
|
|
304
|
+
type: devkit_1.ChangeType.Insert,
|
|
305
|
+
index: argToInsertAfter.getEnd(),
|
|
306
|
+
text: `, ${svgrCallStr}`,
|
|
307
|
+
});
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
else {
|
|
317
|
+
// Remove svgr option from first NxReactRspackPlugin call
|
|
318
|
+
const pluginCalls = (0, tsquery_1.query)(sourceFile, 'NewExpression[expression.name=NxReactRspackPlugin]');
|
|
319
|
+
if (pluginCalls.length > 0) {
|
|
320
|
+
const newExpr = pluginCalls[0];
|
|
321
|
+
if (newExpr.arguments && newExpr.arguments.length > 0) {
|
|
322
|
+
const arg = newExpr.arguments[0];
|
|
323
|
+
if (ts.isObjectLiteralExpression(arg)) {
|
|
324
|
+
const svgrProp = arg.properties.find((prop) => ts.isPropertyAssignment(prop) &&
|
|
325
|
+
ts.isIdentifier(prop.name) &&
|
|
326
|
+
prop.name.text === 'svgr');
|
|
327
|
+
if (svgrProp) {
|
|
328
|
+
const hasOnlySvgrProperty = arg.properties.length === 1;
|
|
329
|
+
if (hasOnlySvgrProperty) {
|
|
330
|
+
changes.push({
|
|
331
|
+
type: devkit_1.ChangeType.Delete,
|
|
332
|
+
start: arg.getStart(),
|
|
333
|
+
length: arg.getEnd() - arg.getStart(),
|
|
334
|
+
});
|
|
335
|
+
}
|
|
336
|
+
else {
|
|
337
|
+
const propIndex = arg.properties.indexOf(svgrProp);
|
|
338
|
+
const isLastProp = propIndex === arg.properties.length - 1;
|
|
339
|
+
const isFirstProp = propIndex === 0;
|
|
340
|
+
let removeStart = svgrProp.getFullStart();
|
|
341
|
+
let removeEnd = svgrProp.getEnd();
|
|
342
|
+
if (!isLastProp) {
|
|
343
|
+
const nextProp = arg.properties[propIndex + 1];
|
|
344
|
+
removeEnd = nextProp.getFullStart();
|
|
345
|
+
}
|
|
346
|
+
else if (!isFirstProp) {
|
|
347
|
+
const prevProp = arg.properties[propIndex - 1];
|
|
348
|
+
const textBetween = content.substring(prevProp.getEnd(), svgrProp.getFullStart());
|
|
349
|
+
const commaIndex = textBetween.indexOf(',');
|
|
350
|
+
if (commaIndex !== -1) {
|
|
351
|
+
removeStart = prevProp.getEnd() + commaIndex;
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
changes.push({
|
|
355
|
+
type: devkit_1.ChangeType.Delete,
|
|
356
|
+
start: removeStart,
|
|
357
|
+
length: removeEnd - removeStart,
|
|
358
|
+
});
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
// For NxReactRspackPlugin style, wrap the entire module.exports or export default with withSvgr
|
|
365
|
+
if (config.svgrOptions) {
|
|
366
|
+
const allAssignments = (0, tsquery_1.query)(sourceFile, 'BinaryExpression');
|
|
367
|
+
const moduleExportsAssignment = allAssignments.find((node) => {
|
|
368
|
+
const binaryExpr = node;
|
|
369
|
+
const left = binaryExpr.left;
|
|
370
|
+
return (ts.isPropertyAccessExpression(left) &&
|
|
371
|
+
ts.isIdentifier(left.expression) &&
|
|
372
|
+
left.expression.text === 'module' &&
|
|
373
|
+
ts.isIdentifier(left.name) &&
|
|
374
|
+
left.name.text === 'exports');
|
|
375
|
+
});
|
|
376
|
+
const exportDefaultStatements = (0, tsquery_1.query)(sourceFile, 'ExportAssignment');
|
|
377
|
+
const exportDefaultStatement = exportDefaultStatements[0];
|
|
378
|
+
let exportValue;
|
|
379
|
+
if (moduleExportsAssignment) {
|
|
380
|
+
exportValue = moduleExportsAssignment.right;
|
|
381
|
+
}
|
|
382
|
+
else if (exportDefaultStatement) {
|
|
383
|
+
exportValue = exportDefaultStatement.expression;
|
|
384
|
+
}
|
|
385
|
+
if (exportValue) {
|
|
386
|
+
let svgrCallStr = '';
|
|
387
|
+
if (config.svgrOptions === true || config.svgrOptions === undefined) {
|
|
388
|
+
svgrCallStr = 'withSvgr()';
|
|
389
|
+
}
|
|
390
|
+
else if (typeof config.svgrOptions === 'object') {
|
|
391
|
+
const options = Object.entries(config.svgrOptions)
|
|
392
|
+
.map(([key, value]) => ` ${key}: ${value}`)
|
|
393
|
+
.join(',\n');
|
|
394
|
+
svgrCallStr = `withSvgr({\n${options}\n})`;
|
|
395
|
+
}
|
|
396
|
+
changes.push({
|
|
397
|
+
type: devkit_1.ChangeType.Insert,
|
|
398
|
+
index: exportValue.getStart(),
|
|
399
|
+
text: `${svgrCallStr}(`,
|
|
400
|
+
});
|
|
401
|
+
changes.push({
|
|
402
|
+
type: devkit_1.ChangeType.Insert,
|
|
403
|
+
index: exportValue.getEnd(),
|
|
404
|
+
text: ')',
|
|
405
|
+
});
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
content = (0, devkit_1.applyChangesToString)(content, changes);
|
|
410
|
+
tree.write(rspackConfigPath, content);
|
|
411
|
+
}
|
|
412
|
+
await (0, devkit_1.formatFiles)(tree);
|
|
413
|
+
}
|