@module-federation/metro 0.0.0-next-20250827124348

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 (118) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +11 -0
  3. package/babel-plugin/index.js +115 -0
  4. package/babel-plugin/patch-initialize-core.js +61 -0
  5. package/babel-plugin/patch-require.js +174 -0
  6. package/bootstrap/index.d.ts +1 -0
  7. package/bootstrap/index.js +1 -0
  8. package/dist/babel/transformer.d.ts +2 -0
  9. package/dist/babel/transformer.js +15 -0
  10. package/dist/commands/bundle-host/index.d.ts +13 -0
  11. package/dist/commands/bundle-host/index.js +95 -0
  12. package/dist/commands/bundle-host/index.mjs +69 -0
  13. package/dist/commands/bundle-host/options.d.ts +5 -0
  14. package/dist/commands/bundle-host/options.js +39 -0
  15. package/dist/commands/bundle-host/options.mjs +7 -0
  16. package/dist/commands/bundle-host/types.d.ts +22 -0
  17. package/dist/commands/bundle-host/types.js +18 -0
  18. package/dist/commands/bundle-host/types.mjs +2 -0
  19. package/dist/commands/bundle-remote/index.d.ts +12 -0
  20. package/dist/commands/bundle-remote/index.js +226 -0
  21. package/dist/commands/bundle-remote/index.mjs +200 -0
  22. package/dist/commands/bundle-remote/options.d.ts +32 -0
  23. package/dist/commands/bundle-remote/options.js +109 -0
  24. package/dist/commands/bundle-remote/options.mjs +67 -0
  25. package/dist/commands/bundle-remote/types.d.ts +16 -0
  26. package/dist/commands/bundle-remote/types.js +18 -0
  27. package/dist/commands/bundle-remote/types.mjs +2 -0
  28. package/dist/commands/index.d.ts +48 -0
  29. package/dist/commands/index.js +72 -0
  30. package/dist/commands/index.mjs +13 -0
  31. package/dist/commands/types.d.ts +14 -0
  32. package/dist/commands/types.js +18 -0
  33. package/dist/commands/types.mjs +2 -0
  34. package/dist/commands/utils/create-module-path-remapper.d.ts +7 -0
  35. package/dist/commands/utils/create-module-path-remapper.js +64 -0
  36. package/dist/commands/utils/create-module-path-remapper.mjs +32 -0
  37. package/dist/commands/utils/create-resolver.d.ts +20 -0
  38. package/dist/commands/utils/create-resolver.js +57 -0
  39. package/dist/commands/utils/create-resolver.mjs +25 -0
  40. package/dist/commands/utils/get-community-plugin.d.ts +29 -0
  41. package/dist/commands/utils/get-community-plugin.js +50 -0
  42. package/dist/commands/utils/get-community-plugin.mjs +18 -0
  43. package/dist/commands/utils/load-metro-config.d.ts +3 -0
  44. package/dist/commands/utils/load-metro-config.js +84 -0
  45. package/dist/commands/utils/load-metro-config.mjs +43 -0
  46. package/dist/commands/utils/save-bundle-and-map.d.ts +5 -0
  47. package/dist/commands/utils/save-bundle-and-map.js +77 -0
  48. package/dist/commands/utils/save-bundle-and-map.mjs +57 -0
  49. package/dist/index.d.ts +2 -0
  50. package/dist/index.js +40 -0
  51. package/dist/index.mjs +5 -0
  52. package/dist/modules/HMRClient.ts +31 -0
  53. package/dist/modules/HMRClientShim.ts +1 -0
  54. package/dist/modules/asyncRequire.ts +134 -0
  55. package/dist/modules/asyncStartup.tsx +38 -0
  56. package/dist/modules/getDevServer.ts +15 -0
  57. package/dist/modules/metroCorePlugin.ts +83 -0
  58. package/dist/plugin/babel-transformer.d.ts +11 -0
  59. package/dist/plugin/babel-transformer.js +68 -0
  60. package/dist/plugin/babel-transformer.mjs +25 -0
  61. package/dist/plugin/constants.d.ts +9 -0
  62. package/dist/plugin/constants.js +68 -0
  63. package/dist/plugin/constants.mjs +12 -0
  64. package/dist/plugin/generators.d.ts +13 -0
  65. package/dist/plugin/generators.js +157 -0
  66. package/dist/plugin/generators.mjs +99 -0
  67. package/dist/plugin/helpers.d.ts +7 -0
  68. package/dist/plugin/helpers.js +119 -0
  69. package/dist/plugin/helpers.mjs +58 -0
  70. package/dist/plugin/index.d.ts +9 -0
  71. package/dist/plugin/index.js +167 -0
  72. package/dist/plugin/index.mjs +124 -0
  73. package/dist/plugin/manifest.d.ts +3 -0
  74. package/dist/plugin/manifest.js +146 -0
  75. package/dist/plugin/manifest.mjs +100 -0
  76. package/dist/plugin/normalize-extra-options.d.ts +8 -0
  77. package/dist/plugin/normalize-extra-options.js +46 -0
  78. package/dist/plugin/normalize-extra-options.mjs +14 -0
  79. package/dist/plugin/normalize-options.d.ts +7 -0
  80. package/dist/plugin/normalize-options.js +89 -0
  81. package/dist/plugin/normalize-options.mjs +46 -0
  82. package/dist/plugin/resolver.d.ts +25 -0
  83. package/dist/plugin/resolver.js +199 -0
  84. package/dist/plugin/resolver.mjs +160 -0
  85. package/dist/plugin/rewrite-request.d.ts +10 -0
  86. package/dist/plugin/rewrite-request.js +76 -0
  87. package/dist/plugin/rewrite-request.mjs +34 -0
  88. package/dist/plugin/serializer.d.ts +5 -0
  89. package/dist/plugin/serializer.js +171 -0
  90. package/dist/plugin/serializer.mjs +151 -0
  91. package/dist/plugin/validate-options.d.ts +2 -0
  92. package/dist/plugin/validate-options.js +61 -0
  93. package/dist/plugin/validate-options.mjs +29 -0
  94. package/dist/runtime/host-entry.d.ts +1 -0
  95. package/dist/runtime/host-entry.js +3 -0
  96. package/dist/runtime/init-host.d.ts +1 -0
  97. package/dist/runtime/init-host.js +31 -0
  98. package/dist/runtime/remote-entry.d.ts +1 -0
  99. package/dist/runtime/remote-entry.js +57 -0
  100. package/dist/runtime/remote-hmr.d.ts +1 -0
  101. package/dist/runtime/remote-hmr.js +19 -0
  102. package/dist/runtime/remote-module-registry.d.ts +7 -0
  103. package/dist/runtime/remote-module-registry.js +57 -0
  104. package/dist/runtime/remote-module.d.ts +1 -0
  105. package/dist/runtime/remote-module.js +2 -0
  106. package/dist/types.d.ts +26 -0
  107. package/dist/types.js +18 -0
  108. package/dist/types.mjs +2 -0
  109. package/dist/utils/errors.d.ts +8 -0
  110. package/dist/utils/errors.js +50 -0
  111. package/dist/utils/errors.mjs +15 -0
  112. package/dist/utils/index.d.ts +2 -0
  113. package/dist/utils/index.js +43 -0
  114. package/dist/utils/index.mjs +5 -0
  115. package/dist/utils/vm-manager.d.ts +21 -0
  116. package/dist/utils/vm-manager.js +116 -0
  117. package/dist/utils/vm-manager.mjs +73 -0
  118. package/package.json +91 -0
@@ -0,0 +1,89 @@
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, 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
+ });
18
+ };
19
+ })();
20
+ (()=>{
21
+ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
22
+ })();
23
+ (()=>{
24
+ __webpack_require__.r = (exports1)=>{
25
+ if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
26
+ value: 'Module'
27
+ });
28
+ Object.defineProperty(exports1, '__esModule', {
29
+ value: true
30
+ });
31
+ };
32
+ })();
33
+ var __webpack_exports__ = {};
34
+ __webpack_require__.r(__webpack_exports__);
35
+ __webpack_require__.d(__webpack_exports__, {
36
+ normalizeOptions: ()=>normalizeOptions
37
+ });
38
+ const external_node_fs_namespaceObject = require("node:fs");
39
+ var external_node_fs_default = /*#__PURE__*/ __webpack_require__.n(external_node_fs_namespaceObject);
40
+ const external_node_path_namespaceObject = require("node:path");
41
+ var external_node_path_default = /*#__PURE__*/ __webpack_require__.n(external_node_path_namespaceObject);
42
+ const external_constants_js_namespaceObject = require("./constants.js");
43
+ function normalizeOptions(options, { projectRoot, tmpDirPath }) {
44
+ const shared = getNormalizedShared(options, projectRoot);
45
+ const shareStrategy = getNormalizedShareStrategy(options);
46
+ const plugins = getNormalizedPlugins(options, tmpDirPath);
47
+ return {
48
+ name: options.name,
49
+ filename: options.filename ?? external_constants_js_namespaceObject.DEFAULT_ENTRY_FILENAME,
50
+ remotes: options.remotes ?? {},
51
+ exposes: options.exposes ?? {},
52
+ shared,
53
+ shareStrategy,
54
+ plugins
55
+ };
56
+ }
57
+ function getNormalizedShared(options, projectRoot) {
58
+ const pkg = getProjectPackageJson(projectRoot);
59
+ const shared = options.shared ?? {};
60
+ if (!options.exposes) for (const sharedName of Object.keys(shared))shared[sharedName].eager = true;
61
+ for (const sharedName of Object.keys(shared))if (!shared[sharedName].requiredVersion) {
62
+ var _pkg_dependencies, _pkg_devDependencies;
63
+ shared[sharedName].requiredVersion = (null == (_pkg_dependencies = pkg.dependencies) ? void 0 : _pkg_dependencies[sharedName]) || (null == (_pkg_devDependencies = pkg.devDependencies) ? void 0 : _pkg_devDependencies[sharedName]);
64
+ }
65
+ if (!shared['react-native/Libraries/Network/RCTNetworking']) {
66
+ const reactNativeSharedConfig = shared['react-native'];
67
+ shared['react-native/Libraries/Network/RCTNetworking'] = reactNativeSharedConfig;
68
+ }
69
+ return shared;
70
+ }
71
+ function getNormalizedShareStrategy(options) {
72
+ return options.shareStrategy ?? 'loaded-first';
73
+ }
74
+ function getNormalizedPlugins(options, tmpDirPath) {
75
+ const plugins = options.plugins ?? [];
76
+ plugins.unshift(require.resolve('../modules/metroCorePlugin.ts'));
77
+ return plugins.map((pluginPath)=>external_node_path_default().relative(tmpDirPath, pluginPath));
78
+ }
79
+ function getProjectPackageJson(projectRoot) {
80
+ const packageJsonPath = external_node_path_default().join(projectRoot, 'package.json');
81
+ return JSON.parse(external_node_fs_default().readFileSync(packageJsonPath, 'utf-8'));
82
+ }
83
+ exports.normalizeOptions = __webpack_exports__.normalizeOptions;
84
+ for(var __webpack_i__ in __webpack_exports__)if (-1 === [
85
+ "normalizeOptions"
86
+ ].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
87
+ Object.defineProperty(exports, '__esModule', {
88
+ value: true
89
+ });
@@ -0,0 +1,46 @@
1
+ import __rslib_shim_module__ from 'module';
2
+ const require = /*#__PURE__*/ __rslib_shim_module__.createRequire(import.meta.url);
3
+ import node_fs from "node:fs";
4
+ import node_path from "node:path";
5
+ import { DEFAULT_ENTRY_FILENAME } from "./constants.mjs";
6
+ function normalizeOptions(options, { projectRoot, tmpDirPath }) {
7
+ const shared = getNormalizedShared(options, projectRoot);
8
+ const shareStrategy = getNormalizedShareStrategy(options);
9
+ const plugins = getNormalizedPlugins(options, tmpDirPath);
10
+ return {
11
+ name: options.name,
12
+ filename: options.filename ?? DEFAULT_ENTRY_FILENAME,
13
+ remotes: options.remotes ?? {},
14
+ exposes: options.exposes ?? {},
15
+ shared,
16
+ shareStrategy,
17
+ plugins
18
+ };
19
+ }
20
+ function getNormalizedShared(options, projectRoot) {
21
+ const pkg = getProjectPackageJson(projectRoot);
22
+ const shared = options.shared ?? {};
23
+ if (!options.exposes) for (const sharedName of Object.keys(shared))shared[sharedName].eager = true;
24
+ for (const sharedName of Object.keys(shared))if (!shared[sharedName].requiredVersion) {
25
+ var _pkg_dependencies, _pkg_devDependencies;
26
+ shared[sharedName].requiredVersion = (null == (_pkg_dependencies = pkg.dependencies) ? void 0 : _pkg_dependencies[sharedName]) || (null == (_pkg_devDependencies = pkg.devDependencies) ? void 0 : _pkg_devDependencies[sharedName]);
27
+ }
28
+ if (!shared['react-native/Libraries/Network/RCTNetworking']) {
29
+ const reactNativeSharedConfig = shared['react-native'];
30
+ shared['react-native/Libraries/Network/RCTNetworking'] = reactNativeSharedConfig;
31
+ }
32
+ return shared;
33
+ }
34
+ function getNormalizedShareStrategy(options) {
35
+ return options.shareStrategy ?? 'loaded-first';
36
+ }
37
+ function getNormalizedPlugins(options, tmpDirPath) {
38
+ const plugins = options.plugins ?? [];
39
+ plugins.unshift(require.resolve('../modules/metroCorePlugin.ts'));
40
+ return plugins.map((pluginPath)=>node_path.relative(tmpDirPath, pluginPath));
41
+ }
42
+ function getProjectPackageJson(projectRoot) {
43
+ const packageJsonPath = node_path.join(projectRoot, 'package.json');
44
+ return JSON.parse(node_fs.readFileSync(packageJsonPath, 'utf-8'));
45
+ }
46
+ export { normalizeOptions };
@@ -0,0 +1,25 @@
1
+ import type { CustomResolver } from 'metro-resolver';
2
+ import type { ModuleFederationConfigNormalized } from '../types';
3
+ import type { VirtualModuleManager } from '../utils';
4
+ interface CreateResolveRequestOptions {
5
+ isRemote: boolean;
6
+ hacks: {
7
+ patchHMRClient: boolean;
8
+ patchInitializeCore: boolean;
9
+ };
10
+ paths: {
11
+ asyncRequire: string;
12
+ hostEntry: string;
13
+ initHost: string;
14
+ originalEntry: string;
15
+ remoteEntry: string;
16
+ remoteHMRSetup: string;
17
+ remoteModuleRegistry: string;
18
+ projectDir: string;
19
+ tmpDir: string;
20
+ };
21
+ options: ModuleFederationConfigNormalized;
22
+ vmManager: VirtualModuleManager;
23
+ }
24
+ export declare function createResolveRequest({ vmManager, options, hacks, paths, isRemote, }: CreateResolveRequestOptions): CustomResolver;
25
+ export {};
@@ -0,0 +1,199 @@
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, 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
+ });
18
+ };
19
+ })();
20
+ (()=>{
21
+ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
22
+ })();
23
+ (()=>{
24
+ __webpack_require__.r = (exports1)=>{
25
+ if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
26
+ value: 'Module'
27
+ });
28
+ Object.defineProperty(exports1, '__esModule', {
29
+ value: true
30
+ });
31
+ };
32
+ })();
33
+ var __webpack_exports__ = {};
34
+ __webpack_require__.r(__webpack_exports__);
35
+ __webpack_require__.d(__webpack_exports__, {
36
+ createResolveRequest: ()=>createResolveRequest
37
+ });
38
+ const external_node_path_namespaceObject = require("node:path");
39
+ var external_node_path_default = /*#__PURE__*/ __webpack_require__.n(external_node_path_namespaceObject);
40
+ const external_constants_js_namespaceObject = require("./constants.js");
41
+ const external_generators_js_namespaceObject = require("./generators.js");
42
+ const external_helpers_js_namespaceObject = require("./helpers.js");
43
+ function createResolveRequest({ vmManager, options, hacks, paths, isRemote }) {
44
+ const hostEntryPathRegex = getEntryPathRegex({
45
+ entry: paths.hostEntry,
46
+ projectDir: paths.projectDir
47
+ });
48
+ const remoteEntryPathRegex = getEntryPathRegex({
49
+ entry: paths.remoteEntry,
50
+ projectDir: paths.projectDir
51
+ });
52
+ return function(context, moduleName, platform) {
53
+ if (moduleName.match(hostEntryPathRegex)) {
54
+ const hostEntryGenerator = ()=>(0, external_generators_js_namespaceObject.getHostEntryModule)(options, {
55
+ originalEntry: paths.originalEntry,
56
+ tmpDir: paths.tmpDir
57
+ });
58
+ vmManager.registerVirtualModule(paths.hostEntry, hostEntryGenerator);
59
+ return {
60
+ type: 'sourceFile',
61
+ filePath: paths.hostEntry
62
+ };
63
+ }
64
+ if (moduleName.match(remoteEntryPathRegex)) {
65
+ const remoteEntryGenerator = ()=>(0, external_generators_js_namespaceObject.getRemoteEntryModule)(options, {
66
+ tmpDir: paths.tmpDir,
67
+ projectDir: paths.projectDir
68
+ });
69
+ vmManager.registerVirtualModule(paths.remoteEntry, remoteEntryGenerator);
70
+ return {
71
+ type: 'sourceFile',
72
+ filePath: paths.remoteEntry
73
+ };
74
+ }
75
+ if (moduleName === external_constants_js_namespaceObject.INIT_HOST) {
76
+ const initHostGenerator = ()=>(0, external_generators_js_namespaceObject.getInitHostModule)(options);
77
+ vmManager.registerVirtualModule(paths.initHost, initHostGenerator);
78
+ return {
79
+ type: 'sourceFile',
80
+ filePath: paths.initHost
81
+ };
82
+ }
83
+ if (moduleName === external_constants_js_namespaceObject.REMOTE_MODULE_REGISTRY) {
84
+ const registryGenerator = ()=>(0, external_generators_js_namespaceObject.getRemoteModuleRegistryModule)();
85
+ vmManager.registerVirtualModule(paths.remoteModuleRegistry, registryGenerator);
86
+ return {
87
+ type: 'sourceFile',
88
+ filePath: paths.remoteModuleRegistry
89
+ };
90
+ }
91
+ if (moduleName === external_constants_js_namespaceObject.REMOTE_HMR_SETUP) {
92
+ const remoteHMRSetupGenerator = ()=>(0, external_generators_js_namespaceObject.getRemoteHMRSetupModule)();
93
+ vmManager.registerVirtualModule(paths.remoteHMRSetup, remoteHMRSetupGenerator);
94
+ return {
95
+ type: 'sourceFile',
96
+ filePath: paths.remoteHMRSetup
97
+ };
98
+ }
99
+ if (moduleName === external_constants_js_namespaceObject.ASYNC_REQUIRE) return {
100
+ type: 'sourceFile',
101
+ filePath: paths.asyncRequire
102
+ };
103
+ if ([
104
+ paths.initHost
105
+ ].includes(context.originModulePath)) return context.resolveRequest(context, moduleName, platform);
106
+ if ([
107
+ paths.remoteEntry
108
+ ].includes(context.originModulePath)) {
109
+ const sharedModule = options.shared[moduleName];
110
+ if (sharedModule && false === sharedModule.import) {
111
+ const sharedPath = getSharedPath(moduleName, paths.tmpDir);
112
+ return {
113
+ type: 'sourceFile',
114
+ filePath: sharedPath
115
+ };
116
+ }
117
+ return context.resolveRequest(context, moduleName, platform);
118
+ }
119
+ for (const remoteName of Object.keys(options.remotes))if (moduleName.startsWith(remoteName + '/')) {
120
+ const remotePath = getRemoteModulePath(moduleName, paths.tmpDir);
121
+ const remoteGenerator = ()=>(0, external_generators_js_namespaceObject.getRemoteModule)(moduleName);
122
+ vmManager.registerVirtualModule(remotePath, remoteGenerator);
123
+ return {
124
+ type: 'sourceFile',
125
+ filePath: remotePath
126
+ };
127
+ }
128
+ for (const sharedName of Object.keys(options.shared)){
129
+ const importName = options.shared[sharedName].import || sharedName;
130
+ if (moduleName === importName) {
131
+ const sharedPath = getSharedPath(moduleName, paths.tmpDir);
132
+ const sharedGenerator = ()=>(0, external_generators_js_namespaceObject.getRemoteModule)(moduleName);
133
+ vmManager.registerVirtualModule(sharedPath, sharedGenerator);
134
+ return {
135
+ type: 'sourceFile',
136
+ filePath: sharedPath
137
+ };
138
+ }
139
+ }
140
+ if (isRemote && moduleName.endsWith('getDevServer')) {
141
+ const res = context.resolveRequest(context, moduleName, platform);
142
+ const from = external_constants_js_namespaceObject.GET_DEV_SERVER_REGEX;
143
+ const to = resolveModule('getDevServer.ts');
144
+ return replaceModule(from, to)(res);
145
+ }
146
+ if ((0, external_helpers_js_namespaceObject.isUsingMFBundleCommand)() && moduleName.endsWith('HMRClient')) {
147
+ const res = context.resolveRequest(context, moduleName, platform);
148
+ const from = external_constants_js_namespaceObject.HMR_CLIENT_REGEX;
149
+ const to = resolveModule('HMRClientShim.ts');
150
+ return replaceModule(from, to)(res);
151
+ }
152
+ if (hacks.patchHMRClient && moduleName.endsWith('HMRClient') && context.originModulePath !== resolveModule('HMRClient.ts')) {
153
+ const res = context.resolveRequest(context, moduleName, platform);
154
+ const from = external_constants_js_namespaceObject.HMR_CLIENT_REGEX;
155
+ const to = resolveModule('HMRClient.ts');
156
+ return replaceModule(from, to)(res);
157
+ }
158
+ return context.resolveRequest(context, moduleName, platform);
159
+ };
160
+ }
161
+ function getSharedPath(name, dir) {
162
+ const sharedModuleName = name.replaceAll('/', '_');
163
+ const sharedModuleDir = external_node_path_default().join(dir, 'shared');
164
+ return external_node_path_default().join(sharedModuleDir, `${sharedModuleName}.js`);
165
+ }
166
+ function getRemoteModulePath(name, dir) {
167
+ const remoteModuleName = name.replaceAll('/', '_');
168
+ const remoteModuleDir = external_node_path_default().join(dir, 'remote');
169
+ return external_node_path_default().join(remoteModuleDir, `${remoteModuleName}.js`);
170
+ }
171
+ function resolveModule(moduleName) {
172
+ return external_node_path_default().resolve(__dirname, `../modules/${moduleName}`);
173
+ }
174
+ function replaceModule(from, to) {
175
+ return (resolved)=>{
176
+ if ('sourceFile' === resolved.type && from.test(resolved.filePath)) {
177
+ if (null === to) return {
178
+ type: 'empty'
179
+ };
180
+ return {
181
+ type: 'sourceFile',
182
+ filePath: to
183
+ };
184
+ }
185
+ return resolved;
186
+ };
187
+ }
188
+ function getEntryPathRegex(paths) {
189
+ const relativeEntryPath = external_node_path_default().relative(paths.projectDir, paths.entry);
190
+ const entryName = (0, external_helpers_js_namespaceObject.removeExtension)(relativeEntryPath);
191
+ return new RegExp(`^\\./${entryName}(\\.js)?$`);
192
+ }
193
+ exports.createResolveRequest = __webpack_exports__.createResolveRequest;
194
+ for(var __webpack_i__ in __webpack_exports__)if (-1 === [
195
+ "createResolveRequest"
196
+ ].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
197
+ Object.defineProperty(exports, '__esModule', {
198
+ value: true
199
+ });
@@ -0,0 +1,160 @@
1
+ import 'module';
2
+ /*#__PURE__*/ import.meta.url;
3
+ import { fileURLToPath as __webpack_fileURLToPath__ } from "node:url";
4
+ import { dirname as __webpack_dirname__ } from "node:path";
5
+ import node_path from "node:path";
6
+ import { ASYNC_REQUIRE, GET_DEV_SERVER_REGEX, HMR_CLIENT_REGEX, INIT_HOST, REMOTE_HMR_SETUP, REMOTE_MODULE_REGISTRY } from "./constants.mjs";
7
+ import { getHostEntryModule, getInitHostModule, getRemoteEntryModule, getRemoteHMRSetupModule, getRemoteModule, getRemoteModuleRegistryModule } from "./generators.mjs";
8
+ import { isUsingMFBundleCommand, removeExtension } from "./helpers.mjs";
9
+ var resolver_dirname = __webpack_dirname__(__webpack_fileURLToPath__(import.meta.url));
10
+ function createResolveRequest({ vmManager, options, hacks, paths, isRemote }) {
11
+ const hostEntryPathRegex = getEntryPathRegex({
12
+ entry: paths.hostEntry,
13
+ projectDir: paths.projectDir
14
+ });
15
+ const remoteEntryPathRegex = getEntryPathRegex({
16
+ entry: paths.remoteEntry,
17
+ projectDir: paths.projectDir
18
+ });
19
+ return function(context, moduleName, platform) {
20
+ if (moduleName.match(hostEntryPathRegex)) {
21
+ const hostEntryGenerator = ()=>getHostEntryModule(options, {
22
+ originalEntry: paths.originalEntry,
23
+ tmpDir: paths.tmpDir
24
+ });
25
+ vmManager.registerVirtualModule(paths.hostEntry, hostEntryGenerator);
26
+ return {
27
+ type: 'sourceFile',
28
+ filePath: paths.hostEntry
29
+ };
30
+ }
31
+ if (moduleName.match(remoteEntryPathRegex)) {
32
+ const remoteEntryGenerator = ()=>getRemoteEntryModule(options, {
33
+ tmpDir: paths.tmpDir,
34
+ projectDir: paths.projectDir
35
+ });
36
+ vmManager.registerVirtualModule(paths.remoteEntry, remoteEntryGenerator);
37
+ return {
38
+ type: 'sourceFile',
39
+ filePath: paths.remoteEntry
40
+ };
41
+ }
42
+ if (moduleName === INIT_HOST) {
43
+ const initHostGenerator = ()=>getInitHostModule(options);
44
+ vmManager.registerVirtualModule(paths.initHost, initHostGenerator);
45
+ return {
46
+ type: 'sourceFile',
47
+ filePath: paths.initHost
48
+ };
49
+ }
50
+ if (moduleName === REMOTE_MODULE_REGISTRY) {
51
+ const registryGenerator = ()=>getRemoteModuleRegistryModule();
52
+ vmManager.registerVirtualModule(paths.remoteModuleRegistry, registryGenerator);
53
+ return {
54
+ type: 'sourceFile',
55
+ filePath: paths.remoteModuleRegistry
56
+ };
57
+ }
58
+ if (moduleName === REMOTE_HMR_SETUP) {
59
+ const remoteHMRSetupGenerator = ()=>getRemoteHMRSetupModule();
60
+ vmManager.registerVirtualModule(paths.remoteHMRSetup, remoteHMRSetupGenerator);
61
+ return {
62
+ type: 'sourceFile',
63
+ filePath: paths.remoteHMRSetup
64
+ };
65
+ }
66
+ if (moduleName === ASYNC_REQUIRE) return {
67
+ type: 'sourceFile',
68
+ filePath: paths.asyncRequire
69
+ };
70
+ if ([
71
+ paths.initHost
72
+ ].includes(context.originModulePath)) return context.resolveRequest(context, moduleName, platform);
73
+ if ([
74
+ paths.remoteEntry
75
+ ].includes(context.originModulePath)) {
76
+ const sharedModule = options.shared[moduleName];
77
+ if (sharedModule && false === sharedModule.import) {
78
+ const sharedPath = getSharedPath(moduleName, paths.tmpDir);
79
+ return {
80
+ type: 'sourceFile',
81
+ filePath: sharedPath
82
+ };
83
+ }
84
+ return context.resolveRequest(context, moduleName, platform);
85
+ }
86
+ for (const remoteName of Object.keys(options.remotes))if (moduleName.startsWith(remoteName + '/')) {
87
+ const remotePath = getRemoteModulePath(moduleName, paths.tmpDir);
88
+ const remoteGenerator = ()=>getRemoteModule(moduleName);
89
+ vmManager.registerVirtualModule(remotePath, remoteGenerator);
90
+ return {
91
+ type: 'sourceFile',
92
+ filePath: remotePath
93
+ };
94
+ }
95
+ for (const sharedName of Object.keys(options.shared)){
96
+ const importName = options.shared[sharedName].import || sharedName;
97
+ if (moduleName === importName) {
98
+ const sharedPath = getSharedPath(moduleName, paths.tmpDir);
99
+ const sharedGenerator = ()=>getRemoteModule(moduleName);
100
+ vmManager.registerVirtualModule(sharedPath, sharedGenerator);
101
+ return {
102
+ type: 'sourceFile',
103
+ filePath: sharedPath
104
+ };
105
+ }
106
+ }
107
+ if (isRemote && moduleName.endsWith('getDevServer')) {
108
+ const res = context.resolveRequest(context, moduleName, platform);
109
+ const from = GET_DEV_SERVER_REGEX;
110
+ const to = resolveModule('getDevServer.ts');
111
+ return replaceModule(from, to)(res);
112
+ }
113
+ if (isUsingMFBundleCommand() && moduleName.endsWith('HMRClient')) {
114
+ const res = context.resolveRequest(context, moduleName, platform);
115
+ const from = HMR_CLIENT_REGEX;
116
+ const to = resolveModule('HMRClientShim.ts');
117
+ return replaceModule(from, to)(res);
118
+ }
119
+ if (hacks.patchHMRClient && moduleName.endsWith('HMRClient') && context.originModulePath !== resolveModule('HMRClient.ts')) {
120
+ const res = context.resolveRequest(context, moduleName, platform);
121
+ const from = HMR_CLIENT_REGEX;
122
+ const to = resolveModule('HMRClient.ts');
123
+ return replaceModule(from, to)(res);
124
+ }
125
+ return context.resolveRequest(context, moduleName, platform);
126
+ };
127
+ }
128
+ function getSharedPath(name, dir) {
129
+ const sharedModuleName = name.replaceAll('/', '_');
130
+ const sharedModuleDir = node_path.join(dir, 'shared');
131
+ return node_path.join(sharedModuleDir, `${sharedModuleName}.js`);
132
+ }
133
+ function getRemoteModulePath(name, dir) {
134
+ const remoteModuleName = name.replaceAll('/', '_');
135
+ const remoteModuleDir = node_path.join(dir, 'remote');
136
+ return node_path.join(remoteModuleDir, `${remoteModuleName}.js`);
137
+ }
138
+ function resolveModule(moduleName) {
139
+ return node_path.resolve(resolver_dirname, `../modules/${moduleName}`);
140
+ }
141
+ function replaceModule(from, to) {
142
+ return (resolved)=>{
143
+ if ('sourceFile' === resolved.type && from.test(resolved.filePath)) {
144
+ if (null === to) return {
145
+ type: 'empty'
146
+ };
147
+ return {
148
+ type: 'sourceFile',
149
+ filePath: to
150
+ };
151
+ }
152
+ return resolved;
153
+ };
154
+ }
155
+ function getEntryPathRegex(paths) {
156
+ const relativeEntryPath = node_path.relative(paths.projectDir, paths.entry);
157
+ const entryName = removeExtension(relativeEntryPath);
158
+ return new RegExp(`^\\./${entryName}(\\.js)?$`);
159
+ }
160
+ export { createResolveRequest };
@@ -0,0 +1,10 @@
1
+ import type { ConfigT } from 'metro-config';
2
+ type CreateRewriteRequestOptions = {
3
+ config: ConfigT;
4
+ originalEntryFilename: string;
5
+ remoteEntryFilename: string;
6
+ manifestPath: string;
7
+ tmpDirPath: string;
8
+ };
9
+ export declare function createRewriteRequest({ config, originalEntryFilename, remoteEntryFilename, manifestPath, tmpDirPath, }: CreateRewriteRequestOptions): (url: string) => string;
10
+ export {};
@@ -0,0 +1,76 @@
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, 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
+ });
18
+ };
19
+ })();
20
+ (()=>{
21
+ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
22
+ })();
23
+ (()=>{
24
+ __webpack_require__.r = (exports1)=>{
25
+ if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
26
+ value: 'Module'
27
+ });
28
+ Object.defineProperty(exports1, '__esModule', {
29
+ value: true
30
+ });
31
+ };
32
+ })();
33
+ var __webpack_exports__ = {};
34
+ __webpack_require__.r(__webpack_exports__);
35
+ __webpack_require__.d(__webpack_exports__, {
36
+ createRewriteRequest: ()=>createRewriteRequest
37
+ });
38
+ const external_node_path_namespaceObject = require("node:path");
39
+ var external_node_path_default = /*#__PURE__*/ __webpack_require__.n(external_node_path_namespaceObject);
40
+ const external_constants_js_namespaceObject = require("./constants.js");
41
+ const external_helpers_js_namespaceObject = require("./helpers.js");
42
+ function createRewriteRequest({ config, originalEntryFilename, remoteEntryFilename, manifestPath, tmpDirPath }) {
43
+ const hostEntryName = (0, external_helpers_js_namespaceObject.removeExtension)(originalEntryFilename);
44
+ const remoteEntryName = (0, external_helpers_js_namespaceObject.removeExtension)(remoteEntryFilename);
45
+ const relativeTmpDirPath = external_node_path_default().relative(config.projectRoot, tmpDirPath).split(external_node_path_default().sep).join(external_node_path_default().posix.sep);
46
+ const hostEntryPathRegex = getEntryPathRegex(hostEntryName);
47
+ const remoteEntryPathRegex = getEntryPathRegex(remoteEntryName);
48
+ return function(url) {
49
+ const root = config.projectRoot;
50
+ const { pathname } = new URL(url, 'protocol://host');
51
+ if (pathname.match(hostEntryPathRegex)) {
52
+ const target = `${relativeTmpDirPath}/${hostEntryName}`;
53
+ return url.replace(hostEntryName, target);
54
+ }
55
+ if (pathname.match(remoteEntryPathRegex)) {
56
+ const target = `${relativeTmpDirPath}/${remoteEntryName}`;
57
+ return url.replace(remoteEntryName, target);
58
+ }
59
+ if (pathname.startsWith(`/${external_constants_js_namespaceObject.MANIFEST_FILENAME}`)) {
60
+ const target = manifestPath.replace(root, '[metro-project]');
61
+ return url.replace(external_constants_js_namespaceObject.MANIFEST_FILENAME, target);
62
+ }
63
+ if (config.server.rewriteRequestUrl) return config.server.rewriteRequestUrl(url);
64
+ return url;
65
+ };
66
+ }
67
+ function getEntryPathRegex(entryFilename) {
68
+ return new RegExp(`^\\/${entryFilename}(\\.js)?(\\.bundle)$`);
69
+ }
70
+ exports.createRewriteRequest = __webpack_exports__.createRewriteRequest;
71
+ for(var __webpack_i__ in __webpack_exports__)if (-1 === [
72
+ "createRewriteRequest"
73
+ ].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
74
+ Object.defineProperty(exports, '__esModule', {
75
+ value: true
76
+ });
@@ -0,0 +1,34 @@
1
+ import 'module';
2
+ /*#__PURE__*/ import.meta.url;
3
+ import node_path from "node:path";
4
+ import { MANIFEST_FILENAME } from "./constants.mjs";
5
+ import { removeExtension } from "./helpers.mjs";
6
+ function createRewriteRequest({ config, originalEntryFilename, remoteEntryFilename, manifestPath, tmpDirPath }) {
7
+ const hostEntryName = removeExtension(originalEntryFilename);
8
+ const remoteEntryName = removeExtension(remoteEntryFilename);
9
+ const relativeTmpDirPath = node_path.relative(config.projectRoot, tmpDirPath).split(node_path.sep).join(node_path.posix.sep);
10
+ const hostEntryPathRegex = getEntryPathRegex(hostEntryName);
11
+ const remoteEntryPathRegex = getEntryPathRegex(remoteEntryName);
12
+ return function(url) {
13
+ const root = config.projectRoot;
14
+ const { pathname } = new URL(url, 'protocol://host');
15
+ if (pathname.match(hostEntryPathRegex)) {
16
+ const target = `${relativeTmpDirPath}/${hostEntryName}`;
17
+ return url.replace(hostEntryName, target);
18
+ }
19
+ if (pathname.match(remoteEntryPathRegex)) {
20
+ const target = `${relativeTmpDirPath}/${remoteEntryName}`;
21
+ return url.replace(remoteEntryName, target);
22
+ }
23
+ if (pathname.startsWith(`/${MANIFEST_FILENAME}`)) {
24
+ const target = manifestPath.replace(root, '[metro-project]');
25
+ return url.replace(MANIFEST_FILENAME, target);
26
+ }
27
+ if (config.server.rewriteRequestUrl) return config.server.rewriteRequestUrl(url);
28
+ return url;
29
+ };
30
+ }
31
+ function getEntryPathRegex(entryFilename) {
32
+ return new RegExp(`^\\/${entryFilename}(\\.js)?(\\.bundle)$`);
33
+ }
34
+ export { createRewriteRequest };
@@ -0,0 +1,5 @@
1
+ import type { SerializerConfigT } from 'metro-config';
2
+ import type { ModuleFederationConfigNormalized } from '../types';
3
+ type CustomSerializer = SerializerConfigT['customSerializer'];
4
+ export declare function getModuleFederationSerializer(mfConfig: ModuleFederationConfigNormalized, isUsingMFBundleCommand: boolean): CustomSerializer;
5
+ export {};