@module-federation/runtime 0.0.0-next-20240102023857 → 0.0.0-next-20240103032717
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/index.cjs.js +20 -27
- package/dist/index.esm.js +20 -27
- package/dist/share.cjs.js +1 -1
- package/dist/share.esm.js +1 -1
- package/dist/src/core.d.ts +16 -1
- package/dist/src/module/index.d.ts +4 -10
- package/dist/src/type/config.d.ts +2 -1
- package/dist/src/type/plugin.d.ts +1 -1
- package/dist/src/utils/plugin.d.ts +1 -1
- package/package.json +2 -2
package/dist/index.cjs.js
CHANGED
|
@@ -191,7 +191,7 @@ let Module = class Module {
|
|
|
191
191
|
remoteInfo: this.remoteInfo,
|
|
192
192
|
remoteEntryExports: this.remoteEntryExports,
|
|
193
193
|
createScriptHook: (url)=>{
|
|
194
|
-
const res = this.loaderHook.lifecycle.createScript.emit({
|
|
194
|
+
const res = this.host.loaderHook.lifecycle.createScript.emit({
|
|
195
195
|
url
|
|
196
196
|
});
|
|
197
197
|
if (res instanceof HTMLScriptElement) {
|
|
@@ -218,20 +218,21 @@ let Module = class Module {
|
|
|
218
218
|
globalShareScope[remoteShareScope] = {};
|
|
219
219
|
}
|
|
220
220
|
const shareScope = globalShareScope[remoteShareScope];
|
|
221
|
-
|
|
221
|
+
const initScope = [];
|
|
222
222
|
const remoteEntryInitOptions = {
|
|
223
|
-
version: this.remoteInfo.version || ''
|
|
224
|
-
// @ts-ignore it will be passed by startup hooks
|
|
225
|
-
region: this.hostInfo.region
|
|
223
|
+
version: this.remoteInfo.version || ''
|
|
226
224
|
};
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
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
|
+
}));
|
|
235
236
|
}
|
|
236
237
|
this.lib = remoteEntryExports;
|
|
237
238
|
this.inited = true;
|
|
@@ -244,15 +245,11 @@ let Module = class Module {
|
|
|
244
245
|
const exposeContent = await moduleFactory();
|
|
245
246
|
return exposeContent;
|
|
246
247
|
}
|
|
247
|
-
|
|
248
|
-
constructor({ hostInfo, remoteInfo, shared, loaderHook }){
|
|
248
|
+
constructor({ remoteInfo, host }){
|
|
249
249
|
this.inited = false;
|
|
250
|
-
this.shared = {};
|
|
251
250
|
this.lib = undefined;
|
|
252
|
-
this.hostInfo = hostInfo;
|
|
253
251
|
this.remoteInfo = remoteInfo;
|
|
254
|
-
this.
|
|
255
|
-
this.loaderHook = loaderHook;
|
|
252
|
+
this.host = host;
|
|
256
253
|
}
|
|
257
254
|
};
|
|
258
255
|
|
|
@@ -1267,14 +1264,8 @@ class FederationHost {
|
|
|
1267
1264
|
share.assert(remote && expose, `The 'beforeRequest' hook was executed, but it failed to return the correct 'remote' and 'expose' values while loading ${idRes}.`);
|
|
1268
1265
|
let module = this.moduleCache.get(remote.name);
|
|
1269
1266
|
const moduleOptions = {
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
version: this.options.version || 'custom'
|
|
1273
|
-
},
|
|
1274
|
-
remoteInfo,
|
|
1275
|
-
shared: this.options.shared || {},
|
|
1276
|
-
plugins: this.options.plugins,
|
|
1277
|
-
loaderHook: this.loaderHook
|
|
1267
|
+
host: this,
|
|
1268
|
+
remoteInfo
|
|
1278
1269
|
};
|
|
1279
1270
|
if (!module) {
|
|
1280
1271
|
module = new Module(moduleOptions);
|
|
@@ -1529,6 +1520,8 @@ class FederationHost {
|
|
|
1529
1520
|
init: new SyncHook(),
|
|
1530
1521
|
beforeRequest: new AsyncWaterfallHook('beforeRequest'),
|
|
1531
1522
|
afterResolve: new AsyncWaterfallHook('afterResolve'),
|
|
1523
|
+
beforeInitContainer: new AsyncWaterfallHook('beforeInitContainer'),
|
|
1524
|
+
initContainer: new AsyncWaterfallHook('initContainer'),
|
|
1532
1525
|
onLoad: new AsyncHook('onLoad'),
|
|
1533
1526
|
handlePreloadModule: new SyncHook('handlePreloadModule'),
|
|
1534
1527
|
errorLoadRemote: new AsyncHook('errorLoadRemote'),
|
package/dist/index.esm.js
CHANGED
|
@@ -188,7 +188,7 @@ let Module = class Module {
|
|
|
188
188
|
remoteInfo: this.remoteInfo,
|
|
189
189
|
remoteEntryExports: this.remoteEntryExports,
|
|
190
190
|
createScriptHook: (url)=>{
|
|
191
|
-
const res = this.loaderHook.lifecycle.createScript.emit({
|
|
191
|
+
const res = this.host.loaderHook.lifecycle.createScript.emit({
|
|
192
192
|
url
|
|
193
193
|
});
|
|
194
194
|
if (res instanceof HTMLScriptElement) {
|
|
@@ -215,20 +215,21 @@ let Module = class Module {
|
|
|
215
215
|
globalShareScope[remoteShareScope] = {};
|
|
216
216
|
}
|
|
217
217
|
const shareScope = globalShareScope[remoteShareScope];
|
|
218
|
-
|
|
218
|
+
const initScope = [];
|
|
219
219
|
const remoteEntryInitOptions = {
|
|
220
|
-
version: this.remoteInfo.version || ''
|
|
221
|
-
// @ts-ignore it will be passed by startup hooks
|
|
222
|
-
region: this.hostInfo.region
|
|
220
|
+
version: this.remoteInfo.version || ''
|
|
223
221
|
};
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
222
|
+
const initContainerOptions = await this.host.hooks.lifecycle.beforeInitContainer.emit({
|
|
223
|
+
shareScope,
|
|
224
|
+
remoteEntryInitOptions,
|
|
225
|
+
initScope,
|
|
226
|
+
remoteInfo: this.remoteInfo,
|
|
227
|
+
origin: this.host
|
|
228
|
+
});
|
|
229
|
+
remoteEntryExports.init(initContainerOptions.shareScope, initContainerOptions.initScope, initContainerOptions.remoteEntryInitOptions);
|
|
230
|
+
await this.host.hooks.lifecycle.initContainer.emit(_extends$4({}, initContainerOptions, {
|
|
231
|
+
remoteEntryExports
|
|
232
|
+
}));
|
|
232
233
|
}
|
|
233
234
|
this.lib = remoteEntryExports;
|
|
234
235
|
this.inited = true;
|
|
@@ -241,15 +242,11 @@ let Module = class Module {
|
|
|
241
242
|
const exposeContent = await moduleFactory();
|
|
242
243
|
return exposeContent;
|
|
243
244
|
}
|
|
244
|
-
|
|
245
|
-
constructor({ hostInfo, remoteInfo, shared, loaderHook }){
|
|
245
|
+
constructor({ remoteInfo, host }){
|
|
246
246
|
this.inited = false;
|
|
247
|
-
this.shared = {};
|
|
248
247
|
this.lib = undefined;
|
|
249
|
-
this.hostInfo = hostInfo;
|
|
250
248
|
this.remoteInfo = remoteInfo;
|
|
251
|
-
this.
|
|
252
|
-
this.loaderHook = loaderHook;
|
|
249
|
+
this.host = host;
|
|
253
250
|
}
|
|
254
251
|
};
|
|
255
252
|
|
|
@@ -1264,14 +1261,8 @@ class FederationHost {
|
|
|
1264
1261
|
assert(remote && expose, `The 'beforeRequest' hook was executed, but it failed to return the correct 'remote' and 'expose' values while loading ${idRes}.`);
|
|
1265
1262
|
let module = this.moduleCache.get(remote.name);
|
|
1266
1263
|
const moduleOptions = {
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
version: this.options.version || 'custom'
|
|
1270
|
-
},
|
|
1271
|
-
remoteInfo,
|
|
1272
|
-
shared: this.options.shared || {},
|
|
1273
|
-
plugins: this.options.plugins,
|
|
1274
|
-
loaderHook: this.loaderHook
|
|
1264
|
+
host: this,
|
|
1265
|
+
remoteInfo
|
|
1275
1266
|
};
|
|
1276
1267
|
if (!module) {
|
|
1277
1268
|
module = new Module(moduleOptions);
|
|
@@ -1526,6 +1517,8 @@ class FederationHost {
|
|
|
1526
1517
|
init: new SyncHook(),
|
|
1527
1518
|
beforeRequest: new AsyncWaterfallHook('beforeRequest'),
|
|
1528
1519
|
afterResolve: new AsyncWaterfallHook('afterResolve'),
|
|
1520
|
+
beforeInitContainer: new AsyncWaterfallHook('beforeInitContainer'),
|
|
1521
|
+
initContainer: new AsyncWaterfallHook('initContainer'),
|
|
1529
1522
|
onLoad: new AsyncHook('onLoad'),
|
|
1530
1523
|
handlePreloadModule: new SyncHook('handlePreloadModule'),
|
|
1531
1524
|
errorLoadRemote: new AsyncHook('errorLoadRemote'),
|
package/dist/share.cjs.js
CHANGED
|
@@ -150,7 +150,7 @@ function getGlobalFederationInstance(name, version) {
|
|
|
150
150
|
if (buildId && GMInstance.options.id === getBuilderId()) {
|
|
151
151
|
return true;
|
|
152
152
|
}
|
|
153
|
-
if (GMInstance.options.name === name && !version) {
|
|
153
|
+
if (GMInstance.options.name === name && !GMInstance.options.version && !version) {
|
|
154
154
|
return true;
|
|
155
155
|
}
|
|
156
156
|
if (GMInstance.options.name === name && version && GMInstance.options.version === version) {
|
package/dist/share.esm.js
CHANGED
|
@@ -148,7 +148,7 @@ function getGlobalFederationInstance(name, version) {
|
|
|
148
148
|
if (buildId && GMInstance.options.id === getBuilderId()) {
|
|
149
149
|
return true;
|
|
150
150
|
}
|
|
151
|
-
if (GMInstance.options.name === name && !version) {
|
|
151
|
+
if (GMInstance.options.name === name && !GMInstance.options.version && !version) {
|
|
152
152
|
return true;
|
|
153
153
|
}
|
|
154
154
|
if (GMInstance.options.name === name && version && GMInstance.options.version === version) {
|
package/dist/src/core.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ModuleInfo, GlobalModuleInfo } from '@module-federation/sdk';
|
|
2
|
-
import { Options, PreloadAssets, PreloadOptions, PreloadRemoteArgs, Remote, Shared, ShareInfos, UserOptions, RemoteInfo } from './type';
|
|
2
|
+
import { Options, PreloadAssets, PreloadOptions, PreloadRemoteArgs, RemoteEntryExports, Remote, Shared, ShareInfos, UserOptions, RemoteInfo, GlobalShareScope, InitScope, RemoteEntryInitOptions } from './type';
|
|
3
3
|
import { Module, ModuleOptions } from './module';
|
|
4
4
|
import { AsyncHook, AsyncWaterfallHook, PluginSystem, SyncHook, SyncWaterfallHook } from './utils/hooks';
|
|
5
5
|
import { SnapshotHandler } from './plugins/snapshot/SnapshotHandler';
|
|
@@ -32,6 +32,21 @@ export declare class FederationHost {
|
|
|
32
32
|
origin: FederationHost;
|
|
33
33
|
}>;
|
|
34
34
|
afterResolve: AsyncWaterfallHook<LoadRemoteMatch>;
|
|
35
|
+
beforeInitContainer: AsyncWaterfallHook<{
|
|
36
|
+
shareScope: GlobalShareScope[string];
|
|
37
|
+
initScope: InitScope;
|
|
38
|
+
remoteEntryInitOptions: RemoteEntryInitOptions;
|
|
39
|
+
remoteInfo: RemoteInfo;
|
|
40
|
+
origin: FederationHost;
|
|
41
|
+
}>;
|
|
42
|
+
initContainer: AsyncWaterfallHook<{
|
|
43
|
+
shareScope: GlobalShareScope[string];
|
|
44
|
+
initScope: InitScope;
|
|
45
|
+
remoteEntryInitOptions: RemoteEntryInitOptions;
|
|
46
|
+
remoteInfo: RemoteInfo;
|
|
47
|
+
remoteEntryExports: RemoteEntryExports;
|
|
48
|
+
origin: FederationHost;
|
|
49
|
+
}>;
|
|
35
50
|
onLoad: AsyncHook<[{
|
|
36
51
|
id: string;
|
|
37
52
|
expose: string;
|
|
@@ -1,21 +1,15 @@
|
|
|
1
1
|
import { FederationHost } from '../core';
|
|
2
|
-
import { RemoteEntryExports,
|
|
2
|
+
import { RemoteEntryExports, RemoteInfo } from '../type';
|
|
3
3
|
export type ModuleOptions = ConstructorParameters<typeof Module>[0];
|
|
4
|
-
type HostInfo = Remote;
|
|
5
4
|
declare class Module {
|
|
6
|
-
hostInfo: HostInfo;
|
|
7
5
|
remoteInfo: RemoteInfo;
|
|
8
6
|
inited: boolean;
|
|
9
|
-
shared: ShareInfos;
|
|
10
7
|
remoteEntryExports?: RemoteEntryExports;
|
|
11
8
|
lib: RemoteEntryExports | undefined;
|
|
12
|
-
|
|
13
|
-
constructor({
|
|
14
|
-
hostInfo: HostInfo;
|
|
9
|
+
host: FederationHost;
|
|
10
|
+
constructor({ remoteInfo, host, }: {
|
|
15
11
|
remoteInfo: RemoteInfo;
|
|
16
|
-
|
|
17
|
-
plugins: Options['plugins'];
|
|
18
|
-
loaderHook: FederationHost['loaderHook'];
|
|
12
|
+
host: FederationHost;
|
|
19
13
|
});
|
|
20
14
|
getEntry(): Promise<RemoteEntryExports>;
|
|
21
15
|
get(expose: string, options?: {
|
|
@@ -87,8 +87,9 @@ export type LoadModuleOptions = {
|
|
|
87
87
|
export type RemoteEntryInitOptions = {
|
|
88
88
|
version: string;
|
|
89
89
|
};
|
|
90
|
+
export type InitScope = Array<Record<string, never>>;
|
|
90
91
|
export type RemoteEntryExports = {
|
|
91
92
|
get: (id: string) => () => Promise<Module>;
|
|
92
|
-
init: (shareScope: GlobalShareScope[string], initScope?:
|
|
93
|
+
init: (shareScope: GlobalShareScope[string], initScope?: InitScope, remoteEntryInitOPtions?: RemoteEntryInitOptions) => void;
|
|
93
94
|
};
|
|
94
95
|
export {};
|
|
@@ -9,7 +9,7 @@ type SnapshotLifeCycle = SnapshotHandler['hooks']['lifecycle'];
|
|
|
9
9
|
type SnapshotLifeCycleCyclePartial = Partial<{
|
|
10
10
|
[k in keyof SnapshotLifeCycle]: Parameters<SnapshotLifeCycle[k]['on']>[0];
|
|
11
11
|
}>;
|
|
12
|
-
type ModuleLifeCycle = Module['loaderHook']['lifecycle'];
|
|
12
|
+
type ModuleLifeCycle = Module['host']['loaderHook']['lifecycle'];
|
|
13
13
|
type ModuleLifeCycleCyclePartial = Partial<{
|
|
14
14
|
[k in keyof ModuleLifeCycle]: Parameters<ModuleLifeCycle[k]['on']>[0];
|
|
15
15
|
}>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { FederationHost } from '../core';
|
|
2
2
|
import { UserOptions } from '../type';
|
|
3
3
|
import { Module } from '../module';
|
|
4
|
-
export declare function registerPlugins(plugins: UserOptions['plugins'], hookInstances: Array<FederationHost['hooks'] | FederationHost['snapshotHandler']['hooks'] | Module['loaderHook']>): void;
|
|
4
|
+
export declare function registerPlugins(plugins: UserOptions['plugins'], hookInstances: Array<FederationHost['hooks'] | FederationHost['snapshotHandler']['hooks'] | Module['host']['loaderHook']>): void;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@module-federation/runtime",
|
|
3
|
-
"version": "0.0.0-next-
|
|
3
|
+
"version": "0.0.0-next-20240103032717",
|
|
4
4
|
"author": "zhouxiao <codingzx@gmail.com>",
|
|
5
5
|
"main": "./dist/index.cjs",
|
|
6
6
|
"module": "./dist/index.esm.js",
|
|
@@ -45,6 +45,6 @@
|
|
|
45
45
|
}
|
|
46
46
|
},
|
|
47
47
|
"dependencies": {
|
|
48
|
-
"@module-federation/sdk": "0.0.0-next-
|
|
48
|
+
"@module-federation/sdk": "0.0.0-next-20240103032717"
|
|
49
49
|
}
|
|
50
50
|
}
|