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