@nx/rspack 20.2.0-beta.2 → 20.2.0-beta.4

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 (103) hide show
  1. package/app-plugin.d.ts +2 -0
  2. package/app-plugin.js +5 -0
  3. package/generators.json +10 -0
  4. package/migrations.json +21 -1
  5. package/module-federation.d.ts +4 -1
  6. package/module-federation.js +7 -2
  7. package/package.json +10 -8
  8. package/react-plugin.d.ts +1 -0
  9. package/react-plugin.js +5 -0
  10. package/src/executors/module-federation-dev-server/module-federation-dev-server.impl.js +5 -7
  11. package/src/executors/module-federation-ssr-dev-server/module-federation-ssr-dev-server.impl.js +5 -7
  12. package/src/executors/module-federation-static-server/module-federation-static-server.impl.d.ts +1 -1
  13. package/src/executors/module-federation-static-server/module-federation-static-server.impl.js +4 -5
  14. package/src/executors/rspack/schema.d.ts +1 -1
  15. package/src/executors/rspack/schema.json +1 -1
  16. package/src/generators/application/application.js +0 -2
  17. package/src/generators/configuration/configuration.js +0 -2
  18. package/src/generators/convert-config-to-rspack-plugin/convert-config-to-rspack-plugin.d.ts +7 -0
  19. package/src/generators/convert-config-to-rspack-plugin/convert-config-to-rspack-plugin.js +92 -0
  20. package/src/generators/convert-config-to-rspack-plugin/lib/extract-rspack-options.d.ts +6 -0
  21. package/src/generators/convert-config-to-rspack-plugin/lib/extract-rspack-options.js +106 -0
  22. package/src/generators/convert-config-to-rspack-plugin/lib/normalize-path-options.d.ts +2 -0
  23. package/src/generators/convert-config-to-rspack-plugin/lib/normalize-path-options.js +73 -0
  24. package/src/generators/convert-config-to-rspack-plugin/lib/utils.d.ts +1 -0
  25. package/src/generators/convert-config-to-rspack-plugin/lib/utils.js +13 -0
  26. package/src/generators/convert-config-to-rspack-plugin/lib/validate-project.d.ts +9 -0
  27. package/src/generators/convert-config-to-rspack-plugin/lib/validate-project.js +40 -0
  28. package/src/generators/convert-config-to-rspack-plugin/schema.json +19 -0
  29. package/src/generators/convert-to-inferred/__snapshots__/convert-to-inferred.spec.ts.snap +268 -0
  30. package/src/generators/convert-to-inferred/convert-to-inferred.d.ts +12 -0
  31. package/src/generators/convert-to-inferred/convert-to-inferred.js +114 -0
  32. package/src/generators/convert-to-inferred/schema.json +19 -0
  33. package/src/generators/convert-to-inferred/utils/ast.d.ts +3 -0
  34. package/src/generators/convert-to-inferred/utils/ast.js +40 -0
  35. package/src/generators/convert-to-inferred/utils/build-post-target-transformer.d.ts +6 -0
  36. package/src/generators/convert-to-inferred/utils/build-post-target-transformer.js +210 -0
  37. package/src/generators/convert-to-inferred/utils/index.d.ts +3 -0
  38. package/src/generators/convert-to-inferred/utils/index.js +6 -0
  39. package/src/generators/convert-to-inferred/utils/serve-post-target-transformer.d.ts +6 -0
  40. package/src/generators/convert-to-inferred/utils/serve-post-target-transformer.js +207 -0
  41. package/src/generators/convert-to-inferred/utils/types.d.ts +11 -0
  42. package/src/generators/convert-webpack/lib/transform-cjs.js +5 -5
  43. package/src/generators/convert-webpack/lib/transform-esm.js +5 -5
  44. package/src/generators/init/init.js +0 -2
  45. package/src/index.d.ts +1 -0
  46. package/src/index.js +1 -0
  47. package/src/migrations/update-20-2-0/migrate-with-mf-import-to-new-package.d.ts +2 -0
  48. package/src/migrations/update-20-2-0/migrate-with-mf-import-to-new-package.js +35 -0
  49. package/src/plugins/nx-app-rspack-plugin/nx-app-rspack-plugin.d.ts +16 -0
  50. package/src/plugins/nx-app-rspack-plugin/nx-app-rspack-plugin.js +43 -0
  51. package/src/plugins/nx-react-rspack-plugin/nx-react-rspack-plugin.d.ts +8 -0
  52. package/src/plugins/nx-react-rspack-plugin/nx-react-rspack-plugin.js +13 -0
  53. package/src/plugins/use-legacy-nx-plugin/use-legacy-nx-plugin.d.ts +31 -0
  54. package/src/plugins/use-legacy-nx-plugin/use-legacy-nx-plugin.js +73 -0
  55. package/src/plugins/utils/apply-base-config.js +3 -0
  56. package/src/plugins/utils/apply-web-config.d.ts +2 -2
  57. package/src/plugins/utils/apply-web-config.js +1 -1
  58. package/src/plugins/utils/plugins/normalize-options.js +1 -1
  59. package/src/plugins/utils/plugins/nx-tsconfig-paths-rspack-plugin.js +3 -2
  60. package/src/utils/create-compiler.js +3 -1
  61. package/src/utils/generator-utils.d.ts +2 -2
  62. package/src/utils/generator-utils.js +134 -67
  63. package/src/utils/has-plugin.d.ts +2 -0
  64. package/src/utils/has-plugin.js +10 -0
  65. package/src/utils/module-federation/build-static.remotes.d.ts +1 -1
  66. package/src/utils/versions.d.ts +2 -2
  67. package/src/utils/versions.js +2 -2
  68. package/src/utils/module-federation/dependencies.d.ts +0 -6
  69. package/src/utils/module-federation/dependencies.js +0 -56
  70. package/src/utils/module-federation/get-remotes-for-host.d.ts +0 -16
  71. package/src/utils/module-federation/get-remotes-for-host.js +0 -99
  72. package/src/utils/module-federation/index.d.ts +0 -6
  73. package/src/utils/module-federation/index.js +0 -9
  74. package/src/utils/module-federation/models/index.d.ts +0 -47
  75. package/src/utils/module-federation/package-json.d.ts +0 -8
  76. package/src/utils/module-federation/package-json.js +0 -12
  77. package/src/utils/module-federation/parse-static-remotes-config.d.ts +0 -13
  78. package/src/utils/module-federation/parse-static-remotes-config.js +0 -34
  79. package/src/utils/module-federation/plugins/runtime-library-control.plugin.d.ts +0 -3
  80. package/src/utils/module-federation/plugins/runtime-library-control.plugin.js +0 -54
  81. package/src/utils/module-federation/public-api.d.ts +0 -8
  82. package/src/utils/module-federation/public-api.js +0 -20
  83. package/src/utils/module-federation/remotes.d.ts +0 -19
  84. package/src/utils/module-federation/remotes.js +0 -85
  85. package/src/utils/module-federation/secondary-entry-points.d.ts +0 -12
  86. package/src/utils/module-federation/secondary-entry-points.js +0 -104
  87. package/src/utils/module-federation/share.d.ts +0 -48
  88. package/src/utils/module-federation/share.js +0 -235
  89. package/src/utils/module-federation/start-remote-proxies.d.ts +0 -5
  90. package/src/utils/module-federation/start-remote-proxies.js +0 -45
  91. package/src/utils/module-federation/start-ssr-remote-proxies.d.ts +0 -5
  92. package/src/utils/module-federation/start-ssr-remote-proxies.js +0 -59
  93. package/src/utils/module-federation/typescript.d.ts +0 -4
  94. package/src/utils/module-federation/typescript.js +0 -53
  95. package/src/utils/module-federation/with-module-federation/package-json.d.ts +0 -8
  96. package/src/utils/module-federation/with-module-federation/package-json.js +0 -12
  97. package/src/utils/module-federation/with-module-federation/utils.d.ts +0 -12
  98. package/src/utils/module-federation/with-module-federation/utils.js +0 -76
  99. package/src/utils/module-federation/with-module-federation/with-module-federation-ssr.d.ts +0 -3
  100. package/src/utils/module-federation/with-module-federation/with-module-federation-ssr.js +0 -62
  101. package/src/utils/module-federation/with-module-federation/with-module-federation.d.ts +0 -8
  102. package/src/utils/module-federation/with-module-federation/with-module-federation.js +0 -70
  103. /package/src/{utils/module-federation/models/index.js → generators/convert-to-inferred/utils/types.js} +0 -0
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NxAppRspackPlugin = void 0;
4
+ const normalize_options_1 = require("../utils/plugins/normalize-options");
5
+ const apply_base_config_1 = require("../utils/apply-base-config");
6
+ const apply_web_config_1 = require("../utils/apply-web-config");
7
+ /**
8
+ * This plugin provides features to build Node and Web applications.
9
+ * - TS Support (including tsconfig paths
10
+ * - Assets handling
11
+ * - Stylesheets handling
12
+ * - index.html and package.json generation
13
+ *
14
+ * Web-only features, such as stylesheets and images, are only supported when `target` is `web` or `webworker`.
15
+ */
16
+ class NxAppRspackPlugin {
17
+ constructor(options = {}) {
18
+ // If we're building inferred targets, skip normalizing the build options
19
+ if (!global.NX_GRAPH_CREATION) {
20
+ this.options = (0, normalize_options_1.normalizeOptions)(options);
21
+ }
22
+ }
23
+ apply(compiler) {
24
+ // Default's to web
25
+ const target = this.options.target ?? compiler.options.target;
26
+ this.options.outputPath ??= compiler.options.output?.path;
27
+ if (typeof target === 'string') {
28
+ this.options.target = target;
29
+ }
30
+ (0, apply_base_config_1.applyBaseConfig)(this.options, compiler.options, {
31
+ useNormalizedEntry: true,
32
+ });
33
+ if (compiler.options.target) {
34
+ this.options.target = compiler.options.target;
35
+ }
36
+ if (this.options.target === 'web' || this.options.target === 'webworker') {
37
+ (0, apply_web_config_1.applyWebConfig)(this.options, compiler.options, {
38
+ useNormalizedEntry: true,
39
+ });
40
+ }
41
+ }
42
+ }
43
+ exports.NxAppRspackPlugin = NxAppRspackPlugin;
@@ -0,0 +1,8 @@
1
+ import type { Compiler } from '@rspack/core';
2
+ export declare class NxReactRspackPlugin {
3
+ private options;
4
+ constructor(options?: {
5
+ svgr?: boolean;
6
+ });
7
+ apply(compiler: Compiler): void;
8
+ }
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NxReactRspackPlugin = void 0;
4
+ const apply_react_config_1 = require("../utils/apply-react-config");
5
+ class NxReactRspackPlugin {
6
+ constructor(options = {}) {
7
+ this.options = options;
8
+ }
9
+ apply(compiler) {
10
+ (0, apply_react_config_1.applyReactConfig)(this.options, compiler.options);
11
+ }
12
+ }
13
+ exports.NxReactRspackPlugin = NxReactRspackPlugin;
@@ -0,0 +1,31 @@
1
+ import type { NxRspackExecutionContext } from '../../utils/config';
2
+ import type { NxAppRspackPluginOptions } from '../utils/models';
3
+ import type { Compiler, Configuration } from '@rspack/core';
4
+ /**
5
+ * This function is used to wrap the legacy plugin function to be used with the `composePlugins` function.
6
+ * Initially the rspack config would be passed to the legacy plugin function and the options would be passed as a second argument.
7
+ * example:
8
+ * module.exports = composePlugins(
9
+ withNx(),
10
+ (config) => {
11
+ return config;
12
+ }
13
+ );
14
+
15
+ Since composePlugins is async, this function is used to wrap the legacy plugin function to be async.
16
+ Using the nxUseLegacyPlugin function, the first argument is the legacy plugin function and the second argument is the options.
17
+ The context options are created and passed to the legacy plugin function.
18
+
19
+ module.exports = async () => ({
20
+ plugins: [
21
+ ...otherPlugins,
22
+ await nxUseLegacyPlugin(require({path}), options),
23
+ ],
24
+ });
25
+ * @param fn The legacy plugin function usually from `combinedPlugins`
26
+ * @param executorOptions The options passed usually inside the executor or the config file
27
+ * @returns Rspack configuration
28
+ */
29
+ export declare function useLegacyNxPlugin(fn: (config: Configuration, ctx: NxRspackExecutionContext) => Promise<Configuration>, executorOptions: NxAppRspackPluginOptions): Promise<{
30
+ apply(compiler: Compiler): void;
31
+ }>;
@@ -0,0 +1,73 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useLegacyNxPlugin = useLegacyNxPlugin;
4
+ const devkit_1 = require("@nx/devkit");
5
+ const normalize_options_1 = require("../utils/plugins/normalize-options");
6
+ const configuration_1 = require("nx/src/config/configuration");
7
+ /**
8
+ * This function is used to wrap the legacy plugin function to be used with the `composePlugins` function.
9
+ * Initially the rspack config would be passed to the legacy plugin function and the options would be passed as a second argument.
10
+ * example:
11
+ * module.exports = composePlugins(
12
+ withNx(),
13
+ (config) => {
14
+ return config;
15
+ }
16
+ );
17
+
18
+ Since composePlugins is async, this function is used to wrap the legacy plugin function to be async.
19
+ Using the nxUseLegacyPlugin function, the first argument is the legacy plugin function and the second argument is the options.
20
+ The context options are created and passed to the legacy plugin function.
21
+
22
+ module.exports = async () => ({
23
+ plugins: [
24
+ ...otherPlugins,
25
+ await nxUseLegacyPlugin(require({path}), options),
26
+ ],
27
+ });
28
+ * @param fn The legacy plugin function usually from `combinedPlugins`
29
+ * @param executorOptions The options passed usually inside the executor or the config file
30
+ * @returns Rspack configuration
31
+ */
32
+ async function useLegacyNxPlugin(fn, executorOptions) {
33
+ if (global.NX_GRAPH_CREATION) {
34
+ return;
35
+ }
36
+ const options = (0, normalize_options_1.normalizeOptions)(executorOptions);
37
+ const projectGraph = (0, devkit_1.readCachedProjectGraph)();
38
+ const projectName = process.env.NX_TASK_TARGET_PROJECT;
39
+ const project = projectGraph.nodes[projectName];
40
+ const targetName = process.env.NX_TASK_TARGET_TARGET;
41
+ const context = {
42
+ cwd: process.cwd(),
43
+ isVerbose: process.env.NX_VERBOSE_LOGGING === 'true',
44
+ root: devkit_1.workspaceRoot,
45
+ projectGraph,
46
+ projectsConfigurations: (0, devkit_1.readProjectsConfigurationFromProjectGraph)(projectGraph),
47
+ nxJsonConfiguration: (0, configuration_1.readNxJson)(devkit_1.workspaceRoot),
48
+ target: project.data.targets[targetName],
49
+ targetName: targetName,
50
+ projectName: projectName,
51
+ };
52
+ const configuration = process.env.NX_TASK_TARGET_CONFIGURATION;
53
+ const ctx = {
54
+ context,
55
+ options: options,
56
+ configuration,
57
+ };
58
+ return {
59
+ apply(compiler) {
60
+ compiler.hooks.beforeCompile.tapPromise('NxLegacyAsyncPlugin', () => {
61
+ return new Promise((resolve) => {
62
+ fn(compiler.options, ctx).then((updated) => {
63
+ // Merge options back shallowly since it's a fully functional configuration.
64
+ // Most likely, the user modified the config in place, but this guarantees that updates are applied if users did something like:
65
+ // `return { ...config, plugins: [...config.plugins, new MyPlugin()] }`
66
+ Object.assign(compiler.options, updated);
67
+ resolve();
68
+ });
69
+ });
70
+ });
71
+ },
72
+ };
73
+ }
@@ -26,6 +26,7 @@ function applyBaseConfig(options, config = {}, { useNormalizedEntry, } = {}) {
26
26
  options.memoryLimit ??= 2048;
27
27
  options.transformers ??= [];
28
28
  options.progress ??= true;
29
+ options.outputHashing ??= 'all';
29
30
  applyNxIndependentConfig(options, config);
30
31
  // Some of the options only work during actual tasks, not when reading the rspack config during CreateNodes.
31
32
  if (global.NX_GRAPH_CREATION)
@@ -79,6 +80,7 @@ function applyNxIndependentConfig(options, config) {
79
80
  hashFunction: config.output?.hashFunction ?? 'xxhash64',
80
81
  // Disabled for performance
81
82
  pathinfo: config.output?.pathinfo ?? false,
83
+ clean: options.deleteOutputPath,
82
84
  };
83
85
  config.watch = options.watch;
84
86
  config.watchOptions = {
@@ -91,6 +93,7 @@ function applyNxIndependentConfig(options, config) {
91
93
  };
92
94
  config.ignoreWarnings = [
93
95
  (x) => IGNORED_RSPACK_WARNINGS.some((r) => typeof x === 'string' ? r.test(x) : r.test(x.message)),
96
+ ...(config.ignoreWarnings ?? []),
94
97
  ];
95
98
  config.optimization = !isProd
96
99
  ? undefined
@@ -1,5 +1,5 @@
1
- import { type Configuration } from '@rspack/core';
1
+ import { type Configuration, RspackOptionsNormalized } from '@rspack/core';
2
2
  import { NormalizedNxAppRspackPluginOptions } from './models';
3
- export declare function applyWebConfig(options: NormalizedNxAppRspackPluginOptions, config?: Configuration, { useNormalizedEntry, }?: {
3
+ export declare function applyWebConfig(options: NormalizedNxAppRspackPluginOptions, config?: Partial<RspackOptionsNormalized | Configuration>, { useNormalizedEntry, }?: {
4
4
  useNormalizedEntry?: boolean;
5
5
  }): void;
@@ -283,7 +283,7 @@ function applyWebConfig(options, config = {}, { useNormalizedEntry, } = {}) {
283
283
  }
284
284
  });
285
285
  config.optimization = !isProd
286
- ? undefined
286
+ ? {}
287
287
  : {
288
288
  ...(config.optimization ?? {}),
289
289
  minimizer: [...(config.optimization?.minimizer ?? []), ...minimizer],
@@ -81,7 +81,7 @@ function normalizeOptions(options) {
81
81
  sourceMap: combinedPluginAndMaybeExecutorOptions.sourceMap ?? !isProd,
82
82
  sourceRoot,
83
83
  styles: combinedPluginAndMaybeExecutorOptions.styles ?? [],
84
- target: combinedPluginAndMaybeExecutorOptions.target,
84
+ target: combinedPluginAndMaybeExecutorOptions.target ?? 'web',
85
85
  targetName,
86
86
  vendorChunk: combinedPluginAndMaybeExecutorOptions.vendorChunk ?? !isProd,
87
87
  };
@@ -16,7 +16,7 @@ class NxTsconfigPathsRspackPlugin {
16
16
  apply(compiler) {
17
17
  // TODO(Colum): Investigate the best way to handle this, currently it is not working and affecting HMR
18
18
  // // If we are not building libs from source, we need to remap paths so tsconfig may be updated.
19
- // this.handleBuildLibsFromSource(compiler.options, this.options);
19
+ this.handleBuildLibsFromSource(compiler.options, this.options);
20
20
  const pathToTsconfig = !path.isAbsolute(this.options.tsConfig)
21
21
  ? path.join(devkit_1.workspaceRoot, this.options.tsConfig)
22
22
  : this.options.tsConfig;
@@ -44,7 +44,8 @@ class NxTsconfigPathsRspackPlugin {
44
44
  if (!options.buildLibsFromSource && options.targetName) {
45
45
  const remappedTarget = options.targetName === 'serve' ? 'build' : options.targetName;
46
46
  const { target, dependencies } = (0, buildable_libs_utils_1.calculateProjectBuildableDependencies)(undefined, options.projectGraph, options.root, options.projectName, remappedTarget, options.configurationName);
47
- options.tsConfig = (0, buildable_libs_utils_1.createTmpTsConfig)(options.tsConfig, options.root, target.data.root, dependencies);
47
+ options.tsConfig = (0, buildable_libs_utils_1.createTmpTsConfig)(options.tsConfig, options.root, target.data.root, dependencies, true // There is an issue with Rspack that requires the baseUrl to be set in the generated tsconfig
48
+ );
48
49
  this.tmpTsConfigPath = options.tsConfig;
49
50
  if (options.targetName === 'serve') {
50
51
  const buildableDependencies = dependencies
@@ -6,7 +6,9 @@ const core_1 = require("@rspack/core");
6
6
  const config_1 = require("../executors/rspack/lib/config");
7
7
  async function createCompiler(options, context) {
8
8
  const config = await (0, config_1.getRspackConfigs)(options, context);
9
- validateConfig(config);
9
+ if (!options.standardRspackConfigFunction) {
10
+ validateConfig(config);
11
+ }
10
12
  return (0, core_1.rspack)(config);
11
13
  }
12
14
  function isMultiCompiler(compiler) {
@@ -1,6 +1,6 @@
1
1
  import { TargetConfiguration, Tree } from '@nx/devkit';
2
- import { ConfigurationSchema } from '../generators/configuration/schema';
3
- import { Framework } from '../generators/init/schema';
2
+ import { type ConfigurationSchema } from '../generators/configuration/schema';
3
+ import { type Framework } from '../generators/init/schema';
4
4
  export type Target = 'build' | 'serve';
5
5
  export type TargetFlags = Partial<Record<Target, boolean>>;
6
6
  export type UserProvidedTargetName = Partial<Record<Target, string>>;
@@ -15,6 +15,7 @@ exports.determineMain = determineMain;
15
15
  exports.determineTsConfig = determineTsConfig;
16
16
  const devkit_1 = require("@nx/devkit");
17
17
  const ensure_typescript_1 = require("@nx/js/src/utils/typescript/ensure-typescript");
18
+ const has_plugin_1 = require("./has-plugin");
18
19
  function findExistingTargetsInProject(targets, userProvidedTargets) {
19
20
  const output = {
20
21
  validFoundTargetName: {},
@@ -177,82 +178,148 @@ function addOrChangeServeTarget(tree, options, target) {
177
178
  }
178
179
  function writeRspackConfigFile(tree, options, stylePreprocessorOptions) {
179
180
  const project = (0, devkit_1.readProjectConfiguration)(tree, options.project);
180
- tree.write((0, devkit_1.joinPathFragments)(project.root, 'rspack.config.js'), createConfig(options, stylePreprocessorOptions));
181
+ tree.write((0, devkit_1.joinPathFragments)(project.root, 'rspack.config.js'), createConfig(tree, { ...options, stylePreprocessorOptions }));
181
182
  }
182
- function createConfig(options, stylePreprocessorOptions) {
183
- if (options.framework === 'react') {
184
- return `
185
- const { composePlugins, withNx, withReact } = require('@nx/rspack');
186
-
187
- module.exports = composePlugins(withNx(), withReact(${stylePreprocessorOptions
188
- ? `
189
- {
190
- stylePreprocessorOptions: ${JSON.stringify(stylePreprocessorOptions)},
191
- }
192
- `
193
- : ''}), (config) => {
194
- return config;
195
- });
196
- `;
183
+ function createConfig(tree, options) {
184
+ const project = (0, devkit_1.readProjectConfiguration)(tree, options.project);
185
+ const buildOptions = createBuildOptions(tree, options, project);
186
+ const defaultConfig = generateDefaultConfig(project, buildOptions);
187
+ if (isWebFramework(options)) {
188
+ return generateWebConfig(tree, options, defaultConfig);
197
189
  }
198
- else if (options.framework === 'web' || options.target === 'web') {
199
- return `
200
- const { composePlugins, withNx, withWeb } = require('@nx/rspack');
190
+ else if (options.framework === 'nest') {
191
+ return generateNestConfig(tree, options, project, buildOptions);
192
+ }
193
+ else {
194
+ return generateGenericConfig(tree, options, defaultConfig);
195
+ }
196
+ }
197
+ function createBuildOptions(tree, options, project) {
198
+ return {
199
+ target: options.target ?? 'web',
200
+ outputPath: (0, devkit_1.joinPathFragments)('dist', project.root === '.' ? project.name : project.root),
201
+ main: determineMain(tree, options),
202
+ tsConfig: determineTsConfig(tree, options),
203
+ rspackConfig: (0, devkit_1.joinPathFragments)(project.root, 'rspack.config.js'),
204
+ };
205
+ }
206
+ function generateDefaultConfig(project, buildOptions) {
207
+ return `
208
+ const { NxAppRspackPlugin } = require('@nx/rspack/app-plugin');
209
+ const { join } = require('path');
201
210
 
202
- module.exports = composePlugins(withNx(), withWeb(${stylePreprocessorOptions
203
- ? `
204
- {
205
- stylePreprocessorOptions: ${JSON.stringify(stylePreprocessorOptions)},
206
- }
207
- `
208
- : ''}), (config) => {
209
- return config;
210
- });
211
- `;
211
+ module.exports = {
212
+ output: {
213
+ path: join(__dirname, '${(0, devkit_1.offsetFromRoot)(project.root)}${buildOptions.outputPath}'),
214
+ },
215
+ plugins: [
216
+ new NxAppRspackPlugin({
217
+ target: '${buildOptions.target}',
218
+ tsConfig: '${buildOptions.tsConfig}',
219
+ main: '${buildOptions.main}',
220
+ outputHashing: '${buildOptions.target !== 'web' ? 'none' : 'all'}',
221
+ })
222
+ ]
223
+ }`;
224
+ }
225
+ function isWebFramework(options) {
226
+ return options.framework === 'web' || options.target === 'web';
227
+ }
228
+ function generateWebConfig(tree, options, defaultConfig) {
229
+ if ((0, has_plugin_1.hasPlugin)(tree)) {
230
+ return defaultConfig;
212
231
  }
213
- else if (options.framework === 'nest') {
232
+ return `
233
+ const { composePlugins, withNx, withWeb } = require('@nx/rspack');
234
+ module.exports = composePlugins(withNx(), withWeb(${options.stylePreprocessorOptions
235
+ ? `
236
+ {
237
+ stylePreprocessorOptions: ${JSON.stringify(options.stylePreprocessorOptions)},
238
+ }
239
+ `
240
+ : ''}), (config) => {
241
+ return config;
242
+ });
243
+ `;
244
+ }
245
+ function generateNestConfig(tree, options, project, buildOptions) {
246
+ if ((0, has_plugin_1.hasPlugin)(tree)) {
214
247
  return `
215
- const { composePlugins, withNx } = require('@nx/rspack');
216
- const rspack = require('@rspack/core');
248
+ const { NxAppRspackPlugin } = require('@nx/rspack/app-plugin');
249
+ const rspack = require('@rspack/core');
250
+ const { join } = require('path');
217
251
 
218
- module.exports = composePlugins(withNx(), (config) => {
219
- config.optimization = {
220
- minimizer: [
221
- new rspack.SwcJsMinimizerRspackPlugin({
222
- minimizerOptions: {
223
- // We need to disable mangling and compression for class names and function names for Nest.js to work properly
224
- // The execution context class returns a reference to the class/handler function, which is for example used for applying metadata using decorators
225
- // https://docs.nestjs.com/fundamentals/execution-context#executioncontext-class
226
- compress: {
227
- keep_classnames: true,
228
- keep_fnames: true,
229
- },
230
- mangle: {
231
- keep_classnames: true,
232
- keep_fnames: true,
233
- },
234
- },
235
- }),
236
- ],
237
- };
238
- return config;
239
- });
240
- `;
252
+ module.exports = {
253
+ output: {
254
+ path: join(__dirname, '${(0, devkit_1.offsetFromRoot)(project.root)}${buildOptions.outputPath}'),
255
+ },
256
+ optimization: {
257
+ minimizer: [
258
+ new rspack.SwcJsMinimizerRspackPlugin({
259
+ minimizerOptions: {
260
+ compress: {
261
+ keep_classnames: true,
262
+ keep_fnames: true,
263
+ },
264
+ mangle: {
265
+ keep_classnames: true,
266
+ keep_fnames: true,
267
+ },
268
+ },
269
+ }),
270
+ ],
271
+ },
272
+ plugins: [
273
+ new NxAppRspackPlugin({
274
+ target: '${buildOptions.target}',
275
+ tsConfig: '${buildOptions.tsConfig}',
276
+ main: '${buildOptions.main}',
277
+ outputHashing: '${buildOptions.target !== 'web' ? 'none' : 'all'}',
278
+ })
279
+ ]
280
+ }`;
241
281
  }
242
- else {
243
- return `
244
- const { composePlugins, withNx${stylePreprocessorOptions ? ', withWeb' : ''} } = require('@nx/rspack');
282
+ return `
283
+ const { composePlugins, withNx } = require('@nx/rspack');
284
+ const rspack = require('@rspack/core');
245
285
 
246
- module.exports = composePlugins(withNx()${stylePreprocessorOptions
247
- ? `,
248
- withWeb({
249
- stylePreprocessorOptions: ${JSON.stringify(stylePreprocessorOptions)},
250
- })`
251
- : ''}, (config) => {
252
- return config;
253
- });
254
- `;
286
+ module.exports = composePlugins(withNx(), (config) => {
287
+ config.optimization = {
288
+ minimizer: [
289
+ new rspack.SwcJsMinimizerRspackPlugin({
290
+ minimizerOptions: {
291
+ compress: {
292
+ keep_classnames: true,
293
+ keep_fnames: true,
294
+ },
295
+ mangle: {
296
+ keep_classnames: true,
297
+ keep_fnames: true,
298
+ },
299
+ },
300
+ }),
301
+ ],
302
+ };
303
+ return config;
304
+ });
305
+ `;
306
+ }
307
+ function generateGenericConfig(tree, options, defaultConfig) {
308
+ if ((0, has_plugin_1.hasPlugin)(tree)) {
309
+ return defaultConfig;
255
310
  }
311
+ return `
312
+ const { composePlugins, withNx${options.stylePreprocessorOptions ? ', withWeb' : ''} } = require('@nx/rspack');
313
+
314
+ module.exports = composePlugins(withNx()${options.stylePreprocessorOptions
315
+ ? `,
316
+ withWeb({
317
+ stylePreprocessorOptions: ${JSON.stringify(options.stylePreprocessorOptions)},
318
+ })`
319
+ : ''}, (config) => {
320
+ return config;
321
+ });
322
+ `;
256
323
  }
257
324
  function deleteWebpackConfig(tree, projectRoot, webpackConfigFilePath) {
258
325
  const webpackConfigPath = webpackConfigFilePath && tree.exists(webpackConfigFilePath)
@@ -0,0 +1,2 @@
1
+ import { Tree } from '@nx/devkit';
2
+ export declare function hasPlugin(tree: Tree): boolean;
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.hasPlugin = hasPlugin;
4
+ const devkit_1 = require("@nx/devkit");
5
+ function hasPlugin(tree) {
6
+ const nxJson = (0, devkit_1.readNxJson)(tree);
7
+ return !!nxJson.plugins?.some((p) => typeof p === 'string'
8
+ ? p === '@nx/rspack/plugin'
9
+ : p.plugin === '@nx/rspack/plugin');
10
+ }
@@ -1,4 +1,4 @@
1
1
  import { ExecutorContext } from '@nx/devkit';
2
2
  import { ModuleFederationDevServerOptions } from '../../executors/module-federation-dev-server/schema';
3
- import type { StaticRemotesConfig } from './parse-static-remotes-config';
3
+ import type { StaticRemotesConfig } from '@nx/module-federation/src/utils';
4
4
  export declare function buildStaticRemotes(staticRemotesConfig: StaticRemotesConfig, nxBin: any, context: ExecutorContext, options: ModuleFederationDevServerOptions): Promise<Record<string, string>>;
@@ -1,6 +1,6 @@
1
1
  export declare const nxVersion: any;
2
- export declare const rspackCoreVersion = "1.0.5";
3
- export declare const rspackDevServerVersion = "1.0.5";
2
+ export declare const rspackCoreVersion = "1.1.2";
3
+ export declare const rspackDevServerVersion = "1.0.9";
4
4
  export declare const rspackPluginMinifyVersion = "^0.7.5";
5
5
  export declare const rspackPluginReactRefreshVersion = "^1.0.0";
6
6
  export declare const lessLoaderVersion = "~11.1.3";
@@ -2,8 +2,8 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.eslintPluginReactHooksVersion = exports.eslintPluginReactVersion = exports.eslintPluginJsxA11yVersion = exports.eslintPluginImportVersion = exports.stylusVersion = exports.sassVersion = exports.lessVersion = exports.nestjsMicroservicesVersion = exports.nestjsPlatformExpressVersion = exports.nestjsCoreVersion = exports.nestjsCommonVersion = exports.typesReactDomVersion = exports.typesReactVersion = exports.reactDomVersion = exports.reactRefreshVersion = exports.reactVersion = exports.lessLoaderVersion = exports.rspackPluginReactRefreshVersion = exports.rspackPluginMinifyVersion = exports.rspackDevServerVersion = exports.rspackCoreVersion = exports.nxVersion = void 0;
4
4
  exports.nxVersion = require('../../package.json').version;
5
- exports.rspackCoreVersion = '1.0.5';
6
- exports.rspackDevServerVersion = '1.0.5';
5
+ exports.rspackCoreVersion = '1.1.2';
6
+ exports.rspackDevServerVersion = '1.0.9';
7
7
  exports.rspackPluginMinifyVersion = '^0.7.5';
8
8
  exports.rspackPluginReactRefreshVersion = '^1.0.0';
9
9
  exports.lessLoaderVersion = '~11.1.3';
@@ -1,6 +0,0 @@
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
- };
@@ -1,56 +0,0 @@
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
- }
@@ -1,16 +0,0 @@
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 {};