@module-federation/webpack-bundler-runtime 0.19.1 → 0.21.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/constant.cjs.cjs +1 -3
- package/dist/constant.cjs.cjs.map +1 -1
- package/dist/constant.esm.js +1 -3
- package/dist/constant.esm.js.map +1 -1
- package/dist/index.cjs.cjs +282 -112
- package/dist/index.cjs.cjs.map +1 -1
- package/dist/index.esm.js +282 -112
- package/dist/index.esm.js.map +1 -1
- package/dist/src/types.d.ts +68 -10
- package/dist/src/updateOptions.d.ts +3 -0
- package/package.json +4 -4
package/dist/index.esm.js
CHANGED
|
@@ -3,24 +3,168 @@ import { FEDERATION_SUPPORTED_TYPES } from './constant.esm.js';
|
|
|
3
3
|
import { decodeName, ENCODE_NAME_PREFIX } from '@module-federation/sdk';
|
|
4
4
|
|
|
5
5
|
function attachShareScopeMap(webpackRequire) {
|
|
6
|
-
if (!webpackRequire.S ||
|
|
6
|
+
if (!webpackRequire.S ||
|
|
7
|
+
webpackRequire.federation.hasAttachShareScopeMap ||
|
|
8
|
+
!webpackRequire.federation.instance ||
|
|
9
|
+
!webpackRequire.federation.instance.shareScopeMap) {
|
|
7
10
|
return;
|
|
8
11
|
}
|
|
9
12
|
webpackRequire.S = webpackRequire.federation.instance.shareScopeMap;
|
|
10
13
|
webpackRequire.federation.hasAttachShareScopeMap = true;
|
|
11
14
|
}
|
|
12
15
|
|
|
16
|
+
function updateConsumeOptions(options) {
|
|
17
|
+
const { webpackRequire, moduleToHandlerMapping } = options;
|
|
18
|
+
const { consumesLoadingData, initializeSharingData } = webpackRequire;
|
|
19
|
+
if (consumesLoadingData && !consumesLoadingData._updated) {
|
|
20
|
+
const { moduleIdToConsumeDataMapping: updatedModuleIdToConsumeDataMapping = {}, initialConsumes: updatedInitialConsumes = [], chunkMapping: updatedChunkMapping = {}, } = consumesLoadingData;
|
|
21
|
+
Object.entries(updatedModuleIdToConsumeDataMapping).forEach(([id, data]) => {
|
|
22
|
+
if (!moduleToHandlerMapping[id]) {
|
|
23
|
+
moduleToHandlerMapping[id] = {
|
|
24
|
+
getter: data.fallback,
|
|
25
|
+
shareInfo: {
|
|
26
|
+
shareConfig: {
|
|
27
|
+
requiredVersion: data.requiredVersion,
|
|
28
|
+
strictVersion: data.strictVersion,
|
|
29
|
+
singleton: data.singleton,
|
|
30
|
+
eager: data.eager,
|
|
31
|
+
layer: data.layer,
|
|
32
|
+
},
|
|
33
|
+
scope: Array.isArray(data.shareScope)
|
|
34
|
+
? data.shareScope
|
|
35
|
+
: [data.shareScope || 'default'],
|
|
36
|
+
},
|
|
37
|
+
shareKey: data.shareKey,
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
if ('initialConsumes' in options) {
|
|
42
|
+
const { initialConsumes = [] } = options;
|
|
43
|
+
updatedInitialConsumes.forEach((id) => {
|
|
44
|
+
if (!initialConsumes.includes(id)) {
|
|
45
|
+
initialConsumes.push(id);
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
if ('chunkMapping' in options) {
|
|
50
|
+
const { chunkMapping = {} } = options;
|
|
51
|
+
Object.entries(updatedChunkMapping).forEach(([id, chunkModules]) => {
|
|
52
|
+
if (!chunkMapping[id]) {
|
|
53
|
+
chunkMapping[id] = [];
|
|
54
|
+
}
|
|
55
|
+
chunkModules.forEach((moduleId) => {
|
|
56
|
+
if (!chunkMapping[id].includes(moduleId)) {
|
|
57
|
+
chunkMapping[id].push(moduleId);
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
consumesLoadingData._updated = 1;
|
|
63
|
+
}
|
|
64
|
+
if (initializeSharingData && !initializeSharingData._updated) {
|
|
65
|
+
const { federation } = webpackRequire;
|
|
66
|
+
if (!federation.instance ||
|
|
67
|
+
!initializeSharingData.scopeToSharingDataMapping) {
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
const shared = {};
|
|
71
|
+
for (let [scope, stages] of Object.entries(initializeSharingData.scopeToSharingDataMapping)) {
|
|
72
|
+
for (let stage of stages) {
|
|
73
|
+
if (typeof stage === 'object' && stage !== null) {
|
|
74
|
+
const { name, version, factory, eager, singleton, requiredVersion, strictVersion, } = stage;
|
|
75
|
+
const shareConfig = {
|
|
76
|
+
requiredVersion: `^${version}`,
|
|
77
|
+
};
|
|
78
|
+
const isValidValue = function (val) {
|
|
79
|
+
return typeof val !== 'undefined';
|
|
80
|
+
};
|
|
81
|
+
if (isValidValue(singleton)) {
|
|
82
|
+
shareConfig.singleton = singleton;
|
|
83
|
+
}
|
|
84
|
+
if (isValidValue(requiredVersion)) {
|
|
85
|
+
shareConfig.requiredVersion = requiredVersion;
|
|
86
|
+
}
|
|
87
|
+
if (isValidValue(eager)) {
|
|
88
|
+
shareConfig.eager = eager;
|
|
89
|
+
}
|
|
90
|
+
if (isValidValue(strictVersion)) {
|
|
91
|
+
shareConfig.strictVersion = strictVersion;
|
|
92
|
+
}
|
|
93
|
+
const options = {
|
|
94
|
+
version,
|
|
95
|
+
scope: [scope],
|
|
96
|
+
shareConfig,
|
|
97
|
+
get: factory,
|
|
98
|
+
};
|
|
99
|
+
if (shared[name]) {
|
|
100
|
+
shared[name].push(options);
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
shared[name] = [options];
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
federation.instance.registerShared(shared);
|
|
109
|
+
initializeSharingData._updated = 1;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
function updateRemoteOptions(options) {
|
|
113
|
+
const { webpackRequire, idToExternalAndNameMapping = {}, idToRemoteMap = {}, chunkMapping = {}, } = options;
|
|
114
|
+
const { remotesLoadingData } = webpackRequire;
|
|
115
|
+
const remoteInfos = webpackRequire.federation?.bundlerRuntimeOptions?.remotes?.remoteInfos;
|
|
116
|
+
if (!remotesLoadingData || remotesLoadingData._updated || !remoteInfos) {
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
const { chunkMapping: updatedChunkMapping, moduleIdToRemoteDataMapping } = remotesLoadingData;
|
|
120
|
+
if (!updatedChunkMapping || !moduleIdToRemoteDataMapping) {
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
for (let [moduleId, data] of Object.entries(moduleIdToRemoteDataMapping)) {
|
|
124
|
+
if (!idToExternalAndNameMapping[moduleId]) {
|
|
125
|
+
idToExternalAndNameMapping[moduleId] = [
|
|
126
|
+
data.shareScope,
|
|
127
|
+
data.name,
|
|
128
|
+
data.externalModuleId,
|
|
129
|
+
];
|
|
130
|
+
}
|
|
131
|
+
if (!idToRemoteMap[moduleId] && remoteInfos[data.remoteName]) {
|
|
132
|
+
const items = remoteInfos[data.remoteName];
|
|
133
|
+
idToRemoteMap[moduleId] ||= [];
|
|
134
|
+
items.forEach((item) => {
|
|
135
|
+
if (!idToRemoteMap[moduleId].includes(item)) {
|
|
136
|
+
idToRemoteMap[moduleId].push(item);
|
|
137
|
+
}
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
if (chunkMapping) {
|
|
142
|
+
Object.entries(updatedChunkMapping).forEach(([id, chunkModules]) => {
|
|
143
|
+
if (!chunkMapping[id]) {
|
|
144
|
+
chunkMapping[id] = [];
|
|
145
|
+
}
|
|
146
|
+
chunkModules.forEach((moduleId) => {
|
|
147
|
+
if (!chunkMapping[id].includes(moduleId)) {
|
|
148
|
+
chunkMapping[id].push(moduleId);
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
remotesLoadingData._updated = 1;
|
|
154
|
+
}
|
|
155
|
+
|
|
13
156
|
function remotes(options) {
|
|
14
|
-
|
|
157
|
+
updateRemoteOptions(options);
|
|
158
|
+
const { chunkId, promises, webpackRequire, chunkMapping, idToExternalAndNameMapping, idToRemoteMap, } = options;
|
|
15
159
|
attachShareScopeMap(webpackRequire);
|
|
16
160
|
if (webpackRequire.o(chunkMapping, chunkId)) {
|
|
17
|
-
chunkMapping[chunkId].forEach((id)=>{
|
|
161
|
+
chunkMapping[chunkId].forEach((id) => {
|
|
18
162
|
let getScope = webpackRequire.R;
|
|
19
163
|
if (!getScope) {
|
|
20
164
|
getScope = [];
|
|
21
165
|
}
|
|
22
166
|
const data = idToExternalAndNameMapping[id];
|
|
23
|
-
const remoteInfos = idToRemoteMap[id];
|
|
167
|
+
const remoteInfos = idToRemoteMap[id] || [];
|
|
24
168
|
// @ts-ignore seems not work
|
|
25
169
|
if (getScope.indexOf(data) >= 0) {
|
|
26
170
|
return;
|
|
@@ -30,68 +174,77 @@ function remotes(options) {
|
|
|
30
174
|
if (data.p) {
|
|
31
175
|
return promises.push(data.p);
|
|
32
176
|
}
|
|
33
|
-
const onError = (error)=>{
|
|
177
|
+
const onError = (error) => {
|
|
34
178
|
if (!error) {
|
|
35
179
|
error = new Error('Container missing');
|
|
36
180
|
}
|
|
37
181
|
if (typeof error.message === 'string') {
|
|
38
182
|
error.message += `\nwhile loading "${data[1]}" from ${data[2]}`;
|
|
39
183
|
}
|
|
40
|
-
webpackRequire.m[id] = ()=>{
|
|
184
|
+
webpackRequire.m[id] = () => {
|
|
41
185
|
throw error;
|
|
42
186
|
};
|
|
43
187
|
data.p = 0;
|
|
44
188
|
};
|
|
45
|
-
const handleFunction = (fn, arg1, arg2, d, next, first)=>{
|
|
189
|
+
const handleFunction = (fn, arg1, arg2, d, next, first) => {
|
|
46
190
|
try {
|
|
47
191
|
const promise = fn(arg1, arg2);
|
|
48
192
|
if (promise && promise.then) {
|
|
49
|
-
const p = promise.then((result)=>next(result, d), onError);
|
|
193
|
+
const p = promise.then((result) => next(result, d), onError);
|
|
50
194
|
if (first) {
|
|
51
|
-
promises.push(data.p = p);
|
|
52
|
-
}
|
|
195
|
+
promises.push((data.p = p));
|
|
196
|
+
}
|
|
197
|
+
else {
|
|
53
198
|
return p;
|
|
54
199
|
}
|
|
55
|
-
}
|
|
200
|
+
}
|
|
201
|
+
else {
|
|
56
202
|
return next(promise, d, first);
|
|
57
203
|
}
|
|
58
|
-
}
|
|
204
|
+
}
|
|
205
|
+
catch (error) {
|
|
59
206
|
onError(error);
|
|
60
207
|
}
|
|
61
208
|
};
|
|
62
|
-
const onExternal = (external, _, first)=>
|
|
209
|
+
const onExternal = (external, _, first) => external
|
|
210
|
+
? handleFunction(webpackRequire.I, data[0], 0, external, onInitialized, first)
|
|
211
|
+
: onError();
|
|
63
212
|
// eslint-disable-next-line no-var
|
|
64
|
-
var onInitialized = (_, external, first)=>handleFunction(external.get, data[1], getScope, 0, onFactory, first);
|
|
213
|
+
var onInitialized = (_, external, first) => handleFunction(external.get, data[1], getScope, 0, onFactory, first);
|
|
65
214
|
// eslint-disable-next-line no-var
|
|
66
|
-
var onFactory = (factory)=>{
|
|
215
|
+
var onFactory = (factory) => {
|
|
67
216
|
data.p = 1;
|
|
68
|
-
webpackRequire.m[id] = (module)=>{
|
|
217
|
+
webpackRequire.m[id] = (module) => {
|
|
69
218
|
module.exports = factory();
|
|
70
219
|
};
|
|
71
220
|
};
|
|
72
|
-
const onRemoteLoaded = ()=>{
|
|
221
|
+
const onRemoteLoaded = () => {
|
|
73
222
|
try {
|
|
74
223
|
const remoteName = decodeName(remoteInfos[0].name, ENCODE_NAME_PREFIX);
|
|
75
224
|
const remoteModuleName = remoteName + data[1].slice(1);
|
|
76
225
|
const instance = webpackRequire.federation.instance;
|
|
77
|
-
const loadRemote = ()=>webpackRequire.federation.instance.loadRemote(remoteModuleName, {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
226
|
+
const loadRemote = () => webpackRequire.federation.instance.loadRemote(remoteModuleName, {
|
|
227
|
+
loadFactory: false,
|
|
228
|
+
from: 'build',
|
|
229
|
+
});
|
|
81
230
|
if (instance.options.shareStrategy === 'version-first') {
|
|
82
|
-
return Promise.all(instance.sharedHandler.initializeSharing(data[0])).then(()=>{
|
|
231
|
+
return Promise.all(instance.sharedHandler.initializeSharing(data[0])).then(() => {
|
|
83
232
|
return loadRemote();
|
|
84
233
|
});
|
|
85
234
|
}
|
|
86
235
|
return loadRemote();
|
|
87
|
-
}
|
|
236
|
+
}
|
|
237
|
+
catch (error) {
|
|
88
238
|
onError(error);
|
|
89
239
|
}
|
|
90
240
|
};
|
|
91
|
-
const useRuntimeLoad = remoteInfos.length === 1 &&
|
|
241
|
+
const useRuntimeLoad = remoteInfos.length === 1 &&
|
|
242
|
+
FEDERATION_SUPPORTED_TYPES.includes(remoteInfos[0].externalType) &&
|
|
243
|
+
remoteInfos[0].name;
|
|
92
244
|
if (useRuntimeLoad) {
|
|
93
245
|
handleFunction(onRemoteLoaded, data[2], 0, 0, onFactory, 1);
|
|
94
|
-
}
|
|
246
|
+
}
|
|
247
|
+
else {
|
|
95
248
|
handleFunction(webpackRequire, data[2], 0, 0, onExternal, 1);
|
|
96
249
|
}
|
|
97
250
|
});
|
|
@@ -99,37 +252,41 @@ function remotes(options) {
|
|
|
99
252
|
}
|
|
100
253
|
|
|
101
254
|
function consumes(options) {
|
|
102
|
-
|
|
255
|
+
updateConsumeOptions(options);
|
|
256
|
+
const { chunkId, promises, installedModules, webpackRequire, chunkMapping, moduleToHandlerMapping, } = options;
|
|
103
257
|
attachShareScopeMap(webpackRequire);
|
|
104
258
|
if (webpackRequire.o(chunkMapping, chunkId)) {
|
|
105
|
-
chunkMapping[chunkId].forEach((id)=>{
|
|
259
|
+
chunkMapping[chunkId].forEach((id) => {
|
|
106
260
|
if (webpackRequire.o(installedModules, id)) {
|
|
107
261
|
return promises.push(installedModules[id]);
|
|
108
262
|
}
|
|
109
|
-
const onFactory = (factory)=>{
|
|
263
|
+
const onFactory = (factory) => {
|
|
110
264
|
installedModules[id] = 0;
|
|
111
|
-
webpackRequire.m[id] = (module)=>{
|
|
112
|
-
var _shareInfo_shareConfig;
|
|
265
|
+
webpackRequire.m[id] = (module) => {
|
|
113
266
|
delete webpackRequire.c[id];
|
|
114
267
|
const result = factory();
|
|
115
268
|
// Add layer property from shareConfig if available
|
|
116
269
|
const { shareInfo } = moduleToHandlerMapping[id];
|
|
117
|
-
if (
|
|
270
|
+
if (shareInfo?.shareConfig?.layer &&
|
|
271
|
+
result &&
|
|
272
|
+
typeof result === 'object') {
|
|
118
273
|
try {
|
|
119
274
|
// Only set layer if it's not already defined or if it's undefined
|
|
120
|
-
if (!result.hasOwnProperty('layer') ||
|
|
275
|
+
if (!result.hasOwnProperty('layer') ||
|
|
276
|
+
result.layer === undefined) {
|
|
121
277
|
result.layer = shareInfo.shareConfig.layer;
|
|
122
278
|
}
|
|
123
|
-
}
|
|
124
|
-
|
|
279
|
+
}
|
|
280
|
+
catch (e) {
|
|
281
|
+
// Ignore if layer property is read-only
|
|
125
282
|
}
|
|
126
283
|
}
|
|
127
284
|
module.exports = result;
|
|
128
285
|
};
|
|
129
286
|
};
|
|
130
|
-
const onError = (error)=>{
|
|
287
|
+
const onError = (error) => {
|
|
131
288
|
delete installedModules[id];
|
|
132
|
-
webpackRequire.m[id] = (module)=>{
|
|
289
|
+
webpackRequire.m[id] = (module) => {
|
|
133
290
|
delete webpackRequire.c[id];
|
|
134
291
|
throw error;
|
|
135
292
|
};
|
|
@@ -140,78 +297,89 @@ function consumes(options) {
|
|
|
140
297
|
throw new Error('Federation instance not found!');
|
|
141
298
|
}
|
|
142
299
|
const { shareKey, getter, shareInfo } = moduleToHandlerMapping[id];
|
|
143
|
-
const promise = federationInstance
|
|
144
|
-
customShareInfo: shareInfo
|
|
145
|
-
|
|
300
|
+
const promise = federationInstance
|
|
301
|
+
.loadShare(shareKey, { customShareInfo: shareInfo })
|
|
302
|
+
.then((factory) => {
|
|
146
303
|
if (factory === false) {
|
|
147
304
|
return getter();
|
|
148
305
|
}
|
|
149
306
|
return factory;
|
|
150
307
|
});
|
|
151
308
|
if (promise.then) {
|
|
152
|
-
promises.push(installedModules[id] = promise.then(onFactory).catch(onError));
|
|
153
|
-
}
|
|
309
|
+
promises.push((installedModules[id] = promise.then(onFactory).catch(onError)));
|
|
310
|
+
}
|
|
311
|
+
else {
|
|
154
312
|
// @ts-ignore maintain previous logic
|
|
155
313
|
onFactory(promise);
|
|
156
314
|
}
|
|
157
|
-
}
|
|
315
|
+
}
|
|
316
|
+
catch (e) {
|
|
158
317
|
onError(e);
|
|
159
318
|
}
|
|
160
319
|
});
|
|
161
320
|
}
|
|
162
321
|
}
|
|
163
322
|
|
|
164
|
-
function initializeSharing({ shareScopeName, webpackRequire, initPromises, initTokens, initScope }) {
|
|
165
|
-
const shareScopeKeys = Array.isArray(shareScopeName)
|
|
166
|
-
shareScopeName
|
|
167
|
-
|
|
323
|
+
function initializeSharing({ shareScopeName, webpackRequire, initPromises, initTokens, initScope, }) {
|
|
324
|
+
const shareScopeKeys = Array.isArray(shareScopeName)
|
|
325
|
+
? shareScopeName
|
|
326
|
+
: [shareScopeName];
|
|
168
327
|
var initializeSharingPromises = [];
|
|
169
|
-
var _initializeSharing = function(shareScopeKey) {
|
|
170
|
-
if (!initScope)
|
|
328
|
+
var _initializeSharing = function (shareScopeKey) {
|
|
329
|
+
if (!initScope)
|
|
330
|
+
initScope = [];
|
|
171
331
|
const mfInstance = webpackRequire.federation.instance;
|
|
172
332
|
// handling circular init calls
|
|
173
333
|
var initToken = initTokens[shareScopeKey];
|
|
174
|
-
if (!initToken)
|
|
175
|
-
from: mfInstance.name
|
|
176
|
-
|
|
177
|
-
|
|
334
|
+
if (!initToken)
|
|
335
|
+
initToken = initTokens[shareScopeKey] = { from: mfInstance.name };
|
|
336
|
+
if (initScope.indexOf(initToken) >= 0)
|
|
337
|
+
return;
|
|
178
338
|
initScope.push(initToken);
|
|
179
339
|
const promise = initPromises[shareScopeKey];
|
|
180
|
-
if (promise)
|
|
181
|
-
|
|
182
|
-
var
|
|
183
|
-
|
|
340
|
+
if (promise)
|
|
341
|
+
return promise;
|
|
342
|
+
var warn = (msg) => typeof console !== 'undefined' && console.warn && console.warn(msg);
|
|
343
|
+
var initExternal = (id) => {
|
|
344
|
+
var handleError = (err) => warn('Initialization of sharing external failed: ' + err);
|
|
184
345
|
try {
|
|
185
346
|
var module = webpackRequire(id);
|
|
186
|
-
if (!module)
|
|
187
|
-
|
|
347
|
+
if (!module)
|
|
348
|
+
return;
|
|
349
|
+
var initFn = (module) => module &&
|
|
350
|
+
module.init &&
|
|
351
|
+
// @ts-ignore compat legacy mf shared behavior
|
|
188
352
|
module.init(webpackRequire.S[shareScopeKey], initScope, {
|
|
189
353
|
shareScopeMap: webpackRequire.S || {},
|
|
190
|
-
shareScopeKeys: shareScopeName
|
|
354
|
+
shareScopeKeys: shareScopeName,
|
|
191
355
|
});
|
|
192
|
-
if (module.then)
|
|
356
|
+
if (module.then)
|
|
357
|
+
return promises.push(module.then(initFn, handleError));
|
|
193
358
|
var initResult = initFn(module);
|
|
194
359
|
// @ts-ignore
|
|
195
|
-
if (initResult && typeof initResult !== 'boolean' && initResult.then)
|
|
196
|
-
|
|
197
|
-
|
|
360
|
+
if (initResult && typeof initResult !== 'boolean' && initResult.then)
|
|
361
|
+
// @ts-ignore
|
|
362
|
+
return promises.push(initResult['catch'](handleError));
|
|
363
|
+
}
|
|
364
|
+
catch (err) {
|
|
198
365
|
handleError(err);
|
|
199
366
|
}
|
|
200
367
|
};
|
|
201
368
|
const promises = mfInstance.initializeSharing(shareScopeKey, {
|
|
202
369
|
strategy: mfInstance.options.shareStrategy,
|
|
203
370
|
initScope,
|
|
204
|
-
from: 'build'
|
|
371
|
+
from: 'build',
|
|
205
372
|
});
|
|
206
373
|
attachShareScopeMap(webpackRequire);
|
|
207
374
|
const bundlerRuntimeRemotesOptions = webpackRequire.federation.bundlerRuntimeOptions.remotes;
|
|
208
375
|
if (bundlerRuntimeRemotesOptions) {
|
|
209
|
-
Object.keys(bundlerRuntimeRemotesOptions.idToRemoteMap).forEach((moduleId)=>{
|
|
376
|
+
Object.keys(bundlerRuntimeRemotesOptions.idToRemoteMap).forEach((moduleId) => {
|
|
210
377
|
const info = bundlerRuntimeRemotesOptions.idToRemoteMap[moduleId];
|
|
211
378
|
const externalModuleId = bundlerRuntimeRemotesOptions.idToExternalAndNameMapping[moduleId][2];
|
|
212
379
|
if (info.length > 1) {
|
|
213
380
|
initExternal(externalModuleId);
|
|
214
|
-
}
|
|
381
|
+
}
|
|
382
|
+
else if (info.length === 1) {
|
|
215
383
|
const remoteInfo = info[0];
|
|
216
384
|
if (!FEDERATION_SUPPORTED_TYPES.includes(remoteInfo.externalType)) {
|
|
217
385
|
initExternal(externalModuleId);
|
|
@@ -220,14 +388,14 @@ function initializeSharing({ shareScopeName, webpackRequire, initPromises, initT
|
|
|
220
388
|
});
|
|
221
389
|
}
|
|
222
390
|
if (!promises.length) {
|
|
223
|
-
return initPromises[shareScopeKey] = true;
|
|
391
|
+
return (initPromises[shareScopeKey] = true);
|
|
224
392
|
}
|
|
225
|
-
return initPromises[shareScopeKey] = Promise.all(promises).then(()=>initPromises[shareScopeKey] = true);
|
|
393
|
+
return (initPromises[shareScopeKey] = Promise.all(promises).then(() => (initPromises[shareScopeKey] = true)));
|
|
226
394
|
};
|
|
227
|
-
shareScopeKeys.forEach((key)=>{
|
|
395
|
+
shareScopeKeys.forEach((key) => {
|
|
228
396
|
initializeSharingPromises.push(_initializeSharing(key));
|
|
229
397
|
});
|
|
230
|
-
return Promise.all(initializeSharingPromises).then(()=>true);
|
|
398
|
+
return Promise.all(initializeSharingPromises).then(() => true);
|
|
231
399
|
}
|
|
232
400
|
|
|
233
401
|
function handleInitialConsumes(options) {
|
|
@@ -239,26 +407,28 @@ function handleInitialConsumes(options) {
|
|
|
239
407
|
const { shareKey, shareInfo } = moduleToHandlerMapping[moduleId];
|
|
240
408
|
try {
|
|
241
409
|
return federationInstance.loadShareSync(shareKey, {
|
|
242
|
-
customShareInfo: shareInfo
|
|
410
|
+
customShareInfo: shareInfo,
|
|
243
411
|
});
|
|
244
|
-
}
|
|
412
|
+
}
|
|
413
|
+
catch (err) {
|
|
245
414
|
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.');
|
|
246
415
|
console.error('The original error message is as follows: ');
|
|
247
416
|
throw err;
|
|
248
417
|
}
|
|
249
418
|
}
|
|
250
419
|
function installInitialConsumes(options) {
|
|
251
|
-
const {
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
420
|
+
const { webpackRequire } = options;
|
|
421
|
+
updateConsumeOptions(options);
|
|
422
|
+
const { initialConsumes, moduleToHandlerMapping, installedModules } = options;
|
|
423
|
+
initialConsumes.forEach((id) => {
|
|
424
|
+
webpackRequire.m[id] = (module) => {
|
|
255
425
|
// Handle scenario when module is used synchronously
|
|
256
426
|
installedModules[id] = 0;
|
|
257
427
|
delete webpackRequire.c[id];
|
|
258
428
|
const factory = handleInitialConsumes({
|
|
259
429
|
moduleId: id,
|
|
260
430
|
moduleToHandlerMapping,
|
|
261
|
-
webpackRequire
|
|
431
|
+
webpackRequire,
|
|
262
432
|
});
|
|
263
433
|
if (typeof factory !== 'function') {
|
|
264
434
|
throw new Error(`Shared module is not available for eager consumption: ${id}`);
|
|
@@ -266,14 +436,18 @@ function installInitialConsumes(options) {
|
|
|
266
436
|
const result = factory();
|
|
267
437
|
// Add layer property from shareConfig if available
|
|
268
438
|
const { shareInfo } = moduleToHandlerMapping[id];
|
|
269
|
-
if (
|
|
439
|
+
if (shareInfo?.shareConfig?.layer &&
|
|
440
|
+
result &&
|
|
441
|
+
typeof result === 'object') {
|
|
270
442
|
try {
|
|
271
443
|
// Only set layer if it's not already defined or if it's undefined
|
|
272
|
-
if (!result.hasOwnProperty('layer') ||
|
|
444
|
+
if (!result.hasOwnProperty('layer') ||
|
|
445
|
+
result.layer === undefined) {
|
|
273
446
|
result.layer = shareInfo.shareConfig.layer;
|
|
274
447
|
}
|
|
275
|
-
}
|
|
276
|
-
|
|
448
|
+
}
|
|
449
|
+
catch (e) {
|
|
450
|
+
// Ignore if layer property is read-only
|
|
277
451
|
}
|
|
278
452
|
}
|
|
279
453
|
module.exports = result;
|
|
@@ -281,28 +455,22 @@ function installInitialConsumes(options) {
|
|
|
281
455
|
});
|
|
282
456
|
}
|
|
283
457
|
|
|
284
|
-
function _extends() {
|
|
285
|
-
_extends = Object.assign || function assign(target) {
|
|
286
|
-
for(var i = 1; i < arguments.length; i++){
|
|
287
|
-
var source = arguments[i];
|
|
288
|
-
for(var key in source)if (Object.prototype.hasOwnProperty.call(source, key)) target[key] = source[key];
|
|
289
|
-
}
|
|
290
|
-
return target;
|
|
291
|
-
};
|
|
292
|
-
return _extends.apply(this, arguments);
|
|
293
|
-
}
|
|
294
|
-
|
|
295
458
|
function initContainerEntry(options) {
|
|
296
|
-
const { webpackRequire, shareScope, initScope, shareScopeKey, remoteEntryInitOptions } = options;
|
|
297
|
-
if (!webpackRequire.S)
|
|
298
|
-
|
|
459
|
+
const { webpackRequire, shareScope, initScope, shareScopeKey, remoteEntryInitOptions, } = options;
|
|
460
|
+
if (!webpackRequire.S)
|
|
461
|
+
return;
|
|
462
|
+
if (!webpackRequire.federation ||
|
|
463
|
+
!webpackRequire.federation.instance ||
|
|
464
|
+
!webpackRequire.federation.initOptions)
|
|
465
|
+
return;
|
|
299
466
|
const federationInstance = webpackRequire.federation.instance;
|
|
300
|
-
federationInstance.initOptions(
|
|
467
|
+
federationInstance.initOptions({
|
|
301
468
|
name: webpackRequire.federation.initOptions.name,
|
|
302
|
-
remotes: []
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
const
|
|
469
|
+
remotes: [],
|
|
470
|
+
...remoteEntryInitOptions,
|
|
471
|
+
});
|
|
472
|
+
const hostShareScopeKeys = remoteEntryInitOptions?.shareScopeKeys;
|
|
473
|
+
const hostShareScopeMap = remoteEntryInitOptions?.shareScopeMap;
|
|
306
474
|
// host: 'default' remote: 'default' remote['default'] = hostShareScopeMap['default']
|
|
307
475
|
// host: ['default', 'scope1'] remote: 'default' remote['default'] = hostShareScopeMap['default']; remote['scope1'] = hostShareScopeMap['scop1']
|
|
308
476
|
// host: 'default' remote: ['default','scope1'] remote['default'] = hostShareScopeMap['default']; remote['scope1'] = hostShareScopeMap['scope1'] = {}
|
|
@@ -317,25 +485,27 @@ function initContainerEntry(options) {
|
|
|
317
485
|
// federationInstance.initShareScopeMap(key, sc, {
|
|
318
486
|
// hostShareScopeMap: remoteEntryInitOptions?.shareScopeMap || {},
|
|
319
487
|
// });
|
|
320
|
-
hostShareScopeKeys.forEach((hostKey)=>{
|
|
488
|
+
hostShareScopeKeys.forEach((hostKey) => {
|
|
321
489
|
if (!hostShareScopeMap[hostKey]) {
|
|
322
490
|
hostShareScopeMap[hostKey] = {};
|
|
323
491
|
}
|
|
324
492
|
const sc = hostShareScopeMap[hostKey];
|
|
325
493
|
federationInstance.initShareScopeMap(hostKey, sc, {
|
|
326
|
-
hostShareScopeMap:
|
|
494
|
+
hostShareScopeMap: remoteEntryInitOptions?.shareScopeMap || {},
|
|
327
495
|
});
|
|
328
496
|
});
|
|
329
|
-
}
|
|
497
|
+
}
|
|
498
|
+
else {
|
|
330
499
|
federationInstance.initShareScopeMap(key, shareScope, {
|
|
331
|
-
hostShareScopeMap:
|
|
500
|
+
hostShareScopeMap: remoteEntryInitOptions?.shareScopeMap || {},
|
|
332
501
|
});
|
|
333
502
|
}
|
|
334
|
-
}
|
|
335
|
-
|
|
503
|
+
}
|
|
504
|
+
else {
|
|
505
|
+
shareScopeKey.forEach((key) => {
|
|
336
506
|
if (!hostShareScopeKeys || !hostShareScopeMap) {
|
|
337
507
|
federationInstance.initShareScopeMap(key, shareScope, {
|
|
338
|
-
hostShareScopeMap:
|
|
508
|
+
hostShareScopeMap: remoteEntryInitOptions?.shareScopeMap || {},
|
|
339
509
|
});
|
|
340
510
|
return;
|
|
341
511
|
}
|
|
@@ -344,7 +514,7 @@ function initContainerEntry(options) {
|
|
|
344
514
|
}
|
|
345
515
|
const sc = hostShareScopeMap[key];
|
|
346
516
|
federationInstance.initShareScopeMap(key, sc, {
|
|
347
|
-
hostShareScopeMap:
|
|
517
|
+
hostShareScopeMap: remoteEntryInitOptions?.shareScopeMap || {},
|
|
348
518
|
});
|
|
349
519
|
});
|
|
350
520
|
}
|
|
@@ -364,10 +534,10 @@ function initContainerEntry(options) {
|
|
|
364
534
|
return webpackRequire.I(shareScopeKey, initScope);
|
|
365
535
|
}
|
|
366
536
|
// @ts-ignore
|
|
367
|
-
return Promise.all(shareScopeKey.map((key)=>{
|
|
537
|
+
return Promise.all(shareScopeKey.map((key) => {
|
|
368
538
|
// @ts-ignore
|
|
369
539
|
return webpackRequire.I(key, initScope);
|
|
370
|
-
})).then(()=>true);
|
|
540
|
+
})).then(() => true);
|
|
371
541
|
}
|
|
372
542
|
|
|
373
543
|
const federation = {
|
|
@@ -380,10 +550,10 @@ const federation = {
|
|
|
380
550
|
I: initializeSharing,
|
|
381
551
|
S: {},
|
|
382
552
|
installInitialConsumes,
|
|
383
|
-
initContainerEntry
|
|
553
|
+
initContainerEntry,
|
|
384
554
|
},
|
|
385
555
|
attachShareScopeMap,
|
|
386
|
-
bundlerRuntimeOptions: {}
|
|
556
|
+
bundlerRuntimeOptions: {},
|
|
387
557
|
};
|
|
388
558
|
|
|
389
559
|
export { federation as default };
|