@module-federation/runtime 0.0.16 → 0.1.0
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/README.md +70 -3
- package/dist/index.cjs.js +88 -27
- package/dist/index.esm.js +88 -30
- package/dist/package.json +1 -1
- package/dist/share.cjs.js +1 -1
- package/dist/share.esm.js +2 -2
- package/dist/src/core.d.ts +7 -0
- package/dist/src/index.d.ts +2 -0
- package/dist/src/utils/index.d.ts +1 -0
- package/dist/src/utils/load.d.ts +1 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -212,15 +212,15 @@ init({
|
|
|
212
212
|
remotes: [
|
|
213
213
|
{
|
|
214
214
|
name: '@demo/sub1',
|
|
215
|
-
entry: 'http://localhost:2001/
|
|
215
|
+
entry: 'http://localhost:2001/mf-manifest.json',
|
|
216
216
|
},
|
|
217
217
|
{
|
|
218
218
|
name: '@demo/sub2',
|
|
219
|
-
entry: 'http://localhost:2001/
|
|
219
|
+
entry: 'http://localhost:2001/mf-manifest.json',
|
|
220
220
|
},
|
|
221
221
|
{
|
|
222
222
|
name: '@demo/sub3',
|
|
223
|
-
entry: 'http://localhost:2001/
|
|
223
|
+
entry: 'http://localhost:2001/mf-manifest.json',
|
|
224
224
|
},
|
|
225
225
|
],
|
|
226
226
|
});
|
|
@@ -258,6 +258,73 @@ preloadRemote([
|
|
|
258
258
|
]);
|
|
259
259
|
```
|
|
260
260
|
|
|
261
|
+
### registerRemotes
|
|
262
|
+
|
|
263
|
+
- Type: `registerRemotes(remotes: Remote[], options?: { force?: boolean }): void`
|
|
264
|
+
- Used to register remotes after init .
|
|
265
|
+
|
|
266
|
+
- Type
|
|
267
|
+
|
|
268
|
+
```typescript
|
|
269
|
+
function registerRemotes(remotes: Remote[], options?: { force?: boolean }) {}
|
|
270
|
+
|
|
271
|
+
type Remote = (RemoteWithEntry | RemoteWithVersion) & RemoteInfoCommon;
|
|
272
|
+
|
|
273
|
+
interface RemoteInfoCommon {
|
|
274
|
+
alias?: string;
|
|
275
|
+
shareScope?: string;
|
|
276
|
+
type?: RemoteEntryType;
|
|
277
|
+
entryGlobalName?: string;
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
interface RemoteWithEntry {
|
|
281
|
+
name: string;
|
|
282
|
+
entry: string;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
interface RemoteWithVersion {
|
|
286
|
+
name: string;
|
|
287
|
+
version: string;
|
|
288
|
+
}
|
|
289
|
+
```
|
|
290
|
+
|
|
291
|
+
- Details
|
|
292
|
+
**info**: Please be careful when setting `force:true` !
|
|
293
|
+
|
|
294
|
+
If set `force: true`, it will merge remote(include loaded remote), and remove loaded remote cache , as well as console.warn to tell this action may have risks.
|
|
295
|
+
|
|
296
|
+
* Example
|
|
297
|
+
|
|
298
|
+
```ts
|
|
299
|
+
import { init, registerRemotes } from '@module-federation/runtime';
|
|
300
|
+
|
|
301
|
+
init({
|
|
302
|
+
name: '@demo/register-new-remotes',
|
|
303
|
+
remotes: [
|
|
304
|
+
{
|
|
305
|
+
name: '@demo/sub1',
|
|
306
|
+
entry: 'http://localhost:2001/mf-manifest.json',
|
|
307
|
+
}
|
|
308
|
+
],
|
|
309
|
+
});
|
|
310
|
+
|
|
311
|
+
// add new remote @demo/sub2
|
|
312
|
+
registerRemotes([
|
|
313
|
+
{
|
|
314
|
+
name: '@demo/sub2',
|
|
315
|
+
entry: 'http://localhost:2002/mf-manifest.json',
|
|
316
|
+
}
|
|
317
|
+
]);
|
|
318
|
+
|
|
319
|
+
// override previous remote @demo/sub1
|
|
320
|
+
registerRemotes([
|
|
321
|
+
{
|
|
322
|
+
name: '@demo/sub1',
|
|
323
|
+
entry: 'http://localhost:2003/mf-manifest.json',
|
|
324
|
+
}
|
|
325
|
+
]);
|
|
326
|
+
```
|
|
327
|
+
|
|
261
328
|
## hooks
|
|
262
329
|
|
|
263
330
|
Lifecycle hooks for FederationHost interaction.
|
package/dist/index.cjs.js
CHANGED
|
@@ -160,9 +160,13 @@ async function loadEntryScript({ name, globalName, entry, createScriptHook }) {
|
|
|
160
160
|
return e;
|
|
161
161
|
});
|
|
162
162
|
}
|
|
163
|
+
function getRemoteEntryUniqueKey(remoteInfo) {
|
|
164
|
+
const { entry, name } = remoteInfo;
|
|
165
|
+
return sdk.composeKeyWithSeparator(name, entry);
|
|
166
|
+
}
|
|
163
167
|
async function getRemoteEntry({ remoteEntryExports, remoteInfo, createScriptHook }) {
|
|
164
168
|
const { entry, name, type, entryGlobalName } = remoteInfo;
|
|
165
|
-
const uniqueKey =
|
|
169
|
+
const uniqueKey = getRemoteEntryUniqueKey(remoteInfo);
|
|
166
170
|
if (remoteEntryExports) {
|
|
167
171
|
return remoteEntryExports;
|
|
168
172
|
}
|
|
@@ -786,7 +790,9 @@ function generatePreloadAssets(origin, preloadOptions, remote, globalSnapshot, r
|
|
|
786
790
|
id: assetsInfo.moduleName === '.' ? remoteInfo.name : exposeFullPath,
|
|
787
791
|
name: remoteInfo.name,
|
|
788
792
|
remoteSnapshot: moduleInfoSnapshot,
|
|
789
|
-
preloadConfig
|
|
793
|
+
preloadConfig,
|
|
794
|
+
remote: remoteInfo,
|
|
795
|
+
origin
|
|
790
796
|
});
|
|
791
797
|
const preloaded = share.getPreloaded(exposeFullPath);
|
|
792
798
|
if (preloaded) {
|
|
@@ -1478,30 +1484,9 @@ class FederationHost {
|
|
|
1478
1484
|
});
|
|
1479
1485
|
const userRemotes = userOptionsRes.remotes || [];
|
|
1480
1486
|
const remotes = userRemotes.reduce((res, remote)=>{
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
// As multi-level path references cannot guarantee unique names, alias being a prefix of remote.name is not supported
|
|
1485
|
-
const findEqual = res.find((item)=>{
|
|
1486
|
-
var _item_alias;
|
|
1487
|
-
return remote.alias && (item.name.startsWith(remote.alias) || ((_item_alias = item.alias) == null ? void 0 : _item_alias.startsWith(remote.alias)));
|
|
1488
|
-
});
|
|
1489
|
-
share.assert(!findEqual, `The alias ${remote.alias} of remote ${remote.name} is not allowed to be the prefix of ${findEqual && findEqual.name} name or alias`);
|
|
1490
|
-
}
|
|
1491
|
-
// Set the remote entry to a complete path
|
|
1492
|
-
if ('entry' in remote) {
|
|
1493
|
-
if (share.isBrowserEnv() && !remote.entry.startsWith('http')) {
|
|
1494
|
-
remote.entry = new URL(remote.entry, window.location.origin).href;
|
|
1495
|
-
}
|
|
1496
|
-
}
|
|
1497
|
-
if (!remote.shareScope) {
|
|
1498
|
-
remote.shareScope = share.DEFAULT_SCOPE;
|
|
1499
|
-
}
|
|
1500
|
-
if (!remote.type) {
|
|
1501
|
-
remote.type = share.DEFAULT_REMOTE_TYPE;
|
|
1502
|
-
}
|
|
1503
|
-
res.push(remote);
|
|
1504
|
-
}
|
|
1487
|
+
this.registerRemote(remote, res, {
|
|
1488
|
+
force: false
|
|
1489
|
+
});
|
|
1505
1490
|
return res;
|
|
1506
1491
|
}, globalOptionsRes.remotes);
|
|
1507
1492
|
// register shared in shareScopeMap
|
|
@@ -1581,6 +1566,74 @@ class FederationHost {
|
|
|
1581
1566
|
}
|
|
1582
1567
|
});
|
|
1583
1568
|
}
|
|
1569
|
+
removeRemote(remote) {
|
|
1570
|
+
const { name } = remote;
|
|
1571
|
+
const remoteIndex = this.options.remotes.findIndex((item)=>item.name === name);
|
|
1572
|
+
if (remoteIndex !== -1) {
|
|
1573
|
+
this.options.remotes.splice(remoteIndex, 1);
|
|
1574
|
+
}
|
|
1575
|
+
const loadedModule = this.moduleCache.get(remote.name);
|
|
1576
|
+
if (loadedModule) {
|
|
1577
|
+
const key = loadedModule.remoteInfo.entryGlobalName;
|
|
1578
|
+
if (globalThis[key]) {
|
|
1579
|
+
delete globalThis[key];
|
|
1580
|
+
}
|
|
1581
|
+
const remoteEntryUniqueKey = getRemoteEntryUniqueKey(loadedModule.remoteInfo);
|
|
1582
|
+
if (share.globalLoading[remoteEntryUniqueKey]) {
|
|
1583
|
+
delete share.globalLoading[remoteEntryUniqueKey];
|
|
1584
|
+
}
|
|
1585
|
+
this.moduleCache.delete(remote.name);
|
|
1586
|
+
}
|
|
1587
|
+
}
|
|
1588
|
+
registerRemote(remote, targetRemotes, options) {
|
|
1589
|
+
const normalizeRemote = ()=>{
|
|
1590
|
+
if (remote.alias) {
|
|
1591
|
+
// Validate if alias equals the prefix of remote.name and remote.alias, if so, throw an error
|
|
1592
|
+
// As multi-level path references cannot guarantee unique names, alias being a prefix of remote.name is not supported
|
|
1593
|
+
const findEqual = targetRemotes.find((item)=>{
|
|
1594
|
+
var _item_alias;
|
|
1595
|
+
return remote.alias && (item.name.startsWith(remote.alias) || ((_item_alias = item.alias) == null ? void 0 : _item_alias.startsWith(remote.alias)));
|
|
1596
|
+
});
|
|
1597
|
+
share.assert(!findEqual, `The alias ${remote.alias} of remote ${remote.name} is not allowed to be the prefix of ${findEqual && findEqual.name} name or alias`);
|
|
1598
|
+
}
|
|
1599
|
+
// Set the remote entry to a complete path
|
|
1600
|
+
if ('entry' in remote) {
|
|
1601
|
+
if (share.isBrowserEnv() && !remote.entry.startsWith('http')) {
|
|
1602
|
+
remote.entry = new URL(remote.entry, window.location.origin).href;
|
|
1603
|
+
}
|
|
1604
|
+
}
|
|
1605
|
+
if (!remote.shareScope) {
|
|
1606
|
+
remote.shareScope = share.DEFAULT_SCOPE;
|
|
1607
|
+
}
|
|
1608
|
+
if (!remote.type) {
|
|
1609
|
+
remote.type = share.DEFAULT_REMOTE_TYPE;
|
|
1610
|
+
}
|
|
1611
|
+
};
|
|
1612
|
+
const registeredRemote = targetRemotes.find((item)=>item.name === remote.name);
|
|
1613
|
+
if (!registeredRemote) {
|
|
1614
|
+
normalizeRemote();
|
|
1615
|
+
targetRemotes.push(remote);
|
|
1616
|
+
} else {
|
|
1617
|
+
const messages = [
|
|
1618
|
+
`The remote "${remote.name}" is already registered.`,
|
|
1619
|
+
(options == null ? void 0 : options.force) ? 'Hope you have known that OVERRIDE it may have some unexpected errors' : 'If you want to merge the remote, you can set "force: true".'
|
|
1620
|
+
];
|
|
1621
|
+
if (options == null ? void 0 : options.force) {
|
|
1622
|
+
// remove registered remote
|
|
1623
|
+
this.removeRemote(registeredRemote);
|
|
1624
|
+
normalizeRemote();
|
|
1625
|
+
targetRemotes.push(remote);
|
|
1626
|
+
}
|
|
1627
|
+
share.warn(messages.join(' '));
|
|
1628
|
+
}
|
|
1629
|
+
}
|
|
1630
|
+
registerRemotes(remotes, options) {
|
|
1631
|
+
remotes.forEach((remote)=>{
|
|
1632
|
+
this.registerRemote(remote, this.options.remotes, {
|
|
1633
|
+
force: options == null ? void 0 : options.force
|
|
1634
|
+
});
|
|
1635
|
+
});
|
|
1636
|
+
}
|
|
1584
1637
|
constructor(userOptions){
|
|
1585
1638
|
this.hooks = new PluginSystem({
|
|
1586
1639
|
beforeInit: new SyncWaterfallHook('beforeInit'),
|
|
@@ -1605,7 +1658,7 @@ class FederationHost {
|
|
|
1605
1658
|
// not used yet
|
|
1606
1659
|
afterPreloadRemote: new AsyncHook()
|
|
1607
1660
|
});
|
|
1608
|
-
this.version = "0.0
|
|
1661
|
+
this.version = "0.1.0";
|
|
1609
1662
|
this.moduleCache = new Map();
|
|
1610
1663
|
this.loaderHook = new PluginSystem({
|
|
1611
1664
|
// FIXME: may not be suitable , not open to the public yet
|
|
@@ -1680,6 +1733,11 @@ function preloadRemote(...args) {
|
|
|
1680
1733
|
// eslint-disable-next-line prefer-spread
|
|
1681
1734
|
return FederationInstance.preloadRemote.apply(FederationInstance, args);
|
|
1682
1735
|
}
|
|
1736
|
+
function registerRemotes(...args) {
|
|
1737
|
+
share.assert(FederationInstance, 'Please call init first');
|
|
1738
|
+
// eslint-disable-next-line prefer-spread
|
|
1739
|
+
return FederationInstance.registerRemotes.apply(FederationInstance, args);
|
|
1740
|
+
}
|
|
1683
1741
|
// Inject for debug
|
|
1684
1742
|
share.setGlobalFederationConstructor(FederationHost);
|
|
1685
1743
|
|
|
@@ -1693,8 +1751,11 @@ Object.defineProperty(exports, 'loadScriptNode', {
|
|
|
1693
1751
|
get: function () { return sdk.loadScriptNode; }
|
|
1694
1752
|
});
|
|
1695
1753
|
exports.FederationHost = FederationHost;
|
|
1754
|
+
exports.getRemoteEntry = getRemoteEntry;
|
|
1755
|
+
exports.getRemoteInfo = getRemoteInfo;
|
|
1696
1756
|
exports.init = init;
|
|
1697
1757
|
exports.loadRemote = loadRemote;
|
|
1698
1758
|
exports.loadShare = loadShare;
|
|
1699
1759
|
exports.loadShareSync = loadShareSync;
|
|
1700
1760
|
exports.preloadRemote = preloadRemote;
|
|
1761
|
+
exports.registerRemotes = registerRemotes;
|
package/dist/index.esm.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { g as getGlobalHostPlugins,
|
|
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 getRegisteredShare, m as getInfoWithoutType, n as getPreloaded, o as setPreloaded, p as getGlobalSnapshotInfoByModuleInfo, q as addGlobalSnapshot, r as setGlobalSnapshotInfoByModuleInfo, t as getGlobalSnapshot, G as Global, u as getGlobalShareScope, v as formatShareConfigs, x as getBuilderId, y as isBrowserEnv, z as addUniqueItem, A as setGlobalFederationConstructor, B as getGlobalFederationInstance, C as getGlobalFederationConstructor, E as setGlobalFederationInstance } from './share.esm.js';
|
|
2
2
|
export { F as registerGlobalPlugins } from './share.esm.js';
|
|
3
|
-
import {
|
|
3
|
+
import { loadScriptNode, loadScript, composeKeyWithSeparator, createLink, getResourceUrl, isManifestProvider, generateSnapshotFromManifest } 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
|
|
@@ -158,9 +158,13 @@ async function loadEntryScript({ name, globalName, entry, createScriptHook }) {
|
|
|
158
158
|
return e;
|
|
159
159
|
});
|
|
160
160
|
}
|
|
161
|
+
function getRemoteEntryUniqueKey(remoteInfo) {
|
|
162
|
+
const { entry, name } = remoteInfo;
|
|
163
|
+
return composeKeyWithSeparator(name, entry);
|
|
164
|
+
}
|
|
161
165
|
async function getRemoteEntry({ remoteEntryExports, remoteInfo, createScriptHook }) {
|
|
162
166
|
const { entry, name, type, entryGlobalName } = remoteInfo;
|
|
163
|
-
const uniqueKey =
|
|
167
|
+
const uniqueKey = getRemoteEntryUniqueKey(remoteInfo);
|
|
164
168
|
if (remoteEntryExports) {
|
|
165
169
|
return remoteEntryExports;
|
|
166
170
|
}
|
|
@@ -784,7 +788,9 @@ function generatePreloadAssets(origin, preloadOptions, remote, globalSnapshot, r
|
|
|
784
788
|
id: assetsInfo.moduleName === '.' ? remoteInfo.name : exposeFullPath,
|
|
785
789
|
name: remoteInfo.name,
|
|
786
790
|
remoteSnapshot: moduleInfoSnapshot,
|
|
787
|
-
preloadConfig
|
|
791
|
+
preloadConfig,
|
|
792
|
+
remote: remoteInfo,
|
|
793
|
+
origin
|
|
788
794
|
});
|
|
789
795
|
const preloaded = getPreloaded(exposeFullPath);
|
|
790
796
|
if (preloaded) {
|
|
@@ -1476,30 +1482,9 @@ class FederationHost {
|
|
|
1476
1482
|
});
|
|
1477
1483
|
const userRemotes = userOptionsRes.remotes || [];
|
|
1478
1484
|
const remotes = userRemotes.reduce((res, remote)=>{
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
// As multi-level path references cannot guarantee unique names, alias being a prefix of remote.name is not supported
|
|
1483
|
-
const findEqual = res.find((item)=>{
|
|
1484
|
-
var _item_alias;
|
|
1485
|
-
return remote.alias && (item.name.startsWith(remote.alias) || ((_item_alias = item.alias) == null ? void 0 : _item_alias.startsWith(remote.alias)));
|
|
1486
|
-
});
|
|
1487
|
-
assert(!findEqual, `The alias ${remote.alias} of remote ${remote.name} is not allowed to be the prefix of ${findEqual && findEqual.name} name or alias`);
|
|
1488
|
-
}
|
|
1489
|
-
// Set the remote entry to a complete path
|
|
1490
|
-
if ('entry' in remote) {
|
|
1491
|
-
if (isBrowserEnv() && !remote.entry.startsWith('http')) {
|
|
1492
|
-
remote.entry = new URL(remote.entry, window.location.origin).href;
|
|
1493
|
-
}
|
|
1494
|
-
}
|
|
1495
|
-
if (!remote.shareScope) {
|
|
1496
|
-
remote.shareScope = DEFAULT_SCOPE;
|
|
1497
|
-
}
|
|
1498
|
-
if (!remote.type) {
|
|
1499
|
-
remote.type = DEFAULT_REMOTE_TYPE;
|
|
1500
|
-
}
|
|
1501
|
-
res.push(remote);
|
|
1502
|
-
}
|
|
1485
|
+
this.registerRemote(remote, res, {
|
|
1486
|
+
force: false
|
|
1487
|
+
});
|
|
1503
1488
|
return res;
|
|
1504
1489
|
}, globalOptionsRes.remotes);
|
|
1505
1490
|
// register shared in shareScopeMap
|
|
@@ -1579,6 +1564,74 @@ class FederationHost {
|
|
|
1579
1564
|
}
|
|
1580
1565
|
});
|
|
1581
1566
|
}
|
|
1567
|
+
removeRemote(remote) {
|
|
1568
|
+
const { name } = remote;
|
|
1569
|
+
const remoteIndex = this.options.remotes.findIndex((item)=>item.name === name);
|
|
1570
|
+
if (remoteIndex !== -1) {
|
|
1571
|
+
this.options.remotes.splice(remoteIndex, 1);
|
|
1572
|
+
}
|
|
1573
|
+
const loadedModule = this.moduleCache.get(remote.name);
|
|
1574
|
+
if (loadedModule) {
|
|
1575
|
+
const key = loadedModule.remoteInfo.entryGlobalName;
|
|
1576
|
+
if (globalThis[key]) {
|
|
1577
|
+
delete globalThis[key];
|
|
1578
|
+
}
|
|
1579
|
+
const remoteEntryUniqueKey = getRemoteEntryUniqueKey(loadedModule.remoteInfo);
|
|
1580
|
+
if (globalLoading[remoteEntryUniqueKey]) {
|
|
1581
|
+
delete globalLoading[remoteEntryUniqueKey];
|
|
1582
|
+
}
|
|
1583
|
+
this.moduleCache.delete(remote.name);
|
|
1584
|
+
}
|
|
1585
|
+
}
|
|
1586
|
+
registerRemote(remote, targetRemotes, options) {
|
|
1587
|
+
const normalizeRemote = ()=>{
|
|
1588
|
+
if (remote.alias) {
|
|
1589
|
+
// Validate if alias equals the prefix of remote.name and remote.alias, if so, throw an error
|
|
1590
|
+
// As multi-level path references cannot guarantee unique names, alias being a prefix of remote.name is not supported
|
|
1591
|
+
const findEqual = targetRemotes.find((item)=>{
|
|
1592
|
+
var _item_alias;
|
|
1593
|
+
return remote.alias && (item.name.startsWith(remote.alias) || ((_item_alias = item.alias) == null ? void 0 : _item_alias.startsWith(remote.alias)));
|
|
1594
|
+
});
|
|
1595
|
+
assert(!findEqual, `The alias ${remote.alias} of remote ${remote.name} is not allowed to be the prefix of ${findEqual && findEqual.name} name or alias`);
|
|
1596
|
+
}
|
|
1597
|
+
// Set the remote entry to a complete path
|
|
1598
|
+
if ('entry' in remote) {
|
|
1599
|
+
if (isBrowserEnv() && !remote.entry.startsWith('http')) {
|
|
1600
|
+
remote.entry = new URL(remote.entry, window.location.origin).href;
|
|
1601
|
+
}
|
|
1602
|
+
}
|
|
1603
|
+
if (!remote.shareScope) {
|
|
1604
|
+
remote.shareScope = DEFAULT_SCOPE;
|
|
1605
|
+
}
|
|
1606
|
+
if (!remote.type) {
|
|
1607
|
+
remote.type = DEFAULT_REMOTE_TYPE;
|
|
1608
|
+
}
|
|
1609
|
+
};
|
|
1610
|
+
const registeredRemote = targetRemotes.find((item)=>item.name === remote.name);
|
|
1611
|
+
if (!registeredRemote) {
|
|
1612
|
+
normalizeRemote();
|
|
1613
|
+
targetRemotes.push(remote);
|
|
1614
|
+
} else {
|
|
1615
|
+
const messages = [
|
|
1616
|
+
`The remote "${remote.name}" is already registered.`,
|
|
1617
|
+
(options == null ? void 0 : options.force) ? 'Hope you have known that OVERRIDE it may have some unexpected errors' : 'If you want to merge the remote, you can set "force: true".'
|
|
1618
|
+
];
|
|
1619
|
+
if (options == null ? void 0 : options.force) {
|
|
1620
|
+
// remove registered remote
|
|
1621
|
+
this.removeRemote(registeredRemote);
|
|
1622
|
+
normalizeRemote();
|
|
1623
|
+
targetRemotes.push(remote);
|
|
1624
|
+
}
|
|
1625
|
+
warn(messages.join(' '));
|
|
1626
|
+
}
|
|
1627
|
+
}
|
|
1628
|
+
registerRemotes(remotes, options) {
|
|
1629
|
+
remotes.forEach((remote)=>{
|
|
1630
|
+
this.registerRemote(remote, this.options.remotes, {
|
|
1631
|
+
force: options == null ? void 0 : options.force
|
|
1632
|
+
});
|
|
1633
|
+
});
|
|
1634
|
+
}
|
|
1582
1635
|
constructor(userOptions){
|
|
1583
1636
|
this.hooks = new PluginSystem({
|
|
1584
1637
|
beforeInit: new SyncWaterfallHook('beforeInit'),
|
|
@@ -1603,7 +1656,7 @@ class FederationHost {
|
|
|
1603
1656
|
// not used yet
|
|
1604
1657
|
afterPreloadRemote: new AsyncHook()
|
|
1605
1658
|
});
|
|
1606
|
-
this.version = "0.0
|
|
1659
|
+
this.version = "0.1.0";
|
|
1607
1660
|
this.moduleCache = new Map();
|
|
1608
1661
|
this.loaderHook = new PluginSystem({
|
|
1609
1662
|
// FIXME: may not be suitable , not open to the public yet
|
|
@@ -1678,7 +1731,12 @@ function preloadRemote(...args) {
|
|
|
1678
1731
|
// eslint-disable-next-line prefer-spread
|
|
1679
1732
|
return FederationInstance.preloadRemote.apply(FederationInstance, args);
|
|
1680
1733
|
}
|
|
1734
|
+
function registerRemotes(...args) {
|
|
1735
|
+
assert(FederationInstance, 'Please call init first');
|
|
1736
|
+
// eslint-disable-next-line prefer-spread
|
|
1737
|
+
return FederationInstance.registerRemotes.apply(FederationInstance, args);
|
|
1738
|
+
}
|
|
1681
1739
|
// Inject for debug
|
|
1682
1740
|
setGlobalFederationConstructor(FederationHost);
|
|
1683
1741
|
|
|
1684
|
-
export { FederationHost, init, loadRemote, loadShare, loadShareSync, preloadRemote };
|
|
1742
|
+
export { FederationHost, getRemoteEntry, getRemoteInfo, init, loadRemote, loadShare, loadShareSync, preloadRemote, registerRemotes };
|
package/dist/package.json
CHANGED
package/dist/share.cjs.js
CHANGED
|
@@ -185,7 +185,7 @@ function getGlobalFederationConstructor() {
|
|
|
185
185
|
function setGlobalFederationConstructor(FederationConstructor, isDebug = isDebugMode()) {
|
|
186
186
|
if (isDebug) {
|
|
187
187
|
globalThis.__FEDERATION__.__DEBUG_CONSTRUCTOR__ = FederationConstructor;
|
|
188
|
-
globalThis.__FEDERATION__.__DEBUG_CONSTRUCTOR_VERSION__ = "0.0
|
|
188
|
+
globalThis.__FEDERATION__.__DEBUG_CONSTRUCTOR_VERSION__ = "0.1.0";
|
|
189
189
|
}
|
|
190
190
|
}
|
|
191
191
|
// eslint-disable-next-line @typescript-eslint/ban-types
|
package/dist/share.esm.js
CHANGED
|
@@ -183,7 +183,7 @@ function getGlobalFederationConstructor() {
|
|
|
183
183
|
function setGlobalFederationConstructor(FederationConstructor, isDebug = isDebugMode()) {
|
|
184
184
|
if (isDebug) {
|
|
185
185
|
globalThis.__FEDERATION__.__DEBUG_CONSTRUCTOR__ = FederationConstructor;
|
|
186
|
-
globalThis.__FEDERATION__.__DEBUG_CONSTRUCTOR_VERSION__ = "0.0
|
|
186
|
+
globalThis.__FEDERATION__.__DEBUG_CONSTRUCTOR_VERSION__ = "0.1.0";
|
|
187
187
|
}
|
|
188
188
|
}
|
|
189
189
|
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
@@ -803,4 +803,4 @@ function getGlobalShareScope() {
|
|
|
803
803
|
return Global.__FEDERATION__.__SHARE__;
|
|
804
804
|
}
|
|
805
805
|
|
|
806
|
-
export { setGlobalFederationConstructor as A, getGlobalFederationInstance as B, getGlobalFederationConstructor as C, DEFAULT_REMOTE_TYPE as D, setGlobalFederationInstance as E, registerGlobalPlugins as F, Global as G, nativeGlobal as H, resetFederationGlobalInfo as I, getTargetSnapshotInfoByModuleInfo as J,
|
|
806
|
+
export { setGlobalFederationConstructor as A, getGlobalFederationInstance as B, getGlobalFederationConstructor as C, DEFAULT_REMOTE_TYPE as D, setGlobalFederationInstance as E, registerGlobalPlugins as F, Global as G, nativeGlobal as H, resetFederationGlobalInfo as I, getTargetSnapshotInfoByModuleInfo as J, 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, getRegisteredShare as l, getInfoWithoutType as m, getPreloaded as n, setPreloaded as o, getGlobalSnapshotInfoByModuleInfo as p, addGlobalSnapshot as q, setGlobalSnapshotInfoByModuleInfo as r, safeToString as s, getGlobalSnapshot as t, getGlobalShareScope as u, formatShareConfigs as v, warn as w, getBuilderId as x, isBrowserEnv as y, addUniqueItem as z };
|
package/dist/src/core.d.ts
CHANGED
|
@@ -67,8 +67,10 @@ export declare class FederationHost {
|
|
|
67
67
|
handlePreloadModule: SyncHook<{
|
|
68
68
|
id: string;
|
|
69
69
|
name: string;
|
|
70
|
+
remote: Remote;
|
|
70
71
|
remoteSnapshot: ModuleInfo;
|
|
71
72
|
preloadConfig: PreloadRemoteArgs;
|
|
73
|
+
origin: FederationHost;
|
|
72
74
|
}, void>;
|
|
73
75
|
errorLoadRemote: AsyncHook<[{
|
|
74
76
|
id: string;
|
|
@@ -153,5 +155,10 @@ export declare class FederationHost {
|
|
|
153
155
|
private formatOptions;
|
|
154
156
|
private registerPlugins;
|
|
155
157
|
private setShared;
|
|
158
|
+
private removeRemote;
|
|
159
|
+
private registerRemote;
|
|
160
|
+
registerRemotes(remotes: Remote[], options?: {
|
|
161
|
+
force?: boolean;
|
|
162
|
+
}): void;
|
|
156
163
|
}
|
|
157
164
|
export {};
|
package/dist/src/index.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { FederationHost } from './core';
|
|
|
2
2
|
import { UserOptions, FederationRuntimePlugin } from './type';
|
|
3
3
|
export { FederationHost } from './core';
|
|
4
4
|
export { registerGlobalPlugins } from './global';
|
|
5
|
+
export { getRemoteEntry, getRemoteInfo } from './utils';
|
|
5
6
|
export { loadScript, loadScriptNode } from '@module-federation/sdk';
|
|
6
7
|
export type { Federation } from './global';
|
|
7
8
|
export type { FederationRuntimePlugin };
|
|
@@ -10,3 +11,4 @@ export declare function loadRemote(...args: Parameters<FederationHost['loadRemot
|
|
|
10
11
|
export declare function loadShare(...args: Parameters<FederationHost['loadShare']>): ReturnType<FederationHost['loadShare']>;
|
|
11
12
|
export declare function loadShareSync(...args: Parameters<FederationHost['loadShareSync']>): ReturnType<FederationHost['loadShareSync']>;
|
|
12
13
|
export declare function preloadRemote(...args: Parameters<FederationHost['preloadRemote']>): ReturnType<FederationHost['preloadRemote']>;
|
|
14
|
+
export declare function registerRemotes(...args: Parameters<FederationHost['registerRemotes']>): ReturnType<FederationHost['registerRemotes']>;
|
package/dist/src/utils/load.d.ts
CHANGED
|
@@ -9,6 +9,7 @@ export declare function loadEntryScript({ name, globalName, entry, createScriptH
|
|
|
9
9
|
entry: string;
|
|
10
10
|
createScriptHook?: (url: string) => HTMLScriptElement | void;
|
|
11
11
|
}): Promise<RemoteEntryExports>;
|
|
12
|
+
export declare function getRemoteEntryUniqueKey(remoteInfo: RemoteInfo): string;
|
|
12
13
|
export declare function getRemoteEntry({ remoteEntryExports, remoteInfo, createScriptHook, }: {
|
|
13
14
|
remoteInfo: RemoteInfo;
|
|
14
15
|
remoteEntryExports?: RemoteEntryExports | undefined;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@module-federation/runtime",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.1.0",
|
|
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
|
|
48
|
+
"@module-federation/sdk": "0.1.0"
|
|
49
49
|
}
|
|
50
50
|
}
|