@module-federation/runtime 0.0.0-next-20240102063242 → 0.0.0-next-20240103035759
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 +85 -174
- package/dist/index.esm.js +87 -173
- package/dist/package.json +2 -2
- package/dist/share.cjs.js +52 -81
- package/dist/share.esm.js +52 -81
- package/dist/src/core.d.ts +20 -18
- package/dist/src/global.d.ts +3 -2
- package/dist/src/helpers.d.ts +4 -3
- package/dist/src/index.d.ts +0 -1
- package/dist/src/module/index.d.ts +4 -12
- package/dist/src/type/config.d.ts +3 -6
- package/dist/src/type/plugin.d.ts +1 -1
- package/dist/src/utils/plugin.d.ts +1 -1
- 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/helpers.cjs.js
CHANGED
|
@@ -3,10 +3,11 @@
|
|
|
3
3
|
var share = require('./share.cjs.js');
|
|
4
4
|
|
|
5
5
|
const ShareUtils = {
|
|
6
|
-
|
|
6
|
+
getGlobalShare: share.getGlobalShare,
|
|
7
7
|
getGlobalShareScope: share.getGlobalShareScope
|
|
8
8
|
};
|
|
9
9
|
const GlobalUtils = {
|
|
10
|
+
Global: share.Global,
|
|
10
11
|
nativeGlobal: share.nativeGlobal,
|
|
11
12
|
resetFederationGlobalInfo: share.resetFederationGlobalInfo,
|
|
12
13
|
getGlobalFederationInstance: share.getGlobalFederationInstance,
|
package/dist/helpers.esm.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import { l as
|
|
1
|
+
import { l as getGlobalShare, x as getGlobalShareScope, G as Global, F as nativeGlobal, H as resetFederationGlobalInfo, A as getGlobalFederationInstance, C as setGlobalFederationInstance, B as getGlobalFederationConstructor, z as setGlobalFederationConstructor, m as getInfoWithoutType, r as getGlobalSnapshot, I as getTargetSnapshotInfoByModuleInfo, p as getGlobalSnapshotInfoByModuleInfo, q as setGlobalSnapshotInfoByModuleInfo, J as addGlobalSnapshot, c as getRemoteEntryExports, E as registerGlobalPlugins, g as getGlobalHostPlugins, n as getPreloaded, o as setPreloaded } from './share.esm.js';
|
|
2
2
|
|
|
3
3
|
const ShareUtils = {
|
|
4
|
-
|
|
4
|
+
getGlobalShare,
|
|
5
5
|
getGlobalShareScope
|
|
6
6
|
};
|
|
7
7
|
const GlobalUtils = {
|
|
8
|
+
Global,
|
|
8
9
|
nativeGlobal,
|
|
9
10
|
resetFederationGlobalInfo,
|
|
10
11
|
getGlobalFederationInstance,
|
package/dist/index.cjs.js
CHANGED
|
@@ -121,27 +121,6 @@ async function loadEntryScript({ name, globalName, entry, createScriptHook }) {
|
|
|
121
121
|
if (remoteEntryExports) {
|
|
122
122
|
return remoteEntryExports;
|
|
123
123
|
}
|
|
124
|
-
if (typeof document === 'undefined') {
|
|
125
|
-
return sdk.loadScriptNode(entry, {
|
|
126
|
-
attrs: {
|
|
127
|
-
name,
|
|
128
|
-
globalName
|
|
129
|
-
},
|
|
130
|
-
createScriptHook
|
|
131
|
-
}).then(()=>{
|
|
132
|
-
const { remoteEntryKey, entryExports } = share.getRemoteEntryExports(name, globalName);
|
|
133
|
-
share.assert(entryExports, `
|
|
134
|
-
Unable to use the ${name}'s '${entry}' URL with ${remoteEntryKey}'s globalName to get remoteEntry exports.
|
|
135
|
-
Possible reasons could be:\n
|
|
136
|
-
1. '${entry}' is not the correct URL, or the remoteEntry resource or name is incorrect.\n
|
|
137
|
-
2. ${remoteEntryKey} cannot be used to get remoteEntry exports in the window object.
|
|
138
|
-
`);
|
|
139
|
-
console.log(entryExports);
|
|
140
|
-
return entryExports;
|
|
141
|
-
}).catch((e)=>{
|
|
142
|
-
return e;
|
|
143
|
-
});
|
|
144
|
-
}
|
|
145
124
|
return sdk.loadScript(entry, {
|
|
146
125
|
attrs: {},
|
|
147
126
|
createScriptHook
|
|
@@ -154,8 +133,6 @@ async function loadEntryScript({ name, globalName, entry, createScriptHook }) {
|
|
|
154
133
|
2. ${remoteEntryKey} cannot be used to get remoteEntry exports in the window object.
|
|
155
134
|
`);
|
|
156
135
|
return entryExports;
|
|
157
|
-
}).catch((e)=>{
|
|
158
|
-
return e;
|
|
159
136
|
});
|
|
160
137
|
}
|
|
161
138
|
async function getRemoteEntry({ remoteEntryExports, remoteInfo, createScriptHook }) {
|
|
@@ -214,13 +191,9 @@ let Module = class Module {
|
|
|
214
191
|
remoteInfo: this.remoteInfo,
|
|
215
192
|
remoteEntryExports: this.remoteEntryExports,
|
|
216
193
|
createScriptHook: (url)=>{
|
|
217
|
-
const res = this.loaderHook.lifecycle.createScript.emit({
|
|
194
|
+
const res = this.host.loaderHook.lifecycle.createScript.emit({
|
|
218
195
|
url
|
|
219
196
|
});
|
|
220
|
-
if (typeof document === 'undefined') {
|
|
221
|
-
//todo: needs real fix
|
|
222
|
-
return res;
|
|
223
|
-
}
|
|
224
197
|
if (res instanceof HTMLScriptElement) {
|
|
225
198
|
return res;
|
|
226
199
|
}
|
|
@@ -236,38 +209,30 @@ let Module = class Module {
|
|
|
236
209
|
const { loadFactory = true } = options || {
|
|
237
210
|
loadFactory: true
|
|
238
211
|
};
|
|
239
|
-
this.hostInfo.name;
|
|
240
212
|
// Get remoteEntry.js
|
|
241
213
|
const remoteEntryExports = await this.getEntry();
|
|
242
214
|
if (!this.inited) {
|
|
243
|
-
const
|
|
215
|
+
const globalShareScope = share.Global.__FEDERATION__.__SHARE__;
|
|
244
216
|
const remoteShareScope = this.remoteInfo.shareScope || 'default';
|
|
245
|
-
if (!
|
|
246
|
-
|
|
217
|
+
if (!globalShareScope[remoteShareScope]) {
|
|
218
|
+
globalShareScope[remoteShareScope] = {};
|
|
247
219
|
}
|
|
248
|
-
const shareScope =
|
|
249
|
-
|
|
220
|
+
const shareScope = globalShareScope[remoteShareScope];
|
|
221
|
+
const initScope = [];
|
|
250
222
|
const remoteEntryInitOptions = {
|
|
251
|
-
version: this.remoteInfo.version || ''
|
|
252
|
-
// @ts-ignore it will be passed by startup hooks
|
|
253
|
-
region: this.hostInfo.region
|
|
223
|
+
version: this.remoteInfo.version || ''
|
|
254
224
|
};
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
// @ts-ignore compat prev logic , and it will be optimized by supporting startup hook
|
|
267
|
-
__FEDERATION__.__SHARE__['default'] = this.shareScopeMap['default'];
|
|
268
|
-
}
|
|
269
|
-
}
|
|
270
|
-
}
|
|
225
|
+
const initContainerOptions = await this.host.hooks.lifecycle.beforeInitContainer.emit({
|
|
226
|
+
shareScope,
|
|
227
|
+
remoteEntryInitOptions,
|
|
228
|
+
initScope,
|
|
229
|
+
remoteInfo: this.remoteInfo,
|
|
230
|
+
origin: this.host
|
|
231
|
+
});
|
|
232
|
+
remoteEntryExports.init(initContainerOptions.shareScope, initContainerOptions.initScope, initContainerOptions.remoteEntryInitOptions);
|
|
233
|
+
await this.host.hooks.lifecycle.initContainer.emit(_extends$4({}, initContainerOptions, {
|
|
234
|
+
remoteEntryExports
|
|
235
|
+
}));
|
|
271
236
|
}
|
|
272
237
|
this.lib = remoteEntryExports;
|
|
273
238
|
this.inited = true;
|
|
@@ -280,16 +245,11 @@ let Module = class Module {
|
|
|
280
245
|
const exposeContent = await moduleFactory();
|
|
281
246
|
return exposeContent;
|
|
282
247
|
}
|
|
283
|
-
|
|
284
|
-
constructor({ hostInfo, remoteInfo, shared, loaderHook, shareScopeMap }){
|
|
248
|
+
constructor({ remoteInfo, host }){
|
|
285
249
|
this.inited = false;
|
|
286
|
-
this.shared = {};
|
|
287
250
|
this.lib = undefined;
|
|
288
|
-
this.hostInfo = hostInfo;
|
|
289
251
|
this.remoteInfo = remoteInfo;
|
|
290
|
-
this.
|
|
291
|
-
this.loaderHook = loaderHook;
|
|
292
|
-
this.shareScopeMap = shareScopeMap;
|
|
252
|
+
this.host = host;
|
|
293
253
|
}
|
|
294
254
|
};
|
|
295
255
|
|
|
@@ -816,9 +776,9 @@ function generatePreloadAssets(origin, preloadOptions, remote, globalSnapshot, r
|
|
|
816
776
|
if (!shareInfo) {
|
|
817
777
|
return;
|
|
818
778
|
}
|
|
819
|
-
const
|
|
779
|
+
const globalShare = share.getGlobalShare(shared.sharedName, shareInfo);
|
|
820
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.
|
|
821
|
-
if (
|
|
781
|
+
if (globalShare && typeof globalShare.lib === 'function') {
|
|
822
782
|
shared.assets.js.sync.forEach((asset)=>{
|
|
823
783
|
loadedSharedJsAssets.add(asset);
|
|
824
784
|
});
|
|
@@ -1145,13 +1105,6 @@ function _object_without_properties_loose(source, excluded) {
|
|
|
1145
1105
|
return target;
|
|
1146
1106
|
}
|
|
1147
1107
|
class FederationHost {
|
|
1148
|
-
_setGlobalShareScopeMap() {
|
|
1149
|
-
const globalShareScopeMap = share.getGlobalShareScope();
|
|
1150
|
-
const identifier = this.options.id || this.options.name;
|
|
1151
|
-
if (identifier && !globalShareScopeMap[identifier]) {
|
|
1152
|
-
globalShareScopeMap[identifier] = this.shareScopeMap;
|
|
1153
|
-
}
|
|
1154
|
-
}
|
|
1155
1108
|
initOptions(userOptions) {
|
|
1156
1109
|
this.registerPlugins(userOptions.plugins);
|
|
1157
1110
|
const options = this.formatOptions(this.options, userOptions);
|
|
@@ -1166,11 +1119,6 @@ class FederationHost {
|
|
|
1166
1119
|
// 2. Searches globally for a matching share, if found, it uses it directly
|
|
1167
1120
|
// 3. If not found, it retrieves it from the current share and stores the obtained share globally.
|
|
1168
1121
|
const shareInfo = Object.assign({}, (_this_options_shared = this.options.shared) == null ? void 0 : _this_options_shared[pkgName], customShareInfo);
|
|
1169
|
-
if (shareInfo == null ? void 0 : shareInfo.scope) {
|
|
1170
|
-
shareInfo.scope.forEach((shareScope)=>{
|
|
1171
|
-
this.initializeSharing(shareScope, shareInfo.strategy);
|
|
1172
|
-
});
|
|
1173
|
-
}
|
|
1174
1122
|
const loadShareRes = await this.hooks.lifecycle.beforeLoadShare.emit({
|
|
1175
1123
|
pkgName,
|
|
1176
1124
|
shareInfo,
|
|
@@ -1181,42 +1129,30 @@ class FederationHost {
|
|
|
1181
1129
|
// Assert that shareInfoRes exists, if not, throw an error
|
|
1182
1130
|
share.assert(shareInfoRes, `Cannot find ${pkgName} Share in the ${this.options.name}. Please ensure that the ${pkgName} Share parameters have been injected`);
|
|
1183
1131
|
// Retrieve from cache
|
|
1184
|
-
const
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
if (registeredShared && registeredShared.lib) {
|
|
1192
|
-
addUseIn(registeredShared);
|
|
1193
|
-
return registeredShared.lib;
|
|
1194
|
-
} else if (registeredShared && registeredShared.loading && !registeredShared.loaded) {
|
|
1195
|
-
const factory = await registeredShared.loading;
|
|
1196
|
-
registeredShared.loaded = true;
|
|
1197
|
-
if (!registeredShared.lib) {
|
|
1198
|
-
registeredShared.lib = factory;
|
|
1199
|
-
}
|
|
1200
|
-
addUseIn(registeredShared);
|
|
1132
|
+
const globalShare = share.getGlobalShare(pkgName, shareInfoRes);
|
|
1133
|
+
if (globalShare && globalShare.lib) {
|
|
1134
|
+
share.addUniqueItem(globalShare.useIn, this.options.name);
|
|
1135
|
+
return globalShare.lib;
|
|
1136
|
+
} else if (globalShare && globalShare.loading) {
|
|
1137
|
+
const factory = await globalShare.loading;
|
|
1138
|
+
share.addUniqueItem(globalShare.useIn, this.options.name);
|
|
1201
1139
|
return factory;
|
|
1202
|
-
} else if (
|
|
1140
|
+
} else if (globalShare) {
|
|
1203
1141
|
const asyncLoadProcess = async ()=>{
|
|
1204
|
-
const factory = await
|
|
1142
|
+
const factory = await globalShare.get();
|
|
1205
1143
|
shareInfoRes.lib = factory;
|
|
1206
|
-
shareInfoRes.
|
|
1207
|
-
|
|
1208
|
-
const gShared = share.getRegisteredShare(this.shareScopeMap, pkgName, shareInfoRes, this.hooks.lifecycle.resolveShare);
|
|
1144
|
+
share.addUniqueItem(shareInfoRes.useIn, this.options.name);
|
|
1145
|
+
const gShared = share.getGlobalShare(pkgName, shareInfoRes);
|
|
1209
1146
|
if (gShared) {
|
|
1210
1147
|
gShared.lib = factory;
|
|
1211
|
-
gShared.loaded = true;
|
|
1212
1148
|
}
|
|
1213
1149
|
return factory;
|
|
1214
1150
|
};
|
|
1215
1151
|
const loading = asyncLoadProcess();
|
|
1216
1152
|
this.setShared({
|
|
1217
1153
|
pkgName,
|
|
1218
|
-
loaded:
|
|
1219
|
-
shared:
|
|
1154
|
+
loaded: true,
|
|
1155
|
+
shared: shareInfoRes,
|
|
1220
1156
|
from: this.options.name,
|
|
1221
1157
|
lib: null,
|
|
1222
1158
|
loading
|
|
@@ -1229,19 +1165,17 @@ class FederationHost {
|
|
|
1229
1165
|
const asyncLoadProcess = async ()=>{
|
|
1230
1166
|
const factory = await shareInfoRes.get();
|
|
1231
1167
|
shareInfoRes.lib = factory;
|
|
1232
|
-
shareInfoRes.
|
|
1233
|
-
|
|
1234
|
-
const gShared = share.getRegisteredShare(this.shareScopeMap, pkgName, shareInfoRes, this.hooks.lifecycle.resolveShare);
|
|
1168
|
+
share.addUniqueItem(shareInfoRes.useIn, this.options.name);
|
|
1169
|
+
const gShared = share.getGlobalShare(pkgName, shareInfoRes);
|
|
1235
1170
|
if (gShared) {
|
|
1236
1171
|
gShared.lib = factory;
|
|
1237
|
-
gShared.loaded = true;
|
|
1238
1172
|
}
|
|
1239
1173
|
return factory;
|
|
1240
1174
|
};
|
|
1241
1175
|
const loading = asyncLoadProcess();
|
|
1242
1176
|
this.setShared({
|
|
1243
1177
|
pkgName,
|
|
1244
|
-
loaded:
|
|
1178
|
+
loaded: true,
|
|
1245
1179
|
shared: shareInfoRes,
|
|
1246
1180
|
from: this.options.name,
|
|
1247
1181
|
lib: null,
|
|
@@ -1257,16 +1191,16 @@ class FederationHost {
|
|
|
1257
1191
|
loadShareSync(pkgName) {
|
|
1258
1192
|
var _this_options_shared;
|
|
1259
1193
|
const shareInfo = (_this_options_shared = this.options.shared) == null ? void 0 : _this_options_shared[pkgName];
|
|
1260
|
-
const
|
|
1261
|
-
if (
|
|
1262
|
-
share.addUniqueItem(
|
|
1263
|
-
if (!
|
|
1264
|
-
|
|
1265
|
-
if (
|
|
1194
|
+
const globalShare = share.getGlobalShare(pkgName, shareInfo);
|
|
1195
|
+
if (globalShare && typeof globalShare.lib === 'function') {
|
|
1196
|
+
share.addUniqueItem(globalShare.useIn, this.options.name);
|
|
1197
|
+
if (!globalShare.loaded) {
|
|
1198
|
+
globalShare.loaded = true;
|
|
1199
|
+
if (globalShare.from === this.options.name) {
|
|
1266
1200
|
shareInfo.loaded = true;
|
|
1267
1201
|
}
|
|
1268
1202
|
}
|
|
1269
|
-
return
|
|
1203
|
+
return globalShare.lib;
|
|
1270
1204
|
}
|
|
1271
1205
|
if (shareInfo.lib) {
|
|
1272
1206
|
if (!shareInfo.loaded) {
|
|
@@ -1330,15 +1264,8 @@ class FederationHost {
|
|
|
1330
1264
|
share.assert(remote && expose, `The 'beforeRequest' hook was executed, but it failed to return the correct 'remote' and 'expose' values while loading ${idRes}.`);
|
|
1331
1265
|
let module = this.moduleCache.get(remote.name);
|
|
1332
1266
|
const moduleOptions = {
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
version: this.options.version || 'custom'
|
|
1336
|
-
},
|
|
1337
|
-
remoteInfo,
|
|
1338
|
-
shared: this.options.shared || {},
|
|
1339
|
-
plugins: this.options.plugins,
|
|
1340
|
-
loaderHook: this.loaderHook,
|
|
1341
|
-
shareScopeMap: this.shareScopeMap
|
|
1267
|
+
host: this,
|
|
1268
|
+
remoteInfo
|
|
1342
1269
|
};
|
|
1343
1270
|
if (!module) {
|
|
1344
1271
|
module = new Module(moduleOptions);
|
|
@@ -1380,19 +1307,11 @@ class FederationHost {
|
|
|
1380
1307
|
});
|
|
1381
1308
|
return moduleOrFactory;
|
|
1382
1309
|
} catch (error) {
|
|
1383
|
-
|
|
1384
|
-
from: 'runtime'
|
|
1385
|
-
};
|
|
1386
|
-
const failOver = await this.hooks.lifecycle.errorLoadRemote.emit({
|
|
1310
|
+
this.hooks.lifecycle.errorLoadRemote.emit({
|
|
1387
1311
|
id,
|
|
1388
|
-
error
|
|
1389
|
-
from,
|
|
1390
|
-
origin: this
|
|
1312
|
+
error
|
|
1391
1313
|
});
|
|
1392
|
-
|
|
1393
|
-
throw error;
|
|
1394
|
-
}
|
|
1395
|
-
return failOver;
|
|
1314
|
+
throw error;
|
|
1396
1315
|
}
|
|
1397
1316
|
}
|
|
1398
1317
|
// eslint-disable-next-line @typescript-eslint/member-ordering
|
|
@@ -1426,9 +1345,14 @@ class FederationHost {
|
|
|
1426
1345
|
* It accepts one argument, the name of the share scope.
|
|
1427
1346
|
* If the share scope does not exist, it creates one.
|
|
1428
1347
|
*/ // eslint-disable-next-line @typescript-eslint/member-ordering
|
|
1429
|
-
initializeSharing(shareScopeName = share.DEFAULT_SCOPE
|
|
1430
|
-
const
|
|
1348
|
+
initializeSharing(shareScopeName = share.DEFAULT_SCOPE) {
|
|
1349
|
+
const shareScopeLoading = share.Global.__FEDERATION__.__SHARE_SCOPE_LOADING__;
|
|
1350
|
+
const shareScope = share.Global.__FEDERATION__.__SHARE__;
|
|
1431
1351
|
const hostName = this.options.name;
|
|
1352
|
+
// Executes only once
|
|
1353
|
+
if (shareScopeLoading[shareScopeName]) {
|
|
1354
|
+
return shareScopeLoading[shareScopeName];
|
|
1355
|
+
}
|
|
1432
1356
|
// Creates a new share scope if necessary
|
|
1433
1357
|
if (!shareScope[shareScopeName]) {
|
|
1434
1358
|
shareScope[shareScopeName] = {};
|
|
@@ -1436,27 +1360,21 @@ class FederationHost {
|
|
|
1436
1360
|
// Executes all initialization snippets from all accessible modules
|
|
1437
1361
|
const scope = shareScope[shareScopeName];
|
|
1438
1362
|
const register = (name, shared)=>{
|
|
1439
|
-
var _activeVersion_shareConfig;
|
|
1440
1363
|
const { version, eager } = shared;
|
|
1441
1364
|
scope[name] = scope[name] || {};
|
|
1442
1365
|
const versions = scope[name];
|
|
1443
1366
|
const activeVersion = versions[version];
|
|
1444
|
-
const activeVersionEager = Boolean(activeVersion && (activeVersion.eager ||
|
|
1367
|
+
const activeVersionEager = Boolean(activeVersion && (activeVersion.eager || activeVersion.shareConfig.eager));
|
|
1445
1368
|
if (!activeVersion || !activeVersion.loaded && (Boolean(!eager) !== !activeVersionEager ? eager : hostName > activeVersion.from)) {
|
|
1446
1369
|
versions[version] = shared;
|
|
1447
1370
|
}
|
|
1448
1371
|
};
|
|
1449
1372
|
const promises = [];
|
|
1450
|
-
const initFn = (mod)=>mod && mod.init && mod.init(shareScope[shareScopeName]);
|
|
1451
1373
|
const initRemoteModule = async (key)=>{
|
|
1452
1374
|
const { module } = await this._getRemoteModuleAndOptions(key);
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
initFn(entry);
|
|
1457
|
-
module.inited = true;
|
|
1458
|
-
}
|
|
1459
|
-
}
|
|
1375
|
+
const initFn = (mod)=>mod && mod.init && mod.init(shareScope[shareScopeName]);
|
|
1376
|
+
const entry = await module.getEntry();
|
|
1377
|
+
initFn(entry);
|
|
1460
1378
|
};
|
|
1461
1379
|
Object.keys(this.options.shared).forEach((shareName)=>{
|
|
1462
1380
|
const shared = this.options.shared[shareName];
|
|
@@ -1464,17 +1382,15 @@ class FederationHost {
|
|
|
1464
1382
|
register(shareName, shared);
|
|
1465
1383
|
}
|
|
1466
1384
|
});
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1385
|
+
this.options.remotes.forEach((remote)=>{
|
|
1386
|
+
if (remote.shareScope === shareScopeName) {
|
|
1387
|
+
promises.push(initRemoteModule(remote.name));
|
|
1388
|
+
}
|
|
1389
|
+
});
|
|
1390
|
+
if (!promises.length) {
|
|
1391
|
+
return shareScopeLoading[shareScopeName] = true;
|
|
1473
1392
|
}
|
|
1474
|
-
return promises;
|
|
1475
|
-
}
|
|
1476
|
-
initShareScopeMap(scopeName, shareScope) {
|
|
1477
|
-
this.shareScopeMap[scopeName] = shareScope;
|
|
1393
|
+
return shareScopeLoading[shareScopeName] = Promise.all(promises).then(()=>shareScopeLoading[shareScopeName] = true);
|
|
1478
1394
|
}
|
|
1479
1395
|
formatOptions(globalOptions, userOptions) {
|
|
1480
1396
|
const formatShareOptions = share.formatShareConfigs(userOptions.shared || {}, userOptions.name);
|
|
@@ -1514,17 +1430,16 @@ class FederationHost {
|
|
|
1514
1430
|
}
|
|
1515
1431
|
return res;
|
|
1516
1432
|
}, globalOptionsRes.remotes);
|
|
1517
|
-
// register shared
|
|
1433
|
+
// register shared include lib
|
|
1518
1434
|
const sharedKeys = Object.keys(formatShareOptions);
|
|
1519
1435
|
sharedKeys.forEach((sharedKey)=>{
|
|
1520
1436
|
const sharedVal = formatShareOptions[sharedKey];
|
|
1521
|
-
const
|
|
1522
|
-
if (!
|
|
1437
|
+
const globalShare = share.getGlobalShare(sharedKey, sharedVal);
|
|
1438
|
+
if (!globalShare && sharedVal && sharedVal.lib) {
|
|
1523
1439
|
this.setShared({
|
|
1524
1440
|
pkgName: sharedKey,
|
|
1525
1441
|
lib: sharedVal.lib,
|
|
1526
1442
|
get: sharedVal.get,
|
|
1527
|
-
loaded: true,
|
|
1528
1443
|
shared: sharedVal,
|
|
1529
1444
|
from: userOptions.name
|
|
1530
1445
|
});
|
|
@@ -1559,6 +1474,7 @@ class FederationHost {
|
|
|
1559
1474
|
]);
|
|
1560
1475
|
}
|
|
1561
1476
|
setShared({ pkgName, shared, from, lib, loading, loaded, get }) {
|
|
1477
|
+
const target = share.getGlobalShareScope();
|
|
1562
1478
|
const { version, scope = 'default' } = shared, shareInfo = _object_without_properties_loose(shared, [
|
|
1563
1479
|
"version",
|
|
1564
1480
|
"scope"
|
|
@@ -1567,23 +1483,23 @@ class FederationHost {
|
|
|
1567
1483
|
scope
|
|
1568
1484
|
];
|
|
1569
1485
|
scopes.forEach((sc)=>{
|
|
1570
|
-
if (!
|
|
1571
|
-
|
|
1486
|
+
if (!target[sc]) {
|
|
1487
|
+
target[sc] = {};
|
|
1572
1488
|
}
|
|
1573
|
-
if (!
|
|
1574
|
-
|
|
1489
|
+
if (!target[sc][pkgName]) {
|
|
1490
|
+
target[sc][pkgName] = {};
|
|
1575
1491
|
}
|
|
1576
|
-
if (
|
|
1492
|
+
if (target[sc][pkgName][version]) {
|
|
1577
1493
|
share.warn(// eslint-disable-next-line max-len
|
|
1578
1494
|
`The share \n ${share.safeToString({
|
|
1579
1495
|
scope: sc,
|
|
1580
1496
|
pkgName,
|
|
1581
1497
|
version,
|
|
1582
|
-
from:
|
|
1498
|
+
from: target[sc][pkgName][version].from
|
|
1583
1499
|
})} has been registered`);
|
|
1584
1500
|
return;
|
|
1585
1501
|
}
|
|
1586
|
-
|
|
1502
|
+
target[sc][pkgName][version] = _extends({
|
|
1587
1503
|
version,
|
|
1588
1504
|
scope: [
|
|
1589
1505
|
'default'
|
|
@@ -1594,7 +1510,7 @@ class FederationHost {
|
|
|
1594
1510
|
loading
|
|
1595
1511
|
});
|
|
1596
1512
|
if (get) {
|
|
1597
|
-
|
|
1513
|
+
target[sc][pkgName][version].get = get;
|
|
1598
1514
|
}
|
|
1599
1515
|
});
|
|
1600
1516
|
}
|
|
@@ -1604,18 +1520,18 @@ class FederationHost {
|
|
|
1604
1520
|
init: new SyncHook(),
|
|
1605
1521
|
beforeRequest: new AsyncWaterfallHook('beforeRequest'),
|
|
1606
1522
|
afterResolve: new AsyncWaterfallHook('afterResolve'),
|
|
1523
|
+
beforeInitContainer: new AsyncWaterfallHook('beforeInitContainer'),
|
|
1524
|
+
initContainer: new AsyncWaterfallHook('initContainer'),
|
|
1607
1525
|
onLoad: new AsyncHook('onLoad'),
|
|
1608
1526
|
handlePreloadModule: new SyncHook('handlePreloadModule'),
|
|
1609
1527
|
errorLoadRemote: new AsyncHook('errorLoadRemote'),
|
|
1610
1528
|
beforeLoadShare: new AsyncWaterfallHook('beforeLoadShare'),
|
|
1611
1529
|
loadShare: new AsyncHook(),
|
|
1612
|
-
resolveShare: new SyncWaterfallHook('resolveShare'),
|
|
1613
1530
|
beforePreloadRemote: new AsyncHook(),
|
|
1614
1531
|
generatePreloadAssets: new AsyncHook('generatePreloadAssets'),
|
|
1615
1532
|
afterPreloadRemote: new AsyncHook()
|
|
1616
1533
|
});
|
|
1617
|
-
this.
|
|
1618
|
-
this.version = `0.0.5`;
|
|
1534
|
+
this.version = '0.0.5';
|
|
1619
1535
|
this.moduleCache = new Map();
|
|
1620
1536
|
this.loaderHook = new PluginSystem({
|
|
1621
1537
|
// FIXME: may not be suitable
|
|
@@ -1623,6 +1539,7 @@ class FederationHost {
|
|
|
1623
1539
|
createScript: new SyncHook(),
|
|
1624
1540
|
fetch: new AsyncHook('fetch')
|
|
1625
1541
|
});
|
|
1542
|
+
this.loadingShare = {};
|
|
1626
1543
|
// TODO: Validate the details of the options
|
|
1627
1544
|
// Initialize options with default values
|
|
1628
1545
|
const defaultOptions = {
|
|
@@ -1638,8 +1555,6 @@ class FederationHost {
|
|
|
1638
1555
|
};
|
|
1639
1556
|
this.name = userOptions.name;
|
|
1640
1557
|
this.options = defaultOptions;
|
|
1641
|
-
this.shareScopeMap = {};
|
|
1642
|
-
this._setGlobalShareScopeMap();
|
|
1643
1558
|
this.snapshotHandler = new SnapshotHandler(this);
|
|
1644
1559
|
this.registerPlugins([
|
|
1645
1560
|
...defaultOptions.plugins,
|
|
@@ -1689,10 +1604,6 @@ function preloadRemote(...args) {
|
|
|
1689
1604
|
share.setGlobalFederationConstructor(FederationHost);
|
|
1690
1605
|
|
|
1691
1606
|
exports.registerGlobalPlugins = share.registerGlobalPlugins;
|
|
1692
|
-
Object.defineProperty(exports, 'loadScript', {
|
|
1693
|
-
enumerable: true,
|
|
1694
|
-
get: function () { return sdk.loadScript; }
|
|
1695
|
-
});
|
|
1696
1607
|
exports.FederationHost = FederationHost;
|
|
1697
1608
|
exports.init = init;
|
|
1698
1609
|
exports.loadRemote = loadRemote;
|