@module-federation/metro 0.0.0-docs-remove-invalid-lark-link-20251205062649

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 +43 -0
  56. package/dist/modules/getDevServer.ts +15 -0
  57. package/dist/modules/metroCorePlugin.ts +88 -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,171 @@
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
+ getModuleFederationSerializer: ()=>getModuleFederationSerializer
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 baseJSBundle_namespaceObject = require("metro/src/DeltaBundler/Serializers/baseJSBundle");
41
+ var baseJSBundle_default = /*#__PURE__*/ __webpack_require__.n(baseJSBundle_namespaceObject);
42
+ const CountingSet_namespaceObject = require("metro/src/lib/CountingSet");
43
+ var CountingSet_default = /*#__PURE__*/ __webpack_require__.n(CountingSet_namespaceObject);
44
+ const bundleToString_namespaceObject = require("metro/src/lib/bundleToString");
45
+ var bundleToString_default = /*#__PURE__*/ __webpack_require__.n(bundleToString_namespaceObject);
46
+ const errors_js_namespaceObject = require("../utils/errors.js");
47
+ function getModuleFederationSerializer(mfConfig, isUsingMFBundleCommand) {
48
+ return async (entryPoint, preModules, graph, options)=>{
49
+ const syncRemoteModules = collectSyncRemoteModules(graph, mfConfig.remotes);
50
+ const syncSharedModules = collectSyncSharedModules(graph, mfConfig.shared);
51
+ if (true === options.runModule) {
52
+ const finalPreModules = [
53
+ getEarlyShared(syncSharedModules),
54
+ getEarlyRemotes(syncRemoteModules),
55
+ ...preModules
56
+ ];
57
+ return getBundleCode(entryPoint, finalPreModules, graph, options);
58
+ }
59
+ if (!isProjectSource(entryPoint, options.projectRoot)) return getBundleCode(entryPoint, preModules, graph, options);
60
+ const bundlePath = getBundlePath(entryPoint, options.projectRoot, mfConfig.exposes, isUsingMFBundleCommand);
61
+ const finalPreModules = [
62
+ getSyncShared(syncSharedModules, bundlePath, mfConfig.name),
63
+ getSyncRemotes(syncRemoteModules, bundlePath, mfConfig.name)
64
+ ];
65
+ if (false === options.modulesOnly) finalPreModules.push(...preModules);
66
+ const finalOptions = {
67
+ ...options,
68
+ modulesOnly: false
69
+ };
70
+ return getBundleCode(entryPoint, finalPreModules, graph, finalOptions);
71
+ };
72
+ }
73
+ function collectSyncRemoteModules(graph, _remotes) {
74
+ const remotes = new Set(Object.keys(_remotes));
75
+ const syncRemoteModules = new Set();
76
+ for (const [, module] of graph.dependencies)for (const dependency of module.dependencies.values()){
77
+ if (null !== dependency.data.data.asyncType) continue;
78
+ const remoteCandidate = dependency.data.name.split('/')[0];
79
+ const isValidCandidate = remoteCandidate.length < dependency.data.name.length;
80
+ if (isValidCandidate && remotes.has(remoteCandidate)) syncRemoteModules.add(dependency.data.name);
81
+ }
82
+ return Array.from(syncRemoteModules);
83
+ }
84
+ function collectSyncSharedModules(graph, _shared) {
85
+ const sharedImports = new Set(Object.keys(_shared).map((sharedName)=>_shared[sharedName].import || sharedName));
86
+ const syncSharedModules = new Set([
87
+ 'react',
88
+ 'react-native'
89
+ ]);
90
+ for (const [, module] of graph.dependencies)for (const dependency of module.dependencies.values())if (null === dependency.data.data.asyncType) {
91
+ if (!module.path.endsWith('init-host.js')) {
92
+ if (sharedImports.has(dependency.data.name)) syncSharedModules.add(dependency.data.name);
93
+ }
94
+ }
95
+ return Array.from(syncSharedModules);
96
+ }
97
+ function getFederationSharedDependenciesNamespace(scope) {
98
+ return `globalThis.__FEDERATION__.__NATIVE__["${scope}"].deps.shared`;
99
+ }
100
+ function getFederationRemotesDependenciesNamespace(scope) {
101
+ return `globalThis.__FEDERATION__.__NATIVE__["${scope}"].deps.remotes`;
102
+ }
103
+ function getSyncShared(shared, entry, scope) {
104
+ const namespace = getFederationSharedDependenciesNamespace(scope);
105
+ const code = `${namespace}["${entry}"]=${JSON.stringify(shared)};`;
106
+ return generateVirtualModule('__required_shared__', code);
107
+ }
108
+ function getSyncRemotes(remotes, entry, scope) {
109
+ const namespace = getFederationRemotesDependenciesNamespace(scope);
110
+ const code = `${namespace}["${entry}"]=${JSON.stringify(remotes)};`;
111
+ return generateVirtualModule('__required_remotes__', code);
112
+ }
113
+ function getEarlyShared(shared) {
114
+ const code = `var __EARLY_SHARED__=${JSON.stringify(shared)};`;
115
+ return generateVirtualModule('__early_shared__', code);
116
+ }
117
+ function getEarlyRemotes(remotes) {
118
+ const code = `var __EARLY_REMOTES__=${JSON.stringify(remotes)};`;
119
+ return generateVirtualModule('__early_remotes__', code);
120
+ }
121
+ function generateVirtualModule(name, code) {
122
+ return {
123
+ dependencies: new Map(),
124
+ getSource: ()=>Buffer.from(code),
125
+ inverseDependencies: new (CountingSet_default())(),
126
+ path: name,
127
+ output: [
128
+ {
129
+ type: "js/script/virtual",
130
+ data: {
131
+ code,
132
+ lineCount: 1,
133
+ map: []
134
+ }
135
+ }
136
+ ]
137
+ };
138
+ }
139
+ function isProjectSource(entryPoint, projectRoot) {
140
+ const relativePath = external_node_path_default().relative(projectRoot, entryPoint);
141
+ return !relativePath.startsWith('..') && !relativePath.startsWith('node_modules');
142
+ }
143
+ function getBundlePath(entryPoint, projectRoot, exposes, isUsingMFBundleCommand) {
144
+ const relativeEntryPath = external_node_path_default().relative(projectRoot, entryPoint);
145
+ if (!isUsingMFBundleCommand) {
146
+ const { dir, name } = external_node_path_default().parse(relativeEntryPath);
147
+ return external_node_path_default().format({
148
+ dir,
149
+ name,
150
+ ext: ''
151
+ });
152
+ }
153
+ const exposedMatchedKey = Object.keys(exposes).find((exposeKey)=>exposes[exposeKey].match(relativeEntryPath));
154
+ if (exposedMatchedKey) {
155
+ let exposedName = exposedMatchedKey;
156
+ if (exposedName.startsWith('./')) exposedName = exposedName.slice(2);
157
+ return `exposed/${exposedName}`;
158
+ }
159
+ throw new errors_js_namespaceObject.ConfigError(`Unable to handle entry point: ${relativeEntryPath}. Expected to match an entrypoint with one of the exposed keys, but failed. This is most likely a configuration error. If you believe this is not a configuration issue, please report it as a bug. Debug info: entryPoint="${entryPoint}", projectRoot="${projectRoot}", exposesKeys=[${Object.keys(exposes).join(', ')}]`);
160
+ }
161
+ function getBundleCode(entryPoint, preModules, graph, options) {
162
+ const { code } = bundleToString_default()(baseJSBundle_default()(entryPoint, preModules, graph, options));
163
+ return code;
164
+ }
165
+ exports.getModuleFederationSerializer = __webpack_exports__.getModuleFederationSerializer;
166
+ for(var __webpack_i__ in __webpack_exports__)if (-1 === [
167
+ "getModuleFederationSerializer"
168
+ ].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
169
+ Object.defineProperty(exports, '__esModule', {
170
+ value: true
171
+ });
@@ -0,0 +1,151 @@
1
+ import 'module';
2
+ /*#__PURE__*/ import.meta.url;
3
+ import node_path from "node:path";
4
+ import { ConfigError } from "../utils/errors.mjs";
5
+ import { createRequire as __WEBPACK_EXTERNAL_createRequire } from "node:module";
6
+ var __webpack_require__ = {};
7
+ (()=>{
8
+ __webpack_require__.n = (module)=>{
9
+ var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
10
+ __webpack_require__.d(getter, {
11
+ a: getter
12
+ });
13
+ return getter;
14
+ };
15
+ })();
16
+ (()=>{
17
+ __webpack_require__.d = (exports, definition)=>{
18
+ for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) Object.defineProperty(exports, key, {
19
+ enumerable: true,
20
+ get: definition[key]
21
+ });
22
+ };
23
+ })();
24
+ (()=>{
25
+ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
26
+ })();
27
+ const baseJSBundle_namespaceObject = __WEBPACK_EXTERNAL_createRequire(import.meta.url)("metro/src/DeltaBundler/Serializers/baseJSBundle");
28
+ var baseJSBundle_default = /*#__PURE__*/ __webpack_require__.n(baseJSBundle_namespaceObject);
29
+ const CountingSet_namespaceObject = __WEBPACK_EXTERNAL_createRequire(import.meta.url)("metro/src/lib/CountingSet");
30
+ var CountingSet_default = /*#__PURE__*/ __webpack_require__.n(CountingSet_namespaceObject);
31
+ const bundleToString_namespaceObject = __WEBPACK_EXTERNAL_createRequire(import.meta.url)("metro/src/lib/bundleToString");
32
+ var bundleToString_default = /*#__PURE__*/ __webpack_require__.n(bundleToString_namespaceObject);
33
+ function getModuleFederationSerializer(mfConfig, isUsingMFBundleCommand) {
34
+ return async (entryPoint, preModules, graph, options)=>{
35
+ const syncRemoteModules = collectSyncRemoteModules(graph, mfConfig.remotes);
36
+ const syncSharedModules = collectSyncSharedModules(graph, mfConfig.shared);
37
+ if (true === options.runModule) {
38
+ const finalPreModules = [
39
+ getEarlyShared(syncSharedModules),
40
+ getEarlyRemotes(syncRemoteModules),
41
+ ...preModules
42
+ ];
43
+ return getBundleCode(entryPoint, finalPreModules, graph, options);
44
+ }
45
+ if (!isProjectSource(entryPoint, options.projectRoot)) return getBundleCode(entryPoint, preModules, graph, options);
46
+ const bundlePath = getBundlePath(entryPoint, options.projectRoot, mfConfig.exposes, isUsingMFBundleCommand);
47
+ const finalPreModules = [
48
+ getSyncShared(syncSharedModules, bundlePath, mfConfig.name),
49
+ getSyncRemotes(syncRemoteModules, bundlePath, mfConfig.name)
50
+ ];
51
+ if (false === options.modulesOnly) finalPreModules.push(...preModules);
52
+ const finalOptions = {
53
+ ...options,
54
+ modulesOnly: false
55
+ };
56
+ return getBundleCode(entryPoint, finalPreModules, graph, finalOptions);
57
+ };
58
+ }
59
+ function collectSyncRemoteModules(graph, _remotes) {
60
+ const remotes = new Set(Object.keys(_remotes));
61
+ const syncRemoteModules = new Set();
62
+ for (const [, module] of graph.dependencies)for (const dependency of module.dependencies.values()){
63
+ if (null !== dependency.data.data.asyncType) continue;
64
+ const remoteCandidate = dependency.data.name.split('/')[0];
65
+ const isValidCandidate = remoteCandidate.length < dependency.data.name.length;
66
+ if (isValidCandidate && remotes.has(remoteCandidate)) syncRemoteModules.add(dependency.data.name);
67
+ }
68
+ return Array.from(syncRemoteModules);
69
+ }
70
+ function collectSyncSharedModules(graph, _shared) {
71
+ const sharedImports = new Set(Object.keys(_shared).map((sharedName)=>_shared[sharedName].import || sharedName));
72
+ const syncSharedModules = new Set([
73
+ 'react',
74
+ 'react-native'
75
+ ]);
76
+ for (const [, module] of graph.dependencies)for (const dependency of module.dependencies.values())if (null === dependency.data.data.asyncType) {
77
+ if (!module.path.endsWith('init-host.js')) {
78
+ if (sharedImports.has(dependency.data.name)) syncSharedModules.add(dependency.data.name);
79
+ }
80
+ }
81
+ return Array.from(syncSharedModules);
82
+ }
83
+ function getFederationSharedDependenciesNamespace(scope) {
84
+ return `globalThis.__FEDERATION__.__NATIVE__["${scope}"].deps.shared`;
85
+ }
86
+ function getFederationRemotesDependenciesNamespace(scope) {
87
+ return `globalThis.__FEDERATION__.__NATIVE__["${scope}"].deps.remotes`;
88
+ }
89
+ function getSyncShared(shared, entry, scope) {
90
+ const namespace = getFederationSharedDependenciesNamespace(scope);
91
+ const code = `${namespace}["${entry}"]=${JSON.stringify(shared)};`;
92
+ return generateVirtualModule('__required_shared__', code);
93
+ }
94
+ function getSyncRemotes(remotes, entry, scope) {
95
+ const namespace = getFederationRemotesDependenciesNamespace(scope);
96
+ const code = `${namespace}["${entry}"]=${JSON.stringify(remotes)};`;
97
+ return generateVirtualModule('__required_remotes__', code);
98
+ }
99
+ function getEarlyShared(shared) {
100
+ const code = `var __EARLY_SHARED__=${JSON.stringify(shared)};`;
101
+ return generateVirtualModule('__early_shared__', code);
102
+ }
103
+ function getEarlyRemotes(remotes) {
104
+ const code = `var __EARLY_REMOTES__=${JSON.stringify(remotes)};`;
105
+ return generateVirtualModule('__early_remotes__', code);
106
+ }
107
+ function generateVirtualModule(name, code) {
108
+ return {
109
+ dependencies: new Map(),
110
+ getSource: ()=>Buffer.from(code),
111
+ inverseDependencies: new (CountingSet_default())(),
112
+ path: name,
113
+ output: [
114
+ {
115
+ type: "js/script/virtual",
116
+ data: {
117
+ code,
118
+ lineCount: 1,
119
+ map: []
120
+ }
121
+ }
122
+ ]
123
+ };
124
+ }
125
+ function isProjectSource(entryPoint, projectRoot) {
126
+ const relativePath = node_path.relative(projectRoot, entryPoint);
127
+ return !relativePath.startsWith('..') && !relativePath.startsWith('node_modules');
128
+ }
129
+ function getBundlePath(entryPoint, projectRoot, exposes, isUsingMFBundleCommand) {
130
+ const relativeEntryPath = node_path.relative(projectRoot, entryPoint);
131
+ if (!isUsingMFBundleCommand) {
132
+ const { dir, name } = node_path.parse(relativeEntryPath);
133
+ return node_path.format({
134
+ dir,
135
+ name,
136
+ ext: ''
137
+ });
138
+ }
139
+ const exposedMatchedKey = Object.keys(exposes).find((exposeKey)=>exposes[exposeKey].match(relativeEntryPath));
140
+ if (exposedMatchedKey) {
141
+ let exposedName = exposedMatchedKey;
142
+ if (exposedName.startsWith('./')) exposedName = exposedName.slice(2);
143
+ return `exposed/${exposedName}`;
144
+ }
145
+ throw new ConfigError(`Unable to handle entry point: ${relativeEntryPath}. Expected to match an entrypoint with one of the exposed keys, but failed. This is most likely a configuration error. If you believe this is not a configuration issue, please report it as a bug. Debug info: entryPoint="${entryPoint}", projectRoot="${projectRoot}", exposesKeys=[${Object.keys(exposes).join(', ')}]`);
146
+ }
147
+ function getBundleCode(entryPoint, preModules, graph, options) {
148
+ const { code } = bundleToString_default()(baseJSBundle_default()(entryPoint, preModules, graph, options));
149
+ return code;
150
+ }
151
+ export { getModuleFederationSerializer };
@@ -0,0 +1,2 @@
1
+ import type { ModuleFederationConfig } from '../types';
2
+ export declare function validateOptions(options: ModuleFederationConfig): void;
@@ -0,0 +1,61 @@
1
+ "use strict";
2
+ var __webpack_require__ = {};
3
+ (()=>{
4
+ __webpack_require__.d = (exports1, definition)=>{
5
+ for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
6
+ enumerable: true,
7
+ get: definition[key]
8
+ });
9
+ };
10
+ })();
11
+ (()=>{
12
+ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
13
+ })();
14
+ (()=>{
15
+ __webpack_require__.r = (exports1)=>{
16
+ if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
17
+ value: 'Module'
18
+ });
19
+ Object.defineProperty(exports1, '__esModule', {
20
+ value: true
21
+ });
22
+ };
23
+ })();
24
+ var __webpack_exports__ = {};
25
+ __webpack_require__.r(__webpack_exports__);
26
+ __webpack_require__.d(__webpack_exports__, {
27
+ validateOptions: ()=>validateOptions
28
+ });
29
+ const index_js_namespaceObject = require("../utils/index.js");
30
+ function validateName(name) {
31
+ const validEcmaIdentifierRegex = /^[$_\p{ID_Start}][$_\u{200C}\u{200D}\p{ID_Continue}]*$/u;
32
+ if (!validEcmaIdentifierRegex.test(name)) throw new index_js_namespaceObject.ConfigError(`Invalid 'name': ${name}. The 'name' must be a valid JavaScript identifier.`);
33
+ }
34
+ function validateFilename(filename) {
35
+ if (!filename) return;
36
+ if (!filename.endsWith('.bundle')) throw new index_js_namespaceObject.ConfigError(`Invalid filename: ${filename}. Filename must end with .bundle extension.`);
37
+ }
38
+ function validateShared(shared) {
39
+ if (!shared) throw new index_js_namespaceObject.ConfigError('Shared configuration is required.');
40
+ if ('object' != typeof shared) throw new index_js_namespaceObject.ConfigError('Shared must be an object.');
41
+ if (Array.isArray(shared)) throw new index_js_namespaceObject.ConfigError('Array format is not supported for shared.');
42
+ if (!('react' in shared)) throw new index_js_namespaceObject.ConfigError("Dependency 'react' must be present in shared.");
43
+ if (!('react-native' in shared)) throw new index_js_namespaceObject.ConfigError("Dependency 'react-native' must be present in shared.");
44
+ for (const sharedName of Object.keys(shared)){
45
+ if (sharedName.startsWith('./') || sharedName.startsWith('../')) throw new index_js_namespaceObject.ConfigError('Relative paths are not supported as shared module names.');
46
+ if (sharedName.startsWith('/')) throw new index_js_namespaceObject.ConfigError('Absolute paths are not supported as shared module names.');
47
+ if (sharedName.endsWith('/')) throw new index_js_namespaceObject.ConfigError("Deep import wildcards are not supported as shared module names. You need to list all deep imports explicitly.");
48
+ }
49
+ }
50
+ function validateOptions(options) {
51
+ validateName(options.name);
52
+ validateFilename(options.filename);
53
+ validateShared(options.shared);
54
+ }
55
+ exports.validateOptions = __webpack_exports__.validateOptions;
56
+ for(var __webpack_i__ in __webpack_exports__)if (-1 === [
57
+ "validateOptions"
58
+ ].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
59
+ Object.defineProperty(exports, '__esModule', {
60
+ value: true
61
+ });
@@ -0,0 +1,29 @@
1
+ import 'module';
2
+ /*#__PURE__*/ import.meta.url;
3
+ import { ConfigError } from "../utils/index.mjs";
4
+ function validateName(name) {
5
+ const validEcmaIdentifierRegex = /^[$_\p{ID_Start}][$_\u{200C}\u{200D}\p{ID_Continue}]*$/u;
6
+ if (!validEcmaIdentifierRegex.test(name)) throw new ConfigError(`Invalid 'name': ${name}. The 'name' must be a valid JavaScript identifier.`);
7
+ }
8
+ function validateFilename(filename) {
9
+ if (!filename) return;
10
+ if (!filename.endsWith('.bundle')) throw new ConfigError(`Invalid filename: ${filename}. Filename must end with .bundle extension.`);
11
+ }
12
+ function validateShared(shared) {
13
+ if (!shared) throw new ConfigError('Shared configuration is required.');
14
+ if ('object' != typeof shared) throw new ConfigError('Shared must be an object.');
15
+ if (Array.isArray(shared)) throw new ConfigError('Array format is not supported for shared.');
16
+ if (!('react' in shared)) throw new ConfigError("Dependency 'react' must be present in shared.");
17
+ if (!('react-native' in shared)) throw new ConfigError("Dependency 'react-native' must be present in shared.");
18
+ for (const sharedName of Object.keys(shared)){
19
+ if (sharedName.startsWith('./') || sharedName.startsWith('../')) throw new ConfigError('Relative paths are not supported as shared module names.');
20
+ if (sharedName.startsWith('/')) throw new ConfigError('Absolute paths are not supported as shared module names.');
21
+ if (sharedName.endsWith('/')) throw new ConfigError("Deep import wildcards are not supported as shared module names. You need to list all deep imports explicitly.");
22
+ }
23
+ }
24
+ function validateOptions(options) {
25
+ validateName(options.name);
26
+ validateFilename(options.filename);
27
+ validateShared(options.shared);
28
+ }
29
+ export { validateOptions };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,3 @@
1
+ import 'mf:init-host';
2
+ import 'mf:async-require';
3
+ __ENTRYPOINT_IMPORT__;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,31 @@
1
+ import { loadRemoteToRegistry, loadSharedToRegistry } from 'mf:remote-module-registry';
2
+ import { init } from '@module-federation/runtime';
3
+ __PLUGINS__;
4
+ const usedRemotes = __REMOTES__;
5
+ const usedShared = __SHARED__;
6
+ const name = __NAME__;
7
+ const shareScopeName = 'default';
8
+ const shareStrategy = __SHARE_STRATEGY__;
9
+ const instance = init({
10
+ name,
11
+ remotes: usedRemotes,
12
+ plugins,
13
+ shared: usedShared,
14
+ shareStrategy
15
+ });
16
+ globalThis.__FEDERATION__ ??= {};
17
+ globalThis.__FEDERATION__.__NATIVE__ ??= {};
18
+ globalThis.__FEDERATION__.__NATIVE__[name] ??= {};
19
+ globalThis.__FEDERATION__.__NATIVE__[name].deps ??= {
20
+ shared: {},
21
+ remotes: {}
22
+ };
23
+ globalThis.__FEDERATION__.__NATIVE__[name].init = Promise.all(instance.initializeSharing(shareScopeName, {
24
+ strategy: shareStrategy,
25
+ from: 'build',
26
+ initScope: []
27
+ })).then(()=>Promise.all([
28
+ ...Object.keys(usedShared).map(loadSharedToRegistry),
29
+ ...__EARLY_REMOTES__.map(loadRemoteToRegistry)
30
+ ]));
31
+ __EARLY_SHARED__.forEach(loadSharedToRegistry);
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,57 @@
1
+ import 'mf:async-require';
2
+ import { loadSharedToRegistry } from 'mf:remote-module-registry';
3
+ import { init as runtimeInit } from '@module-federation/runtime';
4
+ __PLUGINS__;
5
+ const usedRemotes = __REMOTES__;
6
+ const usedShared = __SHARED__;
7
+ const exposesMap = __EXPOSES_MAP__;
8
+ function get(moduleName) {
9
+ if (!(moduleName in exposesMap)) throw new Error(`Module ${moduleName} does not exist in container.`);
10
+ return exposesMap[moduleName]().then((m)=>()=>m);
11
+ }
12
+ const initTokens = {};
13
+ const name = __NAME__;
14
+ const shareScopeName = 'default';
15
+ const shareStrategy = __SHARE_STRATEGY__;
16
+ let hmrInitialized = false;
17
+ async function init(shared = {}, initScope = []) {
18
+ const instance = runtimeInit({
19
+ name,
20
+ remotes: usedRemotes,
21
+ shared: usedShared,
22
+ plugins,
23
+ shareStrategy
24
+ });
25
+ let initToken = initTokens[shareScopeName];
26
+ if (!initToken) initToken = initTokens[shareScopeName] = {
27
+ from: name
28
+ };
29
+ if (initScope.indexOf(initToken) >= 0) return;
30
+ initScope.push(initToken);
31
+ instance.initShareScopeMap(shareScopeName, shared);
32
+ const initSharingPromise = Promise.all(instance.initializeSharing(shareScopeName, {
33
+ strategy: shareStrategy,
34
+ from: 'build',
35
+ initScope
36
+ }));
37
+ __EARLY_SHARED__.forEach(loadSharedToRegistry);
38
+ await initSharingPromise;
39
+ if (__DEV__ && !hmrInitialized) {
40
+ const hmr = require('mf:remote-hmr');
41
+ hmr.setup();
42
+ hmrInitialized = true;
43
+ }
44
+ await Promise.all(Object.keys(shared).map(loadSharedToRegistry));
45
+ return instance;
46
+ }
47
+ globalThis.__FEDERATION__ ??= {};
48
+ globalThis.__FEDERATION__.__NATIVE__ ??= {};
49
+ globalThis.__FEDERATION__.__NATIVE__[name] ??= {};
50
+ globalThis.__FEDERATION__.__NATIVE__[name].deps ??= {
51
+ shared: {},
52
+ remotes: {}
53
+ };
54
+ globalThis.__FEDERATION__.__NATIVE__[name].exports = {
55
+ get,
56
+ init
57
+ };
@@ -0,0 +1 @@
1
+ export function setup(): void;
@@ -0,0 +1,19 @@
1
+ function parseUrl(url) {
2
+ const urlPattern = /^((https?):\/\/([^:/]+)(?::(\d+))?)\/?(.*)?$/;
3
+ const match = url.match(urlPattern);
4
+ if (!match) throw new Error('Invalid URL: ' + url);
5
+ const [, origin, scheme, host, port, path] = match;
6
+ return {
7
+ origin,
8
+ scheme,
9
+ host,
10
+ port,
11
+ path
12
+ };
13
+ }
14
+ export function setup() {
15
+ const HMRClient = require('react-native/Libraries/Utilities/HMRClient');
16
+ const platform = require('react-native').Platform.OS;
17
+ const { scheme, host, port, path } = parseUrl(globalThis.__FEDERATION__.__NATIVE__[__METRO_GLOBAL_PREFIX__].origin);
18
+ HMRClient.default.setup(platform, path, host, port, true, scheme);
19
+ }
@@ -0,0 +1,7 @@
1
+ export function loadAndGetShared(id: any): Promise<any>;
2
+ export function loadAndGetRemote(id: any): Promise<any>;
3
+ export function loadRemoteToRegistry(id: any): Promise<void>;
4
+ export function loadSharedToRegistry(id: any): void | Promise<void>;
5
+ export function loadSharedToRegistryAsync(id: any): Promise<void>;
6
+ export function loadSharedToRegistrySync(id: any): void;
7
+ export function getModuleFromRegistry(id: any): any;
@@ -0,0 +1,57 @@
1
+ import { loadRemote, loadShare, loadShareSync } from '@module-federation/runtime';
2
+ const registry = {};
3
+ const loading = {};
4
+ const earlyModuleTest = __EARLY_MODULE_TEST__;
5
+ function cloneModule(module, target) {
6
+ for (const key of Object.getOwnPropertyNames(module)){
7
+ const descriptor = Object.getOwnPropertyDescriptor(module, key);
8
+ Object.defineProperty(target, key, descriptor);
9
+ }
10
+ }
11
+ export async function loadAndGetShared(id) {
12
+ await loadSharedToRegistry(id);
13
+ return getModuleFromRegistry(id);
14
+ }
15
+ export async function loadAndGetRemote(id) {
16
+ await loadRemoteToRegistry(id);
17
+ return getModuleFromRegistry(id);
18
+ }
19
+ export async function loadRemoteToRegistry(id) {
20
+ const promise = loading[id];
21
+ if (promise) await promise;
22
+ else {
23
+ registry[id] = {};
24
+ loading[id] = (async ()=>{
25
+ const remoteModule = await loadRemote(id);
26
+ cloneModule(remoteModule, registry[id]);
27
+ })();
28
+ await loading[id];
29
+ }
30
+ }
31
+ export function loadSharedToRegistry(id) {
32
+ if (earlyModuleTest.test(id)) return loadSharedToRegistrySync(id);
33
+ return loadSharedToRegistryAsync(id);
34
+ }
35
+ export async function loadSharedToRegistryAsync(id) {
36
+ const promise = loading[id];
37
+ if (promise) await promise;
38
+ else {
39
+ registry[id] = {};
40
+ loading[id] = (async ()=>{
41
+ const factory = await loadShare(id);
42
+ const sharedModule = factory();
43
+ cloneModule(sharedModule, registry[id]);
44
+ })();
45
+ await loading[id];
46
+ }
47
+ }
48
+ export function loadSharedToRegistrySync(id) {
49
+ if (loading[id]) return;
50
+ loading[id] = loadShareSync(id);
51
+ registry[id] = loading[id]();
52
+ }
53
+ export function getModuleFromRegistry(id) {
54
+ const module = registry[id];
55
+ if (!module) throw new Error(`Module ${id} not found in registry`);
56
+ return module;
57
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,2 @@
1
+ import { getModuleFromRegistry } from 'mf:remote-module-registry';
2
+ module.exports = getModuleFromRegistry(__MODULE_ID__);
@@ -0,0 +1,26 @@
1
+ export interface SharedConfig {
2
+ singleton: boolean;
3
+ eager: boolean;
4
+ version: string;
5
+ requiredVersion: string;
6
+ import?: false;
7
+ }
8
+ export type Shared = Record<string, SharedConfig>;
9
+ export interface ModuleFederationConfig {
10
+ name: string;
11
+ filename?: string;
12
+ remotes?: Record<string, string>;
13
+ exposes?: Record<string, string>;
14
+ shared?: Shared;
15
+ shareStrategy?: 'loaded-first' | 'version-first';
16
+ plugins?: string[];
17
+ }
18
+ export type ModuleFederationConfigNormalized = Required<ModuleFederationConfig>;
19
+ export type ModuleFederationExtraOptions = {
20
+ flags?: MetroMFFlags;
21
+ };
22
+ export type MetroMFFlags = {
23
+ unstable_patchHMRClient?: boolean;
24
+ unstable_patchInitializeCore?: boolean;
25
+ unstable_patchRuntimeRequire?: boolean;
26
+ };
package/dist/types.js ADDED
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __webpack_require__ = {};
3
+ (()=>{
4
+ __webpack_require__.r = (exports1)=>{
5
+ if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
6
+ value: 'Module'
7
+ });
8
+ Object.defineProperty(exports1, '__esModule', {
9
+ value: true
10
+ });
11
+ };
12
+ })();
13
+ var __webpack_exports__ = {};
14
+ __webpack_require__.r(__webpack_exports__);
15
+ for(var __webpack_i__ in __webpack_exports__)exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
16
+ Object.defineProperty(exports, '__esModule', {
17
+ value: true
18
+ });
package/dist/types.mjs ADDED
@@ -0,0 +1,2 @@
1
+ import 'module';
2
+ /*#__PURE__*/ import.meta.url;