@module-federation/runtime 0.0.0-next-20231228055514 → 0.0.0-next-20231229074949
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 +71 -153
- package/dist/index.esm.js +73 -152
- package/dist/package.json +2 -2
- package/dist/share.cjs.js +116 -137
- package/dist/share.esm.js +116 -137
- package/dist/src/core.d.ts +5 -18
- package/dist/src/global.d.ts +4 -5
- package/dist/src/helpers.d.ts +2 -2
- package/dist/src/index.d.ts +0 -1
- package/dist/src/module/index.d.ts +2 -4
- package/dist/src/type/config.d.ts +2 -6
- package/dist/src/utils/share.d.ts +3 -12
- package/dist/type.cjs.d.ts +1 -0
- package/package.json +4 -4
- package/dist/types.cjs.d.ts +0 -1
- /package/dist/{types.cjs.js → type.cjs.js} +0 -0
- /package/dist/{types.esm.js → type.esm.js} +0 -0
package/dist/index.esm.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
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 getGlobalShare, m as getInfoWithoutType, n as getPreloaded, o as setPreloaded, p as getGlobalSnapshotInfoByModuleInfo, q as setGlobalSnapshotInfoByModuleInfo, r as getGlobalSnapshot, t as addUniqueItem, u as formatShareConfigs, v as isBrowserEnv, x as getGlobalShareScope, 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,
|
|
4
|
-
export { loadScript } from '@module-federation/sdk';
|
|
3
|
+
import { composeKeyWithSeparator, loadScript, createScript, getResourceUrl, isManifestProvider, generateSnapshotFromManifest } from '@module-federation/sdk';
|
|
5
4
|
|
|
6
5
|
// Function to match a remote with its name and expose
|
|
7
6
|
// id: pkgName(@federation/app1) + expose(button) = @federation/app1/button
|
|
@@ -119,27 +118,6 @@ async function loadEntryScript({ name, globalName, entry, createScriptHook }) {
|
|
|
119
118
|
if (remoteEntryExports) {
|
|
120
119
|
return remoteEntryExports;
|
|
121
120
|
}
|
|
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
|
-
}
|
|
143
121
|
return loadScript(entry, {
|
|
144
122
|
attrs: {},
|
|
145
123
|
createScriptHook
|
|
@@ -152,8 +130,6 @@ async function loadEntryScript({ name, globalName, entry, createScriptHook }) {
|
|
|
152
130
|
2. ${remoteEntryKey} cannot be used to get remoteEntry exports in the window object.
|
|
153
131
|
`);
|
|
154
132
|
return entryExports;
|
|
155
|
-
}).catch((e)=>{
|
|
156
|
-
return e;
|
|
157
133
|
});
|
|
158
134
|
}
|
|
159
135
|
async function getRemoteEntry({ remoteEntryExports, remoteInfo, createScriptHook }) {
|
|
@@ -215,10 +191,6 @@ let Module = class Module {
|
|
|
215
191
|
const res = this.loaderHook.lifecycle.createScript.emit({
|
|
216
192
|
url
|
|
217
193
|
});
|
|
218
|
-
if (typeof document === 'undefined') {
|
|
219
|
-
//todo: needs real fix
|
|
220
|
-
return res;
|
|
221
|
-
}
|
|
222
194
|
if (res instanceof HTMLScriptElement) {
|
|
223
195
|
return res;
|
|
224
196
|
}
|
|
@@ -234,16 +206,15 @@ let Module = class Module {
|
|
|
234
206
|
const { loadFactory = true } = options || {
|
|
235
207
|
loadFactory: true
|
|
236
208
|
};
|
|
237
|
-
this.hostInfo.name;
|
|
238
209
|
// Get remoteEntry.js
|
|
239
210
|
const remoteEntryExports = await this.getEntry();
|
|
240
211
|
if (!this.inited) {
|
|
241
|
-
const
|
|
212
|
+
const globalShareScope = Global.__FEDERATION__.__SHARE__;
|
|
242
213
|
const remoteShareScope = this.remoteInfo.shareScope || 'default';
|
|
243
|
-
if (!
|
|
244
|
-
|
|
214
|
+
if (!globalShareScope[remoteShareScope]) {
|
|
215
|
+
globalShareScope[remoteShareScope] = {};
|
|
245
216
|
}
|
|
246
|
-
const shareScope =
|
|
217
|
+
const shareScope = globalShareScope[remoteShareScope];
|
|
247
218
|
// TODO: compat logic , it could be moved after providing startup hooks
|
|
248
219
|
const remoteEntryInitOptions = {
|
|
249
220
|
version: this.remoteInfo.version || '',
|
|
@@ -253,18 +224,10 @@ let Module = class Module {
|
|
|
253
224
|
remoteEntryExports.init(shareScope, [], remoteEntryInitOptions);
|
|
254
225
|
const federationInstance = Global.__FEDERATION__.__INSTANCES__.find((i)=>i.options.id === composeKeyWithSeparator(this.remoteInfo.name, this.remoteInfo.buildVersion));
|
|
255
226
|
if (federationInstance) {
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
remotes: [],
|
|
261
|
-
name: this.remoteInfo.name
|
|
262
|
-
}));
|
|
263
|
-
if (!__FEDERATION__.__SHARE__['default'] && this.shareScopeMap && this.shareScopeMap['default']) {
|
|
264
|
-
// @ts-ignore compat prev logic , and it will be optimized by supporting startup hook
|
|
265
|
-
__FEDERATION__.__SHARE__['default'] = this.shareScopeMap['default'];
|
|
266
|
-
}
|
|
267
|
-
}
|
|
227
|
+
federationInstance.initOptions(_extends$4({}, remoteEntryInitOptions, {
|
|
228
|
+
remotes: [],
|
|
229
|
+
name: this.remoteInfo.name
|
|
230
|
+
}));
|
|
268
231
|
}
|
|
269
232
|
}
|
|
270
233
|
this.lib = remoteEntryExports;
|
|
@@ -279,7 +242,7 @@ let Module = class Module {
|
|
|
279
242
|
return exposeContent;
|
|
280
243
|
}
|
|
281
244
|
// loading: Record<string, undefined | Promise<RemoteEntryExports | void>> = {};
|
|
282
|
-
constructor({ hostInfo, remoteInfo, shared, loaderHook
|
|
245
|
+
constructor({ hostInfo, remoteInfo, shared, loaderHook }){
|
|
283
246
|
this.inited = false;
|
|
284
247
|
this.shared = {};
|
|
285
248
|
this.lib = undefined;
|
|
@@ -287,7 +250,6 @@ let Module = class Module {
|
|
|
287
250
|
this.remoteInfo = remoteInfo;
|
|
288
251
|
this.shared = shared;
|
|
289
252
|
this.loaderHook = loaderHook;
|
|
290
|
-
this.shareScopeMap = shareScopeMap;
|
|
291
253
|
}
|
|
292
254
|
};
|
|
293
255
|
|
|
@@ -814,9 +776,9 @@ function generatePreloadAssets(origin, preloadOptions, remote, globalSnapshot, r
|
|
|
814
776
|
if (!shareInfo) {
|
|
815
777
|
return;
|
|
816
778
|
}
|
|
817
|
-
const
|
|
779
|
+
const globalShare = getGlobalShare(shared.sharedName, shareInfo);
|
|
818
780
|
// 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.
|
|
819
|
-
if (
|
|
781
|
+
if (globalShare && typeof globalShare.lib === 'function') {
|
|
820
782
|
shared.assets.js.sync.forEach((asset)=>{
|
|
821
783
|
loadedSharedJsAssets.add(asset);
|
|
822
784
|
});
|
|
@@ -1143,13 +1105,6 @@ function _object_without_properties_loose(source, excluded) {
|
|
|
1143
1105
|
return target;
|
|
1144
1106
|
}
|
|
1145
1107
|
class FederationHost {
|
|
1146
|
-
_setGlobalShareScopeMap() {
|
|
1147
|
-
const globalShareScopeMap = getGlobalShareScope();
|
|
1148
|
-
const identifier = this.options.id || this.options.name;
|
|
1149
|
-
if (identifier && !globalShareScopeMap[identifier]) {
|
|
1150
|
-
globalShareScopeMap[identifier] = this.shareScopeMap;
|
|
1151
|
-
}
|
|
1152
|
-
}
|
|
1153
1108
|
initOptions(userOptions) {
|
|
1154
1109
|
this.registerPlugins(userOptions.plugins);
|
|
1155
1110
|
const options = this.formatOptions(this.options, userOptions);
|
|
@@ -1164,11 +1119,6 @@ class FederationHost {
|
|
|
1164
1119
|
// 2. Searches globally for a matching share, if found, it uses it directly
|
|
1165
1120
|
// 3. If not found, it retrieves it from the current share and stores the obtained share globally.
|
|
1166
1121
|
const shareInfo = Object.assign({}, (_this_options_shared = this.options.shared) == null ? void 0 : _this_options_shared[pkgName], customShareInfo);
|
|
1167
|
-
if (shareInfo == null ? void 0 : shareInfo.scope) {
|
|
1168
|
-
shareInfo.scope.forEach((shareScope)=>{
|
|
1169
|
-
this.initializeSharing(shareScope, shareInfo.strategy);
|
|
1170
|
-
});
|
|
1171
|
-
}
|
|
1172
1122
|
const loadShareRes = await this.hooks.lifecycle.beforeLoadShare.emit({
|
|
1173
1123
|
pkgName,
|
|
1174
1124
|
shareInfo,
|
|
@@ -1179,42 +1129,30 @@ class FederationHost {
|
|
|
1179
1129
|
// Assert that shareInfoRes exists, if not, throw an error
|
|
1180
1130
|
assert(shareInfoRes, `Cannot find ${pkgName} Share in the ${this.options.name}. Please ensure that the ${pkgName} Share parameters have been injected`);
|
|
1181
1131
|
// Retrieve from cache
|
|
1182
|
-
const
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
if (registeredShared && registeredShared.lib) {
|
|
1190
|
-
addUseIn(registeredShared);
|
|
1191
|
-
return registeredShared.lib;
|
|
1192
|
-
} else if (registeredShared && registeredShared.loading && !registeredShared.loaded) {
|
|
1193
|
-
const factory = await registeredShared.loading;
|
|
1194
|
-
registeredShared.loaded = true;
|
|
1195
|
-
if (!registeredShared.lib) {
|
|
1196
|
-
registeredShared.lib = factory;
|
|
1197
|
-
}
|
|
1198
|
-
addUseIn(registeredShared);
|
|
1132
|
+
const globalShare = getGlobalShare(pkgName, shareInfoRes);
|
|
1133
|
+
if (globalShare && globalShare.lib) {
|
|
1134
|
+
addUniqueItem(globalShare.useIn, this.options.name);
|
|
1135
|
+
return globalShare.lib;
|
|
1136
|
+
} else if (globalShare && globalShare.loading) {
|
|
1137
|
+
const factory = await globalShare.loading;
|
|
1138
|
+
addUniqueItem(globalShare.useIn, this.options.name);
|
|
1199
1139
|
return factory;
|
|
1200
|
-
} else if (
|
|
1140
|
+
} else if (globalShare) {
|
|
1201
1141
|
const asyncLoadProcess = async ()=>{
|
|
1202
|
-
const factory = await
|
|
1142
|
+
const factory = await globalShare.get();
|
|
1203
1143
|
shareInfoRes.lib = factory;
|
|
1204
|
-
shareInfoRes.
|
|
1205
|
-
|
|
1206
|
-
const gShared = getRegisteredShare(this.shareScopeMap, pkgName, shareInfoRes, this.hooks.lifecycle.resolveShare);
|
|
1144
|
+
addUniqueItem(shareInfoRes.useIn, this.options.name);
|
|
1145
|
+
const gShared = getGlobalShare(pkgName, shareInfoRes);
|
|
1207
1146
|
if (gShared) {
|
|
1208
1147
|
gShared.lib = factory;
|
|
1209
|
-
gShared.loaded = true;
|
|
1210
1148
|
}
|
|
1211
1149
|
return factory;
|
|
1212
1150
|
};
|
|
1213
1151
|
const loading = asyncLoadProcess();
|
|
1214
1152
|
this.setShared({
|
|
1215
1153
|
pkgName,
|
|
1216
|
-
loaded:
|
|
1217
|
-
shared:
|
|
1154
|
+
loaded: true,
|
|
1155
|
+
shared: shareInfoRes,
|
|
1218
1156
|
from: this.options.name,
|
|
1219
1157
|
lib: null,
|
|
1220
1158
|
loading
|
|
@@ -1227,19 +1165,17 @@ class FederationHost {
|
|
|
1227
1165
|
const asyncLoadProcess = async ()=>{
|
|
1228
1166
|
const factory = await shareInfoRes.get();
|
|
1229
1167
|
shareInfoRes.lib = factory;
|
|
1230
|
-
shareInfoRes.
|
|
1231
|
-
|
|
1232
|
-
const gShared = getRegisteredShare(this.shareScopeMap, pkgName, shareInfoRes, this.hooks.lifecycle.resolveShare);
|
|
1168
|
+
addUniqueItem(shareInfoRes.useIn, this.options.name);
|
|
1169
|
+
const gShared = getGlobalShare(pkgName, shareInfoRes);
|
|
1233
1170
|
if (gShared) {
|
|
1234
1171
|
gShared.lib = factory;
|
|
1235
|
-
gShared.loaded = true;
|
|
1236
1172
|
}
|
|
1237
1173
|
return factory;
|
|
1238
1174
|
};
|
|
1239
1175
|
const loading = asyncLoadProcess();
|
|
1240
1176
|
this.setShared({
|
|
1241
1177
|
pkgName,
|
|
1242
|
-
loaded:
|
|
1178
|
+
loaded: true,
|
|
1243
1179
|
shared: shareInfoRes,
|
|
1244
1180
|
from: this.options.name,
|
|
1245
1181
|
lib: null,
|
|
@@ -1255,16 +1191,16 @@ class FederationHost {
|
|
|
1255
1191
|
loadShareSync(pkgName) {
|
|
1256
1192
|
var _this_options_shared;
|
|
1257
1193
|
const shareInfo = (_this_options_shared = this.options.shared) == null ? void 0 : _this_options_shared[pkgName];
|
|
1258
|
-
const
|
|
1259
|
-
if (
|
|
1260
|
-
addUniqueItem(
|
|
1261
|
-
if (!
|
|
1262
|
-
|
|
1263
|
-
if (
|
|
1194
|
+
const globalShare = getGlobalShare(pkgName, shareInfo);
|
|
1195
|
+
if (globalShare && typeof globalShare.lib === 'function') {
|
|
1196
|
+
addUniqueItem(globalShare.useIn, this.options.name);
|
|
1197
|
+
if (!globalShare.loaded) {
|
|
1198
|
+
globalShare.loaded = true;
|
|
1199
|
+
if (globalShare.from === this.options.name) {
|
|
1264
1200
|
shareInfo.loaded = true;
|
|
1265
1201
|
}
|
|
1266
1202
|
}
|
|
1267
|
-
return
|
|
1203
|
+
return globalShare.lib;
|
|
1268
1204
|
}
|
|
1269
1205
|
if (shareInfo.lib) {
|
|
1270
1206
|
if (!shareInfo.loaded) {
|
|
@@ -1335,8 +1271,7 @@ class FederationHost {
|
|
|
1335
1271
|
remoteInfo,
|
|
1336
1272
|
shared: this.options.shared || {},
|
|
1337
1273
|
plugins: this.options.plugins,
|
|
1338
|
-
loaderHook: this.loaderHook
|
|
1339
|
-
shareScopeMap: this.shareScopeMap
|
|
1274
|
+
loaderHook: this.loaderHook
|
|
1340
1275
|
};
|
|
1341
1276
|
if (!module) {
|
|
1342
1277
|
module = new Module(moduleOptions);
|
|
@@ -1378,19 +1313,11 @@ class FederationHost {
|
|
|
1378
1313
|
});
|
|
1379
1314
|
return moduleOrFactory;
|
|
1380
1315
|
} catch (error) {
|
|
1381
|
-
|
|
1382
|
-
from: 'runtime'
|
|
1383
|
-
};
|
|
1384
|
-
const failOver = await this.hooks.lifecycle.errorLoadRemote.emit({
|
|
1316
|
+
this.hooks.lifecycle.errorLoadRemote.emit({
|
|
1385
1317
|
id,
|
|
1386
|
-
error
|
|
1387
|
-
from,
|
|
1388
|
-
origin: this
|
|
1318
|
+
error
|
|
1389
1319
|
});
|
|
1390
|
-
|
|
1391
|
-
throw error;
|
|
1392
|
-
}
|
|
1393
|
-
return failOver;
|
|
1320
|
+
throw error;
|
|
1394
1321
|
}
|
|
1395
1322
|
}
|
|
1396
1323
|
// eslint-disable-next-line @typescript-eslint/member-ordering
|
|
@@ -1424,9 +1351,14 @@ class FederationHost {
|
|
|
1424
1351
|
* It accepts one argument, the name of the share scope.
|
|
1425
1352
|
* If the share scope does not exist, it creates one.
|
|
1426
1353
|
*/ // eslint-disable-next-line @typescript-eslint/member-ordering
|
|
1427
|
-
initializeSharing(shareScopeName = DEFAULT_SCOPE
|
|
1428
|
-
const
|
|
1354
|
+
initializeSharing(shareScopeName = DEFAULT_SCOPE) {
|
|
1355
|
+
const shareScopeLoading = Global.__FEDERATION__.__SHARE_SCOPE_LOADING__;
|
|
1356
|
+
const shareScope = Global.__FEDERATION__.__SHARE__;
|
|
1429
1357
|
const hostName = this.options.name;
|
|
1358
|
+
// Executes only once
|
|
1359
|
+
if (shareScopeLoading[shareScopeName]) {
|
|
1360
|
+
return shareScopeLoading[shareScopeName];
|
|
1361
|
+
}
|
|
1430
1362
|
// Creates a new share scope if necessary
|
|
1431
1363
|
if (!shareScope[shareScopeName]) {
|
|
1432
1364
|
shareScope[shareScopeName] = {};
|
|
@@ -1434,27 +1366,21 @@ class FederationHost {
|
|
|
1434
1366
|
// Executes all initialization snippets from all accessible modules
|
|
1435
1367
|
const scope = shareScope[shareScopeName];
|
|
1436
1368
|
const register = (name, shared)=>{
|
|
1437
|
-
var _activeVersion_shareConfig;
|
|
1438
1369
|
const { version, eager } = shared;
|
|
1439
1370
|
scope[name] = scope[name] || {};
|
|
1440
1371
|
const versions = scope[name];
|
|
1441
1372
|
const activeVersion = versions[version];
|
|
1442
|
-
const activeVersionEager = Boolean(activeVersion && (activeVersion.eager ||
|
|
1373
|
+
const activeVersionEager = Boolean(activeVersion && (activeVersion.eager || activeVersion.shareConfig.eager));
|
|
1443
1374
|
if (!activeVersion || !activeVersion.loaded && (Boolean(!eager) !== !activeVersionEager ? eager : hostName > activeVersion.from)) {
|
|
1444
1375
|
versions[version] = shared;
|
|
1445
1376
|
}
|
|
1446
1377
|
};
|
|
1447
1378
|
const promises = [];
|
|
1448
|
-
const initFn = (mod)=>mod && mod.init && mod.init(shareScope[shareScopeName]);
|
|
1449
1379
|
const initRemoteModule = async (key)=>{
|
|
1450
1380
|
const { module } = await this._getRemoteModuleAndOptions(key);
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
initFn(entry);
|
|
1455
|
-
module.inited = true;
|
|
1456
|
-
}
|
|
1457
|
-
}
|
|
1381
|
+
const initFn = (mod)=>mod && mod.init && mod.init(shareScope[shareScopeName]);
|
|
1382
|
+
const entry = await module.getEntry();
|
|
1383
|
+
initFn(entry);
|
|
1458
1384
|
};
|
|
1459
1385
|
Object.keys(this.options.shared).forEach((shareName)=>{
|
|
1460
1386
|
const shared = this.options.shared[shareName];
|
|
@@ -1462,17 +1388,15 @@ class FederationHost {
|
|
|
1462
1388
|
register(shareName, shared);
|
|
1463
1389
|
}
|
|
1464
1390
|
});
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1391
|
+
this.options.remotes.forEach((remote)=>{
|
|
1392
|
+
if (remote.shareScope === shareScopeName) {
|
|
1393
|
+
promises.push(initRemoteModule(remote.name));
|
|
1394
|
+
}
|
|
1395
|
+
});
|
|
1396
|
+
if (!promises.length) {
|
|
1397
|
+
return shareScopeLoading[shareScopeName] = true;
|
|
1471
1398
|
}
|
|
1472
|
-
return promises;
|
|
1473
|
-
}
|
|
1474
|
-
initShareScopeMap(scopeName, shareScope) {
|
|
1475
|
-
this.shareScopeMap[scopeName] = shareScope;
|
|
1399
|
+
return shareScopeLoading[shareScopeName] = Promise.all(promises).then(()=>shareScopeLoading[shareScopeName] = true);
|
|
1476
1400
|
}
|
|
1477
1401
|
formatOptions(globalOptions, userOptions) {
|
|
1478
1402
|
const formatShareOptions = formatShareConfigs(userOptions.shared || {}, userOptions.name);
|
|
@@ -1512,17 +1436,16 @@ class FederationHost {
|
|
|
1512
1436
|
}
|
|
1513
1437
|
return res;
|
|
1514
1438
|
}, globalOptionsRes.remotes);
|
|
1515
|
-
// register shared
|
|
1439
|
+
// register shared include lib
|
|
1516
1440
|
const sharedKeys = Object.keys(formatShareOptions);
|
|
1517
1441
|
sharedKeys.forEach((sharedKey)=>{
|
|
1518
1442
|
const sharedVal = formatShareOptions[sharedKey];
|
|
1519
|
-
const
|
|
1520
|
-
if (!
|
|
1443
|
+
const globalShare = getGlobalShare(sharedKey, sharedVal);
|
|
1444
|
+
if (!globalShare && sharedVal && sharedVal.lib) {
|
|
1521
1445
|
this.setShared({
|
|
1522
1446
|
pkgName: sharedKey,
|
|
1523
1447
|
lib: sharedVal.lib,
|
|
1524
1448
|
get: sharedVal.get,
|
|
1525
|
-
loaded: true,
|
|
1526
1449
|
shared: sharedVal,
|
|
1527
1450
|
from: userOptions.name
|
|
1528
1451
|
});
|
|
@@ -1557,6 +1480,7 @@ class FederationHost {
|
|
|
1557
1480
|
]);
|
|
1558
1481
|
}
|
|
1559
1482
|
setShared({ pkgName, shared, from, lib, loading, loaded, get }) {
|
|
1483
|
+
const target = getGlobalShareScope();
|
|
1560
1484
|
const { version, scope = 'default' } = shared, shareInfo = _object_without_properties_loose(shared, [
|
|
1561
1485
|
"version",
|
|
1562
1486
|
"scope"
|
|
@@ -1565,23 +1489,23 @@ class FederationHost {
|
|
|
1565
1489
|
scope
|
|
1566
1490
|
];
|
|
1567
1491
|
scopes.forEach((sc)=>{
|
|
1568
|
-
if (!
|
|
1569
|
-
|
|
1492
|
+
if (!target[sc]) {
|
|
1493
|
+
target[sc] = {};
|
|
1570
1494
|
}
|
|
1571
|
-
if (!
|
|
1572
|
-
|
|
1495
|
+
if (!target[sc][pkgName]) {
|
|
1496
|
+
target[sc][pkgName] = {};
|
|
1573
1497
|
}
|
|
1574
|
-
if (
|
|
1498
|
+
if (target[sc][pkgName][version]) {
|
|
1575
1499
|
warn(// eslint-disable-next-line max-len
|
|
1576
1500
|
`The share \n ${safeToString({
|
|
1577
1501
|
scope: sc,
|
|
1578
1502
|
pkgName,
|
|
1579
1503
|
version,
|
|
1580
|
-
from:
|
|
1504
|
+
from: target[sc][pkgName][version].from
|
|
1581
1505
|
})} has been registered`);
|
|
1582
1506
|
return;
|
|
1583
1507
|
}
|
|
1584
|
-
|
|
1508
|
+
target[sc][pkgName][version] = _extends({
|
|
1585
1509
|
version,
|
|
1586
1510
|
scope: [
|
|
1587
1511
|
'default'
|
|
@@ -1592,7 +1516,7 @@ class FederationHost {
|
|
|
1592
1516
|
loading
|
|
1593
1517
|
});
|
|
1594
1518
|
if (get) {
|
|
1595
|
-
|
|
1519
|
+
target[sc][pkgName][version].get = get;
|
|
1596
1520
|
}
|
|
1597
1521
|
});
|
|
1598
1522
|
}
|
|
@@ -1607,13 +1531,11 @@ class FederationHost {
|
|
|
1607
1531
|
errorLoadRemote: new AsyncHook('errorLoadRemote'),
|
|
1608
1532
|
beforeLoadShare: new AsyncWaterfallHook('beforeLoadShare'),
|
|
1609
1533
|
loadShare: new AsyncHook(),
|
|
1610
|
-
resolveShare: new SyncWaterfallHook('resolveShare'),
|
|
1611
1534
|
beforePreloadRemote: new AsyncHook(),
|
|
1612
1535
|
generatePreloadAssets: new AsyncHook('generatePreloadAssets'),
|
|
1613
1536
|
afterPreloadRemote: new AsyncHook()
|
|
1614
1537
|
});
|
|
1615
|
-
this.
|
|
1616
|
-
this.version = `0.0.4`;
|
|
1538
|
+
this.version = '0.0.4';
|
|
1617
1539
|
this.moduleCache = new Map();
|
|
1618
1540
|
this.loaderHook = new PluginSystem({
|
|
1619
1541
|
// FIXME: may not be suitable
|
|
@@ -1621,6 +1543,7 @@ class FederationHost {
|
|
|
1621
1543
|
createScript: new SyncHook(),
|
|
1622
1544
|
fetch: new AsyncHook('fetch')
|
|
1623
1545
|
});
|
|
1546
|
+
this.loadingShare = {};
|
|
1624
1547
|
// TODO: Validate the details of the options
|
|
1625
1548
|
// Initialize options with default values
|
|
1626
1549
|
const defaultOptions = {
|
|
@@ -1636,8 +1559,6 @@ class FederationHost {
|
|
|
1636
1559
|
};
|
|
1637
1560
|
this.name = userOptions.name;
|
|
1638
1561
|
this.options = defaultOptions;
|
|
1639
|
-
this.shareScopeMap = {};
|
|
1640
|
-
this._setGlobalShareScopeMap();
|
|
1641
1562
|
this.snapshotHandler = new SnapshotHandler(this);
|
|
1642
1563
|
this.registerPlugins([
|
|
1643
1564
|
...defaultOptions.plugins,
|