@module-federation/runtime
Advanced tools
Comparing version 0.0.0-next-20231228055514 to 0.0.0-next-20231229025030
@@ -6,3 +6,3 @@ 'use strict'; | ||
const ShareUtils = { | ||
getRegisteredShare: share.getRegisteredShare, | ||
getGlobalShare: share.getGlobalShare, | ||
getGlobalShareScope: share.getGlobalShareScope | ||
@@ -9,0 +9,0 @@ }; |
@@ -1,5 +0,5 @@ | ||
import { l as getRegisteredShare, t as getGlobalShareScope, F as nativeGlobal, H as resetFederationGlobalInfo, A as getGlobalFederationInstance, C as setGlobalFederationInstance, B as getGlobalFederationConstructor, z as setGlobalFederationConstructor, m as getInfoWithoutType, r as getGlobalSnapshot, I as getTargetSnapshotInfoByModuleInfo, p as getGlobalSnapshotInfoByModuleInfo, q as setGlobalSnapshotInfoByModuleInfo, J as addGlobalSnapshot, c as getRemoteEntryExports, E as registerGlobalPlugins, g as getGlobalHostPlugins, n as getPreloaded, o as setPreloaded } from './share.esm.js'; | ||
import { l as getGlobalShare, x as getGlobalShareScope, F as nativeGlobal, H as resetFederationGlobalInfo, A as getGlobalFederationInstance, C as setGlobalFederationInstance, B as getGlobalFederationConstructor, z as setGlobalFederationConstructor, m as getInfoWithoutType, r as getGlobalSnapshot, I as getTargetSnapshotInfoByModuleInfo, p as getGlobalSnapshotInfoByModuleInfo, q as setGlobalSnapshotInfoByModuleInfo, J as addGlobalSnapshot, c as getRemoteEntryExports, E as registerGlobalPlugins, g as getGlobalHostPlugins, n as getPreloaded, o as setPreloaded } from './share.esm.js'; | ||
const ShareUtils = { | ||
getRegisteredShare, | ||
getGlobalShare, | ||
getGlobalShareScope | ||
@@ -6,0 +6,0 @@ }; |
@@ -42,4 +42,4 @@ { | ||
], | ||
"types": [ | ||
"./dist/types.cjs.d.ts" | ||
"type": [ | ||
"./dist/type.cjs.d.ts" | ||
] | ||
@@ -46,0 +46,0 @@ } |
'use strict'; | ||
function getBuilderId() { | ||
//@ts-ignore | ||
return typeof FEDERATION_BUILD_IDENTIFIER !== 'undefined' ? FEDERATION_BUILD_IDENTIFIER : ''; | ||
@@ -47,3 +46,3 @@ } | ||
function isPureRemoteEntry(remote) { | ||
return remote.entry.endsWith('.js'); | ||
return !remote.entry.includes('.json') && remote.entry.includes('.js'); | ||
} | ||
@@ -93,5 +92,5 @@ // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types | ||
} | ||
var _nativeGlobal___FEDERATION__, _nativeGlobal___FEDERATION__1, _nativeGlobal___FEDERATION__2, _nativeGlobal___FEDERATION__3, _nativeGlobal___FEDERATION__4, _nativeGlobal___FEDERATION__5; | ||
// export const nativeGlobal: typeof global = new Function('return this')(); | ||
const nativeGlobal = new Function('return this')(); | ||
const Global = nativeGlobal; | ||
// This section is to prevent encapsulation by certain microfrontend frameworks. Due to reuse policies, sandbox escapes. | ||
@@ -107,44 +106,56 @@ // The sandbox in the microfrontend does not replicate the value of 'configurable'. | ||
const globalLoading = globalThis.__GLOBAL_LOADING_REMOTE_ENTRY__; | ||
// | ||
if (nativeGlobal.__VMOK__) { | ||
nativeGlobal.__FEDERATION__ = nativeGlobal.__VMOK__; | ||
} else if (!nativeGlobal.__FEDERATION__) { | ||
nativeGlobal.__FEDERATION__ = { | ||
__GLOBAL_PLUGIN__: [], | ||
__INSTANCES__: [], | ||
moduleInfo: {}, | ||
__SHARE__: {}, | ||
__MANIFEST_LOADING__: {}, | ||
__PRELOADED_MAP__: new Map() | ||
}; | ||
nativeGlobal.__VMOK__ = nativeGlobal.__FEDERATION__; | ||
function setGlobalDefaultVal(target) { | ||
var _target___FEDERATION__, _target___FEDERATION__1, _target___FEDERATION__2, _target___FEDERATION__3, _target___FEDERATION__4, _target___FEDERATION__5, _target___FEDERATION__6; | ||
if (Object.hasOwnProperty.call(target, '__VMOK__')) { | ||
Object.defineProperty(target, '__FEDERATION__', { | ||
value: target.__VMOK__, | ||
configurable: false | ||
}); | ||
} | ||
if (!Object.hasOwnProperty.call(target, '__FEDERATION__')) { | ||
Object.defineProperty(target, '__FEDERATION__', { | ||
value: { | ||
__GLOBAL_PLUGIN__: [], | ||
__INSTANCES__: [], | ||
moduleInfo: {}, | ||
__SHARE__: {}, | ||
__MANIFEST_LOADING__: {}, | ||
__SHARE_SCOPE_LOADING__: {}, | ||
__PRELOADED_MAP__: new Map() | ||
}, | ||
configurable: false | ||
}); | ||
Object.defineProperty(target, '__VMOK__', { | ||
value: target.__FEDERATION__, | ||
configurable: false | ||
}); | ||
} | ||
var ___GLOBAL_PLUGIN__; | ||
(___GLOBAL_PLUGIN__ = (_target___FEDERATION__ = target.__FEDERATION__).__GLOBAL_PLUGIN__) != null ? ___GLOBAL_PLUGIN__ : _target___FEDERATION__.__GLOBAL_PLUGIN__ = []; | ||
var ___INSTANCES__; | ||
(___INSTANCES__ = (_target___FEDERATION__1 = target.__FEDERATION__).__INSTANCES__) != null ? ___INSTANCES__ : _target___FEDERATION__1.__INSTANCES__ = []; | ||
var _moduleInfo; | ||
(_moduleInfo = (_target___FEDERATION__2 = target.__FEDERATION__).moduleInfo) != null ? _moduleInfo : _target___FEDERATION__2.moduleInfo = {}; | ||
var ___SHARE__; | ||
(___SHARE__ = (_target___FEDERATION__3 = target.__FEDERATION__).__SHARE__) != null ? ___SHARE__ : _target___FEDERATION__3.__SHARE__ = {}; | ||
var ___MANIFEST_LOADING__; | ||
(___MANIFEST_LOADING__ = (_target___FEDERATION__4 = target.__FEDERATION__).__MANIFEST_LOADING__) != null ? ___MANIFEST_LOADING__ : _target___FEDERATION__4.__MANIFEST_LOADING__ = {}; | ||
var ___SHARE_SCOPE_LOADING__; | ||
(___SHARE_SCOPE_LOADING__ = (_target___FEDERATION__5 = target.__FEDERATION__).__SHARE_SCOPE_LOADING__) != null ? ___SHARE_SCOPE_LOADING__ : _target___FEDERATION__5.__SHARE_SCOPE_LOADING__ = {}; | ||
var ___PRELOADED_MAP__; | ||
(___PRELOADED_MAP__ = (_target___FEDERATION__6 = target.__FEDERATION__).__PRELOADED_MAP__) != null ? ___PRELOADED_MAP__ : _target___FEDERATION__6.__PRELOADED_MAP__ = new Map(); | ||
} | ||
var ___GLOBAL_PLUGIN__; | ||
(___GLOBAL_PLUGIN__ = (_nativeGlobal___FEDERATION__ = nativeGlobal.__FEDERATION__).__GLOBAL_PLUGIN__) != null ? ___GLOBAL_PLUGIN__ : _nativeGlobal___FEDERATION__.__GLOBAL_PLUGIN__ = []; | ||
var ___INSTANCES__; | ||
(___INSTANCES__ = (_nativeGlobal___FEDERATION__1 = nativeGlobal.__FEDERATION__).__INSTANCES__) != null ? ___INSTANCES__ : _nativeGlobal___FEDERATION__1.__INSTANCES__ = []; | ||
var _moduleInfo; | ||
(_moduleInfo = (_nativeGlobal___FEDERATION__2 = nativeGlobal.__FEDERATION__).moduleInfo) != null ? _moduleInfo : _nativeGlobal___FEDERATION__2.moduleInfo = {}; | ||
var ___SHARE__; | ||
(___SHARE__ = (_nativeGlobal___FEDERATION__3 = nativeGlobal.__FEDERATION__).__SHARE__) != null ? ___SHARE__ : _nativeGlobal___FEDERATION__3.__SHARE__ = {}; | ||
var ___MANIFEST_LOADING__; | ||
(___MANIFEST_LOADING__ = (_nativeGlobal___FEDERATION__4 = nativeGlobal.__FEDERATION__).__MANIFEST_LOADING__) != null ? ___MANIFEST_LOADING__ : _nativeGlobal___FEDERATION__4.__MANIFEST_LOADING__ = {}; | ||
var ___PRELOADED_MAP__; | ||
(___PRELOADED_MAP__ = (_nativeGlobal___FEDERATION__5 = nativeGlobal.__FEDERATION__).__PRELOADED_MAP__) != null ? ___PRELOADED_MAP__ : _nativeGlobal___FEDERATION__5.__PRELOADED_MAP__ = new Map(); | ||
const Global = { | ||
get __FEDERATION__ () { | ||
const globalThisVal = new Function('return globalThis')(); | ||
return globalThisVal.__FEDERATION__; | ||
} | ||
}; | ||
setGlobalDefaultVal(globalThis); | ||
setGlobalDefaultVal(nativeGlobal); | ||
function resetFederationGlobalInfo() { | ||
nativeGlobal.__FEDERATION__.__GLOBAL_PLUGIN__ = []; | ||
nativeGlobal.__FEDERATION__.__INSTANCES__ = []; | ||
nativeGlobal.__FEDERATION__.moduleInfo = {}; | ||
nativeGlobal.__FEDERATION__.__SHARE__ = {}; | ||
nativeGlobal.__FEDERATION__.__MANIFEST_LOADING__ = {}; | ||
globalThis.__FEDERATION__.__GLOBAL_PLUGIN__ = []; | ||
globalThis.__FEDERATION__.__INSTANCES__ = []; | ||
globalThis.__FEDERATION__.moduleInfo = {}; | ||
globalThis.__FEDERATION__.__SHARE__ = {}; | ||
globalThis.__FEDERATION__.__MANIFEST_LOADING__ = {}; | ||
globalThis.__FEDERATION__.__SHARE_SCOPE_LOADING__ = {}; | ||
} | ||
function getGlobalFederationInstance(name, version) { | ||
const buildId = getBuilderId(); | ||
return Global.__FEDERATION__.__INSTANCES__.find((GMInstance)=>{ | ||
return globalThis.__FEDERATION__.__INSTANCES__.find((GMInstance)=>{ | ||
if (buildId && GMInstance.options.id === getBuilderId()) { | ||
@@ -163,11 +174,11 @@ return true; | ||
function setGlobalFederationInstance(FederationInstance) { | ||
Global.__FEDERATION__.__INSTANCES__.push(FederationInstance); | ||
globalThis.__FEDERATION__.__INSTANCES__.push(FederationInstance); | ||
} | ||
function getGlobalFederationConstructor() { | ||
return Global.__FEDERATION__.__DEBUG_CONSTRUCTOR__; | ||
return globalThis.__FEDERATION__.__DEBUG_CONSTRUCTOR__; | ||
} | ||
function setGlobalFederationConstructor(FederationConstructor) { | ||
if (isDebugMode()) { | ||
Global.__FEDERATION__.__DEBUG_CONSTRUCTOR__ = FederationConstructor; | ||
Global.__FEDERATION__.__DEBUG_CONSTRUCTOR_VERSION__ = '0.0.4'; | ||
globalThis.__FEDERATION__.__DEBUG_CONSTRUCTOR__ = FederationConstructor; | ||
globalThis.__FEDERATION__.__DEBUG_CONSTRUCTOR_VERSION__ = '0.0.4'; | ||
} | ||
@@ -187,3 +198,3 @@ } | ||
} | ||
const getGlobalSnapshot = ()=>Global.__FEDERATION__.moduleInfo; | ||
const getGlobalSnapshot = ()=>nativeGlobal.__FEDERATION__.moduleInfo; | ||
const getTargetSnapshotInfoByModuleInfo = (moduleInfo, snapshot, getModuleInfoHook)=>{ | ||
@@ -206,3 +217,3 @@ // Check if the remote is included in the hostSnapshot | ||
const moduleKeyWithoutVersion = getFMId(resModuleInfo); | ||
const getModuleInfoWithoutVersion = getInfoWithoutType(Global.__FEDERATION__.moduleInfo, moduleKeyWithoutVersion, getModuleInfoHook).value; | ||
const getModuleInfoWithoutVersion = getInfoWithoutType(nativeGlobal.__FEDERATION__.moduleInfo, moduleKeyWithoutVersion, getModuleInfoHook).value; | ||
if ((getModuleInfoWithoutVersion == null ? void 0 : getModuleInfoWithoutVersion.version) === version) { | ||
@@ -214,14 +225,14 @@ return getModuleInfoWithoutVersion; | ||
}; | ||
const getGlobalSnapshotInfoByModuleInfo = (moduleInfo, extraOptions)=>getTargetSnapshotInfoByModuleInfo(moduleInfo, Global.__FEDERATION__.moduleInfo, extraOptions == null ? void 0 : extraOptions.getModuleInfoHook); | ||
const getGlobalSnapshotInfoByModuleInfo = (moduleInfo, extraOptions)=>getTargetSnapshotInfoByModuleInfo(moduleInfo, nativeGlobal.__FEDERATION__.moduleInfo, extraOptions == null ? void 0 : extraOptions.getModuleInfoHook); | ||
const setGlobalSnapshotInfoByModuleInfo = (remoteInfo, moduleDetailInfo)=>{ | ||
const moduleKey = getFMId(remoteInfo); | ||
Global.__FEDERATION__.moduleInfo[moduleKey] = moduleDetailInfo; | ||
return Global.__FEDERATION__.moduleInfo; | ||
nativeGlobal.__FEDERATION__.moduleInfo[moduleKey] = moduleDetailInfo; | ||
return nativeGlobal.__FEDERATION__.moduleInfo; | ||
}; | ||
const addGlobalSnapshot = (moduleInfos)=>{ | ||
Global.__FEDERATION__.moduleInfo = _extends$1({}, Global.__FEDERATION__.moduleInfo, moduleInfos); | ||
nativeGlobal.__FEDERATION__.moduleInfo = _extends$1({}, nativeGlobal.__FEDERATION__.moduleInfo, moduleInfos); | ||
return ()=>{ | ||
const keys = Object.keys(moduleInfos); | ||
for (const key of keys){ | ||
delete Global.__FEDERATION__.moduleInfo[key]; | ||
delete nativeGlobal.__FEDERATION__.moduleInfo[key]; | ||
} | ||
@@ -243,3 +254,3 @@ }; | ||
const registerGlobalPlugins = (plugins)=>{ | ||
const { __GLOBAL_PLUGIN__ } = Global.__FEDERATION__; | ||
const { __GLOBAL_PLUGIN__ } = nativeGlobal.__FEDERATION__; | ||
plugins.forEach((plugin)=>{ | ||
@@ -253,5 +264,5 @@ if (__GLOBAL_PLUGIN__.findIndex((p)=>p.name === plugin.name) === -1) { | ||
}; | ||
const getGlobalHostPlugins = ()=>Global.__FEDERATION__.__GLOBAL_PLUGIN__; | ||
const getPreloaded = (id)=>Global.__FEDERATION__.__PRELOADED_MAP__.get(id); | ||
const setPreloaded = (id)=>Global.__FEDERATION__.__PRELOADED_MAP__.set(id, true); | ||
const getGlobalHostPlugins = ()=>nativeGlobal.__FEDERATION__.__GLOBAL_PLUGIN__; | ||
const getPreloaded = (id)=>globalThis.__FEDERATION__.__PRELOADED_MAP__.get(id); | ||
const setPreloaded = (id)=>globalThis.__FEDERATION__.__PRELOADED_MAP__.set(id, true); | ||
@@ -626,12 +637,10 @@ const DEFAULT_SCOPE = 'default'; | ||
from, | ||
shareConfig: { | ||
requiredVersion: `^${shareArgs.version}`, | ||
singleton: false, | ||
eager: false | ||
}, | ||
loading: null | ||
}, shareArgs, { | ||
shareConfig: _extends({ | ||
requiredVersion: `^${shareArgs.version}`, | ||
singleton: false, | ||
eager: false, | ||
strictVersion: false | ||
}, shareArgs.shareConfig), | ||
get, | ||
loaded: 'lib' in shareArgs ? true : undefined, | ||
scope: Array.isArray(shareArgs.scope) ? shareArgs.scope : [ | ||
@@ -653,15 +662,3 @@ 'default' | ||
function versionLt(a, b) { | ||
const transformInvalidVersion = (version)=>{ | ||
const isNumberVersion = !Number.isNaN(Number(version)); | ||
if (isNumberVersion) { | ||
const splitArr = version.split('.'); | ||
let validVersion = version; | ||
for(let i = 0; i < 3 - splitArr.length; i++){ | ||
validVersion += '.0'; | ||
} | ||
return validVersion; | ||
} | ||
return version; | ||
}; | ||
if (satisfy(transformInvalidVersion(a), `<=${transformInvalidVersion(b)}`)) { | ||
if (satisfy(a, `<=${b}`)) { | ||
return true; | ||
@@ -672,4 +669,5 @@ } else { | ||
} | ||
const findVersion = (shareScopeMap, scope, pkgName, cb)=>{ | ||
const versions = shareScopeMap[scope][pkgName]; | ||
const findVersion = (scope, pkgName, cb)=>{ | ||
const globalShares = Global.__FEDERATION__.__SHARE__; | ||
const versions = globalShares[scope][pkgName]; | ||
const callback = cb || function(prev, cur) { | ||
@@ -685,18 +683,16 @@ return versionLt(prev, cur); | ||
} | ||
// default version is '0' https://github.com/webpack/webpack/blob/main/lib/sharing/ProvideSharedModule.js#L136 | ||
if (prev === '0') { | ||
return cur; | ||
} | ||
return prev; | ||
}, 0); | ||
}; | ||
function findSingletonVersionOrderByVersion(shareScopeMap, scope, pkgName) { | ||
const versions = shareScopeMap[scope][pkgName]; | ||
function findSingletonVersionOrderByVersion(scope, pkgName) { | ||
const globalShares = Global.__FEDERATION__.__SHARE__; | ||
const versions = globalShares[scope][pkgName]; | ||
const callback = function(prev, cur) { | ||
return !versions[prev].loaded && versionLt(prev, cur); | ||
}; | ||
return findVersion(shareScopeMap, scope, pkgName, callback); | ||
return findVersion(scope, pkgName, callback); | ||
} | ||
function findSingletonVersionOrderByLoaded(shareScopeMap, scope, pkgName) { | ||
const versions = shareScopeMap[scope][pkgName]; | ||
function findSingletonVersionOrderByLoaded(scope, pkgName) { | ||
const globalShares = Global.__FEDERATION__.__SHARE__; | ||
const versions = globalShares[scope][pkgName]; | ||
const callback = function(prev, cur) { | ||
@@ -715,16 +711,8 @@ if (versions[cur].loaded) { | ||
}; | ||
return findVersion(shareScopeMap, scope, pkgName, callback); | ||
return findVersion(scope, pkgName, callback); | ||
} | ||
function getFindShareFunction(strategy) { | ||
if (strategy === 'loaded-first') { | ||
return findSingletonVersionOrderByLoaded; | ||
} | ||
return findSingletonVersionOrderByVersion; | ||
} | ||
// Details about shared resources | ||
// TODO: Implement strictVersion for alignment with module federation. | ||
function getRegisteredShare(localShareScopeMap, pkgName, shareInfo, resolveShare) { | ||
if (!localShareScopeMap) { | ||
return; | ||
} | ||
function getGlobalShare(pkgName, shareInfo) { | ||
const globalShares = Global.__FEDERATION__.__SHARE__; | ||
const { shareConfig, scope = DEFAULT_SCOPE, strategy } = shareInfo; | ||
@@ -735,39 +723,30 @@ const scopes = Array.isArray(scope) ? scope : [ | ||
for (const sc of scopes){ | ||
if (shareConfig && localShareScopeMap[sc] && localShareScopeMap[sc][pkgName]) { | ||
if (shareConfig && globalShares[sc] && globalShares[sc][pkgName]) { | ||
const { requiredVersion } = shareConfig; | ||
const findShareFunction = getFindShareFunction(strategy); | ||
const maxOrSingletonVersion = findShareFunction(localShareScopeMap, sc, pkgName); | ||
//@ts-ignore | ||
const defaultResolver = ()=>{ | ||
if (shareConfig.singleton) { | ||
if (typeof requiredVersion === 'string' && !satisfy(maxOrSingletonVersion, requiredVersion)) { | ||
const msg = `Version ${maxOrSingletonVersion} from ${maxOrSingletonVersion && localShareScopeMap[sc][pkgName][maxOrSingletonVersion].from} of shared singleton module ${pkgName} does not satisfy the requirement of ${shareInfo.from} which needs ${requiredVersion})`; | ||
if (shareConfig.strictVersion) { | ||
error(msg); | ||
} else { | ||
warn(msg); | ||
} | ||
// eslint-disable-next-line max-depth | ||
if (shareConfig.singleton) { | ||
const singletonVersion = strategy === 'loaded-first' ? findSingletonVersionOrderByLoaded(sc, pkgName) : findSingletonVersionOrderByVersion(sc, pkgName); | ||
// eslint-disable-next-line max-depth | ||
if (typeof requiredVersion === 'string' && !satisfy(singletonVersion, requiredVersion)) { | ||
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})`); | ||
} | ||
return globalShares[sc][pkgName][singletonVersion]; | ||
} else { | ||
const maxVersion = findSingletonVersionOrderByLoaded(sc, pkgName); | ||
// eslint-disable-next-line max-depth | ||
if (requiredVersion === false || requiredVersion === '*') { | ||
return globalShares[sc][pkgName][maxVersion]; | ||
} | ||
// eslint-disable-next-line max-depth | ||
if (satisfy(maxVersion, requiredVersion)) { | ||
return globalShares[sc][pkgName][maxVersion]; | ||
} | ||
// eslint-disable-next-line max-depth | ||
for (const [versionKey, versionValue] of Object.entries(globalShares[sc][pkgName])){ | ||
// eslint-disable-next-line max-depth | ||
if (satisfy(versionKey, requiredVersion)) { | ||
return versionValue; | ||
} | ||
return localShareScopeMap[sc][pkgName][maxOrSingletonVersion]; | ||
} else { | ||
if (requiredVersion === false || requiredVersion === '*') { | ||
return localShareScopeMap[sc][pkgName][maxOrSingletonVersion]; | ||
} | ||
for (const [versionKey, versionValue] of Object.entries(localShareScopeMap[sc][pkgName])){ | ||
if (satisfy(versionKey, requiredVersion)) { | ||
return versionValue; | ||
} | ||
} | ||
} | ||
}; | ||
const params = { | ||
shareScopeMap: localShareScopeMap, | ||
scope: sc, | ||
pkgName, | ||
version: maxOrSingletonVersion, | ||
GlobalFederation: Global.__FEDERATION__, | ||
resolver: defaultResolver | ||
}; | ||
const resolveShared = resolveShare.emit(params) || params; | ||
return resolveShared.resolver(); | ||
} | ||
} | ||
@@ -793,2 +772,3 @@ } | ||
exports.getGlobalHostPlugins = getGlobalHostPlugins; | ||
exports.getGlobalShare = getGlobalShare; | ||
exports.getGlobalShareScope = getGlobalShareScope; | ||
@@ -799,3 +779,2 @@ exports.getGlobalSnapshot = getGlobalSnapshot; | ||
exports.getPreloaded = getPreloaded; | ||
exports.getRegisteredShare = getRegisteredShare; | ||
exports.getRemoteEntryExports = getRemoteEntryExports; | ||
@@ -802,0 +781,0 @@ exports.getTargetSnapshotInfoByModuleInfo = getTargetSnapshotInfoByModuleInfo; |
function getBuilderId() { | ||
//@ts-ignore | ||
return typeof FEDERATION_BUILD_IDENTIFIER !== 'undefined' ? FEDERATION_BUILD_IDENTIFIER : ''; | ||
@@ -45,3 +44,3 @@ } | ||
function isPureRemoteEntry(remote) { | ||
return remote.entry.endsWith('.js'); | ||
return !remote.entry.includes('.json') && remote.entry.includes('.js'); | ||
} | ||
@@ -91,5 +90,5 @@ // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types | ||
} | ||
var _nativeGlobal___FEDERATION__, _nativeGlobal___FEDERATION__1, _nativeGlobal___FEDERATION__2, _nativeGlobal___FEDERATION__3, _nativeGlobal___FEDERATION__4, _nativeGlobal___FEDERATION__5; | ||
// export const nativeGlobal: typeof global = new Function('return this')(); | ||
const nativeGlobal = new Function('return this')(); | ||
const Global = nativeGlobal; | ||
// This section is to prevent encapsulation by certain microfrontend frameworks. Due to reuse policies, sandbox escapes. | ||
@@ -105,44 +104,56 @@ // The sandbox in the microfrontend does not replicate the value of 'configurable'. | ||
const globalLoading = globalThis.__GLOBAL_LOADING_REMOTE_ENTRY__; | ||
// | ||
if (nativeGlobal.__VMOK__) { | ||
nativeGlobal.__FEDERATION__ = nativeGlobal.__VMOK__; | ||
} else if (!nativeGlobal.__FEDERATION__) { | ||
nativeGlobal.__FEDERATION__ = { | ||
__GLOBAL_PLUGIN__: [], | ||
__INSTANCES__: [], | ||
moduleInfo: {}, | ||
__SHARE__: {}, | ||
__MANIFEST_LOADING__: {}, | ||
__PRELOADED_MAP__: new Map() | ||
}; | ||
nativeGlobal.__VMOK__ = nativeGlobal.__FEDERATION__; | ||
function setGlobalDefaultVal(target) { | ||
var _target___FEDERATION__, _target___FEDERATION__1, _target___FEDERATION__2, _target___FEDERATION__3, _target___FEDERATION__4, _target___FEDERATION__5, _target___FEDERATION__6; | ||
if (Object.hasOwnProperty.call(target, '__VMOK__')) { | ||
Object.defineProperty(target, '__FEDERATION__', { | ||
value: target.__VMOK__, | ||
configurable: false | ||
}); | ||
} | ||
if (!Object.hasOwnProperty.call(target, '__FEDERATION__')) { | ||
Object.defineProperty(target, '__FEDERATION__', { | ||
value: { | ||
__GLOBAL_PLUGIN__: [], | ||
__INSTANCES__: [], | ||
moduleInfo: {}, | ||
__SHARE__: {}, | ||
__MANIFEST_LOADING__: {}, | ||
__SHARE_SCOPE_LOADING__: {}, | ||
__PRELOADED_MAP__: new Map() | ||
}, | ||
configurable: false | ||
}); | ||
Object.defineProperty(target, '__VMOK__', { | ||
value: target.__FEDERATION__, | ||
configurable: false | ||
}); | ||
} | ||
var ___GLOBAL_PLUGIN__; | ||
(___GLOBAL_PLUGIN__ = (_target___FEDERATION__ = target.__FEDERATION__).__GLOBAL_PLUGIN__) != null ? ___GLOBAL_PLUGIN__ : _target___FEDERATION__.__GLOBAL_PLUGIN__ = []; | ||
var ___INSTANCES__; | ||
(___INSTANCES__ = (_target___FEDERATION__1 = target.__FEDERATION__).__INSTANCES__) != null ? ___INSTANCES__ : _target___FEDERATION__1.__INSTANCES__ = []; | ||
var _moduleInfo; | ||
(_moduleInfo = (_target___FEDERATION__2 = target.__FEDERATION__).moduleInfo) != null ? _moduleInfo : _target___FEDERATION__2.moduleInfo = {}; | ||
var ___SHARE__; | ||
(___SHARE__ = (_target___FEDERATION__3 = target.__FEDERATION__).__SHARE__) != null ? ___SHARE__ : _target___FEDERATION__3.__SHARE__ = {}; | ||
var ___MANIFEST_LOADING__; | ||
(___MANIFEST_LOADING__ = (_target___FEDERATION__4 = target.__FEDERATION__).__MANIFEST_LOADING__) != null ? ___MANIFEST_LOADING__ : _target___FEDERATION__4.__MANIFEST_LOADING__ = {}; | ||
var ___SHARE_SCOPE_LOADING__; | ||
(___SHARE_SCOPE_LOADING__ = (_target___FEDERATION__5 = target.__FEDERATION__).__SHARE_SCOPE_LOADING__) != null ? ___SHARE_SCOPE_LOADING__ : _target___FEDERATION__5.__SHARE_SCOPE_LOADING__ = {}; | ||
var ___PRELOADED_MAP__; | ||
(___PRELOADED_MAP__ = (_target___FEDERATION__6 = target.__FEDERATION__).__PRELOADED_MAP__) != null ? ___PRELOADED_MAP__ : _target___FEDERATION__6.__PRELOADED_MAP__ = new Map(); | ||
} | ||
var ___GLOBAL_PLUGIN__; | ||
(___GLOBAL_PLUGIN__ = (_nativeGlobal___FEDERATION__ = nativeGlobal.__FEDERATION__).__GLOBAL_PLUGIN__) != null ? ___GLOBAL_PLUGIN__ : _nativeGlobal___FEDERATION__.__GLOBAL_PLUGIN__ = []; | ||
var ___INSTANCES__; | ||
(___INSTANCES__ = (_nativeGlobal___FEDERATION__1 = nativeGlobal.__FEDERATION__).__INSTANCES__) != null ? ___INSTANCES__ : _nativeGlobal___FEDERATION__1.__INSTANCES__ = []; | ||
var _moduleInfo; | ||
(_moduleInfo = (_nativeGlobal___FEDERATION__2 = nativeGlobal.__FEDERATION__).moduleInfo) != null ? _moduleInfo : _nativeGlobal___FEDERATION__2.moduleInfo = {}; | ||
var ___SHARE__; | ||
(___SHARE__ = (_nativeGlobal___FEDERATION__3 = nativeGlobal.__FEDERATION__).__SHARE__) != null ? ___SHARE__ : _nativeGlobal___FEDERATION__3.__SHARE__ = {}; | ||
var ___MANIFEST_LOADING__; | ||
(___MANIFEST_LOADING__ = (_nativeGlobal___FEDERATION__4 = nativeGlobal.__FEDERATION__).__MANIFEST_LOADING__) != null ? ___MANIFEST_LOADING__ : _nativeGlobal___FEDERATION__4.__MANIFEST_LOADING__ = {}; | ||
var ___PRELOADED_MAP__; | ||
(___PRELOADED_MAP__ = (_nativeGlobal___FEDERATION__5 = nativeGlobal.__FEDERATION__).__PRELOADED_MAP__) != null ? ___PRELOADED_MAP__ : _nativeGlobal___FEDERATION__5.__PRELOADED_MAP__ = new Map(); | ||
const Global = { | ||
get __FEDERATION__ () { | ||
const globalThisVal = new Function('return globalThis')(); | ||
return globalThisVal.__FEDERATION__; | ||
} | ||
}; | ||
setGlobalDefaultVal(globalThis); | ||
setGlobalDefaultVal(nativeGlobal); | ||
function resetFederationGlobalInfo() { | ||
nativeGlobal.__FEDERATION__.__GLOBAL_PLUGIN__ = []; | ||
nativeGlobal.__FEDERATION__.__INSTANCES__ = []; | ||
nativeGlobal.__FEDERATION__.moduleInfo = {}; | ||
nativeGlobal.__FEDERATION__.__SHARE__ = {}; | ||
nativeGlobal.__FEDERATION__.__MANIFEST_LOADING__ = {}; | ||
globalThis.__FEDERATION__.__GLOBAL_PLUGIN__ = []; | ||
globalThis.__FEDERATION__.__INSTANCES__ = []; | ||
globalThis.__FEDERATION__.moduleInfo = {}; | ||
globalThis.__FEDERATION__.__SHARE__ = {}; | ||
globalThis.__FEDERATION__.__MANIFEST_LOADING__ = {}; | ||
globalThis.__FEDERATION__.__SHARE_SCOPE_LOADING__ = {}; | ||
} | ||
function getGlobalFederationInstance(name, version) { | ||
const buildId = getBuilderId(); | ||
return Global.__FEDERATION__.__INSTANCES__.find((GMInstance)=>{ | ||
return globalThis.__FEDERATION__.__INSTANCES__.find((GMInstance)=>{ | ||
if (buildId && GMInstance.options.id === getBuilderId()) { | ||
@@ -161,11 +172,11 @@ return true; | ||
function setGlobalFederationInstance(FederationInstance) { | ||
Global.__FEDERATION__.__INSTANCES__.push(FederationInstance); | ||
globalThis.__FEDERATION__.__INSTANCES__.push(FederationInstance); | ||
} | ||
function getGlobalFederationConstructor() { | ||
return Global.__FEDERATION__.__DEBUG_CONSTRUCTOR__; | ||
return globalThis.__FEDERATION__.__DEBUG_CONSTRUCTOR__; | ||
} | ||
function setGlobalFederationConstructor(FederationConstructor) { | ||
if (isDebugMode()) { | ||
Global.__FEDERATION__.__DEBUG_CONSTRUCTOR__ = FederationConstructor; | ||
Global.__FEDERATION__.__DEBUG_CONSTRUCTOR_VERSION__ = '0.0.4'; | ||
globalThis.__FEDERATION__.__DEBUG_CONSTRUCTOR__ = FederationConstructor; | ||
globalThis.__FEDERATION__.__DEBUG_CONSTRUCTOR_VERSION__ = '0.0.4'; | ||
} | ||
@@ -185,3 +196,3 @@ } | ||
} | ||
const getGlobalSnapshot = ()=>Global.__FEDERATION__.moduleInfo; | ||
const getGlobalSnapshot = ()=>nativeGlobal.__FEDERATION__.moduleInfo; | ||
const getTargetSnapshotInfoByModuleInfo = (moduleInfo, snapshot, getModuleInfoHook)=>{ | ||
@@ -204,3 +215,3 @@ // Check if the remote is included in the hostSnapshot | ||
const moduleKeyWithoutVersion = getFMId(resModuleInfo); | ||
const getModuleInfoWithoutVersion = getInfoWithoutType(Global.__FEDERATION__.moduleInfo, moduleKeyWithoutVersion, getModuleInfoHook).value; | ||
const getModuleInfoWithoutVersion = getInfoWithoutType(nativeGlobal.__FEDERATION__.moduleInfo, moduleKeyWithoutVersion, getModuleInfoHook).value; | ||
if ((getModuleInfoWithoutVersion == null ? void 0 : getModuleInfoWithoutVersion.version) === version) { | ||
@@ -212,14 +223,14 @@ return getModuleInfoWithoutVersion; | ||
}; | ||
const getGlobalSnapshotInfoByModuleInfo = (moduleInfo, extraOptions)=>getTargetSnapshotInfoByModuleInfo(moduleInfo, Global.__FEDERATION__.moduleInfo, extraOptions == null ? void 0 : extraOptions.getModuleInfoHook); | ||
const getGlobalSnapshotInfoByModuleInfo = (moduleInfo, extraOptions)=>getTargetSnapshotInfoByModuleInfo(moduleInfo, nativeGlobal.__FEDERATION__.moduleInfo, extraOptions == null ? void 0 : extraOptions.getModuleInfoHook); | ||
const setGlobalSnapshotInfoByModuleInfo = (remoteInfo, moduleDetailInfo)=>{ | ||
const moduleKey = getFMId(remoteInfo); | ||
Global.__FEDERATION__.moduleInfo[moduleKey] = moduleDetailInfo; | ||
return Global.__FEDERATION__.moduleInfo; | ||
nativeGlobal.__FEDERATION__.moduleInfo[moduleKey] = moduleDetailInfo; | ||
return nativeGlobal.__FEDERATION__.moduleInfo; | ||
}; | ||
const addGlobalSnapshot = (moduleInfos)=>{ | ||
Global.__FEDERATION__.moduleInfo = _extends$1({}, Global.__FEDERATION__.moduleInfo, moduleInfos); | ||
nativeGlobal.__FEDERATION__.moduleInfo = _extends$1({}, nativeGlobal.__FEDERATION__.moduleInfo, moduleInfos); | ||
return ()=>{ | ||
const keys = Object.keys(moduleInfos); | ||
for (const key of keys){ | ||
delete Global.__FEDERATION__.moduleInfo[key]; | ||
delete nativeGlobal.__FEDERATION__.moduleInfo[key]; | ||
} | ||
@@ -241,3 +252,3 @@ }; | ||
const registerGlobalPlugins = (plugins)=>{ | ||
const { __GLOBAL_PLUGIN__ } = Global.__FEDERATION__; | ||
const { __GLOBAL_PLUGIN__ } = nativeGlobal.__FEDERATION__; | ||
plugins.forEach((plugin)=>{ | ||
@@ -251,5 +262,5 @@ if (__GLOBAL_PLUGIN__.findIndex((p)=>p.name === plugin.name) === -1) { | ||
}; | ||
const getGlobalHostPlugins = ()=>Global.__FEDERATION__.__GLOBAL_PLUGIN__; | ||
const getPreloaded = (id)=>Global.__FEDERATION__.__PRELOADED_MAP__.get(id); | ||
const setPreloaded = (id)=>Global.__FEDERATION__.__PRELOADED_MAP__.set(id, true); | ||
const getGlobalHostPlugins = ()=>nativeGlobal.__FEDERATION__.__GLOBAL_PLUGIN__; | ||
const getPreloaded = (id)=>globalThis.__FEDERATION__.__PRELOADED_MAP__.get(id); | ||
const setPreloaded = (id)=>globalThis.__FEDERATION__.__PRELOADED_MAP__.set(id, true); | ||
@@ -624,12 +635,10 @@ const DEFAULT_SCOPE = 'default'; | ||
from, | ||
shareConfig: { | ||
requiredVersion: `^${shareArgs.version}`, | ||
singleton: false, | ||
eager: false | ||
}, | ||
loading: null | ||
}, shareArgs, { | ||
shareConfig: _extends({ | ||
requiredVersion: `^${shareArgs.version}`, | ||
singleton: false, | ||
eager: false, | ||
strictVersion: false | ||
}, shareArgs.shareConfig), | ||
get, | ||
loaded: 'lib' in shareArgs ? true : undefined, | ||
scope: Array.isArray(shareArgs.scope) ? shareArgs.scope : [ | ||
@@ -651,15 +660,3 @@ 'default' | ||
function versionLt(a, b) { | ||
const transformInvalidVersion = (version)=>{ | ||
const isNumberVersion = !Number.isNaN(Number(version)); | ||
if (isNumberVersion) { | ||
const splitArr = version.split('.'); | ||
let validVersion = version; | ||
for(let i = 0; i < 3 - splitArr.length; i++){ | ||
validVersion += '.0'; | ||
} | ||
return validVersion; | ||
} | ||
return version; | ||
}; | ||
if (satisfy(transformInvalidVersion(a), `<=${transformInvalidVersion(b)}`)) { | ||
if (satisfy(a, `<=${b}`)) { | ||
return true; | ||
@@ -670,4 +667,5 @@ } else { | ||
} | ||
const findVersion = (shareScopeMap, scope, pkgName, cb)=>{ | ||
const versions = shareScopeMap[scope][pkgName]; | ||
const findVersion = (scope, pkgName, cb)=>{ | ||
const globalShares = Global.__FEDERATION__.__SHARE__; | ||
const versions = globalShares[scope][pkgName]; | ||
const callback = cb || function(prev, cur) { | ||
@@ -683,18 +681,16 @@ return versionLt(prev, cur); | ||
} | ||
// default version is '0' https://github.com/webpack/webpack/blob/main/lib/sharing/ProvideSharedModule.js#L136 | ||
if (prev === '0') { | ||
return cur; | ||
} | ||
return prev; | ||
}, 0); | ||
}; | ||
function findSingletonVersionOrderByVersion(shareScopeMap, scope, pkgName) { | ||
const versions = shareScopeMap[scope][pkgName]; | ||
function findSingletonVersionOrderByVersion(scope, pkgName) { | ||
const globalShares = Global.__FEDERATION__.__SHARE__; | ||
const versions = globalShares[scope][pkgName]; | ||
const callback = function(prev, cur) { | ||
return !versions[prev].loaded && versionLt(prev, cur); | ||
}; | ||
return findVersion(shareScopeMap, scope, pkgName, callback); | ||
return findVersion(scope, pkgName, callback); | ||
} | ||
function findSingletonVersionOrderByLoaded(shareScopeMap, scope, pkgName) { | ||
const versions = shareScopeMap[scope][pkgName]; | ||
function findSingletonVersionOrderByLoaded(scope, pkgName) { | ||
const globalShares = Global.__FEDERATION__.__SHARE__; | ||
const versions = globalShares[scope][pkgName]; | ||
const callback = function(prev, cur) { | ||
@@ -713,16 +709,8 @@ if (versions[cur].loaded) { | ||
}; | ||
return findVersion(shareScopeMap, scope, pkgName, callback); | ||
return findVersion(scope, pkgName, callback); | ||
} | ||
function getFindShareFunction(strategy) { | ||
if (strategy === 'loaded-first') { | ||
return findSingletonVersionOrderByLoaded; | ||
} | ||
return findSingletonVersionOrderByVersion; | ||
} | ||
// Details about shared resources | ||
// TODO: Implement strictVersion for alignment with module federation. | ||
function getRegisteredShare(localShareScopeMap, pkgName, shareInfo, resolveShare) { | ||
if (!localShareScopeMap) { | ||
return; | ||
} | ||
function getGlobalShare(pkgName, shareInfo) { | ||
const globalShares = Global.__FEDERATION__.__SHARE__; | ||
const { shareConfig, scope = DEFAULT_SCOPE, strategy } = shareInfo; | ||
@@ -733,39 +721,30 @@ const scopes = Array.isArray(scope) ? scope : [ | ||
for (const sc of scopes){ | ||
if (shareConfig && localShareScopeMap[sc] && localShareScopeMap[sc][pkgName]) { | ||
if (shareConfig && globalShares[sc] && globalShares[sc][pkgName]) { | ||
const { requiredVersion } = shareConfig; | ||
const findShareFunction = getFindShareFunction(strategy); | ||
const maxOrSingletonVersion = findShareFunction(localShareScopeMap, sc, pkgName); | ||
//@ts-ignore | ||
const defaultResolver = ()=>{ | ||
if (shareConfig.singleton) { | ||
if (typeof requiredVersion === 'string' && !satisfy(maxOrSingletonVersion, requiredVersion)) { | ||
const msg = `Version ${maxOrSingletonVersion} from ${maxOrSingletonVersion && localShareScopeMap[sc][pkgName][maxOrSingletonVersion].from} of shared singleton module ${pkgName} does not satisfy the requirement of ${shareInfo.from} which needs ${requiredVersion})`; | ||
if (shareConfig.strictVersion) { | ||
error(msg); | ||
} else { | ||
warn(msg); | ||
} | ||
// eslint-disable-next-line max-depth | ||
if (shareConfig.singleton) { | ||
const singletonVersion = strategy === 'loaded-first' ? findSingletonVersionOrderByLoaded(sc, pkgName) : findSingletonVersionOrderByVersion(sc, pkgName); | ||
// eslint-disable-next-line max-depth | ||
if (typeof requiredVersion === 'string' && !satisfy(singletonVersion, requiredVersion)) { | ||
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})`); | ||
} | ||
return globalShares[sc][pkgName][singletonVersion]; | ||
} else { | ||
const maxVersion = findSingletonVersionOrderByLoaded(sc, pkgName); | ||
// eslint-disable-next-line max-depth | ||
if (requiredVersion === false || requiredVersion === '*') { | ||
return globalShares[sc][pkgName][maxVersion]; | ||
} | ||
// eslint-disable-next-line max-depth | ||
if (satisfy(maxVersion, requiredVersion)) { | ||
return globalShares[sc][pkgName][maxVersion]; | ||
} | ||
// eslint-disable-next-line max-depth | ||
for (const [versionKey, versionValue] of Object.entries(globalShares[sc][pkgName])){ | ||
// eslint-disable-next-line max-depth | ||
if (satisfy(versionKey, requiredVersion)) { | ||
return versionValue; | ||
} | ||
return localShareScopeMap[sc][pkgName][maxOrSingletonVersion]; | ||
} else { | ||
if (requiredVersion === false || requiredVersion === '*') { | ||
return localShareScopeMap[sc][pkgName][maxOrSingletonVersion]; | ||
} | ||
for (const [versionKey, versionValue] of Object.entries(localShareScopeMap[sc][pkgName])){ | ||
if (satisfy(versionKey, requiredVersion)) { | ||
return versionValue; | ||
} | ||
} | ||
} | ||
}; | ||
const params = { | ||
shareScopeMap: localShareScopeMap, | ||
scope: sc, | ||
pkgName, | ||
version: maxOrSingletonVersion, | ||
GlobalFederation: Global.__FEDERATION__, | ||
resolver: defaultResolver | ||
}; | ||
const resolveShared = resolveShare.emit(params) || params; | ||
return resolveShared.resolver(); | ||
} | ||
} | ||
@@ -778,2 +757,2 @@ } | ||
export { getGlobalFederationInstance as A, getGlobalFederationConstructor as B, setGlobalFederationInstance as C, DEFAULT_REMOTE_TYPE as D, registerGlobalPlugins as E, nativeGlobal as F, Global as G, resetFederationGlobalInfo as H, getTargetSnapshotInfoByModuleInfo as I, addGlobalSnapshot as J, DEFAULT_SCOPE as a, globalLoading 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, setGlobalSnapshotInfoByModuleInfo as q, getGlobalSnapshot as r, safeToString as s, getGlobalShareScope as t, addUniqueItem as u, formatShareConfigs as v, warn as w, isBrowserEnv as x, getBuilderId as y, setGlobalFederationConstructor as z }; | ||
export { getGlobalFederationInstance as A, getGlobalFederationConstructor as B, setGlobalFederationInstance as C, DEFAULT_REMOTE_TYPE as D, registerGlobalPlugins as E, nativeGlobal as F, Global as G, resetFederationGlobalInfo as H, getTargetSnapshotInfoByModuleInfo as I, addGlobalSnapshot as J, DEFAULT_SCOPE as a, globalLoading 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, getGlobalShare as l, getInfoWithoutType as m, getPreloaded as n, setPreloaded as o, getGlobalSnapshotInfoByModuleInfo as p, setGlobalSnapshotInfoByModuleInfo as q, getGlobalSnapshot as r, safeToString as s, addUniqueItem as t, formatShareConfigs as u, isBrowserEnv as v, warn as w, getGlobalShareScope as x, getBuilderId as y, setGlobalFederationConstructor as z }; |
import type { ModuleInfo, GlobalModuleInfo } from '@module-federation/sdk'; | ||
import { Options, PreloadAssets, PreloadOptions, PreloadRemoteArgs, Remote, Shared, ShareInfos, UserOptions, RemoteInfo, ShareScopeMap } from './type'; | ||
import { Options, PreloadAssets, PreloadOptions, PreloadRemoteArgs, Remote, Shared, ShareInfos, UserOptions, RemoteInfo } from './type'; | ||
import { Module, ModuleOptions } from './module'; | ||
import { AsyncHook, AsyncWaterfallHook, PluginSystem, SyncHook, SyncWaterfallHook } from './utils/hooks'; | ||
import { Federation } from './global'; | ||
import { SnapshotHandler } from './plugins/snapshot/SnapshotHandler'; | ||
@@ -56,4 +55,2 @@ interface LoadRemoteMatch { | ||
error: unknown; | ||
from: 'build' | 'runtime'; | ||
origin: FederationHost; | ||
}], void>; | ||
@@ -67,10 +64,2 @@ beforeLoadShare: AsyncWaterfallHook<{ | ||
loadShare: AsyncHook<[FederationHost, string, ShareInfos], false | void | Promise<false | void>>; | ||
resolveShare: SyncWaterfallHook<{ | ||
shareScopeMap: ShareScopeMap; | ||
scope: string; | ||
pkgName: string; | ||
version: string; | ||
GlobalFederation: Federation; | ||
resolver: () => Shared | undefined; | ||
}>; | ||
beforePreloadRemote: AsyncHook<{ | ||
@@ -95,3 +84,2 @@ preloadOps: Array<PreloadRemoteArgs>; | ||
}>; | ||
releaseNumber: string; | ||
version: string; | ||
@@ -101,3 +89,2 @@ name: string; | ||
snapshotHandler: SnapshotHandler; | ||
shareScopeMap: ShareScopeMap; | ||
loaderHook: PluginSystem<{ | ||
@@ -116,4 +103,6 @@ getModuleInfo: SyncHook<[{ | ||
}>; | ||
loadingShare: { | ||
[key: string]: Promise<any>; | ||
}; | ||
constructor(userOptions: UserOptions); | ||
private _setGlobalShareScopeMap; | ||
initOptions(userOptions: UserOptions): Options; | ||
@@ -125,3 +114,2 @@ loadShare<T>(pkgName: string, customShareInfo?: Partial<Shared>): Promise<false | (() => T | undefined)>; | ||
loadFactory?: boolean; | ||
from: 'build' | 'runtime'; | ||
}): Promise<T | null>; | ||
@@ -134,4 +122,3 @@ preloadRemote(preloadOptions: Array<PreloadRemoteArgs>): Promise<void>; | ||
*/ | ||
initializeSharing(shareScopeName?: string, strategy?: Shared['strategy']): Array<Promise<void>>; | ||
initShareScopeMap(scopeName: string, shareScope: ShareScopeMap[string]): void; | ||
initializeSharing(shareScopeName?: string): boolean | Promise<boolean>; | ||
private formatOptions; | ||
@@ -138,0 +125,0 @@ private registerPlugins; |
/// <reference types="node" /> | ||
import { FederationHost } from './core'; | ||
import { RemoteEntryExports, GlobalShareScopeMap, Remote, Optional } from './type'; | ||
import { RemoteEntryExports, GlobalShareScope, Remote, Optional } from './type'; | ||
import { GlobalModuleInfo, ModuleInfo } from '@module-federation/sdk'; | ||
@@ -12,7 +12,9 @@ import { FederationRuntimePlugin } from './type/plugin'; | ||
__INSTANCES__: Array<FederationHost>; | ||
__SHARE__: GlobalShareScopeMap; | ||
__SHARE__: GlobalShareScope; | ||
__MANIFEST_LOADING__: Record<string, Promise<ModuleInfo>>; | ||
__SHARE_SCOPE_LOADING__: Record<string, boolean | Promise<boolean>>; | ||
__PRELOADED_MAP__: Map<string, boolean>; | ||
} | ||
export declare const nativeGlobal: typeof global; | ||
export declare const Global: typeof globalThis; | ||
declare global { | ||
@@ -22,5 +24,2 @@ var __FEDERATION__: Federation, __VMOK__: Federation, __GLOBAL_LOADING_REMOTE_ENTRY__: Record<string, undefined | Promise<RemoteEntryExports | void>>; | ||
export declare const globalLoading: Record<string, Promise<void | RemoteEntryExports> | undefined>; | ||
export declare const Global: { | ||
readonly __FEDERATION__: Federation; | ||
}; | ||
export declare function resetFederationGlobalInfo(): void; | ||
@@ -27,0 +26,0 @@ export declare function getGlobalFederationInstance(name: string, version: string | undefined): FederationHost | undefined; |
/// <reference types="node" /> | ||
import { resetFederationGlobalInfo, getGlobalFederationInstance, setGlobalFederationInstance, getGlobalFederationConstructor, setGlobalFederationConstructor, getInfoWithoutType, getGlobalSnapshot, getTargetSnapshotInfoByModuleInfo, getGlobalSnapshotInfoByModuleInfo, setGlobalSnapshotInfoByModuleInfo, addGlobalSnapshot, getRemoteEntryExports, registerGlobalPlugins, getGlobalHostPlugins, getPreloaded, setPreloaded } from './global'; | ||
import { getRegisteredShare, getGlobalShareScope } from './utils/share'; | ||
import { getGlobalShare, getGlobalShareScope } from './utils/share'; | ||
interface IShareUtils { | ||
getRegisteredShare: typeof getRegisteredShare; | ||
getGlobalShare: typeof getGlobalShare; | ||
getGlobalShareScope: typeof getGlobalShareScope; | ||
@@ -7,0 +7,0 @@ } |
@@ -5,3 +5,2 @@ import { FederationHost } from './core'; | ||
export { registerGlobalPlugins } from './global'; | ||
export { loadScript } from '@module-federation/sdk'; | ||
export type { Federation } from './global'; | ||
@@ -8,0 +7,0 @@ export declare function init(options: UserOptions): FederationHost; |
import { FederationHost } from '../core'; | ||
import { RemoteEntryExports, Options, Remote, ShareInfos, RemoteInfo, ShareScopeMap } from '../type'; | ||
import { RemoteEntryExports, Options, Remote, ShareInfos, RemoteInfo } from '../type'; | ||
export type ModuleOptions = ConstructorParameters<typeof Module>[0]; | ||
@@ -13,4 +13,3 @@ type HostInfo = Remote; | ||
loaderHook: FederationHost['loaderHook']; | ||
shareScopeMap: ShareScopeMap; | ||
constructor({ hostInfo, remoteInfo, shared, loaderHook, shareScopeMap, }: { | ||
constructor({ hostInfo, remoteInfo, shared, loaderHook, }: { | ||
hostInfo: HostInfo; | ||
@@ -21,3 +20,2 @@ remoteInfo: RemoteInfo; | ||
loaderHook: FederationHost['loaderHook']; | ||
shareScopeMap: ShareScopeMap; | ||
}); | ||
@@ -24,0 +22,0 @@ getEntry(): Promise<RemoteEntryExports>; |
@@ -32,3 +32,2 @@ import type { RemoteWithEntry, RemoteWithVersion, Module, RemoteEntryType } from '@module-federation/sdk'; | ||
eager?: boolean; | ||
strictVersion?: boolean; | ||
} | ||
@@ -62,3 +61,3 @@ type SharedBaseArgs = { | ||
}; | ||
export type ShareScopeMap = { | ||
export type GlobalShareScope = { | ||
[scope: string]: { | ||
@@ -70,5 +69,2 @@ [pkgName: string]: { | ||
}; | ||
export type GlobalShareScopeMap = { | ||
[instanceName: string]: ShareScopeMap; | ||
}; | ||
export type ShareInfos = { | ||
@@ -99,4 +95,4 @@ [pkgName: string]: Shared; | ||
get: (id: string) => () => Promise<Module>; | ||
init: (shareScope: ShareScopeMap[string], initScope?: Array<Record<string, any>>, remoteEntryInitOPtions?: RemoteEntryInitOptions) => void; | ||
init: (shareScope: GlobalShareScope[string], initScope?: Array<Record<string, never>>, remoteEntryInitOPtions?: RemoteEntryInitOptions) => void; | ||
}; | ||
export {}; |
@@ -1,4 +0,2 @@ | ||
import { Federation } from '../global'; | ||
import { GlobalShareScopeMap, Shared, ShareArgs, ShareInfos, ShareScopeMap } from '../type'; | ||
import { SyncWaterfallHook } from './hooks'; | ||
import { GlobalShareScope, Shared, ShareArgs, ShareInfos } from '../type'; | ||
export declare function formatShare(shareArgs: ShareArgs, from: string): Shared; | ||
@@ -8,10 +6,3 @@ export declare function formatShareConfigs(shareArgs: { | ||
}, from: string): ShareInfos; | ||
export declare function getRegisteredShare(localShareScopeMap: ShareScopeMap, pkgName: string, shareInfo: ShareInfos[keyof ShareInfos], resolveShare: SyncWaterfallHook<{ | ||
shareScopeMap: ShareScopeMap; | ||
scope: string; | ||
pkgName: string; | ||
version: string; | ||
GlobalFederation: Federation; | ||
resolver: () => Shared | undefined; | ||
}>): Shared | void; | ||
export declare function getGlobalShareScope(): GlobalShareScopeMap; | ||
export declare function getGlobalShare(pkgName: string, shareInfo: ShareInfos[keyof ShareInfos]): Shared | void; | ||
export declare function getGlobalShareScope(): GlobalShareScope; |
{ | ||
"name": "@module-federation/runtime", | ||
"version": "0.0.0-next-20231228055514", | ||
"version": "0.0.0-next-20231229025030", | ||
"author": "zhouxiao <codingzx@gmail.com>", | ||
@@ -42,4 +42,4 @@ "main": "./dist/index.cjs", | ||
], | ||
"types": [ | ||
"./dist/types.cjs.d.ts" | ||
"type": [ | ||
"./dist/type.cjs.d.ts" | ||
] | ||
@@ -49,4 +49,4 @@ } | ||
"dependencies": { | ||
"@module-federation/sdk": "0.0.0-next-20231228055514" | ||
"@module-federation/sdk": "0.0.0-next-20231229025030" | ||
} | ||
} |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
237832
5380
+ Added@module-federation/sdk@0.0.0-next-20231229025030(transitive)
- Removed@module-federation/sdk@0.0.0-next-20231228055514(transitive)