@module-federation/metro 0.0.0-chore-bump-node-22-20260710161714

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 (126) 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.js +15 -0
  9. package/dist/commands/bundle-host/index.d.ts +13 -0
  10. package/dist/commands/bundle-host/index.js +100 -0
  11. package/dist/commands/bundle-host/index.mjs +47 -0
  12. package/dist/commands/bundle-host/options.d.ts +5 -0
  13. package/dist/commands/bundle-host/options.js +43 -0
  14. package/dist/commands/bundle-host/options.mjs +6 -0
  15. package/dist/commands/bundle-host/types.d.ts +22 -0
  16. package/dist/commands/bundle-host/types.js +18 -0
  17. package/dist/commands/bundle-host/types.mjs +1 -0
  18. package/dist/commands/bundle-remote/index.d.ts +12 -0
  19. package/dist/commands/bundle-remote/index.js +241 -0
  20. package/dist/commands/bundle-remote/index.mjs +190 -0
  21. package/dist/commands/bundle-remote/options.d.ts +32 -0
  22. package/dist/commands/bundle-remote/options.js +113 -0
  23. package/dist/commands/bundle-remote/options.mjs +66 -0
  24. package/dist/commands/bundle-remote/types.d.ts +16 -0
  25. package/dist/commands/bundle-remote/types.js +18 -0
  26. package/dist/commands/bundle-remote/types.mjs +1 -0
  27. package/dist/commands/index.d.ts +48 -0
  28. package/dist/commands/index.js +76 -0
  29. package/dist/commands/index.mjs +13 -0
  30. package/dist/commands/types.d.ts +14 -0
  31. package/dist/commands/types.js +18 -0
  32. package/dist/commands/types.mjs +1 -0
  33. package/dist/commands/utils/create-module-path-remapper.d.ts +7 -0
  34. package/dist/commands/utils/create-module-path-remapper.js +68 -0
  35. package/dist/commands/utils/create-module-path-remapper.mjs +31 -0
  36. package/dist/commands/utils/create-resolver.d.ts +20 -0
  37. package/dist/commands/utils/create-resolver.js +61 -0
  38. package/dist/commands/utils/create-resolver.mjs +24 -0
  39. package/dist/commands/utils/get-community-plugin.d.ts +28 -0
  40. package/dist/commands/utils/get-community-plugin.js +53 -0
  41. package/dist/commands/utils/get-community-plugin.mjs +17 -0
  42. package/dist/commands/utils/load-metro-config.d.ts +3 -0
  43. package/dist/commands/utils/load-metro-config.js +85 -0
  44. package/dist/commands/utils/load-metro-config.mjs +41 -0
  45. package/dist/commands/utils/path-utils.d.ts +2 -0
  46. package/dist/commands/utils/path-utils.js +51 -0
  47. package/dist/commands/utils/path-utils.mjs +11 -0
  48. package/dist/commands/utils/save-bundle-and-map.d.ts +5 -0
  49. package/dist/commands/utils/save-bundle-and-map.js +80 -0
  50. package/dist/commands/utils/save-bundle-and-map.mjs +33 -0
  51. package/dist/index.d.ts +2 -0
  52. package/dist/index.js +44 -0
  53. package/dist/index.mjs +3 -0
  54. package/dist/logger.d.ts +2 -0
  55. package/dist/logger.js +43 -0
  56. package/dist/logger.mjs +6 -0
  57. package/dist/modules/HMRClient.ts +31 -0
  58. package/dist/modules/HMRClientShim.ts +1 -0
  59. package/dist/modules/asyncRequire.ts +156 -0
  60. package/dist/modules/asyncStartup.tsx +43 -0
  61. package/dist/modules/getDevServer.ts +15 -0
  62. package/dist/modules/metroCorePlugin.ts +87 -0
  63. package/dist/plugin/babel-transformer.d.ts +11 -0
  64. package/dist/plugin/babel-transformer.js +72 -0
  65. package/dist/plugin/babel-transformer.mjs +25 -0
  66. package/dist/plugin/constants.d.ts +10 -0
  67. package/dist/plugin/constants.js +76 -0
  68. package/dist/plugin/constants.mjs +12 -0
  69. package/dist/plugin/generators.d.ts +13 -0
  70. package/dist/plugin/generators.js +164 -0
  71. package/dist/plugin/generators.mjs +102 -0
  72. package/dist/plugin/helpers.d.ts +8 -0
  73. package/dist/plugin/helpers.js +127 -0
  74. package/dist/plugin/helpers.mjs +58 -0
  75. package/dist/plugin/index.d.ts +11 -0
  76. package/dist/plugin/index.js +219 -0
  77. package/dist/plugin/index.mjs +172 -0
  78. package/dist/plugin/manifest-middleware.d.ts +12 -0
  79. package/dist/plugin/manifest-middleware.js +217 -0
  80. package/dist/plugin/manifest-middleware.mjs +170 -0
  81. package/dist/plugin/manifest.d.ts +16 -0
  82. package/dist/plugin/manifest.js +246 -0
  83. package/dist/plugin/manifest.mjs +185 -0
  84. package/dist/plugin/normalize-extra-options.d.ts +8 -0
  85. package/dist/plugin/normalize-extra-options.js +50 -0
  86. package/dist/plugin/normalize-extra-options.mjs +13 -0
  87. package/dist/plugin/normalize-options.d.ts +7 -0
  88. package/dist/plugin/normalize-options.js +139 -0
  89. package/dist/plugin/normalize-options.mjs +92 -0
  90. package/dist/plugin/resolver.d.ts +26 -0
  91. package/dist/plugin/resolver.js +203 -0
  92. package/dist/plugin/resolver.mjs +159 -0
  93. package/dist/plugin/rewrite-request.d.ts +14 -0
  94. package/dist/plugin/rewrite-request.js +89 -0
  95. package/dist/plugin/rewrite-request.mjs +42 -0
  96. package/dist/plugin/serializer.d.ts +6 -0
  97. package/dist/plugin/serializer.js +191 -0
  98. package/dist/plugin/serializer.mjs +144 -0
  99. package/dist/plugin/validate-options.d.ts +2 -0
  100. package/dist/plugin/validate-options.js +165 -0
  101. package/dist/plugin/validate-options.mjs +117 -0
  102. package/dist/runtime/host-entry.js +3 -0
  103. package/dist/runtime/init-host.js +31 -0
  104. package/dist/runtime/remote-entry.js +57 -0
  105. package/dist/runtime/remote-hmr.js +19 -0
  106. package/dist/runtime/remote-module-registry.js +57 -0
  107. package/dist/runtime/remote-module.js +2 -0
  108. package/dist/types.d.ts +26 -0
  109. package/dist/types.js +18 -0
  110. package/dist/types.mjs +1 -0
  111. package/dist/utils/errors.d.ts +8 -0
  112. package/dist/utils/errors.js +54 -0
  113. package/dist/utils/errors.mjs +14 -0
  114. package/dist/utils/federated-remote-types.d.ts +12 -0
  115. package/dist/utils/federated-remote-types.js +140 -0
  116. package/dist/utils/federated-remote-types.mjs +90 -0
  117. package/dist/utils/index.d.ts +2 -0
  118. package/dist/utils/index.js +47 -0
  119. package/dist/utils/index.mjs +3 -0
  120. package/dist/utils/metro-compat.d.ts +23 -0
  121. package/dist/utils/metro-compat.js +74 -0
  122. package/dist/utils/metro-compat.mjs +26 -0
  123. package/dist/utils/vm-manager.d.ts +21 -0
  124. package/dist/utils/vm-manager.js +118 -0
  125. package/dist/utils/vm-manager.mjs +70 -0
  126. package/package.json +106 -0
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ var __webpack_require__ = {};
3
+ (()=>{
4
+ __webpack_require__.d = (exports1, getters, values)=>{
5
+ var define = (defs, kind)=>{
6
+ for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
7
+ enumerable: true,
8
+ [kind]: defs[key]
9
+ });
10
+ };
11
+ define(getters, "get");
12
+ define(values, "value");
13
+ };
14
+ })();
15
+ (()=>{
16
+ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
17
+ })();
18
+ (()=>{
19
+ __webpack_require__.r = (exports1)=>{
20
+ if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
21
+ value: 'Module'
22
+ });
23
+ Object.defineProperty(exports1, '__esModule', {
24
+ value: true
25
+ });
26
+ };
27
+ })();
28
+ var __webpack_exports__ = {};
29
+ __webpack_require__.r(__webpack_exports__);
30
+ __webpack_require__.d(__webpack_exports__, {
31
+ normalizeOutputRelativePath: ()=>normalizeOutputRelativePath,
32
+ toFileSourceUrl: ()=>toFileSourceUrl
33
+ });
34
+ const external_node_url_namespaceObject = require("node:url");
35
+ const helpers_js_namespaceObject = require("../../plugin/helpers.js");
36
+ function normalizeOutputRelativePath(relativePath) {
37
+ return (0, helpers_js_namespaceObject.toPosixPath)(relativePath);
38
+ }
39
+ function toFileSourceUrl(relativePath) {
40
+ const normalizedRelativePath = normalizeOutputRelativePath(relativePath);
41
+ return (0, external_node_url_namespaceObject.pathToFileURL)(`/${normalizedRelativePath}`).href;
42
+ }
43
+ exports.normalizeOutputRelativePath = __webpack_exports__.normalizeOutputRelativePath;
44
+ exports.toFileSourceUrl = __webpack_exports__.toFileSourceUrl;
45
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
46
+ "normalizeOutputRelativePath",
47
+ "toFileSourceUrl"
48
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
49
+ Object.defineProperty(exports, '__esModule', {
50
+ value: true
51
+ });
@@ -0,0 +1,11 @@
1
+ import "node:module";
2
+ import { pathToFileURL } from "node:url";
3
+ import { toPosixPath } from "../../plugin/helpers.mjs";
4
+ function normalizeOutputRelativePath(relativePath) {
5
+ return toPosixPath(relativePath);
6
+ }
7
+ function toFileSourceUrl(relativePath) {
8
+ const normalizedRelativePath = normalizeOutputRelativePath(relativePath);
9
+ return pathToFileURL(`/${normalizedRelativePath}`).href;
10
+ }
11
+ export { normalizeOutputRelativePath, toFileSourceUrl };
@@ -0,0 +1,5 @@
1
+ import type { OutputOptions } from '../../utils/metro-compat';
2
+ export declare function saveBundleAndMap(bundle: {
3
+ code: string;
4
+ map: string;
5
+ }, options: OutputOptions, log: (msg: string) => void): Promise<void>;
@@ -0,0 +1,80 @@
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
+ saveBundleAndMap: ()=>saveBundleAndMap
41
+ });
42
+ const external_node_fs_namespaceObject = require("node:fs");
43
+ const external_node_util_namespaceObject = require("node:util");
44
+ var external_node_util_default = /*#__PURE__*/ __webpack_require__.n(external_node_util_namespaceObject);
45
+ const metro_compat_js_namespaceObject = require("../../utils/metro-compat.js");
46
+ function relativizeSerializedMap(map, sourceMapSourcesRoot) {
47
+ const sourceMap = JSON.parse(map);
48
+ (0, metro_compat_js_namespaceObject.relativizeSourceMapInline)(sourceMap, sourceMapSourcesRoot);
49
+ return JSON.stringify(sourceMap);
50
+ }
51
+ async function saveBundleAndMap(bundle, options, log) {
52
+ const { bundleOutput, bundleEncoding: encoding, sourcemapOutput, sourcemapSourcesRoot } = options;
53
+ const writeFns = [];
54
+ writeFns.push(async ()=>{
55
+ log(`Writing bundle output to:\n${external_node_util_default().styleText('dim', bundleOutput)}`);
56
+ await external_node_fs_namespaceObject.promises.writeFile(bundleOutput, bundle.code, encoding);
57
+ log('Done writing bundle output');
58
+ });
59
+ if (sourcemapOutput) {
60
+ let { map } = bundle;
61
+ if (null != sourcemapSourcesRoot) {
62
+ log('Start relativating source map');
63
+ map = relativizeSerializedMap(map, sourcemapSourcesRoot);
64
+ log('Finished relativating');
65
+ }
66
+ writeFns.push(async ()=>{
67
+ log(`Writing sourcemap output to:\n${external_node_util_default().styleText('dim', sourcemapOutput)}`);
68
+ await external_node_fs_namespaceObject.promises.writeFile(sourcemapOutput, map);
69
+ log('Done writing sourcemap output');
70
+ });
71
+ }
72
+ await Promise.all(writeFns.map((cb)=>cb()));
73
+ }
74
+ exports.saveBundleAndMap = __webpack_exports__.saveBundleAndMap;
75
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
76
+ "saveBundleAndMap"
77
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
78
+ Object.defineProperty(exports, '__esModule', {
79
+ value: true
80
+ });
@@ -0,0 +1,33 @@
1
+ import "node:module";
2
+ import { promises } from "node:fs";
3
+ import node_util from "node:util";
4
+ import { relativizeSourceMapInline } from "../../utils/metro-compat.mjs";
5
+ function relativizeSerializedMap(map, sourceMapSourcesRoot) {
6
+ const sourceMap = JSON.parse(map);
7
+ relativizeSourceMapInline(sourceMap, sourceMapSourcesRoot);
8
+ return JSON.stringify(sourceMap);
9
+ }
10
+ async function saveBundleAndMap(bundle, options, log) {
11
+ const { bundleOutput, bundleEncoding: encoding, sourcemapOutput, sourcemapSourcesRoot } = options;
12
+ const writeFns = [];
13
+ writeFns.push(async ()=>{
14
+ log(`Writing bundle output to:\n${node_util.styleText('dim', bundleOutput)}`);
15
+ await promises.writeFile(bundleOutput, bundle.code, encoding);
16
+ log('Done writing bundle output');
17
+ });
18
+ if (sourcemapOutput) {
19
+ let { map } = bundle;
20
+ if (null != sourcemapSourcesRoot) {
21
+ log('Start relativating source map');
22
+ map = relativizeSerializedMap(map, sourcemapSourcesRoot);
23
+ log('Finished relativating');
24
+ }
25
+ writeFns.push(async ()=>{
26
+ log(`Writing sourcemap output to:\n${node_util.styleText('dim', sourcemapOutput)}`);
27
+ await promises.writeFile(sourcemapOutput, map);
28
+ log('Done writing sourcemap output');
29
+ });
30
+ }
31
+ await Promise.all(writeFns.map((cb)=>cb()));
32
+ }
33
+ export { saveBundleAndMap };
@@ -0,0 +1,2 @@
1
+ export { withModuleFederation } from './plugin';
2
+ export { updateManifest } from './plugin/manifest';
package/dist/index.js ADDED
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ var __webpack_require__ = {};
3
+ (()=>{
4
+ __webpack_require__.d = (exports1, getters, values)=>{
5
+ var define = (defs, kind)=>{
6
+ for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
7
+ enumerable: true,
8
+ [kind]: defs[key]
9
+ });
10
+ };
11
+ define(getters, "get");
12
+ define(values, "value");
13
+ };
14
+ })();
15
+ (()=>{
16
+ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
17
+ })();
18
+ (()=>{
19
+ __webpack_require__.r = (exports1)=>{
20
+ if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
21
+ value: 'Module'
22
+ });
23
+ Object.defineProperty(exports1, '__esModule', {
24
+ value: true
25
+ });
26
+ };
27
+ })();
28
+ var __webpack_exports__ = {};
29
+ __webpack_require__.r(__webpack_exports__);
30
+ __webpack_require__.d(__webpack_exports__, {
31
+ updateManifest: ()=>manifest_js_namespaceObject.updateManifest,
32
+ withModuleFederation: ()=>index_js_namespaceObject.withModuleFederation
33
+ });
34
+ const index_js_namespaceObject = require("./plugin/index.js");
35
+ const manifest_js_namespaceObject = require("./plugin/manifest.js");
36
+ exports.updateManifest = __webpack_exports__.updateManifest;
37
+ exports.withModuleFederation = __webpack_exports__.withModuleFederation;
38
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
39
+ "updateManifest",
40
+ "withModuleFederation"
41
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
42
+ Object.defineProperty(exports, '__esModule', {
43
+ value: true
44
+ });
package/dist/index.mjs ADDED
@@ -0,0 +1,3 @@
1
+ import "node:module";
2
+ export { withModuleFederation } from "./plugin/index.mjs";
3
+ export { updateManifest } from "./plugin/manifest.mjs";
@@ -0,0 +1,2 @@
1
+ declare const logger: import("@module-federation/sdk").Logger;
2
+ export default logger;
package/dist/logger.js ADDED
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ var __webpack_require__ = {};
3
+ (()=>{
4
+ __webpack_require__.d = (exports1, getters, values)=>{
5
+ var define = (defs, kind)=>{
6
+ for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
7
+ enumerable: true,
8
+ [kind]: defs[key]
9
+ });
10
+ };
11
+ define(getters, "get");
12
+ define(values, "value");
13
+ };
14
+ })();
15
+ (()=>{
16
+ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
17
+ })();
18
+ (()=>{
19
+ __webpack_require__.r = (exports1)=>{
20
+ if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
21
+ value: 'Module'
22
+ });
23
+ Object.defineProperty(exports1, '__esModule', {
24
+ value: true
25
+ });
26
+ };
27
+ })();
28
+ var __webpack_exports__ = {};
29
+ __webpack_require__.r(__webpack_exports__);
30
+ __webpack_require__.d(__webpack_exports__, {
31
+ default: ()=>src_logger
32
+ });
33
+ const sdk_namespaceObject = require("@module-federation/sdk");
34
+ const constants_js_namespaceObject = require("./plugin/constants.js");
35
+ const logger = (0, sdk_namespaceObject.createLogger)(constants_js_namespaceObject.PLUGIN_IDENTIFIER);
36
+ const src_logger = logger;
37
+ exports["default"] = __webpack_exports__["default"];
38
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
39
+ "default"
40
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
41
+ Object.defineProperty(exports, '__esModule', {
42
+ value: true
43
+ });
@@ -0,0 +1,6 @@
1
+ import "node:module";
2
+ import { createLogger } from "@module-federation/sdk";
3
+ import { PLUGIN_IDENTIFIER } from "./plugin/constants.mjs";
4
+ const logger = createLogger(PLUGIN_IDENTIFIER);
5
+ const src_logger = logger;
6
+ export default src_logger;
@@ -0,0 +1,31 @@
1
+ import HMRClient from 'react-native/Libraries/Utilities/HMRClient';
2
+
3
+ let hmrOrigin: string | null = null;
4
+
5
+ const originalRegisterBundle = HMRClient.registerBundle;
6
+ const originalSetup = HMRClient.setup;
7
+
8
+ HMRClient.setup = (
9
+ platform: string,
10
+ bundleEntry: string,
11
+ host: string,
12
+ port: number | string,
13
+ isEnabled: boolean,
14
+ scheme = 'http',
15
+ ) => {
16
+ const serverHost = port !== null && port !== '' ? `${host}:${port}` : host;
17
+ hmrOrigin = `${scheme}://${serverHost}`;
18
+
19
+ return originalSetup(platform, bundleEntry, host, port, isEnabled, scheme);
20
+ };
21
+
22
+ HMRClient.registerBundle = (requestUrl: string) => {
23
+ // only process registerBundle calls from the same origin
24
+ if (!requestUrl.includes(hmrOrigin as string)) {
25
+ return;
26
+ }
27
+
28
+ return originalRegisterBundle(requestUrl);
29
+ };
30
+
31
+ export default HMRClient;
@@ -0,0 +1 @@
1
+ export { default } from 'react-native/Libraries/Utilities/HMRClientProdShim';
@@ -0,0 +1,156 @@
1
+ // join two paths
2
+ // e.g. /a/b/ + /c/d -> /a/b/c/d
3
+ function joinComponents(prefix: string, suffix: string) {
4
+ return prefix.replace(/\/+$/, '') + '/' + suffix.replace(/^\/+/, '');
5
+ }
6
+
7
+ // get the public path from the url
8
+ // e.g. http://host:8081/a/b.bundle -> http://host:8081/a
9
+ function getPublicPath(url?: string) {
10
+ return url?.split('/').slice(0, -1).join('/');
11
+ }
12
+
13
+ function isUrl(url: string) {
14
+ return url.match(/^https?:\/\//);
15
+ }
16
+
17
+ // get bundle id from the bundle path
18
+ // e.g. /a/b.bundle?platform=ios -> a/b
19
+ // e.g. http://host:8081/a/b.bundle -> a/b
20
+ function getBundleId(bundlePath: string, publicPath: string) {
21
+ let path = bundlePath;
22
+ // remove the public path if it's an url
23
+ if (isUrl(path)) {
24
+ path = path.replace(publicPath, '');
25
+ }
26
+ // remove the leading slash
27
+ if (path.startsWith('/')) {
28
+ path = path.slice(1);
29
+ }
30
+ // remove the query params and normalize Windows separators
31
+ path = path.split('?')[0].replaceAll('\\', '/');
32
+ // remove the bundle extension
33
+ return path.replace('.bundle', '');
34
+ }
35
+
36
+ function isSameOrigin(url: string, originPublicPath?: string) {
37
+ // if it's not a fully qualified url, we assume it's the same origin
38
+ if (!isUrl(url)) {
39
+ return true;
40
+ }
41
+ return !!originPublicPath && url.startsWith(originPublicPath);
42
+ }
43
+
44
+ // prefix the bundle path with the public path
45
+ // e.g. /a/b.bundle -> http://host:8081/a/b.bundle
46
+ function getBundlePath(bundlePath: string, bundleOrigin?: string) {
47
+ // don't modify the path in development
48
+ if (process.env.NODE_ENV !== 'production') {
49
+ return bundlePath;
50
+ }
51
+ // don't modify fully qualified urls
52
+ // e.g. when loading container modules
53
+ if (isUrl(bundlePath)) {
54
+ return bundlePath;
55
+ }
56
+ // don't modify the path if we don't know the bundle origin
57
+ // e.g. when loading host split bundles
58
+ if (!bundleOrigin) {
59
+ return bundlePath;
60
+ }
61
+ return joinComponents(bundleOrigin, bundlePath);
62
+ }
63
+
64
+ function buildLoadBundleAsyncWrapper() {
65
+ const registry = require('mf:remote-module-registry');
66
+
67
+ const __loadBundleAsync =
68
+ globalThis[`${__METRO_GLOBAL_PREFIX__ ?? ''}__loadBundleAsync`];
69
+
70
+ const loadBundleAsync =
71
+ __loadBundleAsync as typeof globalThis.__loadBundleAsync;
72
+
73
+ return async (originalBundlePath: string): Promise<void> => {
74
+ const scope = globalThis.__FEDERATION__.__NATIVE__[__METRO_GLOBAL_PREFIX__];
75
+
76
+ // entry is always in the root directory of assets associated with remote
77
+ // based on that, we extract the public path from the origin URL
78
+ // e.g. http://example.com/a/b/c/mf-manfiest.json -> http://example.com/a/b/c
79
+ const publicPath = getPublicPath(scope.origin);
80
+ let bundlePath = getBundlePath(originalBundlePath, publicPath);
81
+
82
+ const isSplitBundle = !isUrl(originalBundlePath);
83
+
84
+ // Cache handler registered externally (e.g. by zephyr-native-cache register()).
85
+ // Stored under __FEDERATION__.__NATIVE__.__CACHE__ as a singleton (no prefix scope).
86
+ const cacheHandler = (globalThis as any).__FEDERATION__?.__NATIVE__
87
+ ?.__CACHE__ as
88
+ | ((
89
+ fallback: (path: string) => Promise<void>,
90
+ bundlePath: string,
91
+ ) => Promise<void>)
92
+ | undefined;
93
+
94
+ // For remote split bundles with cache enabled, convert relative paths to
95
+ // full URLs so they enter the same cache path as container bundles.
96
+ // In dev mode, getBundlePath returns relative paths unchanged, but we need
97
+ // full URLs for the cache layer (download + eval).
98
+ if (isSplitBundle && cacheHandler && publicPath && !isUrl(bundlePath)) {
99
+ bundlePath = joinComponents(publicPath, bundlePath);
100
+ }
101
+
102
+ // ../../node_modules/ -> ..%2F..%2Fnode_modules/ so that it's not automatically sanitized
103
+ const encodedBundlePath = bundlePath.replaceAll('../', '..%2F');
104
+
105
+ let result;
106
+ if (cacheHandler) {
107
+ await cacheHandler(loadBundleAsync, encodedBundlePath);
108
+ } else {
109
+ result = await loadBundleAsync(encodedBundlePath);
110
+ }
111
+
112
+ // when the origin is not the same, it means we are loading a remote container
113
+ // we can return early since dependencies are processed differently for entry bundles
114
+ if (!isSameOrigin(bundlePath, publicPath)) {
115
+ return result;
116
+ }
117
+
118
+ // at this point the code in the bundle has been evaluated
119
+ // but not yet executed through metroRequire
120
+ // note: at this point, public path is always defined
121
+ const bundleId = getBundleId(bundlePath, publicPath!);
122
+ const shared = scope.deps.shared[bundleId];
123
+ const remotes = scope.deps.remotes[bundleId];
124
+
125
+ const promises = [];
126
+ if (shared && shared.length > 0) {
127
+ // load shared used synchronously in the bundle
128
+ promises.push(...shared.map(registry.loadSharedToRegistry));
129
+ }
130
+ if (remotes && remotes.length > 0) {
131
+ // load remotes used synchronously in the bundle
132
+ promises.push(...remotes.map(registry.loadRemoteToRegistry));
133
+ }
134
+
135
+ await Promise.all(promises);
136
+
137
+ return result;
138
+ };
139
+ }
140
+
141
+ // load expo async require if outside expo
142
+ if (!process.env.EXPO_OS) {
143
+ // @expo/metro-runtime/src/async-require/fetchAsync.native.ts requires
144
+ // process.env.EXPO_OS to be set but since expo is optional, we set it
145
+ // to an empty string as a fallback to prevent reference errors
146
+ process.env.EXPO_OS = '';
147
+
148
+ const {
149
+ buildAsyncRequire,
150
+ } = require('@expo/metro-runtime/src/async-require/buildAsyncRequire');
151
+
152
+ global[`${__METRO_GLOBAL_PREFIX__}__loadBundleAsync`] = buildAsyncRequire();
153
+ }
154
+
155
+ global[`${__METRO_GLOBAL_PREFIX__}__loadBundleAsync`] =
156
+ buildLoadBundleAsyncWrapper();
@@ -0,0 +1,43 @@
1
+ import type { Federation } from '@module-federation/runtime';
2
+ import React from 'react';
3
+
4
+ declare global {
5
+ // eslint-disable-next-line no-var
6
+ var __DEV__: boolean;
7
+ // eslint-disable-next-line no-var
8
+ var __METRO_GLOBAL_PREFIX__: string;
9
+ // eslint-disable-next-line no-var
10
+ var __FUSEBOX_HAS_FULL_CONSOLE_SUPPORT__: boolean;
11
+ // eslint-disable-next-line no-var
12
+ var __loadBundleAsync: (entry: string) => Promise<void>;
13
+ // eslint-disable-next-line no-var
14
+ var __FEDERATION__: Federation;
15
+ }
16
+
17
+ type LazyComponent = { default: React.ComponentType };
18
+
19
+ function getFallbackComponent(lazyFallbackFn?: () => LazyComponent) {
20
+ if (!lazyFallbackFn) return () => null;
21
+ const fallback = lazyFallbackFn();
22
+ return fallback.default;
23
+ }
24
+
25
+ export function withAsyncStartup(
26
+ lazyAppFn: () => LazyComponent,
27
+ lazyFallbackFn?: () => LazyComponent,
28
+ ): () => () => React.JSX.Element {
29
+ const AppComponent = React.lazy(async () => {
30
+ await globalThis.__FEDERATION__.__NATIVE__[__METRO_GLOBAL_PREFIX__].init;
31
+ return lazyAppFn();
32
+ });
33
+
34
+ const FallbackComponent = getFallbackComponent(lazyFallbackFn);
35
+
36
+ return () => () => {
37
+ return (
38
+ <React.Suspense fallback={<FallbackComponent />}>
39
+ <AppComponent />
40
+ </React.Suspense>
41
+ );
42
+ };
43
+ }
@@ -0,0 +1,15 @@
1
+ export default function getDevServer() {
2
+ const scriptUrl =
3
+ globalThis.__FEDERATION__.__NATIVE__[__METRO_GLOBAL_PREFIX__].origin;
4
+
5
+ if (!scriptUrl) {
6
+ throw new Error(
7
+ `Cannot determine dev server URL for ${__METRO_GLOBAL_PREFIX__} remote`,
8
+ );
9
+ }
10
+
11
+ return {
12
+ url: scriptUrl.match(/^https?:\/\/.*?\//)![0],
13
+ fullBundleUrl: scriptUrl,
14
+ };
15
+ }
@@ -0,0 +1,87 @@
1
+ import type {
2
+ Federation,
3
+ ModuleFederationRuntimePlugin,
4
+ } from '@module-federation/runtime';
5
+
6
+ declare global {
7
+ // eslint-disable-next-line no-var
8
+ var __DEV__: boolean;
9
+ // eslint-disable-next-line no-var
10
+ var __METRO_GLOBAL_PREFIX__: string;
11
+ // eslint-disable-next-line no-var
12
+ var __FUSEBOX_HAS_FULL_CONSOLE_SUPPORT__: boolean;
13
+ // eslint-disable-next-line no-var
14
+ var __loadBundleAsync: (entry: string) => Promise<void>;
15
+ // eslint-disable-next-line no-var
16
+ var __FEDERATION__: Federation;
17
+ }
18
+
19
+ const getQueryParams = () => {
20
+ const isFuseboxEnabled = !!globalThis.__FUSEBOX_HAS_FULL_CONSOLE_SUPPORT__;
21
+ const queryParams: Record<string, string> = {
22
+ platform: require('react-native').Platform.OS,
23
+ dev: 'true',
24
+ lazy: 'true',
25
+ minify: 'false',
26
+ runModule: 'true',
27
+ modulesOnly: 'false',
28
+ };
29
+
30
+ if (isFuseboxEnabled) {
31
+ queryParams.excludeSource = 'true';
32
+ queryParams.sourcePaths = 'url-server';
33
+ }
34
+
35
+ return new URLSearchParams(queryParams);
36
+ };
37
+
38
+ const buildUrlForEntryBundle = (entry: string) => {
39
+ if (__DEV__) {
40
+ return `${entry}?${getQueryParams().toString()}`;
41
+ }
42
+ return entry;
43
+ };
44
+
45
+ const MetroCorePlugin: () => ModuleFederationRuntimePlugin = () => ({
46
+ name: 'metro-core-plugin',
47
+ loadEntry: async ({ remoteInfo }) => {
48
+ const { entry, entryGlobalName } = remoteInfo;
49
+
50
+ const __loadBundleAsync =
51
+ globalThis[`${__METRO_GLOBAL_PREFIX__ ?? ''}__loadBundleAsync`];
52
+
53
+ const loadBundleAsync =
54
+ __loadBundleAsync as typeof globalThis.__loadBundleAsync;
55
+
56
+ if (!loadBundleAsync) {
57
+ throw new Error('loadBundleAsync is not defined');
58
+ }
59
+
60
+ try {
61
+ const entryUrl = buildUrlForEntryBundle(entry);
62
+ await loadBundleAsync(entryUrl);
63
+
64
+ if (!globalThis.__FEDERATION__.__NATIVE__[entryGlobalName]) {
65
+ throw new Error(`Remote entry ${entryGlobalName} failed to register.`);
66
+ }
67
+
68
+ globalThis.__FEDERATION__.__NATIVE__[entryGlobalName].origin = entryUrl;
69
+
70
+ return globalThis.__FEDERATION__.__NATIVE__[entryGlobalName].exports;
71
+ } catch (error) {
72
+ throw new Error(
73
+ `Failed to load remote entry: ${entryGlobalName}. Reason: ${error}`,
74
+ );
75
+ }
76
+ },
77
+ generatePreloadAssets: async () => {
78
+ // noop for compatibility
79
+ return Promise.resolve({
80
+ cssAssets: [],
81
+ jsAssetsWithoutEntry: [],
82
+ entryAssets: [],
83
+ });
84
+ },
85
+ });
86
+
87
+ export default MetroCorePlugin;
@@ -0,0 +1,11 @@
1
+ import type { ModuleFederationConfigNormalized } from '../types';
2
+ interface CreateBabelTransformerOptions {
3
+ blacklistedPaths: string[];
4
+ federationConfig: ModuleFederationConfigNormalized;
5
+ originalBabelTransformerPath: string;
6
+ tmpDirPath: string;
7
+ enableInitializeCorePatching: boolean;
8
+ enableRuntimeRequirePatching: boolean;
9
+ }
10
+ export declare function createBabelTransformer({ blacklistedPaths, federationConfig, originalBabelTransformerPath, tmpDirPath, enableInitializeCorePatching, enableRuntimeRequirePatching, }: CreateBabelTransformerOptions): string;
11
+ export {};