@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.
- package/LICENSE +21 -0
- package/README.md +11 -0
- package/babel-plugin/index.js +115 -0
- package/babel-plugin/patch-initialize-core.js +61 -0
- package/babel-plugin/patch-require.js +174 -0
- package/bootstrap/index.d.ts +1 -0
- package/bootstrap/index.js +1 -0
- package/dist/babel/transformer.js +15 -0
- package/dist/commands/bundle-host/index.d.ts +13 -0
- package/dist/commands/bundle-host/index.js +100 -0
- package/dist/commands/bundle-host/index.mjs +47 -0
- package/dist/commands/bundle-host/options.d.ts +5 -0
- package/dist/commands/bundle-host/options.js +43 -0
- package/dist/commands/bundle-host/options.mjs +6 -0
- package/dist/commands/bundle-host/types.d.ts +22 -0
- package/dist/commands/bundle-host/types.js +18 -0
- package/dist/commands/bundle-host/types.mjs +1 -0
- package/dist/commands/bundle-remote/index.d.ts +12 -0
- package/dist/commands/bundle-remote/index.js +241 -0
- package/dist/commands/bundle-remote/index.mjs +190 -0
- package/dist/commands/bundle-remote/options.d.ts +32 -0
- package/dist/commands/bundle-remote/options.js +113 -0
- package/dist/commands/bundle-remote/options.mjs +66 -0
- package/dist/commands/bundle-remote/types.d.ts +16 -0
- package/dist/commands/bundle-remote/types.js +18 -0
- package/dist/commands/bundle-remote/types.mjs +1 -0
- package/dist/commands/index.d.ts +48 -0
- package/dist/commands/index.js +76 -0
- package/dist/commands/index.mjs +13 -0
- package/dist/commands/types.d.ts +14 -0
- package/dist/commands/types.js +18 -0
- package/dist/commands/types.mjs +1 -0
- package/dist/commands/utils/create-module-path-remapper.d.ts +7 -0
- package/dist/commands/utils/create-module-path-remapper.js +68 -0
- package/dist/commands/utils/create-module-path-remapper.mjs +31 -0
- package/dist/commands/utils/create-resolver.d.ts +20 -0
- package/dist/commands/utils/create-resolver.js +61 -0
- package/dist/commands/utils/create-resolver.mjs +24 -0
- package/dist/commands/utils/get-community-plugin.d.ts +28 -0
- package/dist/commands/utils/get-community-plugin.js +53 -0
- package/dist/commands/utils/get-community-plugin.mjs +17 -0
- package/dist/commands/utils/load-metro-config.d.ts +3 -0
- package/dist/commands/utils/load-metro-config.js +85 -0
- package/dist/commands/utils/load-metro-config.mjs +41 -0
- package/dist/commands/utils/path-utils.d.ts +2 -0
- package/dist/commands/utils/path-utils.js +51 -0
- package/dist/commands/utils/path-utils.mjs +11 -0
- package/dist/commands/utils/save-bundle-and-map.d.ts +5 -0
- package/dist/commands/utils/save-bundle-and-map.js +80 -0
- package/dist/commands/utils/save-bundle-and-map.mjs +33 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +44 -0
- package/dist/index.mjs +3 -0
- package/dist/logger.d.ts +2 -0
- package/dist/logger.js +43 -0
- package/dist/logger.mjs +6 -0
- package/dist/modules/HMRClient.ts +31 -0
- package/dist/modules/HMRClientShim.ts +1 -0
- package/dist/modules/asyncRequire.ts +156 -0
- package/dist/modules/asyncStartup.tsx +43 -0
- package/dist/modules/getDevServer.ts +15 -0
- package/dist/modules/metroCorePlugin.ts +87 -0
- package/dist/plugin/babel-transformer.d.ts +11 -0
- package/dist/plugin/babel-transformer.js +72 -0
- package/dist/plugin/babel-transformer.mjs +25 -0
- package/dist/plugin/constants.d.ts +10 -0
- package/dist/plugin/constants.js +76 -0
- package/dist/plugin/constants.mjs +12 -0
- package/dist/plugin/generators.d.ts +13 -0
- package/dist/plugin/generators.js +164 -0
- package/dist/plugin/generators.mjs +102 -0
- package/dist/plugin/helpers.d.ts +8 -0
- package/dist/plugin/helpers.js +127 -0
- package/dist/plugin/helpers.mjs +58 -0
- package/dist/plugin/index.d.ts +11 -0
- package/dist/plugin/index.js +219 -0
- package/dist/plugin/index.mjs +172 -0
- package/dist/plugin/manifest-middleware.d.ts +12 -0
- package/dist/plugin/manifest-middleware.js +217 -0
- package/dist/plugin/manifest-middleware.mjs +170 -0
- package/dist/plugin/manifest.d.ts +16 -0
- package/dist/plugin/manifest.js +246 -0
- package/dist/plugin/manifest.mjs +185 -0
- package/dist/plugin/normalize-extra-options.d.ts +8 -0
- package/dist/plugin/normalize-extra-options.js +50 -0
- package/dist/plugin/normalize-extra-options.mjs +13 -0
- package/dist/plugin/normalize-options.d.ts +7 -0
- package/dist/plugin/normalize-options.js +139 -0
- package/dist/plugin/normalize-options.mjs +92 -0
- package/dist/plugin/resolver.d.ts +26 -0
- package/dist/plugin/resolver.js +203 -0
- package/dist/plugin/resolver.mjs +159 -0
- package/dist/plugin/rewrite-request.d.ts +14 -0
- package/dist/plugin/rewrite-request.js +89 -0
- package/dist/plugin/rewrite-request.mjs +42 -0
- package/dist/plugin/serializer.d.ts +6 -0
- package/dist/plugin/serializer.js +191 -0
- package/dist/plugin/serializer.mjs +144 -0
- package/dist/plugin/validate-options.d.ts +2 -0
- package/dist/plugin/validate-options.js +165 -0
- package/dist/plugin/validate-options.mjs +117 -0
- package/dist/runtime/host-entry.js +3 -0
- package/dist/runtime/init-host.js +31 -0
- package/dist/runtime/remote-entry.js +57 -0
- package/dist/runtime/remote-hmr.js +19 -0
- package/dist/runtime/remote-module-registry.js +57 -0
- package/dist/runtime/remote-module.js +2 -0
- package/dist/types.d.ts +26 -0
- package/dist/types.js +18 -0
- package/dist/types.mjs +1 -0
- package/dist/utils/errors.d.ts +8 -0
- package/dist/utils/errors.js +54 -0
- package/dist/utils/errors.mjs +14 -0
- package/dist/utils/federated-remote-types.d.ts +12 -0
- package/dist/utils/federated-remote-types.js +140 -0
- package/dist/utils/federated-remote-types.mjs +90 -0
- package/dist/utils/index.d.ts +2 -0
- package/dist/utils/index.js +47 -0
- package/dist/utils/index.mjs +3 -0
- package/dist/utils/metro-compat.d.ts +23 -0
- package/dist/utils/metro-compat.js +74 -0
- package/dist/utils/metro-compat.mjs +26 -0
- package/dist/utils/vm-manager.d.ts +21 -0
- package/dist/utils/vm-manager.js +118 -0
- package/dist/utils/vm-manager.mjs +70 -0
- package/package.json +106 -0
|
@@ -0,0 +1,191 @@
|
|
|
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
|
+
getModuleFederationSerializer: ()=>getModuleFederationSerializer
|
|
41
|
+
});
|
|
42
|
+
const external_node_path_namespaceObject = require("node:path");
|
|
43
|
+
var external_node_path_default = /*#__PURE__*/ __webpack_require__.n(external_node_path_namespaceObject);
|
|
44
|
+
const errors_js_namespaceObject = require("../utils/errors.js");
|
|
45
|
+
const external_helpers_js_namespaceObject = require("./helpers.js");
|
|
46
|
+
const external_manifest_js_namespaceObject = require("./manifest.js");
|
|
47
|
+
const metro_compat_js_namespaceObject = require("../utils/metro-compat.js");
|
|
48
|
+
function getModuleFederationSerializer(mfConfig, isUsingMFBundleCommand, manifestPath, manifestOptions) {
|
|
49
|
+
const bundleHashes = new Map();
|
|
50
|
+
return async (entryPoint, preModules, graph, options)=>{
|
|
51
|
+
const syncRemoteModules = collectSyncRemoteModules(graph, mfConfig.remotes);
|
|
52
|
+
const syncSharedModules = collectSyncSharedModules(graph, mfConfig.shared);
|
|
53
|
+
let code;
|
|
54
|
+
if (true === options.runModule) {
|
|
55
|
+
const finalPreModules = [
|
|
56
|
+
getEarlyShared(syncSharedModules),
|
|
57
|
+
getEarlyRemotes(syncRemoteModules),
|
|
58
|
+
...preModules
|
|
59
|
+
];
|
|
60
|
+
code = getBundleCode(entryPoint, finalPreModules, graph, options);
|
|
61
|
+
} else if (isProjectSource(entryPoint, options.projectRoot)) {
|
|
62
|
+
const bundlePath = getBundlePath(entryPoint, options.projectRoot, mfConfig.exposes, isUsingMFBundleCommand);
|
|
63
|
+
const finalPreModules = [
|
|
64
|
+
getSyncShared(syncSharedModules, bundlePath, mfConfig.name),
|
|
65
|
+
getSyncRemotes(syncRemoteModules, bundlePath, mfConfig.name)
|
|
66
|
+
];
|
|
67
|
+
if (false === options.modulesOnly) finalPreModules.push(...preModules);
|
|
68
|
+
const finalOptions = {
|
|
69
|
+
...options,
|
|
70
|
+
modulesOnly: false
|
|
71
|
+
};
|
|
72
|
+
code = getBundleCode(entryPoint, finalPreModules, graph, finalOptions);
|
|
73
|
+
} else code = getBundleCode(entryPoint, preModules, graph, options);
|
|
74
|
+
if (manifestPath) {
|
|
75
|
+
(0, external_manifest_js_namespaceObject.recordBundleHash)(bundleHashes, code, entryPoint, options.projectRoot, mfConfig);
|
|
76
|
+
(0, external_manifest_js_namespaceObject.updateManifest)(manifestPath, mfConfig, bundleHashes, manifestOptions);
|
|
77
|
+
}
|
|
78
|
+
return code;
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
function collectSyncRemoteModules(graph, _remotes) {
|
|
82
|
+
const remotes = new Set(Object.keys(_remotes));
|
|
83
|
+
const syncRemoteModules = new Set();
|
|
84
|
+
for (const [, module] of graph.dependencies)for (const dependency of module.dependencies.values()){
|
|
85
|
+
if (null !== dependency.data.data.asyncType) continue;
|
|
86
|
+
const remoteCandidate = dependency.data.name.split('/')[0];
|
|
87
|
+
const isValidCandidate = remoteCandidate.length < dependency.data.name.length;
|
|
88
|
+
if (isValidCandidate && remotes.has(remoteCandidate)) syncRemoteModules.add(dependency.data.name);
|
|
89
|
+
}
|
|
90
|
+
return Array.from(syncRemoteModules);
|
|
91
|
+
}
|
|
92
|
+
function collectSyncSharedModules(graph, _shared) {
|
|
93
|
+
const sharedImports = new Set(Object.keys(_shared).map((sharedName)=>_shared[sharedName].import || sharedName));
|
|
94
|
+
const syncSharedModules = new Set([
|
|
95
|
+
'react',
|
|
96
|
+
'react-native'
|
|
97
|
+
]);
|
|
98
|
+
for (const [, module] of graph.dependencies)for (const dependency of module.dependencies.values())if (null === dependency.data.data.asyncType) {
|
|
99
|
+
if (!module.path.endsWith('init-host.js')) {
|
|
100
|
+
if (sharedImports.has(dependency.data.name)) syncSharedModules.add(dependency.data.name);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
return Array.from(syncSharedModules);
|
|
104
|
+
}
|
|
105
|
+
function getFederationSharedDependenciesNamespace(scope) {
|
|
106
|
+
return `globalThis.__FEDERATION__.__NATIVE__["${scope}"].deps.shared`;
|
|
107
|
+
}
|
|
108
|
+
function getFederationRemotesDependenciesNamespace(scope) {
|
|
109
|
+
return `globalThis.__FEDERATION__.__NATIVE__["${scope}"].deps.remotes`;
|
|
110
|
+
}
|
|
111
|
+
function getSyncShared(shared, entry, scope) {
|
|
112
|
+
const namespace = getFederationSharedDependenciesNamespace(scope);
|
|
113
|
+
const code = `${namespace}["${entry}"]=${JSON.stringify(shared)};`;
|
|
114
|
+
return generateVirtualModule('__required_shared__', code);
|
|
115
|
+
}
|
|
116
|
+
function getSyncRemotes(remotes, entry, scope) {
|
|
117
|
+
const namespace = getFederationRemotesDependenciesNamespace(scope);
|
|
118
|
+
const code = `${namespace}["${entry}"]=${JSON.stringify(remotes)};`;
|
|
119
|
+
return generateVirtualModule('__required_remotes__', code);
|
|
120
|
+
}
|
|
121
|
+
function getEarlyShared(shared) {
|
|
122
|
+
const code = `var __EARLY_SHARED__=${JSON.stringify(shared)};`;
|
|
123
|
+
return generateVirtualModule('__early_shared__', code);
|
|
124
|
+
}
|
|
125
|
+
function getEarlyRemotes(remotes) {
|
|
126
|
+
const code = `var __EARLY_REMOTES__=${JSON.stringify(remotes)};`;
|
|
127
|
+
return generateVirtualModule('__early_remotes__', code);
|
|
128
|
+
}
|
|
129
|
+
function generateVirtualModule(name, code) {
|
|
130
|
+
return {
|
|
131
|
+
dependencies: new Map(),
|
|
132
|
+
getSource: ()=>Buffer.from(code),
|
|
133
|
+
inverseDependencies: new metro_compat_js_namespaceObject.CountingSet(),
|
|
134
|
+
path: name,
|
|
135
|
+
output: [
|
|
136
|
+
{
|
|
137
|
+
type: "js/script/virtual",
|
|
138
|
+
data: {
|
|
139
|
+
code,
|
|
140
|
+
lineCount: 1,
|
|
141
|
+
map: []
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
]
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
function isProjectSource(entryPoint, projectRoot) {
|
|
148
|
+
const relativePath = external_node_path_default().relative(projectRoot, entryPoint);
|
|
149
|
+
return !relativePath.startsWith('..') && !relativePath.startsWith('node_modules');
|
|
150
|
+
}
|
|
151
|
+
function getBundlePath(entryPoint, projectRoot, exposes, isUsingMFBundleCommand) {
|
|
152
|
+
const relativeEntryPath = external_node_path_default().relative(projectRoot, entryPoint);
|
|
153
|
+
const normalizedRelativeEntryPath = normalizeEntryPath(relativeEntryPath);
|
|
154
|
+
if (!isUsingMFBundleCommand) return removePathExtension(normalizedRelativeEntryPath);
|
|
155
|
+
const exposeEntries = Object.entries(exposes).map(([exposeKey, exposePath])=>({
|
|
156
|
+
exposeKey,
|
|
157
|
+
normalizedExposePath: normalizeEntryPath(exposePath)
|
|
158
|
+
}));
|
|
159
|
+
const exactMatch = exposeEntries.find(({ normalizedExposePath })=>normalizedExposePath === normalizedRelativeEntryPath);
|
|
160
|
+
const extensionlessMatch = exposeEntries.find(({ normalizedExposePath })=>removePathExtension(normalizedExposePath) === removePathExtension(normalizedRelativeEntryPath));
|
|
161
|
+
const exposedMatchedKey = exactMatch?.exposeKey ?? extensionlessMatch?.exposeKey;
|
|
162
|
+
if (exposedMatchedKey) {
|
|
163
|
+
let exposedName = exposedMatchedKey;
|
|
164
|
+
if (exposedName.startsWith('./')) exposedName = exposedName.slice(2);
|
|
165
|
+
return `exposed/${exposedName}`;
|
|
166
|
+
}
|
|
167
|
+
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(', ')}]`);
|
|
168
|
+
}
|
|
169
|
+
function normalizeEntryPath(value) {
|
|
170
|
+
const normalized = (0, external_helpers_js_namespaceObject.toPosixPath)(external_node_path_default().normalize(value));
|
|
171
|
+
return normalized.startsWith('./') ? normalized.slice(2) : normalized;
|
|
172
|
+
}
|
|
173
|
+
function removePathExtension(value) {
|
|
174
|
+
const parsed = external_node_path_default().posix.parse(value);
|
|
175
|
+
return external_node_path_default().posix.format({
|
|
176
|
+
dir: parsed.dir,
|
|
177
|
+
name: parsed.name,
|
|
178
|
+
ext: ''
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
function getBundleCode(entryPoint, preModules, graph, options) {
|
|
182
|
+
const { code } = (0, metro_compat_js_namespaceObject.bundleToString)((0, metro_compat_js_namespaceObject.baseJSBundle)(entryPoint, preModules, graph, options));
|
|
183
|
+
return code;
|
|
184
|
+
}
|
|
185
|
+
exports.getModuleFederationSerializer = __webpack_exports__.getModuleFederationSerializer;
|
|
186
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
187
|
+
"getModuleFederationSerializer"
|
|
188
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
189
|
+
Object.defineProperty(exports, '__esModule', {
|
|
190
|
+
value: true
|
|
191
|
+
});
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import "node:module";
|
|
2
|
+
import node_path from "node:path";
|
|
3
|
+
import { ConfigError } from "../utils/errors.mjs";
|
|
4
|
+
import { toPosixPath } from "./helpers.mjs";
|
|
5
|
+
import { recordBundleHash, updateManifest } from "./manifest.mjs";
|
|
6
|
+
import { CountingSet, baseJSBundle, bundleToString } from "../utils/metro-compat.mjs";
|
|
7
|
+
function getModuleFederationSerializer(mfConfig, isUsingMFBundleCommand, manifestPath, manifestOptions) {
|
|
8
|
+
const bundleHashes = new Map();
|
|
9
|
+
return async (entryPoint, preModules, graph, options)=>{
|
|
10
|
+
const syncRemoteModules = collectSyncRemoteModules(graph, mfConfig.remotes);
|
|
11
|
+
const syncSharedModules = collectSyncSharedModules(graph, mfConfig.shared);
|
|
12
|
+
let code;
|
|
13
|
+
if (true === options.runModule) {
|
|
14
|
+
const finalPreModules = [
|
|
15
|
+
getEarlyShared(syncSharedModules),
|
|
16
|
+
getEarlyRemotes(syncRemoteModules),
|
|
17
|
+
...preModules
|
|
18
|
+
];
|
|
19
|
+
code = getBundleCode(entryPoint, finalPreModules, graph, options);
|
|
20
|
+
} else if (isProjectSource(entryPoint, options.projectRoot)) {
|
|
21
|
+
const bundlePath = getBundlePath(entryPoint, options.projectRoot, mfConfig.exposes, isUsingMFBundleCommand);
|
|
22
|
+
const finalPreModules = [
|
|
23
|
+
getSyncShared(syncSharedModules, bundlePath, mfConfig.name),
|
|
24
|
+
getSyncRemotes(syncRemoteModules, bundlePath, mfConfig.name)
|
|
25
|
+
];
|
|
26
|
+
if (false === options.modulesOnly) finalPreModules.push(...preModules);
|
|
27
|
+
const finalOptions = {
|
|
28
|
+
...options,
|
|
29
|
+
modulesOnly: false
|
|
30
|
+
};
|
|
31
|
+
code = getBundleCode(entryPoint, finalPreModules, graph, finalOptions);
|
|
32
|
+
} else code = getBundleCode(entryPoint, preModules, graph, options);
|
|
33
|
+
if (manifestPath) {
|
|
34
|
+
recordBundleHash(bundleHashes, code, entryPoint, options.projectRoot, mfConfig);
|
|
35
|
+
updateManifest(manifestPath, mfConfig, bundleHashes, manifestOptions);
|
|
36
|
+
}
|
|
37
|
+
return code;
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
function collectSyncRemoteModules(graph, _remotes) {
|
|
41
|
+
const remotes = new Set(Object.keys(_remotes));
|
|
42
|
+
const syncRemoteModules = new Set();
|
|
43
|
+
for (const [, module] of graph.dependencies)for (const dependency of module.dependencies.values()){
|
|
44
|
+
if (null !== dependency.data.data.asyncType) continue;
|
|
45
|
+
const remoteCandidate = dependency.data.name.split('/')[0];
|
|
46
|
+
const isValidCandidate = remoteCandidate.length < dependency.data.name.length;
|
|
47
|
+
if (isValidCandidate && remotes.has(remoteCandidate)) syncRemoteModules.add(dependency.data.name);
|
|
48
|
+
}
|
|
49
|
+
return Array.from(syncRemoteModules);
|
|
50
|
+
}
|
|
51
|
+
function collectSyncSharedModules(graph, _shared) {
|
|
52
|
+
const sharedImports = new Set(Object.keys(_shared).map((sharedName)=>_shared[sharedName].import || sharedName));
|
|
53
|
+
const syncSharedModules = new Set([
|
|
54
|
+
'react',
|
|
55
|
+
'react-native'
|
|
56
|
+
]);
|
|
57
|
+
for (const [, module] of graph.dependencies)for (const dependency of module.dependencies.values())if (null === dependency.data.data.asyncType) {
|
|
58
|
+
if (!module.path.endsWith('init-host.js')) {
|
|
59
|
+
if (sharedImports.has(dependency.data.name)) syncSharedModules.add(dependency.data.name);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return Array.from(syncSharedModules);
|
|
63
|
+
}
|
|
64
|
+
function getFederationSharedDependenciesNamespace(scope) {
|
|
65
|
+
return `globalThis.__FEDERATION__.__NATIVE__["${scope}"].deps.shared`;
|
|
66
|
+
}
|
|
67
|
+
function getFederationRemotesDependenciesNamespace(scope) {
|
|
68
|
+
return `globalThis.__FEDERATION__.__NATIVE__["${scope}"].deps.remotes`;
|
|
69
|
+
}
|
|
70
|
+
function getSyncShared(shared, entry, scope) {
|
|
71
|
+
const namespace = getFederationSharedDependenciesNamespace(scope);
|
|
72
|
+
const code = `${namespace}["${entry}"]=${JSON.stringify(shared)};`;
|
|
73
|
+
return generateVirtualModule('__required_shared__', code);
|
|
74
|
+
}
|
|
75
|
+
function getSyncRemotes(remotes, entry, scope) {
|
|
76
|
+
const namespace = getFederationRemotesDependenciesNamespace(scope);
|
|
77
|
+
const code = `${namespace}["${entry}"]=${JSON.stringify(remotes)};`;
|
|
78
|
+
return generateVirtualModule('__required_remotes__', code);
|
|
79
|
+
}
|
|
80
|
+
function getEarlyShared(shared) {
|
|
81
|
+
const code = `var __EARLY_SHARED__=${JSON.stringify(shared)};`;
|
|
82
|
+
return generateVirtualModule('__early_shared__', code);
|
|
83
|
+
}
|
|
84
|
+
function getEarlyRemotes(remotes) {
|
|
85
|
+
const code = `var __EARLY_REMOTES__=${JSON.stringify(remotes)};`;
|
|
86
|
+
return generateVirtualModule('__early_remotes__', code);
|
|
87
|
+
}
|
|
88
|
+
function generateVirtualModule(name, code) {
|
|
89
|
+
return {
|
|
90
|
+
dependencies: new Map(),
|
|
91
|
+
getSource: ()=>Buffer.from(code),
|
|
92
|
+
inverseDependencies: new CountingSet(),
|
|
93
|
+
path: name,
|
|
94
|
+
output: [
|
|
95
|
+
{
|
|
96
|
+
type: "js/script/virtual",
|
|
97
|
+
data: {
|
|
98
|
+
code,
|
|
99
|
+
lineCount: 1,
|
|
100
|
+
map: []
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
]
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
function isProjectSource(entryPoint, projectRoot) {
|
|
107
|
+
const relativePath = node_path.relative(projectRoot, entryPoint);
|
|
108
|
+
return !relativePath.startsWith('..') && !relativePath.startsWith('node_modules');
|
|
109
|
+
}
|
|
110
|
+
function getBundlePath(entryPoint, projectRoot, exposes, isUsingMFBundleCommand) {
|
|
111
|
+
const relativeEntryPath = node_path.relative(projectRoot, entryPoint);
|
|
112
|
+
const normalizedRelativeEntryPath = normalizeEntryPath(relativeEntryPath);
|
|
113
|
+
if (!isUsingMFBundleCommand) return removePathExtension(normalizedRelativeEntryPath);
|
|
114
|
+
const exposeEntries = Object.entries(exposes).map(([exposeKey, exposePath])=>({
|
|
115
|
+
exposeKey,
|
|
116
|
+
normalizedExposePath: normalizeEntryPath(exposePath)
|
|
117
|
+
}));
|
|
118
|
+
const exactMatch = exposeEntries.find(({ normalizedExposePath })=>normalizedExposePath === normalizedRelativeEntryPath);
|
|
119
|
+
const extensionlessMatch = exposeEntries.find(({ normalizedExposePath })=>removePathExtension(normalizedExposePath) === removePathExtension(normalizedRelativeEntryPath));
|
|
120
|
+
const exposedMatchedKey = exactMatch?.exposeKey ?? extensionlessMatch?.exposeKey;
|
|
121
|
+
if (exposedMatchedKey) {
|
|
122
|
+
let exposedName = exposedMatchedKey;
|
|
123
|
+
if (exposedName.startsWith('./')) exposedName = exposedName.slice(2);
|
|
124
|
+
return `exposed/${exposedName}`;
|
|
125
|
+
}
|
|
126
|
+
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(', ')}]`);
|
|
127
|
+
}
|
|
128
|
+
function normalizeEntryPath(value) {
|
|
129
|
+
const normalized = toPosixPath(node_path.normalize(value));
|
|
130
|
+
return normalized.startsWith('./') ? normalized.slice(2) : normalized;
|
|
131
|
+
}
|
|
132
|
+
function removePathExtension(value) {
|
|
133
|
+
const parsed = node_path.posix.parse(value);
|
|
134
|
+
return node_path.posix.format({
|
|
135
|
+
dir: parsed.dir,
|
|
136
|
+
name: parsed.name,
|
|
137
|
+
ext: ''
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
function getBundleCode(entryPoint, preModules, graph, options) {
|
|
141
|
+
const { code } = bundleToString(baseJSBundle(entryPoint, preModules, graph, options));
|
|
142
|
+
return code;
|
|
143
|
+
}
|
|
144
|
+
export { getModuleFederationSerializer };
|
|
@@ -0,0 +1,165 @@
|
|
|
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
|
+
validateOptions: ()=>validateOptions
|
|
41
|
+
});
|
|
42
|
+
const external_node_path_namespaceObject = require("node:path");
|
|
43
|
+
var external_node_path_default = /*#__PURE__*/ __webpack_require__.n(external_node_path_namespaceObject);
|
|
44
|
+
const external_logger_js_namespaceObject = require("../logger.js");
|
|
45
|
+
var external_logger_js_default = /*#__PURE__*/ __webpack_require__.n(external_logger_js_namespaceObject);
|
|
46
|
+
const index_js_namespaceObject = require("../utils/index.js");
|
|
47
|
+
const unsupportedTopLevelOptions = [
|
|
48
|
+
'library',
|
|
49
|
+
'remoteType',
|
|
50
|
+
'runtime',
|
|
51
|
+
'shareScope',
|
|
52
|
+
'getPublicPath',
|
|
53
|
+
'implementation',
|
|
54
|
+
'manifest',
|
|
55
|
+
'dev',
|
|
56
|
+
'virtualRuntimeEntry',
|
|
57
|
+
'experiments',
|
|
58
|
+
'bridge',
|
|
59
|
+
'async',
|
|
60
|
+
'treeShakingDir',
|
|
61
|
+
'injectTreeShakingUsedExports',
|
|
62
|
+
'treeShakingSharedExcludePlugins',
|
|
63
|
+
'treeShakingSharedPlugins'
|
|
64
|
+
];
|
|
65
|
+
const unsupportedSharedFields = [
|
|
66
|
+
'packageName',
|
|
67
|
+
'shareKey',
|
|
68
|
+
'shareScope',
|
|
69
|
+
'strictVersion',
|
|
70
|
+
'treeShaking',
|
|
71
|
+
'shareStrategy'
|
|
72
|
+
];
|
|
73
|
+
const warningSet = new Set();
|
|
74
|
+
function validateName(name) {
|
|
75
|
+
if (!name || 'string' != typeof name) throw new index_js_namespaceObject.ConfigError("Option 'name' is required.");
|
|
76
|
+
const validEcmaIdentifierRegex = /^[$_\p{ID_Start}][$_\u{200C}\u{200D}\p{ID_Continue}]*$/u;
|
|
77
|
+
if (!validEcmaIdentifierRegex.test(name)) throw new index_js_namespaceObject.ConfigError(`Invalid 'name': ${name}. The 'name' must be a valid JavaScript identifier.`);
|
|
78
|
+
}
|
|
79
|
+
function validateFilename(filename) {
|
|
80
|
+
if (!filename) return;
|
|
81
|
+
if (!filename.endsWith('.bundle')) throw new index_js_namespaceObject.ConfigError(`Invalid filename: ${filename}. Filename must end with .bundle extension.`);
|
|
82
|
+
}
|
|
83
|
+
function validateShared(shared) {
|
|
84
|
+
if (!shared) throw new index_js_namespaceObject.ConfigError('Shared configuration is required.');
|
|
85
|
+
if ('object' != typeof shared) throw new index_js_namespaceObject.ConfigError('Shared must be an object.');
|
|
86
|
+
if (Array.isArray(shared)) throw new index_js_namespaceObject.ConfigError('Array format is not supported for shared.');
|
|
87
|
+
if (!isPlainObject(shared)) throw new index_js_namespaceObject.ConfigError('Shared must be an object.');
|
|
88
|
+
const sharedObject = shared;
|
|
89
|
+
if (!('react' in sharedObject)) throw new index_js_namespaceObject.ConfigError("Dependency 'react' must be present in shared.");
|
|
90
|
+
if (!('react-native' in sharedObject)) throw new index_js_namespaceObject.ConfigError("Dependency 'react-native' must be present in shared.");
|
|
91
|
+
for (const sharedName of Object.keys(sharedObject)){
|
|
92
|
+
const sharedConfig = sharedObject[sharedName];
|
|
93
|
+
if (isRelativePathLike(sharedName)) throw new index_js_namespaceObject.ConfigError('Relative paths are not supported as shared module names.');
|
|
94
|
+
if (isAbsolutePathLike(sharedName)) throw new index_js_namespaceObject.ConfigError('Absolute paths are not supported as shared module names.');
|
|
95
|
+
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.");
|
|
96
|
+
if (!isPlainObject(sharedConfig)) throw new index_js_namespaceObject.ConfigError(`Unsupported shared format for '${sharedName}'. Metro only supports object notation for shared modules.`);
|
|
97
|
+
if ('import' in sharedConfig && false !== sharedConfig.import && 'string' != typeof sharedConfig.import) throw new index_js_namespaceObject.ConfigError(`Unsupported shared.import value for '${sharedName}'. Only string and false are supported in Metro.`);
|
|
98
|
+
for (const unsupportedField of unsupportedSharedFields)if (unsupportedField in sharedConfig) warnUnsupported(`shared.${sharedName}.${unsupportedField}`, `Option 'shared.${sharedName}.${unsupportedField}' is not supported in Metro and will have no effect.`);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
function validateRemotes(remotes) {
|
|
102
|
+
if (void 0 === remotes) return;
|
|
103
|
+
if (!isPlainObject(remotes)) throw new index_js_namespaceObject.ConfigError('Unsupported remotes format. Metro only supports remotes as Record<string, string>.');
|
|
104
|
+
for (const remoteConfig of Object.values(remotes))if ('string' != typeof remoteConfig) throw new index_js_namespaceObject.ConfigError('Unsupported remotes format. Metro only supports remotes as Record<string, string>.');
|
|
105
|
+
}
|
|
106
|
+
function validateExposes(exposes) {
|
|
107
|
+
if (void 0 === exposes) return;
|
|
108
|
+
if (!isPlainObject(exposes)) throw new index_js_namespaceObject.ConfigError('Unsupported exposes format. Metro only supports exposes as Record<string, string>.');
|
|
109
|
+
for (const exposeConfig of Object.values(exposes))if ('string' != typeof exposeConfig) throw new index_js_namespaceObject.ConfigError('Unsupported exposes format. Metro only supports exposes as Record<string, string>.');
|
|
110
|
+
}
|
|
111
|
+
function validateRuntimePlugins(runtimePlugins) {
|
|
112
|
+
if (void 0 === runtimePlugins) return;
|
|
113
|
+
if (!Array.isArray(runtimePlugins)) throw new index_js_namespaceObject.ConfigError('runtimePlugins must be an array.');
|
|
114
|
+
runtimePlugins.forEach((runtimePlugin, index)=>{
|
|
115
|
+
if ('string' == typeof runtimePlugin) return;
|
|
116
|
+
if (!Array.isArray(runtimePlugin)) throw new index_js_namespaceObject.ConfigError('runtimePlugins entries must be either a string or a tuple of [path, params].');
|
|
117
|
+
const [pluginPath, pluginParams] = runtimePlugin;
|
|
118
|
+
if ('string' != typeof pluginPath) throw new index_js_namespaceObject.ConfigError(`Invalid runtimePlugins[${index}] path. Expected a string path.`);
|
|
119
|
+
if (void 0 !== pluginParams) warnUnsupported(`runtimePlugins[${index}][1]`, `Option 'runtimePlugins[${index}][1]' is not supported in Metro and will have no effect.`);
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
function validateDts(dts) {
|
|
123
|
+
if (void 0 === dts || 'boolean' == typeof dts) return;
|
|
124
|
+
if (!isPlainObject(dts)) throw new index_js_namespaceObject.ConfigError("Option 'dts' must be a boolean or a plain object.");
|
|
125
|
+
}
|
|
126
|
+
function validateUnsupportedTopLevelOptions(options) {
|
|
127
|
+
unsupportedTopLevelOptions.forEach((unsupportedOption)=>{
|
|
128
|
+
if (void 0 !== options[unsupportedOption]) warnUnsupported(String(unsupportedOption), `Option '${String(unsupportedOption)}' is not supported in Metro and will have no effect.`);
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
function validateDeprecatedOptions(options) {
|
|
132
|
+
if (options.plugins && options.plugins.length > 0) warnUnsupported('deprecated.plugins', "The 'plugins' option is deprecated. Use 'runtimePlugins' instead. Support for 'plugins' will be removed in the next major version.");
|
|
133
|
+
}
|
|
134
|
+
function warnUnsupported(key, message) {
|
|
135
|
+
if (warningSet.has(key)) return;
|
|
136
|
+
warningSet.add(key);
|
|
137
|
+
external_logger_js_default().warn(message);
|
|
138
|
+
}
|
|
139
|
+
function isPlainObject(value) {
|
|
140
|
+
return 'object' == typeof value && null !== value && !Array.isArray(value);
|
|
141
|
+
}
|
|
142
|
+
function isRelativePathLike(value) {
|
|
143
|
+
return /^\.{1,2}[\\/]/.test(value);
|
|
144
|
+
}
|
|
145
|
+
function isAbsolutePathLike(value) {
|
|
146
|
+
return external_node_path_default().posix.isAbsolute(value) || external_node_path_default().win32.isAbsolute(value);
|
|
147
|
+
}
|
|
148
|
+
function validateOptions(options) {
|
|
149
|
+
validateUnsupportedTopLevelOptions(options);
|
|
150
|
+
validateDeprecatedOptions(options);
|
|
151
|
+
validateName(options.name);
|
|
152
|
+
validateFilename(options.filename);
|
|
153
|
+
validateRemotes(options.remotes);
|
|
154
|
+
validateExposes(options.exposes);
|
|
155
|
+
validateRuntimePlugins(options.runtimePlugins);
|
|
156
|
+
validateDts(options.dts);
|
|
157
|
+
validateShared(options.shared);
|
|
158
|
+
}
|
|
159
|
+
exports.validateOptions = __webpack_exports__.validateOptions;
|
|
160
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
161
|
+
"validateOptions"
|
|
162
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
163
|
+
Object.defineProperty(exports, '__esModule', {
|
|
164
|
+
value: true
|
|
165
|
+
});
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import "node:module";
|
|
2
|
+
import node_path from "node:path";
|
|
3
|
+
import logger from "../logger.mjs";
|
|
4
|
+
import { ConfigError } from "../utils/index.mjs";
|
|
5
|
+
const unsupportedTopLevelOptions = [
|
|
6
|
+
'library',
|
|
7
|
+
'remoteType',
|
|
8
|
+
'runtime',
|
|
9
|
+
'shareScope',
|
|
10
|
+
'getPublicPath',
|
|
11
|
+
'implementation',
|
|
12
|
+
'manifest',
|
|
13
|
+
'dev',
|
|
14
|
+
'virtualRuntimeEntry',
|
|
15
|
+
'experiments',
|
|
16
|
+
'bridge',
|
|
17
|
+
'async',
|
|
18
|
+
'treeShakingDir',
|
|
19
|
+
'injectTreeShakingUsedExports',
|
|
20
|
+
'treeShakingSharedExcludePlugins',
|
|
21
|
+
'treeShakingSharedPlugins'
|
|
22
|
+
];
|
|
23
|
+
const unsupportedSharedFields = [
|
|
24
|
+
'packageName',
|
|
25
|
+
'shareKey',
|
|
26
|
+
'shareScope',
|
|
27
|
+
'strictVersion',
|
|
28
|
+
'treeShaking',
|
|
29
|
+
'shareStrategy'
|
|
30
|
+
];
|
|
31
|
+
const warningSet = new Set();
|
|
32
|
+
function validateName(name) {
|
|
33
|
+
if (!name || 'string' != typeof name) throw new ConfigError("Option 'name' is required.");
|
|
34
|
+
const validEcmaIdentifierRegex = /^[$_\p{ID_Start}][$_\u{200C}\u{200D}\p{ID_Continue}]*$/u;
|
|
35
|
+
if (!validEcmaIdentifierRegex.test(name)) throw new ConfigError(`Invalid 'name': ${name}. The 'name' must be a valid JavaScript identifier.`);
|
|
36
|
+
}
|
|
37
|
+
function validateFilename(filename) {
|
|
38
|
+
if (!filename) return;
|
|
39
|
+
if (!filename.endsWith('.bundle')) throw new ConfigError(`Invalid filename: ${filename}. Filename must end with .bundle extension.`);
|
|
40
|
+
}
|
|
41
|
+
function validateShared(shared) {
|
|
42
|
+
if (!shared) throw new ConfigError('Shared configuration is required.');
|
|
43
|
+
if ('object' != typeof shared) throw new ConfigError('Shared must be an object.');
|
|
44
|
+
if (Array.isArray(shared)) throw new ConfigError('Array format is not supported for shared.');
|
|
45
|
+
if (!isPlainObject(shared)) throw new ConfigError('Shared must be an object.');
|
|
46
|
+
const sharedObject = shared;
|
|
47
|
+
if (!('react' in sharedObject)) throw new ConfigError("Dependency 'react' must be present in shared.");
|
|
48
|
+
if (!('react-native' in sharedObject)) throw new ConfigError("Dependency 'react-native' must be present in shared.");
|
|
49
|
+
for (const sharedName of Object.keys(sharedObject)){
|
|
50
|
+
const sharedConfig = sharedObject[sharedName];
|
|
51
|
+
if (isRelativePathLike(sharedName)) throw new ConfigError('Relative paths are not supported as shared module names.');
|
|
52
|
+
if (isAbsolutePathLike(sharedName)) throw new ConfigError('Absolute paths are not supported as shared module names.');
|
|
53
|
+
if (sharedName.endsWith('/')) throw new ConfigError("Deep import wildcards are not supported as shared module names. You need to list all deep imports explicitly.");
|
|
54
|
+
if (!isPlainObject(sharedConfig)) throw new ConfigError(`Unsupported shared format for '${sharedName}'. Metro only supports object notation for shared modules.`);
|
|
55
|
+
if ('import' in sharedConfig && false !== sharedConfig.import && 'string' != typeof sharedConfig.import) throw new ConfigError(`Unsupported shared.import value for '${sharedName}'. Only string and false are supported in Metro.`);
|
|
56
|
+
for (const unsupportedField of unsupportedSharedFields)if (unsupportedField in sharedConfig) warnUnsupported(`shared.${sharedName}.${unsupportedField}`, `Option 'shared.${sharedName}.${unsupportedField}' is not supported in Metro and will have no effect.`);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
function validateRemotes(remotes) {
|
|
60
|
+
if (void 0 === remotes) return;
|
|
61
|
+
if (!isPlainObject(remotes)) throw new ConfigError('Unsupported remotes format. Metro only supports remotes as Record<string, string>.');
|
|
62
|
+
for (const remoteConfig of Object.values(remotes))if ('string' != typeof remoteConfig) throw new ConfigError('Unsupported remotes format. Metro only supports remotes as Record<string, string>.');
|
|
63
|
+
}
|
|
64
|
+
function validateExposes(exposes) {
|
|
65
|
+
if (void 0 === exposes) return;
|
|
66
|
+
if (!isPlainObject(exposes)) throw new ConfigError('Unsupported exposes format. Metro only supports exposes as Record<string, string>.');
|
|
67
|
+
for (const exposeConfig of Object.values(exposes))if ('string' != typeof exposeConfig) throw new ConfigError('Unsupported exposes format. Metro only supports exposes as Record<string, string>.');
|
|
68
|
+
}
|
|
69
|
+
function validateRuntimePlugins(runtimePlugins) {
|
|
70
|
+
if (void 0 === runtimePlugins) return;
|
|
71
|
+
if (!Array.isArray(runtimePlugins)) throw new ConfigError('runtimePlugins must be an array.');
|
|
72
|
+
runtimePlugins.forEach((runtimePlugin, index)=>{
|
|
73
|
+
if ('string' == typeof runtimePlugin) return;
|
|
74
|
+
if (!Array.isArray(runtimePlugin)) throw new ConfigError('runtimePlugins entries must be either a string or a tuple of [path, params].');
|
|
75
|
+
const [pluginPath, pluginParams] = runtimePlugin;
|
|
76
|
+
if ('string' != typeof pluginPath) throw new ConfigError(`Invalid runtimePlugins[${index}] path. Expected a string path.`);
|
|
77
|
+
if (void 0 !== pluginParams) warnUnsupported(`runtimePlugins[${index}][1]`, `Option 'runtimePlugins[${index}][1]' is not supported in Metro and will have no effect.`);
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
function validateDts(dts) {
|
|
81
|
+
if (void 0 === dts || 'boolean' == typeof dts) return;
|
|
82
|
+
if (!isPlainObject(dts)) throw new ConfigError("Option 'dts' must be a boolean or a plain object.");
|
|
83
|
+
}
|
|
84
|
+
function validateUnsupportedTopLevelOptions(options) {
|
|
85
|
+
unsupportedTopLevelOptions.forEach((unsupportedOption)=>{
|
|
86
|
+
if (void 0 !== options[unsupportedOption]) warnUnsupported(String(unsupportedOption), `Option '${String(unsupportedOption)}' is not supported in Metro and will have no effect.`);
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
function validateDeprecatedOptions(options) {
|
|
90
|
+
if (options.plugins && options.plugins.length > 0) warnUnsupported('deprecated.plugins', "The 'plugins' option is deprecated. Use 'runtimePlugins' instead. Support for 'plugins' will be removed in the next major version.");
|
|
91
|
+
}
|
|
92
|
+
function warnUnsupported(key, message) {
|
|
93
|
+
if (warningSet.has(key)) return;
|
|
94
|
+
warningSet.add(key);
|
|
95
|
+
logger.warn(message);
|
|
96
|
+
}
|
|
97
|
+
function isPlainObject(value) {
|
|
98
|
+
return 'object' == typeof value && null !== value && !Array.isArray(value);
|
|
99
|
+
}
|
|
100
|
+
function isRelativePathLike(value) {
|
|
101
|
+
return /^\.{1,2}[\\/]/.test(value);
|
|
102
|
+
}
|
|
103
|
+
function isAbsolutePathLike(value) {
|
|
104
|
+
return node_path.posix.isAbsolute(value) || node_path.win32.isAbsolute(value);
|
|
105
|
+
}
|
|
106
|
+
function validateOptions(options) {
|
|
107
|
+
validateUnsupportedTopLevelOptions(options);
|
|
108
|
+
validateDeprecatedOptions(options);
|
|
109
|
+
validateName(options.name);
|
|
110
|
+
validateFilename(options.filename);
|
|
111
|
+
validateRemotes(options.remotes);
|
|
112
|
+
validateExposes(options.exposes);
|
|
113
|
+
validateRuntimePlugins(options.runtimePlugins);
|
|
114
|
+
validateDts(options.dts);
|
|
115
|
+
validateShared(options.shared);
|
|
116
|
+
}
|
|
117
|
+
export { validateOptions };
|
|
@@ -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);
|