@module-federation/webpack-bundler-runtime 2.0.0 → 2.1.0
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/dist/_virtual/_rolldown/runtime.cjs +29 -0
- package/dist/attachShareScopeMap.cjs +11 -0
- package/dist/attachShareScopeMap.cjs.map +1 -0
- package/dist/attachShareScopeMap.d.ts +7 -0
- package/dist/attachShareScopeMap.js +10 -0
- package/dist/attachShareScopeMap.js.map +1 -0
- package/dist/constant.cjs +8 -0
- package/dist/constant.cjs.map +1 -0
- package/dist/constant.d.ts +5 -1
- package/dist/constant.js +6 -0
- package/dist/constant.js.map +1 -0
- package/dist/consumes.cjs +55 -0
- package/dist/consumes.cjs.map +1 -0
- package/dist/consumes.js +55 -0
- package/dist/consumes.js.map +1 -0
- package/dist/getSharedFallbackGetter.cjs +27 -0
- package/dist/getSharedFallbackGetter.cjs.map +1 -0
- package/dist/getSharedFallbackGetter.js +26 -0
- package/dist/getSharedFallbackGetter.js.map +1 -0
- package/dist/getUsedExports.cjs +11 -0
- package/dist/getUsedExports.cjs.map +1 -0
- package/dist/getUsedExports.js +10 -0
- package/dist/getUsedExports.js.map +1 -0
- package/dist/index.cjs +50 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +48 -2
- package/dist/index.js +36 -0
- package/dist/index.js.map +1 -0
- package/dist/init.cjs +82 -0
- package/dist/init.cjs.map +1 -0
- package/dist/init.js +80 -0
- package/dist/init.js.map +1 -0
- package/dist/initContainerEntry.cjs +43 -0
- package/dist/initContainerEntry.cjs.map +1 -0
- package/dist/initContainerEntry.d.ts +7 -0
- package/dist/initContainerEntry.js +42 -0
- package/dist/initContainerEntry.js.map +1 -0
- package/dist/initializeSharing.cjs +61 -0
- package/dist/initializeSharing.cjs.map +1 -0
- package/dist/initializeSharing.d.ts +13 -0
- package/dist/initializeSharing.js +61 -0
- package/dist/initializeSharing.js.map +1 -0
- package/dist/installInitialConsumes.cjs +63 -0
- package/dist/installInitialConsumes.cjs.map +1 -0
- package/dist/installInitialConsumes.js +63 -0
- package/dist/installInitialConsumes.js.map +1 -0
- package/dist/remotes.cjs +74 -0
- package/dist/remotes.cjs.map +1 -0
- package/dist/remotes.js +73 -0
- package/dist/remotes.js.map +1 -0
- package/dist/runtime-core/dist/core.d.ts +132 -0
- package/dist/runtime-core/dist/global.d.ts +25 -0
- package/dist/runtime-core/dist/helpers.d.ts +4 -0
- package/dist/runtime-core/dist/index.d.ts +15 -0
- package/dist/runtime-core/dist/module/index.d.ts +33 -0
- package/dist/runtime-core/dist/plugins/snapshot/SnapshotHandler.d.ts +68 -0
- package/dist/runtime-core/dist/remote/index.d.ts +121 -0
- package/dist/runtime-core/dist/shared/index.d.ts +85 -0
- package/dist/runtime-core/dist/type/config.d.ts +117 -0
- package/dist/runtime-core/dist/type/index.d.ts +3 -0
- package/dist/runtime-core/dist/type/plugin.d.ts +28 -0
- package/dist/runtime-core/dist/type/preload.d.ts +32 -0
- package/dist/runtime-core/dist/types.d.ts +4 -0
- package/dist/runtime-core/dist/utils/env.d.ts +1 -0
- package/dist/runtime-core/dist/utils/hooks/asyncHook.d.ts +11 -0
- package/dist/runtime-core/dist/utils/hooks/asyncWaterfallHooks.d.ts +13 -0
- package/dist/runtime-core/dist/utils/hooks/pluginSystem.d.ts +20 -0
- package/dist/runtime-core/dist/utils/hooks/syncHook.d.ts +17 -0
- package/dist/runtime-core/dist/utils/hooks/syncWaterfallHook.d.ts +12 -0
- package/dist/runtime-core/dist/utils/index.d.ts +2 -0
- package/dist/runtime-core/dist/utils/load.d.ts +16 -0
- package/dist/runtime-core/dist/utils/logger.d.ts +1 -0
- package/dist/runtime-core/dist/utils/manifest.d.ts +2 -0
- package/dist/runtime-core/dist/utils/plugin.d.ts +2 -0
- package/dist/runtime-core/dist/utils/preload.d.ts +4 -0
- package/dist/runtime-core/dist/utils/share.d.ts +3 -0
- package/dist/runtime-core/dist/utils/tool.d.ts +1 -0
- package/dist/sdk/dist/types/plugins/ModuleFederationPlugin.d.ts +13 -0
- package/dist/types.d.ts +201 -0
- package/dist/updateOptions.cjs +112 -0
- package/dist/updateOptions.cjs.map +1 -0
- package/dist/updateOptions.js +110 -0
- package/dist/updateOptions.js.map +1 -0
- package/package.json +9 -9
- package/dist/constant.cjs.cjs +0 -6
- package/dist/constant.cjs.cjs.map +0 -1
- package/dist/constant.cjs.d.ts +0 -1
- package/dist/constant.esm.js +0 -4
- package/dist/constant.esm.js.map +0 -1
- package/dist/index.cjs.cjs +0 -781
- package/dist/index.cjs.cjs.map +0 -1
- package/dist/index.cjs.d.ts +0 -2
- package/dist/index.esm.js +0 -767
- package/dist/index.esm.js.map +0 -1
- package/dist/src/attachShareScopeMap.d.ts +0 -2
- package/dist/src/constant.d.ts +0 -1
- package/dist/src/consumes.d.ts +0 -2
- package/dist/src/getSharedFallbackGetter.d.ts +0 -2
- package/dist/src/getUsedExports.d.ts +0 -2
- package/dist/src/index.d.ts +0 -4
- package/dist/src/init.d.ts +0 -4
- package/dist/src/initContainerEntry.d.ts +0 -2
- package/dist/src/initializeSharing.d.ts +0 -2
- package/dist/src/installInitialConsumes.d.ts +0 -2
- package/dist/src/remotes.d.ts +0 -2
- package/dist/src/types.d.ts +0 -194
- package/dist/src/updateOptions.d.ts +0 -3
package/dist/index.esm.js
DELETED
|
@@ -1,767 +0,0 @@
|
|
|
1
|
-
import * as runtime from '@module-federation/runtime';
|
|
2
|
-
import { getRemoteEntry } from '@module-federation/runtime';
|
|
3
|
-
import { FEDERATION_SUPPORTED_TYPES } from './constant.esm.js';
|
|
4
|
-
import { decodeName, ENCODE_NAME_PREFIX } from '@module-federation/sdk';
|
|
5
|
-
import helpers from '@module-federation/runtime/helpers';
|
|
6
|
-
|
|
7
|
-
function attachShareScopeMap(webpackRequire) {
|
|
8
|
-
if (!webpackRequire.S ||
|
|
9
|
-
webpackRequire.federation.hasAttachShareScopeMap ||
|
|
10
|
-
!webpackRequire.federation.instance ||
|
|
11
|
-
!webpackRequire.federation.instance.shareScopeMap) {
|
|
12
|
-
return;
|
|
13
|
-
}
|
|
14
|
-
webpackRequire.S = webpackRequire.federation.instance.shareScopeMap;
|
|
15
|
-
webpackRequire.federation.hasAttachShareScopeMap = true;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
function updateConsumeOptions(options) {
|
|
19
|
-
const { webpackRequire, moduleToHandlerMapping } = options;
|
|
20
|
-
const { consumesLoadingData, initializeSharingData } = webpackRequire;
|
|
21
|
-
const { sharedFallback, bundlerRuntime, libraryType } = webpackRequire.federation;
|
|
22
|
-
if (consumesLoadingData && !consumesLoadingData._updated) {
|
|
23
|
-
const { moduleIdToConsumeDataMapping: updatedModuleIdToConsumeDataMapping = {}, initialConsumes: updatedInitialConsumes = [], chunkMapping: updatedChunkMapping = {}, } = consumesLoadingData;
|
|
24
|
-
Object.entries(updatedModuleIdToConsumeDataMapping).forEach(([id, data]) => {
|
|
25
|
-
if (!moduleToHandlerMapping[id]) {
|
|
26
|
-
moduleToHandlerMapping[id] = {
|
|
27
|
-
// @ts-ignore
|
|
28
|
-
getter: sharedFallback
|
|
29
|
-
? bundlerRuntime?.getSharedFallbackGetter({
|
|
30
|
-
shareKey: data.shareKey,
|
|
31
|
-
factory: data.fallback,
|
|
32
|
-
webpackRequire,
|
|
33
|
-
libraryType,
|
|
34
|
-
})
|
|
35
|
-
: data.fallback,
|
|
36
|
-
treeShakingGetter: sharedFallback ? data.fallback : undefined,
|
|
37
|
-
shareInfo: {
|
|
38
|
-
shareConfig: {
|
|
39
|
-
requiredVersion: data.requiredVersion,
|
|
40
|
-
strictVersion: data.strictVersion,
|
|
41
|
-
singleton: data.singleton,
|
|
42
|
-
eager: data.eager,
|
|
43
|
-
layer: data.layer,
|
|
44
|
-
},
|
|
45
|
-
scope: Array.isArray(data.shareScope)
|
|
46
|
-
? data.shareScope
|
|
47
|
-
: [data.shareScope || 'default'],
|
|
48
|
-
treeShaking: sharedFallback
|
|
49
|
-
? {
|
|
50
|
-
get: data.fallback,
|
|
51
|
-
mode: data.treeShakingMode,
|
|
52
|
-
}
|
|
53
|
-
: undefined,
|
|
54
|
-
},
|
|
55
|
-
shareKey: data.shareKey,
|
|
56
|
-
};
|
|
57
|
-
}
|
|
58
|
-
});
|
|
59
|
-
if ('initialConsumes' in options) {
|
|
60
|
-
const { initialConsumes = [] } = options;
|
|
61
|
-
updatedInitialConsumes.forEach((id) => {
|
|
62
|
-
if (!initialConsumes.includes(id)) {
|
|
63
|
-
initialConsumes.push(id);
|
|
64
|
-
}
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
if ('chunkMapping' in options) {
|
|
68
|
-
const { chunkMapping = {} } = options;
|
|
69
|
-
Object.entries(updatedChunkMapping).forEach(([id, chunkModules]) => {
|
|
70
|
-
if (!chunkMapping[id]) {
|
|
71
|
-
chunkMapping[id] = [];
|
|
72
|
-
}
|
|
73
|
-
chunkModules.forEach((moduleId) => {
|
|
74
|
-
if (!chunkMapping[id].includes(moduleId)) {
|
|
75
|
-
chunkMapping[id].push(moduleId);
|
|
76
|
-
}
|
|
77
|
-
});
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
consumesLoadingData._updated = 1;
|
|
81
|
-
}
|
|
82
|
-
if (initializeSharingData && !initializeSharingData._updated) {
|
|
83
|
-
const { federation } = webpackRequire;
|
|
84
|
-
if (!federation.instance ||
|
|
85
|
-
!initializeSharingData.scopeToSharingDataMapping) {
|
|
86
|
-
return;
|
|
87
|
-
}
|
|
88
|
-
const shared = {};
|
|
89
|
-
for (let [scope, stages] of Object.entries(initializeSharingData.scopeToSharingDataMapping)) {
|
|
90
|
-
for (let stage of stages) {
|
|
91
|
-
if (typeof stage === 'object' && stage !== null) {
|
|
92
|
-
const { name, version, factory, eager, singleton, requiredVersion, strictVersion, } = stage;
|
|
93
|
-
const shareConfig = {
|
|
94
|
-
requiredVersion: `^${version}`,
|
|
95
|
-
};
|
|
96
|
-
const isValidValue = function (val) {
|
|
97
|
-
return typeof val !== 'undefined';
|
|
98
|
-
};
|
|
99
|
-
if (isValidValue(singleton)) {
|
|
100
|
-
shareConfig.singleton = singleton;
|
|
101
|
-
}
|
|
102
|
-
if (isValidValue(requiredVersion)) {
|
|
103
|
-
shareConfig.requiredVersion = requiredVersion;
|
|
104
|
-
}
|
|
105
|
-
if (isValidValue(eager)) {
|
|
106
|
-
shareConfig.eager = eager;
|
|
107
|
-
}
|
|
108
|
-
if (isValidValue(strictVersion)) {
|
|
109
|
-
shareConfig.strictVersion = strictVersion;
|
|
110
|
-
}
|
|
111
|
-
const options = {
|
|
112
|
-
version,
|
|
113
|
-
scope: [scope],
|
|
114
|
-
shareConfig,
|
|
115
|
-
get: factory,
|
|
116
|
-
};
|
|
117
|
-
if (shared[name]) {
|
|
118
|
-
shared[name].push(options);
|
|
119
|
-
}
|
|
120
|
-
else {
|
|
121
|
-
shared[name] = [options];
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
federation.instance.registerShared(shared);
|
|
127
|
-
initializeSharingData._updated = 1;
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
function updateRemoteOptions(options) {
|
|
131
|
-
const { webpackRequire, idToExternalAndNameMapping = {}, idToRemoteMap = {}, chunkMapping = {}, } = options;
|
|
132
|
-
const { remotesLoadingData } = webpackRequire;
|
|
133
|
-
const remoteInfos = webpackRequire.federation?.bundlerRuntimeOptions?.remotes?.remoteInfos;
|
|
134
|
-
if (!remotesLoadingData || remotesLoadingData._updated || !remoteInfos) {
|
|
135
|
-
return;
|
|
136
|
-
}
|
|
137
|
-
const { chunkMapping: updatedChunkMapping, moduleIdToRemoteDataMapping } = remotesLoadingData;
|
|
138
|
-
if (!updatedChunkMapping || !moduleIdToRemoteDataMapping) {
|
|
139
|
-
return;
|
|
140
|
-
}
|
|
141
|
-
for (let [moduleId, data] of Object.entries(moduleIdToRemoteDataMapping)) {
|
|
142
|
-
if (!idToExternalAndNameMapping[moduleId]) {
|
|
143
|
-
idToExternalAndNameMapping[moduleId] = [
|
|
144
|
-
data.shareScope,
|
|
145
|
-
data.name,
|
|
146
|
-
data.externalModuleId,
|
|
147
|
-
];
|
|
148
|
-
}
|
|
149
|
-
if (!idToRemoteMap[moduleId] && remoteInfos[data.remoteName]) {
|
|
150
|
-
const items = remoteInfos[data.remoteName];
|
|
151
|
-
idToRemoteMap[moduleId] ||= [];
|
|
152
|
-
items.forEach((item) => {
|
|
153
|
-
if (!idToRemoteMap[moduleId].includes(item)) {
|
|
154
|
-
idToRemoteMap[moduleId].push(item);
|
|
155
|
-
}
|
|
156
|
-
});
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
if (chunkMapping) {
|
|
160
|
-
Object.entries(updatedChunkMapping).forEach(([id, chunkModules]) => {
|
|
161
|
-
if (!chunkMapping[id]) {
|
|
162
|
-
chunkMapping[id] = [];
|
|
163
|
-
}
|
|
164
|
-
chunkModules.forEach((moduleId) => {
|
|
165
|
-
if (!chunkMapping[id].includes(moduleId)) {
|
|
166
|
-
chunkMapping[id].push(moduleId);
|
|
167
|
-
}
|
|
168
|
-
});
|
|
169
|
-
});
|
|
170
|
-
}
|
|
171
|
-
remotesLoadingData._updated = 1;
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
function remotes(options) {
|
|
175
|
-
updateRemoteOptions(options);
|
|
176
|
-
const { chunkId, promises, webpackRequire, chunkMapping, idToExternalAndNameMapping, idToRemoteMap, } = options;
|
|
177
|
-
attachShareScopeMap(webpackRequire);
|
|
178
|
-
if (webpackRequire.o(chunkMapping, chunkId)) {
|
|
179
|
-
chunkMapping[chunkId].forEach((id) => {
|
|
180
|
-
let getScope = webpackRequire.R;
|
|
181
|
-
if (!getScope) {
|
|
182
|
-
getScope = [];
|
|
183
|
-
}
|
|
184
|
-
const data = idToExternalAndNameMapping[id];
|
|
185
|
-
const remoteInfos = idToRemoteMap[id] || [];
|
|
186
|
-
// @ts-ignore seems not work
|
|
187
|
-
if (getScope.indexOf(data) >= 0) {
|
|
188
|
-
return;
|
|
189
|
-
}
|
|
190
|
-
// @ts-ignore seems not work
|
|
191
|
-
getScope.push(data);
|
|
192
|
-
if (data.p) {
|
|
193
|
-
return promises.push(data.p);
|
|
194
|
-
}
|
|
195
|
-
const onError = (error) => {
|
|
196
|
-
if (!error) {
|
|
197
|
-
error = new Error('Container missing');
|
|
198
|
-
}
|
|
199
|
-
if (typeof error.message === 'string') {
|
|
200
|
-
error.message += `\nwhile loading "${data[1]}" from ${data[2]}`;
|
|
201
|
-
}
|
|
202
|
-
webpackRequire.m[id] = () => {
|
|
203
|
-
throw error;
|
|
204
|
-
};
|
|
205
|
-
data.p = 0;
|
|
206
|
-
};
|
|
207
|
-
const handleFunction = (fn, arg1, arg2, d, next, first) => {
|
|
208
|
-
try {
|
|
209
|
-
const promise = fn(arg1, arg2);
|
|
210
|
-
if (promise && promise.then) {
|
|
211
|
-
const p = promise.then((result) => next(result, d), onError);
|
|
212
|
-
if (first) {
|
|
213
|
-
promises.push((data.p = p));
|
|
214
|
-
}
|
|
215
|
-
else {
|
|
216
|
-
return p;
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
else {
|
|
220
|
-
return next(promise, d, first);
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
catch (error) {
|
|
224
|
-
onError(error);
|
|
225
|
-
}
|
|
226
|
-
};
|
|
227
|
-
const onExternal = (external, _, first) => external
|
|
228
|
-
? handleFunction(webpackRequire.I, data[0], 0, external, onInitialized, first)
|
|
229
|
-
: onError();
|
|
230
|
-
// eslint-disable-next-line no-var
|
|
231
|
-
var onInitialized = (_, external, first) => handleFunction(external.get, data[1], getScope, 0, onFactory, first);
|
|
232
|
-
// eslint-disable-next-line no-var
|
|
233
|
-
var onFactory = (factory) => {
|
|
234
|
-
data.p = 1;
|
|
235
|
-
webpackRequire.m[id] = (module) => {
|
|
236
|
-
module.exports = factory();
|
|
237
|
-
};
|
|
238
|
-
};
|
|
239
|
-
const onRemoteLoaded = () => {
|
|
240
|
-
try {
|
|
241
|
-
const remoteName = decodeName(remoteInfos[0].name, ENCODE_NAME_PREFIX);
|
|
242
|
-
const remoteModuleName = remoteName + data[1].slice(1);
|
|
243
|
-
const instance = webpackRequire.federation.instance;
|
|
244
|
-
const loadRemote = () => webpackRequire.federation.instance.loadRemote(remoteModuleName, {
|
|
245
|
-
loadFactory: false,
|
|
246
|
-
from: 'build',
|
|
247
|
-
});
|
|
248
|
-
if (instance.options.shareStrategy === 'version-first') {
|
|
249
|
-
return Promise.all(instance.sharedHandler.initializeSharing(data[0])).then(() => {
|
|
250
|
-
return loadRemote();
|
|
251
|
-
});
|
|
252
|
-
}
|
|
253
|
-
return loadRemote();
|
|
254
|
-
}
|
|
255
|
-
catch (error) {
|
|
256
|
-
onError(error);
|
|
257
|
-
}
|
|
258
|
-
};
|
|
259
|
-
const useRuntimeLoad = remoteInfos.length === 1 &&
|
|
260
|
-
FEDERATION_SUPPORTED_TYPES.includes(remoteInfos[0].externalType) &&
|
|
261
|
-
remoteInfos[0].name;
|
|
262
|
-
if (useRuntimeLoad) {
|
|
263
|
-
handleFunction(onRemoteLoaded, data[2], 0, 0, onFactory, 1);
|
|
264
|
-
}
|
|
265
|
-
else {
|
|
266
|
-
handleFunction(webpackRequire, data[2], 0, 0, onExternal, 1);
|
|
267
|
-
}
|
|
268
|
-
});
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
function getUsedExports(webpackRequire, sharedName) {
|
|
273
|
-
const usedExports = webpackRequire.federation.usedExports;
|
|
274
|
-
if (!usedExports) {
|
|
275
|
-
return;
|
|
276
|
-
}
|
|
277
|
-
return usedExports[sharedName];
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
function consumes(options) {
|
|
281
|
-
updateConsumeOptions(options);
|
|
282
|
-
const { chunkId, promises, installedModules, webpackRequire, chunkMapping, moduleToHandlerMapping, } = options;
|
|
283
|
-
attachShareScopeMap(webpackRequire);
|
|
284
|
-
if (webpackRequire.o(chunkMapping, chunkId)) {
|
|
285
|
-
chunkMapping[chunkId].forEach((id) => {
|
|
286
|
-
if (webpackRequire.o(installedModules, id)) {
|
|
287
|
-
return promises.push(installedModules[id]);
|
|
288
|
-
}
|
|
289
|
-
const onFactory = (factory) => {
|
|
290
|
-
installedModules[id] = 0;
|
|
291
|
-
webpackRequire.m[id] = (module) => {
|
|
292
|
-
delete webpackRequire.c[id];
|
|
293
|
-
const result = factory();
|
|
294
|
-
// Add layer property from shareConfig if available
|
|
295
|
-
const { shareInfo } = moduleToHandlerMapping[id];
|
|
296
|
-
if (shareInfo?.shareConfig?.layer &&
|
|
297
|
-
result &&
|
|
298
|
-
typeof result === 'object') {
|
|
299
|
-
try {
|
|
300
|
-
// Only set layer if it's not already defined or if it's undefined
|
|
301
|
-
if (!result.hasOwnProperty('layer') ||
|
|
302
|
-
result.layer === undefined) {
|
|
303
|
-
result.layer = shareInfo.shareConfig.layer;
|
|
304
|
-
}
|
|
305
|
-
}
|
|
306
|
-
catch (e) {
|
|
307
|
-
// Ignore if layer property is read-only
|
|
308
|
-
}
|
|
309
|
-
}
|
|
310
|
-
module.exports = result;
|
|
311
|
-
};
|
|
312
|
-
};
|
|
313
|
-
const onError = (error) => {
|
|
314
|
-
delete installedModules[id];
|
|
315
|
-
webpackRequire.m[id] = (module) => {
|
|
316
|
-
delete webpackRequire.c[id];
|
|
317
|
-
throw error;
|
|
318
|
-
};
|
|
319
|
-
};
|
|
320
|
-
try {
|
|
321
|
-
const federationInstance = webpackRequire.federation.instance;
|
|
322
|
-
if (!federationInstance) {
|
|
323
|
-
throw new Error('Federation instance not found!');
|
|
324
|
-
}
|
|
325
|
-
const { shareKey, getter, shareInfo, treeShakingGetter } = moduleToHandlerMapping[id];
|
|
326
|
-
const usedExports = getUsedExports(webpackRequire, shareKey);
|
|
327
|
-
const customShareInfo = { ...shareInfo };
|
|
328
|
-
if (usedExports) {
|
|
329
|
-
customShareInfo.treeShaking = {
|
|
330
|
-
usedExports,
|
|
331
|
-
useIn: [federationInstance.options.name],
|
|
332
|
-
};
|
|
333
|
-
}
|
|
334
|
-
const promise = federationInstance
|
|
335
|
-
.loadShare(shareKey, {
|
|
336
|
-
customShareInfo,
|
|
337
|
-
})
|
|
338
|
-
.then((factory) => {
|
|
339
|
-
if (factory === false) {
|
|
340
|
-
return treeShakingGetter?.() || getter();
|
|
341
|
-
}
|
|
342
|
-
return factory;
|
|
343
|
-
});
|
|
344
|
-
if (promise.then) {
|
|
345
|
-
promises.push((installedModules[id] = promise.then(onFactory).catch(onError)));
|
|
346
|
-
}
|
|
347
|
-
else {
|
|
348
|
-
// @ts-ignore maintain previous logic
|
|
349
|
-
onFactory(promise);
|
|
350
|
-
}
|
|
351
|
-
}
|
|
352
|
-
catch (e) {
|
|
353
|
-
onError(e);
|
|
354
|
-
}
|
|
355
|
-
});
|
|
356
|
-
}
|
|
357
|
-
}
|
|
358
|
-
|
|
359
|
-
function initializeSharing({ shareScopeName, webpackRequire, initPromises, initTokens, initScope, }) {
|
|
360
|
-
const shareScopeKeys = Array.isArray(shareScopeName)
|
|
361
|
-
? shareScopeName
|
|
362
|
-
: [shareScopeName];
|
|
363
|
-
var initializeSharingPromises = [];
|
|
364
|
-
var _initializeSharing = function (shareScopeKey) {
|
|
365
|
-
if (!initScope)
|
|
366
|
-
initScope = [];
|
|
367
|
-
const mfInstance = webpackRequire.federation.instance;
|
|
368
|
-
// handling circular init calls
|
|
369
|
-
var initToken = initTokens[shareScopeKey];
|
|
370
|
-
if (!initToken)
|
|
371
|
-
initToken = initTokens[shareScopeKey] = { from: mfInstance.name };
|
|
372
|
-
if (initScope.indexOf(initToken) >= 0)
|
|
373
|
-
return;
|
|
374
|
-
initScope.push(initToken);
|
|
375
|
-
const promise = initPromises[shareScopeKey];
|
|
376
|
-
if (promise)
|
|
377
|
-
return promise;
|
|
378
|
-
var warn = (msg) => typeof console !== 'undefined' && console.warn && console.warn(msg);
|
|
379
|
-
var initExternal = (id) => {
|
|
380
|
-
var handleError = (err) => warn('Initialization of sharing external failed: ' + err);
|
|
381
|
-
try {
|
|
382
|
-
var module = webpackRequire(id);
|
|
383
|
-
if (!module)
|
|
384
|
-
return;
|
|
385
|
-
var initFn = (module) => module &&
|
|
386
|
-
module.init &&
|
|
387
|
-
// @ts-ignore compat legacy mf shared behavior
|
|
388
|
-
module.init(webpackRequire.S[shareScopeKey], initScope, {
|
|
389
|
-
shareScopeMap: webpackRequire.S || {},
|
|
390
|
-
shareScopeKeys: shareScopeName,
|
|
391
|
-
});
|
|
392
|
-
if (module.then)
|
|
393
|
-
return promises.push(module.then(initFn, handleError));
|
|
394
|
-
var initResult = initFn(module);
|
|
395
|
-
// @ts-ignore
|
|
396
|
-
if (initResult && typeof initResult !== 'boolean' && initResult.then)
|
|
397
|
-
// @ts-ignore
|
|
398
|
-
return promises.push(initResult['catch'](handleError));
|
|
399
|
-
}
|
|
400
|
-
catch (err) {
|
|
401
|
-
handleError(err);
|
|
402
|
-
}
|
|
403
|
-
};
|
|
404
|
-
const promises = mfInstance.initializeSharing(shareScopeKey, {
|
|
405
|
-
strategy: mfInstance.options.shareStrategy,
|
|
406
|
-
initScope,
|
|
407
|
-
from: 'build',
|
|
408
|
-
});
|
|
409
|
-
attachShareScopeMap(webpackRequire);
|
|
410
|
-
const bundlerRuntimeRemotesOptions = webpackRequire.federation.bundlerRuntimeOptions.remotes;
|
|
411
|
-
if (bundlerRuntimeRemotesOptions) {
|
|
412
|
-
Object.keys(bundlerRuntimeRemotesOptions.idToRemoteMap).forEach((moduleId) => {
|
|
413
|
-
const info = bundlerRuntimeRemotesOptions.idToRemoteMap[moduleId];
|
|
414
|
-
const externalModuleId = bundlerRuntimeRemotesOptions.idToExternalAndNameMapping[moduleId][2];
|
|
415
|
-
if (info.length > 1) {
|
|
416
|
-
initExternal(externalModuleId);
|
|
417
|
-
}
|
|
418
|
-
else if (info.length === 1) {
|
|
419
|
-
const remoteInfo = info[0];
|
|
420
|
-
if (!FEDERATION_SUPPORTED_TYPES.includes(remoteInfo.externalType)) {
|
|
421
|
-
initExternal(externalModuleId);
|
|
422
|
-
}
|
|
423
|
-
}
|
|
424
|
-
});
|
|
425
|
-
}
|
|
426
|
-
if (!promises.length) {
|
|
427
|
-
return (initPromises[shareScopeKey] = true);
|
|
428
|
-
}
|
|
429
|
-
return (initPromises[shareScopeKey] = Promise.all(promises).then(() => (initPromises[shareScopeKey] = true)));
|
|
430
|
-
};
|
|
431
|
-
shareScopeKeys.forEach((key) => {
|
|
432
|
-
initializeSharingPromises.push(_initializeSharing(key));
|
|
433
|
-
});
|
|
434
|
-
return Promise.all(initializeSharingPromises).then(() => true);
|
|
435
|
-
}
|
|
436
|
-
|
|
437
|
-
function handleInitialConsumes(options) {
|
|
438
|
-
const { moduleId, moduleToHandlerMapping, webpackRequire, asyncLoad } = options;
|
|
439
|
-
const federationInstance = webpackRequire.federation.instance;
|
|
440
|
-
if (!federationInstance) {
|
|
441
|
-
throw new Error('Federation instance not found!');
|
|
442
|
-
}
|
|
443
|
-
const { shareKey, shareInfo } = moduleToHandlerMapping[moduleId];
|
|
444
|
-
try {
|
|
445
|
-
const usedExports = getUsedExports(webpackRequire, shareKey);
|
|
446
|
-
const customShareInfo = { ...shareInfo };
|
|
447
|
-
if (usedExports) {
|
|
448
|
-
customShareInfo.treeShaking = {
|
|
449
|
-
usedExports,
|
|
450
|
-
useIn: [federationInstance.options.name],
|
|
451
|
-
};
|
|
452
|
-
}
|
|
453
|
-
if (asyncLoad) {
|
|
454
|
-
return federationInstance.loadShare(shareKey, {
|
|
455
|
-
customShareInfo,
|
|
456
|
-
});
|
|
457
|
-
}
|
|
458
|
-
return federationInstance.loadShareSync(shareKey, {
|
|
459
|
-
customShareInfo,
|
|
460
|
-
});
|
|
461
|
-
}
|
|
462
|
-
catch (err) {
|
|
463
|
-
console.error('loadShareSync failed! The function should not be called unless you set "eager:true". If you do not set it, and encounter this issue, you can check whether an async boundary is implemented.');
|
|
464
|
-
console.error('The original error message is as follows: ');
|
|
465
|
-
throw err;
|
|
466
|
-
}
|
|
467
|
-
}
|
|
468
|
-
function installInitialConsumes(options) {
|
|
469
|
-
updateConsumeOptions(options);
|
|
470
|
-
const { moduleToHandlerMapping, webpackRequire, installedModules, initialConsumes, asyncLoad, } = options;
|
|
471
|
-
const factoryIdSets = [];
|
|
472
|
-
initialConsumes.forEach((id) => {
|
|
473
|
-
const factoryGetter = () => handleInitialConsumes({
|
|
474
|
-
moduleId: id,
|
|
475
|
-
moduleToHandlerMapping,
|
|
476
|
-
webpackRequire,
|
|
477
|
-
asyncLoad,
|
|
478
|
-
});
|
|
479
|
-
factoryIdSets.push([id, factoryGetter]);
|
|
480
|
-
});
|
|
481
|
-
const setModule = (id, factoryGetter) => {
|
|
482
|
-
webpackRequire.m[id] = (module) => {
|
|
483
|
-
// Handle scenario when module is used synchronously
|
|
484
|
-
installedModules[id] = 0;
|
|
485
|
-
delete webpackRequire.c[id];
|
|
486
|
-
const factory = factoryGetter();
|
|
487
|
-
if (typeof factory !== 'function') {
|
|
488
|
-
throw new Error(`Shared module is not available for eager consumption: ${id}`);
|
|
489
|
-
}
|
|
490
|
-
const result = factory();
|
|
491
|
-
// Add layer property from shareConfig if available
|
|
492
|
-
const { shareInfo } = moduleToHandlerMapping[id];
|
|
493
|
-
if (shareInfo?.shareConfig?.layer &&
|
|
494
|
-
result &&
|
|
495
|
-
typeof result === 'object') {
|
|
496
|
-
try {
|
|
497
|
-
// Only set layer if it's not already defined or if it's undefined
|
|
498
|
-
if (!result.hasOwnProperty('layer') ||
|
|
499
|
-
result.layer === undefined) {
|
|
500
|
-
result.layer = shareInfo.shareConfig.layer;
|
|
501
|
-
}
|
|
502
|
-
}
|
|
503
|
-
catch (e) {
|
|
504
|
-
// Ignore if layer property is read-only
|
|
505
|
-
}
|
|
506
|
-
}
|
|
507
|
-
module.exports = result;
|
|
508
|
-
};
|
|
509
|
-
};
|
|
510
|
-
if (asyncLoad) {
|
|
511
|
-
return Promise.all(factoryIdSets.map(async ([id, factoryGetter]) => {
|
|
512
|
-
const result = await factoryGetter();
|
|
513
|
-
setModule(id, () => result);
|
|
514
|
-
}));
|
|
515
|
-
}
|
|
516
|
-
factoryIdSets.forEach(([id, factoryGetter]) => {
|
|
517
|
-
setModule(id, factoryGetter);
|
|
518
|
-
});
|
|
519
|
-
}
|
|
520
|
-
|
|
521
|
-
function initContainerEntry(options) {
|
|
522
|
-
const { webpackRequire, shareScope, initScope, shareScopeKey, remoteEntryInitOptions, } = options;
|
|
523
|
-
if (!webpackRequire.S)
|
|
524
|
-
return;
|
|
525
|
-
if (!webpackRequire.federation ||
|
|
526
|
-
!webpackRequire.federation.instance ||
|
|
527
|
-
!webpackRequire.federation.initOptions)
|
|
528
|
-
return;
|
|
529
|
-
const federationInstance = webpackRequire.federation.instance;
|
|
530
|
-
federationInstance.initOptions({
|
|
531
|
-
name: webpackRequire.federation.initOptions.name,
|
|
532
|
-
remotes: [],
|
|
533
|
-
...remoteEntryInitOptions,
|
|
534
|
-
});
|
|
535
|
-
const hostShareScopeKeys = remoteEntryInitOptions?.shareScopeKeys;
|
|
536
|
-
const hostShareScopeMap = remoteEntryInitOptions?.shareScopeMap;
|
|
537
|
-
// host: 'default' remote: 'default' remote['default'] = hostShareScopeMap['default']
|
|
538
|
-
// host: ['default', 'scope1'] remote: 'default' remote['default'] = hostShareScopeMap['default']; remote['scope1'] = hostShareScopeMap['scop1']
|
|
539
|
-
// host: 'default' remote: ['default','scope1'] remote['default'] = hostShareScopeMap['default']; remote['scope1'] = hostShareScopeMap['scope1'] = {}
|
|
540
|
-
// host: ['scope1','default'] remote: ['scope1','scope2'] => remote['scope1'] = hostShareScopeMap['scope1']; remote['scope2'] = hostShareScopeMap['scope2'] = {};
|
|
541
|
-
if (!shareScopeKey || typeof shareScopeKey === 'string') {
|
|
542
|
-
const key = shareScopeKey || 'default';
|
|
543
|
-
if (Array.isArray(hostShareScopeKeys)) {
|
|
544
|
-
// const sc = hostShareScopeMap![key];
|
|
545
|
-
// if (!sc) {
|
|
546
|
-
// throw new Error('shareScopeKey is not exist in hostShareScopeMap');
|
|
547
|
-
// }
|
|
548
|
-
// federationInstance.initShareScopeMap(key, sc, {
|
|
549
|
-
// hostShareScopeMap: remoteEntryInitOptions?.shareScopeMap || {},
|
|
550
|
-
// });
|
|
551
|
-
hostShareScopeKeys.forEach((hostKey) => {
|
|
552
|
-
if (!hostShareScopeMap[hostKey]) {
|
|
553
|
-
hostShareScopeMap[hostKey] = {};
|
|
554
|
-
}
|
|
555
|
-
const sc = hostShareScopeMap[hostKey];
|
|
556
|
-
federationInstance.initShareScopeMap(hostKey, sc, {
|
|
557
|
-
hostShareScopeMap: remoteEntryInitOptions?.shareScopeMap || {},
|
|
558
|
-
});
|
|
559
|
-
});
|
|
560
|
-
}
|
|
561
|
-
else {
|
|
562
|
-
federationInstance.initShareScopeMap(key, shareScope, {
|
|
563
|
-
hostShareScopeMap: remoteEntryInitOptions?.shareScopeMap || {},
|
|
564
|
-
});
|
|
565
|
-
}
|
|
566
|
-
}
|
|
567
|
-
else {
|
|
568
|
-
shareScopeKey.forEach((key) => {
|
|
569
|
-
if (!hostShareScopeKeys || !hostShareScopeMap) {
|
|
570
|
-
federationInstance.initShareScopeMap(key, shareScope, {
|
|
571
|
-
hostShareScopeMap: remoteEntryInitOptions?.shareScopeMap || {},
|
|
572
|
-
});
|
|
573
|
-
return;
|
|
574
|
-
}
|
|
575
|
-
if (!hostShareScopeMap[key]) {
|
|
576
|
-
hostShareScopeMap[key] = {};
|
|
577
|
-
}
|
|
578
|
-
const sc = hostShareScopeMap[key];
|
|
579
|
-
federationInstance.initShareScopeMap(key, sc, {
|
|
580
|
-
hostShareScopeMap: remoteEntryInitOptions?.shareScopeMap || {},
|
|
581
|
-
});
|
|
582
|
-
});
|
|
583
|
-
}
|
|
584
|
-
if (webpackRequire.federation.attachShareScopeMap) {
|
|
585
|
-
webpackRequire.federation.attachShareScopeMap(webpackRequire);
|
|
586
|
-
}
|
|
587
|
-
if (typeof webpackRequire.federation.prefetch === 'function') {
|
|
588
|
-
webpackRequire.federation.prefetch();
|
|
589
|
-
}
|
|
590
|
-
if (!Array.isArray(shareScopeKey)) {
|
|
591
|
-
// @ts-ignore
|
|
592
|
-
return webpackRequire.I(shareScopeKey || 'default', initScope);
|
|
593
|
-
}
|
|
594
|
-
var proxyInitializeSharing = Boolean(webpackRequire.federation.initOptions.shared);
|
|
595
|
-
if (proxyInitializeSharing) {
|
|
596
|
-
// @ts-ignore
|
|
597
|
-
return webpackRequire.I(shareScopeKey, initScope);
|
|
598
|
-
}
|
|
599
|
-
// @ts-ignore
|
|
600
|
-
return Promise.all(shareScopeKey.map((key) => {
|
|
601
|
-
// @ts-ignore
|
|
602
|
-
return webpackRequire.I(key, initScope);
|
|
603
|
-
})).then(() => true);
|
|
604
|
-
}
|
|
605
|
-
|
|
606
|
-
function init({ webpackRequire }) {
|
|
607
|
-
const { initOptions, runtime, sharedFallback, bundlerRuntime, libraryType } = webpackRequire.federation;
|
|
608
|
-
if (!initOptions) {
|
|
609
|
-
throw new Error('initOptions is required!');
|
|
610
|
-
}
|
|
611
|
-
const treeShakingSharePlugin = function () {
|
|
612
|
-
return {
|
|
613
|
-
name: 'tree-shake-plugin',
|
|
614
|
-
beforeInit(args) {
|
|
615
|
-
const { userOptions, origin, options: registeredOptions } = args;
|
|
616
|
-
const version = userOptions.version || registeredOptions.version;
|
|
617
|
-
if (!sharedFallback) {
|
|
618
|
-
return args;
|
|
619
|
-
}
|
|
620
|
-
const currentShared = userOptions.shared || {};
|
|
621
|
-
const shared = [];
|
|
622
|
-
Object.keys(currentShared).forEach((sharedName) => {
|
|
623
|
-
const sharedArgs = Array.isArray(currentShared[sharedName])
|
|
624
|
-
? currentShared[sharedName]
|
|
625
|
-
: [currentShared[sharedName]];
|
|
626
|
-
sharedArgs.forEach((sharedArg) => {
|
|
627
|
-
shared.push([sharedName, sharedArg]);
|
|
628
|
-
if ('get' in sharedArg) {
|
|
629
|
-
sharedArg.treeShaking ||= {};
|
|
630
|
-
sharedArg.treeShaking.get = sharedArg.get;
|
|
631
|
-
sharedArg.get = bundlerRuntime.getSharedFallbackGetter({
|
|
632
|
-
shareKey: sharedName,
|
|
633
|
-
factory: sharedArg.get,
|
|
634
|
-
webpackRequire,
|
|
635
|
-
libraryType,
|
|
636
|
-
version: sharedArg.version,
|
|
637
|
-
});
|
|
638
|
-
}
|
|
639
|
-
});
|
|
640
|
-
});
|
|
641
|
-
// read snapshot to override re-shake getter
|
|
642
|
-
const hostGlobalSnapshot = helpers.global.getGlobalSnapshotInfoByModuleInfo({
|
|
643
|
-
name: origin.name,
|
|
644
|
-
version: version,
|
|
645
|
-
});
|
|
646
|
-
if (!hostGlobalSnapshot || !('shared' in hostGlobalSnapshot)) {
|
|
647
|
-
return args;
|
|
648
|
-
}
|
|
649
|
-
Object.keys(registeredOptions.shared || {}).forEach((pkgName) => {
|
|
650
|
-
const sharedInfo = registeredOptions.shared[pkgName];
|
|
651
|
-
sharedInfo.forEach((sharedArg) => {
|
|
652
|
-
shared.push([pkgName, sharedArg]);
|
|
653
|
-
});
|
|
654
|
-
});
|
|
655
|
-
const patchShared = (pkgName, shared) => {
|
|
656
|
-
const shareSnapshot = hostGlobalSnapshot.shared.find((item) => item.sharedName === pkgName);
|
|
657
|
-
if (!shareSnapshot) {
|
|
658
|
-
return;
|
|
659
|
-
}
|
|
660
|
-
const { treeShaking } = shared;
|
|
661
|
-
if (!treeShaking) {
|
|
662
|
-
return;
|
|
663
|
-
}
|
|
664
|
-
const { secondarySharedTreeShakingName, secondarySharedTreeShakingEntry, treeShakingStatus, } = shareSnapshot;
|
|
665
|
-
if (treeShaking.status === treeShakingStatus) {
|
|
666
|
-
return;
|
|
667
|
-
}
|
|
668
|
-
treeShaking.status = treeShakingStatus;
|
|
669
|
-
if (secondarySharedTreeShakingEntry &&
|
|
670
|
-
libraryType &&
|
|
671
|
-
secondarySharedTreeShakingName) {
|
|
672
|
-
treeShaking.get = async () => {
|
|
673
|
-
const shareEntry = await getRemoteEntry({
|
|
674
|
-
origin,
|
|
675
|
-
remoteInfo: {
|
|
676
|
-
name: secondarySharedTreeShakingName,
|
|
677
|
-
entry: secondarySharedTreeShakingEntry,
|
|
678
|
-
type: libraryType,
|
|
679
|
-
entryGlobalName: secondarySharedTreeShakingName,
|
|
680
|
-
// current not used
|
|
681
|
-
shareScope: 'default',
|
|
682
|
-
},
|
|
683
|
-
});
|
|
684
|
-
// TODO: add errorLoad hook ?
|
|
685
|
-
// @ts-ignore
|
|
686
|
-
await shareEntry.init(origin,
|
|
687
|
-
// @ts-ignore
|
|
688
|
-
__webpack_require__.federation.bundlerRuntime);
|
|
689
|
-
// @ts-ignore
|
|
690
|
-
const getter = shareEntry.get();
|
|
691
|
-
return getter;
|
|
692
|
-
};
|
|
693
|
-
}
|
|
694
|
-
};
|
|
695
|
-
shared.forEach(([pkgName, sharedArg]) => {
|
|
696
|
-
patchShared(pkgName, sharedArg);
|
|
697
|
-
});
|
|
698
|
-
return args;
|
|
699
|
-
},
|
|
700
|
-
};
|
|
701
|
-
};
|
|
702
|
-
initOptions.plugins ||= [];
|
|
703
|
-
initOptions.plugins.push(treeShakingSharePlugin());
|
|
704
|
-
return runtime.init(initOptions);
|
|
705
|
-
}
|
|
706
|
-
|
|
707
|
-
const getSharedFallbackGetter = ({ shareKey, factory, version, webpackRequire, libraryType = 'global', }) => {
|
|
708
|
-
const { runtime, instance, bundlerRuntime, sharedFallback } = webpackRequire.federation;
|
|
709
|
-
if (!sharedFallback) {
|
|
710
|
-
return factory;
|
|
711
|
-
}
|
|
712
|
-
// { react: [ [ react/19.0.0/index.js , 19.0.0, react_global_name, var ] ] }
|
|
713
|
-
const fallbackItems = sharedFallback[shareKey];
|
|
714
|
-
if (!fallbackItems) {
|
|
715
|
-
return factory;
|
|
716
|
-
}
|
|
717
|
-
const fallbackItem = version
|
|
718
|
-
? fallbackItems.find((item) => item[1] === version)
|
|
719
|
-
: fallbackItems[0];
|
|
720
|
-
if (!fallbackItem) {
|
|
721
|
-
throw new Error(`No fallback item found for shareKey: ${shareKey} and version: ${version}`);
|
|
722
|
-
}
|
|
723
|
-
return () => runtime
|
|
724
|
-
.getRemoteEntry({
|
|
725
|
-
origin: webpackRequire.federation.instance,
|
|
726
|
-
remoteInfo: {
|
|
727
|
-
name: fallbackItem[2],
|
|
728
|
-
entry: `${webpackRequire.p}${fallbackItem[0]}`,
|
|
729
|
-
type: libraryType,
|
|
730
|
-
entryGlobalName: fallbackItem[2],
|
|
731
|
-
// current not used
|
|
732
|
-
shareScope: 'default',
|
|
733
|
-
},
|
|
734
|
-
})
|
|
735
|
-
// @ts-ignore
|
|
736
|
-
.then((shareEntry) => {
|
|
737
|
-
if (!shareEntry) {
|
|
738
|
-
throw new Error(`Failed to load fallback entry for shareKey: ${shareKey} and version: ${version}`);
|
|
739
|
-
}
|
|
740
|
-
return (shareEntry
|
|
741
|
-
// @ts-ignore
|
|
742
|
-
.init(webpackRequire.federation.instance, bundlerRuntime)
|
|
743
|
-
// @ts-ignore
|
|
744
|
-
.then(() => shareEntry.get()));
|
|
745
|
-
});
|
|
746
|
-
};
|
|
747
|
-
|
|
748
|
-
const federation = {
|
|
749
|
-
runtime,
|
|
750
|
-
instance: undefined,
|
|
751
|
-
initOptions: undefined,
|
|
752
|
-
bundlerRuntime: {
|
|
753
|
-
remotes,
|
|
754
|
-
consumes,
|
|
755
|
-
I: initializeSharing,
|
|
756
|
-
S: {},
|
|
757
|
-
installInitialConsumes,
|
|
758
|
-
initContainerEntry,
|
|
759
|
-
init,
|
|
760
|
-
getSharedFallbackGetter,
|
|
761
|
-
},
|
|
762
|
-
attachShareScopeMap,
|
|
763
|
-
bundlerRuntimeOptions: {},
|
|
764
|
-
};
|
|
765
|
-
|
|
766
|
-
export { federation as default };
|
|
767
|
-
//# sourceMappingURL=index.esm.js.map
|