@nx/rspack 24.0.0-beta.1 → 24.0.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.
Files changed (79) hide show
  1. package/dist/src/executors/dev-server/dev-server.impl.js +0 -2
  2. package/dist/src/executors/rspack/lib/config.js +18 -8
  3. package/dist/src/generators/configuration/configuration.js +2 -24
  4. package/dist/src/generators/convert-config-to-rspack-plugin/convert-config-to-rspack-plugin.js +78 -45
  5. package/dist/src/generators/convert-config-to-rspack-plugin/lib/extract-rspack-options.d.ts +1 -0
  6. package/dist/src/generators/convert-config-to-rspack-plugin/lib/extract-rspack-options.js +31 -2
  7. package/dist/src/generators/convert-config-to-rspack-plugin/schema.json +2 -2
  8. package/dist/src/generators/convert-to-inferred/convert-to-inferred.js +5 -4
  9. package/dist/src/generators/convert-to-inferred/utils/build-post-target-transformer.js +13 -5
  10. package/dist/src/generators/convert-to-inferred/utils/serve-post-target-transformer.js +8 -14
  11. package/dist/src/generators/convert-webpack/convert-webpack.js +20 -74
  12. package/dist/src/generators/convert-webpack/lib/transform-plugin-config.d.ts +1 -1
  13. package/dist/src/generators/convert-webpack/lib/transform-plugin-config.js +47 -69
  14. package/dist/src/generators/init/init.js +38 -44
  15. package/dist/src/generators/init/schema.d.ts +0 -1
  16. package/dist/src/migrations/update-24-0-0/finish-inferred-conversion.md +11 -0
  17. package/dist/src/migrations/update-24-0-0/inventory.d.ts +9 -0
  18. package/dist/src/migrations/update-24-0-0/inventory.js +53 -0
  19. package/dist/src/migrations/update-24-0-0/migrate-compose-plugins.d.ts +10 -0
  20. package/dist/src/migrations/update-24-0-0/migrate-compose-plugins.js +60 -0
  21. package/dist/src/migrations/update-24-0-0/migrate-compose-plugins.md +95 -0
  22. package/dist/src/migrations/update-24-0-0/remove-deprecated-executors.d.ts +6 -0
  23. package/dist/src/migrations/update-24-0-0/remove-deprecated-executors.js +36 -0
  24. package/dist/src/migrations/update-24-0-0/remove-deprecated-executors.md +90 -0
  25. package/dist/src/plugins/nx-app-rspack-plugin/nx-app-rspack-plugin.js +4 -1
  26. package/dist/src/utils/config.d.ts +10 -14
  27. package/dist/src/utils/config.js +17 -70
  28. package/dist/src/utils/deprecation.d.ts +1 -6
  29. package/dist/src/utils/deprecation.js +4 -23
  30. package/dist/src/utils/e2e-web-server-info-utils.d.ts +1 -1
  31. package/dist/src/utils/e2e-web-server-info-utils.js +2 -2
  32. package/dist/src/utils/generator-utils.d.ts +0 -2
  33. package/dist/src/utils/generator-utils.js +45 -167
  34. package/dist/src/utils/with-nx.d.ts +5 -9
  35. package/dist/src/utils/with-nx.js +5 -32
  36. package/dist/src/utils/with-react.d.ts +5 -8
  37. package/dist/src/utils/with-react.js +5 -15
  38. package/dist/src/utils/with-web.d.ts +5 -8
  39. package/dist/src/utils/with-web.js +5 -44
  40. package/executors.json +0 -25
  41. package/migrations.json +13 -0
  42. package/package.json +6 -25
  43. package/dist/module-federation.d.ts +0 -4
  44. package/dist/module-federation.js +0 -9
  45. package/dist/src/executors/module-federation-dev-server/lib/index.d.ts +0 -2
  46. package/dist/src/executors/module-federation-dev-server/lib/index.js +0 -5
  47. package/dist/src/executors/module-federation-dev-server/lib/normalize-options.d.ts +0 -4
  48. package/dist/src/executors/module-federation-dev-server/lib/normalize-options.js +0 -19
  49. package/dist/src/executors/module-federation-dev-server/lib/start-remotes.d.ts +0 -5
  50. package/dist/src/executors/module-federation-dev-server/lib/start-remotes.js +0 -33
  51. package/dist/src/executors/module-federation-dev-server/module-federation-dev-server.impl.d.ts +0 -6
  52. package/dist/src/executors/module-federation-dev-server/module-federation-dev-server.impl.js +0 -74
  53. package/dist/src/executors/module-federation-dev-server/schema.d.ts +0 -25
  54. package/dist/src/executors/module-federation-dev-server/schema.json +0 -104
  55. package/dist/src/executors/module-federation-ssr-dev-server/lib/index.d.ts +0 -2
  56. package/dist/src/executors/module-federation-ssr-dev-server/lib/index.js +0 -5
  57. package/dist/src/executors/module-federation-ssr-dev-server/lib/normalize-options.d.ts +0 -4
  58. package/dist/src/executors/module-federation-ssr-dev-server/lib/normalize-options.js +0 -23
  59. package/dist/src/executors/module-federation-ssr-dev-server/lib/start-remotes.d.ts +0 -5
  60. package/dist/src/executors/module-federation-ssr-dev-server/lib/start-remotes.js +0 -34
  61. package/dist/src/executors/module-federation-ssr-dev-server/module-federation-ssr-dev-server.impl.d.ts +0 -5
  62. package/dist/src/executors/module-federation-ssr-dev-server/module-federation-ssr-dev-server.impl.js +0 -65
  63. package/dist/src/executors/module-federation-ssr-dev-server/schema.d.ts +0 -29
  64. package/dist/src/executors/module-federation-ssr-dev-server/schema.json +0 -85
  65. package/dist/src/executors/module-federation-static-server/module-federation-static-server.impl.d.ts +0 -12
  66. package/dist/src/executors/module-federation-static-server/module-federation-static-server.impl.js +0 -237
  67. package/dist/src/executors/module-federation-static-server/schema.d.ts +0 -3
  68. package/dist/src/executors/module-federation-static-server/schema.json +0 -16
  69. package/dist/src/executors/rspack/rspack.impl.d.ts +0 -7
  70. package/dist/src/executors/rspack/rspack.impl.js +0 -127
  71. package/dist/src/executors/rspack/schema.json +0 -410
  72. package/dist/src/generators/convert-webpack/lib/transform-cjs.d.ts +0 -2
  73. package/dist/src/generators/convert-webpack/lib/transform-cjs.js +0 -263
  74. package/dist/src/generators/convert-webpack/lib/transform-esm.d.ts +0 -2
  75. package/dist/src/generators/convert-webpack/lib/transform-esm.js +0 -263
  76. package/dist/src/utils/has-plugin.d.ts +0 -2
  77. package/dist/src/utils/has-plugin.js +0 -10
  78. package/dist/src/utils/module-federation-deprecation.d.ts +0 -6
  79. package/dist/src/utils/module-federation-deprecation.js +0 -30
@@ -1,410 +0,0 @@
1
- {
2
- "$schema": "http://json-schema.org/schema",
3
- "version": 2,
4
- "title": "Rspack build executor",
5
- "description": "Run Rspack via an executor for a project.",
6
- "type": "object",
7
- "x-deprecated": "The `@nx/rspack:rspack` executor is deprecated and will be removed in Nx v24. Run `nx g @nx/rspack:convert-to-inferred` to migrate to the `@nx/rspack/plugin` inferred plugin. See https://nx.dev/docs/guides/tasks--caching/convert-to-inferred for details.",
8
- "properties": {
9
- "target": {
10
- "type": "string",
11
- "description": "The platform to target (e.g. web, node).",
12
- "enum": ["web", "node"]
13
- },
14
- "main": {
15
- "type": "string",
16
- "description": "The main entry file."
17
- },
18
- "outputPath": {
19
- "type": "string",
20
- "description": "The output path for the bundle."
21
- },
22
- "outputFileName": {
23
- "type": "string",
24
- "description": "The main output entry file"
25
- },
26
- "tsConfig": {
27
- "type": "string",
28
- "description": "The tsconfig file to build the project."
29
- },
30
- "skipTypeChecking": {
31
- "alias": "typeCheck",
32
- "type": "boolean",
33
- "description": "Skip the type checking. Default is `false`.",
34
- "x-deprecated": "Use `typeCheckOptions` instead. This option will be removed in Nx 24."
35
- },
36
- "typeCheckOptions": {
37
- "description": "Configure type checking during the build. Set to `true` to enable with defaults (async: true). Set to `false` to disable type checking entirely. Use `{ async: true }` to run type checking in a separate process without blocking the build. Default is `{ async: true }`.",
38
- "oneOf": [
39
- {
40
- "type": "boolean"
41
- },
42
- {
43
- "type": "object",
44
- "properties": {
45
- "async": {
46
- "type": "boolean",
47
- "description": "Run type checking in a separate process without blocking the build.",
48
- "default": true
49
- }
50
- },
51
- "additionalProperties": false
52
- }
53
- ]
54
- },
55
- "index": {
56
- "alias": "indexHtml",
57
- "type": "string",
58
- "description": "HTML File which will be contain the application.",
59
- "x-completion-type": "file",
60
- "x-completion-glob": "**/*@(.html|.htm)"
61
- },
62
- "baseHref": {
63
- "type": "string",
64
- "description": "Base url for the application being built."
65
- },
66
- "deployUrl": {
67
- "type": "string",
68
- "description": "URL where the application will be deployed."
69
- },
70
- "rspackConfig": {
71
- "type": "string",
72
- "description": "The path to the rspack config file."
73
- },
74
- "optimization": {
75
- "description": "Enables optimization of the build output.",
76
- "oneOf": [
77
- {
78
- "type": "object",
79
- "properties": {
80
- "scripts": {
81
- "type": "boolean",
82
- "description": "Enables optimization of the scripts output.",
83
- "default": true
84
- },
85
- "styles": {
86
- "type": "boolean",
87
- "description": "Enables optimization of the styles output.",
88
- "default": true
89
- }
90
- },
91
- "additionalProperties": false
92
- },
93
- {
94
- "type": "boolean"
95
- }
96
- ]
97
- },
98
- "sourceMap": {
99
- "description": "Output sourcemaps. Use 'hidden' for use with error reporting tools without generating sourcemap comment.",
100
- "default": true,
101
- "oneOf": [
102
- {
103
- "type": "boolean"
104
- },
105
- {
106
- "type": "string"
107
- }
108
- ]
109
- },
110
- "assets": {
111
- "type": "array",
112
- "description": "List of static application assets.",
113
- "default": [],
114
- "items": {
115
- "$ref": "#/definitions/assetPattern"
116
- }
117
- },
118
- "extractLicenses": {
119
- "type": "boolean",
120
- "description": "Extract all licenses in a separate file.",
121
- "default": false
122
- },
123
- "fileReplacements": {
124
- "description": "Replace files with other files in the build.",
125
- "type": "array",
126
- "items": {
127
- "type": "object",
128
- "properties": {
129
- "replace": {
130
- "type": "string",
131
- "description": "The file to be replaced.",
132
- "x-completion-type": "file"
133
- },
134
- "with": {
135
- "type": "string",
136
- "description": "The file to replace with.",
137
- "x-completion-type": "file"
138
- }
139
- },
140
- "additionalProperties": false,
141
- "required": ["replace", "with"]
142
- },
143
- "default": []
144
- },
145
- "mode": {
146
- "type": "string",
147
- "description": "Mode to run the build in.",
148
- "enum": ["development", "production", "none"]
149
- },
150
- "generatePackageJson": {
151
- "type": "boolean",
152
- "description": "Generates a `package.json` and pruned lock file with the project's `node_module` dependencies populated for installing in a container. If a `package.json` exists in the project's directory, it will be reused with dependencies populated."
153
- },
154
- "runtimeDependencies": {
155
- "type": "array",
156
- "items": {
157
- "type": "string"
158
- },
159
- "description": "Add runtime dependencies to the generated `package.json` file. Useful for Docker installs. Only works in conjunction with `generatePackageJson` option."
160
- },
161
- "additionalEntryPoints": {
162
- "type": "array",
163
- "items": {
164
- "type": "object",
165
- "properties": {
166
- "entryName": {
167
- "type": "string",
168
- "description": "Name of the additional entry file."
169
- },
170
- "entryPath": {
171
- "type": "string",
172
- "description": "Path to the additional entry file.",
173
- "x-completion-type": "file",
174
- "x-completion-glob": "**/*@(.js|.ts)"
175
- }
176
- }
177
- }
178
- },
179
- "buildLibsFromSource": {
180
- "type": "boolean",
181
- "description": "Read buildable libraries from source instead of building them separately. If set to `false`, the `tsConfig` option must also be set to remap paths.",
182
- "default": true
183
- },
184
- "extractCss": {
185
- "type": "boolean",
186
- "description": "Extract CSS into a `.css` file."
187
- },
188
- "cssModuleHashFunction": {
189
- "type": "string",
190
- "description": "Hash algorithm used to generate CSS module class names. Defaults to `md5`, which FIPS-restricted OpenSSL rejects. Changing it renames generated class names."
191
- },
192
- "externalDependencies": {
193
- "oneOf": [
194
- {
195
- "type": "string",
196
- "enum": ["none", "all"]
197
- },
198
- {
199
- "type": "array",
200
- "items": {
201
- "type": "string"
202
- }
203
- }
204
- ],
205
- "description": "Dependencies to keep external to the bundle. (`all` (default), `none`, or an array of module names)"
206
- },
207
- "generateIndexHtml": {
208
- "type": "boolean",
209
- "description": "Generates `index.html` file to the output path. This can be turned off if using a webpack plugin to generate HTML such as `html-webpack-plugin`."
210
- },
211
- "memoryLimit": {
212
- "type": "number",
213
- "description": "Memory limit for type checking service process in `MB`."
214
- },
215
- "namedChunks": {
216
- "type": "boolean",
217
- "description": "Names the produced bundles according to their entry file."
218
- },
219
- "outputHashing": {
220
- "type": "string",
221
- "description": "Define the output filename cache-busting hashing mode.",
222
- "enum": ["none", "all", "media", "bundles"]
223
- },
224
- "poll": {
225
- "type": "number",
226
- "description": "Enable and define the file watching poll time period."
227
- },
228
- "polyfills": {
229
- "type": "string",
230
- "description": "Polyfills to load before application",
231
- "x-completion-type": "file",
232
- "x-completion-glob": "**/*@(.js|.ts|.tsx)"
233
- },
234
- "postcssConfig": {
235
- "type": "string",
236
- "description": "Set a path to PostCSS config that applies to the app and all libs. Defaults to `undefined`, which auto-detects postcss.config.js files in each `app`/`lib` directory."
237
- },
238
- "progress": {
239
- "type": "boolean",
240
- "description": "Log progress to the console while building."
241
- },
242
- "publicPath": {
243
- "type": "string",
244
- "description": "Set a public path for assets resources with absolute paths."
245
- },
246
- "rebaseRootRelative": {
247
- "type": "boolean",
248
- "description": "Whether to rebase absolute path for assets in postcss cli resources."
249
- },
250
- "runtimeChunk": {
251
- "type": "boolean",
252
- "description": "Use a separate bundle containing the runtime."
253
- },
254
- "scripts": {
255
- "type": "array",
256
- "description": "External Scripts which will be included before the main application entry.",
257
- "items": {
258
- "$ref": "#/definitions/extraEntryPoint"
259
- }
260
- },
261
- "standardRspackConfigFunction": {
262
- "type": "boolean",
263
- "description": "Set to true if the rspack config exports a standard rspack function, not an Nx-specific one. See: https://rspack.dev/config/",
264
- "default": false
265
- },
266
- "statsJson": {
267
- "type": "boolean",
268
- "description": "Generates a 'stats.json' file which can be analyzed using tools such as: 'webpack-bundle-analyzer' See: https://rspack.dev/guide/optimization/analysis"
269
- },
270
- "stylePreprocessorOptions": {
271
- "description": "Options to pass to style preprocessors.",
272
- "type": "object",
273
- "properties": {
274
- "includePaths": {
275
- "description": "Paths to include. Paths will be resolved to project root.",
276
- "type": "array",
277
- "items": {
278
- "type": "string"
279
- }
280
- },
281
- "sassOptions": {
282
- "description": "Options to pass to sass-loader.",
283
- "type": "object"
284
- },
285
- "lessOptions": {
286
- "description": "Options to pass to less-loader.",
287
- "type": "object"
288
- }
289
- },
290
- "additionalProperties": false
291
- },
292
- "styles": {
293
- "type": "array",
294
- "description": "External Styles which will be included with the application",
295
- "items": {
296
- "$ref": "#/definitions/extraEntryPoint"
297
- }
298
- },
299
- "transformers": {
300
- "type": "array",
301
- "description": "List of TypeScript Compiler Transfomers Plugins.",
302
- "aliases": ["tsPlugins"],
303
- "items": {
304
- "$ref": "#/definitions/transformerPattern"
305
- }
306
- },
307
- "vendorChunk": {
308
- "type": "boolean",
309
- "description": "Use a separate bundle containing only vendor libraries."
310
- },
311
- "cache": {
312
- "type": "boolean",
313
- "description": "Configure rspack caching behavior. When not specified, defaults to `true` for Node targets in watch mode, and `undefined` otherwise."
314
- }
315
- },
316
- "required": ["rspackConfig"],
317
- "definitions": {
318
- "assetPattern": {
319
- "oneOf": [
320
- {
321
- "type": "object",
322
- "properties": {
323
- "glob": {
324
- "type": "string",
325
- "description": "The pattern to match."
326
- },
327
- "input": {
328
- "type": "string",
329
- "description": "The input directory path in which to apply 'glob'. Defaults to the project root."
330
- },
331
- "ignore": {
332
- "description": "An array of globs to ignore.",
333
- "type": "array",
334
- "items": {
335
- "type": "string"
336
- }
337
- },
338
- "output": {
339
- "type": "string",
340
- "description": "Absolute path within the output."
341
- },
342
- "watch": {
343
- "type": "boolean",
344
- "description": "Enable re-building when files change.",
345
- "default": false
346
- }
347
- },
348
- "additionalProperties": false,
349
- "required": ["glob", "input", "output"]
350
- },
351
- {
352
- "type": "string"
353
- }
354
- ]
355
- },
356
- "extraEntryPoint": {
357
- "oneOf": [
358
- {
359
- "type": "object",
360
- "properties": {
361
- "input": {
362
- "type": "string",
363
- "description": "The file to include.",
364
- "x-completion-type": "file",
365
- "x-completion-glob": "**/*@(.css|.scss|.less|.sass)"
366
- },
367
- "bundleName": {
368
- "type": "string",
369
- "description": "The bundle name for this extra entry point."
370
- },
371
- "inject": {
372
- "type": "boolean",
373
- "description": "If the bundle will be referenced in the HTML file.",
374
- "default": true
375
- }
376
- },
377
- "additionalProperties": false,
378
- "required": ["input"]
379
- },
380
- {
381
- "type": "string",
382
- "description": "The file to include.",
383
- "x-completion-type": "file",
384
- "x-completion-glob": "**/*@(.css|.scss|.less|.sass)"
385
- }
386
- ]
387
- },
388
- "transformerPattern": {
389
- "oneOf": [
390
- {
391
- "type": "string"
392
- },
393
- {
394
- "type": "object",
395
- "properties": {
396
- "name": {
397
- "type": "string"
398
- },
399
- "options": {
400
- "type": "object",
401
- "additionalProperties": true
402
- }
403
- },
404
- "additionalProperties": false,
405
- "required": ["name"]
406
- }
407
- ]
408
- }
409
- }
410
- }
@@ -1,2 +0,0 @@
1
- import type { Tree } from '@nx/devkit';
2
- export declare function transformCjsConfigFile(tree: Tree, configPath: string): void;
@@ -1,263 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.transformCjsConfigFile = transformCjsConfigFile;
4
- const tsquery_1 = require("@phenomnomnominal/tsquery");
5
- function transformCjsConfigFile(tree, configPath) {
6
- const configContents = tree.read(configPath, 'utf-8');
7
- const usesJsExtensions = detectJsExtensions(configContents);
8
- ['@nx', '@nrwl'].forEach((scope) => {
9
- transformComposePlugins(tree, configPath, scope);
10
- transformWithNx(tree, configPath, scope);
11
- transformWithWeb(tree, configPath, scope);
12
- transformWithReact(tree, configPath, scope);
13
- transformModuleFederationConfig(tree, configPath, scope);
14
- transformWithModuleFederation(tree, configPath, scope, usesJsExtensions);
15
- transformWithModuleFederationSSR(tree, configPath, scope, usesJsExtensions);
16
- });
17
- // Add useLegacyHtmlPlugin: true to withWeb() calls
18
- transformWithWebCalls(tree, configPath);
19
- }
20
- function detectJsExtensions(configContents) {
21
- // Check if any require calls use .js extensions
22
- const requireWithJsExtensionRegex = /require\s*\(\s*['"]@nx\/[^'"]*\.js['"]\s*\)/;
23
- return requireWithJsExtensionRegex.test(configContents);
24
- }
25
- function transformWithWebCalls(tree, configPath) {
26
- const configContents = tree.read(configPath, 'utf-8');
27
- const sourceFile = (0, tsquery_1.ast)(configContents);
28
- // Find withWeb() calls
29
- const withWebCallNodes = (0, tsquery_1.query)(sourceFile, 'CallExpression > Identifier[name=withWeb]');
30
- // If there are withWeb calls, update them
31
- if (withWebCallNodes.length > 0) {
32
- let newContents = configContents;
33
- for (const node of withWebCallNodes) {
34
- const callExpr = node.parent;
35
- if (!callExpr)
36
- continue;
37
- const startPos = callExpr.getStart();
38
- const endPos = callExpr.getEnd();
39
- const callText = configContents.substring(startPos, endPos);
40
- // Skip if useLegacyHtmlPlugin is already present
41
- if (callText.includes('useLegacyHtmlPlugin')) {
42
- continue;
43
- }
44
- // If it's already withWeb({ ... }), add useLegacyHtmlPlugin: true to the options
45
- if (callText.includes('{') && callText.includes('}')) {
46
- const newCallText = callText.replace(/\{\s*/, '{ useLegacyHtmlPlugin: true,\n ');
47
- newContents =
48
- newContents.substring(0, startPos) +
49
- newCallText +
50
- newContents.substring(endPos);
51
- }
52
- else {
53
- // If it's just withWeb(), replace with withWeb({ useLegacyHtmlPlugin: true })
54
- const newCallText = 'withWeb({ useLegacyHtmlPlugin: true })';
55
- newContents =
56
- newContents.substring(0, startPos) +
57
- newCallText +
58
- newContents.substring(endPos);
59
- }
60
- }
61
- if (newContents !== configContents) {
62
- tree.write(configPath, newContents);
63
- }
64
- return;
65
- }
66
- // If no withWeb calls, check for withReact calls
67
- const withReactCallNodes = (0, tsquery_1.query)(sourceFile, 'CallExpression > Identifier[name=withReact]');
68
- if (withReactCallNodes.length === 0) {
69
- return;
70
- }
71
- let newContents = configContents;
72
- for (const node of withReactCallNodes) {
73
- const callExpr = node.parent;
74
- if (!callExpr)
75
- continue;
76
- const startPos = callExpr.getStart();
77
- const endPos = callExpr.getEnd();
78
- const callText = configContents.substring(startPos, endPos);
79
- // Skip if useLegacyHtmlPlugin is already present
80
- if (callText.includes('useLegacyHtmlPlugin')) {
81
- continue;
82
- }
83
- // If it's already withReact({ ... }), add useLegacyHtmlPlugin: true to the options
84
- if (callText.includes('{') && callText.includes('}')) {
85
- const newCallText = callText.replace(/\{\s*/, '{ useLegacyHtmlPlugin: true,\n ');
86
- newContents =
87
- newContents.substring(0, startPos) +
88
- newCallText +
89
- newContents.substring(endPos);
90
- }
91
- else {
92
- // If it's just withReact(), replace with withReact({ useLegacyHtmlPlugin: true })
93
- const newCallText = 'withReact({ useLegacyHtmlPlugin: true })';
94
- newContents =
95
- newContents.substring(0, startPos) +
96
- newCallText +
97
- newContents.substring(endPos);
98
- }
99
- }
100
- if (newContents !== configContents) {
101
- tree.write(configPath, newContents);
102
- }
103
- }
104
- function transformComposePlugins(tree, configPath, scope) {
105
- const configContents = tree.read(configPath, 'utf-8');
106
- const sourceFile = (0, tsquery_1.ast)(configContents);
107
- const HAS_COMPOSE_PLUGINS_FROM_NX_WEBPACK = `VariableDeclaration:has(Identifier[name=composePlugins]) > CallExpression:has(Identifier[name=require]) StringLiteral[value=${scope}/webpack]`;
108
- const nodes = (0, tsquery_1.query)(sourceFile, HAS_COMPOSE_PLUGINS_FROM_NX_WEBPACK);
109
- if (nodes.length === 0) {
110
- return;
111
- }
112
- const COMPOSE_PLUGINS_IMPORT = 'VariableDeclaration:has(Identifier[name=composePlugins]) Identifier[name=composePlugins]';
113
- const composePluginsNodes = (0, tsquery_1.query)(sourceFile, COMPOSE_PLUGINS_IMPORT);
114
- if (nodes.length === 0) {
115
- return;
116
- }
117
- const startIndex = composePluginsNodes[0].getStart();
118
- let endIndex = composePluginsNodes[0].getEnd();
119
- if (configContents.charAt(endIndex) === ',') {
120
- endIndex++;
121
- }
122
- const newContents = `const { composePlugins } = require('@nx/rspack');
123
- ${configContents.slice(0, startIndex)}${configContents.slice(endIndex)}`;
124
- tree.write(configPath, newContents);
125
- }
126
- function transformWithNx(tree, configPath, scope) {
127
- const configContents = tree.read(configPath, 'utf-8');
128
- const sourceFile = (0, tsquery_1.ast)(configContents);
129
- const HAS_WITH_NX_FROM_NX_WEBPACK = `VariableDeclaration:has(Identifier[name=withNx]) > CallExpression:has(Identifier[name=require]) StringLiteral[value=${scope}/webpack]`;
130
- const nodes = (0, tsquery_1.query)(sourceFile, HAS_WITH_NX_FROM_NX_WEBPACK);
131
- if (nodes.length === 0) {
132
- return;
133
- }
134
- const WITH_NX_IMPORT = 'VariableDeclaration:has(Identifier[name=withNx]) Identifier[name=withNx]';
135
- const withNxNodes = (0, tsquery_1.query)(sourceFile, WITH_NX_IMPORT);
136
- if (nodes.length === 0) {
137
- return;
138
- }
139
- const startIndex = withNxNodes[0].getStart();
140
- let endIndex = withNxNodes[0].getEnd();
141
- if (configContents.charAt(endIndex) === ',') {
142
- endIndex++;
143
- }
144
- const newContents = `const { withNx } = require('@nx/rspack');
145
- ${configContents.slice(0, startIndex)}${configContents.slice(endIndex)}`;
146
- tree.write(configPath, newContents);
147
- }
148
- function transformWithWeb(tree, configPath, scope) {
149
- const configContents = tree.read(configPath, 'utf-8');
150
- const sourceFile = (0, tsquery_1.ast)(configContents);
151
- const HAS_WITH_WEB_FROM_NX_WEBPACK = `VariableDeclaration:has(Identifier[name=withWeb]) > CallExpression:has(Identifier[name=require]) StringLiteral[value=${scope}/webpack]`;
152
- const nodes = (0, tsquery_1.query)(sourceFile, HAS_WITH_WEB_FROM_NX_WEBPACK);
153
- if (nodes.length === 0) {
154
- return;
155
- }
156
- const WITH_WEB_IMPORT = 'VariableDeclaration:has(Identifier[name=withWeb]) Identifier[name=withWeb]';
157
- const withWebNodes = (0, tsquery_1.query)(sourceFile, WITH_WEB_IMPORT);
158
- if (nodes.length === 0) {
159
- return;
160
- }
161
- const startIndex = withWebNodes[0].getStart();
162
- let endIndex = withWebNodes[0].getEnd();
163
- if (configContents.charAt(endIndex) === ',') {
164
- endIndex++;
165
- }
166
- const newContents = `const { withWeb } = require('@nx/rspack');
167
- ${configContents.slice(0, startIndex)}${configContents.slice(endIndex)}`;
168
- tree.write(configPath, newContents);
169
- }
170
- function transformWithReact(tree, configPath, scope) {
171
- const configContents = tree.read(configPath, 'utf-8');
172
- const sourceFile = (0, tsquery_1.ast)(configContents);
173
- const HAS_WITH_REACT_FROM_NX_REACT = `VariableDeclaration:has(Identifier[name=withReact]) > CallExpression:has(Identifier[name=require]) StringLiteral[value=${scope}/react]`;
174
- const nodes = (0, tsquery_1.query)(sourceFile, HAS_WITH_REACT_FROM_NX_REACT);
175
- if (nodes.length === 0) {
176
- return;
177
- }
178
- const WITH_REACT_IMPORT = 'VariableDeclaration:has(Identifier[name=withReact]) Identifier[name=withReact]';
179
- const withReactNodes = (0, tsquery_1.query)(sourceFile, WITH_REACT_IMPORT);
180
- if (nodes.length === 0) {
181
- return;
182
- }
183
- const startIndex = withReactNodes[0].getStart();
184
- let endIndex = withReactNodes[0].getEnd();
185
- if (configContents.charAt(endIndex) === ',') {
186
- endIndex++;
187
- }
188
- const newContents = `const { withReact } = require('@nx/rspack');
189
- ${configContents.slice(0, startIndex)}${configContents.slice(endIndex)}`;
190
- tree.write(configPath, newContents);
191
- }
192
- function transformModuleFederationConfig(tree, configPath, scope) {
193
- const configContents = tree.read(configPath, 'utf-8');
194
- const sourceFile = (0, tsquery_1.ast)(configContents);
195
- const HAS_WITH_MODULE_FEDERATION_FROM_NX_REACT = `VariableDeclaration:has(Identifier[name=ModuleFederationConfig]) > CallExpression:has(Identifier[name=require]) StringLiteral[value=${scope}/webpack]`;
196
- const nodes = (0, tsquery_1.query)(sourceFile, HAS_WITH_MODULE_FEDERATION_FROM_NX_REACT);
197
- if (nodes.length === 0) {
198
- return;
199
- }
200
- const WITH_MODULE_FEDERATION_IMPORT = 'VariableDeclaration:has(Identifier[name=ModuleFederationConfig]) Identifier[name=ModuleFederationConfig]';
201
- const withModuleFederationNodes = (0, tsquery_1.query)(sourceFile, WITH_MODULE_FEDERATION_IMPORT);
202
- if (nodes.length === 0) {
203
- return;
204
- }
205
- const startIndex = withModuleFederationNodes[0].getStart();
206
- let endIndex = withModuleFederationNodes[0].getEnd();
207
- if (configContents.charAt(endIndex) === ',') {
208
- endIndex++;
209
- }
210
- const newContents = `const { ModuleFederationConfig } = require('@nx/module-federation');
211
- ${configContents.slice(0, startIndex)}${configContents.slice(endIndex)}`;
212
- tree.write(configPath, newContents);
213
- }
214
- function transformWithModuleFederation(tree, configPath, scope, usesJsExtensions) {
215
- const configContents = tree.read(configPath, 'utf-8');
216
- const sourceFile = (0, tsquery_1.ast)(configContents);
217
- const HAS_WITH_MODULE_FEDERATION_FROM_NX_REACT = `VariableDeclaration:has(Identifier[name=withModuleFederation]) > CallExpression:has(Identifier[name=require]) StringLiteral[value="${scope}/module-federation/webpack${usesJsExtensions ? '.js' : ''}"]`;
218
- const nodes = (0, tsquery_1.query)(sourceFile, HAS_WITH_MODULE_FEDERATION_FROM_NX_REACT);
219
- if (nodes.length === 0) {
220
- return;
221
- }
222
- const WITH_MODULE_FEDERATION_IMPORT = 'VariableDeclaration:has(Identifier[name=withModuleFederation]) Identifier[name=withModuleFederation]';
223
- const withModuleFederationNodes = (0, tsquery_1.query)(sourceFile, WITH_MODULE_FEDERATION_IMPORT);
224
- if (nodes.length === 0) {
225
- return;
226
- }
227
- const startIndex = withModuleFederationNodes[0].getStart();
228
- let endIndex = withModuleFederationNodes[0].getEnd();
229
- if (configContents.charAt(endIndex) === ',') {
230
- endIndex++;
231
- }
232
- const rspackImport = usesJsExtensions
233
- ? '@nx/module-federation/rspack.js'
234
- : '@nx/module-federation/rspack';
235
- const newContents = `const { withModuleFederation } = require('${rspackImport}');
236
- ${configContents.slice(0, startIndex)}${configContents.slice(endIndex)}`;
237
- tree.write(configPath, newContents);
238
- }
239
- function transformWithModuleFederationSSR(tree, configPath, scope, usesJsExtensions) {
240
- const configContents = tree.read(configPath, 'utf-8');
241
- const sourceFile = (0, tsquery_1.ast)(configContents);
242
- const HAS_WITH_MODULE_FEDERATION_FROM_NX_REACT = `VariableDeclaration:has(Identifier[name=withModuleFederationForSSR]) > CallExpression:has(Identifier[name=require]) StringLiteral[value="${scope}/module-federation/webpack${usesJsExtensions ? '.js' : ''}"]`;
243
- const nodes = (0, tsquery_1.query)(sourceFile, HAS_WITH_MODULE_FEDERATION_FROM_NX_REACT);
244
- if (nodes.length === 0) {
245
- return;
246
- }
247
- const WITH_MODULE_FEDERATION_IMPORT = 'VariableDeclaration:has(Identifier[name=withModuleFederationForSSR]) Identifier[name=withModuleFederationForSSR]';
248
- const withModuleFederationNodes = (0, tsquery_1.query)(sourceFile, WITH_MODULE_FEDERATION_IMPORT);
249
- if (nodes.length === 0) {
250
- return;
251
- }
252
- const startIndex = withModuleFederationNodes[0].getStart();
253
- let endIndex = withModuleFederationNodes[0].getEnd();
254
- if (configContents.charAt(endIndex) === ',') {
255
- endIndex++;
256
- }
257
- const rspackImport = usesJsExtensions
258
- ? '@nx/module-federation/rspack.js'
259
- : '@nx/module-federation/rspack';
260
- const newContents = `const { withModuleFederationForSSR } = require('${rspackImport}');
261
- ${configContents.slice(0, startIndex)}${configContents.slice(endIndex)}`;
262
- tree.write(configPath, newContents);
263
- }
@@ -1,2 +0,0 @@
1
- import type { Tree } from '@nx/devkit';
2
- export declare function transformEsmConfigFile(tree: Tree, configPath: string): void;