@module-federation/metro 0.0.0-perf-devtools-20260107043700 → 0.0.0-perf-website-code-usage-20260914033703

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 (100) hide show
  1. package/babel-plugin/patch-initialize-core.js +3 -3
  2. package/babel-plugin/patch-require.js +3 -3
  3. package/dist/babel/transformer.js +1 -1
  4. package/dist/commands/bundle-host/index.js +17 -12
  5. package/dist/commands/bundle-host/index.mjs +8 -30
  6. package/dist/commands/bundle-host/options.js +12 -8
  7. package/dist/commands/bundle-host/options.mjs +2 -3
  8. package/dist/commands/bundle-host/types.js +2 -2
  9. package/dist/commands/bundle-host/types.mjs +1 -2
  10. package/dist/commands/bundle-remote/index.js +34 -19
  11. package/dist/commands/bundle-remote/index.mjs +28 -38
  12. package/dist/commands/bundle-remote/options.js +15 -11
  13. package/dist/commands/bundle-remote/options.mjs +4 -5
  14. package/dist/commands/bundle-remote/types.js +2 -2
  15. package/dist/commands/bundle-remote/types.mjs +1 -2
  16. package/dist/commands/index.js +14 -10
  17. package/dist/commands/index.mjs +3 -3
  18. package/dist/commands/types.js +2 -2
  19. package/dist/commands/types.mjs +1 -2
  20. package/dist/commands/utils/create-module-path-remapper.js +15 -11
  21. package/dist/commands/utils/create-module-path-remapper.mjs +1 -2
  22. package/dist/commands/utils/create-resolver.d.ts +1 -1
  23. package/dist/commands/utils/create-resolver.js +15 -11
  24. package/dist/commands/utils/create-resolver.mjs +1 -2
  25. package/dist/commands/utils/get-community-plugin.d.ts +1 -2
  26. package/dist/commands/utils/get-community-plugin.js +15 -12
  27. package/dist/commands/utils/get-community-plugin.mjs +5 -6
  28. package/dist/commands/utils/load-metro-config.js +15 -14
  29. package/dist/commands/utils/load-metro-config.mjs +9 -11
  30. package/dist/commands/utils/path-utils.d.ts +2 -0
  31. package/dist/commands/utils/path-utils.js +51 -0
  32. package/dist/commands/utils/path-utils.mjs +11 -0
  33. package/dist/commands/utils/save-bundle-and-map.d.ts +1 -1
  34. package/dist/commands/utils/save-bundle-and-map.js +14 -11
  35. package/dist/commands/utils/save-bundle-and-map.mjs +3 -27
  36. package/dist/index.js +14 -10
  37. package/dist/index.mjs +3 -5
  38. package/dist/logger.d.ts +2 -0
  39. package/dist/logger.js +43 -0
  40. package/dist/logger.mjs +6 -0
  41. package/dist/modules/asyncRequire.ts +41 -10
  42. package/dist/modules/metroCorePlugin.ts +2 -3
  43. package/dist/plugin/babel-transformer.js +13 -9
  44. package/dist/plugin/babel-transformer.mjs +3 -3
  45. package/dist/plugin/constants.d.ts +1 -0
  46. package/dist/plugin/constants.js +27 -19
  47. package/dist/plugin/constants.mjs +3 -3
  48. package/dist/plugin/generators.js +28 -21
  49. package/dist/plugin/generators.mjs +14 -11
  50. package/dist/plugin/helpers.d.ts +1 -0
  51. package/dist/plugin/helpers.js +28 -20
  52. package/dist/plugin/helpers.mjs +9 -9
  53. package/dist/plugin/index.d.ts +2 -0
  54. package/dist/plugin/index.js +64 -13
  55. package/dist/plugin/index.mjs +54 -7
  56. package/dist/plugin/manifest-middleware.d.ts +12 -0
  57. package/dist/plugin/manifest-middleware.js +217 -0
  58. package/dist/plugin/manifest-middleware.mjs +170 -0
  59. package/dist/plugin/manifest.d.ts +15 -2
  60. package/dist/plugin/manifest.js +126 -26
  61. package/dist/plugin/manifest.mjs +107 -22
  62. package/dist/plugin/normalize-extra-options.js +16 -12
  63. package/dist/plugin/normalize-extra-options.mjs +2 -3
  64. package/dist/plugin/normalize-options.js +70 -20
  65. package/dist/plugin/normalize-options.mjs +60 -14
  66. package/dist/plugin/resolver.d.ts +1 -1
  67. package/dist/plugin/resolver.js +16 -12
  68. package/dist/plugin/resolver.mjs +10 -11
  69. package/dist/plugin/rewrite-request.d.ts +5 -1
  70. package/dist/plugin/rewrite-request.js +23 -10
  71. package/dist/plugin/rewrite-request.mjs +13 -5
  72. package/dist/plugin/serializer.d.ts +2 -1
  73. package/dist/plugin/serializer.js +59 -39
  74. package/dist/plugin/serializer.mjs +48 -55
  75. package/dist/plugin/validate-options.js +116 -12
  76. package/dist/plugin/validate-options.mjs +95 -7
  77. package/dist/types.d.ts +15 -15
  78. package/dist/types.js +2 -2
  79. package/dist/types.mjs +1 -2
  80. package/dist/utils/errors.js +16 -12
  81. package/dist/utils/errors.mjs +1 -2
  82. package/dist/utils/federated-remote-types.d.ts +12 -0
  83. package/dist/utils/federated-remote-types.js +140 -0
  84. package/dist/utils/federated-remote-types.mjs +90 -0
  85. package/dist/utils/index.js +14 -10
  86. package/dist/utils/index.mjs +3 -5
  87. package/dist/utils/metro-compat.d.ts +23 -0
  88. package/dist/utils/metro-compat.js +74 -0
  89. package/dist/utils/metro-compat.mjs +26 -0
  90. package/dist/utils/vm-manager.d.ts +1 -1
  91. package/dist/utils/vm-manager.js +14 -12
  92. package/dist/utils/vm-manager.mjs +3 -6
  93. package/package.json +22 -7
  94. package/dist/babel/transformer.d.ts +0 -2
  95. package/dist/runtime/host-entry.d.ts +0 -1
  96. package/dist/runtime/init-host.d.ts +0 -1
  97. package/dist/runtime/remote-entry.d.ts +0 -1
  98. package/dist/runtime/remote-hmr.d.ts +0 -1
  99. package/dist/runtime/remote-module-registry.d.ts +0 -7
  100. package/dist/runtime/remote-module.d.ts +0 -1
@@ -10,11 +10,15 @@ var __webpack_require__ = {};
10
10
  };
11
11
  })();
12
12
  (()=>{
13
- __webpack_require__.d = (exports1, definition)=>{
14
- for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
15
- enumerable: true,
16
- get: definition[key]
17
- });
13
+ __webpack_require__.d = (exports1, getters, values)=>{
14
+ var define = (defs, kind)=>{
15
+ for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
16
+ enumerable: true,
17
+ [kind]: defs[key]
18
+ });
19
+ };
20
+ define(getters, "get");
21
+ define(values, "value");
18
22
  };
19
23
  })();
20
24
  (()=>{
@@ -22,7 +26,7 @@ var __webpack_require__ = {};
22
26
  })();
23
27
  (()=>{
24
28
  __webpack_require__.r = (exports1)=>{
25
- if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
29
+ if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
26
30
  value: 'Module'
27
31
  });
28
32
  Object.defineProperty(exports1, '__esModule', {
@@ -33,13 +37,14 @@ var __webpack_require__ = {};
33
37
  var __webpack_exports__ = {};
34
38
  __webpack_require__.r(__webpack_exports__);
35
39
  __webpack_require__.d(__webpack_exports__, {
36
- stubHostEntry: ()=>stubHostEntry,
37
- stubRemoteEntry: ()=>stubRemoteEntry,
38
- isUsingMFCommand: ()=>isUsingMFCommand,
39
40
  isUsingMFBundleCommand: ()=>isUsingMFBundleCommand,
40
- removeExtension: ()=>removeExtension,
41
+ isUsingMFCommand: ()=>isUsingMFCommand,
41
42
  prepareTmpDir: ()=>prepareTmpDir,
42
- replaceExtension: ()=>replaceExtension
43
+ removeExtension: ()=>removeExtension,
44
+ replaceExtension: ()=>replaceExtension,
45
+ stubHostEntry: ()=>stubHostEntry,
46
+ stubRemoteEntry: ()=>stubRemoteEntry,
47
+ toPosixPath: ()=>toPosixPath
43
48
  });
44
49
  const external_node_fs_namespaceObject = require("node:fs");
45
50
  var external_node_fs_default = /*#__PURE__*/ __webpack_require__.n(external_node_fs_namespaceObject);
@@ -62,12 +67,10 @@ function isUsingMFBundleCommand(command = process.argv[2]) {
62
67
  return allowedCommands.includes(command);
63
68
  }
64
69
  function replaceExtension(filepath, extension) {
65
- const { dir, name } = external_node_path_default().parse(filepath);
66
- return external_node_path_default().format({
67
- dir,
68
- name,
69
- ext: extension
70
- });
70
+ const separatorIndex = Math.max(filepath.lastIndexOf('/'), filepath.lastIndexOf('\\'));
71
+ const dotIndex = filepath.lastIndexOf('.');
72
+ const extensionStart = dotIndex > separatorIndex + 1 ? dotIndex : filepath.length;
73
+ return `${filepath.slice(0, extensionStart)}${extension}`;
71
74
  }
72
75
  function removeExtension(filepath) {
73
76
  return replaceExtension(filepath, '');
@@ -98,6 +101,9 @@ function prepareTmpDir(projectRootPath) {
98
101
  });
99
102
  return tmpDirPath;
100
103
  }
104
+ function toPosixPath(value) {
105
+ return value.replaceAll('\\', '/');
106
+ }
101
107
  exports.isUsingMFBundleCommand = __webpack_exports__.isUsingMFBundleCommand;
102
108
  exports.isUsingMFCommand = __webpack_exports__.isUsingMFCommand;
103
109
  exports.prepareTmpDir = __webpack_exports__.prepareTmpDir;
@@ -105,15 +111,17 @@ exports.removeExtension = __webpack_exports__.removeExtension;
105
111
  exports.replaceExtension = __webpack_exports__.replaceExtension;
106
112
  exports.stubHostEntry = __webpack_exports__.stubHostEntry;
107
113
  exports.stubRemoteEntry = __webpack_exports__.stubRemoteEntry;
108
- for(var __webpack_i__ in __webpack_exports__)if (-1 === [
114
+ exports.toPosixPath = __webpack_exports__.toPosixPath;
115
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
109
116
  "isUsingMFBundleCommand",
110
117
  "isUsingMFCommand",
111
118
  "prepareTmpDir",
112
119
  "removeExtension",
113
120
  "replaceExtension",
114
121
  "stubHostEntry",
115
- "stubRemoteEntry"
116
- ].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
122
+ "stubRemoteEntry",
123
+ "toPosixPath"
124
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
117
125
  Object.defineProperty(exports, '__esModule', {
118
126
  value: true
119
127
  });
@@ -1,5 +1,4 @@
1
- import 'module';
2
- /*#__PURE__*/ import.meta.url;
1
+ import "node:module";
3
2
  import node_fs from "node:fs";
4
3
  import node_path from "node:path";
5
4
  import { TMP_DIR_NAME } from "./constants.mjs";
@@ -19,12 +18,10 @@ function isUsingMFBundleCommand(command = process.argv[2]) {
19
18
  return allowedCommands.includes(command);
20
19
  }
21
20
  function replaceExtension(filepath, extension) {
22
- const { dir, name } = node_path.parse(filepath);
23
- return node_path.format({
24
- dir,
25
- name,
26
- ext: extension
27
- });
21
+ const separatorIndex = Math.max(filepath.lastIndexOf('/'), filepath.lastIndexOf('\\'));
22
+ const dotIndex = filepath.lastIndexOf('.');
23
+ const extensionStart = dotIndex > separatorIndex + 1 ? dotIndex : filepath.length;
24
+ return `${filepath.slice(0, extensionStart)}${extension}`;
28
25
  }
29
26
  function removeExtension(filepath) {
30
27
  return replaceExtension(filepath, '');
@@ -55,4 +52,7 @@ function prepareTmpDir(projectRootPath) {
55
52
  });
56
53
  return tmpDirPath;
57
54
  }
58
- export { isUsingMFBundleCommand, isUsingMFCommand, prepareTmpDir, removeExtension, replaceExtension, stubHostEntry, stubRemoteEntry };
55
+ function toPosixPath(value) {
56
+ return value.replaceAll('\\', '/');
57
+ }
58
+ export { isUsingMFBundleCommand, isUsingMFCommand, prepareTmpDir, removeExtension, replaceExtension, stubHostEntry, stubRemoteEntry, toPosixPath };
@@ -1,9 +1,11 @@
1
1
  import type { ConfigT } from 'metro-config';
2
2
  import type { ModuleFederationConfig, ModuleFederationConfigNormalized, ModuleFederationExtraOptions } from '../types';
3
+ import type { FederatedTypesMeta } from '../utils/federated-remote-types';
3
4
  declare global {
4
5
  var __METRO_FEDERATION_CONFIG: ModuleFederationConfigNormalized;
5
6
  var __METRO_FEDERATION_ORIGINAL_ENTRY_PATH: string | undefined;
6
7
  var __METRO_FEDERATION_REMOTE_ENTRY_PATH: string | undefined;
7
8
  var __METRO_FEDERATION_MANIFEST_PATH: string | undefined;
9
+ var __METRO_FEDERATION_DTS_ASSETS: FederatedTypesMeta | undefined;
8
10
  }
9
11
  export declare function withModuleFederation(config: ConfigT, federationOptions: ModuleFederationConfig, extraOptions?: ModuleFederationExtraOptions): ConfigT;
@@ -10,11 +10,15 @@ var __webpack_require__ = {};
10
10
  };
11
11
  })();
12
12
  (()=>{
13
- __webpack_require__.d = (exports1, definition)=>{
14
- for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
15
- enumerable: true,
16
- get: definition[key]
17
- });
13
+ __webpack_require__.d = (exports1, getters, values)=>{
14
+ var define = (defs, kind)=>{
15
+ for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
16
+ enumerable: true,
17
+ [kind]: defs[key]
18
+ });
19
+ };
20
+ define(getters, "get");
21
+ define(values, "value");
18
22
  };
19
23
  })();
20
24
  (()=>{
@@ -22,7 +26,7 @@ var __webpack_require__ = {};
22
26
  })();
23
27
  (()=>{
24
28
  __webpack_require__.r = (exports1)=>{
25
- if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
29
+ if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
26
30
  value: 'Module'
27
31
  });
28
32
  Object.defineProperty(exports1, '__esModule', {
@@ -37,12 +41,15 @@ __webpack_require__.d(__webpack_exports__, {
37
41
  });
38
42
  const external_node_path_namespaceObject = require("node:path");
39
43
  var external_node_path_default = /*#__PURE__*/ __webpack_require__.n(external_node_path_namespaceObject);
44
+ const external_node_fs_namespaceObject = require("node:fs");
40
45
  const external_node_util_namespaceObject = require("node:util");
41
46
  var external_node_util_default = /*#__PURE__*/ __webpack_require__.n(external_node_util_namespaceObject);
42
47
  const index_js_namespaceObject = require("../utils/index.js");
48
+ const federated_remote_types_js_namespaceObject = require("../utils/federated-remote-types.js");
43
49
  const external_babel_transformer_js_namespaceObject = require("./babel-transformer.js");
44
50
  const external_helpers_js_namespaceObject = require("./helpers.js");
45
51
  const external_manifest_js_namespaceObject = require("./manifest.js");
52
+ const external_manifest_middleware_js_namespaceObject = require("./manifest-middleware.js");
46
53
  const external_normalize_extra_options_js_namespaceObject = require("./normalize-extra-options.js");
47
54
  const external_normalize_options_js_namespaceObject = require("./normalize-options.js");
48
55
  const external_resolver_js_namespaceObject = require("./resolver.js");
@@ -51,7 +58,7 @@ const external_serializer_js_namespaceObject = require("./serializer.js");
51
58
  const external_validate_options_js_namespaceObject = require("./validate-options.js");
52
59
  function withModuleFederation(config, federationOptions, extraOptions) {
53
60
  if ((0, external_helpers_js_namespaceObject.isUsingMFCommand)()) return augmentConfig(config, federationOptions, extraOptions);
54
- console.warn(external_node_util_default().styleText('yellow', 'Warning: Module Federation build is disabled for this command.\n') + external_node_util_default().styleText('yellow', 'To enable Module Federation, please use one of the dedicated bundle commands:\n') + ` ${external_node_util_default().styleText('dim', "\u2022")} bundle-mf-host` + external_node_util_default().styleText('dim', ' - for bundling a host application\n') + ` ${external_node_util_default().styleText('dim', "\u2022")} bundle-mf-remote` + external_node_util_default().styleText('dim', ' - for bundling a remote application\n'));
61
+ console.warn(external_node_util_default().styleText('yellow', 'Warning: Module Federation build is disabled for this command.\n') + external_node_util_default().styleText('yellow', 'To enable Module Federation, please use one of the dedicated bundle commands:\n') + ` ${external_node_util_default().styleText('dim', '•')} bundle-mf-host` + external_node_util_default().styleText('dim', ' - for bundling a host application\n') + ` ${external_node_util_default().styleText('dim', '•')} bundle-mf-remote` + external_node_util_default().styleText('dim', ' - for bundling a remote application\n'));
55
62
  return config;
56
63
  }
57
64
  function augmentConfig(config, federationOptions, extraOptions) {
@@ -85,18 +92,31 @@ function augmentConfig(config, federationOptions, extraOptions) {
85
92
  enableInitializeCorePatching: flags.unstable_patchInitializeCore,
86
93
  enableRuntimeRequirePatching: flags.unstable_patchRuntimeRequire
87
94
  });
88
- const manifestPath = (0, external_manifest_js_namespaceObject.createManifest)(options, tmpDirPath);
95
+ const manifestOptions = {
96
+ projectRoot: config.projectRoot,
97
+ target: (0, external_helpers_js_namespaceObject.isUsingMFBundleCommand)() ? 'build' : 'development',
98
+ tmpDirPath
99
+ };
100
+ const manifestPath = (0, external_manifest_js_namespaceObject.createManifest)(options, tmpDirPath, manifestOptions);
89
101
  (0, external_helpers_js_namespaceObject.stubHostEntry)(hostEntryPath);
90
102
  (0, external_helpers_js_namespaceObject.stubRemoteEntry)(remoteEntryPath);
91
103
  global.__METRO_FEDERATION_CONFIG = options;
92
104
  global.__METRO_FEDERATION_HOST_ENTRY_PATH = hostEntryPath;
93
105
  global.__METRO_FEDERATION_REMOTE_ENTRY_PATH = remoteEntryPath;
94
106
  global.__METRO_FEDERATION_MANIFEST_PATH = manifestPath;
107
+ global.__METRO_FEDERATION_DTS_ASSETS = void 0;
108
+ maybeGenerateRemoteTypesForStart({
109
+ isRemote,
110
+ options,
111
+ projectRoot: config.projectRoot,
112
+ tmpDirPath,
113
+ manifestPath
114
+ });
95
115
  return {
96
116
  ...config,
97
117
  serializer: {
98
118
  ...config.serializer,
99
- customSerializer: (0, external_serializer_js_namespaceObject.getModuleFederationSerializer)(options, (0, external_helpers_js_namespaceObject.isUsingMFBundleCommand)()),
119
+ customSerializer: (0, external_serializer_js_namespaceObject.getModuleFederationSerializer)(options, (0, external_helpers_js_namespaceObject.isUsingMFBundleCommand)(), manifestPath, manifestOptions),
100
120
  getModulesRunBeforeMainModule: (entryFilePath)=>{
101
121
  if (flags.unstable_patchInitializeCore) return config.serializer.getModulesRunBeforeMainModule(entryFilePath);
102
122
  if (isRemote) return [];
@@ -140,17 +160,48 @@ function augmentConfig(config, federationOptions, extraOptions) {
140
160
  },
141
161
  server: {
142
162
  ...config.server,
143
- enhanceMiddleware: vmManager.getMiddleware(),
163
+ enhanceMiddleware: (middleware, metroServer)=>{
164
+ const manifestMiddleware = (0, external_manifest_middleware_js_namespaceObject.createManifestMiddleware)({
165
+ federationConfig: options,
166
+ projectRoot: config.projectRoot,
167
+ remoteEntryPath,
168
+ tmpDirPath,
169
+ vmManager
170
+ })(middleware, metroServer);
171
+ return vmManager.getMiddleware()(manifestMiddleware, metroServer);
172
+ },
144
173
  rewriteRequestUrl: (0, external_rewrite_request_js_namespaceObject.createRewriteRequest)({
145
174
  config,
146
175
  originalEntryFilename,
147
176
  remoteEntryFilename,
148
177
  manifestPath,
149
- tmpDirPath
178
+ tmpDirPath,
179
+ getDtsAssetNames: ()=>global.__METRO_FEDERATION_DTS_ASSETS
150
180
  })
151
181
  }
152
182
  };
153
183
  }
184
+ function maybeGenerateRemoteTypesForStart(opts) {
185
+ if ('start' !== process.argv[2]) return;
186
+ if (!opts.isRemote || false === opts.options.dts) return;
187
+ (async ()=>{
188
+ try {
189
+ const typesMeta = await (0, federated_remote_types_js_namespaceObject.maybeGenerateFederatedRemoteTypes)({
190
+ federationConfig: opts.options,
191
+ projectRoot: opts.projectRoot,
192
+ outputDir: opts.tmpDirPath,
193
+ logger: console
194
+ });
195
+ if (!typesMeta) return;
196
+ global.__METRO_FEDERATION_DTS_ASSETS = typesMeta;
197
+ const manifest = JSON.parse(await external_node_fs_namespaceObject.promises.readFile(opts.manifestPath, 'utf-8'));
198
+ (0, federated_remote_types_js_namespaceObject.applyTypesMetaToManifest)(manifest, typesMeta);
199
+ await external_node_fs_namespaceObject.promises.writeFile(opts.manifestPath, JSON.stringify(manifest, void 0, 2), 'utf-8');
200
+ } catch (error) {
201
+ console.warn(`${external_node_util_default().styleText('yellow', 'Failed to generate federated types for dev server:')}\n${String(error)}`);
202
+ }
203
+ })();
204
+ }
154
205
  function getOriginalEntry(projectRoot, entryFilename) {
155
206
  const originalEntryFilename = external_node_path_default().basename(global.__METRO_FEDERATION_ORIGINAL_ENTRY_PATH ?? entryFilename);
156
207
  const originalEntryPath = external_node_path_default().resolve(projectRoot, global.__METRO_FEDERATION_ORIGINAL_ENTRY_PATH ?? entryFilename);
@@ -160,9 +211,9 @@ function getOriginalEntry(projectRoot, entryFilename) {
160
211
  };
161
212
  }
162
213
  exports.withModuleFederation = __webpack_exports__.withModuleFederation;
163
- for(var __webpack_i__ in __webpack_exports__)if (-1 === [
214
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
164
215
  "withModuleFederation"
165
- ].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
216
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
166
217
  Object.defineProperty(exports, '__esModule', {
167
218
  value: true
168
219
  });
@@ -1,11 +1,14 @@
1
- import __rslib_shim_module__ from 'module';
2
- const require = /*#__PURE__*/ __rslib_shim_module__.createRequire(import.meta.url);
1
+ import __rslib_shim_module__ from "node:module";
2
+ const require = /*#__PURE__*/ __rslib_shim_module__.createRequire(/*#__PURE__*/ (()=>import.meta.url)());
3
3
  import node_path from "node:path";
4
+ import { promises } from "node:fs";
4
5
  import node_util from "node:util";
5
6
  import { VirtualModuleManager } from "../utils/index.mjs";
7
+ import { applyTypesMetaToManifest, maybeGenerateFederatedRemoteTypes } from "../utils/federated-remote-types.mjs";
6
8
  import { createBabelTransformer } from "./babel-transformer.mjs";
7
9
  import { isUsingMFBundleCommand, isUsingMFCommand, prepareTmpDir, replaceExtension, stubHostEntry, stubRemoteEntry } from "./helpers.mjs";
8
10
  import { createManifest } from "./manifest.mjs";
11
+ import { createManifestMiddleware } from "./manifest-middleware.mjs";
9
12
  import { normalizeExtraOptions } from "./normalize-extra-options.mjs";
10
13
  import { normalizeOptions } from "./normalize-options.mjs";
11
14
  import { createResolveRequest } from "./resolver.mjs";
@@ -14,7 +17,7 @@ import { getModuleFederationSerializer } from "./serializer.mjs";
14
17
  import { validateOptions } from "./validate-options.mjs";
15
18
  function withModuleFederation(config, federationOptions, extraOptions) {
16
19
  if (isUsingMFCommand()) return augmentConfig(config, federationOptions, extraOptions);
17
- console.warn(node_util.styleText('yellow', 'Warning: Module Federation build is disabled for this command.\n') + node_util.styleText('yellow', 'To enable Module Federation, please use one of the dedicated bundle commands:\n') + ` ${node_util.styleText('dim', "\u2022")} bundle-mf-host` + node_util.styleText('dim', ' - for bundling a host application\n') + ` ${node_util.styleText('dim', "\u2022")} bundle-mf-remote` + node_util.styleText('dim', ' - for bundling a remote application\n'));
20
+ console.warn(node_util.styleText('yellow', 'Warning: Module Federation build is disabled for this command.\n') + node_util.styleText('yellow', 'To enable Module Federation, please use one of the dedicated bundle commands:\n') + ` ${node_util.styleText('dim', '•')} bundle-mf-host` + node_util.styleText('dim', ' - for bundling a host application\n') + ` ${node_util.styleText('dim', '•')} bundle-mf-remote` + node_util.styleText('dim', ' - for bundling a remote application\n'));
18
21
  return config;
19
22
  }
20
23
  function augmentConfig(config, federationOptions, extraOptions) {
@@ -48,18 +51,31 @@ function augmentConfig(config, federationOptions, extraOptions) {
48
51
  enableInitializeCorePatching: flags.unstable_patchInitializeCore,
49
52
  enableRuntimeRequirePatching: flags.unstable_patchRuntimeRequire
50
53
  });
51
- const manifestPath = createManifest(options, tmpDirPath);
54
+ const manifestOptions = {
55
+ projectRoot: config.projectRoot,
56
+ target: isUsingMFBundleCommand() ? 'build' : 'development',
57
+ tmpDirPath
58
+ };
59
+ const manifestPath = createManifest(options, tmpDirPath, manifestOptions);
52
60
  stubHostEntry(hostEntryPath);
53
61
  stubRemoteEntry(remoteEntryPath);
54
62
  global.__METRO_FEDERATION_CONFIG = options;
55
63
  global.__METRO_FEDERATION_HOST_ENTRY_PATH = hostEntryPath;
56
64
  global.__METRO_FEDERATION_REMOTE_ENTRY_PATH = remoteEntryPath;
57
65
  global.__METRO_FEDERATION_MANIFEST_PATH = manifestPath;
66
+ global.__METRO_FEDERATION_DTS_ASSETS = void 0;
67
+ maybeGenerateRemoteTypesForStart({
68
+ isRemote,
69
+ options,
70
+ projectRoot: config.projectRoot,
71
+ tmpDirPath,
72
+ manifestPath
73
+ });
58
74
  return {
59
75
  ...config,
60
76
  serializer: {
61
77
  ...config.serializer,
62
- customSerializer: getModuleFederationSerializer(options, isUsingMFBundleCommand()),
78
+ customSerializer: getModuleFederationSerializer(options, isUsingMFBundleCommand(), manifestPath, manifestOptions),
63
79
  getModulesRunBeforeMainModule: (entryFilePath)=>{
64
80
  if (flags.unstable_patchInitializeCore) return config.serializer.getModulesRunBeforeMainModule(entryFilePath);
65
81
  if (isRemote) return [];
@@ -103,17 +119,48 @@ function augmentConfig(config, federationOptions, extraOptions) {
103
119
  },
104
120
  server: {
105
121
  ...config.server,
106
- enhanceMiddleware: vmManager.getMiddleware(),
122
+ enhanceMiddleware: (middleware, metroServer)=>{
123
+ const manifestMiddleware = createManifestMiddleware({
124
+ federationConfig: options,
125
+ projectRoot: config.projectRoot,
126
+ remoteEntryPath,
127
+ tmpDirPath,
128
+ vmManager
129
+ })(middleware, metroServer);
130
+ return vmManager.getMiddleware()(manifestMiddleware, metroServer);
131
+ },
107
132
  rewriteRequestUrl: createRewriteRequest({
108
133
  config,
109
134
  originalEntryFilename,
110
135
  remoteEntryFilename,
111
136
  manifestPath,
112
- tmpDirPath
137
+ tmpDirPath,
138
+ getDtsAssetNames: ()=>global.__METRO_FEDERATION_DTS_ASSETS
113
139
  })
114
140
  }
115
141
  };
116
142
  }
143
+ function maybeGenerateRemoteTypesForStart(opts) {
144
+ if ('start' !== process.argv[2]) return;
145
+ if (!opts.isRemote || false === opts.options.dts) return;
146
+ (async ()=>{
147
+ try {
148
+ const typesMeta = await maybeGenerateFederatedRemoteTypes({
149
+ federationConfig: opts.options,
150
+ projectRoot: opts.projectRoot,
151
+ outputDir: opts.tmpDirPath,
152
+ logger: console
153
+ });
154
+ if (!typesMeta) return;
155
+ global.__METRO_FEDERATION_DTS_ASSETS = typesMeta;
156
+ const manifest = JSON.parse(await promises.readFile(opts.manifestPath, 'utf-8'));
157
+ applyTypesMetaToManifest(manifest, typesMeta);
158
+ await promises.writeFile(opts.manifestPath, JSON.stringify(manifest, void 0, 2), 'utf-8');
159
+ } catch (error) {
160
+ console.warn(`${node_util.styleText('yellow', 'Failed to generate federated types for dev server:')}\n${String(error)}`);
161
+ }
162
+ })();
163
+ }
117
164
  function getOriginalEntry(projectRoot, entryFilename) {
118
165
  const originalEntryFilename = node_path.basename(global.__METRO_FEDERATION_ORIGINAL_ENTRY_PATH ?? entryFilename);
119
166
  const originalEntryPath = node_path.resolve(projectRoot, global.__METRO_FEDERATION_ORIGINAL_ENTRY_PATH ?? entryFilename);
@@ -0,0 +1,12 @@
1
+ import type { ServerConfigT } from 'metro-config';
2
+ import type { ModuleFederationConfigNormalized } from '../types';
3
+ import type { VirtualModuleManager } from '../utils';
4
+ type ManifestMiddlewareOptions = {
5
+ federationConfig: ModuleFederationConfigNormalized;
6
+ projectRoot: string;
7
+ remoteEntryPath: string;
8
+ tmpDirPath: string;
9
+ vmManager: Pick<VirtualModuleManager, 'registerVirtualModule'>;
10
+ };
11
+ export declare function createManifestMiddleware({ federationConfig, projectRoot, remoteEntryPath, tmpDirPath, vmManager, }: ManifestMiddlewareOptions): NonNullable<ServerConfigT['enhanceMiddleware']>;
12
+ export {};
@@ -0,0 +1,217 @@
1
+ "use strict";
2
+ var __webpack_require__ = {};
3
+ (()=>{
4
+ __webpack_require__.n = (module)=>{
5
+ var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
6
+ __webpack_require__.d(getter, {
7
+ a: getter
8
+ });
9
+ return getter;
10
+ };
11
+ })();
12
+ (()=>{
13
+ __webpack_require__.d = (exports1, getters, values)=>{
14
+ var define = (defs, kind)=>{
15
+ for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
16
+ enumerable: true,
17
+ [kind]: defs[key]
18
+ });
19
+ };
20
+ define(getters, "get");
21
+ define(values, "value");
22
+ };
23
+ })();
24
+ (()=>{
25
+ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
26
+ })();
27
+ (()=>{
28
+ __webpack_require__.r = (exports1)=>{
29
+ if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
30
+ value: 'Module'
31
+ });
32
+ Object.defineProperty(exports1, '__esModule', {
33
+ value: true
34
+ });
35
+ };
36
+ })();
37
+ var __webpack_exports__ = {};
38
+ __webpack_require__.r(__webpack_exports__);
39
+ __webpack_require__.d(__webpack_exports__, {
40
+ createManifestMiddleware: ()=>createManifestMiddleware
41
+ });
42
+ const external_node_fs_namespaceObject = require("node:fs");
43
+ const external_node_path_namespaceObject = require("node:path");
44
+ var external_node_path_default = /*#__PURE__*/ __webpack_require__.n(external_node_path_namespaceObject);
45
+ const metro_compat_js_namespaceObject = require("../utils/metro-compat.js");
46
+ const external_constants_js_namespaceObject = require("./constants.js");
47
+ const external_generators_js_namespaceObject = require("./generators.js");
48
+ const external_helpers_js_namespaceObject = require("./helpers.js");
49
+ const external_manifest_js_namespaceObject = require("./manifest.js");
50
+ function createManifestMiddleware({ federationConfig, projectRoot, remoteEntryPath, tmpDirPath, vmManager }) {
51
+ const warmups = new Map();
52
+ return (middleware, metroServer)=>{
53
+ const nextMiddleware = middleware;
54
+ return async (req, res, next)=>{
55
+ try {
56
+ const warmupOptions = getManifestWarmupOptions(req.url);
57
+ if (warmupOptions) {
58
+ const warmupKey = JSON.stringify(warmupOptions);
59
+ let warmup = warmups.get(warmupKey);
60
+ if (!warmup) {
61
+ warmup = warmManifestBundles(metroServer, {
62
+ federationConfig,
63
+ host: req.headers.host,
64
+ projectRoot,
65
+ remoteEntryPath,
66
+ tmpDirPath,
67
+ vmManager,
68
+ warmupOptions
69
+ }).finally(()=>{
70
+ warmups.delete(warmupKey);
71
+ });
72
+ warmups.set(warmupKey, warmup);
73
+ }
74
+ await warmup;
75
+ }
76
+ return nextMiddleware(req, res, next);
77
+ } catch (error) {
78
+ next(error instanceof Error ? error : new Error(String(error)));
79
+ }
80
+ };
81
+ };
82
+ }
83
+ function getManifestWarmupOptions(rawUrl) {
84
+ const parsedUrl = new URL(rawUrl ?? '/', 'http://localhost');
85
+ if (parsedUrl.pathname !== `/${external_constants_js_namespaceObject.MANIFEST_FILENAME}`) return null;
86
+ const platform = parsedUrl.searchParams.get('platform');
87
+ if (!platform) return null;
88
+ return {
89
+ dev: getBoolean(parsedUrl.searchParams, 'dev', true),
90
+ excludeSource: getBoolean(parsedUrl.searchParams, 'excludeSource', false),
91
+ minify: getBoolean(parsedUrl.searchParams, 'minify', false),
92
+ platform,
93
+ sourcePaths: parsedUrl.searchParams.get('sourcePaths') ?? void 0
94
+ };
95
+ }
96
+ async function warmManifestBundles(metroServer, { federationConfig, host, projectRoot, remoteEntryPath, tmpDirPath, vmManager, warmupOptions }) {
97
+ for (const request of getBundleWarmupRequests({
98
+ federationConfig,
99
+ projectRoot,
100
+ remoteEntryPath,
101
+ tmpDirPath,
102
+ vmManager
103
+ })){
104
+ if (request.virtualModule) await ensureVirtualModuleReady(request.virtualModule, vmManager);
105
+ await metroServer.build(getBundleOptions(request, host, warmupOptions));
106
+ }
107
+ }
108
+ function getBundleWarmupRequests({ federationConfig, projectRoot, remoteEntryPath, tmpDirPath }) {
109
+ const relativeTmpDirPath = (0, external_helpers_js_namespaceObject.toPosixPath)(external_node_path_default().relative(projectRoot, tmpDirPath));
110
+ const remoteEntryName = (0, external_helpers_js_namespaceObject.removeExtension)(external_node_path_default().basename(remoteEntryPath));
111
+ const relativeRemoteEntryPath = (0, external_helpers_js_namespaceObject.toPosixPath)(external_node_path_default().relative(projectRoot, remoteEntryPath));
112
+ const requests = [
113
+ {
114
+ bundlePath: `${relativeTmpDirPath}/${remoteEntryName}.bundle`,
115
+ entryFile: `./${relativeRemoteEntryPath}`,
116
+ isContainer: true,
117
+ virtualModule: {
118
+ filePath: remoteEntryPath,
119
+ getCode: ()=>(0, external_generators_js_namespaceObject.getRemoteEntryModule)(federationConfig, {
120
+ projectDir: projectRoot,
121
+ tmpDir: tmpDirPath
122
+ })
123
+ }
124
+ }
125
+ ];
126
+ for (const exposePath of Object.values(federationConfig.exposes)){
127
+ const bundlePath = getBundlePathForSource(exposePath);
128
+ requests.push({
129
+ bundlePath,
130
+ entryFile: normalizeEntryFile(exposePath),
131
+ isContainer: false
132
+ });
133
+ }
134
+ for (const [sharedName, sharedConfig] of Object.entries(federationConfig.shared)){
135
+ if (sharedConfig.eager || false === sharedConfig.import) continue;
136
+ const sharedVirtualModulePath = (0, external_manifest_js_namespaceObject.getSharedVirtualModulePath)(tmpDirPath, sharedName);
137
+ const relativeSharedVirtualModulePath = (0, external_helpers_js_namespaceObject.toPosixPath)(external_node_path_default().relative(projectRoot, sharedVirtualModulePath));
138
+ const sharedImportName = getSharedImportName(sharedName, sharedConfig);
139
+ requests.push({
140
+ bundlePath: (0, external_helpers_js_namespaceObject.replaceExtension)(relativeSharedVirtualModulePath, '.bundle'),
141
+ entryFile: normalizeEntryFile(relativeSharedVirtualModulePath),
142
+ isContainer: false,
143
+ virtualModule: {
144
+ filePath: sharedVirtualModulePath,
145
+ getCode: ()=>(0, external_generators_js_namespaceObject.getRemoteModule)(sharedImportName)
146
+ }
147
+ });
148
+ }
149
+ return requests;
150
+ }
151
+ async function ensureVirtualModuleReady(virtualModule, vmManager) {
152
+ const code = virtualModule.getCode();
153
+ await external_node_fs_namespaceObject.promises.mkdir(external_node_path_default().dirname(virtualModule.filePath), {
154
+ recursive: true
155
+ });
156
+ await external_node_fs_namespaceObject.promises.writeFile(virtualModule.filePath, code, 'utf-8');
157
+ vmManager.registerVirtualModule(virtualModule.filePath, ()=>code);
158
+ }
159
+ function getBundleOptions(request, host, warmupOptions) {
160
+ const query = getBundleQuery(warmupOptions, request.isContainer);
161
+ const sourceUrl = getSourceUrl(host, request.bundlePath, query);
162
+ const bundleOptions = {
163
+ ...metro_compat_js_namespaceObject.Server.DEFAULT_BUNDLE_OPTIONS,
164
+ dev: warmupOptions.dev,
165
+ entryFile: request.entryFile,
166
+ excludeSource: warmupOptions.excludeSource,
167
+ lazy: true,
168
+ minify: warmupOptions.minify,
169
+ modulesOnly: !request.isContainer,
170
+ platform: warmupOptions.platform,
171
+ runModule: request.isContainer,
172
+ sourceMapUrl: sourceUrl.replace(/\.bundle(\?)/, '.map$1'),
173
+ sourceUrl
174
+ };
175
+ if (warmupOptions.sourcePaths) bundleOptions.sourcePaths = warmupOptions.sourcePaths;
176
+ return bundleOptions;
177
+ }
178
+ function getBundleQuery(warmupOptions, isContainer) {
179
+ const query = new URLSearchParams();
180
+ query.set('platform', warmupOptions.platform);
181
+ query.set('dev', String(warmupOptions.dev));
182
+ query.set('lazy', 'true');
183
+ query.set('minify', String(warmupOptions.minify));
184
+ query.set('runModule', String(isContainer));
185
+ query.set('modulesOnly', String(!isContainer));
186
+ if (warmupOptions.excludeSource) query.set('excludeSource', 'true');
187
+ if (warmupOptions.sourcePaths) query.set('sourcePaths', warmupOptions.sourcePaths);
188
+ return query;
189
+ }
190
+ function getSourceUrl(host, bundlePath, query) {
191
+ const normalizedBundlePath = bundlePath.startsWith('/') ? bundlePath : `/${bundlePath}`;
192
+ return `http://${host ?? 'localhost'}${normalizedBundlePath}?${query.toString()}`;
193
+ }
194
+ function getBundlePathForSource(sourcePath) {
195
+ const normalized = (0, external_helpers_js_namespaceObject.toPosixPath)(external_node_path_default().normalize(sourcePath));
196
+ const withoutPrefix = normalized.startsWith('./') ? normalized.slice(2) : normalized;
197
+ return (0, external_helpers_js_namespaceObject.replaceExtension)(withoutPrefix, '.bundle');
198
+ }
199
+ function normalizeEntryFile(sourcePath) {
200
+ const normalized = (0, external_helpers_js_namespaceObject.toPosixPath)(external_node_path_default().normalize(sourcePath));
201
+ return normalized.startsWith('./') ? normalized : `./${normalized}`;
202
+ }
203
+ function getSharedImportName(sharedName, sharedConfig) {
204
+ return 'string' == typeof sharedConfig.import ? sharedConfig.import : sharedName;
205
+ }
206
+ function getBoolean(params, key, defaultValue) {
207
+ const value = params.get(key);
208
+ if (null == value) return defaultValue;
209
+ return 'true' === value || '1' === value;
210
+ }
211
+ exports.createManifestMiddleware = __webpack_exports__.createManifestMiddleware;
212
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
213
+ "createManifestMiddleware"
214
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
215
+ Object.defineProperty(exports, '__esModule', {
216
+ value: true
217
+ });