@module-federation/runtime 0.0.0-next-20231220085130 → 0.0.0-next-20231221094341
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/helpers.cjs.js +1 -1
- package/dist/helpers.esm.js +2 -2
- package/dist/index.cjs.js +144 -68
- package/dist/index.esm.js +143 -70
- package/dist/package.json +3 -3
- package/dist/share.cjs.js +70 -47
- package/dist/share.esm.js +70 -47
- package/dist/src/core.d.ts +15 -5
- package/dist/src/global.d.ts +2 -3
- package/dist/src/helpers.d.ts +2 -2
- package/dist/src/index.d.ts +1 -0
- package/dist/src/module/index.d.ts +4 -2
- package/dist/src/type/config.d.ts +5 -2
- package/dist/src/utils/share.d.ts +12 -3
- package/dist/types.cjs.d.ts +1 -0
- package/package.json +4 -4
- package/dist/type.cjs.d.ts +0 -1
- /package/dist/{type.cjs.js → types.cjs.js} +0 -0
- /package/dist/{type.esm.js → types.esm.js} +0 -0
package/dist/index.esm.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { g as getGlobalHostPlugins, D as DEFAULT_REMOTE_TYPE, a as DEFAULT_SCOPE, b as globalLoading, c as getRemoteEntryExports, d as assert, s as safeToString, G as Global, e as getFMId, i as isObject, f as error, w as warn, h as isPlainObject, j as isRemoteInfoWithEntry, k as isPureRemoteEntry, l as
|
|
1
|
+
import { g as getGlobalHostPlugins, D as DEFAULT_REMOTE_TYPE, a as DEFAULT_SCOPE, b as globalLoading, c as getRemoteEntryExports, d as assert, s as safeToString, G as Global, e as getFMId, i as isObject, f as error, w as warn, h as isPlainObject, j as isRemoteInfoWithEntry, k as isPureRemoteEntry, l as getRegisteredShare, m as getInfoWithoutType, n as getPreloaded, o as setPreloaded, p as getGlobalSnapshotInfoByModuleInfo, q as setGlobalSnapshotInfoByModuleInfo, r as getGlobalSnapshot, t as getGlobalShareScope, u as addUniqueItem, v as formatShareConfigs, x as isBrowserEnv, y as getBuilderId, z as setGlobalFederationConstructor, A as getGlobalFederationInstance, B as getGlobalFederationConstructor, C as setGlobalFederationInstance } from './share.esm.js';
|
|
2
2
|
export { E as registerGlobalPlugins } from './share.esm.js';
|
|
3
|
-
import { composeKeyWithSeparator, loadScript, createScript, getResourceUrl, isManifestProvider, generateSnapshotFromManifest } from '@module-federation/sdk';
|
|
3
|
+
import { composeKeyWithSeparator, loadScriptNode, loadScript, createScript, getResourceUrl, isManifestProvider, generateSnapshotFromManifest } from '@module-federation/sdk';
|
|
4
|
+
export { loadScript } from '@module-federation/sdk';
|
|
4
5
|
|
|
5
6
|
// Function to match a remote with its name and expose
|
|
6
7
|
// id: pkgName(@federation/app1) + expose(button) = @federation/app1/button
|
|
@@ -118,6 +119,24 @@ async function loadEntryScript({ name, globalName, entry, createScriptHook }) {
|
|
|
118
119
|
if (remoteEntryExports) {
|
|
119
120
|
return remoteEntryExports;
|
|
120
121
|
}
|
|
122
|
+
if (typeof document === 'undefined') {
|
|
123
|
+
return loadScriptNode(entry, {
|
|
124
|
+
attrs: {
|
|
125
|
+
name,
|
|
126
|
+
globalName
|
|
127
|
+
},
|
|
128
|
+
createScriptHook
|
|
129
|
+
}).then(()=>{
|
|
130
|
+
const { remoteEntryKey, entryExports } = getRemoteEntryExports(name, globalName);
|
|
131
|
+
assert(entryExports, `
|
|
132
|
+
Unable to use the ${name}'s '${entry}' URL with ${remoteEntryKey}'s globalName to get remoteEntry exports.
|
|
133
|
+
Possible reasons could be:\n
|
|
134
|
+
1. '${entry}' is not the correct URL, or the remoteEntry resource or name is incorrect.\n
|
|
135
|
+
2. ${remoteEntryKey} cannot be used to get remoteEntry exports in the window object.
|
|
136
|
+
`);
|
|
137
|
+
return entryExports;
|
|
138
|
+
});
|
|
139
|
+
}
|
|
121
140
|
return loadScript(entry, {
|
|
122
141
|
attrs: {},
|
|
123
142
|
createScriptHook
|
|
@@ -191,6 +210,10 @@ let Module = class Module {
|
|
|
191
210
|
const res = this.loaderHook.lifecycle.createScript.emit({
|
|
192
211
|
url
|
|
193
212
|
});
|
|
213
|
+
if (typeof document === 'undefined') {
|
|
214
|
+
//todo: needs real fix
|
|
215
|
+
return res;
|
|
216
|
+
}
|
|
194
217
|
if (res instanceof HTMLScriptElement) {
|
|
195
218
|
return res;
|
|
196
219
|
}
|
|
@@ -206,15 +229,16 @@ let Module = class Module {
|
|
|
206
229
|
const { loadFactory = true } = options || {
|
|
207
230
|
loadFactory: true
|
|
208
231
|
};
|
|
232
|
+
this.hostInfo.name;
|
|
209
233
|
// Get remoteEntry.js
|
|
210
234
|
const remoteEntryExports = await this.getEntry();
|
|
211
235
|
if (!this.inited) {
|
|
212
|
-
const
|
|
236
|
+
const localShareScopeMap = this.shareScopeMap;
|
|
213
237
|
const remoteShareScope = this.remoteInfo.shareScope || 'default';
|
|
214
|
-
if (!
|
|
215
|
-
|
|
238
|
+
if (!localShareScopeMap[remoteShareScope]) {
|
|
239
|
+
localShareScopeMap[remoteShareScope] = {};
|
|
216
240
|
}
|
|
217
|
-
const shareScope =
|
|
241
|
+
const shareScope = localShareScopeMap[remoteShareScope];
|
|
218
242
|
// TODO: compat logic , it could be moved after providing startup hooks
|
|
219
243
|
const remoteEntryInitOptions = {
|
|
220
244
|
version: this.remoteInfo.version || '',
|
|
@@ -224,10 +248,18 @@ let Module = class Module {
|
|
|
224
248
|
remoteEntryExports.init(shareScope, [], remoteEntryInitOptions);
|
|
225
249
|
const federationInstance = Global.__FEDERATION__.__INSTANCES__.find((i)=>i.options.id === composeKeyWithSeparator(this.remoteInfo.name, this.remoteInfo.buildVersion));
|
|
226
250
|
if (federationInstance) {
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
251
|
+
// means the instance is prev vmok instance
|
|
252
|
+
if (!federationInstance.releaseNumber || Number(federationInstance.releaseNumber) <= 100) {
|
|
253
|
+
// 兼容旧的生产者传参
|
|
254
|
+
federationInstance.initOptions(_extends$4({}, remoteEntryInitOptions, {
|
|
255
|
+
remotes: [],
|
|
256
|
+
name: this.remoteInfo.name
|
|
257
|
+
}));
|
|
258
|
+
if (!__FEDERATION__.__SHARE__['default'] && this.shareScopeMap && this.shareScopeMap['default']) {
|
|
259
|
+
// @ts-ignore compat prev logic , and it will be optimized by supporting startup hook
|
|
260
|
+
__FEDERATION__.__SHARE__['default'] = this.shareScopeMap['default'];
|
|
261
|
+
}
|
|
262
|
+
}
|
|
231
263
|
}
|
|
232
264
|
}
|
|
233
265
|
this.lib = remoteEntryExports;
|
|
@@ -242,7 +274,7 @@ let Module = class Module {
|
|
|
242
274
|
return exposeContent;
|
|
243
275
|
}
|
|
244
276
|
// loading: Record<string, undefined | Promise<RemoteEntryExports | void>> = {};
|
|
245
|
-
constructor({ hostInfo, remoteInfo, shared, loaderHook }){
|
|
277
|
+
constructor({ hostInfo, remoteInfo, shared, loaderHook, shareScopeMap }){
|
|
246
278
|
this.inited = false;
|
|
247
279
|
this.shared = {};
|
|
248
280
|
this.lib = undefined;
|
|
@@ -250,6 +282,7 @@ let Module = class Module {
|
|
|
250
282
|
this.remoteInfo = remoteInfo;
|
|
251
283
|
this.shared = shared;
|
|
252
284
|
this.loaderHook = loaderHook;
|
|
285
|
+
this.shareScopeMap = shareScopeMap;
|
|
253
286
|
}
|
|
254
287
|
};
|
|
255
288
|
|
|
@@ -776,9 +809,9 @@ function generatePreloadAssets(origin, preloadOptions, remote, globalSnapshot, r
|
|
|
776
809
|
if (!shareInfo) {
|
|
777
810
|
return;
|
|
778
811
|
}
|
|
779
|
-
const
|
|
812
|
+
const registeredShared = getRegisteredShare(origin.shareScopeMap, shared.sharedName, shareInfo, origin.hooks.lifecycle.resolveShare);
|
|
780
813
|
// If the global share does not exist, or the lib function does not exist, it means that the shared has not been loaded yet and can be preloaded.
|
|
781
|
-
if (
|
|
814
|
+
if (registeredShared && typeof registeredShared.lib === 'function') {
|
|
782
815
|
shared.assets.js.sync.forEach((asset)=>{
|
|
783
816
|
loadedSharedJsAssets.add(asset);
|
|
784
817
|
});
|
|
@@ -1105,6 +1138,13 @@ function _object_without_properties_loose(source, excluded) {
|
|
|
1105
1138
|
return target;
|
|
1106
1139
|
}
|
|
1107
1140
|
class FederationHost {
|
|
1141
|
+
_setGlobalShareScopeMap() {
|
|
1142
|
+
const globalShareScopeMap = getGlobalShareScope();
|
|
1143
|
+
const identifier = this.options.id || this.options.name;
|
|
1144
|
+
if (identifier && !globalShareScopeMap[identifier]) {
|
|
1145
|
+
globalShareScopeMap[identifier] = this.shareScopeMap;
|
|
1146
|
+
}
|
|
1147
|
+
}
|
|
1108
1148
|
initOptions(userOptions) {
|
|
1109
1149
|
this.registerPlugins(userOptions.plugins);
|
|
1110
1150
|
const options = this.formatOptions(this.options, userOptions);
|
|
@@ -1119,6 +1159,11 @@ class FederationHost {
|
|
|
1119
1159
|
// 2. Searches globally for a matching share, if found, it uses it directly
|
|
1120
1160
|
// 3. If not found, it retrieves it from the current share and stores the obtained share globally.
|
|
1121
1161
|
const shareInfo = Object.assign({}, (_this_options_shared = this.options.shared) == null ? void 0 : _this_options_shared[pkgName], customShareInfo);
|
|
1162
|
+
if (shareInfo == null ? void 0 : shareInfo.scope) {
|
|
1163
|
+
shareInfo.scope.forEach((shareScope)=>{
|
|
1164
|
+
this.initializeSharing(shareScope, shareInfo.strategy);
|
|
1165
|
+
});
|
|
1166
|
+
}
|
|
1122
1167
|
const loadShareRes = await this.hooks.lifecycle.beforeLoadShare.emit({
|
|
1123
1168
|
pkgName,
|
|
1124
1169
|
shareInfo,
|
|
@@ -1129,30 +1174,42 @@ class FederationHost {
|
|
|
1129
1174
|
// Assert that shareInfoRes exists, if not, throw an error
|
|
1130
1175
|
assert(shareInfoRes, `Cannot find ${pkgName} Share in the ${this.options.name}. Please ensure that the ${pkgName} Share parameters have been injected`);
|
|
1131
1176
|
// Retrieve from cache
|
|
1132
|
-
const
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1177
|
+
const registeredShared = getRegisteredShare(this.shareScopeMap, pkgName, shareInfoRes, this.hooks.lifecycle.resolveShare);
|
|
1178
|
+
const addUseIn = (shared)=>{
|
|
1179
|
+
if (!shared.useIn) {
|
|
1180
|
+
shared.useIn = [];
|
|
1181
|
+
}
|
|
1182
|
+
addUniqueItem(shared.useIn, this.options.name);
|
|
1183
|
+
};
|
|
1184
|
+
if (registeredShared && registeredShared.lib) {
|
|
1185
|
+
addUseIn(registeredShared);
|
|
1186
|
+
return registeredShared.lib;
|
|
1187
|
+
} else if (registeredShared && registeredShared.loading && !registeredShared.loaded) {
|
|
1188
|
+
const factory = await registeredShared.loading;
|
|
1189
|
+
registeredShared.loaded = true;
|
|
1190
|
+
if (!registeredShared.lib) {
|
|
1191
|
+
registeredShared.lib = factory;
|
|
1192
|
+
}
|
|
1193
|
+
addUseIn(registeredShared);
|
|
1139
1194
|
return factory;
|
|
1140
|
-
} else if (
|
|
1195
|
+
} else if (registeredShared) {
|
|
1141
1196
|
const asyncLoadProcess = async ()=>{
|
|
1142
|
-
const factory = await
|
|
1197
|
+
const factory = await registeredShared.get();
|
|
1143
1198
|
shareInfoRes.lib = factory;
|
|
1144
|
-
|
|
1145
|
-
|
|
1199
|
+
shareInfoRes.loaded = true;
|
|
1200
|
+
addUseIn(shareInfoRes);
|
|
1201
|
+
const gShared = getRegisteredShare(this.shareScopeMap, pkgName, shareInfoRes, this.hooks.lifecycle.resolveShare);
|
|
1146
1202
|
if (gShared) {
|
|
1147
1203
|
gShared.lib = factory;
|
|
1204
|
+
gShared.loaded = true;
|
|
1148
1205
|
}
|
|
1149
1206
|
return factory;
|
|
1150
1207
|
};
|
|
1151
1208
|
const loading = asyncLoadProcess();
|
|
1152
1209
|
this.setShared({
|
|
1153
1210
|
pkgName,
|
|
1154
|
-
loaded:
|
|
1155
|
-
shared:
|
|
1211
|
+
loaded: false,
|
|
1212
|
+
shared: registeredShared,
|
|
1156
1213
|
from: this.options.name,
|
|
1157
1214
|
lib: null,
|
|
1158
1215
|
loading
|
|
@@ -1165,17 +1222,19 @@ class FederationHost {
|
|
|
1165
1222
|
const asyncLoadProcess = async ()=>{
|
|
1166
1223
|
const factory = await shareInfoRes.get();
|
|
1167
1224
|
shareInfoRes.lib = factory;
|
|
1168
|
-
|
|
1169
|
-
|
|
1225
|
+
shareInfoRes.loaded = true;
|
|
1226
|
+
addUseIn(shareInfoRes);
|
|
1227
|
+
const gShared = getRegisteredShare(this.shareScopeMap, pkgName, shareInfoRes, this.hooks.lifecycle.resolveShare);
|
|
1170
1228
|
if (gShared) {
|
|
1171
1229
|
gShared.lib = factory;
|
|
1230
|
+
gShared.loaded = true;
|
|
1172
1231
|
}
|
|
1173
1232
|
return factory;
|
|
1174
1233
|
};
|
|
1175
1234
|
const loading = asyncLoadProcess();
|
|
1176
1235
|
this.setShared({
|
|
1177
1236
|
pkgName,
|
|
1178
|
-
loaded:
|
|
1237
|
+
loaded: false,
|
|
1179
1238
|
shared: shareInfoRes,
|
|
1180
1239
|
from: this.options.name,
|
|
1181
1240
|
lib: null,
|
|
@@ -1191,16 +1250,16 @@ class FederationHost {
|
|
|
1191
1250
|
loadShareSync(pkgName) {
|
|
1192
1251
|
var _this_options_shared;
|
|
1193
1252
|
const shareInfo = (_this_options_shared = this.options.shared) == null ? void 0 : _this_options_shared[pkgName];
|
|
1194
|
-
const
|
|
1195
|
-
if (
|
|
1196
|
-
addUniqueItem(
|
|
1197
|
-
if (!
|
|
1198
|
-
|
|
1199
|
-
if (
|
|
1253
|
+
const registeredShared = getRegisteredShare(this.shareScopeMap, pkgName, shareInfo, this.hooks.lifecycle.resolveShare);
|
|
1254
|
+
if (registeredShared && typeof registeredShared.lib === 'function') {
|
|
1255
|
+
addUniqueItem(registeredShared.useIn, this.options.name);
|
|
1256
|
+
if (!registeredShared.loaded) {
|
|
1257
|
+
registeredShared.loaded = true;
|
|
1258
|
+
if (registeredShared.from === this.options.name) {
|
|
1200
1259
|
shareInfo.loaded = true;
|
|
1201
1260
|
}
|
|
1202
1261
|
}
|
|
1203
|
-
return
|
|
1262
|
+
return registeredShared.lib;
|
|
1204
1263
|
}
|
|
1205
1264
|
if (shareInfo.lib) {
|
|
1206
1265
|
if (!shareInfo.loaded) {
|
|
@@ -1271,7 +1330,8 @@ class FederationHost {
|
|
|
1271
1330
|
remoteInfo,
|
|
1272
1331
|
shared: this.options.shared || {},
|
|
1273
1332
|
plugins: this.options.plugins,
|
|
1274
|
-
loaderHook: this.loaderHook
|
|
1333
|
+
loaderHook: this.loaderHook,
|
|
1334
|
+
shareScopeMap: this.shareScopeMap
|
|
1275
1335
|
};
|
|
1276
1336
|
if (!module) {
|
|
1277
1337
|
module = new Module(moduleOptions);
|
|
@@ -1351,14 +1411,9 @@ class FederationHost {
|
|
|
1351
1411
|
* It accepts one argument, the name of the share scope.
|
|
1352
1412
|
* If the share scope does not exist, it creates one.
|
|
1353
1413
|
*/ // eslint-disable-next-line @typescript-eslint/member-ordering
|
|
1354
|
-
initializeSharing(shareScopeName = DEFAULT_SCOPE) {
|
|
1355
|
-
const
|
|
1356
|
-
const shareScope = Global.__FEDERATION__.__SHARE__;
|
|
1414
|
+
initializeSharing(shareScopeName = DEFAULT_SCOPE, strategy) {
|
|
1415
|
+
const shareScope = this.shareScopeMap;
|
|
1357
1416
|
const hostName = this.options.name;
|
|
1358
|
-
// Executes only once
|
|
1359
|
-
if (shareScopeLoading[shareScopeName]) {
|
|
1360
|
-
return shareScopeLoading[shareScopeName];
|
|
1361
|
-
}
|
|
1362
1417
|
// Creates a new share scope if necessary
|
|
1363
1418
|
if (!shareScope[shareScopeName]) {
|
|
1364
1419
|
shareScope[shareScopeName] = {};
|
|
@@ -1366,21 +1421,27 @@ class FederationHost {
|
|
|
1366
1421
|
// Executes all initialization snippets from all accessible modules
|
|
1367
1422
|
const scope = shareScope[shareScopeName];
|
|
1368
1423
|
const register = (name, shared)=>{
|
|
1424
|
+
var _activeVersion_shareConfig;
|
|
1369
1425
|
const { version, eager } = shared;
|
|
1370
1426
|
scope[name] = scope[name] || {};
|
|
1371
1427
|
const versions = scope[name];
|
|
1372
1428
|
const activeVersion = versions[version];
|
|
1373
|
-
const activeVersionEager = Boolean(activeVersion && (activeVersion.eager || activeVersion.shareConfig.eager));
|
|
1429
|
+
const activeVersionEager = Boolean(activeVersion && (activeVersion.eager || ((_activeVersion_shareConfig = activeVersion.shareConfig) == null ? void 0 : _activeVersion_shareConfig.eager)));
|
|
1374
1430
|
if (!activeVersion || !activeVersion.loaded && (Boolean(!eager) !== !activeVersionEager ? eager : hostName > activeVersion.from)) {
|
|
1375
1431
|
versions[version] = shared;
|
|
1376
1432
|
}
|
|
1377
1433
|
};
|
|
1378
1434
|
const promises = [];
|
|
1435
|
+
const initFn = (mod)=>mod && mod.init && mod.init(shareScope[shareScopeName]);
|
|
1379
1436
|
const initRemoteModule = async (key)=>{
|
|
1380
1437
|
const { module } = await this._getRemoteModuleAndOptions(key);
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1438
|
+
if (module.getEntry) {
|
|
1439
|
+
const entry = await module.getEntry();
|
|
1440
|
+
if (!module.inited) {
|
|
1441
|
+
initFn(entry);
|
|
1442
|
+
module.inited = true;
|
|
1443
|
+
}
|
|
1444
|
+
}
|
|
1384
1445
|
};
|
|
1385
1446
|
Object.keys(this.options.shared).forEach((shareName)=>{
|
|
1386
1447
|
const shared = this.options.shared[shareName];
|
|
@@ -1388,15 +1449,24 @@ class FederationHost {
|
|
|
1388
1449
|
register(shareName, shared);
|
|
1389
1450
|
}
|
|
1390
1451
|
});
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1452
|
+
if (strategy === 'version-first') {
|
|
1453
|
+
this.options.remotes.forEach((remote)=>{
|
|
1454
|
+
if (remote.shareScope === shareScopeName) {
|
|
1455
|
+
promises.push(initRemoteModule(remote.name));
|
|
1456
|
+
}
|
|
1457
|
+
});
|
|
1458
|
+
}
|
|
1459
|
+
return promises;
|
|
1460
|
+
}
|
|
1461
|
+
initShareScopeMap(scopeName, shareScope) {
|
|
1462
|
+
// compat prev consumers
|
|
1463
|
+
if ('version' in shareScope && typeof shareScope['version'] !== 'object') {
|
|
1464
|
+
return;
|
|
1465
|
+
}
|
|
1466
|
+
if ('region' in shareScope && typeof shareScope['region'] !== 'object') {
|
|
1467
|
+
return;
|
|
1398
1468
|
}
|
|
1399
|
-
|
|
1469
|
+
this.shareScopeMap[scopeName] = shareScope;
|
|
1400
1470
|
}
|
|
1401
1471
|
formatOptions(globalOptions, userOptions) {
|
|
1402
1472
|
const formatShareOptions = formatShareConfigs(userOptions.shared || {}, userOptions.name);
|
|
@@ -1436,16 +1506,17 @@ class FederationHost {
|
|
|
1436
1506
|
}
|
|
1437
1507
|
return res;
|
|
1438
1508
|
}, globalOptionsRes.remotes);
|
|
1439
|
-
// register shared
|
|
1509
|
+
// register shared in shareScopeMap
|
|
1440
1510
|
const sharedKeys = Object.keys(formatShareOptions);
|
|
1441
1511
|
sharedKeys.forEach((sharedKey)=>{
|
|
1442
1512
|
const sharedVal = formatShareOptions[sharedKey];
|
|
1443
|
-
const
|
|
1444
|
-
if (!
|
|
1513
|
+
const registeredShared = getRegisteredShare(this.shareScopeMap, sharedKey, sharedVal, this.hooks.lifecycle.resolveShare);
|
|
1514
|
+
if (!registeredShared && sharedVal && sharedVal.lib) {
|
|
1445
1515
|
this.setShared({
|
|
1446
1516
|
pkgName: sharedKey,
|
|
1447
1517
|
lib: sharedVal.lib,
|
|
1448
1518
|
get: sharedVal.get,
|
|
1519
|
+
loaded: true,
|
|
1449
1520
|
shared: sharedVal,
|
|
1450
1521
|
from: userOptions.name
|
|
1451
1522
|
});
|
|
@@ -1480,7 +1551,6 @@ class FederationHost {
|
|
|
1480
1551
|
]);
|
|
1481
1552
|
}
|
|
1482
1553
|
setShared({ pkgName, shared, from, lib, loading, loaded, get }) {
|
|
1483
|
-
const target = getGlobalShareScope();
|
|
1484
1554
|
const { version, scope = 'default' } = shared, shareInfo = _object_without_properties_loose(shared, [
|
|
1485
1555
|
"version",
|
|
1486
1556
|
"scope"
|
|
@@ -1489,23 +1559,23 @@ class FederationHost {
|
|
|
1489
1559
|
scope
|
|
1490
1560
|
];
|
|
1491
1561
|
scopes.forEach((sc)=>{
|
|
1492
|
-
if (!
|
|
1493
|
-
|
|
1562
|
+
if (!this.shareScopeMap[sc]) {
|
|
1563
|
+
this.shareScopeMap[sc] = {};
|
|
1494
1564
|
}
|
|
1495
|
-
if (!
|
|
1496
|
-
|
|
1565
|
+
if (!this.shareScopeMap[sc][pkgName]) {
|
|
1566
|
+
this.shareScopeMap[sc][pkgName] = {};
|
|
1497
1567
|
}
|
|
1498
|
-
if (
|
|
1568
|
+
if (this.shareScopeMap[sc][pkgName][version]) {
|
|
1499
1569
|
warn(// eslint-disable-next-line max-len
|
|
1500
1570
|
`The share \n ${safeToString({
|
|
1501
1571
|
scope: sc,
|
|
1502
1572
|
pkgName,
|
|
1503
1573
|
version,
|
|
1504
|
-
from:
|
|
1574
|
+
from: this.shareScopeMap[sc][pkgName][version].from
|
|
1505
1575
|
})} has been registered`);
|
|
1506
1576
|
return;
|
|
1507
1577
|
}
|
|
1508
|
-
|
|
1578
|
+
this.shareScopeMap[sc][pkgName][version] = _extends({
|
|
1509
1579
|
version,
|
|
1510
1580
|
scope: [
|
|
1511
1581
|
'default'
|
|
@@ -1516,7 +1586,7 @@ class FederationHost {
|
|
|
1516
1586
|
loading
|
|
1517
1587
|
});
|
|
1518
1588
|
if (get) {
|
|
1519
|
-
|
|
1589
|
+
this.shareScopeMap[sc][pkgName][version].get = get;
|
|
1520
1590
|
}
|
|
1521
1591
|
});
|
|
1522
1592
|
}
|
|
@@ -1531,11 +1601,13 @@ class FederationHost {
|
|
|
1531
1601
|
errorLoadRemote: new AsyncHook('errorLoadRemote'),
|
|
1532
1602
|
beforeLoadShare: new AsyncWaterfallHook('beforeLoadShare'),
|
|
1533
1603
|
loadShare: new AsyncHook(),
|
|
1604
|
+
resolveShare: new SyncWaterfallHook('resolveShare'),
|
|
1534
1605
|
beforePreloadRemote: new AsyncHook(),
|
|
1535
1606
|
generatePreloadAssets: new AsyncHook('generatePreloadAssets'),
|
|
1536
1607
|
afterPreloadRemote: new AsyncHook()
|
|
1537
1608
|
});
|
|
1538
|
-
this.
|
|
1609
|
+
this.releaseNumber = `4`;
|
|
1610
|
+
this.version = `0.0.4`;
|
|
1539
1611
|
this.moduleCache = new Map();
|
|
1540
1612
|
this.loaderHook = new PluginSystem({
|
|
1541
1613
|
// FIXME: may not be suitable
|
|
@@ -1543,7 +1615,6 @@ class FederationHost {
|
|
|
1543
1615
|
createScript: new SyncHook(),
|
|
1544
1616
|
fetch: new AsyncHook('fetch')
|
|
1545
1617
|
});
|
|
1546
|
-
this.loadingShare = {};
|
|
1547
1618
|
// TODO: Validate the details of the options
|
|
1548
1619
|
// Initialize options with default values
|
|
1549
1620
|
const defaultOptions = {
|
|
@@ -1559,6 +1630,8 @@ class FederationHost {
|
|
|
1559
1630
|
};
|
|
1560
1631
|
this.name = userOptions.name;
|
|
1561
1632
|
this.options = defaultOptions;
|
|
1633
|
+
this.shareScopeMap = {};
|
|
1634
|
+
this._setGlobalShareScopeMap();
|
|
1562
1635
|
this.snapshotHandler = new SnapshotHandler(this);
|
|
1563
1636
|
this.registerPlugins([
|
|
1564
1637
|
...defaultOptions.plugins,
|
package/dist/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@module-federation/runtime",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.4",
|
|
4
4
|
"author": "zhouxiao <codingzx@gmail.com>",
|
|
5
5
|
"main": "./index.cjs.js",
|
|
6
6
|
"module": "./index.esm.js",
|
|
@@ -39,8 +39,8 @@
|
|
|
39
39
|
"helpers": [
|
|
40
40
|
"./dist/helpers.cjs.d.ts"
|
|
41
41
|
],
|
|
42
|
-
"
|
|
43
|
-
"./dist/
|
|
42
|
+
"types": [
|
|
43
|
+
"./dist/types.cjs.d.ts"
|
|
44
44
|
]
|
|
45
45
|
}
|
|
46
46
|
},
|