@nx/rspack 0.0.0-pr-28218-5048fd1

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 (133) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +117 -0
  3. package/executors.json +35 -0
  4. package/generators.json +31 -0
  5. package/migrations.json +98 -0
  6. package/module-federation.d.ts +1 -0
  7. package/module-federation.js +4 -0
  8. package/package.json +49 -0
  9. package/plugin.d.ts +2 -0
  10. package/plugin.js +6 -0
  11. package/src/executors/dev-server/dev-server.impl.d.ts +6 -0
  12. package/src/executors/dev-server/dev-server.impl.js +50 -0
  13. package/src/executors/dev-server/lib/get-dev-server-config.d.ts +4 -0
  14. package/src/executors/dev-server/lib/get-dev-server-config.js +69 -0
  15. package/src/executors/dev-server/lib/serve-path.d.ts +3 -0
  16. package/src/executors/dev-server/lib/serve-path.js +44 -0
  17. package/src/executors/dev-server/schema.d.ts +12 -0
  18. package/src/executors/dev-server/schema.json +45 -0
  19. package/src/executors/module-federation-dev-server/module-federation-dev-server.impl.d.ts +6 -0
  20. package/src/executors/module-federation-dev-server/module-federation-dev-server.impl.js +177 -0
  21. package/src/executors/module-federation-dev-server/schema.d.ts +18 -0
  22. package/src/executors/module-federation-dev-server/schema.json +98 -0
  23. package/src/executors/module-federation-ssr-dev-server/module-federation-ssr-dev-server.impl.d.ts +21 -0
  24. package/src/executors/module-federation-ssr-dev-server/module-federation-ssr-dev-server.impl.js +214 -0
  25. package/src/executors/module-federation-ssr-dev-server/schema.json +79 -0
  26. package/src/executors/module-federation-static-server/module-federation-static-server.impl.d.ts +12 -0
  27. package/src/executors/module-federation-static-server/module-federation-static-server.impl.js +244 -0
  28. package/src/executors/module-federation-static-server/schema.d.ts +3 -0
  29. package/src/executors/module-federation-static-server/schema.json +14 -0
  30. package/src/executors/rspack/rspack.impl.d.ts +6 -0
  31. package/src/executors/rspack/rspack.impl.js +118 -0
  32. package/src/executors/rspack/schema.d.ts +34 -0
  33. package/src/executors/rspack/schema.json +177 -0
  34. package/src/executors/ssr-dev-server/lib/wait-until-server-is-listening.d.ts +1 -0
  35. package/src/executors/ssr-dev-server/lib/wait-until-server-is-listening.js +39 -0
  36. package/src/executors/ssr-dev-server/schema.d.ts +11 -0
  37. package/src/executors/ssr-dev-server/schema.json +36 -0
  38. package/src/executors/ssr-dev-server/ssr-dev-server.impl.d.ts +8 -0
  39. package/src/executors/ssr-dev-server/ssr-dev-server.impl.js +38 -0
  40. package/src/generators/application/application.d.ts +3 -0
  41. package/src/generators/application/application.js +90 -0
  42. package/src/generators/application/lib/create-ts-config.d.ts +3 -0
  43. package/src/generators/application/lib/create-ts-config.js +49 -0
  44. package/src/generators/application/lib/normalize-options.d.ts +5 -0
  45. package/src/generators/application/lib/normalize-options.js +42 -0
  46. package/src/generators/application/schema.d.ts +16 -0
  47. package/src/generators/application/schema.json +98 -0
  48. package/src/generators/configuration/configuration.d.ts +4 -0
  49. package/src/generators/configuration/configuration.js +79 -0
  50. package/src/generators/configuration/schema.d.ts +12 -0
  51. package/src/generators/configuration/schema.json +73 -0
  52. package/src/generators/init/init.d.ts +5 -0
  53. package/src/generators/init/init.js +71 -0
  54. package/src/generators/init/schema.d.ts +11 -0
  55. package/src/generators/init/schema.json +31 -0
  56. package/src/generators/preset/preset.d.ts +3 -0
  57. package/src/generators/preset/preset.js +34 -0
  58. package/src/generators/preset/schema.d.ts +18 -0
  59. package/src/generators/preset/schema.json +71 -0
  60. package/src/index.d.ts +6 -0
  61. package/src/index.js +9 -0
  62. package/src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages.d.ts +2 -0
  63. package/src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages.js +9 -0
  64. package/src/plugins/generate-package-json-plugin.d.ts +12 -0
  65. package/src/plugins/generate-package-json-plugin.js +46 -0
  66. package/src/plugins/plugin.d.ts +9 -0
  67. package/src/plugins/plugin.js +149 -0
  68. package/src/utils/config.d.ts +17 -0
  69. package/src/utils/config.js +22 -0
  70. package/src/utils/create-compiler.d.ts +7 -0
  71. package/src/utils/create-compiler.js +33 -0
  72. package/src/utils/generator-utils.d.ts +34 -0
  73. package/src/utils/generator-utils.js +444 -0
  74. package/src/utils/get-copy-patterns.d.ts +9 -0
  75. package/src/utils/get-copy-patterns.js +22 -0
  76. package/src/utils/jest-utils.d.ts +1 -0
  77. package/src/utils/jest-utils.js +8 -0
  78. package/src/utils/mode-utils.d.ts +2 -0
  79. package/src/utils/mode-utils.js +6 -0
  80. package/src/utils/model.d.ts +6 -0
  81. package/src/utils/model.js +2 -0
  82. package/src/utils/module-federation/build-static.remotes.d.ts +4 -0
  83. package/src/utils/module-federation/build-static.remotes.js +69 -0
  84. package/src/utils/module-federation/dependencies.d.ts +6 -0
  85. package/src/utils/module-federation/dependencies.js +56 -0
  86. package/src/utils/module-federation/get-remotes-for-host.d.ts +16 -0
  87. package/src/utils/module-federation/get-remotes-for-host.js +99 -0
  88. package/src/utils/module-federation/index.d.ts +6 -0
  89. package/src/utils/module-federation/index.js +9 -0
  90. package/src/utils/module-federation/models/index.d.ts +47 -0
  91. package/src/utils/module-federation/models/index.js +2 -0
  92. package/src/utils/module-federation/package-json.d.ts +8 -0
  93. package/src/utils/module-federation/package-json.js +12 -0
  94. package/src/utils/module-federation/parse-static-remotes-config.d.ts +13 -0
  95. package/src/utils/module-federation/parse-static-remotes-config.js +34 -0
  96. package/src/utils/module-federation/plugins/runtime-library-control.plugin.d.ts +3 -0
  97. package/src/utils/module-federation/plugins/runtime-library-control.plugin.js +54 -0
  98. package/src/utils/module-federation/public-api.d.ts +8 -0
  99. package/src/utils/module-federation/public-api.js +20 -0
  100. package/src/utils/module-federation/remotes.d.ts +19 -0
  101. package/src/utils/module-federation/remotes.js +77 -0
  102. package/src/utils/module-federation/secondary-entry-points.d.ts +12 -0
  103. package/src/utils/module-federation/secondary-entry-points.js +104 -0
  104. package/src/utils/module-federation/share.d.ts +48 -0
  105. package/src/utils/module-federation/share.js +235 -0
  106. package/src/utils/module-federation/start-remote-proxies.d.ts +5 -0
  107. package/src/utils/module-federation/start-remote-proxies.js +45 -0
  108. package/src/utils/module-federation/start-ssr-remote-proxies.d.ts +5 -0
  109. package/src/utils/module-federation/start-ssr-remote-proxies.js +59 -0
  110. package/src/utils/module-federation/typescript.d.ts +4 -0
  111. package/src/utils/module-federation/typescript.js +53 -0
  112. package/src/utils/module-federation/with-module-federation/package-json.d.ts +8 -0
  113. package/src/utils/module-federation/with-module-federation/package-json.js +12 -0
  114. package/src/utils/module-federation/with-module-federation/utils.d.ts +12 -0
  115. package/src/utils/module-federation/with-module-federation/utils.js +76 -0
  116. package/src/utils/module-federation/with-module-federation/with-module-federation-ssr.d.ts +3 -0
  117. package/src/utils/module-federation/with-module-federation/with-module-federation-ssr.js +55 -0
  118. package/src/utils/module-federation/with-module-federation/with-module-federation.d.ts +8 -0
  119. package/src/utils/module-federation/with-module-federation/with-module-federation.js +70 -0
  120. package/src/utils/normalize-assets.d.ts +1 -0
  121. package/src/utils/normalize-assets.js +42 -0
  122. package/src/utils/read-rspack-options.d.ts +10 -0
  123. package/src/utils/read-rspack-options.js +37 -0
  124. package/src/utils/resolve-user-defined-rspack-config.d.ts +3 -0
  125. package/src/utils/resolve-user-defined-rspack-config.js +38 -0
  126. package/src/utils/versions.d.ts +21 -0
  127. package/src/utils/versions.js +24 -0
  128. package/src/utils/with-nx.d.ts +3 -0
  129. package/src/utils/with-nx.js +187 -0
  130. package/src/utils/with-react.d.ts +3 -0
  131. package/src/utils/with-react.js +69 -0
  132. package/src/utils/with-web.d.ts +9 -0
  133. package/src/utils/with-web.js +106 -0
@@ -0,0 +1,444 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.findExistingTargetsInProject = findExistingTargetsInProject;
4
+ exports.addOrChangeBuildTarget = addOrChangeBuildTarget;
5
+ exports.addOrChangeServeTarget = addOrChangeServeTarget;
6
+ exports.writeRspackConfigFile = writeRspackConfigFile;
7
+ exports.deleteWebpackConfig = deleteWebpackConfig;
8
+ exports.moveAndEditIndexHtml = moveAndEditIndexHtml;
9
+ exports.normalizeViteConfigFilePathWithTree = normalizeViteConfigFilePathWithTree;
10
+ exports.getViteConfigPathForProject = getViteConfigPathForProject;
11
+ exports.handleUnsupportedUserProvidedTargets = handleUnsupportedUserProvidedTargets;
12
+ exports.handleUnknownExecutors = handleUnknownExecutors;
13
+ exports.determineFrameworkAndTarget = determineFrameworkAndTarget;
14
+ exports.determineMain = determineMain;
15
+ exports.determineTsConfig = determineTsConfig;
16
+ const devkit_1 = require("@nx/devkit");
17
+ const ensure_typescript_1 = require("@nx/js/src/utils/typescript/ensure-typescript");
18
+ function findExistingTargetsInProject(targets, userProvidedTargets) {
19
+ const output = {
20
+ validFoundTargetName: {},
21
+ projectContainsUnsupportedExecutor: false,
22
+ userProvidedTargetIsUnsupported: {},
23
+ alreadyHasNxRspackTargets: {},
24
+ };
25
+ const supportedExecutors = {
26
+ build: [
27
+ '@nxext/vite:build',
28
+ '@nrwl/webpack:webpack',
29
+ '@nrwl/rollup:rollup',
30
+ '@nrwl/web:rollup',
31
+ '@nrwl/vite:build',
32
+ '@nx/webpack:webpack',
33
+ '@nx/rollup:rollup',
34
+ '@nx/web:rollup',
35
+ '@nx/vite:build',
36
+ ],
37
+ serve: [
38
+ '@nxext/vite:dev',
39
+ '@nrwl/webpack:dev-server',
40
+ '@nrwl/vite:dev-server',
41
+ '@nx/webpack:dev-server',
42
+ '@nx/vite:dev-server',
43
+ ],
44
+ };
45
+ const unsupportedExecutors = [
46
+ '@nx/js:babel',
47
+ '@nx/js:node',
48
+ '@nx/js:swc',
49
+ '@nx/react-native:run-ios',
50
+ '@nx/react-native:start',
51
+ '@nx/react-native:run-android',
52
+ '@nx/react-native:bundle',
53
+ '@nx/react-native:build-android',
54
+ '@nx/react-native:bundle',
55
+ '@nx/next:build',
56
+ '@nx/next:server',
57
+ '@nx/js:tsc',
58
+ '@nx/angular:ng-packagr-lite',
59
+ '@nx/angular:package',
60
+ '@nx/angular:webpack-browser',
61
+ '@nx/esbuild:esbuild',
62
+ '@nrwl/js:babel',
63
+ '@nrwl/js:node',
64
+ '@nrwl/js:swc',
65
+ '@nrwl/react-native:run-ios',
66
+ '@nrwl/react-native:start',
67
+ '@nrwl/react-native:run-android',
68
+ '@nrwl/react-native:bundle',
69
+ '@nrwl/react-native:build-android',
70
+ '@nrwl/react-native:bundle',
71
+ '@nrwl/next:build',
72
+ '@nrwl/next:server',
73
+ '@nrwl/js:tsc',
74
+ '@nrwl/angular:ng-packagr-lite',
75
+ '@nrwl/angular:package',
76
+ '@nrwl/angular:webpack-browser',
77
+ '@nrwl/esbuild:esbuild',
78
+ '@angular-devkit/build-angular:browser',
79
+ '@angular-devkit/build-angular:dev-server',
80
+ ];
81
+ // First, we check if the user has provided a target
82
+ // If they have, we check if the executor the target is using is supported
83
+ // If it's not supported, then we set the unsupported flag to true for that target
84
+ function checkUserProvidedTarget(target) {
85
+ if (userProvidedTargets?.[target]) {
86
+ if (supportedExecutors[target].includes(targets[userProvidedTargets[target]]?.executor)) {
87
+ output.validFoundTargetName[target] = userProvidedTargets[target];
88
+ }
89
+ else {
90
+ output.userProvidedTargetIsUnsupported[target] = true;
91
+ }
92
+ }
93
+ }
94
+ checkUserProvidedTarget('build');
95
+ checkUserProvidedTarget('serve');
96
+ // Returns early when we have a build, serve, and test targets.
97
+ if (output.validFoundTargetName.build && output.validFoundTargetName.serve) {
98
+ return output;
99
+ }
100
+ // We try to find the targets that are using the supported executors
101
+ // for build, serve and test, since these are the ones we will be converting
102
+ for (const target in targets) {
103
+ const executorName = targets[target].executor;
104
+ const hasRspackTargets = output.alreadyHasNxRspackTargets;
105
+ hasRspackTargets.build ||= executorName === '@nx/rspack:rspack';
106
+ hasRspackTargets.serve ||= executorName === '@nx/rspack:dev-server';
107
+ const foundTargets = output.validFoundTargetName;
108
+ if (!foundTargets.build &&
109
+ supportedExecutors.build.includes(executorName)) {
110
+ foundTargets.build = target;
111
+ }
112
+ if (!foundTargets.serve &&
113
+ supportedExecutors.serve.includes(executorName)) {
114
+ foundTargets.serve = target;
115
+ }
116
+ output.projectContainsUnsupportedExecutor ||=
117
+ unsupportedExecutors.includes(executorName);
118
+ }
119
+ return output;
120
+ }
121
+ function addOrChangeBuildTarget(tree, options, target) {
122
+ const project = (0, devkit_1.readProjectConfiguration)(tree, options.project);
123
+ const assets = [];
124
+ if (options.target === 'web' &&
125
+ tree.exists((0, devkit_1.joinPathFragments)(project.root, 'src/favicon.ico'))) {
126
+ assets.push((0, devkit_1.joinPathFragments)(project.root, 'src/favicon.ico'));
127
+ }
128
+ if (tree.exists((0, devkit_1.joinPathFragments)(project.root, 'src/assets'))) {
129
+ assets.push((0, devkit_1.joinPathFragments)(project.root, 'src/assets'));
130
+ }
131
+ const buildOptions = {
132
+ target: options.target ?? 'web',
133
+ outputPath: (0, devkit_1.joinPathFragments)('dist',
134
+ // If standalone project then use the project's name in dist.
135
+ project.root === '.' ? project.name : project.root),
136
+ main: determineMain(tree, options),
137
+ tsConfig: determineTsConfig(tree, options),
138
+ rspackConfig: (0, devkit_1.joinPathFragments)(project.root, 'rspack.config.js'),
139
+ assets,
140
+ };
141
+ project.targets ??= {};
142
+ project.targets[target] = {
143
+ executor: '@nx/rspack:rspack',
144
+ outputs: ['{options.outputPath}'],
145
+ defaultConfiguration: 'production',
146
+ options: buildOptions,
147
+ configurations: {
148
+ development: {
149
+ mode: 'development',
150
+ },
151
+ production: {
152
+ mode: 'production',
153
+ optimization: options.target === 'web' ? true : undefined,
154
+ sourceMap: false,
155
+ },
156
+ },
157
+ };
158
+ (0, devkit_1.updateProjectConfiguration)(tree, options.project, project);
159
+ }
160
+ function addOrChangeServeTarget(tree, options, target) {
161
+ const project = (0, devkit_1.readProjectConfiguration)(tree, options.project);
162
+ project.targets ??= {};
163
+ project.targets[target] = {
164
+ executor: '@nx/rspack:dev-server',
165
+ options: {
166
+ buildTarget: `${options.project}:build:development`,
167
+ },
168
+ configurations: {
169
+ development: {},
170
+ production: {
171
+ buildTarget: `${options.project}:build:production`,
172
+ },
173
+ },
174
+ };
175
+ (0, devkit_1.updateProjectConfiguration)(tree, options.project, project);
176
+ }
177
+ function writeRspackConfigFile(tree, options, stylePreprocessorOptions) {
178
+ const project = (0, devkit_1.readProjectConfiguration)(tree, options.project);
179
+ tree.write((0, devkit_1.joinPathFragments)(project.root, 'rspack.config.js'), createConfig(options, stylePreprocessorOptions));
180
+ }
181
+ function createConfig(options, stylePreprocessorOptions) {
182
+ if (options.framework === 'react') {
183
+ return `
184
+ const { composePlugins, withNx, withReact } = require('@nx/rspack');
185
+
186
+ module.exports = composePlugins(withNx(), withReact(${stylePreprocessorOptions
187
+ ? `
188
+ {
189
+ stylePreprocessorOptions: ${JSON.stringify(stylePreprocessorOptions)},
190
+ }
191
+ `
192
+ : ''}), (config) => {
193
+ return config;
194
+ });
195
+ `;
196
+ }
197
+ else if (options.framework === 'web' || options.target === 'web') {
198
+ return `
199
+ const { composePlugins, withNx, withWeb } = require('@nx/rspack');
200
+
201
+ module.exports = composePlugins(withNx(), withWeb(${stylePreprocessorOptions
202
+ ? `
203
+ {
204
+ stylePreprocessorOptions: ${JSON.stringify(stylePreprocessorOptions)},
205
+ }
206
+ `
207
+ : ''}), (config) => {
208
+ return config;
209
+ });
210
+ `;
211
+ }
212
+ else if (options.framework === 'nest') {
213
+ return `
214
+ const { composePlugins, withNx } = require('@nx/rspack');
215
+
216
+ module.exports = composePlugins(withNx(), (config) => {
217
+ return config;
218
+ });
219
+ `;
220
+ }
221
+ else {
222
+ return `
223
+ const { composePlugins, withNx${stylePreprocessorOptions ? ', withWeb' : ''} } = require('@nx/rspack');
224
+
225
+ module.exports = composePlugins(withNx()${stylePreprocessorOptions
226
+ ? `,
227
+ withWeb({
228
+ stylePreprocessorOptions: ${JSON.stringify(stylePreprocessorOptions)},
229
+ })`
230
+ : ''}, (config) => {
231
+ return config;
232
+ });
233
+ `;
234
+ }
235
+ }
236
+ function deleteWebpackConfig(tree, projectRoot, webpackConfigFilePath) {
237
+ const webpackConfigPath = webpackConfigFilePath && tree.exists(webpackConfigFilePath)
238
+ ? webpackConfigFilePath
239
+ : tree.exists(`${projectRoot}/webpack.config.js`)
240
+ ? `${projectRoot}/webpack.config.js`
241
+ : tree.exists(`${projectRoot}/webpack.config.ts`)
242
+ ? `${projectRoot}/webpack.config.ts`
243
+ : null;
244
+ if (webpackConfigPath) {
245
+ tree.delete(webpackConfigPath);
246
+ }
247
+ }
248
+ // Maybe add delete vite config?
249
+ function moveAndEditIndexHtml(tree, options, buildTarget) {
250
+ const projectConfig = (0, devkit_1.readProjectConfiguration)(tree, options.project);
251
+ let indexHtmlPath = projectConfig.targets?.[buildTarget]?.options?.index ??
252
+ `${projectConfig.root}/src/index.html`;
253
+ let mainPath = projectConfig.targets?.[buildTarget]?.options?.main ??
254
+ `${projectConfig.root}/src/main.ts${options.framework === 'react' ? 'x' : ''}`;
255
+ if (projectConfig.root !== '.') {
256
+ mainPath = mainPath.replace(projectConfig.root, '');
257
+ }
258
+ if (!tree.exists(indexHtmlPath) &&
259
+ tree.exists(`${projectConfig.root}/index.html`)) {
260
+ indexHtmlPath = `${projectConfig.root}/index.html`;
261
+ }
262
+ if (tree.exists(indexHtmlPath)) {
263
+ const indexHtmlContent = tree.read(indexHtmlPath, 'utf8');
264
+ if (!indexHtmlContent.includes(`<script type="module" src="${mainPath}"></script>`)) {
265
+ tree.write(`${projectConfig.root}/index.html`, indexHtmlContent.replace('</body>', `<script type="module" src="${mainPath}"></script>
266
+ </body>`));
267
+ if (tree.exists(`${projectConfig.root}/src/index.html`)) {
268
+ tree.delete(`${projectConfig.root}/src/index.html`);
269
+ }
270
+ }
271
+ }
272
+ else {
273
+ tree.write(`${projectConfig.root}/index.html`, `<!DOCTYPE html>
274
+ <html lang="en">
275
+ <head>
276
+ <meta charset="UTF-8" />
277
+ <link rel="icon" href="/favicon.ico" />
278
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
279
+ <title>Vite</title>
280
+ </head>
281
+ <body>
282
+ <div id="root"></div>
283
+ <script type="module" src="${mainPath}"></script>
284
+ </body>
285
+ </html>`);
286
+ }
287
+ }
288
+ function normalizeViteConfigFilePathWithTree(tree, projectRoot, configFile) {
289
+ return configFile && tree.exists(configFile)
290
+ ? configFile
291
+ : tree.exists((0, devkit_1.joinPathFragments)(`${projectRoot}/rspack.config.ts`))
292
+ ? (0, devkit_1.joinPathFragments)(`${projectRoot}/rspack.config.ts`)
293
+ : tree.exists((0, devkit_1.joinPathFragments)(`${projectRoot}/rspack.config.js`))
294
+ ? (0, devkit_1.joinPathFragments)(`${projectRoot}/rspack.config.js`)
295
+ : undefined;
296
+ }
297
+ function getViteConfigPathForProject(tree, projectName, target) {
298
+ let viteConfigPath;
299
+ const { targets, root } = (0, devkit_1.readProjectConfiguration)(tree, projectName);
300
+ if (target) {
301
+ viteConfigPath = targets?.[target]?.options?.configFile;
302
+ }
303
+ else {
304
+ const config = Object.values(targets).find((config) => config.executor === '@nx/rspack:build');
305
+ viteConfigPath = config?.options?.configFile;
306
+ }
307
+ return normalizeViteConfigFilePathWithTree(tree, root, viteConfigPath);
308
+ }
309
+ async function handleUnsupportedUserProvidedTargets(userProvidedTargetIsUnsupported, userProvidedTargetName, validFoundTargetName, framework) {
310
+ if (userProvidedTargetIsUnsupported.build && validFoundTargetName.build) {
311
+ await handleUnsupportedUserProvidedTargetsErrors(userProvidedTargetName.build, validFoundTargetName.build, 'build', 'rspack');
312
+ }
313
+ if (framework !== 'nest' &&
314
+ userProvidedTargetIsUnsupported.serve &&
315
+ validFoundTargetName.serve) {
316
+ await handleUnsupportedUserProvidedTargetsErrors(userProvidedTargetName.serve, validFoundTargetName.serve, 'serve', 'dev-server');
317
+ }
318
+ }
319
+ async function handleUnsupportedUserProvidedTargetsErrors(userProvidedTargetName, validFoundTargetName, target, executor) {
320
+ devkit_1.logger.warn(`The custom ${target} target you provided (${userProvidedTargetName}) cannot be converted to use the @nx/rspack:${executor} executor.
321
+ However, we found the following ${target} target in your project that can be converted: ${validFoundTargetName}
322
+
323
+ Please note that converting a potentially non-compatible project to use Vite.js may result in unexpected behavior. Always commit
324
+ your changes before converting a project to use Vite.js, and test the converted project thoroughly before deploying it.
325
+ `);
326
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
327
+ const { Confirm } = require('enquirer');
328
+ const prompt = new Confirm({
329
+ name: 'question',
330
+ message: `Should we convert the ${validFoundTargetName} target to use the @nx/rspack:${executor} executor?`,
331
+ initial: true,
332
+ });
333
+ const shouldConvert = await prompt.run();
334
+ if (!shouldConvert) {
335
+ throw new Error(`The ${target} target ${userProvidedTargetName} cannot be converted to use the @nx/rspack:${executor} executor.
336
+ Please try again, either by providing a different ${target} target or by not providing a target at all (Nx will
337
+ convert the first one it finds, most probably this one: ${validFoundTargetName})
338
+
339
+ Please note that converting a potentially non-compatible project to use Vite.js may result in unexpected behavior. Always commit
340
+ your changes before converting a project to use Vite.js, and test the converted project thoroughly before deploying it.
341
+ `);
342
+ }
343
+ }
344
+ async function handleUnknownExecutors(projectName) {
345
+ devkit_1.logger.warn(`
346
+ We could not find any targets in project ${projectName} that use executors which
347
+ can be converted to the @nx/rspack executors.
348
+
349
+ This either means that your project may not have a target
350
+ for building, serving, or testing at all, or that your targets are
351
+ using executors that are not known to Nx.
352
+
353
+ If you still want to convert your project to use the @nx/rspack executors,
354
+ please make sure to commit your changes before running this generator.
355
+ `);
356
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
357
+ const { Confirm } = require('enquirer');
358
+ const prompt = new Confirm({
359
+ name: 'question',
360
+ message: `Should Nx convert your project to use the @nx/rspack executors?`,
361
+ initial: true,
362
+ });
363
+ const shouldConvert = await prompt.run();
364
+ if (!shouldConvert) {
365
+ throw new Error(`
366
+ Nx could not verify that the executors you are using can be converted to the @nx/rspack executors.
367
+ Please try again with a different project.
368
+ `);
369
+ }
370
+ }
371
+ function determineFrameworkAndTarget(tree, options, projectRoot, targets) {
372
+ (0, ensure_typescript_1.ensureTypescript)();
373
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
374
+ const { tsquery } = require('@phenomnomnominal/tsquery');
375
+ // First try to infer if the target is node
376
+ if (options.target !== 'node') {
377
+ // Try to infer from jest config if the env is node
378
+ let jestConfigPath;
379
+ if (targets?.test?.executor !== '@nx/jest:jest' &&
380
+ targets?.test?.options?.jestConfig) {
381
+ jestConfigPath = targets?.test?.options?.jestConfig;
382
+ }
383
+ else {
384
+ jestConfigPath = (0, devkit_1.joinPathFragments)(projectRoot, 'jest.config.ts');
385
+ }
386
+ if (!tree.exists(jestConfigPath)) {
387
+ return { target: options.target, framework: options.framework };
388
+ }
389
+ const appFileContent = tree.read(jestConfigPath, 'utf-8');
390
+ const file = tsquery.ast(appFileContent);
391
+ // find testEnvironment: 'node' in jest config
392
+ const testEnvironment = tsquery(file, `PropertyAssignment:has(Identifier[name="testEnvironment"]) > StringLiteral[value="node"]`);
393
+ if (testEnvironment.length > 0) {
394
+ return { target: 'node', framework: options.framework };
395
+ }
396
+ if (tree.exists((0, devkit_1.joinPathFragments)(projectRoot, 'src/main.ts'))) {
397
+ const appFileContent = tree.read((0, devkit_1.joinPathFragments)(projectRoot, 'src/main.ts'), 'utf-8');
398
+ const file = tsquery.ast(appFileContent);
399
+ const hasNestJsDependency = tsquery(file, `ImportDeclaration:has(StringLiteral[value="@nestjs/common"])`);
400
+ if (hasNestJsDependency?.length > 0) {
401
+ return { target: 'node', framework: 'nest' };
402
+ }
403
+ }
404
+ }
405
+ if (options.framework === 'nest') {
406
+ return { target: 'node', framework: 'nest' };
407
+ }
408
+ if (options.framework !== 'react' && options.target === 'web') {
409
+ // Look if React is used in the project
410
+ let tsConfigPath = (0, devkit_1.joinPathFragments)(projectRoot, 'tsconfig.json');
411
+ if (!tree.exists(tsConfigPath)) {
412
+ tsConfigPath = determineTsConfig(tree, options);
413
+ }
414
+ const tsConfig = JSON.parse(tree.read(tsConfigPath).toString());
415
+ if (tsConfig?.compilerOptions?.jsx?.includes('react')) {
416
+ return { target: 'web', framework: 'react' };
417
+ }
418
+ else {
419
+ return { target: options.target, framework: options.framework };
420
+ }
421
+ }
422
+ return { target: options.target, framework: options.framework };
423
+ }
424
+ function determineMain(tree, options) {
425
+ if (options.main)
426
+ return options.main;
427
+ const project = (0, devkit_1.readProjectConfiguration)(tree, options.project);
428
+ const mainTsx = (0, devkit_1.joinPathFragments)(project.root, 'src/main.tsx');
429
+ if (tree.exists(mainTsx))
430
+ return mainTsx;
431
+ return (0, devkit_1.joinPathFragments)(project.root, 'src/main.ts');
432
+ }
433
+ function determineTsConfig(tree, options) {
434
+ if (options.tsConfig)
435
+ return options.tsConfig;
436
+ const project = (0, devkit_1.readProjectConfiguration)(tree, options.project);
437
+ const appJson = (0, devkit_1.joinPathFragments)(project.root, 'tsconfig.app.json');
438
+ if (tree.exists(appJson))
439
+ return appJson;
440
+ const libJson = (0, devkit_1.joinPathFragments)(project.root, 'tsconfig.lib.json');
441
+ if (tree.exists(libJson))
442
+ return libJson;
443
+ return (0, devkit_1.joinPathFragments)(project.root, 'tsconfig.json');
444
+ }
@@ -0,0 +1,9 @@
1
+ export declare function getCopyPatterns(assets: any[]): {
2
+ context: any;
3
+ to: any;
4
+ from: any;
5
+ globOptions: {
6
+ ignore: any[];
7
+ dot: boolean;
8
+ };
9
+ }[];
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getCopyPatterns = getCopyPatterns;
4
+ function getCopyPatterns(assets) {
5
+ return assets.map((asset) => {
6
+ return {
7
+ context: asset.input,
8
+ // Now we remove starting slash to make Webpack place it from the output root.
9
+ to: asset.output,
10
+ from: asset.glob,
11
+ globOptions: {
12
+ ignore: [
13
+ '.gitkeep',
14
+ '**/.DS_Store',
15
+ '**/Thumbs.db',
16
+ ...(asset.ignore ?? []),
17
+ ],
18
+ dot: true,
19
+ },
20
+ };
21
+ });
22
+ }
@@ -0,0 +1 @@
1
+ export declare function updateJestConfigContent(content: string): string;
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.updateJestConfigContent = updateJestConfigContent;
4
+ function updateJestConfigContent(content) {
5
+ return content
6
+ .replace('transform: {', "transform: {\n '^(?!.*\\\\.(js|jsx|ts|tsx|css|json)$)': '@nx/react/plugins/jest',")
7
+ .replace(`'babel-jest'`, `['babel-jest', { presets: ['@nx/react/babel'] }]`);
8
+ }
@@ -0,0 +1,2 @@
1
+ import { Mode } from '@rspack/core';
2
+ export declare function isMode(mode: string): mode is Mode;
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isMode = isMode;
4
+ function isMode(mode) {
5
+ return mode === 'development' || mode === 'production' || mode === 'none';
6
+ }
@@ -0,0 +1,6 @@
1
+ import { ExecutorContext } from '@nx/devkit';
2
+ import { RspackExecutorSchema } from '../executors/rspack/schema';
3
+ export interface SharedConfigContext {
4
+ options: RspackExecutorSchema;
5
+ context: ExecutorContext;
6
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,4 @@
1
+ import { ExecutorContext } from '@nx/devkit';
2
+ import { ModuleFederationDevServerOptions } from '../../executors/module-federation-dev-server/schema';
3
+ import type { StaticRemotesConfig } from './parse-static-remotes-config';
4
+ export declare function buildStaticRemotes(staticRemotesConfig: StaticRemotesConfig, nxBin: any, context: ExecutorContext, options: ModuleFederationDevServerOptions): Promise<Record<string, string>>;
@@ -0,0 +1,69 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.buildStaticRemotes = buildStaticRemotes;
4
+ const fs_1 = require("fs");
5
+ const node_child_process_1 = require("node:child_process");
6
+ const cache_directory_1 = require("nx/src/utils/cache-directory");
7
+ const logger_1 = require("nx/src/utils/logger");
8
+ const path_1 = require("path");
9
+ async function buildStaticRemotes(staticRemotesConfig, nxBin, context, options) {
10
+ if (!staticRemotesConfig.remotes.length) {
11
+ return;
12
+ }
13
+ logger_1.logger.info(`NX Building ${staticRemotesConfig.remotes.length} static remotes...`);
14
+ const mappedLocationOfRemotes = {};
15
+ for (const app of staticRemotesConfig.remotes) {
16
+ mappedLocationOfRemotes[app] = `http${options.ssl ? 's' : ''}://${options.host}:${options.staticRemotesPort}/${staticRemotesConfig.config[app].urlSegment}`;
17
+ }
18
+ await new Promise((res, rej) => {
19
+ const staticProcess = (0, node_child_process_1.fork)(nxBin, [
20
+ 'run-many',
21
+ `--target=build`,
22
+ `--projects=${staticRemotesConfig.remotes.join(',')}`,
23
+ ...(context.configurationName
24
+ ? [`--configuration=${context.configurationName}`]
25
+ : []),
26
+ ...(options.parallel ? [`--parallel=${options.parallel}`] : []),
27
+ ], {
28
+ cwd: context.root,
29
+ stdio: ['ignore', 'pipe', 'pipe', 'ipc'],
30
+ });
31
+ // File to debug build failures e.g. 2024-01-01T00_00_0_0Z-build.log'
32
+ const remoteBuildLogFile = (0, path_1.join)(cache_directory_1.workspaceDataDirectory,
33
+ // eslint-disable-next-line
34
+ `${new Date().toISOString().replace(/[:\.]/g, '_')}-build.log`);
35
+ const stdoutStream = (0, fs_1.createWriteStream)(remoteBuildLogFile);
36
+ staticProcess.stdout.on('data', (data) => {
37
+ const ANSII_CODE_REGEX =
38
+ // eslint-disable-next-line no-control-regex
39
+ /[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g;
40
+ const stdoutString = data.toString().replace(ANSII_CODE_REGEX, '');
41
+ stdoutStream.write(stdoutString);
42
+ // in addition to writing into the stdout stream, also show error directly in console
43
+ // so the error is easily discoverable. 'ERROR in' is the key word to search in webpack output.
44
+ if (stdoutString.includes('ERROR in')) {
45
+ logger_1.logger.log(stdoutString);
46
+ }
47
+ if (stdoutString.includes('Successfully ran target build')) {
48
+ staticProcess.stdout.removeAllListeners('data');
49
+ logger_1.logger.info(`NX Built ${staticRemotesConfig.remotes.length} static remotes`);
50
+ res();
51
+ }
52
+ });
53
+ staticProcess.stderr.on('data', (data) => logger_1.logger.info(data.toString()));
54
+ staticProcess.once('exit', (code) => {
55
+ stdoutStream.end();
56
+ staticProcess.stdout.removeAllListeners('data');
57
+ staticProcess.stderr.removeAllListeners('data');
58
+ if (code !== 0) {
59
+ rej(`Remote failed to start. A complete log can be found in: ${remoteBuildLogFile}`);
60
+ }
61
+ else {
62
+ res();
63
+ }
64
+ });
65
+ process.on('SIGTERM', () => staticProcess.kill('SIGTERM'));
66
+ process.on('exit', () => staticProcess.kill('SIGTERM'));
67
+ });
68
+ return mappedLocationOfRemotes;
69
+ }
@@ -0,0 +1,6 @@
1
+ import type { ProjectGraph } from '@nx/devkit';
2
+ import type { WorkspaceLibrary } from './models';
3
+ export declare function getDependentPackagesForProject(projectGraph: ProjectGraph, name: string): {
4
+ workspaceLibraries: WorkspaceLibrary[];
5
+ npmPackages: string[];
6
+ };
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getDependentPackagesForProject = getDependentPackagesForProject;
4
+ const typescript_1 = require("./typescript");
5
+ const devkit_1 = require("@nx/devkit");
6
+ function getDependentPackagesForProject(projectGraph, name) {
7
+ const { npmPackages, workspaceLibraries } = collectDependencies(projectGraph, name);
8
+ return {
9
+ workspaceLibraries: [...workspaceLibraries.values()],
10
+ npmPackages: [...npmPackages],
11
+ };
12
+ }
13
+ function collectDependencies(projectGraph, name, dependencies = {
14
+ workspaceLibraries: new Map(),
15
+ npmPackages: new Set(),
16
+ }, seen = new Set()) {
17
+ if (seen.has(name)) {
18
+ return dependencies;
19
+ }
20
+ seen.add(name);
21
+ (projectGraph.dependencies[name] ?? []).forEach((dependency) => {
22
+ if (dependency.target.startsWith('npm:')) {
23
+ dependencies.npmPackages.add(dependency.target.replace('npm:', ''));
24
+ }
25
+ else {
26
+ dependencies.workspaceLibraries.set(dependency.target, {
27
+ name: dependency.target,
28
+ root: projectGraph.nodes[dependency.target].data.root,
29
+ importKey: getLibraryImportPath(dependency.target, projectGraph),
30
+ });
31
+ collectDependencies(projectGraph, dependency.target, dependencies, seen);
32
+ }
33
+ });
34
+ return dependencies;
35
+ }
36
+ function getLibraryImportPath(library, projectGraph) {
37
+ let buildLibsFromSource = true;
38
+ if (process.env.NX_BUILD_LIBS_FROM_SOURCE) {
39
+ buildLibsFromSource = process.env.NX_BUILD_LIBS_FROM_SOURCE === 'true';
40
+ }
41
+ const libraryNode = projectGraph.nodes[library];
42
+ let sourceRoots = [libraryNode.data.sourceRoot];
43
+ if (!buildLibsFromSource && process.env.NX_BUILD_TARGET) {
44
+ const buildTarget = (0, devkit_1.parseTargetString)(process.env.NX_BUILD_TARGET, projectGraph);
45
+ sourceRoots = (0, devkit_1.getOutputsForTargetAndConfiguration)(buildTarget, {}, libraryNode);
46
+ }
47
+ const tsConfigPathMappings = (0, typescript_1.readTsPathMappings)();
48
+ for (const [key, value] of Object.entries(tsConfigPathMappings)) {
49
+ for (const src of sourceRoots) {
50
+ if (value.find((path) => path.startsWith(src))) {
51
+ return key;
52
+ }
53
+ }
54
+ }
55
+ return undefined;
56
+ }
@@ -0,0 +1,16 @@
1
+ import { type ProjectGraph } from '@nx/devkit';
2
+ import { ModuleFederationConfig } from './models';
3
+ interface ModuleFederationExecutorContext {
4
+ projectName: string;
5
+ projectGraph: ProjectGraph;
6
+ root: string;
7
+ }
8
+ export declare function getRemotes(devRemotes: string[], skipRemotes: string[], config: ModuleFederationConfig, context: ModuleFederationExecutorContext, pathToManifestFile?: string): {
9
+ staticRemotes: string[];
10
+ devRemotes: any[];
11
+ dynamicRemotes: any[];
12
+ remotePorts: any[];
13
+ staticRemotePort: number;
14
+ };
15
+ export declare function getModuleFederationConfig(tsconfigPath: string, workspaceRoot: string, projectRoot: string, pluginName?: 'react' | 'angular'): any;
16
+ export {};