@module-federation/runtime 0.0.0-next-20240103032717 → 0.0.0-next-20240104022642
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 +2 -1
- package/dist/helpers.esm.js +3 -2
- package/dist/index.cjs.js +170 -69
- package/dist/index.esm.js +169 -71
- package/dist/package.json +3 -3
- package/dist/share.cjs.js +142 -107
- package/dist/share.esm.js +142 -107
- package/dist/src/core.d.ts +21 -8
- package/dist/src/global.d.ts +3 -6
- package/dist/src/helpers.d.ts +4 -3
- package/dist/src/index.d.ts +1 -0
- package/dist/src/type/config.d.ts +6 -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,
|
|
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, 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, G as Global, t as getGlobalShareScope, u as formatShareConfigs, v as isBrowserEnv, x as getBuilderId, y as addUniqueItem, 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,27 @@ 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
|
+
console.log(entryExports);
|
|
138
|
+
return entryExports;
|
|
139
|
+
}).catch((e)=>{
|
|
140
|
+
return e;
|
|
141
|
+
});
|
|
142
|
+
}
|
|
121
143
|
return loadScript(entry, {
|
|
122
144
|
attrs: {},
|
|
123
145
|
createScriptHook
|
|
@@ -130,6 +152,8 @@ async function loadEntryScript({ name, globalName, entry, createScriptHook }) {
|
|
|
130
152
|
2. ${remoteEntryKey} cannot be used to get remoteEntry exports in the window object.
|
|
131
153
|
`);
|
|
132
154
|
return entryExports;
|
|
155
|
+
}).catch((e)=>{
|
|
156
|
+
return e;
|
|
133
157
|
});
|
|
134
158
|
}
|
|
135
159
|
async function getRemoteEntry({ remoteEntryExports, remoteInfo, createScriptHook }) {
|
|
@@ -191,6 +215,10 @@ let Module = class Module {
|
|
|
191
215
|
const res = this.host.loaderHook.lifecycle.createScript.emit({
|
|
192
216
|
url
|
|
193
217
|
});
|
|
218
|
+
if (typeof document === 'undefined') {
|
|
219
|
+
//todo: needs real fix
|
|
220
|
+
return res;
|
|
221
|
+
}
|
|
194
222
|
if (res instanceof HTMLScriptElement) {
|
|
195
223
|
return res;
|
|
196
224
|
}
|
|
@@ -209,12 +237,12 @@ let Module = class Module {
|
|
|
209
237
|
// Get remoteEntry.js
|
|
210
238
|
const remoteEntryExports = await this.getEntry();
|
|
211
239
|
if (!this.inited) {
|
|
212
|
-
const
|
|
240
|
+
const localShareScopeMap = this.host.shareScopeMap;
|
|
213
241
|
const remoteShareScope = this.remoteInfo.shareScope || 'default';
|
|
214
|
-
if (!
|
|
215
|
-
|
|
242
|
+
if (!localShareScopeMap[remoteShareScope]) {
|
|
243
|
+
localShareScopeMap[remoteShareScope] = {};
|
|
216
244
|
}
|
|
217
|
-
const shareScope =
|
|
245
|
+
const shareScope = localShareScopeMap[remoteShareScope];
|
|
218
246
|
const initScope = [];
|
|
219
247
|
const remoteEntryInitOptions = {
|
|
220
248
|
version: this.remoteInfo.version || ''
|
|
@@ -773,9 +801,9 @@ function generatePreloadAssets(origin, preloadOptions, remote, globalSnapshot, r
|
|
|
773
801
|
if (!shareInfo) {
|
|
774
802
|
return;
|
|
775
803
|
}
|
|
776
|
-
const
|
|
804
|
+
const registeredShared = getRegisteredShare(origin.shareScopeMap, shared.sharedName, shareInfo, origin.hooks.lifecycle.resolveShare);
|
|
777
805
|
// 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.
|
|
778
|
-
if (
|
|
806
|
+
if (registeredShared && typeof registeredShared.lib === 'function') {
|
|
779
807
|
shared.assets.js.sync.forEach((asset)=>{
|
|
780
808
|
loadedSharedJsAssets.add(asset);
|
|
781
809
|
});
|
|
@@ -1102,13 +1130,19 @@ function _object_without_properties_loose(source, excluded) {
|
|
|
1102
1130
|
return target;
|
|
1103
1131
|
}
|
|
1104
1132
|
class FederationHost {
|
|
1133
|
+
_setGlobalShareScopeMap() {
|
|
1134
|
+
const globalShareScopeMap = getGlobalShareScope();
|
|
1135
|
+
const identifier = this.options.id || this.options.name;
|
|
1136
|
+
if (identifier && !globalShareScopeMap[identifier]) {
|
|
1137
|
+
globalShareScopeMap[identifier] = this.shareScopeMap;
|
|
1138
|
+
}
|
|
1139
|
+
}
|
|
1105
1140
|
initOptions(userOptions) {
|
|
1106
1141
|
this.registerPlugins(userOptions.plugins);
|
|
1107
1142
|
const options = this.formatOptions(this.options, userOptions);
|
|
1108
1143
|
this.options = options;
|
|
1109
1144
|
return options;
|
|
1110
1145
|
}
|
|
1111
|
-
// overrideSharedOptions(shareScope: GlobalShareScope[string]): void {}
|
|
1112
1146
|
async loadShare(pkgName, customShareInfo) {
|
|
1113
1147
|
var _this_options_shared;
|
|
1114
1148
|
// This function performs the following steps:
|
|
@@ -1116,6 +1150,12 @@ class FederationHost {
|
|
|
1116
1150
|
// 2. Searches globally for a matching share, if found, it uses it directly
|
|
1117
1151
|
// 3. If not found, it retrieves it from the current share and stores the obtained share globally.
|
|
1118
1152
|
const shareInfo = Object.assign({}, (_this_options_shared = this.options.shared) == null ? void 0 : _this_options_shared[pkgName], customShareInfo);
|
|
1153
|
+
if (shareInfo == null ? void 0 : shareInfo.scope) {
|
|
1154
|
+
await Promise.all(shareInfo.scope.map(async (shareScope)=>{
|
|
1155
|
+
await Promise.all(this.initializeSharing(shareScope, shareInfo.strategy));
|
|
1156
|
+
return;
|
|
1157
|
+
}));
|
|
1158
|
+
}
|
|
1119
1159
|
const loadShareRes = await this.hooks.lifecycle.beforeLoadShare.emit({
|
|
1120
1160
|
pkgName,
|
|
1121
1161
|
shareInfo,
|
|
@@ -1126,30 +1166,42 @@ class FederationHost {
|
|
|
1126
1166
|
// Assert that shareInfoRes exists, if not, throw an error
|
|
1127
1167
|
assert(shareInfoRes, `Cannot find ${pkgName} Share in the ${this.options.name}. Please ensure that the ${pkgName} Share parameters have been injected`);
|
|
1128
1168
|
// Retrieve from cache
|
|
1129
|
-
const
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1169
|
+
const registeredShared = getRegisteredShare(this.shareScopeMap, pkgName, shareInfoRes, this.hooks.lifecycle.resolveShare);
|
|
1170
|
+
const addUseIn = (shared)=>{
|
|
1171
|
+
if (!shared.useIn) {
|
|
1172
|
+
shared.useIn = [];
|
|
1173
|
+
}
|
|
1174
|
+
addUniqueItem(shared.useIn, this.options.name);
|
|
1175
|
+
};
|
|
1176
|
+
if (registeredShared && registeredShared.lib) {
|
|
1177
|
+
addUseIn(registeredShared);
|
|
1178
|
+
return registeredShared.lib;
|
|
1179
|
+
} else if (registeredShared && registeredShared.loading && !registeredShared.loaded) {
|
|
1180
|
+
const factory = await registeredShared.loading;
|
|
1181
|
+
registeredShared.loaded = true;
|
|
1182
|
+
if (!registeredShared.lib) {
|
|
1183
|
+
registeredShared.lib = factory;
|
|
1184
|
+
}
|
|
1185
|
+
addUseIn(registeredShared);
|
|
1136
1186
|
return factory;
|
|
1137
|
-
} else if (
|
|
1187
|
+
} else if (registeredShared) {
|
|
1138
1188
|
const asyncLoadProcess = async ()=>{
|
|
1139
|
-
const factory = await
|
|
1189
|
+
const factory = await registeredShared.get();
|
|
1140
1190
|
shareInfoRes.lib = factory;
|
|
1141
|
-
|
|
1142
|
-
|
|
1191
|
+
shareInfoRes.loaded = true;
|
|
1192
|
+
addUseIn(shareInfoRes);
|
|
1193
|
+
const gShared = getRegisteredShare(this.shareScopeMap, pkgName, shareInfoRes, this.hooks.lifecycle.resolveShare);
|
|
1143
1194
|
if (gShared) {
|
|
1144
1195
|
gShared.lib = factory;
|
|
1196
|
+
gShared.loaded = true;
|
|
1145
1197
|
}
|
|
1146
1198
|
return factory;
|
|
1147
1199
|
};
|
|
1148
1200
|
const loading = asyncLoadProcess();
|
|
1149
1201
|
this.setShared({
|
|
1150
1202
|
pkgName,
|
|
1151
|
-
loaded:
|
|
1152
|
-
shared:
|
|
1203
|
+
loaded: false,
|
|
1204
|
+
shared: registeredShared,
|
|
1153
1205
|
from: this.options.name,
|
|
1154
1206
|
lib: null,
|
|
1155
1207
|
loading
|
|
@@ -1162,17 +1214,19 @@ class FederationHost {
|
|
|
1162
1214
|
const asyncLoadProcess = async ()=>{
|
|
1163
1215
|
const factory = await shareInfoRes.get();
|
|
1164
1216
|
shareInfoRes.lib = factory;
|
|
1165
|
-
|
|
1166
|
-
|
|
1217
|
+
shareInfoRes.loaded = true;
|
|
1218
|
+
addUseIn(shareInfoRes);
|
|
1219
|
+
const gShared = getRegisteredShare(this.shareScopeMap, pkgName, shareInfoRes, this.hooks.lifecycle.resolveShare);
|
|
1167
1220
|
if (gShared) {
|
|
1168
1221
|
gShared.lib = factory;
|
|
1222
|
+
gShared.loaded = true;
|
|
1169
1223
|
}
|
|
1170
1224
|
return factory;
|
|
1171
1225
|
};
|
|
1172
1226
|
const loading = asyncLoadProcess();
|
|
1173
1227
|
this.setShared({
|
|
1174
1228
|
pkgName,
|
|
1175
|
-
loaded:
|
|
1229
|
+
loaded: false,
|
|
1176
1230
|
shared: shareInfoRes,
|
|
1177
1231
|
from: this.options.name,
|
|
1178
1232
|
lib: null,
|
|
@@ -1185,19 +1239,46 @@ class FederationHost {
|
|
|
1185
1239
|
// 1. If the loaded shared already exists globally, then it will be reused
|
|
1186
1240
|
// 2. If lib exists in local shared, it will be used directly
|
|
1187
1241
|
// 3. If the local get returns something other than Promise, then it will be used directly
|
|
1188
|
-
loadShareSync(pkgName) {
|
|
1242
|
+
loadShareSync(pkgName, customShareInfo) {
|
|
1189
1243
|
var _this_options_shared;
|
|
1190
|
-
const shareInfo = (_this_options_shared = this.options.shared) == null ? void 0 : _this_options_shared[pkgName];
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1244
|
+
const shareInfo = Object.assign({}, (_this_options_shared = this.options.shared) == null ? void 0 : _this_options_shared[pkgName], customShareInfo);
|
|
1245
|
+
if (shareInfo == null ? void 0 : shareInfo.scope) {
|
|
1246
|
+
shareInfo.scope.forEach((shareScope)=>{
|
|
1247
|
+
this.initializeSharing(shareScope, shareInfo.strategy);
|
|
1248
|
+
});
|
|
1249
|
+
}
|
|
1250
|
+
const registeredShared = getRegisteredShare(this.shareScopeMap, pkgName, shareInfo, this.hooks.lifecycle.resolveShare);
|
|
1251
|
+
const addUseIn = (shared)=>{
|
|
1252
|
+
if (!shared.useIn) {
|
|
1253
|
+
shared.useIn = [];
|
|
1254
|
+
}
|
|
1255
|
+
addUniqueItem(shared.useIn, this.options.name);
|
|
1256
|
+
};
|
|
1257
|
+
if (registeredShared) {
|
|
1258
|
+
if (typeof registeredShared.lib === 'function') {
|
|
1259
|
+
addUseIn(registeredShared);
|
|
1260
|
+
if (!registeredShared.loaded) {
|
|
1261
|
+
registeredShared.loaded = true;
|
|
1262
|
+
if (registeredShared.from === this.options.name) {
|
|
1263
|
+
shareInfo.loaded = true;
|
|
1264
|
+
}
|
|
1265
|
+
}
|
|
1266
|
+
return registeredShared.lib;
|
|
1267
|
+
}
|
|
1268
|
+
if (typeof registeredShared.get === 'function') {
|
|
1269
|
+
const module = registeredShared.get();
|
|
1270
|
+
if (!(module instanceof Promise)) {
|
|
1271
|
+
addUseIn(registeredShared);
|
|
1272
|
+
this.setShared({
|
|
1273
|
+
pkgName,
|
|
1274
|
+
loaded: true,
|
|
1275
|
+
from: this.options.name,
|
|
1276
|
+
lib: module,
|
|
1277
|
+
shared: registeredShared
|
|
1278
|
+
});
|
|
1279
|
+
return module;
|
|
1198
1280
|
}
|
|
1199
1281
|
}
|
|
1200
|
-
return globalShare.lib;
|
|
1201
1282
|
}
|
|
1202
1283
|
if (shareInfo.lib) {
|
|
1203
1284
|
if (!shareInfo.loaded) {
|
|
@@ -1304,11 +1385,19 @@ class FederationHost {
|
|
|
1304
1385
|
});
|
|
1305
1386
|
return moduleOrFactory;
|
|
1306
1387
|
} catch (error) {
|
|
1307
|
-
|
|
1388
|
+
const { from = 'runtime' } = options || {
|
|
1389
|
+
from: 'runtime'
|
|
1390
|
+
};
|
|
1391
|
+
const failOver = await this.hooks.lifecycle.errorLoadRemote.emit({
|
|
1308
1392
|
id,
|
|
1309
|
-
error
|
|
1393
|
+
error,
|
|
1394
|
+
from,
|
|
1395
|
+
origin: this
|
|
1310
1396
|
});
|
|
1311
|
-
|
|
1397
|
+
if (!failOver) {
|
|
1398
|
+
throw error;
|
|
1399
|
+
}
|
|
1400
|
+
return failOver;
|
|
1312
1401
|
}
|
|
1313
1402
|
}
|
|
1314
1403
|
// eslint-disable-next-line @typescript-eslint/member-ordering
|
|
@@ -1342,14 +1431,9 @@ class FederationHost {
|
|
|
1342
1431
|
* It accepts one argument, the name of the share scope.
|
|
1343
1432
|
* If the share scope does not exist, it creates one.
|
|
1344
1433
|
*/ // eslint-disable-next-line @typescript-eslint/member-ordering
|
|
1345
|
-
initializeSharing(shareScopeName = DEFAULT_SCOPE) {
|
|
1346
|
-
const
|
|
1347
|
-
const shareScope = Global.__FEDERATION__.__SHARE__;
|
|
1434
|
+
initializeSharing(shareScopeName = DEFAULT_SCOPE, strategy) {
|
|
1435
|
+
const shareScope = this.shareScopeMap;
|
|
1348
1436
|
const hostName = this.options.name;
|
|
1349
|
-
// Executes only once
|
|
1350
|
-
if (shareScopeLoading[shareScopeName]) {
|
|
1351
|
-
return shareScopeLoading[shareScopeName];
|
|
1352
|
-
}
|
|
1353
1437
|
// Creates a new share scope if necessary
|
|
1354
1438
|
if (!shareScope[shareScopeName]) {
|
|
1355
1439
|
shareScope[shareScopeName] = {};
|
|
@@ -1357,21 +1441,27 @@ class FederationHost {
|
|
|
1357
1441
|
// Executes all initialization snippets from all accessible modules
|
|
1358
1442
|
const scope = shareScope[shareScopeName];
|
|
1359
1443
|
const register = (name, shared)=>{
|
|
1444
|
+
var _activeVersion_shareConfig;
|
|
1360
1445
|
const { version, eager } = shared;
|
|
1361
1446
|
scope[name] = scope[name] || {};
|
|
1362
1447
|
const versions = scope[name];
|
|
1363
1448
|
const activeVersion = versions[version];
|
|
1364
|
-
const activeVersionEager = Boolean(activeVersion && (activeVersion.eager || activeVersion.shareConfig.eager));
|
|
1449
|
+
const activeVersionEager = Boolean(activeVersion && (activeVersion.eager || ((_activeVersion_shareConfig = activeVersion.shareConfig) == null ? void 0 : _activeVersion_shareConfig.eager)));
|
|
1365
1450
|
if (!activeVersion || !activeVersion.loaded && (Boolean(!eager) !== !activeVersionEager ? eager : hostName > activeVersion.from)) {
|
|
1366
1451
|
versions[version] = shared;
|
|
1367
1452
|
}
|
|
1368
1453
|
};
|
|
1369
1454
|
const promises = [];
|
|
1455
|
+
const initFn = (mod)=>mod && mod.init && mod.init(shareScope[shareScopeName]);
|
|
1370
1456
|
const initRemoteModule = async (key)=>{
|
|
1371
1457
|
const { module } = await this._getRemoteModuleAndOptions(key);
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1458
|
+
if (module.getEntry) {
|
|
1459
|
+
const entry = await module.getEntry();
|
|
1460
|
+
if (!module.inited) {
|
|
1461
|
+
initFn(entry);
|
|
1462
|
+
module.inited = true;
|
|
1463
|
+
}
|
|
1464
|
+
}
|
|
1375
1465
|
};
|
|
1376
1466
|
Object.keys(this.options.shared).forEach((shareName)=>{
|
|
1377
1467
|
const shared = this.options.shared[shareName];
|
|
@@ -1379,15 +1469,17 @@ class FederationHost {
|
|
|
1379
1469
|
register(shareName, shared);
|
|
1380
1470
|
}
|
|
1381
1471
|
});
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
return shareScopeLoading[shareScopeName] = true;
|
|
1472
|
+
if (strategy === 'version-first') {
|
|
1473
|
+
this.options.remotes.forEach((remote)=>{
|
|
1474
|
+
if (remote.shareScope === shareScopeName) {
|
|
1475
|
+
promises.push(initRemoteModule(remote.name));
|
|
1476
|
+
}
|
|
1477
|
+
});
|
|
1389
1478
|
}
|
|
1390
|
-
return
|
|
1479
|
+
return promises;
|
|
1480
|
+
}
|
|
1481
|
+
initShareScopeMap(scopeName, shareScope) {
|
|
1482
|
+
this.shareScopeMap[scopeName] = shareScope;
|
|
1391
1483
|
}
|
|
1392
1484
|
formatOptions(globalOptions, userOptions) {
|
|
1393
1485
|
const formatShareOptions = formatShareConfigs(userOptions.shared || {}, userOptions.name);
|
|
@@ -1427,16 +1519,17 @@ class FederationHost {
|
|
|
1427
1519
|
}
|
|
1428
1520
|
return res;
|
|
1429
1521
|
}, globalOptionsRes.remotes);
|
|
1430
|
-
// register shared
|
|
1522
|
+
// register shared in shareScopeMap
|
|
1431
1523
|
const sharedKeys = Object.keys(formatShareOptions);
|
|
1432
1524
|
sharedKeys.forEach((sharedKey)=>{
|
|
1433
1525
|
const sharedVal = formatShareOptions[sharedKey];
|
|
1434
|
-
const
|
|
1435
|
-
if (!
|
|
1526
|
+
const registeredShared = getRegisteredShare(this.shareScopeMap, sharedKey, sharedVal, this.hooks.lifecycle.resolveShare);
|
|
1527
|
+
if (!registeredShared && sharedVal && sharedVal.lib) {
|
|
1436
1528
|
this.setShared({
|
|
1437
1529
|
pkgName: sharedKey,
|
|
1438
1530
|
lib: sharedVal.lib,
|
|
1439
1531
|
get: sharedVal.get,
|
|
1532
|
+
loaded: true,
|
|
1440
1533
|
shared: sharedVal,
|
|
1441
1534
|
from: userOptions.name
|
|
1442
1535
|
});
|
|
@@ -1471,7 +1564,6 @@ class FederationHost {
|
|
|
1471
1564
|
]);
|
|
1472
1565
|
}
|
|
1473
1566
|
setShared({ pkgName, shared, from, lib, loading, loaded, get }) {
|
|
1474
|
-
const target = getGlobalShareScope();
|
|
1475
1567
|
const { version, scope = 'default' } = shared, shareInfo = _object_without_properties_loose(shared, [
|
|
1476
1568
|
"version",
|
|
1477
1569
|
"scope"
|
|
@@ -1480,23 +1572,23 @@ class FederationHost {
|
|
|
1480
1572
|
scope
|
|
1481
1573
|
];
|
|
1482
1574
|
scopes.forEach((sc)=>{
|
|
1483
|
-
if (!
|
|
1484
|
-
|
|
1575
|
+
if (!this.shareScopeMap[sc]) {
|
|
1576
|
+
this.shareScopeMap[sc] = {};
|
|
1485
1577
|
}
|
|
1486
|
-
if (!
|
|
1487
|
-
|
|
1578
|
+
if (!this.shareScopeMap[sc][pkgName]) {
|
|
1579
|
+
this.shareScopeMap[sc][pkgName] = {};
|
|
1488
1580
|
}
|
|
1489
|
-
if (
|
|
1581
|
+
if (this.shareScopeMap[sc][pkgName][version]) {
|
|
1490
1582
|
warn(// eslint-disable-next-line max-len
|
|
1491
1583
|
`The share \n ${safeToString({
|
|
1492
1584
|
scope: sc,
|
|
1493
1585
|
pkgName,
|
|
1494
1586
|
version,
|
|
1495
|
-
from:
|
|
1587
|
+
from: this.shareScopeMap[sc][pkgName][version].from
|
|
1496
1588
|
})} has been registered`);
|
|
1497
1589
|
return;
|
|
1498
1590
|
}
|
|
1499
|
-
|
|
1591
|
+
this.shareScopeMap[sc][pkgName][version] = _extends({
|
|
1500
1592
|
version,
|
|
1501
1593
|
scope: [
|
|
1502
1594
|
'default'
|
|
@@ -1507,7 +1599,7 @@ class FederationHost {
|
|
|
1507
1599
|
loading
|
|
1508
1600
|
});
|
|
1509
1601
|
if (get) {
|
|
1510
|
-
|
|
1602
|
+
this.shareScopeMap[sc][pkgName][version].get = get;
|
|
1511
1603
|
}
|
|
1512
1604
|
});
|
|
1513
1605
|
}
|
|
@@ -1524,11 +1616,13 @@ class FederationHost {
|
|
|
1524
1616
|
errorLoadRemote: new AsyncHook('errorLoadRemote'),
|
|
1525
1617
|
beforeLoadShare: new AsyncWaterfallHook('beforeLoadShare'),
|
|
1526
1618
|
loadShare: new AsyncHook(),
|
|
1619
|
+
resolveShare: new SyncWaterfallHook('resolveShare'),
|
|
1527
1620
|
beforePreloadRemote: new AsyncHook(),
|
|
1528
1621
|
generatePreloadAssets: new AsyncHook('generatePreloadAssets'),
|
|
1529
1622
|
afterPreloadRemote: new AsyncHook()
|
|
1530
1623
|
});
|
|
1531
|
-
this.
|
|
1624
|
+
this.releaseNumber = `7`;
|
|
1625
|
+
this.version = `'0.0.7'`;
|
|
1532
1626
|
this.moduleCache = new Map();
|
|
1533
1627
|
this.loaderHook = new PluginSystem({
|
|
1534
1628
|
// FIXME: may not be suitable
|
|
@@ -1536,7 +1630,6 @@ class FederationHost {
|
|
|
1536
1630
|
createScript: new SyncHook(),
|
|
1537
1631
|
fetch: new AsyncHook('fetch')
|
|
1538
1632
|
});
|
|
1539
|
-
this.loadingShare = {};
|
|
1540
1633
|
// TODO: Validate the details of the options
|
|
1541
1634
|
// Initialize options with default values
|
|
1542
1635
|
const defaultOptions = {
|
|
@@ -1552,6 +1645,8 @@ class FederationHost {
|
|
|
1552
1645
|
};
|
|
1553
1646
|
this.name = userOptions.name;
|
|
1554
1647
|
this.options = defaultOptions;
|
|
1648
|
+
this.shareScopeMap = {};
|
|
1649
|
+
this._setGlobalShareScopeMap();
|
|
1555
1650
|
this.snapshotHandler = new SnapshotHandler(this);
|
|
1556
1651
|
this.registerPlugins([
|
|
1557
1652
|
...defaultOptions.plugins,
|
|
@@ -1574,6 +1669,9 @@ function init(options) {
|
|
|
1574
1669
|
} else {
|
|
1575
1670
|
// Merge options
|
|
1576
1671
|
instance.initOptions(options);
|
|
1672
|
+
if (!FederationInstance) {
|
|
1673
|
+
FederationInstance = instance;
|
|
1674
|
+
}
|
|
1577
1675
|
return instance;
|
|
1578
1676
|
}
|
|
1579
1677
|
}
|
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.7",
|
|
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
|
},
|