@module-federation/runtime
Advanced tools
Comparing version 0.0.0-next-20240830100524 to 0.0.0-next-20240902023803
'use strict'; | ||
var share = require('./share.cjs.js'); | ||
require('@swc/helpers/_/_extends'); | ||
require('@swc/helpers/_/_object_without_properties_loose'); | ||
require('@module-federation/sdk'); | ||
var pluginHelper = /*#__PURE__*/Object.freeze({ | ||
__proto__: null, | ||
SyncHook: share.SyncHook, | ||
AsyncHook: share.AsyncHook, | ||
SyncWaterfallHook: share.SyncWaterfallHook, | ||
AsyncWaterfallHook: share.AsyncWaterfallHook, | ||
PluginSystem: share.PluginSystem | ||
}); | ||
const ShareUtils = { | ||
@@ -37,5 +30,3 @@ getRegisteredShare: share.getRegisteredShare, | ||
getPreloaded: share.getPreloaded, | ||
setPreloaded: share.setPreloaded, | ||
registerPlugins: share.registerPlugins, | ||
pluginHelper | ||
setPreloaded: share.setPreloaded | ||
}; | ||
@@ -42,0 +33,0 @@ var helpers = { |
@@ -1,13 +0,6 @@ | ||
import { z as SyncHook, A as AsyncHook, S as SyncWaterfallHook, t as AsyncWaterfallHook, P as PluginSystem, n as getRegisteredShare, x as getGlobalShareScope, G as Global, K as nativeGlobal, L as resetFederationGlobalInfo, F as getGlobalFederationInstance, I as setGlobalFederationInstance, H as getGlobalFederationConstructor, E as setGlobalFederationConstructor, k as getInfoWithoutType, u as getGlobalSnapshot, M as getTargetSnapshotInfoByModuleInfo, p as getGlobalSnapshotInfoByModuleInfo, r as setGlobalSnapshotInfoByModuleInfo, q as addGlobalSnapshot, b as getRemoteEntryExports, J as registerGlobalPlugins, N as getGlobalHostPlugins, l as getPreloaded, m as setPreloaded, B as registerPlugins } from './share.esm.js'; | ||
import { o as getRegisteredShare, y as getGlobalShareScope, G as Global, I as nativeGlobal, J as resetFederationGlobalInfo, C as getGlobalFederationInstance, F as setGlobalFederationInstance, E as getGlobalFederationConstructor, B as setGlobalFederationConstructor, m as getInfoWithoutType, u as getGlobalSnapshot, K as getTargetSnapshotInfoByModuleInfo, q as getGlobalSnapshotInfoByModuleInfo, t as setGlobalSnapshotInfoByModuleInfo, r as addGlobalSnapshot, c as getRemoteEntryExports, H as registerGlobalPlugins, g as getGlobalHostPlugins, n as getPreloaded, s as setPreloaded } from './share.esm.js'; | ||
import '@swc/helpers/_/_extends'; | ||
import '@swc/helpers/_/_object_without_properties_loose'; | ||
import '@module-federation/sdk'; | ||
var pluginHelper = /*#__PURE__*/Object.freeze({ | ||
__proto__: null, | ||
SyncHook: SyncHook, | ||
AsyncHook: AsyncHook, | ||
SyncWaterfallHook: SyncWaterfallHook, | ||
AsyncWaterfallHook: AsyncWaterfallHook, | ||
PluginSystem: PluginSystem | ||
}); | ||
const ShareUtils = { | ||
@@ -35,5 +28,3 @@ getRegisteredShare, | ||
getPreloaded, | ||
setPreloaded, | ||
registerPlugins, | ||
pluginHelper | ||
setPreloaded | ||
}; | ||
@@ -40,0 +31,0 @@ var helpers = { |
{ | ||
"name": "@module-federation/runtime", | ||
"version": "0.5.1", | ||
"version": "0.6.0", | ||
"author": "zhouxiao <codingzx@gmail.com>", | ||
@@ -37,2 +37,7 @@ "main": "./index.cjs.js", | ||
}, | ||
"./embedded": { | ||
"types": "./dist/embedded.cjs.d.ts", | ||
"import": "./dist/embedded.esm.js", | ||
"require": "./dist/embedded.cjs.js" | ||
}, | ||
"./*": "./*" | ||
@@ -39,0 +44,0 @@ }, |
'use strict'; | ||
function _extends() { | ||
_extends = Object.assign || function(target) { | ||
for(var i = 1; i < arguments.length; i++){ | ||
var source = arguments[i]; | ||
for(var key in source){ | ||
if (Object.prototype.hasOwnProperty.call(source, key)) { | ||
target[key] = source[key]; | ||
} | ||
} | ||
} | ||
return target; | ||
}; | ||
return _extends.apply(this, arguments); | ||
} | ||
var _extends = require('@swc/helpers/_/_extends'); | ||
const defaultRetries = 3; | ||
@@ -61,3 +49,3 @@ async function fetchWithRetry({ url, options = {}, retryTimes = defaultRetries, fallbackUrl = '' }) { | ||
url, | ||
options: _extends({}, options, params == null ? void 0 : params.options), | ||
options: _extends._({}, options, params == null ? void 0 : params.options), | ||
retryTimes: params == null ? void 0 : params.retryTimes, | ||
@@ -64,0 +52,0 @@ fallbackUrl: params == null ? void 0 : params.fallbackUrl |
@@ -1,15 +0,3 @@ | ||
function _extends() { | ||
_extends = Object.assign || function(target) { | ||
for(var i = 1; i < arguments.length; i++){ | ||
var source = arguments[i]; | ||
for(var key in source){ | ||
if (Object.prototype.hasOwnProperty.call(source, key)) { | ||
target[key] = source[key]; | ||
} | ||
} | ||
} | ||
return target; | ||
}; | ||
return _extends.apply(this, arguments); | ||
} | ||
import { _ } from '@swc/helpers/_/_extends'; | ||
const defaultRetries = 3; | ||
@@ -59,3 +47,3 @@ async function fetchWithRetry({ url, options = {}, retryTimes = defaultRetries, fallbackUrl = '' }) { | ||
url, | ||
options: _extends({}, options, params == null ? void 0 : params.options), | ||
options: _({}, options, params == null ? void 0 : params.options), | ||
retryTimes: params == null ? void 0 : params.retryTimes, | ||
@@ -62,0 +50,0 @@ fallbackUrl: params == null ? void 0 : params.fallbackUrl |
'use strict'; | ||
require('@module-federation/sdk'); | ||
var _extends = require('@swc/helpers/_/_extends'); | ||
var _object_without_properties_loose = require('@swc/helpers/_/_object_without_properties_loose'); | ||
var sdk = require('@module-federation/sdk'); | ||
@@ -9,8 +11,2 @@ function getBuilderId() { | ||
} | ||
function isDebugMode() { | ||
return Boolean(""); | ||
} | ||
function isBrowserEnv() { | ||
return typeof window !== 'undefined'; | ||
} | ||
@@ -61,10 +57,2 @@ const LOG_CATEGORY = '[ Federation Runtime ]'; | ||
} | ||
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types | ||
function safeToString(info) { | ||
try { | ||
return JSON.stringify(info, null, 2); | ||
} catch (e) { | ||
return ''; | ||
} | ||
} | ||
function isObject(val) { | ||
@@ -89,3 +77,3 @@ return val && typeof val === 'object'; | ||
}; | ||
if (isBrowserEnv()) { | ||
if (sdk.isBrowserEnv()) { | ||
return 'remoteEntry' in snapshot ? { | ||
@@ -107,28 +95,2 @@ url: snapshot.remoteEntry, | ||
function _extends$1() { | ||
_extends$1 = Object.assign || function(target) { | ||
for(var i = 1; i < arguments.length; i++){ | ||
var source = arguments[i]; | ||
for(var key in source){ | ||
if (Object.prototype.hasOwnProperty.call(source, key)) { | ||
target[key] = source[key]; | ||
} | ||
} | ||
} | ||
return target; | ||
}; | ||
return _extends$1.apply(this, arguments); | ||
} | ||
function _object_without_properties_loose(source, excluded) { | ||
if (source == null) return {}; | ||
var target = {}; | ||
var sourceKeys = Object.keys(source); | ||
var key, i; | ||
for(i = 0; i < sourceKeys.length; i++){ | ||
key = sourceKeys[i]; | ||
if (excluded.indexOf(key) >= 0) continue; | ||
target[key] = source[key]; | ||
} | ||
return target; | ||
} | ||
const nativeGlobal = (()=>{ | ||
@@ -218,6 +180,6 @@ try { | ||
} | ||
function setGlobalFederationConstructor(FederationConstructor, isDebug = isDebugMode()) { | ||
function setGlobalFederationConstructor(FederationConstructor, isDebug = sdk.isDebugMode()) { | ||
if (isDebug) { | ||
globalThis.__FEDERATION__.__DEBUG_CONSTRUCTOR__ = FederationConstructor; | ||
globalThis.__FEDERATION__.__DEBUG_CONSTRUCTOR_VERSION__ = "0.5.1"; | ||
globalThis.__FEDERATION__.__DEBUG_CONSTRUCTOR_VERSION__ = "0.6.0"; | ||
} | ||
@@ -270,3 +232,3 @@ } | ||
if ('version' in moduleInfo && moduleInfo['version']) { | ||
const { version } = moduleInfo, resModuleInfo = _object_without_properties_loose(moduleInfo, [ | ||
const { version } = moduleInfo, resModuleInfo = _object_without_properties_loose._(moduleInfo, [ | ||
"version" | ||
@@ -289,3 +251,3 @@ ]); | ||
const addGlobalSnapshot = (moduleInfos)=>{ | ||
nativeGlobal.__FEDERATION__.moduleInfo = _extends$1({}, nativeGlobal.__FEDERATION__.moduleInfo, moduleInfos); | ||
nativeGlobal.__FEDERATION__.moduleInfo = _extends._({}, nativeGlobal.__FEDERATION__.moduleInfo, moduleInfos); | ||
return ()=>{ | ||
@@ -324,212 +286,5 @@ const keys = Object.keys(moduleInfos); | ||
function registerPlugins(plugins, hookInstances) { | ||
const globalPlugins = getGlobalHostPlugins(); | ||
// Incorporate global plugins | ||
if (globalPlugins.length > 0) { | ||
globalPlugins.forEach((plugin)=>{ | ||
if (plugins == null ? void 0 : plugins.find((item)=>item.name !== plugin.name)) { | ||
plugins.push(plugin); | ||
} | ||
}); | ||
} | ||
if (plugins && plugins.length > 0) { | ||
plugins.forEach((plugin)=>{ | ||
hookInstances.forEach((hookInstance)=>{ | ||
hookInstance.applyPlugin(plugin); | ||
}); | ||
}); | ||
} | ||
return plugins; | ||
} | ||
const DEFAULT_SCOPE = 'default'; | ||
const DEFAULT_REMOTE_TYPE = 'global'; | ||
class SyncHook { | ||
on(fn) { | ||
if (typeof fn === 'function') { | ||
this.listeners.add(fn); | ||
} | ||
} | ||
once(fn) { | ||
// eslint-disable-next-line @typescript-eslint/no-this-alias | ||
const self = this; | ||
this.on(function wrapper(...args) { | ||
self.remove(wrapper); | ||
// eslint-disable-next-line prefer-spread | ||
return fn.apply(null, args); | ||
}); | ||
} | ||
emit(...data) { | ||
let result; | ||
if (this.listeners.size > 0) { | ||
// eslint-disable-next-line prefer-spread | ||
this.listeners.forEach((fn)=>{ | ||
result = fn(...data); | ||
}); | ||
} | ||
return result; | ||
} | ||
remove(fn) { | ||
this.listeners.delete(fn); | ||
} | ||
removeAll() { | ||
this.listeners.clear(); | ||
} | ||
constructor(type){ | ||
this.type = ''; | ||
this.listeners = new Set(); | ||
if (type) { | ||
this.type = type; | ||
} | ||
} | ||
} | ||
class AsyncHook extends SyncHook { | ||
emit(...data) { | ||
let result; | ||
const ls = Array.from(this.listeners); | ||
if (ls.length > 0) { | ||
let i = 0; | ||
const call = (prev)=>{ | ||
if (prev === false) { | ||
return false; // Abort process | ||
} else if (i < ls.length) { | ||
return Promise.resolve(ls[i++].apply(null, data)).then(call); | ||
} else { | ||
return prev; | ||
} | ||
}; | ||
result = call(); | ||
} | ||
return Promise.resolve(result); | ||
} | ||
} | ||
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types | ||
function checkReturnData(originalData, returnedData) { | ||
if (!isObject(returnedData)) { | ||
return false; | ||
} | ||
if (originalData !== returnedData) { | ||
// eslint-disable-next-line no-restricted-syntax | ||
for(const key in originalData){ | ||
if (!(key in returnedData)) { | ||
return false; | ||
} | ||
} | ||
} | ||
return true; | ||
} | ||
class SyncWaterfallHook extends SyncHook { | ||
emit(data) { | ||
if (!isObject(data)) { | ||
error(`The data for the "${this.type}" hook should be an object.`); | ||
} | ||
for (const fn of this.listeners){ | ||
try { | ||
const tempData = fn(data); | ||
if (checkReturnData(data, tempData)) { | ||
data = tempData; | ||
} else { | ||
this.onerror(`A plugin returned an unacceptable value for the "${this.type}" type.`); | ||
break; | ||
} | ||
} catch (e) { | ||
warn(e); | ||
this.onerror(e); | ||
} | ||
} | ||
return data; | ||
} | ||
constructor(type){ | ||
super(); | ||
this.onerror = error; | ||
this.type = type; | ||
} | ||
} | ||
class AsyncWaterfallHook extends SyncHook { | ||
emit(data) { | ||
if (!isObject(data)) { | ||
error(`The response data for the "${this.type}" hook must be an object.`); | ||
} | ||
const ls = Array.from(this.listeners); | ||
if (ls.length > 0) { | ||
let i = 0; | ||
const processError = (e)=>{ | ||
warn(e); | ||
this.onerror(e); | ||
return data; | ||
}; | ||
const call = (prevData)=>{ | ||
if (checkReturnData(data, prevData)) { | ||
data = prevData; | ||
if (i < ls.length) { | ||
try { | ||
return Promise.resolve(ls[i++](data)).then(call, processError); | ||
} catch (e) { | ||
return processError(e); | ||
} | ||
} | ||
} else { | ||
this.onerror(`A plugin returned an incorrect value for the "${this.type}" type.`); | ||
} | ||
return data; | ||
}; | ||
return Promise.resolve(call(data)); | ||
} | ||
return Promise.resolve(data); | ||
} | ||
constructor(type){ | ||
super(); | ||
this.onerror = error; | ||
this.type = type; | ||
} | ||
} | ||
class PluginSystem { | ||
applyPlugin(plugin) { | ||
assert(isPlainObject(plugin), 'Plugin configuration is invalid.'); | ||
// The plugin's name is mandatory and must be unique | ||
const pluginName = plugin.name; | ||
assert(pluginName, 'A name must be provided by the plugin.'); | ||
if (!this.registerPlugins[pluginName]) { | ||
this.registerPlugins[pluginName] = plugin; | ||
Object.keys(this.lifecycle).forEach((key)=>{ | ||
const pluginLife = plugin[key]; | ||
if (pluginLife) { | ||
this.lifecycle[key].on(pluginLife); | ||
} | ||
}); | ||
} | ||
} | ||
removePlugin(pluginName) { | ||
assert(pluginName, 'A name is required.'); | ||
const plugin = this.registerPlugins[pluginName]; | ||
assert(plugin, `The plugin "${pluginName}" is not registered.`); | ||
Object.keys(plugin).forEach((key)=>{ | ||
if (key !== 'name') { | ||
this.lifecycle[key].remove(plugin[key]); | ||
} | ||
}); | ||
} | ||
// eslint-disable-next-line @typescript-eslint/no-shadow | ||
inherit({ lifecycle, registerPlugins }) { | ||
Object.keys(lifecycle).forEach((hookName)=>{ | ||
assert(!this.lifecycle[hookName], `The hook "${hookName}" has a conflict and cannot be inherited.`); | ||
this.lifecycle[hookName] = lifecycle[hookName]; | ||
}); | ||
Object.keys(registerPlugins).forEach((pluginName)=>{ | ||
assert(!this.registerPlugins[pluginName], `The plugin "${pluginName}" has a conflict and cannot be inherited.`); | ||
this.applyPlugin(registerPlugins[pluginName]); | ||
}); | ||
} | ||
constructor(lifecycle){ | ||
this.registerPlugins = {}; | ||
this.lifecycle = lifecycle; | ||
this.lifecycleKeys = Object.keys(lifecycle); | ||
} | ||
} | ||
// fork from https://github.com/originjs/vite-plugin-federation/blob/v1.1.12/packages/lib/src/utils/semver/index.ts | ||
@@ -891,16 +646,2 @@ // those constants are based on https://www.rubydoc.info/gems/semantic_range/3.0.0/SemanticRange#BUILDIDENTIFIER-constant | ||
function _extends() { | ||
_extends = Object.assign || function(target) { | ||
for(var i = 1; i < arguments.length; i++){ | ||
var source = arguments[i]; | ||
for(var key in source){ | ||
if (Object.prototype.hasOwnProperty.call(source, key)) { | ||
target[key] = source[key]; | ||
} | ||
} | ||
} | ||
return target; | ||
}; | ||
return _extends.apply(this, arguments); | ||
} | ||
function formatShare(shareArgs, from, name, shareStrategy) { | ||
@@ -922,3 +663,3 @@ let get; | ||
var _shareArgs_version, _shareArgs_scope, _shareArgs_strategy; | ||
return _extends({ | ||
return _extends._({ | ||
deps: [], | ||
@@ -929,3 +670,3 @@ useIn: [], | ||
}, shareArgs, { | ||
shareConfig: _extends({ | ||
shareConfig: _extends._({ | ||
requiredVersion: `^${shareArgs.version}`, | ||
@@ -956,3 +697,3 @@ singleton: false, | ||
}, {}); | ||
const shared = _extends({}, globalOptions.shared); | ||
const shared = _extends._({}, globalOptions.shared); | ||
Object.keys(shareInfos).forEach((shareKey)=>{ | ||
@@ -1121,10 +862,5 @@ if (!shared[shareKey]) { | ||
exports.AsyncHook = AsyncHook; | ||
exports.AsyncWaterfallHook = AsyncWaterfallHook; | ||
exports.DEFAULT_REMOTE_TYPE = DEFAULT_REMOTE_TYPE; | ||
exports.DEFAULT_SCOPE = DEFAULT_SCOPE; | ||
exports.Global = Global; | ||
exports.PluginSystem = PluginSystem; | ||
exports.SyncHook = SyncHook; | ||
exports.SyncWaterfallHook = SyncWaterfallHook; | ||
exports.addGlobalSnapshot = addGlobalSnapshot; | ||
@@ -1152,3 +888,4 @@ exports.addUniqueItem = addUniqueItem; | ||
exports.globalLoading = globalLoading; | ||
exports.isBrowserEnv = isBrowserEnv; | ||
exports.isObject = isObject; | ||
exports.isPlainObject = isPlainObject; | ||
exports.isPureRemoteEntry = isPureRemoteEntry; | ||
@@ -1158,5 +895,3 @@ exports.isRemoteInfoWithEntry = isRemoteInfoWithEntry; | ||
exports.registerGlobalPlugins = registerGlobalPlugins; | ||
exports.registerPlugins = registerPlugins; | ||
exports.resetFederationGlobalInfo = resetFederationGlobalInfo; | ||
exports.safeToString = safeToString; | ||
exports.setGlobalFederationConstructor = setGlobalFederationConstructor; | ||
@@ -1166,1 +901,2 @@ exports.setGlobalFederationInstance = setGlobalFederationInstance; | ||
exports.setPreloaded = setPreloaded; | ||
exports.warn = warn; |
@@ -1,2 +0,4 @@ | ||
import '@module-federation/sdk'; | ||
import { _ as _$1 } from '@swc/helpers/_/_extends'; | ||
import { _ } from '@swc/helpers/_/_object_without_properties_loose'; | ||
import { isBrowserEnv, isDebugMode } from '@module-federation/sdk'; | ||
@@ -7,8 +9,2 @@ function getBuilderId() { | ||
} | ||
function isDebugMode() { | ||
return Boolean(""); | ||
} | ||
function isBrowserEnv() { | ||
return typeof window !== 'undefined'; | ||
} | ||
@@ -59,10 +55,2 @@ const LOG_CATEGORY = '[ Federation Runtime ]'; | ||
} | ||
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types | ||
function safeToString(info) { | ||
try { | ||
return JSON.stringify(info, null, 2); | ||
} catch (e) { | ||
return ''; | ||
} | ||
} | ||
function isObject(val) { | ||
@@ -104,28 +92,2 @@ return val && typeof val === 'object'; | ||
function _extends$1() { | ||
_extends$1 = Object.assign || function(target) { | ||
for(var i = 1; i < arguments.length; i++){ | ||
var source = arguments[i]; | ||
for(var key in source){ | ||
if (Object.prototype.hasOwnProperty.call(source, key)) { | ||
target[key] = source[key]; | ||
} | ||
} | ||
} | ||
return target; | ||
}; | ||
return _extends$1.apply(this, arguments); | ||
} | ||
function _object_without_properties_loose(source, excluded) { | ||
if (source == null) return {}; | ||
var target = {}; | ||
var sourceKeys = Object.keys(source); | ||
var key, i; | ||
for(i = 0; i < sourceKeys.length; i++){ | ||
key = sourceKeys[i]; | ||
if (excluded.indexOf(key) >= 0) continue; | ||
target[key] = source[key]; | ||
} | ||
return target; | ||
} | ||
const nativeGlobal = (()=>{ | ||
@@ -218,3 +180,3 @@ try { | ||
globalThis.__FEDERATION__.__DEBUG_CONSTRUCTOR__ = FederationConstructor; | ||
globalThis.__FEDERATION__.__DEBUG_CONSTRUCTOR_VERSION__ = "0.5.1"; | ||
globalThis.__FEDERATION__.__DEBUG_CONSTRUCTOR_VERSION__ = "0.6.0"; | ||
} | ||
@@ -267,3 +229,3 @@ } | ||
if ('version' in moduleInfo && moduleInfo['version']) { | ||
const { version } = moduleInfo, resModuleInfo = _object_without_properties_loose(moduleInfo, [ | ||
const { version } = moduleInfo, resModuleInfo = _(moduleInfo, [ | ||
"version" | ||
@@ -286,3 +248,3 @@ ]); | ||
const addGlobalSnapshot = (moduleInfos)=>{ | ||
nativeGlobal.__FEDERATION__.moduleInfo = _extends$1({}, nativeGlobal.__FEDERATION__.moduleInfo, moduleInfos); | ||
nativeGlobal.__FEDERATION__.moduleInfo = _$1({}, nativeGlobal.__FEDERATION__.moduleInfo, moduleInfos); | ||
return ()=>{ | ||
@@ -321,212 +283,5 @@ const keys = Object.keys(moduleInfos); | ||
function registerPlugins(plugins, hookInstances) { | ||
const globalPlugins = getGlobalHostPlugins(); | ||
// Incorporate global plugins | ||
if (globalPlugins.length > 0) { | ||
globalPlugins.forEach((plugin)=>{ | ||
if (plugins == null ? void 0 : plugins.find((item)=>item.name !== plugin.name)) { | ||
plugins.push(plugin); | ||
} | ||
}); | ||
} | ||
if (plugins && plugins.length > 0) { | ||
plugins.forEach((plugin)=>{ | ||
hookInstances.forEach((hookInstance)=>{ | ||
hookInstance.applyPlugin(plugin); | ||
}); | ||
}); | ||
} | ||
return plugins; | ||
} | ||
const DEFAULT_SCOPE = 'default'; | ||
const DEFAULT_REMOTE_TYPE = 'global'; | ||
class SyncHook { | ||
on(fn) { | ||
if (typeof fn === 'function') { | ||
this.listeners.add(fn); | ||
} | ||
} | ||
once(fn) { | ||
// eslint-disable-next-line @typescript-eslint/no-this-alias | ||
const self = this; | ||
this.on(function wrapper(...args) { | ||
self.remove(wrapper); | ||
// eslint-disable-next-line prefer-spread | ||
return fn.apply(null, args); | ||
}); | ||
} | ||
emit(...data) { | ||
let result; | ||
if (this.listeners.size > 0) { | ||
// eslint-disable-next-line prefer-spread | ||
this.listeners.forEach((fn)=>{ | ||
result = fn(...data); | ||
}); | ||
} | ||
return result; | ||
} | ||
remove(fn) { | ||
this.listeners.delete(fn); | ||
} | ||
removeAll() { | ||
this.listeners.clear(); | ||
} | ||
constructor(type){ | ||
this.type = ''; | ||
this.listeners = new Set(); | ||
if (type) { | ||
this.type = type; | ||
} | ||
} | ||
} | ||
class AsyncHook extends SyncHook { | ||
emit(...data) { | ||
let result; | ||
const ls = Array.from(this.listeners); | ||
if (ls.length > 0) { | ||
let i = 0; | ||
const call = (prev)=>{ | ||
if (prev === false) { | ||
return false; // Abort process | ||
} else if (i < ls.length) { | ||
return Promise.resolve(ls[i++].apply(null, data)).then(call); | ||
} else { | ||
return prev; | ||
} | ||
}; | ||
result = call(); | ||
} | ||
return Promise.resolve(result); | ||
} | ||
} | ||
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types | ||
function checkReturnData(originalData, returnedData) { | ||
if (!isObject(returnedData)) { | ||
return false; | ||
} | ||
if (originalData !== returnedData) { | ||
// eslint-disable-next-line no-restricted-syntax | ||
for(const key in originalData){ | ||
if (!(key in returnedData)) { | ||
return false; | ||
} | ||
} | ||
} | ||
return true; | ||
} | ||
class SyncWaterfallHook extends SyncHook { | ||
emit(data) { | ||
if (!isObject(data)) { | ||
error(`The data for the "${this.type}" hook should be an object.`); | ||
} | ||
for (const fn of this.listeners){ | ||
try { | ||
const tempData = fn(data); | ||
if (checkReturnData(data, tempData)) { | ||
data = tempData; | ||
} else { | ||
this.onerror(`A plugin returned an unacceptable value for the "${this.type}" type.`); | ||
break; | ||
} | ||
} catch (e) { | ||
warn(e); | ||
this.onerror(e); | ||
} | ||
} | ||
return data; | ||
} | ||
constructor(type){ | ||
super(); | ||
this.onerror = error; | ||
this.type = type; | ||
} | ||
} | ||
class AsyncWaterfallHook extends SyncHook { | ||
emit(data) { | ||
if (!isObject(data)) { | ||
error(`The response data for the "${this.type}" hook must be an object.`); | ||
} | ||
const ls = Array.from(this.listeners); | ||
if (ls.length > 0) { | ||
let i = 0; | ||
const processError = (e)=>{ | ||
warn(e); | ||
this.onerror(e); | ||
return data; | ||
}; | ||
const call = (prevData)=>{ | ||
if (checkReturnData(data, prevData)) { | ||
data = prevData; | ||
if (i < ls.length) { | ||
try { | ||
return Promise.resolve(ls[i++](data)).then(call, processError); | ||
} catch (e) { | ||
return processError(e); | ||
} | ||
} | ||
} else { | ||
this.onerror(`A plugin returned an incorrect value for the "${this.type}" type.`); | ||
} | ||
return data; | ||
}; | ||
return Promise.resolve(call(data)); | ||
} | ||
return Promise.resolve(data); | ||
} | ||
constructor(type){ | ||
super(); | ||
this.onerror = error; | ||
this.type = type; | ||
} | ||
} | ||
class PluginSystem { | ||
applyPlugin(plugin) { | ||
assert(isPlainObject(plugin), 'Plugin configuration is invalid.'); | ||
// The plugin's name is mandatory and must be unique | ||
const pluginName = plugin.name; | ||
assert(pluginName, 'A name must be provided by the plugin.'); | ||
if (!this.registerPlugins[pluginName]) { | ||
this.registerPlugins[pluginName] = plugin; | ||
Object.keys(this.lifecycle).forEach((key)=>{ | ||
const pluginLife = plugin[key]; | ||
if (pluginLife) { | ||
this.lifecycle[key].on(pluginLife); | ||
} | ||
}); | ||
} | ||
} | ||
removePlugin(pluginName) { | ||
assert(pluginName, 'A name is required.'); | ||
const plugin = this.registerPlugins[pluginName]; | ||
assert(plugin, `The plugin "${pluginName}" is not registered.`); | ||
Object.keys(plugin).forEach((key)=>{ | ||
if (key !== 'name') { | ||
this.lifecycle[key].remove(plugin[key]); | ||
} | ||
}); | ||
} | ||
// eslint-disable-next-line @typescript-eslint/no-shadow | ||
inherit({ lifecycle, registerPlugins }) { | ||
Object.keys(lifecycle).forEach((hookName)=>{ | ||
assert(!this.lifecycle[hookName], `The hook "${hookName}" has a conflict and cannot be inherited.`); | ||
this.lifecycle[hookName] = lifecycle[hookName]; | ||
}); | ||
Object.keys(registerPlugins).forEach((pluginName)=>{ | ||
assert(!this.registerPlugins[pluginName], `The plugin "${pluginName}" has a conflict and cannot be inherited.`); | ||
this.applyPlugin(registerPlugins[pluginName]); | ||
}); | ||
} | ||
constructor(lifecycle){ | ||
this.registerPlugins = {}; | ||
this.lifecycle = lifecycle; | ||
this.lifecycleKeys = Object.keys(lifecycle); | ||
} | ||
} | ||
// fork from https://github.com/originjs/vite-plugin-federation/blob/v1.1.12/packages/lib/src/utils/semver/index.ts | ||
@@ -888,16 +643,2 @@ // those constants are based on https://www.rubydoc.info/gems/semantic_range/3.0.0/SemanticRange#BUILDIDENTIFIER-constant | ||
function _extends() { | ||
_extends = Object.assign || function(target) { | ||
for(var i = 1; i < arguments.length; i++){ | ||
var source = arguments[i]; | ||
for(var key in source){ | ||
if (Object.prototype.hasOwnProperty.call(source, key)) { | ||
target[key] = source[key]; | ||
} | ||
} | ||
} | ||
return target; | ||
}; | ||
return _extends.apply(this, arguments); | ||
} | ||
function formatShare(shareArgs, from, name, shareStrategy) { | ||
@@ -919,3 +660,3 @@ let get; | ||
var _shareArgs_version, _shareArgs_scope, _shareArgs_strategy; | ||
return _extends({ | ||
return _$1({ | ||
deps: [], | ||
@@ -926,3 +667,3 @@ useIn: [], | ||
}, shareArgs, { | ||
shareConfig: _extends({ | ||
shareConfig: _$1({ | ||
requiredVersion: `^${shareArgs.version}`, | ||
@@ -953,3 +694,3 @@ singleton: false, | ||
}, {}); | ||
const shared = _extends({}, globalOptions.shared); | ||
const shared = _$1({}, globalOptions.shared); | ||
Object.keys(shareInfos).forEach((shareKey)=>{ | ||
@@ -1118,2 +859,2 @@ if (!shared[shareKey]) { | ||
export { AsyncHook as A, registerPlugins as B, getBuilderId as C, DEFAULT_REMOTE_TYPE as D, setGlobalFederationConstructor as E, getGlobalFederationInstance as F, Global as G, getGlobalFederationConstructor as H, setGlobalFederationInstance as I, registerGlobalPlugins as J, nativeGlobal as K, resetFederationGlobalInfo as L, getTargetSnapshotInfoByModuleInfo as M, getGlobalHostPlugins as N, PluginSystem as P, SyncWaterfallHook as S, DEFAULT_SCOPE as a, getRemoteEntryExports as b, assert as c, getFMId as d, isPureRemoteEntry as e, getRemoteEntryInfoFromSnapshot as f, globalLoading as g, error as h, isRemoteInfoWithEntry as i, isBrowserEnv as j, getInfoWithoutType as k, getPreloaded as l, setPreloaded as m, getRegisteredShare as n, arrayOptions as o, getGlobalSnapshotInfoByModuleInfo as p, addGlobalSnapshot as q, setGlobalSnapshotInfoByModuleInfo as r, safeToString as s, AsyncWaterfallHook as t, getGlobalSnapshot as u, formatShareConfigs as v, getTargetSharedOptions as w, getGlobalShareScope as x, addUniqueItem as y, SyncHook as z }; | ||
export { getBuilderId as A, setGlobalFederationConstructor as B, getGlobalFederationInstance as C, DEFAULT_REMOTE_TYPE as D, getGlobalFederationConstructor as E, setGlobalFederationInstance as F, Global as G, registerGlobalPlugins as H, nativeGlobal as I, resetFederationGlobalInfo as J, getTargetSnapshotInfoByModuleInfo as K, 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, getRemoteEntryInfoFromSnapshot as l, getInfoWithoutType as m, getPreloaded as n, getRegisteredShare as o, arrayOptions as p, getGlobalSnapshotInfoByModuleInfo as q, addGlobalSnapshot as r, setPreloaded as s, setGlobalSnapshotInfoByModuleInfo as t, getGlobalSnapshot as u, formatShareConfigs as v, warn as w, getTargetSharedOptions as x, getGlobalShareScope as y, addUniqueItem as z }; |
import type { CreateScriptHookReturn } from '@module-federation/sdk'; | ||
import { Options, PreloadRemoteArgs, RemoteEntryExports, Remote, Shared, ShareInfos, UserOptions, RemoteInfo, ShareScopeMap, InitScope, RemoteEntryInitOptions } from './type'; | ||
import { Options, PreloadRemoteArgs, RemoteEntryExports, Remote, Shared, ShareInfos, UserOptions, RemoteInfo, ShareScopeMap, InitScope, RemoteEntryInitOptions, CallFrom } from './type'; | ||
import { Module } from './module'; | ||
@@ -72,7 +72,11 @@ import { AsyncHook, AsyncWaterfallHook, PluginSystem, SyncHook, SyncWaterfallHook } from './utils/hooks'; | ||
}): () => T | never; | ||
initializeSharing(shareScopeName?: string, strategy?: Shared['strategy']): Array<Promise<void>>; | ||
initializeSharing(shareScopeName?: string, extraOptions?: { | ||
initScope?: InitScope; | ||
from?: CallFrom; | ||
strategy?: Shared['strategy']; | ||
}): Array<Promise<void>>; | ||
initRawContainer(name: string, url: string, container: RemoteEntryExports): Module; | ||
loadRemote<T>(id: string, options?: { | ||
loadFactory?: boolean; | ||
from: 'build' | 'runtime'; | ||
from: CallFrom; | ||
}): Promise<T | null>; | ||
@@ -79,0 +83,0 @@ preloadRemote(preloadOptions: Array<PreloadRemoteArgs>): Promise<void>; |
import { resetFederationGlobalInfo, getGlobalFederationInstance, setGlobalFederationInstance, getGlobalFederationConstructor, setGlobalFederationConstructor, getInfoWithoutType, getGlobalSnapshot, getTargetSnapshotInfoByModuleInfo, getGlobalSnapshotInfoByModuleInfo, setGlobalSnapshotInfoByModuleInfo, addGlobalSnapshot, getRemoteEntryExports, registerGlobalPlugins, getGlobalHostPlugins, getPreloaded, setPreloaded, Global } from './global'; | ||
import { getRegisteredShare, getGlobalShareScope } from './utils/share'; | ||
import * as pluginHelper from './utils/hooks'; | ||
import { registerPlugins } from './utils'; | ||
interface IShareUtils { | ||
@@ -28,4 +26,2 @@ getRegisteredShare: typeof getRegisteredShare; | ||
setPreloaded: typeof setPreloaded; | ||
registerPlugins: typeof registerPlugins; | ||
pluginHelper: typeof pluginHelper; | ||
} | ||
@@ -32,0 +28,0 @@ declare const _default: { |
@@ -35,7 +35,2 @@ import { GlobalModuleInfo, Manifest, ModuleInfo } from '@module-federation/sdk'; | ||
}>; | ||
afterLoadSnapshot: AsyncWaterfallHook<{ | ||
options: Options; | ||
moduleInfo: Remote; | ||
remoteSnapshot: ModuleInfo; | ||
}>; | ||
}>; | ||
@@ -42,0 +37,0 @@ loaderHook: FederationHost['loaderHook']; |
@@ -1,3 +0,3 @@ | ||
import type { ModuleInfo, GlobalModuleInfo } from '@module-federation/sdk'; | ||
import { Options, UserOptions, PreloadAssets, PreloadOptions, PreloadRemoteArgs, Remote, RemoteInfo, RemoteEntryExports } from '../type'; | ||
import { ModuleInfo, GlobalModuleInfo } from '@module-federation/sdk'; | ||
import { Options, UserOptions, PreloadAssets, PreloadOptions, PreloadRemoteArgs, Remote, RemoteInfo, RemoteEntryExports, CallFrom } from '../type'; | ||
import { FederationHost } from '../core'; | ||
@@ -59,3 +59,3 @@ import { PluginSystem, AsyncHook, AsyncWaterfallHook, SyncHook, SyncWaterfallHook } from '../utils/hooks'; | ||
options?: any; | ||
from: "build" | "runtime"; | ||
from: CallFrom; | ||
lifecycle: "onLoad" | "beforeRequest"; | ||
@@ -93,3 +93,3 @@ origin: FederationHost; | ||
loadFactory?: boolean; | ||
from: 'build' | 'runtime'; | ||
from: CallFrom; | ||
}): Promise<T | null>; | ||
@@ -96,0 +96,0 @@ preloadRemote(preloadOptions: Array<PreloadRemoteArgs>): Promise<void>; |
import { Federation } from '../global'; | ||
import { Options, ShareScopeMap, ShareInfos, Shared, UserOptions, ShareStrategy } from '../type'; | ||
import { Options, ShareScopeMap, ShareInfos, Shared, UserOptions, ShareStrategy, InitScope, InitTokens, CallFrom } from '../type'; | ||
import { FederationHost } from '../core'; | ||
@@ -34,2 +34,3 @@ import { PluginSystem, AsyncHook, AsyncWaterfallHook, SyncWaterfallHook } from '../utils/hooks'; | ||
}>; | ||
initTokens: InitTokens; | ||
constructor(host: FederationHost); | ||
@@ -51,3 +52,7 @@ registerShared(globalOptions: Options, userOptions: UserOptions): { | ||
*/ | ||
initializeSharing(shareScopeName?: string, strategy?: ShareStrategy): Array<Promise<void>>; | ||
initializeSharing(shareScopeName?: string, extraOptions?: { | ||
initScope?: InitScope; | ||
from?: CallFrom; | ||
strategy?: ShareStrategy; | ||
}): Array<Promise<void>>; | ||
loadShareSync<T>(pkgName: string, extraOptions?: { | ||
@@ -54,0 +59,0 @@ customShareInfo?: Partial<Shared>; |
@@ -105,3 +105,5 @@ import type { RemoteWithEntry, RemoteWithVersion, Module, RemoteEntryType } from '@module-federation/sdk'; | ||
}; | ||
export type InitScope = Array<Record<string, never>>; | ||
export type InitTokens = Record<string, Record<string, any>>; | ||
export type InitScope = InitTokens[]; | ||
export type CallFrom = 'build' | 'runtime'; | ||
export type RemoteEntryExports = { | ||
@@ -108,0 +110,0 @@ get: (id: string) => () => Promise<Module>; |
@@ -0,4 +1,3 @@ | ||
export { isBrowserEnv, isDebugMode } from '@module-federation/sdk'; | ||
export declare function isDevelopmentMode(): boolean; | ||
export declare function getBuilderId(): string; | ||
export declare function isDebugMode(): boolean; | ||
export declare function isBrowserEnv(): boolean; |
import { FederationHost } from '../core'; | ||
import { UserOptions } from '../type'; | ||
import { Module } from '../module'; | ||
import { PluginSystem } from './hooks'; | ||
export declare function registerPlugins<Y extends Record<string, any>, T extends PluginSystem<Y>>(plugins: UserOptions['plugins'], hookInstances: Array<T | FederationHost['hooks'] | FederationHost['snapshotHandler']['hooks'] | FederationHost['sharedHandler']['hooks'] | FederationHost['remoteHandler']['hooks'] | Module['host']['loaderHook']>): import("../type").FederationRuntimePlugin[] | undefined; | ||
export declare function registerPlugins(plugins: UserOptions['plugins'], hookInstances: Array<FederationHost['hooks'] | FederationHost['snapshotHandler']['hooks'] | FederationHost['sharedHandler']['hooks'] | FederationHost['remoteHandler']['hooks'] | Module['host']['loaderHook']>): import("../type").FederationRuntimePlugin[] | undefined; |
@@ -1,2 +0,2 @@ | ||
import type { RemoteWithEntry, ModuleInfo, RemoteEntryType } from '@module-federation/sdk'; | ||
import { RemoteWithEntry, ModuleInfo, RemoteEntryType } from '@module-federation/sdk'; | ||
import { Remote, RemoteInfoOptionalVersion } from '../type'; | ||
@@ -8,3 +8,2 @@ export declare function addUniqueItem(arr: Array<string>, item: string): Array<string>; | ||
export declare function safeWrapper<T extends (...args: Array<any>) => any>(callback: T, disableWarn?: boolean): Promise<ReturnType<T> | undefined>; | ||
export declare function safeToString(info: any): string; | ||
export declare function isObject(val: any): boolean; | ||
@@ -11,0 +10,0 @@ export declare const objectToString: () => string; |
{ | ||
"name": "@module-federation/runtime", | ||
"version": "0.0.0-next-20240830100524", | ||
"version": "0.0.0-next-20240902023803", | ||
"author": "zhouxiao <codingzx@gmail.com>", | ||
@@ -37,2 +37,7 @@ "main": "./dist/index.cjs.js", | ||
}, | ||
"./embedded": { | ||
"types": "./dist/embedded.cjs.d.ts", | ||
"import": "./dist/embedded.esm.js", | ||
"require": "./dist/embedded.cjs.js" | ||
}, | ||
"./*": "./*" | ||
@@ -57,4 +62,4 @@ }, | ||
"dependencies": { | ||
"@module-federation/sdk": "0.0.0-next-20240830100524" | ||
"@module-federation/sdk": "0.0.0-next-20240902023803" | ||
} | ||
} |
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
60
299725
6856
+ Added@module-federation/sdk@0.0.0-next-20240902023803(transitive)
- Removed@module-federation/sdk@0.0.0-next-20240830100524(transitive)