@module-federation/runtime 0.1.16 → 0.1.18
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.esm.js +1 -1
- package/dist/index.cjs.js +41 -9
- package/dist/index.esm.js +45 -13
- package/dist/package.json +1 -1
- package/dist/share.cjs.js +1 -1
- package/dist/share.esm.js +2 -2
- package/dist/src/module/index.d.ts +2 -1
- package/package.json +2 -2
package/dist/helpers.esm.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { p as getRegisteredShare, z as getGlobalShareScope, G as Global, J as nativeGlobal, K as resetFederationGlobalInfo, E as getGlobalFederationInstance, H as setGlobalFederationInstance, F as getGlobalFederationConstructor, C as setGlobalFederationConstructor, m as getInfoWithoutType, v as getGlobalSnapshot, L as getTargetSnapshotInfoByModuleInfo, r as getGlobalSnapshotInfoByModuleInfo, u as setGlobalSnapshotInfoByModuleInfo, t as addGlobalSnapshot, c as getRemoteEntryExports, I as registerGlobalPlugins, g as getGlobalHostPlugins, n as getPreloaded, o as setPreloaded } from './share.esm.js';
|
|
2
2
|
|
|
3
3
|
const ShareUtils = {
|
|
4
4
|
getRegisteredShare,
|
package/dist/index.cjs.js
CHANGED
|
@@ -142,7 +142,7 @@ async function loadEntryScript({ name, globalName, entry, createScriptHook }) {
|
|
|
142
142
|
`);
|
|
143
143
|
return entryExports;
|
|
144
144
|
}).catch((e)=>{
|
|
145
|
-
|
|
145
|
+
throw e;
|
|
146
146
|
});
|
|
147
147
|
}
|
|
148
148
|
return sdk.loadScript(entry, {
|
|
@@ -158,7 +158,7 @@ async function loadEntryScript({ name, globalName, entry, createScriptHook }) {
|
|
|
158
158
|
`);
|
|
159
159
|
return entryExports;
|
|
160
160
|
}).catch((e)=>{
|
|
161
|
-
|
|
161
|
+
throw e;
|
|
162
162
|
});
|
|
163
163
|
}
|
|
164
164
|
function getRemoteEntryUniqueKey(remoteInfo) {
|
|
@@ -172,7 +172,10 @@ async function getRemoteEntry({ remoteEntryExports, remoteInfo, createScriptHook
|
|
|
172
172
|
return remoteEntryExports;
|
|
173
173
|
}
|
|
174
174
|
if (!share.globalLoading[uniqueKey]) {
|
|
175
|
-
if (
|
|
175
|
+
if ([
|
|
176
|
+
'esm',
|
|
177
|
+
'module'
|
|
178
|
+
].includes(type)) {
|
|
176
179
|
share.globalLoading[uniqueKey] = loadEsmEntry({
|
|
177
180
|
entry,
|
|
178
181
|
remoteEntryExports
|
|
@@ -243,7 +246,7 @@ let Module = class Module {
|
|
|
243
246
|
return this.remoteEntryExports;
|
|
244
247
|
}
|
|
245
248
|
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
|
246
|
-
async get(expose, options) {
|
|
249
|
+
async get(id, expose, options) {
|
|
247
250
|
const { loadFactory = true } = options || {
|
|
248
251
|
loadFactory: true
|
|
249
252
|
};
|
|
@@ -284,12 +287,38 @@ let Module = class Module {
|
|
|
284
287
|
// get exposeGetter
|
|
285
288
|
const moduleFactory = await remoteEntryExports.get(expose);
|
|
286
289
|
share.assert(moduleFactory, `${share.getFMId(this.remoteInfo)} remote don't export ${expose}.`);
|
|
290
|
+
const wrapModuleFactory = this.wraperFactory(moduleFactory, id);
|
|
287
291
|
if (!loadFactory) {
|
|
288
|
-
return
|
|
292
|
+
return wrapModuleFactory;
|
|
289
293
|
}
|
|
290
|
-
const exposeContent = await
|
|
294
|
+
const exposeContent = await wrapModuleFactory();
|
|
291
295
|
return exposeContent;
|
|
292
296
|
}
|
|
297
|
+
wraperFactory(moduleFactory, id) {
|
|
298
|
+
function defineModuleId(res, id) {
|
|
299
|
+
if (res && typeof res === 'object' && !Object.getOwnPropertyDescriptor(res, Symbol.for('mf_module_id'))) {
|
|
300
|
+
Object.defineProperty(res, Symbol.for('mf_module_id'), {
|
|
301
|
+
value: id,
|
|
302
|
+
enumerable: false
|
|
303
|
+
});
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
if (moduleFactory instanceof Promise) {
|
|
307
|
+
return async ()=>{
|
|
308
|
+
const res = await moduleFactory();
|
|
309
|
+
// This parameter is used for bridge debugging
|
|
310
|
+
defineModuleId(res, id);
|
|
311
|
+
return res;
|
|
312
|
+
};
|
|
313
|
+
} else {
|
|
314
|
+
return ()=>{
|
|
315
|
+
const res = moduleFactory();
|
|
316
|
+
// This parameter is used for bridge debugging
|
|
317
|
+
defineModuleId(res, id);
|
|
318
|
+
return res;
|
|
319
|
+
};
|
|
320
|
+
}
|
|
321
|
+
}
|
|
293
322
|
constructor({ remoteInfo, host }){
|
|
294
323
|
this.inited = false;
|
|
295
324
|
this.lib = undefined;
|
|
@@ -642,7 +671,10 @@ function assignRemoteInfo(remoteInfo, remoteSnapshot) {
|
|
|
642
671
|
share.error(`The attribute remoteEntry of ${name} must not be undefined.`);
|
|
643
672
|
}
|
|
644
673
|
const { remoteEntry } = remoteSnapshot;
|
|
645
|
-
|
|
674
|
+
let entryUrl = sdk.getResourceUrl(remoteSnapshot, remoteEntry);
|
|
675
|
+
if (!share.isBrowserEnv() && !entryUrl.startsWith('http')) {
|
|
676
|
+
entryUrl = `https:${entryUrl}`;
|
|
677
|
+
}
|
|
646
678
|
remoteInfo.type = remoteSnapshot.remoteEntryType;
|
|
647
679
|
remoteInfo.entryGlobalName = remoteSnapshot.globalName;
|
|
648
680
|
remoteInfo.entry = entryUrl;
|
|
@@ -1500,7 +1532,7 @@ class RemoteHandler {
|
|
|
1500
1532
|
id
|
|
1501
1533
|
});
|
|
1502
1534
|
const { pkgNameOrAlias, remote, expose, id: idRes } = remoteMatchInfo;
|
|
1503
|
-
const moduleOrFactory = await module.get(expose, options);
|
|
1535
|
+
const moduleOrFactory = await module.get(idRes, expose, options);
|
|
1504
1536
|
const moduleWrapper = await this.hooks.lifecycle.onLoad.emit({
|
|
1505
1537
|
id: idRes,
|
|
1506
1538
|
pkgNameOrAlias,
|
|
@@ -1881,7 +1913,7 @@ class FederationHost {
|
|
|
1881
1913
|
// maybe will change, temporarily for internal use only
|
|
1882
1914
|
initContainer: new AsyncWaterfallHook('initContainer')
|
|
1883
1915
|
});
|
|
1884
|
-
this.version = "0.1.
|
|
1916
|
+
this.version = "0.1.18";
|
|
1885
1917
|
this.moduleCache = new Map();
|
|
1886
1918
|
this.loaderHook = new PluginSystem({
|
|
1887
1919
|
// FIXME: may not be suitable , not open to the public yet
|
package/dist/index.esm.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { g as getGlobalHostPlugins, a as globalLoading, D as DEFAULT_REMOTE_TYPE, b as DEFAULT_SCOPE, c as getRemoteEntryExports, d as assert, s as safeToString, 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, a as globalLoading, D as DEFAULT_REMOTE_TYPE, b as DEFAULT_SCOPE, c as getRemoteEntryExports, d as assert, s as safeToString, e as getFMId, i as isObject, f as error, w as warn, h as isPlainObject, j as isRemoteInfoWithEntry, k as isPureRemoteEntry, l as isBrowserEnv, m as getInfoWithoutType, n as getPreloaded, o as setPreloaded, p as getRegisteredShare, q as arrayOptions, r as getGlobalSnapshotInfoByModuleInfo, t as addGlobalSnapshot, u as setGlobalSnapshotInfoByModuleInfo, v as getGlobalSnapshot, G as Global, x as formatShareConfigs, y as getTargetSharedOptions, z as getGlobalShareScope, A as addUniqueItem, B as getBuilderId, C as setGlobalFederationConstructor, E as getGlobalFederationInstance, F as getGlobalFederationConstructor, H as setGlobalFederationInstance } from './share.esm.js';
|
|
2
2
|
export { I as registerGlobalPlugins } from './share.esm.js';
|
|
3
|
-
import { loadScriptNode, loadScript, composeKeyWithSeparator, createLink, getResourceUrl, isManifestProvider, generateSnapshotFromManifest, warn as warn$1, isBrowserEnv } from '@module-federation/sdk';
|
|
3
|
+
import { loadScriptNode, loadScript, composeKeyWithSeparator, createLink, getResourceUrl, isManifestProvider, generateSnapshotFromManifest, warn as warn$1, isBrowserEnv as isBrowserEnv$1 } from '@module-federation/sdk';
|
|
4
4
|
export { loadScript, loadScriptNode } from '@module-federation/sdk';
|
|
5
5
|
|
|
6
6
|
// Function to match a remote with its name and expose
|
|
@@ -140,7 +140,7 @@ async function loadEntryScript({ name, globalName, entry, createScriptHook }) {
|
|
|
140
140
|
`);
|
|
141
141
|
return entryExports;
|
|
142
142
|
}).catch((e)=>{
|
|
143
|
-
|
|
143
|
+
throw e;
|
|
144
144
|
});
|
|
145
145
|
}
|
|
146
146
|
return loadScript(entry, {
|
|
@@ -156,7 +156,7 @@ async function loadEntryScript({ name, globalName, entry, createScriptHook }) {
|
|
|
156
156
|
`);
|
|
157
157
|
return entryExports;
|
|
158
158
|
}).catch((e)=>{
|
|
159
|
-
|
|
159
|
+
throw e;
|
|
160
160
|
});
|
|
161
161
|
}
|
|
162
162
|
function getRemoteEntryUniqueKey(remoteInfo) {
|
|
@@ -170,7 +170,10 @@ async function getRemoteEntry({ remoteEntryExports, remoteInfo, createScriptHook
|
|
|
170
170
|
return remoteEntryExports;
|
|
171
171
|
}
|
|
172
172
|
if (!globalLoading[uniqueKey]) {
|
|
173
|
-
if (
|
|
173
|
+
if ([
|
|
174
|
+
'esm',
|
|
175
|
+
'module'
|
|
176
|
+
].includes(type)) {
|
|
174
177
|
globalLoading[uniqueKey] = loadEsmEntry({
|
|
175
178
|
entry,
|
|
176
179
|
remoteEntryExports
|
|
@@ -241,7 +244,7 @@ let Module = class Module {
|
|
|
241
244
|
return this.remoteEntryExports;
|
|
242
245
|
}
|
|
243
246
|
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
|
244
|
-
async get(expose, options) {
|
|
247
|
+
async get(id, expose, options) {
|
|
245
248
|
const { loadFactory = true } = options || {
|
|
246
249
|
loadFactory: true
|
|
247
250
|
};
|
|
@@ -282,12 +285,38 @@ let Module = class Module {
|
|
|
282
285
|
// get exposeGetter
|
|
283
286
|
const moduleFactory = await remoteEntryExports.get(expose);
|
|
284
287
|
assert(moduleFactory, `${getFMId(this.remoteInfo)} remote don't export ${expose}.`);
|
|
288
|
+
const wrapModuleFactory = this.wraperFactory(moduleFactory, id);
|
|
285
289
|
if (!loadFactory) {
|
|
286
|
-
return
|
|
290
|
+
return wrapModuleFactory;
|
|
287
291
|
}
|
|
288
|
-
const exposeContent = await
|
|
292
|
+
const exposeContent = await wrapModuleFactory();
|
|
289
293
|
return exposeContent;
|
|
290
294
|
}
|
|
295
|
+
wraperFactory(moduleFactory, id) {
|
|
296
|
+
function defineModuleId(res, id) {
|
|
297
|
+
if (res && typeof res === 'object' && !Object.getOwnPropertyDescriptor(res, Symbol.for('mf_module_id'))) {
|
|
298
|
+
Object.defineProperty(res, Symbol.for('mf_module_id'), {
|
|
299
|
+
value: id,
|
|
300
|
+
enumerable: false
|
|
301
|
+
});
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
if (moduleFactory instanceof Promise) {
|
|
305
|
+
return async ()=>{
|
|
306
|
+
const res = await moduleFactory();
|
|
307
|
+
// This parameter is used for bridge debugging
|
|
308
|
+
defineModuleId(res, id);
|
|
309
|
+
return res;
|
|
310
|
+
};
|
|
311
|
+
} else {
|
|
312
|
+
return ()=>{
|
|
313
|
+
const res = moduleFactory();
|
|
314
|
+
// This parameter is used for bridge debugging
|
|
315
|
+
defineModuleId(res, id);
|
|
316
|
+
return res;
|
|
317
|
+
};
|
|
318
|
+
}
|
|
319
|
+
}
|
|
291
320
|
constructor({ remoteInfo, host }){
|
|
292
321
|
this.inited = false;
|
|
293
322
|
this.lib = undefined;
|
|
@@ -640,7 +669,10 @@ function assignRemoteInfo(remoteInfo, remoteSnapshot) {
|
|
|
640
669
|
error(`The attribute remoteEntry of ${name} must not be undefined.`);
|
|
641
670
|
}
|
|
642
671
|
const { remoteEntry } = remoteSnapshot;
|
|
643
|
-
|
|
672
|
+
let entryUrl = getResourceUrl(remoteSnapshot, remoteEntry);
|
|
673
|
+
if (!isBrowserEnv() && !entryUrl.startsWith('http')) {
|
|
674
|
+
entryUrl = `https:${entryUrl}`;
|
|
675
|
+
}
|
|
644
676
|
remoteInfo.type = remoteSnapshot.remoteEntryType;
|
|
645
677
|
remoteInfo.entryGlobalName = remoteSnapshot.globalName;
|
|
646
678
|
remoteInfo.entry = entryUrl;
|
|
@@ -1498,7 +1530,7 @@ class RemoteHandler {
|
|
|
1498
1530
|
id
|
|
1499
1531
|
});
|
|
1500
1532
|
const { pkgNameOrAlias, remote, expose, id: idRes } = remoteMatchInfo;
|
|
1501
|
-
const moduleOrFactory = await module.get(expose, options);
|
|
1533
|
+
const moduleOrFactory = await module.get(idRes, expose, options);
|
|
1502
1534
|
const moduleWrapper = await this.hooks.lifecycle.onLoad.emit({
|
|
1503
1535
|
id: idRes,
|
|
1504
1536
|
pkgNameOrAlias,
|
|
@@ -1638,7 +1670,7 @@ class RemoteHandler {
|
|
|
1638
1670
|
}
|
|
1639
1671
|
// Set the remote entry to a complete path
|
|
1640
1672
|
if ('entry' in remote) {
|
|
1641
|
-
if (isBrowserEnv() && !remote.entry.startsWith('http')) {
|
|
1673
|
+
if (isBrowserEnv$1() && !remote.entry.startsWith('http')) {
|
|
1642
1674
|
remote.entry = new URL(remote.entry, window.location.origin).href;
|
|
1643
1675
|
}
|
|
1644
1676
|
}
|
|
@@ -1879,7 +1911,7 @@ class FederationHost {
|
|
|
1879
1911
|
// maybe will change, temporarily for internal use only
|
|
1880
1912
|
initContainer: new AsyncWaterfallHook('initContainer')
|
|
1881
1913
|
});
|
|
1882
|
-
this.version = "0.1.
|
|
1914
|
+
this.version = "0.1.18";
|
|
1883
1915
|
this.moduleCache = new Map();
|
|
1884
1916
|
this.loaderHook = new PluginSystem({
|
|
1885
1917
|
// FIXME: may not be suitable , not open to the public yet
|
|
@@ -1900,7 +1932,7 @@ class FederationHost {
|
|
|
1900
1932
|
],
|
|
1901
1933
|
remotes: [],
|
|
1902
1934
|
shared: {},
|
|
1903
|
-
inBrowser: isBrowserEnv
|
|
1935
|
+
inBrowser: isBrowserEnv()
|
|
1904
1936
|
};
|
|
1905
1937
|
this.name = userOptions.name;
|
|
1906
1938
|
this.options = defaultOptions;
|
package/dist/package.json
CHANGED
package/dist/share.cjs.js
CHANGED
|
@@ -190,7 +190,7 @@ function getGlobalFederationConstructor() {
|
|
|
190
190
|
function setGlobalFederationConstructor(FederationConstructor, isDebug = isDebugMode()) {
|
|
191
191
|
if (isDebug) {
|
|
192
192
|
globalThis.__FEDERATION__.__DEBUG_CONSTRUCTOR__ = FederationConstructor;
|
|
193
|
-
globalThis.__FEDERATION__.__DEBUG_CONSTRUCTOR_VERSION__ = "0.1.
|
|
193
|
+
globalThis.__FEDERATION__.__DEBUG_CONSTRUCTOR_VERSION__ = "0.1.18";
|
|
194
194
|
}
|
|
195
195
|
}
|
|
196
196
|
// eslint-disable-next-line @typescript-eslint/ban-types
|
package/dist/share.esm.js
CHANGED
|
@@ -188,7 +188,7 @@ function getGlobalFederationConstructor() {
|
|
|
188
188
|
function setGlobalFederationConstructor(FederationConstructor, isDebug = isDebugMode()) {
|
|
189
189
|
if (isDebug) {
|
|
190
190
|
globalThis.__FEDERATION__.__DEBUG_CONSTRUCTOR__ = FederationConstructor;
|
|
191
|
-
globalThis.__FEDERATION__.__DEBUG_CONSTRUCTOR_VERSION__ = "0.1.
|
|
191
|
+
globalThis.__FEDERATION__.__DEBUG_CONSTRUCTOR_VERSION__ = "0.1.18";
|
|
192
192
|
}
|
|
193
193
|
}
|
|
194
194
|
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
@@ -870,4 +870,4 @@ function getTargetSharedOptions(options) {
|
|
|
870
870
|
return Object.assign({}, resolver(shareInfos[pkgName]), extraOptions == null ? void 0 : extraOptions.customShareInfo);
|
|
871
871
|
}
|
|
872
872
|
|
|
873
|
-
export {
|
|
873
|
+
export { addUniqueItem as A, getBuilderId as B, setGlobalFederationConstructor as C, DEFAULT_REMOTE_TYPE as D, getGlobalFederationInstance as E, getGlobalFederationConstructor as F, Global as G, setGlobalFederationInstance as H, registerGlobalPlugins as I, nativeGlobal as J, resetFederationGlobalInfo as K, getTargetSnapshotInfoByModuleInfo as L, globalLoading as a, DEFAULT_SCOPE as b, getRemoteEntryExports as c, assert as d, getFMId as e, error as f, getGlobalHostPlugins as g, isPlainObject as h, isObject as i, isRemoteInfoWithEntry as j, isPureRemoteEntry as k, isBrowserEnv as l, getInfoWithoutType as m, getPreloaded as n, setPreloaded as o, getRegisteredShare as p, arrayOptions as q, getGlobalSnapshotInfoByModuleInfo as r, safeToString as s, addGlobalSnapshot as t, setGlobalSnapshotInfoByModuleInfo as u, getGlobalSnapshot as v, warn as w, formatShareConfigs as x, getTargetSharedOptions as y, getGlobalShareScope as z };
|
|
@@ -12,8 +12,9 @@ declare class Module {
|
|
|
12
12
|
host: FederationHost;
|
|
13
13
|
});
|
|
14
14
|
getEntry(): Promise<RemoteEntryExports>;
|
|
15
|
-
get(expose: string, options?: {
|
|
15
|
+
get(id: string, expose: string, options?: {
|
|
16
16
|
loadFactory?: boolean;
|
|
17
17
|
}): Promise<any>;
|
|
18
|
+
private wraperFactory;
|
|
18
19
|
}
|
|
19
20
|
export { Module };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@module-federation/runtime",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.18",
|
|
4
4
|
"author": "zhouxiao <codingzx@gmail.com>",
|
|
5
5
|
"main": "./dist/index.cjs.js",
|
|
6
6
|
"module": "./dist/index.esm.js",
|
|
@@ -45,6 +45,6 @@
|
|
|
45
45
|
}
|
|
46
46
|
},
|
|
47
47
|
"dependencies": {
|
|
48
|
-
"@module-federation/sdk": "0.1.
|
|
48
|
+
"@module-federation/sdk": "0.1.18"
|
|
49
49
|
}
|
|
50
50
|
}
|