@module-federation/runtime 1.0.1-canary.1 → 1.1.0-canary.1
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/index.cjs.js +17 -12
- package/index.esm.js +17 -12
- package/package.json +1 -1
- package/share.cjs.js +1 -1
- package/share.esm.js +1 -1
- package/src/core.d.ts +4 -3
- package/src/plugins/snapshot/SnapshotHandler.d.ts +1 -0
package/index.cjs.js
CHANGED
|
@@ -583,7 +583,7 @@ function assignRemoteInfo(remoteInfo, remoteSnapshot) {
|
|
|
583
583
|
function snapshotPlugin() {
|
|
584
584
|
return {
|
|
585
585
|
name: 'snapshot-plugin',
|
|
586
|
-
async
|
|
586
|
+
async afterResolve (args) {
|
|
587
587
|
const { remote, pkgNameOrAlias, expose, origin, remoteInfo } = args;
|
|
588
588
|
if (!share.isRemoteInfoWithEntry(remote) || !share.isPureRemoteEntry(remote)) {
|
|
589
589
|
const { remoteSnapshot, globalSnapshot } = await origin.snapshotHandler.loadRemoteSnapshotInfo(remote);
|
|
@@ -1033,7 +1033,10 @@ class SnapshotHandler {
|
|
|
1033
1033
|
return manifestJson;
|
|
1034
1034
|
}
|
|
1035
1035
|
try {
|
|
1036
|
-
|
|
1036
|
+
let res = await this.loaderHook.lifecycle.fetch.emit(manifestUrl, {});
|
|
1037
|
+
if (!res || !(res instanceof Response)) {
|
|
1038
|
+
res = await fetch(manifestUrl, {});
|
|
1039
|
+
}
|
|
1037
1040
|
manifestJson = await res.json();
|
|
1038
1041
|
share.assert(manifestJson.metaData && manifestJson.exposes && manifestJson.shared, `${manifestUrl} is not a federation manifest`);
|
|
1039
1042
|
this.manifestCache.set(manifestUrl, manifestJson);
|
|
@@ -1074,6 +1077,7 @@ class SnapshotHandler {
|
|
|
1074
1077
|
});
|
|
1075
1078
|
this.manifestLoading = share.Global.__FEDERATION__.__MANIFEST_LOADING__;
|
|
1076
1079
|
this.HostInstance = HostInstance;
|
|
1080
|
+
this.loaderHook = HostInstance.loaderHook;
|
|
1077
1081
|
}
|
|
1078
1082
|
}
|
|
1079
1083
|
|
|
@@ -1235,7 +1239,7 @@ class FederationHost {
|
|
|
1235
1239
|
`);
|
|
1236
1240
|
}
|
|
1237
1241
|
async _getRemoteModuleAndOptions(id) {
|
|
1238
|
-
const loadRemoteArgs = await this.hooks.lifecycle.
|
|
1242
|
+
const loadRemoteArgs = await this.hooks.lifecycle.beforeRequest.emit({
|
|
1239
1243
|
id,
|
|
1240
1244
|
options: this.options,
|
|
1241
1245
|
origin: this
|
|
@@ -1248,11 +1252,11 @@ class FederationHost {
|
|
|
1248
1252
|
2. ${idRes} could not be found in the 'remotes' of ${this.options.name} with either 'name' or 'alias' attributes.
|
|
1249
1253
|
3. ${idRes} is not online, injected, or loaded.
|
|
1250
1254
|
4. ${idRes} cannot be accessed on the expected.
|
|
1251
|
-
5. The '
|
|
1255
|
+
5. The 'beforeRequest' hook was provided but did not return the correct 'remoteInfo' when attempting to load ${idRes}.
|
|
1252
1256
|
`);
|
|
1253
1257
|
const { remote: rawRemote } = remoteSplitInfo;
|
|
1254
1258
|
const remoteInfo = getRemoteInfo(rawRemote);
|
|
1255
|
-
const matchInfo = await this.hooks.lifecycle.
|
|
1259
|
+
const matchInfo = await this.hooks.lifecycle.afterResolve.emit(_extends({
|
|
1256
1260
|
id: idRes
|
|
1257
1261
|
}, remoteSplitInfo, {
|
|
1258
1262
|
options: this.options,
|
|
@@ -1260,7 +1264,7 @@ class FederationHost {
|
|
|
1260
1264
|
remoteInfo
|
|
1261
1265
|
}));
|
|
1262
1266
|
const { remote, expose } = matchInfo;
|
|
1263
|
-
share.assert(remote && expose, `The '
|
|
1267
|
+
share.assert(remote && expose, `The 'beforeRequest' hook was executed, but it failed to return the correct 'remote' and 'expose' values while loading ${idRes}.`);
|
|
1264
1268
|
let module = this.moduleCache.get(remote.name);
|
|
1265
1269
|
const moduleOptions = {
|
|
1266
1270
|
hostInfo: {
|
|
@@ -1299,7 +1303,7 @@ class FederationHost {
|
|
|
1299
1303
|
const { module, moduleOptions, remoteMatchInfo } = await this._getRemoteModuleAndOptions(id);
|
|
1300
1304
|
const { pkgNameOrAlias, remote, expose, id: idRes } = remoteMatchInfo;
|
|
1301
1305
|
const moduleOrFactory = await module.get(expose, options);
|
|
1302
|
-
await this.hooks.lifecycle.
|
|
1306
|
+
await this.hooks.lifecycle.onLoad.emit({
|
|
1303
1307
|
id: idRes,
|
|
1304
1308
|
pkgNameOrAlias,
|
|
1305
1309
|
expose,
|
|
@@ -1523,9 +1527,9 @@ class FederationHost {
|
|
|
1523
1527
|
this.hooks = new PluginSystem({
|
|
1524
1528
|
beforeInit: new SyncWaterfallHook('beforeInit'),
|
|
1525
1529
|
init: new SyncHook(),
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1530
|
+
beforeRequest: new AsyncWaterfallHook('beforeRequest'),
|
|
1531
|
+
afterResolve: new AsyncWaterfallHook('afterResolve'),
|
|
1532
|
+
onLoad: new AsyncHook('onLoad'),
|
|
1529
1533
|
handlePreloadModule: new SyncHook('handlePreloadModule'),
|
|
1530
1534
|
errorLoadRemote: new AsyncHook('errorLoadRemote'),
|
|
1531
1535
|
beforeLoadShare: new AsyncWaterfallHook('beforeLoadShare'),
|
|
@@ -1534,12 +1538,13 @@ class FederationHost {
|
|
|
1534
1538
|
generatePreloadAssets: new AsyncHook('generatePreloadAssets'),
|
|
1535
1539
|
afterPreloadRemote: new AsyncHook()
|
|
1536
1540
|
});
|
|
1537
|
-
this.version = '1.0.
|
|
1541
|
+
this.version = '1.0.1-canary.1';
|
|
1538
1542
|
this.moduleCache = new Map();
|
|
1539
1543
|
this.loaderHook = new PluginSystem({
|
|
1540
1544
|
// FIXME: may not be suitable
|
|
1541
1545
|
getModuleInfo: new SyncHook(),
|
|
1542
|
-
createScript: new SyncHook()
|
|
1546
|
+
createScript: new SyncHook(),
|
|
1547
|
+
fetch: new AsyncHook('fetch')
|
|
1543
1548
|
});
|
|
1544
1549
|
this.loadingShare = {};
|
|
1545
1550
|
// TODO: Validate the details of the options
|
package/index.esm.js
CHANGED
|
@@ -580,7 +580,7 @@ function assignRemoteInfo(remoteInfo, remoteSnapshot) {
|
|
|
580
580
|
function snapshotPlugin() {
|
|
581
581
|
return {
|
|
582
582
|
name: 'snapshot-plugin',
|
|
583
|
-
async
|
|
583
|
+
async afterResolve (args) {
|
|
584
584
|
const { remote, pkgNameOrAlias, expose, origin, remoteInfo } = args;
|
|
585
585
|
if (!isRemoteInfoWithEntry(remote) || !isPureRemoteEntry(remote)) {
|
|
586
586
|
const { remoteSnapshot, globalSnapshot } = await origin.snapshotHandler.loadRemoteSnapshotInfo(remote);
|
|
@@ -1030,7 +1030,10 @@ class SnapshotHandler {
|
|
|
1030
1030
|
return manifestJson;
|
|
1031
1031
|
}
|
|
1032
1032
|
try {
|
|
1033
|
-
|
|
1033
|
+
let res = await this.loaderHook.lifecycle.fetch.emit(manifestUrl, {});
|
|
1034
|
+
if (!res || !(res instanceof Response)) {
|
|
1035
|
+
res = await fetch(manifestUrl, {});
|
|
1036
|
+
}
|
|
1034
1037
|
manifestJson = await res.json();
|
|
1035
1038
|
assert(manifestJson.metaData && manifestJson.exposes && manifestJson.shared, `${manifestUrl} is not a federation manifest`);
|
|
1036
1039
|
this.manifestCache.set(manifestUrl, manifestJson);
|
|
@@ -1071,6 +1074,7 @@ class SnapshotHandler {
|
|
|
1071
1074
|
});
|
|
1072
1075
|
this.manifestLoading = Global.__FEDERATION__.__MANIFEST_LOADING__;
|
|
1073
1076
|
this.HostInstance = HostInstance;
|
|
1077
|
+
this.loaderHook = HostInstance.loaderHook;
|
|
1074
1078
|
}
|
|
1075
1079
|
}
|
|
1076
1080
|
|
|
@@ -1232,7 +1236,7 @@ class FederationHost {
|
|
|
1232
1236
|
`);
|
|
1233
1237
|
}
|
|
1234
1238
|
async _getRemoteModuleAndOptions(id) {
|
|
1235
|
-
const loadRemoteArgs = await this.hooks.lifecycle.
|
|
1239
|
+
const loadRemoteArgs = await this.hooks.lifecycle.beforeRequest.emit({
|
|
1236
1240
|
id,
|
|
1237
1241
|
options: this.options,
|
|
1238
1242
|
origin: this
|
|
@@ -1245,11 +1249,11 @@ class FederationHost {
|
|
|
1245
1249
|
2. ${idRes} could not be found in the 'remotes' of ${this.options.name} with either 'name' or 'alias' attributes.
|
|
1246
1250
|
3. ${idRes} is not online, injected, or loaded.
|
|
1247
1251
|
4. ${idRes} cannot be accessed on the expected.
|
|
1248
|
-
5. The '
|
|
1252
|
+
5. The 'beforeRequest' hook was provided but did not return the correct 'remoteInfo' when attempting to load ${idRes}.
|
|
1249
1253
|
`);
|
|
1250
1254
|
const { remote: rawRemote } = remoteSplitInfo;
|
|
1251
1255
|
const remoteInfo = getRemoteInfo(rawRemote);
|
|
1252
|
-
const matchInfo = await this.hooks.lifecycle.
|
|
1256
|
+
const matchInfo = await this.hooks.lifecycle.afterResolve.emit(_extends({
|
|
1253
1257
|
id: idRes
|
|
1254
1258
|
}, remoteSplitInfo, {
|
|
1255
1259
|
options: this.options,
|
|
@@ -1257,7 +1261,7 @@ class FederationHost {
|
|
|
1257
1261
|
remoteInfo
|
|
1258
1262
|
}));
|
|
1259
1263
|
const { remote, expose } = matchInfo;
|
|
1260
|
-
assert(remote && expose, `The '
|
|
1264
|
+
assert(remote && expose, `The 'beforeRequest' hook was executed, but it failed to return the correct 'remote' and 'expose' values while loading ${idRes}.`);
|
|
1261
1265
|
let module = this.moduleCache.get(remote.name);
|
|
1262
1266
|
const moduleOptions = {
|
|
1263
1267
|
hostInfo: {
|
|
@@ -1296,7 +1300,7 @@ class FederationHost {
|
|
|
1296
1300
|
const { module, moduleOptions, remoteMatchInfo } = await this._getRemoteModuleAndOptions(id);
|
|
1297
1301
|
const { pkgNameOrAlias, remote, expose, id: idRes } = remoteMatchInfo;
|
|
1298
1302
|
const moduleOrFactory = await module.get(expose, options);
|
|
1299
|
-
await this.hooks.lifecycle.
|
|
1303
|
+
await this.hooks.lifecycle.onLoad.emit({
|
|
1300
1304
|
id: idRes,
|
|
1301
1305
|
pkgNameOrAlias,
|
|
1302
1306
|
expose,
|
|
@@ -1520,9 +1524,9 @@ class FederationHost {
|
|
|
1520
1524
|
this.hooks = new PluginSystem({
|
|
1521
1525
|
beforeInit: new SyncWaterfallHook('beforeInit'),
|
|
1522
1526
|
init: new SyncHook(),
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1527
|
+
beforeRequest: new AsyncWaterfallHook('beforeRequest'),
|
|
1528
|
+
afterResolve: new AsyncWaterfallHook('afterResolve'),
|
|
1529
|
+
onLoad: new AsyncHook('onLoad'),
|
|
1526
1530
|
handlePreloadModule: new SyncHook('handlePreloadModule'),
|
|
1527
1531
|
errorLoadRemote: new AsyncHook('errorLoadRemote'),
|
|
1528
1532
|
beforeLoadShare: new AsyncWaterfallHook('beforeLoadShare'),
|
|
@@ -1531,12 +1535,13 @@ class FederationHost {
|
|
|
1531
1535
|
generatePreloadAssets: new AsyncHook('generatePreloadAssets'),
|
|
1532
1536
|
afterPreloadRemote: new AsyncHook()
|
|
1533
1537
|
});
|
|
1534
|
-
this.version = '1.0.
|
|
1538
|
+
this.version = '1.0.1-canary.1';
|
|
1535
1539
|
this.moduleCache = new Map();
|
|
1536
1540
|
this.loaderHook = new PluginSystem({
|
|
1537
1541
|
// FIXME: may not be suitable
|
|
1538
1542
|
getModuleInfo: new SyncHook(),
|
|
1539
|
-
createScript: new SyncHook()
|
|
1543
|
+
createScript: new SyncHook(),
|
|
1544
|
+
fetch: new AsyncHook('fetch')
|
|
1540
1545
|
});
|
|
1541
1546
|
this.loadingShare = {};
|
|
1542
1547
|
// TODO: Validate the details of the options
|
package/package.json
CHANGED
package/share.cjs.js
CHANGED
|
@@ -168,7 +168,7 @@ function getGlobalFederationConstructor() {
|
|
|
168
168
|
function setGlobalFederationConstructor(FederationConstructor) {
|
|
169
169
|
if (isDebugMode()) {
|
|
170
170
|
Global.__FEDERATION__.__DEBUG_CONSTRUCTOR__ = FederationConstructor;
|
|
171
|
-
Global.__FEDERATION__.__DEBUG_CONSTRUCTOR_VERSION__ = '1.0.
|
|
171
|
+
Global.__FEDERATION__.__DEBUG_CONSTRUCTOR_VERSION__ = '1.0.1-canary.1';
|
|
172
172
|
}
|
|
173
173
|
}
|
|
174
174
|
// eslint-disable-next-line @typescript-eslint/ban-types
|
package/share.esm.js
CHANGED
|
@@ -166,7 +166,7 @@ function getGlobalFederationConstructor() {
|
|
|
166
166
|
function setGlobalFederationConstructor(FederationConstructor) {
|
|
167
167
|
if (isDebugMode()) {
|
|
168
168
|
Global.__FEDERATION__.__DEBUG_CONSTRUCTOR__ = FederationConstructor;
|
|
169
|
-
Global.__FEDERATION__.__DEBUG_CONSTRUCTOR_VERSION__ = '1.0.
|
|
169
|
+
Global.__FEDERATION__.__DEBUG_CONSTRUCTOR_VERSION__ = '1.0.1-canary.1';
|
|
170
170
|
}
|
|
171
171
|
}
|
|
172
172
|
// eslint-disable-next-line @typescript-eslint/ban-types
|
package/src/core.d.ts
CHANGED
|
@@ -26,13 +26,13 @@ export declare class FederationHost {
|
|
|
26
26
|
options: Options;
|
|
27
27
|
origin: FederationHost;
|
|
28
28
|
}], void>;
|
|
29
|
-
|
|
29
|
+
beforeRequest: AsyncWaterfallHook<{
|
|
30
30
|
id: string;
|
|
31
31
|
options: Options;
|
|
32
32
|
origin: FederationHost;
|
|
33
33
|
}>;
|
|
34
|
-
|
|
35
|
-
|
|
34
|
+
afterResolve: AsyncWaterfallHook<LoadRemoteMatch>;
|
|
35
|
+
onLoad: AsyncHook<[{
|
|
36
36
|
id: string;
|
|
37
37
|
expose: string;
|
|
38
38
|
pkgNameOrAlias: string;
|
|
@@ -94,6 +94,7 @@ export declare class FederationHost {
|
|
|
94
94
|
createScript: SyncHook<[{
|
|
95
95
|
url: string;
|
|
96
96
|
}], void | HTMLScriptElement>;
|
|
97
|
+
fetch: AsyncHook<[string, RequestInit], false | void | Promise<Response>>;
|
|
97
98
|
}>;
|
|
98
99
|
loadingShare: {
|
|
99
100
|
[key: string]: Promise<any>;
|
|
@@ -28,6 +28,7 @@ export declare class SnapshotHandler {
|
|
|
28
28
|
from: 'global' | 'manifest';
|
|
29
29
|
}>;
|
|
30
30
|
}>;
|
|
31
|
+
loaderHook: FederationHost['loaderHook'];
|
|
31
32
|
manifestLoading: Record<string, Promise<ModuleInfo>>;
|
|
32
33
|
constructor(HostInstance: FederationHost);
|
|
33
34
|
loadSnapshot(moduleInfo: Remote): Promise<{
|