@module-federation/webpack-bundler-runtime 0.6.7 → 0.6.9
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.js +2 -4
- package/dist/constant.esm.d.ts +1 -0
- package/dist/constant.esm.js +1 -1
- package/dist/container.cjs.js +53 -216
- package/dist/container.esm.d.ts +1 -0
- package/dist/container.esm.js +53 -214
- package/dist/index.cjs.js +68 -111
- package/dist/index.esm.d.ts +2 -0
- package/dist/index.esm.js +66 -108
- package/dist/package.json +2 -2
- package/dist/polyfills.cjs.js +14 -0
- package/dist/polyfills.esm.js +12 -0
- package/package.json +4 -4
package/dist/index.cjs.js
CHANGED
|
@@ -3,9 +3,9 @@
|
|
|
3
3
|
var runtime = require('@module-federation/runtime');
|
|
4
4
|
var constant = require('./constant.cjs.js');
|
|
5
5
|
var sdk = require('@module-federation/sdk');
|
|
6
|
+
var polyfills = require('./polyfills.cjs.js');
|
|
6
7
|
|
|
7
|
-
function
|
|
8
|
-
if (e && e.__esModule) return e;
|
|
8
|
+
function _interopNamespaceDefault(e) {
|
|
9
9
|
var n = Object.create(null);
|
|
10
10
|
if (e) {
|
|
11
11
|
Object.keys(e).forEach(function (k) {
|
|
@@ -18,11 +18,11 @@ function _interopNamespace(e) {
|
|
|
18
18
|
}
|
|
19
19
|
});
|
|
20
20
|
}
|
|
21
|
-
n
|
|
21
|
+
n.default = e;
|
|
22
22
|
return Object.freeze(n);
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
var runtime__namespace = /*#__PURE__*/
|
|
25
|
+
var runtime__namespace = /*#__PURE__*/_interopNamespaceDefault(runtime);
|
|
26
26
|
|
|
27
27
|
function attachShareScopeMap(webpackRequire) {
|
|
28
28
|
if (!webpackRequire.S || webpackRequire.federation.hasAttachShareScopeMap || !webpackRequire.federation.instance || !webpackRequire.federation.instance.shareScopeMap) {
|
|
@@ -33,16 +33,16 @@ function attachShareScopeMap(webpackRequire) {
|
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
function remotes(options) {
|
|
36
|
-
|
|
36
|
+
const { chunkId, promises, chunkMapping, idToExternalAndNameMapping, webpackRequire, idToRemoteMap } = options;
|
|
37
37
|
attachShareScopeMap(webpackRequire);
|
|
38
38
|
if (webpackRequire.o(chunkMapping, chunkId)) {
|
|
39
|
-
chunkMapping[chunkId].forEach(
|
|
40
|
-
|
|
39
|
+
chunkMapping[chunkId].forEach((id)=>{
|
|
40
|
+
let getScope = webpackRequire.R;
|
|
41
41
|
if (!getScope) {
|
|
42
42
|
getScope = [];
|
|
43
43
|
}
|
|
44
|
-
|
|
45
|
-
|
|
44
|
+
const data = idToExternalAndNameMapping[id];
|
|
45
|
+
const remoteInfos = idToRemoteMap[id];
|
|
46
46
|
// @ts-ignore seems not work
|
|
47
47
|
if (getScope.indexOf(data) >= 0) {
|
|
48
48
|
return;
|
|
@@ -52,25 +52,23 @@ function remotes(options) {
|
|
|
52
52
|
if (data.p) {
|
|
53
53
|
return promises.push(data.p);
|
|
54
54
|
}
|
|
55
|
-
|
|
55
|
+
const onError = (error)=>{
|
|
56
56
|
if (!error) {
|
|
57
57
|
error = new Error('Container missing');
|
|
58
58
|
}
|
|
59
59
|
if (typeof error.message === 'string') {
|
|
60
|
-
error.message +=
|
|
60
|
+
error.message += `\nwhile loading "${data[1]}" from ${data[2]}`;
|
|
61
61
|
}
|
|
62
|
-
webpackRequire.m[id] =
|
|
62
|
+
webpackRequire.m[id] = ()=>{
|
|
63
63
|
throw error;
|
|
64
64
|
};
|
|
65
65
|
data.p = 0;
|
|
66
66
|
};
|
|
67
|
-
|
|
67
|
+
const handleFunction = (fn, arg1, arg2, d, next, first)=>{
|
|
68
68
|
try {
|
|
69
|
-
|
|
69
|
+
const promise = fn(arg1, arg2);
|
|
70
70
|
if (promise && promise.then) {
|
|
71
|
-
|
|
72
|
-
return next(result, d);
|
|
73
|
-
}, onError);
|
|
71
|
+
const p = promise.then((result)=>next(result, d), onError);
|
|
74
72
|
if (first) {
|
|
75
73
|
promises.push(data.p = p);
|
|
76
74
|
} else {
|
|
@@ -83,24 +81,20 @@ function remotes(options) {
|
|
|
83
81
|
onError(error);
|
|
84
82
|
}
|
|
85
83
|
};
|
|
86
|
-
|
|
87
|
-
return external ? handleFunction(webpackRequire.I, data[0], 0, external, onInitialized, first) : onError();
|
|
88
|
-
};
|
|
84
|
+
const onExternal = (external, _, first)=>external ? handleFunction(webpackRequire.I, data[0], 0, external, onInitialized, first) : onError();
|
|
89
85
|
// eslint-disable-next-line no-var
|
|
90
|
-
var onInitialized =
|
|
91
|
-
return handleFunction(external.get, data[1], getScope, 0, onFactory, first);
|
|
92
|
-
};
|
|
86
|
+
var onInitialized = (_, external, first)=>handleFunction(external.get, data[1], getScope, 0, onFactory, first);
|
|
93
87
|
// eslint-disable-next-line no-var
|
|
94
|
-
var onFactory =
|
|
88
|
+
var onFactory = (factory)=>{
|
|
95
89
|
data.p = 1;
|
|
96
|
-
webpackRequire.m[id] =
|
|
90
|
+
webpackRequire.m[id] = (module)=>{
|
|
97
91
|
module.exports = factory();
|
|
98
92
|
};
|
|
99
93
|
};
|
|
100
|
-
|
|
94
|
+
const onRemoteLoaded = ()=>{
|
|
101
95
|
try {
|
|
102
|
-
|
|
103
|
-
|
|
96
|
+
const remoteName = sdk.decodeName(remoteInfos[0].name, sdk.ENCODE_NAME_PREFIX);
|
|
97
|
+
const remoteModuleName = remoteName + data[1].slice(1);
|
|
104
98
|
return webpackRequire.federation.instance.loadRemote(remoteModuleName, {
|
|
105
99
|
loadFactory: false,
|
|
106
100
|
from: 'build'
|
|
@@ -109,7 +103,7 @@ function remotes(options) {
|
|
|
109
103
|
onError(error);
|
|
110
104
|
}
|
|
111
105
|
};
|
|
112
|
-
|
|
106
|
+
const useRuntimeLoad = remoteInfos.length === 1 && constant.FEDERATION_SUPPORTED_TYPES.includes(remoteInfos[0].externalType) && remoteInfos[0].name;
|
|
113
107
|
if (useRuntimeLoad) {
|
|
114
108
|
handleFunction(onRemoteLoaded, data[2], 0, 0, onFactory, 1);
|
|
115
109
|
} else {
|
|
@@ -120,36 +114,36 @@ function remotes(options) {
|
|
|
120
114
|
}
|
|
121
115
|
|
|
122
116
|
function consumes(options) {
|
|
123
|
-
|
|
117
|
+
const { chunkId, promises, chunkMapping, installedModules, moduleToHandlerMapping, webpackRequire } = options;
|
|
124
118
|
attachShareScopeMap(webpackRequire);
|
|
125
119
|
if (webpackRequire.o(chunkMapping, chunkId)) {
|
|
126
|
-
chunkMapping[chunkId].forEach(
|
|
120
|
+
chunkMapping[chunkId].forEach((id)=>{
|
|
127
121
|
if (webpackRequire.o(installedModules, id)) {
|
|
128
122
|
return promises.push(installedModules[id]);
|
|
129
123
|
}
|
|
130
|
-
|
|
124
|
+
const onFactory = (factory)=>{
|
|
131
125
|
installedModules[id] = 0;
|
|
132
|
-
webpackRequire.m[id] =
|
|
126
|
+
webpackRequire.m[id] = (module)=>{
|
|
133
127
|
delete webpackRequire.c[id];
|
|
134
128
|
module.exports = factory();
|
|
135
129
|
};
|
|
136
130
|
};
|
|
137
|
-
|
|
131
|
+
const onError = (error)=>{
|
|
138
132
|
delete installedModules[id];
|
|
139
|
-
webpackRequire.m[id] =
|
|
133
|
+
webpackRequire.m[id] = (module)=>{
|
|
140
134
|
delete webpackRequire.c[id];
|
|
141
135
|
throw error;
|
|
142
136
|
};
|
|
143
137
|
};
|
|
144
138
|
try {
|
|
145
|
-
|
|
139
|
+
const federationInstance = webpackRequire.federation.instance;
|
|
146
140
|
if (!federationInstance) {
|
|
147
141
|
throw new Error('Federation instance not found!');
|
|
148
142
|
}
|
|
149
|
-
|
|
150
|
-
|
|
143
|
+
const { shareKey, getter, shareInfo } = moduleToHandlerMapping[id];
|
|
144
|
+
const promise = federationInstance.loadShare(shareKey, {
|
|
151
145
|
customShareInfo: shareInfo
|
|
152
|
-
}).then(
|
|
146
|
+
}).then((factory)=>{
|
|
153
147
|
if (factory === false) {
|
|
154
148
|
return getter();
|
|
155
149
|
}
|
|
@@ -168,10 +162,9 @@ function consumes(options) {
|
|
|
168
162
|
}
|
|
169
163
|
}
|
|
170
164
|
|
|
171
|
-
function initializeSharing(
|
|
172
|
-
var shareScopeName = param.shareScopeName, webpackRequire = param.webpackRequire, initPromises = param.initPromises, initTokens = param.initTokens, initScope = param.initScope;
|
|
165
|
+
function initializeSharing({ shareScopeName, webpackRequire, initPromises, initTokens, initScope }) {
|
|
173
166
|
if (!initScope) initScope = [];
|
|
174
|
-
|
|
167
|
+
const mfInstance = webpackRequire.federation.instance;
|
|
175
168
|
// handling circular init calls
|
|
176
169
|
var initToken = initTokens[shareScopeName];
|
|
177
170
|
if (!initToken) initToken = initTokens[shareScopeName] = {
|
|
@@ -179,22 +172,16 @@ function initializeSharing(param) {
|
|
|
179
172
|
};
|
|
180
173
|
if (initScope.indexOf(initToken) >= 0) return;
|
|
181
174
|
initScope.push(initToken);
|
|
182
|
-
|
|
175
|
+
const promise = initPromises[shareScopeName];
|
|
183
176
|
if (promise) return promise;
|
|
184
|
-
var warn =
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
var initExternal = function(id) {
|
|
188
|
-
var handleError = function(err) {
|
|
189
|
-
return warn('Initialization of sharing external failed: ' + err);
|
|
190
|
-
};
|
|
177
|
+
var warn = (msg)=>typeof console !== 'undefined' && console.warn && console.warn(msg);
|
|
178
|
+
var initExternal = (id)=>{
|
|
179
|
+
var handleError = (err)=>warn('Initialization of sharing external failed: ' + err);
|
|
191
180
|
try {
|
|
192
181
|
var module = webpackRequire(id);
|
|
193
182
|
if (!module) return;
|
|
194
|
-
var initFn =
|
|
195
|
-
return module && module.init && // @ts-ignore compat legacy mf shared behavior
|
|
183
|
+
var initFn = (module)=>module && module.init && // @ts-ignore compat legacy mf shared behavior
|
|
196
184
|
module.init(webpackRequire.S[shareScopeName], initScope);
|
|
197
|
-
};
|
|
198
185
|
if (module.then) return promises.push(module.then(initFn, handleError));
|
|
199
186
|
var initResult = initFn(module);
|
|
200
187
|
// @ts-ignore
|
|
@@ -204,21 +191,21 @@ function initializeSharing(param) {
|
|
|
204
191
|
handleError(err);
|
|
205
192
|
}
|
|
206
193
|
};
|
|
207
|
-
|
|
194
|
+
const promises = mfInstance.initializeSharing(shareScopeName, {
|
|
208
195
|
strategy: mfInstance.options.shareStrategy,
|
|
209
|
-
initScope
|
|
196
|
+
initScope,
|
|
210
197
|
from: 'build'
|
|
211
198
|
});
|
|
212
199
|
attachShareScopeMap(webpackRequire);
|
|
213
|
-
|
|
200
|
+
const bundlerRuntimeRemotesOptions = webpackRequire.federation.bundlerRuntimeOptions.remotes;
|
|
214
201
|
if (bundlerRuntimeRemotesOptions) {
|
|
215
|
-
Object.keys(bundlerRuntimeRemotesOptions.idToRemoteMap).forEach(
|
|
216
|
-
|
|
217
|
-
|
|
202
|
+
Object.keys(bundlerRuntimeRemotesOptions.idToRemoteMap).forEach((moduleId)=>{
|
|
203
|
+
const info = bundlerRuntimeRemotesOptions.idToRemoteMap[moduleId];
|
|
204
|
+
const externalModuleId = bundlerRuntimeRemotesOptions.idToExternalAndNameMapping[moduleId][2];
|
|
218
205
|
if (info.length > 1) {
|
|
219
206
|
initExternal(externalModuleId);
|
|
220
207
|
} else if (info.length === 1) {
|
|
221
|
-
|
|
208
|
+
const remoteInfo = info[0];
|
|
222
209
|
if (!constant.FEDERATION_SUPPORTED_TYPES.includes(remoteInfo.externalType)) {
|
|
223
210
|
initExternal(externalModuleId);
|
|
224
211
|
}
|
|
@@ -228,18 +215,16 @@ function initializeSharing(param) {
|
|
|
228
215
|
if (!promises.length) {
|
|
229
216
|
return initPromises[shareScopeName] = true;
|
|
230
217
|
}
|
|
231
|
-
return initPromises[shareScopeName] = Promise.all(promises).then(
|
|
232
|
-
return initPromises[shareScopeName] = true;
|
|
233
|
-
});
|
|
218
|
+
return initPromises[shareScopeName] = Promise.all(promises).then(()=>initPromises[shareScopeName] = true);
|
|
234
219
|
}
|
|
235
220
|
|
|
236
221
|
function handleInitialConsumes(options) {
|
|
237
|
-
|
|
238
|
-
|
|
222
|
+
const { moduleId, moduleToHandlerMapping, webpackRequire } = options;
|
|
223
|
+
const federationInstance = webpackRequire.federation.instance;
|
|
239
224
|
if (!federationInstance) {
|
|
240
225
|
throw new Error('Federation instance not found!');
|
|
241
226
|
}
|
|
242
|
-
|
|
227
|
+
const { shareKey, shareInfo } = moduleToHandlerMapping[moduleId];
|
|
243
228
|
try {
|
|
244
229
|
return federationInstance.loadShareSync(shareKey, {
|
|
245
230
|
customShareInfo: shareInfo
|
|
@@ -251,65 +236,37 @@ function handleInitialConsumes(options) {
|
|
|
251
236
|
}
|
|
252
237
|
}
|
|
253
238
|
function installInitialConsumes(options) {
|
|
254
|
-
|
|
255
|
-
initialConsumes.forEach(
|
|
256
|
-
webpackRequire.m[id] =
|
|
239
|
+
const { moduleToHandlerMapping, webpackRequire, installedModules, initialConsumes } = options;
|
|
240
|
+
initialConsumes.forEach((id)=>{
|
|
241
|
+
webpackRequire.m[id] = (module)=>{
|
|
257
242
|
// Handle scenario when module is used synchronously
|
|
258
243
|
installedModules[id] = 0;
|
|
259
244
|
delete webpackRequire.c[id];
|
|
260
|
-
|
|
245
|
+
const factory = handleInitialConsumes({
|
|
261
246
|
moduleId: id,
|
|
262
|
-
moduleToHandlerMapping
|
|
263
|
-
webpackRequire
|
|
247
|
+
moduleToHandlerMapping,
|
|
248
|
+
webpackRequire
|
|
264
249
|
});
|
|
265
250
|
if (typeof factory !== 'function') {
|
|
266
|
-
throw new Error(
|
|
251
|
+
throw new Error(`Shared module is not available for eager consumption: ${id}`);
|
|
267
252
|
}
|
|
268
253
|
module.exports = factory();
|
|
269
254
|
};
|
|
270
255
|
});
|
|
271
256
|
}
|
|
272
257
|
|
|
273
|
-
function _define_property(obj, key, value) {
|
|
274
|
-
if (key in obj) {
|
|
275
|
-
Object.defineProperty(obj, key, {
|
|
276
|
-
value: value,
|
|
277
|
-
enumerable: true,
|
|
278
|
-
configurable: true,
|
|
279
|
-
writable: true
|
|
280
|
-
});
|
|
281
|
-
} else {
|
|
282
|
-
obj[key] = value;
|
|
283
|
-
}
|
|
284
|
-
return obj;
|
|
285
|
-
}
|
|
286
|
-
function _object_spread(target) {
|
|
287
|
-
for(var i = 1; i < arguments.length; i++){
|
|
288
|
-
var source = arguments[i] != null ? arguments[i] : {};
|
|
289
|
-
var ownKeys = Object.keys(source);
|
|
290
|
-
if (typeof Object.getOwnPropertySymbols === "function") {
|
|
291
|
-
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
|
|
292
|
-
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
|
|
293
|
-
}));
|
|
294
|
-
}
|
|
295
|
-
ownKeys.forEach(function(key) {
|
|
296
|
-
_define_property(target, key, source[key]);
|
|
297
|
-
});
|
|
298
|
-
}
|
|
299
|
-
return target;
|
|
300
|
-
}
|
|
301
258
|
function initContainerEntry(options) {
|
|
302
|
-
|
|
259
|
+
const { webpackRequire, shareScope, initScope, shareScopeKey, remoteEntryInitOptions } = options;
|
|
303
260
|
if (!webpackRequire.S) return;
|
|
304
261
|
if (!webpackRequire.federation || !webpackRequire.federation.instance || !webpackRequire.federation.initOptions) return;
|
|
305
|
-
|
|
262
|
+
const federationInstance = webpackRequire.federation.instance;
|
|
306
263
|
var name = shareScopeKey || 'default';
|
|
307
|
-
federationInstance.initOptions(
|
|
264
|
+
federationInstance.initOptions(polyfills._extends({
|
|
308
265
|
name: webpackRequire.federation.initOptions.name,
|
|
309
266
|
remotes: []
|
|
310
267
|
}, remoteEntryInitOptions));
|
|
311
268
|
federationInstance.initShareScopeMap(name, shareScope, {
|
|
312
|
-
hostShareScopeMap: (remoteEntryInitOptions
|
|
269
|
+
hostShareScopeMap: (remoteEntryInitOptions == null ? void 0 : remoteEntryInitOptions.shareScopeMap) || {}
|
|
313
270
|
});
|
|
314
271
|
if (webpackRequire.federation.attachShareScopeMap) {
|
|
315
272
|
webpackRequire.federation.attachShareScopeMap(webpackRequire);
|
|
@@ -321,19 +278,19 @@ function initContainerEntry(options) {
|
|
|
321
278
|
return webpackRequire.I(name, initScope);
|
|
322
279
|
}
|
|
323
280
|
|
|
324
|
-
|
|
281
|
+
const federation = {
|
|
325
282
|
runtime: runtime__namespace,
|
|
326
283
|
instance: undefined,
|
|
327
284
|
initOptions: undefined,
|
|
328
285
|
bundlerRuntime: {
|
|
329
|
-
remotes
|
|
330
|
-
consumes
|
|
286
|
+
remotes,
|
|
287
|
+
consumes,
|
|
331
288
|
I: initializeSharing,
|
|
332
289
|
S: {},
|
|
333
|
-
installInitialConsumes
|
|
334
|
-
initContainerEntry
|
|
290
|
+
installInitialConsumes,
|
|
291
|
+
initContainerEntry
|
|
335
292
|
},
|
|
336
|
-
attachShareScopeMap
|
|
293
|
+
attachShareScopeMap,
|
|
337
294
|
bundlerRuntimeOptions: {}
|
|
338
295
|
};
|
|
339
296
|
|