@module-federation/runtime 0.0.0-next-20231222101023 → 0.0.0-next-20231225064454
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 +68 -137
- package/dist/index.esm.js +70 -136
- package/dist/package.json +2 -2
- package/dist/share.cjs.js +47 -70
- package/dist/share.esm.js +47 -70
- package/dist/src/core.d.ts +5 -15
- package/dist/src/global.d.ts +3 -2
- 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 -5
- 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,24 +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
|
-
return entryExports;
|
|
138
|
-
});
|
|
139
|
-
}
|
|
140
121
|
return loadScript(entry, {
|
|
141
122
|
attrs: {},
|
|
142
123
|
createScriptHook
|
|
@@ -210,10 +191,6 @@ let Module = class Module {
|
|
|
210
191
|
const res = this.loaderHook.lifecycle.createScript.emit({
|
|
211
192
|
url
|
|
212
193
|
});
|
|
213
|
-
if (typeof document === 'undefined') {
|
|
214
|
-
//todo: needs real fix
|
|
215
|
-
return res;
|
|
216
|
-
}
|
|
217
194
|
if (res instanceof HTMLScriptElement) {
|
|
218
195
|
return res;
|
|
219
196
|
}
|
|
@@ -229,16 +206,15 @@ let Module = class Module {
|
|
|
229
206
|
const { loadFactory = true } = options || {
|
|
230
207
|
loadFactory: true
|
|
231
208
|
};
|
|
232
|
-
this.hostInfo.name;
|
|
233
209
|
// Get remoteEntry.js
|
|
234
210
|
const remoteEntryExports = await this.getEntry();
|
|
235
211
|
if (!this.inited) {
|
|
236
|
-
const
|
|
212
|
+
const globalShareScope = Global.__FEDERATION__.__SHARE__;
|
|
237
213
|
const remoteShareScope = this.remoteInfo.shareScope || 'default';
|
|
238
|
-
if (!
|
|
239
|
-
|
|
214
|
+
if (!globalShareScope[remoteShareScope]) {
|
|
215
|
+
globalShareScope[remoteShareScope] = {};
|
|
240
216
|
}
|
|
241
|
-
const shareScope =
|
|
217
|
+
const shareScope = globalShareScope[remoteShareScope];
|
|
242
218
|
// TODO: compat logic , it could be moved after providing startup hooks
|
|
243
219
|
const remoteEntryInitOptions = {
|
|
244
220
|
version: this.remoteInfo.version || '',
|
|
@@ -248,18 +224,10 @@ let Module = class Module {
|
|
|
248
224
|
remoteEntryExports.init(shareScope, [], remoteEntryInitOptions);
|
|
249
225
|
const federationInstance = Global.__FEDERATION__.__INSTANCES__.find((i)=>i.options.id === composeKeyWithSeparator(this.remoteInfo.name, this.remoteInfo.buildVersion));
|
|
250
226
|
if (federationInstance) {
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
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
|
-
}
|
|
227
|
+
federationInstance.initOptions(_extends$4({}, remoteEntryInitOptions, {
|
|
228
|
+
remotes: [],
|
|
229
|
+
name: this.remoteInfo.name
|
|
230
|
+
}));
|
|
263
231
|
}
|
|
264
232
|
}
|
|
265
233
|
this.lib = remoteEntryExports;
|
|
@@ -274,7 +242,7 @@ let Module = class Module {
|
|
|
274
242
|
return exposeContent;
|
|
275
243
|
}
|
|
276
244
|
// loading: Record<string, undefined | Promise<RemoteEntryExports | void>> = {};
|
|
277
|
-
constructor({ hostInfo, remoteInfo, shared, loaderHook
|
|
245
|
+
constructor({ hostInfo, remoteInfo, shared, loaderHook }){
|
|
278
246
|
this.inited = false;
|
|
279
247
|
this.shared = {};
|
|
280
248
|
this.lib = undefined;
|
|
@@ -282,7 +250,6 @@ let Module = class Module {
|
|
|
282
250
|
this.remoteInfo = remoteInfo;
|
|
283
251
|
this.shared = shared;
|
|
284
252
|
this.loaderHook = loaderHook;
|
|
285
|
-
this.shareScopeMap = shareScopeMap;
|
|
286
253
|
}
|
|
287
254
|
};
|
|
288
255
|
|
|
@@ -809,9 +776,9 @@ function generatePreloadAssets(origin, preloadOptions, remote, globalSnapshot, r
|
|
|
809
776
|
if (!shareInfo) {
|
|
810
777
|
return;
|
|
811
778
|
}
|
|
812
|
-
const
|
|
779
|
+
const globalShare = getGlobalShare(shared.sharedName, shareInfo);
|
|
813
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.
|
|
814
|
-
if (
|
|
781
|
+
if (globalShare && typeof globalShare.lib === 'function') {
|
|
815
782
|
shared.assets.js.sync.forEach((asset)=>{
|
|
816
783
|
loadedSharedJsAssets.add(asset);
|
|
817
784
|
});
|
|
@@ -1138,13 +1105,6 @@ function _object_without_properties_loose(source, excluded) {
|
|
|
1138
1105
|
return target;
|
|
1139
1106
|
}
|
|
1140
1107
|
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
|
-
}
|
|
1148
1108
|
initOptions(userOptions) {
|
|
1149
1109
|
this.registerPlugins(userOptions.plugins);
|
|
1150
1110
|
const options = this.formatOptions(this.options, userOptions);
|
|
@@ -1159,11 +1119,6 @@ class FederationHost {
|
|
|
1159
1119
|
// 2. Searches globally for a matching share, if found, it uses it directly
|
|
1160
1120
|
// 3. If not found, it retrieves it from the current share and stores the obtained share globally.
|
|
1161
1121
|
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
|
-
}
|
|
1167
1122
|
const loadShareRes = await this.hooks.lifecycle.beforeLoadShare.emit({
|
|
1168
1123
|
pkgName,
|
|
1169
1124
|
shareInfo,
|
|
@@ -1174,42 +1129,30 @@ class FederationHost {
|
|
|
1174
1129
|
// Assert that shareInfoRes exists, if not, throw an error
|
|
1175
1130
|
assert(shareInfoRes, `Cannot find ${pkgName} Share in the ${this.options.name}. Please ensure that the ${pkgName} Share parameters have been injected`);
|
|
1176
1131
|
// Retrieve from cache
|
|
1177
|
-
const
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
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);
|
|
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);
|
|
1194
1139
|
return factory;
|
|
1195
|
-
} else if (
|
|
1140
|
+
} else if (globalShare) {
|
|
1196
1141
|
const asyncLoadProcess = async ()=>{
|
|
1197
|
-
const factory = await
|
|
1142
|
+
const factory = await globalShare.get();
|
|
1198
1143
|
shareInfoRes.lib = factory;
|
|
1199
|
-
shareInfoRes.
|
|
1200
|
-
|
|
1201
|
-
const gShared = getRegisteredShare(this.shareScopeMap, pkgName, shareInfoRes, this.hooks.lifecycle.resolveShare);
|
|
1144
|
+
addUniqueItem(shareInfoRes.useIn, this.options.name);
|
|
1145
|
+
const gShared = getGlobalShare(pkgName, shareInfoRes);
|
|
1202
1146
|
if (gShared) {
|
|
1203
1147
|
gShared.lib = factory;
|
|
1204
|
-
gShared.loaded = true;
|
|
1205
1148
|
}
|
|
1206
1149
|
return factory;
|
|
1207
1150
|
};
|
|
1208
1151
|
const loading = asyncLoadProcess();
|
|
1209
1152
|
this.setShared({
|
|
1210
1153
|
pkgName,
|
|
1211
|
-
loaded:
|
|
1212
|
-
shared:
|
|
1154
|
+
loaded: true,
|
|
1155
|
+
shared: shareInfoRes,
|
|
1213
1156
|
from: this.options.name,
|
|
1214
1157
|
lib: null,
|
|
1215
1158
|
loading
|
|
@@ -1222,19 +1165,17 @@ class FederationHost {
|
|
|
1222
1165
|
const asyncLoadProcess = async ()=>{
|
|
1223
1166
|
const factory = await shareInfoRes.get();
|
|
1224
1167
|
shareInfoRes.lib = factory;
|
|
1225
|
-
shareInfoRes.
|
|
1226
|
-
|
|
1227
|
-
const gShared = getRegisteredShare(this.shareScopeMap, pkgName, shareInfoRes, this.hooks.lifecycle.resolveShare);
|
|
1168
|
+
addUniqueItem(shareInfoRes.useIn, this.options.name);
|
|
1169
|
+
const gShared = getGlobalShare(pkgName, shareInfoRes);
|
|
1228
1170
|
if (gShared) {
|
|
1229
1171
|
gShared.lib = factory;
|
|
1230
|
-
gShared.loaded = true;
|
|
1231
1172
|
}
|
|
1232
1173
|
return factory;
|
|
1233
1174
|
};
|
|
1234
1175
|
const loading = asyncLoadProcess();
|
|
1235
1176
|
this.setShared({
|
|
1236
1177
|
pkgName,
|
|
1237
|
-
loaded:
|
|
1178
|
+
loaded: true,
|
|
1238
1179
|
shared: shareInfoRes,
|
|
1239
1180
|
from: this.options.name,
|
|
1240
1181
|
lib: null,
|
|
@@ -1250,16 +1191,16 @@ class FederationHost {
|
|
|
1250
1191
|
loadShareSync(pkgName) {
|
|
1251
1192
|
var _this_options_shared;
|
|
1252
1193
|
const shareInfo = (_this_options_shared = this.options.shared) == null ? void 0 : _this_options_shared[pkgName];
|
|
1253
|
-
const
|
|
1254
|
-
if (
|
|
1255
|
-
addUniqueItem(
|
|
1256
|
-
if (!
|
|
1257
|
-
|
|
1258
|
-
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) {
|
|
1259
1200
|
shareInfo.loaded = true;
|
|
1260
1201
|
}
|
|
1261
1202
|
}
|
|
1262
|
-
return
|
|
1203
|
+
return globalShare.lib;
|
|
1263
1204
|
}
|
|
1264
1205
|
if (shareInfo.lib) {
|
|
1265
1206
|
if (!shareInfo.loaded) {
|
|
@@ -1330,8 +1271,7 @@ class FederationHost {
|
|
|
1330
1271
|
remoteInfo,
|
|
1331
1272
|
shared: this.options.shared || {},
|
|
1332
1273
|
plugins: this.options.plugins,
|
|
1333
|
-
loaderHook: this.loaderHook
|
|
1334
|
-
shareScopeMap: this.shareScopeMap
|
|
1274
|
+
loaderHook: this.loaderHook
|
|
1335
1275
|
};
|
|
1336
1276
|
if (!module) {
|
|
1337
1277
|
module = new Module(moduleOptions);
|
|
@@ -1411,9 +1351,14 @@ class FederationHost {
|
|
|
1411
1351
|
* It accepts one argument, the name of the share scope.
|
|
1412
1352
|
* If the share scope does not exist, it creates one.
|
|
1413
1353
|
*/ // eslint-disable-next-line @typescript-eslint/member-ordering
|
|
1414
|
-
initializeSharing(shareScopeName = DEFAULT_SCOPE
|
|
1415
|
-
const
|
|
1354
|
+
initializeSharing(shareScopeName = DEFAULT_SCOPE) {
|
|
1355
|
+
const shareScopeLoading = Global.__FEDERATION__.__SHARE_SCOPE_LOADING__;
|
|
1356
|
+
const shareScope = Global.__FEDERATION__.__SHARE__;
|
|
1416
1357
|
const hostName = this.options.name;
|
|
1358
|
+
// Executes only once
|
|
1359
|
+
if (shareScopeLoading[shareScopeName]) {
|
|
1360
|
+
return shareScopeLoading[shareScopeName];
|
|
1361
|
+
}
|
|
1417
1362
|
// Creates a new share scope if necessary
|
|
1418
1363
|
if (!shareScope[shareScopeName]) {
|
|
1419
1364
|
shareScope[shareScopeName] = {};
|
|
@@ -1421,27 +1366,21 @@ class FederationHost {
|
|
|
1421
1366
|
// Executes all initialization snippets from all accessible modules
|
|
1422
1367
|
const scope = shareScope[shareScopeName];
|
|
1423
1368
|
const register = (name, shared)=>{
|
|
1424
|
-
var _activeVersion_shareConfig;
|
|
1425
1369
|
const { version, eager } = shared;
|
|
1426
1370
|
scope[name] = scope[name] || {};
|
|
1427
1371
|
const versions = scope[name];
|
|
1428
1372
|
const activeVersion = versions[version];
|
|
1429
|
-
const activeVersionEager = Boolean(activeVersion && (activeVersion.eager ||
|
|
1373
|
+
const activeVersionEager = Boolean(activeVersion && (activeVersion.eager || activeVersion.shareConfig.eager));
|
|
1430
1374
|
if (!activeVersion || !activeVersion.loaded && (Boolean(!eager) !== !activeVersionEager ? eager : hostName > activeVersion.from)) {
|
|
1431
1375
|
versions[version] = shared;
|
|
1432
1376
|
}
|
|
1433
1377
|
};
|
|
1434
1378
|
const promises = [];
|
|
1435
|
-
const initFn = (mod)=>mod && mod.init && mod.init(shareScope[shareScopeName]);
|
|
1436
1379
|
const initRemoteModule = async (key)=>{
|
|
1437
1380
|
const { module } = await this._getRemoteModuleAndOptions(key);
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
initFn(entry);
|
|
1442
|
-
module.inited = true;
|
|
1443
|
-
}
|
|
1444
|
-
}
|
|
1381
|
+
const initFn = (mod)=>mod && mod.init && mod.init(shareScope[shareScopeName]);
|
|
1382
|
+
const entry = await module.getEntry();
|
|
1383
|
+
initFn(entry);
|
|
1445
1384
|
};
|
|
1446
1385
|
Object.keys(this.options.shared).forEach((shareName)=>{
|
|
1447
1386
|
const shared = this.options.shared[shareName];
|
|
@@ -1449,17 +1388,15 @@ class FederationHost {
|
|
|
1449
1388
|
register(shareName, shared);
|
|
1450
1389
|
}
|
|
1451
1390
|
});
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
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;
|
|
1458
1398
|
}
|
|
1459
|
-
return promises;
|
|
1460
|
-
}
|
|
1461
|
-
initShareScopeMap(scopeName, shareScope) {
|
|
1462
|
-
this.shareScopeMap[scopeName] = shareScope;
|
|
1399
|
+
return shareScopeLoading[shareScopeName] = Promise.all(promises).then(()=>shareScopeLoading[shareScopeName] = true);
|
|
1463
1400
|
}
|
|
1464
1401
|
formatOptions(globalOptions, userOptions) {
|
|
1465
1402
|
const formatShareOptions = formatShareConfigs(userOptions.shared || {}, userOptions.name);
|
|
@@ -1499,17 +1436,16 @@ class FederationHost {
|
|
|
1499
1436
|
}
|
|
1500
1437
|
return res;
|
|
1501
1438
|
}, globalOptionsRes.remotes);
|
|
1502
|
-
// register shared
|
|
1439
|
+
// register shared include lib
|
|
1503
1440
|
const sharedKeys = Object.keys(formatShareOptions);
|
|
1504
1441
|
sharedKeys.forEach((sharedKey)=>{
|
|
1505
1442
|
const sharedVal = formatShareOptions[sharedKey];
|
|
1506
|
-
const
|
|
1507
|
-
if (!
|
|
1443
|
+
const globalShare = getGlobalShare(sharedKey, sharedVal);
|
|
1444
|
+
if (!globalShare && sharedVal && sharedVal.lib) {
|
|
1508
1445
|
this.setShared({
|
|
1509
1446
|
pkgName: sharedKey,
|
|
1510
1447
|
lib: sharedVal.lib,
|
|
1511
1448
|
get: sharedVal.get,
|
|
1512
|
-
loaded: true,
|
|
1513
1449
|
shared: sharedVal,
|
|
1514
1450
|
from: userOptions.name
|
|
1515
1451
|
});
|
|
@@ -1544,6 +1480,7 @@ class FederationHost {
|
|
|
1544
1480
|
]);
|
|
1545
1481
|
}
|
|
1546
1482
|
setShared({ pkgName, shared, from, lib, loading, loaded, get }) {
|
|
1483
|
+
const target = getGlobalShareScope();
|
|
1547
1484
|
const { version, scope = 'default' } = shared, shareInfo = _object_without_properties_loose(shared, [
|
|
1548
1485
|
"version",
|
|
1549
1486
|
"scope"
|
|
@@ -1552,23 +1489,23 @@ class FederationHost {
|
|
|
1552
1489
|
scope
|
|
1553
1490
|
];
|
|
1554
1491
|
scopes.forEach((sc)=>{
|
|
1555
|
-
if (!
|
|
1556
|
-
|
|
1492
|
+
if (!target[sc]) {
|
|
1493
|
+
target[sc] = {};
|
|
1557
1494
|
}
|
|
1558
|
-
if (!
|
|
1559
|
-
|
|
1495
|
+
if (!target[sc][pkgName]) {
|
|
1496
|
+
target[sc][pkgName] = {};
|
|
1560
1497
|
}
|
|
1561
|
-
if (
|
|
1498
|
+
if (target[sc][pkgName][version]) {
|
|
1562
1499
|
warn(// eslint-disable-next-line max-len
|
|
1563
1500
|
`The share \n ${safeToString({
|
|
1564
1501
|
scope: sc,
|
|
1565
1502
|
pkgName,
|
|
1566
1503
|
version,
|
|
1567
|
-
from:
|
|
1504
|
+
from: target[sc][pkgName][version].from
|
|
1568
1505
|
})} has been registered`);
|
|
1569
1506
|
return;
|
|
1570
1507
|
}
|
|
1571
|
-
|
|
1508
|
+
target[sc][pkgName][version] = _extends({
|
|
1572
1509
|
version,
|
|
1573
1510
|
scope: [
|
|
1574
1511
|
'default'
|
|
@@ -1579,7 +1516,7 @@ class FederationHost {
|
|
|
1579
1516
|
loading
|
|
1580
1517
|
});
|
|
1581
1518
|
if (get) {
|
|
1582
|
-
|
|
1519
|
+
target[sc][pkgName][version].get = get;
|
|
1583
1520
|
}
|
|
1584
1521
|
});
|
|
1585
1522
|
}
|
|
@@ -1594,13 +1531,11 @@ class FederationHost {
|
|
|
1594
1531
|
errorLoadRemote: new AsyncHook('errorLoadRemote'),
|
|
1595
1532
|
beforeLoadShare: new AsyncWaterfallHook('beforeLoadShare'),
|
|
1596
1533
|
loadShare: new AsyncHook(),
|
|
1597
|
-
resolveShare: new SyncWaterfallHook('resolveShare'),
|
|
1598
1534
|
beforePreloadRemote: new AsyncHook(),
|
|
1599
1535
|
generatePreloadAssets: new AsyncHook('generatePreloadAssets'),
|
|
1600
1536
|
afterPreloadRemote: new AsyncHook()
|
|
1601
1537
|
});
|
|
1602
|
-
this.
|
|
1603
|
-
this.version = `0.0.4`;
|
|
1538
|
+
this.version = '0.0.4';
|
|
1604
1539
|
this.moduleCache = new Map();
|
|
1605
1540
|
this.loaderHook = new PluginSystem({
|
|
1606
1541
|
// FIXME: may not be suitable
|
|
@@ -1608,6 +1543,7 @@ class FederationHost {
|
|
|
1608
1543
|
createScript: new SyncHook(),
|
|
1609
1544
|
fetch: new AsyncHook('fetch')
|
|
1610
1545
|
});
|
|
1546
|
+
this.loadingShare = {};
|
|
1611
1547
|
// TODO: Validate the details of the options
|
|
1612
1548
|
// Initialize options with default values
|
|
1613
1549
|
const defaultOptions = {
|
|
@@ -1623,8 +1559,6 @@ class FederationHost {
|
|
|
1623
1559
|
};
|
|
1624
1560
|
this.name = userOptions.name;
|
|
1625
1561
|
this.options = defaultOptions;
|
|
1626
|
-
this.shareScopeMap = {};
|
|
1627
|
-
this._setGlobalShareScopeMap();
|
|
1628
1562
|
this.snapshotHandler = new SnapshotHandler(this);
|
|
1629
1563
|
this.registerPlugins([
|
|
1630
1564
|
...defaultOptions.plugins,
|
package/dist/package.json
CHANGED
package/dist/share.cjs.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
function getBuilderId() {
|
|
4
|
-
//@ts-ignore
|
|
5
4
|
return typeof FEDERATION_BUILD_IDENTIFIER !== 'undefined' ? FEDERATION_BUILD_IDENTIFIER : '';
|
|
6
5
|
}
|
|
7
6
|
function isDebugMode() {
|
|
@@ -44,7 +43,7 @@ function isRemoteInfoWithEntry(remote) {
|
|
|
44
43
|
return typeof remote.entry !== 'undefined';
|
|
45
44
|
}
|
|
46
45
|
function isPureRemoteEntry(remote) {
|
|
47
|
-
return remote.entry.
|
|
46
|
+
return !remote.entry.includes('.json') && remote.entry.includes('.js');
|
|
48
47
|
}
|
|
49
48
|
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
|
50
49
|
function safeToString(info) {
|
|
@@ -89,7 +88,7 @@ function _object_without_properties_loose(source, excluded) {
|
|
|
89
88
|
}
|
|
90
89
|
return target;
|
|
91
90
|
}
|
|
92
|
-
var _nativeGlobal___FEDERATION__, _nativeGlobal___FEDERATION__1, _nativeGlobal___FEDERATION__2, _nativeGlobal___FEDERATION__3, _nativeGlobal___FEDERATION__4, _nativeGlobal___FEDERATION__5;
|
|
91
|
+
var _nativeGlobal___FEDERATION__, _nativeGlobal___FEDERATION__1, _nativeGlobal___FEDERATION__2, _nativeGlobal___FEDERATION__3, _nativeGlobal___FEDERATION__4, _nativeGlobal___FEDERATION__5, _nativeGlobal___FEDERATION__6;
|
|
93
92
|
// export const nativeGlobal: typeof global = new Function('return this')();
|
|
94
93
|
const nativeGlobal = new Function('return this')();
|
|
95
94
|
// This section is to prevent encapsulation by certain microfrontend frameworks. Due to reuse policies, sandbox escapes.
|
|
@@ -112,6 +111,7 @@ if (nativeGlobal.__VMOK__) {
|
|
|
112
111
|
moduleInfo: {},
|
|
113
112
|
__SHARE__: {},
|
|
114
113
|
__MANIFEST_LOADING__: {},
|
|
114
|
+
__SHARE_SCOPE_LOADING__: {},
|
|
115
115
|
__PRELOADED_MAP__: new Map()
|
|
116
116
|
};
|
|
117
117
|
nativeGlobal.__VMOK__ = nativeGlobal.__FEDERATION__;
|
|
@@ -126,8 +126,10 @@ var ___SHARE__;
|
|
|
126
126
|
(___SHARE__ = (_nativeGlobal___FEDERATION__3 = nativeGlobal.__FEDERATION__).__SHARE__) != null ? ___SHARE__ : _nativeGlobal___FEDERATION__3.__SHARE__ = {};
|
|
127
127
|
var ___MANIFEST_LOADING__;
|
|
128
128
|
(___MANIFEST_LOADING__ = (_nativeGlobal___FEDERATION__4 = nativeGlobal.__FEDERATION__).__MANIFEST_LOADING__) != null ? ___MANIFEST_LOADING__ : _nativeGlobal___FEDERATION__4.__MANIFEST_LOADING__ = {};
|
|
129
|
+
var ___SHARE_SCOPE_LOADING__;
|
|
130
|
+
(___SHARE_SCOPE_LOADING__ = (_nativeGlobal___FEDERATION__5 = nativeGlobal.__FEDERATION__).__SHARE_SCOPE_LOADING__) != null ? ___SHARE_SCOPE_LOADING__ : _nativeGlobal___FEDERATION__5.__SHARE_SCOPE_LOADING__ = {};
|
|
129
131
|
var ___PRELOADED_MAP__;
|
|
130
|
-
(___PRELOADED_MAP__ = (
|
|
132
|
+
(___PRELOADED_MAP__ = (_nativeGlobal___FEDERATION__6 = nativeGlobal.__FEDERATION__).__PRELOADED_MAP__) != null ? ___PRELOADED_MAP__ : _nativeGlobal___FEDERATION__6.__PRELOADED_MAP__ = new Map();
|
|
131
133
|
const Global = {
|
|
132
134
|
get __FEDERATION__ () {
|
|
133
135
|
const globalThisVal = new Function('return globalThis')();
|
|
@@ -140,6 +142,7 @@ function resetFederationGlobalInfo() {
|
|
|
140
142
|
nativeGlobal.__FEDERATION__.moduleInfo = {};
|
|
141
143
|
nativeGlobal.__FEDERATION__.__SHARE__ = {};
|
|
142
144
|
nativeGlobal.__FEDERATION__.__MANIFEST_LOADING__ = {};
|
|
145
|
+
nativeGlobal.__FEDERATION__.__SHARE_SCOPE_LOADING__ = {};
|
|
143
146
|
}
|
|
144
147
|
function getGlobalFederationInstance(name, version) {
|
|
145
148
|
const buildId = getBuilderId();
|
|
@@ -622,7 +625,6 @@ function formatShare(shareArgs, from) {
|
|
|
622
625
|
loading: null
|
|
623
626
|
}, shareArgs, {
|
|
624
627
|
get,
|
|
625
|
-
loaded: 'lib' in shareArgs ? true : undefined,
|
|
626
628
|
scope: Array.isArray(shareArgs.scope) ? shareArgs.scope : [
|
|
627
629
|
'default'
|
|
628
630
|
],
|
|
@@ -639,26 +641,15 @@ function formatShareConfigs(shareArgs, from) {
|
|
|
639
641
|
}, {});
|
|
640
642
|
}
|
|
641
643
|
function versionLt(a, b) {
|
|
642
|
-
|
|
643
|
-
const isNumberVersion = !Number.isNaN(Number(version));
|
|
644
|
-
if (isNumberVersion) {
|
|
645
|
-
const splitArr = version.split('.');
|
|
646
|
-
let validVersion = version;
|
|
647
|
-
for(let i = 0; i < 3 - splitArr.length; i++){
|
|
648
|
-
validVersion += '.0';
|
|
649
|
-
}
|
|
650
|
-
return validVersion;
|
|
651
|
-
}
|
|
652
|
-
return version;
|
|
653
|
-
};
|
|
654
|
-
if (satisfy(transformInvalidVersion(a), `<=${transformInvalidVersion(b)}`)) {
|
|
644
|
+
if (satisfy(a, `<=${b}`)) {
|
|
655
645
|
return true;
|
|
656
646
|
} else {
|
|
657
647
|
return false;
|
|
658
648
|
}
|
|
659
649
|
}
|
|
660
|
-
const findVersion = (
|
|
661
|
-
const
|
|
650
|
+
const findVersion = (scope, pkgName, cb)=>{
|
|
651
|
+
const globalShares = Global.__FEDERATION__.__SHARE__;
|
|
652
|
+
const versions = globalShares[scope][pkgName];
|
|
662
653
|
const callback = cb || function(prev, cur) {
|
|
663
654
|
return versionLt(prev, cur);
|
|
664
655
|
};
|
|
@@ -669,22 +660,20 @@ const findVersion = (shareScopeMap, scope, pkgName, cb)=>{
|
|
|
669
660
|
if (callback(prev, cur)) {
|
|
670
661
|
return cur;
|
|
671
662
|
}
|
|
672
|
-
// default version is '0' https://github.com/webpack/webpack/blob/main/lib/sharing/ProvideSharedModule.js#L136
|
|
673
|
-
if (prev === '0') {
|
|
674
|
-
return cur;
|
|
675
|
-
}
|
|
676
663
|
return prev;
|
|
677
664
|
}, 0);
|
|
678
665
|
};
|
|
679
|
-
function findSingletonVersionOrderByVersion(
|
|
680
|
-
const
|
|
666
|
+
function findSingletonVersionOrderByVersion(scope, pkgName) {
|
|
667
|
+
const globalShares = Global.__FEDERATION__.__SHARE__;
|
|
668
|
+
const versions = globalShares[scope][pkgName];
|
|
681
669
|
const callback = function(prev, cur) {
|
|
682
670
|
return !versions[prev].loaded && versionLt(prev, cur);
|
|
683
671
|
};
|
|
684
|
-
return findVersion(
|
|
672
|
+
return findVersion(scope, pkgName, callback);
|
|
685
673
|
}
|
|
686
|
-
function findSingletonVersionOrderByLoaded(
|
|
687
|
-
const
|
|
674
|
+
function findSingletonVersionOrderByLoaded(scope, pkgName) {
|
|
675
|
+
const globalShares = Global.__FEDERATION__.__SHARE__;
|
|
676
|
+
const versions = globalShares[scope][pkgName];
|
|
688
677
|
const callback = function(prev, cur) {
|
|
689
678
|
if (versions[cur].loaded) {
|
|
690
679
|
if (versions[prev].loaded) {
|
|
@@ -698,57 +687,45 @@ function findSingletonVersionOrderByLoaded(shareScopeMap, scope, pkgName) {
|
|
|
698
687
|
}
|
|
699
688
|
return versionLt(prev, cur);
|
|
700
689
|
};
|
|
701
|
-
return findVersion(
|
|
702
|
-
}
|
|
703
|
-
function getFindShareFunction(strategy) {
|
|
704
|
-
if (strategy === 'loaded-first') {
|
|
705
|
-
return findSingletonVersionOrderByLoaded;
|
|
706
|
-
}
|
|
707
|
-
return findSingletonVersionOrderByVersion;
|
|
690
|
+
return findVersion(scope, pkgName, callback);
|
|
708
691
|
}
|
|
709
692
|
// Details about shared resources
|
|
710
693
|
// TODO: Implement strictVersion for alignment with module federation.
|
|
711
|
-
function
|
|
712
|
-
|
|
713
|
-
return;
|
|
714
|
-
}
|
|
694
|
+
function getGlobalShare(pkgName, shareInfo) {
|
|
695
|
+
const globalShares = Global.__FEDERATION__.__SHARE__;
|
|
715
696
|
const { shareConfig, scope = DEFAULT_SCOPE, strategy } = shareInfo;
|
|
716
697
|
const scopes = Array.isArray(scope) ? scope : [
|
|
717
698
|
scope
|
|
718
699
|
];
|
|
719
700
|
for (const sc of scopes){
|
|
720
|
-
if (shareConfig &&
|
|
701
|
+
if (shareConfig && globalShares[sc] && globalShares[sc][pkgName]) {
|
|
721
702
|
const { requiredVersion } = shareConfig;
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
if (
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
703
|
+
// eslint-disable-next-line max-depth
|
|
704
|
+
if (shareConfig.singleton) {
|
|
705
|
+
const singletonVersion = strategy === 'loaded-first' ? findSingletonVersionOrderByLoaded(sc, pkgName) : findSingletonVersionOrderByVersion(sc, pkgName);
|
|
706
|
+
// eslint-disable-next-line max-depth
|
|
707
|
+
if (typeof requiredVersion === 'string' && !satisfy(singletonVersion, requiredVersion)) {
|
|
708
|
+
warn(`Version ${singletonVersion} from ${singletonVersion && globalShares[sc][pkgName][singletonVersion].from} of shared singleton module ${pkgName} does not satisfy the requirement of ${shareInfo.from} which needs ${requiredVersion})`);
|
|
709
|
+
}
|
|
710
|
+
return globalShares[sc][pkgName][singletonVersion];
|
|
711
|
+
} else {
|
|
712
|
+
const maxVersion = findSingletonVersionOrderByLoaded(sc, pkgName);
|
|
713
|
+
// eslint-disable-next-line max-depth
|
|
714
|
+
if (requiredVersion === false || requiredVersion === '*') {
|
|
715
|
+
return globalShares[sc][pkgName][maxVersion];
|
|
716
|
+
}
|
|
717
|
+
// eslint-disable-next-line max-depth
|
|
718
|
+
if (satisfy(maxVersion, requiredVersion)) {
|
|
719
|
+
return globalShares[sc][pkgName][maxVersion];
|
|
720
|
+
}
|
|
721
|
+
// eslint-disable-next-line max-depth
|
|
722
|
+
for (const [versionKey, versionValue] of Object.entries(globalShares[sc][pkgName])){
|
|
723
|
+
// eslint-disable-next-line max-depth
|
|
724
|
+
if (satisfy(versionKey, requiredVersion)) {
|
|
725
|
+
return versionValue;
|
|
739
726
|
}
|
|
740
727
|
}
|
|
741
|
-
}
|
|
742
|
-
const params = {
|
|
743
|
-
shareScopeMap: localShareScopeMap,
|
|
744
|
-
scope: sc,
|
|
745
|
-
pkgName,
|
|
746
|
-
version: maxOrSingletonVersion,
|
|
747
|
-
GlobalFederation: Global.__FEDERATION__,
|
|
748
|
-
resolver: defaultResolver
|
|
749
|
-
};
|
|
750
|
-
const resolveShared = resolveShare.emit(params) || params;
|
|
751
|
-
return resolveShared.resolver();
|
|
728
|
+
}
|
|
752
729
|
}
|
|
753
730
|
}
|
|
754
731
|
}
|
|
@@ -769,12 +746,12 @@ exports.getFMId = getFMId;
|
|
|
769
746
|
exports.getGlobalFederationConstructor = getGlobalFederationConstructor;
|
|
770
747
|
exports.getGlobalFederationInstance = getGlobalFederationInstance;
|
|
771
748
|
exports.getGlobalHostPlugins = getGlobalHostPlugins;
|
|
749
|
+
exports.getGlobalShare = getGlobalShare;
|
|
772
750
|
exports.getGlobalShareScope = getGlobalShareScope;
|
|
773
751
|
exports.getGlobalSnapshot = getGlobalSnapshot;
|
|
774
752
|
exports.getGlobalSnapshotInfoByModuleInfo = getGlobalSnapshotInfoByModuleInfo;
|
|
775
753
|
exports.getInfoWithoutType = getInfoWithoutType;
|
|
776
754
|
exports.getPreloaded = getPreloaded;
|
|
777
|
-
exports.getRegisteredShare = getRegisteredShare;
|
|
778
755
|
exports.getRemoteEntryExports = getRemoteEntryExports;
|
|
779
756
|
exports.getTargetSnapshotInfoByModuleInfo = getTargetSnapshotInfoByModuleInfo;
|
|
780
757
|
exports.globalLoading = globalLoading;
|