@nx/rspack 23.0.0-beta.2 → 23.0.0-beta.21

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.
Files changed (87) hide show
  1. package/migrations.json +52 -8
  2. package/package.json +27 -13
  3. package/src/executors/dev-server/dev-server.impl.d.ts.map +1 -1
  4. package/src/executors/dev-server/dev-server.impl.js +6 -4
  5. package/src/executors/dev-server/schema.json +1 -0
  6. package/src/executors/module-federation-dev-server/module-federation-dev-server.impl.d.ts.map +1 -1
  7. package/src/executors/module-federation-dev-server/module-federation-dev-server.impl.js +6 -4
  8. package/src/executors/module-federation-dev-server/schema.json +1 -0
  9. package/src/executors/module-federation-ssr-dev-server/module-federation-ssr-dev-server.impl.d.ts.map +1 -1
  10. package/src/executors/module-federation-ssr-dev-server/module-federation-ssr-dev-server.impl.js +6 -4
  11. package/src/executors/module-federation-ssr-dev-server/schema.json +1 -0
  12. package/src/executors/module-federation-static-server/module-federation-static-server.impl.d.ts.map +1 -1
  13. package/src/executors/module-federation-static-server/module-federation-static-server.impl.js +6 -4
  14. package/src/executors/module-federation-static-server/schema.json +1 -0
  15. package/src/executors/rspack/lib/normalize-options.js +2 -2
  16. package/src/executors/rspack/rspack.impl.d.ts.map +1 -1
  17. package/src/executors/rspack/rspack.impl.js +6 -4
  18. package/src/executors/rspack/schema.json +1 -0
  19. package/src/executors/ssr-dev-server/ssr-dev-server.impl.d.ts.map +1 -1
  20. package/src/executors/ssr-dev-server/ssr-dev-server.impl.js +2 -2
  21. package/src/generators/configuration/configuration.d.ts.map +1 -1
  22. package/src/generators/configuration/configuration.js +13 -10
  23. package/src/generators/convert-config-to-rspack-plugin/convert-config-to-rspack-plugin.d.ts.map +1 -1
  24. package/src/generators/convert-config-to-rspack-plugin/convert-config-to-rspack-plugin.js +5 -7
  25. package/src/generators/convert-to-inferred/convert-to-inferred.d.ts.map +1 -1
  26. package/src/generators/convert-to-inferred/convert-to-inferred.js +13 -6
  27. package/src/generators/convert-to-inferred/utils/build-post-target-transformer.js +8 -8
  28. package/src/generators/convert-to-inferred/utils/serve-post-target-transformer.d.ts.map +1 -1
  29. package/src/generators/convert-to-inferred/utils/serve-post-target-transformer.js +4 -4
  30. package/src/generators/convert-to-inferred/utils/types.d.ts +1 -1
  31. package/src/generators/convert-to-inferred/utils/types.d.ts.map +1 -1
  32. package/src/generators/convert-webpack/convert-webpack.d.ts.map +1 -1
  33. package/src/generators/convert-webpack/convert-webpack.js +8 -1
  34. package/src/generators/init/init.d.ts.map +1 -1
  35. package/src/generators/init/init.js +14 -7
  36. package/src/generators/init/schema.json +1 -1
  37. package/src/migrations/update-20-2-0/migrate-with-mf-import-to-new-package.d.ts.map +1 -1
  38. package/src/migrations/update-20-2-0/migrate-with-mf-import-to-new-package.js +2 -2
  39. package/src/migrations/update-20-3-0/ensure-nx-module-federation-package.d.ts.map +1 -1
  40. package/src/migrations/update-20-3-0/ensure-nx-module-federation-package.js +2 -2
  41. package/src/migrations/update-22-0-0/remove-deprecated-options.d.ts.map +1 -1
  42. package/src/migrations/update-22-0-0/remove-deprecated-options.js +3 -3
  43. package/src/migrations/update-23-0-0/add-svgr-to-rspack-config.d.ts +3 -0
  44. package/src/migrations/update-23-0-0/add-svgr-to-rspack-config.d.ts.map +1 -0
  45. package/src/migrations/update-23-0-0/add-svgr-to-rspack-config.js +413 -0
  46. package/src/migrations/update-23-0-0/add-svgr-to-rspack-config.md +84 -0
  47. package/src/plugins/nx-react-rspack-plugin/nx-react-rspack-plugin.d.ts +1 -7
  48. package/src/plugins/nx-react-rspack-plugin/nx-react-rspack-plugin.d.ts.map +1 -1
  49. package/src/plugins/plugin.d.ts.map +1 -1
  50. package/src/plugins/plugin.js +17 -27
  51. package/src/plugins/utils/apply-base-config.js +2 -2
  52. package/src/plugins/utils/apply-react-config.d.ts +1 -4
  53. package/src/plugins/utils/apply-react-config.d.ts.map +1 -1
  54. package/src/plugins/utils/apply-react-config.js +1 -32
  55. package/src/plugins/utils/apply-web-config.d.ts.map +1 -1
  56. package/src/plugins/utils/apply-web-config.js +4 -14
  57. package/src/plugins/utils/models.d.ts +1 -10
  58. package/src/plugins/utils/models.d.ts.map +1 -1
  59. package/src/plugins/utils/plugins/normalize-options.js +2 -2
  60. package/src/plugins/utils/plugins/nx-tsconfig-paths-rspack-plugin.js +3 -3
  61. package/src/utils/assert-supported-rspack-version.d.ts +3 -0
  62. package/src/utils/assert-supported-rspack-version.d.ts.map +1 -0
  63. package/src/utils/assert-supported-rspack-version.js +8 -0
  64. package/src/utils/config.js +2 -2
  65. package/src/utils/deprecation.d.ts +6 -0
  66. package/src/utils/deprecation.d.ts.map +1 -0
  67. package/src/utils/deprecation.js +21 -0
  68. package/src/utils/e2e-web-server-info-utils.d.ts +1 -1
  69. package/src/utils/e2e-web-server-info-utils.d.ts.map +1 -1
  70. package/src/utils/e2e-web-server-info-utils.js +6 -5
  71. package/src/utils/generator-utils.d.ts.map +1 -1
  72. package/src/utils/generator-utils.js +3 -4
  73. package/src/utils/module-federation-deprecation.d.ts +7 -0
  74. package/src/utils/module-federation-deprecation.d.ts.map +1 -0
  75. package/src/utils/module-federation-deprecation.js +30 -0
  76. package/src/utils/resolve-user-defined-rspack-config.js +2 -2
  77. package/src/utils/version-utils.d.ts +27 -0
  78. package/src/utils/version-utils.d.ts.map +1 -0
  79. package/src/utils/version-utils.js +53 -0
  80. package/src/utils/versions.d.ts +18 -3
  81. package/src/utils/versions.d.ts.map +1 -1
  82. package/src/utils/versions.js +21 -4
  83. package/src/utils/with-react.d.ts +1 -7
  84. package/src/utils/with-react.d.ts.map +1 -1
  85. package/src/utils/with-react.js +1 -1
  86. package/src/utils/with-web.d.ts +1 -1
  87. package/src/utils/with-web.d.ts.map +1 -1
@@ -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
+ }
@@ -0,0 +1,84 @@
1
+ #### Replace the `svgr` Option with the `withSvgr` Composable in Rspack Configs
2
+
3
+ Updates rspack configs that use React to use a new `withSvgr` composable function instead of passing an `svgr` option to `withReact` or `NxReactRspackPlugin`. The option was removed; SVG handling is now consolidated into the images asset rule by default. The migration inlines a `withSvgr` helper into each affected config so existing SVGR-as-React-component behavior is preserved.
4
+
5
+ #### Sample Code Changes
6
+
7
+ Replace the `svgr` option on `withReact` with a `withSvgr(...)` call composed alongside it.
8
+
9
+ ##### Before
10
+
11
+ ```js title="apps/myapp/rspack.config.js" {5}
12
+ const { composePlugins, withNx, withReact } = require('@nx/rspack');
13
+
14
+ module.exports = composePlugins(
15
+ withNx(),
16
+ withReact({ svgr: { svgo: false, titleProp: true, ref: true } })
17
+ );
18
+ ```
19
+
20
+ ##### After
21
+
22
+ ```js title="apps/myapp/rspack.config.js"
23
+ const { composePlugins, withNx, withReact } = require('@nx/rspack');
24
+
25
+ // SVGR support function (migrated from svgr option in withReact/NxReactRspackPlugin)
26
+ function withSvgr(svgrOptions = {}) {
27
+ const defaultOptions = { svgo: false, titleProp: true, ref: true };
28
+ const options = { ...defaultOptions, ...svgrOptions };
29
+ return function configure(config) {
30
+ const svgLoaderIdx = config.module.rules.findIndex(
31
+ (rule) =>
32
+ typeof rule === 'object' &&
33
+ typeof rule.test !== 'undefined' &&
34
+ rule.test.toString().includes('svg')
35
+ );
36
+ if (svgLoaderIdx !== -1) {
37
+ config.module.rules.splice(svgLoaderIdx, 1);
38
+ }
39
+ config.module.rules.push(
40
+ { test: /\.svg$/i, type: 'asset', resourceQuery: /url/ },
41
+ {
42
+ test: /\.svg$/i,
43
+ issuer: /\.[jt]sx?$/,
44
+ resourceQuery: { not: [/url/] },
45
+ use: [{ loader: '@svgr/webpack', options }],
46
+ }
47
+ );
48
+ return config;
49
+ };
50
+ }
51
+
52
+ module.exports = composePlugins(
53
+ withNx(),
54
+ withReact(),
55
+ withSvgr({ svgo: false, titleProp: true, ref: true })
56
+ );
57
+ ```
58
+
59
+ For the `NxReactRspackPlugin` style, the `svgr` option is removed from the plugin call and the entire `module.exports` is wrapped with a `withSvgr(...)` call that registers the loader rules directly on the compiler.
60
+
61
+ ##### Before
62
+
63
+ ```js title="apps/myapp/rspack.config.js" {5}
64
+ const { NxReactRspackPlugin } = require('@nx/rspack');
65
+
66
+ module.exports = {
67
+ plugins: [new NxReactRspackPlugin({ svgr: true, main: './src/main.tsx' })],
68
+ };
69
+ ```
70
+
71
+ ##### After
72
+
73
+ ```js title="apps/myapp/rspack.config.js"
74
+ const { NxReactRspackPlugin } = require('@nx/rspack');
75
+
76
+ // SVGR support function (migrated from svgr option in withReact/NxReactRspackPlugin)
77
+ function withSvgr(svgrOptions = {}) {
78
+ /* same helper as above, compiler.options.module.rules variant */
79
+ }
80
+
81
+ module.exports = withSvgr()({
82
+ plugins: [new NxReactRspackPlugin({ main: './src/main.tsx' })],
83
+ });
84
+ ```
@@ -1,13 +1,7 @@
1
1
  import type { Compiler } from '@rspack/core';
2
2
  export declare class NxReactRspackPlugin {
3
3
  private options;
4
- constructor(options?: {
5
- /**
6
- * @deprecated SVGR support is deprecated and will be removed in Nx 23.
7
- * TODO(v23): Remove SVGR support
8
- */
9
- svgr?: boolean;
10
- });
4
+ constructor(options?: Record<string, any>);
11
5
  apply(compiler: Compiler): void;
12
6
  }
13
7
  //# sourceMappingURL=nx-react-rspack-plugin.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"nx-react-rspack-plugin.d.ts","sourceRoot":"","sources":["../../../../../../packages/rspack/src/plugins/nx-react-rspack-plugin/nx-react-rspack-plugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAG7C,qBAAa,mBAAmB;IAE5B,OAAO,CAAC,OAAO;gBAAP,OAAO,GAAE;QACf;;;WAGG;QACH,IAAI,CAAC,EAAE,OAAO,CAAC;KACX;IAGR,KAAK,CAAC,QAAQ,EAAE,QAAQ;CAGzB"}
1
+ {"version":3,"file":"nx-react-rspack-plugin.d.ts","sourceRoot":"","sources":["../../../../../../packages/rspack/src/plugins/nx-react-rspack-plugin/nx-react-rspack-plugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAG7C,qBAAa,mBAAmB;IAClB,OAAO,CAAC,OAAO;gBAAP,OAAO,GAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAM;IAErD,KAAK,CAAC,QAAQ,EAAE,QAAQ;CAGzB"}
@@ -1 +1 @@
1
- {"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../../../../../packages/rspack/src/plugins/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,EAGlB,aAAa,EAMd,MAAM,YAAY,CAAC;AAapB,MAAM,WAAW,mBAAmB;IAClC,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,qBAAqB,CAAC,EAAE,MAAM,CAAC;IAC/B,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,mBAAmB,CAAC,EAAE,MAAM,CAAC;CAC9B;AAqBD,eAAO,MAAM,kBAAkB,EAAE,kBAEhC,CAAC;AAIF,eAAO,MAAM,aAAa,EAAE,aAAa,CAAC,mBAAmB,CAgC5D,CAAC"}
1
+ {"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../../../../../packages/rspack/src/plugins/plugin.ts"],"names":[],"mappings":"AACA,OAAO,EACL,kBAAkB,EAGlB,aAAa,EAKd,MAAM,YAAY,CAAC;AAapB,MAAM,WAAW,mBAAmB;IAClC,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,qBAAqB,CAAC,EAAE,MAAM,CAAC;IAC/B,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,mBAAmB,CAAC,EAAE,MAAM,CAAC;CAC9B;AAID,eAAO,MAAM,kBAAkB,EAAE,kBAEhC,CAAC;AAIF,eAAO,MAAM,aAAa,EAAE,aAAa,CAAC,mBAAmB,CAiC5D,CAAC"}
@@ -1,10 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createNodesV2 = exports.createDependencies = void 0;
4
+ const internal_1 = require("@nx/devkit/internal");
4
5
  const devkit_1 = require("@nx/devkit");
5
- const get_named_inputs_1 = require("@nx/devkit/src/utils/get-named-inputs");
6
6
  const js_1 = require("@nx/js");
7
- const ts_solution_setup_1 = require("@nx/js/src/utils/typescript/ts-solution-setup");
7
+ const internal_2 = require("@nx/js/internal");
8
8
  const fs_1 = require("fs");
9
9
  const file_hasher_1 = require("nx/src/hasher/file-hasher");
10
10
  const cache_directory_1 = require("nx/src/utils/cache-directory");
@@ -12,20 +12,6 @@ const package_manager_1 = require("nx/src/utils/package-manager");
12
12
  const path_1 = require("path");
13
13
  const read_rspack_options_1 = require("../utils/read-rspack-options");
14
14
  const resolve_user_defined_rspack_config_1 = require("../utils/resolve-user-defined-rspack-config");
15
- const util_1 = require("@nx/js/src/plugins/typescript/util");
16
- function readTargetsCache(cachePath) {
17
- try {
18
- return process.env.NX_CACHE_PROJECT_GRAPH !== 'false'
19
- ? (0, devkit_1.readJsonFile)(cachePath)
20
- : {};
21
- }
22
- catch {
23
- return {};
24
- }
25
- }
26
- function writeTargetsToCache(cachePath, results) {
27
- (0, devkit_1.writeJsonFile)(cachePath, results);
28
- }
29
15
  const createDependencies = () => {
30
16
  return [];
31
17
  };
@@ -36,18 +22,20 @@ exports.createNodesV2 = [
36
22
  async (configFilePaths, options, context) => {
37
23
  const optionsHash = (0, file_hasher_1.hashObject)(options);
38
24
  const cachePath = (0, path_1.join)(cache_directory_1.workspaceDataDirectory, `rspack-${optionsHash}.hash`);
39
- const targetsCache = readTargetsCache(cachePath);
40
- const isTsSolutionSetup = (0, ts_solution_setup_1.isUsingTsSolutionSetup)();
41
- const pmc = (0, package_manager_1.getPackageManagerCommand)((0, devkit_1.detectPackageManager)(context.workspaceRoot));
25
+ const targetsCache = new internal_1.PluginCache(cachePath);
26
+ const isTsSolutionSetup = (0, internal_2.isUsingTsSolutionSetup)();
27
+ const packageManager = (0, devkit_1.detectPackageManager)(context.workspaceRoot);
28
+ const pmc = (0, package_manager_1.getPackageManagerCommand)(packageManager);
29
+ const lockFileName = (0, js_1.getLockFileName)(packageManager);
42
30
  try {
43
- return await (0, devkit_1.createNodesFromFiles)((configFile, options, context) => createNodesInternal(configFile, options, context, targetsCache, isTsSolutionSetup, pmc), configFilePaths, options, context);
31
+ return await (0, devkit_1.createNodesFromFiles)((configFile, options, context) => createNodesInternal(configFile, options, context, targetsCache, isTsSolutionSetup, pmc, lockFileName), configFilePaths, options, context);
44
32
  }
45
33
  finally {
46
- writeTargetsToCache(cachePath, targetsCache);
34
+ targetsCache.writeToDisk();
47
35
  }
48
36
  },
49
37
  ];
50
- async function createNodesInternal(configFilePath, options, context, targetsCache, isTsSolutionSetup, pmc) {
38
+ async function createNodesInternal(configFilePath, options, context, targetsCache, isTsSolutionSetup, pmc, lockFileName) {
51
39
  const projectRoot = (0, path_1.dirname)(configFilePath);
52
40
  // Do not create a project if package.json and project.json isn't there.
53
41
  const siblingFiles = (0, fs_1.readdirSync)((0, path_1.join)(context.workspaceRoot, projectRoot));
@@ -60,7 +48,7 @@ async function createNodesInternal(configFilePath, options, context, targetsCach
60
48
  packageJson = (0, devkit_1.readJsonFile)((0, path_1.join)(context.workspaceRoot, projectRoot, 'package.json'));
61
49
  }
62
50
  const normalizedOptions = normalizeOptions(options);
63
- const lockFileHash = (0, file_hasher_1.hashFile)((0, path_1.join)(context.workspaceRoot, (0, js_1.getLockFileName)((0, devkit_1.detectPackageManager)(context.workspaceRoot)))) ?? '';
51
+ const lockFileHash = (0, file_hasher_1.hashFile)((0, path_1.join)(context.workspaceRoot, lockFileName)) ?? '';
64
52
  const nodeHash = (0, file_hasher_1.hashArray)([
65
53
  (0, file_hasher_1.hashFile)((0, path_1.join)(context.workspaceRoot, configFilePath)),
66
54
  lockFileHash,
@@ -70,8 +58,10 @@ async function createNodesInternal(configFilePath, options, context, targetsCach
70
58
  // We do not want to alter how the hash is calculated, so appending the config file path to the hash
71
59
  // to prevent vite/vitest files overwriting the target cache created by the other
72
60
  const hash = `${nodeHash}_${configFilePath}`;
73
- targetsCache[hash] ??= await createRspackTargets(configFilePath, projectRoot, normalizedOptions, context, isTsSolutionSetup, pmc);
74
- const { targets, metadata } = targetsCache[hash];
61
+ if (!targetsCache.has(hash)) {
62
+ targetsCache.set(hash, await createRspackTargets(configFilePath, projectRoot, normalizedOptions, context, isTsSolutionSetup, pmc));
63
+ }
64
+ const { targets, metadata } = targetsCache.get(hash);
75
65
  return {
76
66
  projects: {
77
67
  [projectRoot]: {
@@ -83,7 +73,7 @@ async function createNodesInternal(configFilePath, options, context, targetsCach
83
73
  };
84
74
  }
85
75
  async function createRspackTargets(configFilePath, projectRoot, options, context, isTsSolutionSetup, pmc) {
86
- const namedInputs = (0, get_named_inputs_1.getNamedInputs)(projectRoot, context);
76
+ const namedInputs = (0, internal_1.getNamedInputs)(projectRoot, context);
87
77
  const rspackConfig = await (0, resolve_user_defined_rspack_config_1.resolveUserDefinedRspackConfig)((0, path_1.join)(context.workspaceRoot, configFilePath), (0, js_1.getRootTsConfigPath)(), true);
88
78
  const rspackOptions = await (0, read_rspack_options_1.readRspackOptions)(rspackConfig);
89
79
  const outputs = [];
@@ -175,7 +165,7 @@ async function createRspackTargets(configFilePath, projectRoot, options, context
175
165
  '@nx/js:typescript-sync',
176
166
  ];
177
167
  }
178
- (0, util_1.addBuildAndWatchDepsTargets)(context.workspaceRoot, projectRoot, targets, options, pmc);
168
+ (0, internal_2.addBuildAndWatchDepsTargets)(context.workspaceRoot, projectRoot, targets, options, pmc);
179
169
  return { targets, metadata: {} };
180
170
  }
181
171
  function normalizeOptions(options) {
@@ -12,7 +12,7 @@ const hash_format_1 = require("./hash-format");
12
12
  const nx_tsconfig_paths_rspack_plugin_1 = require("./plugins/nx-tsconfig-paths-rspack-plugin");
13
13
  const get_terser_ecma_version_1 = require("./get-terser-ecma-version");
14
14
  const nodeExternals = require("webpack-node-externals");
15
- const ts_solution_setup_1 = require("@nx/js/src/utils/typescript/ts-solution-setup");
15
+ const internal_1 = require("@nx/js/internal");
16
16
  const get_non_buildable_libs_1 = require("./get-non-buildable-libs");
17
17
  const IGNORED_RSPACK_WARNINGS = [
18
18
  /The comment file/i,
@@ -201,7 +201,7 @@ function applyNxIndependentConfig(options, config) {
201
201
  function applyNxDependentConfig(options, config, { useNormalizedEntry } = {}) {
202
202
  const tsConfig = options.tsConfig ?? (0, js_1.getRootTsConfigPath)();
203
203
  const plugins = [];
204
- const isUsingTsSolution = (0, ts_solution_setup_1.isUsingTsSolutionSetup)();
204
+ const isUsingTsSolution = (0, internal_1.isUsingTsSolutionSetup)();
205
205
  const executorContext = {
206
206
  projectName: options.projectName,
207
207
  targetName: options.targetName,
@@ -1,6 +1,3 @@
1
1
  import { Configuration, RspackOptionsNormalized } from '@rspack/core';
2
- import { SvgrOptions } from './models';
3
- export declare function applyReactConfig(options: {
4
- svgr?: boolean | SvgrOptions;
5
- }, config?: Partial<RspackOptionsNormalized | Configuration>): void;
2
+ export declare function applyReactConfig(options?: Record<string, any>, config?: Partial<RspackOptionsNormalized | Configuration>): void;
6
3
  //# sourceMappingURL=apply-react-config.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"apply-react-config.d.ts","sourceRoot":"","sources":["../../../../../../packages/rspack/src/plugins/utils/apply-react-config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,uBAAuB,EAAE,MAAM,cAAc,CAAC;AAEtE,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAGvC,wBAAgB,gBAAgB,CAC9B,OAAO,EAAE;IAAE,IAAI,CAAC,EAAE,OAAO,GAAG,WAAW,CAAA;CAAE,EACzC,MAAM,GAAE,OAAO,CAAC,uBAAuB,GAAG,aAAa,CAAM,GAC5D,IAAI,CA4CN"}
1
+ {"version":3,"file":"apply-react-config.d.ts","sourceRoot":"","sources":["../../../../../../packages/rspack/src/plugins/utils/apply-react-config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,uBAAuB,EAAE,MAAM,cAAc,CAAC;AAEtE,wBAAgB,gBAAgB,CAC9B,OAAO,GAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAM,EACjC,MAAM,GAAE,OAAO,CAAC,uBAAuB,GAAG,aAAa,CAAM,GAC5D,IAAI,CAUN"}