Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@module-federation/bridge-react

Package Overview
Dependencies
Maintainers
0
Versions
303
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@module-federation/bridge-react - npm Package Compare versions

Comparing version 0.0.0-next-20241021083129 to 0.0.0-next-20241021084851

7

CHANGELOG.md
# @module-federation/bridge-react
## 0.0.0-next-20241021083129
## 0.0.0-next-20241021084851
### Patch Changes
- 3082116: feat: support module isolated reported
- Updated dependencies [3082116]
- @module-federation/runtime@0.0.0-next-20241021083129
- @module-federation/bridge-shared@0.0.0-next-20241021083129
- @module-federation/bridge-shared@0.0.0-next-20241021084851

@@ -12,0 +9,0 @@ ## 0.6.11

@@ -6,3 +6,2 @@ "use strict";

const ReactRouterDOM = require("react-router-dom");
const runtime = require("@module-federation/runtime");
const ReactDOM = require("react-dom");

@@ -38,6 +37,6 @@ function _interopNamespaceDefault(e) {

}
static getDerivedStateFromError(error2) {
static getDerivedStateFromError(error) {
return {
didCatch: true,
error: error2
error
};

@@ -47,5 +46,5 @@ }

const {
error: error2
error
} = this.state;
if (error2 !== null) {
if (error !== null) {
var _this$props$onReset, _this$props;

@@ -62,5 +61,5 @@ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {

}
componentDidCatch(error2, info) {
componentDidCatch(error, info) {
var _this$props$onError, _this$props2;
(_this$props$onError = (_this$props2 = this.props).onError) === null || _this$props$onError === void 0 ? void 0 : _this$props$onError.call(_this$props2, error2, info);
(_this$props$onError = (_this$props2 = this.props).onError) === null || _this$props$onError === void 0 ? void 0 : _this$props$onError.call(_this$props2, error, info);
}

@@ -93,3 +92,3 @@ componentDidUpdate(prevProps, prevState) {

didCatch,
error: error2
error
} = this.state;

@@ -99,3 +98,3 @@ let childToRender = children;

const props = {
error: error2,
error,
resetErrorBoundary: this.resetErrorBoundary

@@ -110,3 +109,3 @@ };

} else {
throw error2;
throw error;
}

@@ -117,3 +116,3 @@ }

didCatch,
error: error2,
error,
resetErrorBoundary: this.resetErrorBoundary

@@ -129,1022 +128,3 @@ }

}
const BROWSER_LOG_KEY = "FEDERATION_DEBUG";
const BROWSER_LOG_VALUE = "1";
function isBrowserEnv() {
return typeof window !== "undefined";
}
function isDebugMode() {
if (typeof process !== "undefined" && process.env && process.env["FEDERATION_DEBUG"]) {
return Boolean(process.env["FEDERATION_DEBUG"]);
}
return typeof FEDERATION_DEBUG !== "undefined" && Boolean(FEDERATION_DEBUG);
}
const DEBUG_LOG = "[ FEDERATION DEBUG ]";
function safeToString$1(info) {
try {
return JSON.stringify(info, null, 2);
} catch (e) {
return "";
}
}
function safeGetLocalStorageItem() {
try {
if (typeof window !== "undefined" && window.localStorage) {
return localStorage.getItem(BROWSER_LOG_KEY) === BROWSER_LOG_VALUE;
}
} catch (error2) {
return typeof document !== "undefined";
}
return false;
}
let Logger = class Logger2 {
info(msg, info) {
if (this.enable) {
const argsToString = safeToString$1(info) || "";
if (isBrowserEnv()) {
console.info(`%c ${this.identifier}: ${msg} ${argsToString}`, "color:#3300CC");
} else {
console.info("\x1B[34m%s", `${this.identifier}: ${msg} ${argsToString ? `
${argsToString}` : ""}`);
}
}
}
logOriginalInfo(...args) {
if (this.enable) {
if (isBrowserEnv()) {
console.info(`%c ${this.identifier}: OriginalInfo`, "color:#3300CC");
console.log(...args);
} else {
console.info(`%c ${this.identifier}: OriginalInfo`, "color:#3300CC");
console.log(...args);
}
}
}
constructor(identifier) {
this.enable = false;
this.identifier = identifier || DEBUG_LOG;
if (isBrowserEnv() && safeGetLocalStorageItem()) {
this.enable = true;
} else if (isDebugMode()) {
this.enable = true;
}
}
};
new Logger();
function _extends() {
_extends = Object.assign || function assign(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 _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;
}
function getBuilderId() {
return typeof FEDERATION_BUILD_IDENTIFIER !== "undefined" ? FEDERATION_BUILD_IDENTIFIER : "";
}
const LOG_CATEGORY = "[ Federation Runtime ]";
function assert(condition, msg) {
if (!condition) {
error(msg);
}
}
function error(msg) {
if (msg instanceof Error) {
msg.message = `${LOG_CATEGORY}: ${msg.message}`;
throw msg;
}
throw new Error(`${LOG_CATEGORY}: ${msg}`);
}
function warn(msg) {
if (msg instanceof Error) {
msg.message = `${LOG_CATEGORY}: ${msg.message}`;
console.warn(msg);
} else {
console.warn(`${LOG_CATEGORY}: ${msg}`);
}
}
function getFMId(remoteInfo) {
if ("version" in remoteInfo && remoteInfo.version) {
return `${remoteInfo.name}:${remoteInfo.version}`;
} else if ("entry" in remoteInfo && remoteInfo.entry) {
return `${remoteInfo.name}:${remoteInfo.entry}`;
} else {
return `${remoteInfo.name}`;
}
}
function isObject(val) {
return val && typeof val === "object";
}
const objectToString = Object.prototype.toString;
function isPlainObject(val) {
return objectToString.call(val) === "[object Object]";
}
const nativeGlobal = (() => {
try {
return new Function("return this")();
} catch (e) {
return globalThis;
}
})();
const Global = nativeGlobal;
function definePropertyGlobalVal(target, key, val) {
Object.defineProperty(target, key, {
value: val,
configurable: false,
writable: true
});
}
function includeOwnProperty(target, key) {
return Object.hasOwnProperty.call(target, key);
}
if (!includeOwnProperty(globalThis, "__GLOBAL_LOADING_REMOTE_ENTRY__")) {
definePropertyGlobalVal(globalThis, "__GLOBAL_LOADING_REMOTE_ENTRY__", {});
}
function setGlobalDefaultVal(target) {
var _target___FEDERATION__, _target___FEDERATION__1, _target___FEDERATION__2, _target___FEDERATION__3, _target___FEDERATION__4, _target___FEDERATION__5;
if (includeOwnProperty(target, "__VMOK__") && !includeOwnProperty(target, "__FEDERATION__")) {
definePropertyGlobalVal(target, "__FEDERATION__", target.__VMOK__);
}
if (!includeOwnProperty(target, "__FEDERATION__")) {
definePropertyGlobalVal(target, "__FEDERATION__", {
__GLOBAL_PLUGIN__: [],
__INSTANCES__: [],
moduleInfo: {},
__SHARE__: {},
__MANIFEST_LOADING__: {},
__PRELOADED_MAP__: /* @__PURE__ */ new Map()
});
definePropertyGlobalVal(target, "__VMOK__", target.__FEDERATION__);
}
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 ___PRELOADED_MAP__;
(___PRELOADED_MAP__ = (_target___FEDERATION__5 = target.__FEDERATION__).__PRELOADED_MAP__) != null ? ___PRELOADED_MAP__ : _target___FEDERATION__5.__PRELOADED_MAP__ = /* @__PURE__ */ new Map();
}
setGlobalDefaultVal(globalThis);
setGlobalDefaultVal(nativeGlobal);
function resetFederationGlobalInfo() {
globalThis.__FEDERATION__.__GLOBAL_PLUGIN__ = [];
globalThis.__FEDERATION__.__INSTANCES__ = [];
globalThis.__FEDERATION__.moduleInfo = {};
globalThis.__FEDERATION__.__SHARE__ = {};
globalThis.__FEDERATION__.__MANIFEST_LOADING__ = {};
}
function getGlobalFederationInstance(name, version) {
const buildId = getBuilderId();
return globalThis.__FEDERATION__.__INSTANCES__.find((GMInstance) => {
if (buildId && GMInstance.options.id === getBuilderId()) {
return true;
}
if (GMInstance.options.name === name && !GMInstance.options.version && !version) {
return true;
}
if (GMInstance.options.name === name && version && GMInstance.options.version === version) {
return true;
}
return false;
});
}
function setGlobalFederationInstance(FederationInstance) {
globalThis.__FEDERATION__.__INSTANCES__.push(FederationInstance);
}
function getGlobalFederationConstructor() {
return globalThis.__FEDERATION__.__DEBUG_CONSTRUCTOR__;
}
function setGlobalFederationConstructor(FederationConstructor, isDebug = isDebugMode()) {
if (isDebug) {
globalThis.__FEDERATION__.__DEBUG_CONSTRUCTOR__ = FederationConstructor;
globalThis.__FEDERATION__.__DEBUG_CONSTRUCTOR_VERSION__ = "0.6.11";
}
}
function getInfoWithoutType(target, key) {
if (typeof key === "string") {
const keyRes = target[key];
if (keyRes) {
return {
value: target[key],
key
};
} else {
const targetKeys = Object.keys(target);
for (const targetKey of targetKeys) {
const [targetTypeOrName, _] = targetKey.split(":");
const nKey = `${targetTypeOrName}:${key}`;
const typeWithKeyRes = target[nKey];
if (typeWithKeyRes) {
return {
value: typeWithKeyRes,
key: nKey
};
}
}
return {
value: void 0,
key
};
}
} else {
throw new Error("key must be string");
}
}
const getGlobalSnapshot = () => nativeGlobal.__FEDERATION__.moduleInfo;
const getTargetSnapshotInfoByModuleInfo = (moduleInfo, snapshot) => {
const moduleKey = getFMId(moduleInfo);
const getModuleInfo = getInfoWithoutType(snapshot, moduleKey).value;
if (getModuleInfo && !getModuleInfo.version && "version" in moduleInfo && moduleInfo["version"]) {
getModuleInfo.version = moduleInfo["version"];
}
if (getModuleInfo) {
return getModuleInfo;
}
if ("version" in moduleInfo && moduleInfo["version"]) {
const { version } = moduleInfo, resModuleInfo = _object_without_properties_loose(moduleInfo, [
"version"
]);
const moduleKeyWithoutVersion = getFMId(resModuleInfo);
const getModuleInfoWithoutVersion = getInfoWithoutType(nativeGlobal.__FEDERATION__.moduleInfo, moduleKeyWithoutVersion).value;
if ((getModuleInfoWithoutVersion == null ? void 0 : getModuleInfoWithoutVersion.version) === version) {
return getModuleInfoWithoutVersion;
}
}
return;
};
const getGlobalSnapshotInfoByModuleInfo = (moduleInfo) => getTargetSnapshotInfoByModuleInfo(moduleInfo, nativeGlobal.__FEDERATION__.moduleInfo);
const setGlobalSnapshotInfoByModuleInfo = (remoteInfo, moduleDetailInfo) => {
const moduleKey = getFMId(remoteInfo);
nativeGlobal.__FEDERATION__.moduleInfo[moduleKey] = moduleDetailInfo;
return nativeGlobal.__FEDERATION__.moduleInfo;
};
const addGlobalSnapshot = (moduleInfos) => {
nativeGlobal.__FEDERATION__.moduleInfo = _extends({}, nativeGlobal.__FEDERATION__.moduleInfo, moduleInfos);
return () => {
const keys = Object.keys(moduleInfos);
for (const key of keys) {
delete nativeGlobal.__FEDERATION__.moduleInfo[key];
}
};
};
const getRemoteEntryExports = (name, globalName) => {
const remoteEntryKey = globalName || `__FEDERATION_${name}:custom__`;
const entryExports = globalThis[remoteEntryKey];
return {
remoteEntryKey,
entryExports
};
};
const registerGlobalPlugins = (plugins) => {
const { __GLOBAL_PLUGIN__ } = nativeGlobal.__FEDERATION__;
plugins.forEach((plugin) => {
if (__GLOBAL_PLUGIN__.findIndex((p) => p.name === plugin.name) === -1) {
__GLOBAL_PLUGIN__.push(plugin);
} else {
warn(`The plugin ${plugin.name} has been registered.`);
}
});
};
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);
function registerPlugins(plugins, hookInstances) {
const globalPlugins = getGlobalHostPlugins();
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";
class SyncHook {
on(fn) {
if (typeof fn === "function") {
this.listeners.add(fn);
}
}
once(fn) {
const self = this;
this.on(function wrapper(...args) {
self.remove(wrapper);
return fn.apply(null, args);
});
}
emit(...data) {
let result;
if (this.listeners.size > 0) {
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 = /* @__PURE__ */ 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;
} else if (i < ls.length) {
return Promise.resolve(ls[i++].apply(null, data)).then(call);
} else {
return prev;
}
};
result = call();
}
return Promise.resolve(result);
}
}
function checkReturnData(originalData, returnedData) {
if (!isObject(returnedData)) {
return false;
}
if (originalData !== returnedData) {
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.");
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: registerPlugins2 }) {
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(registerPlugins2).forEach((pluginName) => {
assert(!this.registerPlugins[pluginName], `The plugin "${pluginName}" has a conflict and cannot be inherited.`);
this.applyPlugin(registerPlugins2[pluginName]);
});
}
constructor(lifecycle) {
this.registerPlugins = {};
this.lifecycle = lifecycle;
this.lifecycleKeys = Object.keys(lifecycle);
}
}
const buildIdentifier = "[0-9A-Za-z-]+";
const build = `(?:\\+(${buildIdentifier}(?:\\.${buildIdentifier})*))`;
const numericIdentifier = "0|[1-9]\\d*";
const numericIdentifierLoose = "[0-9]+";
const nonNumericIdentifier = "\\d*[a-zA-Z-][a-zA-Z0-9-]*";
const preReleaseIdentifierLoose = `(?:${numericIdentifierLoose}|${nonNumericIdentifier})`;
const preReleaseLoose = `(?:-?(${preReleaseIdentifierLoose}(?:\\.${preReleaseIdentifierLoose})*))`;
const preReleaseIdentifier = `(?:${numericIdentifier}|${nonNumericIdentifier})`;
const preRelease = `(?:-(${preReleaseIdentifier}(?:\\.${preReleaseIdentifier})*))`;
const xRangeIdentifier = `${numericIdentifier}|x|X|\\*`;
const xRangePlain = `[v=\\s]*(${xRangeIdentifier})(?:\\.(${xRangeIdentifier})(?:\\.(${xRangeIdentifier})(?:${preRelease})?${build}?)?)?`;
const hyphenRange = `^\\s*(${xRangePlain})\\s+-\\s+(${xRangePlain})\\s*$`;
const mainVersionLoose = `(${numericIdentifierLoose})\\.(${numericIdentifierLoose})\\.(${numericIdentifierLoose})`;
const loosePlain = `[v=\\s]*${mainVersionLoose}${preReleaseLoose}?${build}?`;
const gtlt = "((?:<|>)?=?)";
const comparatorTrim = `(\\s*)${gtlt}\\s*(${loosePlain}|${xRangePlain})`;
const loneTilde = "(?:~>?)";
const tildeTrim = `(\\s*)${loneTilde}\\s+`;
const loneCaret = "(?:\\^)";
const caretTrim = `(\\s*)${loneCaret}\\s+`;
const star = "(<|>)?=?\\s*\\*";
const caret = `^${loneCaret}${xRangePlain}$`;
const mainVersion = `(${numericIdentifier})\\.(${numericIdentifier})\\.(${numericIdentifier})`;
const fullPlain = `v?${mainVersion}${preRelease}?${build}?`;
const tilde = `^${loneTilde}${xRangePlain}$`;
const xRange = `^${gtlt}\\s*${xRangePlain}$`;
const comparator = `^${gtlt}\\s*(${fullPlain})$|^$`;
const gte0 = "^\\s*>=\\s*0.0.0\\s*$";
function parseRegex(source) {
return new RegExp(source);
}
function isXVersion(version) {
return !version || version.toLowerCase() === "x" || version === "*";
}
function pipe(...fns) {
return (x) => fns.reduce((v, f) => f(v), x);
}
function extractComparator(comparatorString) {
return comparatorString.match(parseRegex(comparator));
}
function combineVersion(major, minor, patch, preRelease2) {
const mainVersion2 = `${major}.${minor}.${patch}`;
if (preRelease2) {
return `${mainVersion2}-${preRelease2}`;
}
return mainVersion2;
}
function parseHyphen(range) {
return range.replace(parseRegex(hyphenRange), (_range, from, fromMajor, fromMinor, fromPatch, _fromPreRelease, _fromBuild, to, toMajor, toMinor, toPatch, toPreRelease) => {
if (isXVersion(fromMajor)) {
from = "";
} else if (isXVersion(fromMinor)) {
from = `>=${fromMajor}.0.0`;
} else if (isXVersion(fromPatch)) {
from = `>=${fromMajor}.${fromMinor}.0`;
} else {
from = `>=${from}`;
}
if (isXVersion(toMajor)) {
to = "";
} else if (isXVersion(toMinor)) {
to = `<${Number(toMajor) + 1}.0.0-0`;
} else if (isXVersion(toPatch)) {
to = `<${toMajor}.${Number(toMinor) + 1}.0-0`;
} else if (toPreRelease) {
to = `<=${toMajor}.${toMinor}.${toPatch}-${toPreRelease}`;
} else {
to = `<=${to}`;
}
return `${from} ${to}`.trim();
});
}
function parseComparatorTrim(range) {
return range.replace(parseRegex(comparatorTrim), "$1$2$3");
}
function parseTildeTrim(range) {
return range.replace(parseRegex(tildeTrim), "$1~");
}
function parseCaretTrim(range) {
return range.replace(parseRegex(caretTrim), "$1^");
}
function parseCarets(range) {
return range.trim().split(/\s+/).map((rangeVersion) => rangeVersion.replace(parseRegex(caret), (_, major, minor, patch, preRelease2) => {
if (isXVersion(major)) {
return "";
} else if (isXVersion(minor)) {
return `>=${major}.0.0 <${Number(major) + 1}.0.0-0`;
} else if (isXVersion(patch)) {
if (major === "0") {
return `>=${major}.${minor}.0 <${major}.${Number(minor) + 1}.0-0`;
} else {
return `>=${major}.${minor}.0 <${Number(major) + 1}.0.0-0`;
}
} else if (preRelease2) {
if (major === "0") {
if (minor === "0") {
return `>=${major}.${minor}.${patch}-${preRelease2} <${major}.${minor}.${Number(patch) + 1}-0`;
} else {
return `>=${major}.${minor}.${patch}-${preRelease2} <${major}.${Number(minor) + 1}.0-0`;
}
} else {
return `>=${major}.${minor}.${patch}-${preRelease2} <${Number(major) + 1}.0.0-0`;
}
} else {
if (major === "0") {
if (minor === "0") {
return `>=${major}.${minor}.${patch} <${major}.${minor}.${Number(patch) + 1}-0`;
} else {
return `>=${major}.${minor}.${patch} <${major}.${Number(minor) + 1}.0-0`;
}
}
return `>=${major}.${minor}.${patch} <${Number(major) + 1}.0.0-0`;
}
})).join(" ");
}
function parseTildes(range) {
return range.trim().split(/\s+/).map((rangeVersion) => rangeVersion.replace(parseRegex(tilde), (_, major, minor, patch, preRelease2) => {
if (isXVersion(major)) {
return "";
} else if (isXVersion(minor)) {
return `>=${major}.0.0 <${Number(major) + 1}.0.0-0`;
} else if (isXVersion(patch)) {
return `>=${major}.${minor}.0 <${major}.${Number(minor) + 1}.0-0`;
} else if (preRelease2) {
return `>=${major}.${minor}.${patch}-${preRelease2} <${major}.${Number(minor) + 1}.0-0`;
}
return `>=${major}.${minor}.${patch} <${major}.${Number(minor) + 1}.0-0`;
})).join(" ");
}
function parseXRanges(range) {
return range.split(/\s+/).map((rangeVersion) => rangeVersion.trim().replace(parseRegex(xRange), (ret, gtlt2, major, minor, patch, preRelease2) => {
const isXMajor = isXVersion(major);
const isXMinor = isXMajor || isXVersion(minor);
const isXPatch = isXMinor || isXVersion(patch);
if (gtlt2 === "=" && isXPatch) {
gtlt2 = "";
}
preRelease2 = "";
if (isXMajor) {
if (gtlt2 === ">" || gtlt2 === "<") {
return "<0.0.0-0";
} else {
return "*";
}
} else if (gtlt2 && isXPatch) {
if (isXMinor) {
minor = 0;
}
patch = 0;
if (gtlt2 === ">") {
gtlt2 = ">=";
if (isXMinor) {
major = Number(major) + 1;
minor = 0;
patch = 0;
} else {
minor = Number(minor) + 1;
patch = 0;
}
} else if (gtlt2 === "<=") {
gtlt2 = "<";
if (isXMinor) {
major = Number(major) + 1;
} else {
minor = Number(minor) + 1;
}
}
if (gtlt2 === "<") {
preRelease2 = "-0";
}
return `${gtlt2 + major}.${minor}.${patch}${preRelease2}`;
} else if (isXMinor) {
return `>=${major}.0.0${preRelease2} <${Number(major) + 1}.0.0-0`;
} else if (isXPatch) {
return `>=${major}.${minor}.0${preRelease2} <${major}.${Number(minor) + 1}.0-0`;
}
return ret;
})).join(" ");
}
function parseStar(range) {
return range.trim().replace(parseRegex(star), "");
}
function parseGTE0(comparatorString) {
return comparatorString.trim().replace(parseRegex(gte0), "");
}
function compareAtom(rangeAtom, versionAtom) {
rangeAtom = Number(rangeAtom) || rangeAtom;
versionAtom = Number(versionAtom) || versionAtom;
if (rangeAtom > versionAtom) {
return 1;
}
if (rangeAtom === versionAtom) {
return 0;
}
return -1;
}
function comparePreRelease(rangeAtom, versionAtom) {
const { preRelease: rangePreRelease } = rangeAtom;
const { preRelease: versionPreRelease } = versionAtom;
if (rangePreRelease === void 0 && Boolean(versionPreRelease)) {
return 1;
}
if (Boolean(rangePreRelease) && versionPreRelease === void 0) {
return -1;
}
if (rangePreRelease === void 0 && versionPreRelease === void 0) {
return 0;
}
for (let i = 0, n = rangePreRelease.length; i <= n; i++) {
const rangeElement = rangePreRelease[i];
const versionElement = versionPreRelease[i];
if (rangeElement === versionElement) {
continue;
}
if (rangeElement === void 0 && versionElement === void 0) {
return 0;
}
if (!rangeElement) {
return 1;
}
if (!versionElement) {
return -1;
}
return compareAtom(rangeElement, versionElement);
}
return 0;
}
function compareVersion(rangeAtom, versionAtom) {
return compareAtom(rangeAtom.major, versionAtom.major) || compareAtom(rangeAtom.minor, versionAtom.minor) || compareAtom(rangeAtom.patch, versionAtom.patch) || comparePreRelease(rangeAtom, versionAtom);
}
function eq(rangeAtom, versionAtom) {
return rangeAtom.version === versionAtom.version;
}
function compare(rangeAtom, versionAtom) {
switch (rangeAtom.operator) {
case "":
case "=":
return eq(rangeAtom, versionAtom);
case ">":
return compareVersion(rangeAtom, versionAtom) < 0;
case ">=":
return eq(rangeAtom, versionAtom) || compareVersion(rangeAtom, versionAtom) < 0;
case "<":
return compareVersion(rangeAtom, versionAtom) > 0;
case "<=":
return eq(rangeAtom, versionAtom) || compareVersion(rangeAtom, versionAtom) > 0;
case void 0: {
return true;
}
default:
return false;
}
}
function parseComparatorString(range) {
return pipe(
// handle caret
// ^ --> * (any, kinda silly)
// ^2, ^2.x, ^2.x.x --> >=2.0.0 <3.0.0-0
// ^2.0, ^2.0.x --> >=2.0.0 <3.0.0-0
// ^1.2, ^1.2.x --> >=1.2.0 <2.0.0-0
// ^1.2.3 --> >=1.2.3 <2.0.0-0
// ^1.2.0 --> >=1.2.0 <2.0.0-0
parseCarets,
// handle tilde
// ~, ~> --> * (any, kinda silly)
// ~2, ~2.x, ~2.x.x, ~>2, ~>2.x ~>2.x.x --> >=2.0.0 <3.0.0-0
// ~2.0, ~2.0.x, ~>2.0, ~>2.0.x --> >=2.0.0 <2.1.0-0
// ~1.2, ~1.2.x, ~>1.2, ~>1.2.x --> >=1.2.0 <1.3.0-0
// ~1.2.3, ~>1.2.3 --> >=1.2.3 <1.3.0-0
// ~1.2.0, ~>1.2.0 --> >=1.2.0 <1.3.0-0
parseTildes,
parseXRanges,
parseStar
)(range);
}
function parseRange(range) {
return pipe(
// handle hyphenRange
// `1.2.3 - 1.2.4` => `>=1.2.3 <=1.2.4`
parseHyphen,
// handle trim comparator
// `> 1.2.3 < 1.2.5` => `>1.2.3 <1.2.5`
parseComparatorTrim,
// handle trim tilde
// `~ 1.2.3` => `~1.2.3`
parseTildeTrim,
// handle trim caret
// `^ 1.2.3` => `^1.2.3`
parseCaretTrim
)(range.trim()).split(/\s+/).join(" ");
}
function satisfy(version, range) {
if (!version) {
return false;
}
const parsedRange = parseRange(range);
const parsedComparator = parsedRange.split(" ").map((rangeVersion) => parseComparatorString(rangeVersion)).join(" ");
const comparators = parsedComparator.split(/\s+/).map((comparator2) => parseGTE0(comparator2));
const extractedVersion = extractComparator(version);
if (!extractedVersion) {
return false;
}
const [, versionOperator, , versionMajor, versionMinor, versionPatch, versionPreRelease] = extractedVersion;
const versionAtom = {
operator: versionOperator,
version: combineVersion(versionMajor, versionMinor, versionPatch, versionPreRelease),
major: versionMajor,
minor: versionMinor,
patch: versionPatch,
preRelease: versionPreRelease == null ? void 0 : versionPreRelease.split(".")
};
for (const comparator2 of comparators) {
const extractedComparator = extractComparator(comparator2);
if (!extractedComparator) {
return false;
}
const [, rangeOperator, , rangeMajor, rangeMinor, rangePatch, rangePreRelease] = extractedComparator;
const rangeAtom = {
operator: rangeOperator,
version: combineVersion(rangeMajor, rangeMinor, rangePatch, rangePreRelease),
major: rangeMajor,
minor: rangeMinor,
patch: rangePatch,
preRelease: rangePreRelease == null ? void 0 : rangePreRelease.split(".")
};
if (!compare(rangeAtom, versionAtom)) {
return false;
}
}
return true;
}
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)}`)) {
return true;
} else {
return false;
}
}
const findVersion = (shareVersionMap, cb) => {
const callback = cb || function(prev, cur) {
return versionLt(prev, cur);
};
return Object.keys(shareVersionMap).reduce((prev, cur) => {
if (!prev) {
return cur;
}
if (callback(prev, cur)) {
return cur;
}
if (prev === "0") {
return cur;
}
return prev;
}, 0);
};
const isLoaded = (shared) => {
return Boolean(shared.loaded) || typeof shared.lib === "function";
};
function findSingletonVersionOrderByVersion(shareScopeMap, scope, pkgName) {
const versions = shareScopeMap[scope][pkgName];
const callback = function(prev, cur) {
return !isLoaded(versions[prev]) && versionLt(prev, cur);
};
return findVersion(shareScopeMap[scope][pkgName], callback);
}
function findSingletonVersionOrderByLoaded(shareScopeMap, scope, pkgName) {
const versions = shareScopeMap[scope][pkgName];
const callback = function(prev, cur) {
if (isLoaded(versions[cur])) {
if (isLoaded(versions[prev])) {
return Boolean(versionLt(prev, cur));
} else {
return true;
}
}
if (isLoaded(versions[prev])) {
return false;
}
return versionLt(prev, cur);
};
return findVersion(shareScopeMap[scope][pkgName], callback);
}
function getFindShareFunction(strategy) {
if (strategy === "loaded-first") {
return findSingletonVersionOrderByLoaded;
}
return findSingletonVersionOrderByVersion;
}
function getRegisteredShare(localShareScopeMap, pkgName, shareInfo, resolveShare) {
if (!localShareScopeMap) {
return;
}
const { shareConfig, scope = DEFAULT_SCOPE, strategy } = shareInfo;
const scopes = Array.isArray(scope) ? scope : [
scope
];
for (const sc of scopes) {
if (shareConfig && localShareScopeMap[sc] && localShareScopeMap[sc][pkgName]) {
const { requiredVersion } = shareConfig;
const findShareFunction = getFindShareFunction(strategy);
const maxOrSingletonVersion = findShareFunction(localShareScopeMap, sc, pkgName);
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);
}
}
return localShareScopeMap[sc][pkgName][maxOrSingletonVersion];
} else {
if (requiredVersion === false || requiredVersion === "*") {
return localShareScopeMap[sc][pkgName][maxOrSingletonVersion];
}
if (satisfy(maxOrSingletonVersion, 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();
}
}
}
function getGlobalShareScope() {
return Global.__FEDERATION__.__SHARE__;
}
var pluginHelper = /* @__PURE__ */ Object.freeze({
__proto__: null,
AsyncHook,
AsyncWaterfallHook,
PluginSystem,
SyncHook,
SyncWaterfallHook
});
const ShareUtils = {
getRegisteredShare,
getGlobalShareScope
};
const GlobalUtils = {
Global,
nativeGlobal,
resetFederationGlobalInfo,
getGlobalFederationInstance,
setGlobalFederationInstance,
getGlobalFederationConstructor,
setGlobalFederationConstructor,
getInfoWithoutType,
getGlobalSnapshot,
getTargetSnapshotInfoByModuleInfo,
getGlobalSnapshotInfoByModuleInfo,
setGlobalSnapshotInfoByModuleInfo,
addGlobalSnapshot,
getRemoteEntryExports,
registerGlobalPlugins,
getGlobalHostPlugins,
getPreloaded,
setPreloaded,
registerPlugins,
pluginHelper
};
var helpers = {
global: GlobalUtils,
share: ShareUtils
};
function registerBridgeLifeCycle() {
var _a;
const { registerPlugins: registerPlugins2, pluginHelper: pluginHelper2 } = helpers.global;
const host = runtime.getInstance();
const pluginSystem = new pluginHelper2.PluginSystem({
beforeBridgeRender: new pluginHelper2.SyncHook(),
afterBridgeRender: new pluginHelper2.SyncHook(),
beforeBridgeDestroy: new pluginHelper2.SyncHook(),
afterBridgeDestroy: new pluginHelper2.SyncHook()
});
if (host) {
registerPlugins2(
(_a = host == null ? void 0 : host.options) == null ? void 0 : _a.plugins,
[pluginSystem]
);
return pluginSystem;
}
return null;
}
const getModuleName = (id) => {
const idArray = id.split("/");
if (idArray.length < 2) {
return id;
}
return idArray[0] + "/" + idArray[1];
};
const getRootDomDefaultClassName = (moduleName) => {
const name = getModuleName(moduleName).replace(/\@/, "").replace(/\//, "-");
return `bridge-root-component-${name}`;
};
const RemoteAppWrapper = React.forwardRef(function(props, ref) {
const bridgeHook = registerBridgeLifeCycle();
const RemoteApp2 = () => {

@@ -1167,6 +147,5 @@ context.LoggerInstance.log(`RemoteAppWrapper RemoteApp props >>>`, { props });

const renderTimeout = setTimeout(() => {
var _a, _b;
const providerReturn = providerInfo();
providerInfoRef.current = providerReturn;
let renderProps = {
const renderProps = {
moduleName,

@@ -1184,12 +163,2 @@ dom: rootRef.current,

);
if (bridgeHook && ((_a = bridgeHook == null ? void 0 : bridgeHook.lifecycle) == null ? void 0 : _a.beforeBridgeRender)) {
const beforeBridgeRenderRes = (_b = bridgeHook == null ? void 0 : bridgeHook.lifecycle) == null ? void 0 : _b.beforeBridgeRender.emit({
...renderProps
});
const extraProps = beforeBridgeRenderRes && typeof beforeBridgeRenderRes === "object" && (beforeBridgeRenderRes == null ? void 0 : beforeBridgeRenderRes.extraProps) ? beforeBridgeRenderRes == null ? void 0 : beforeBridgeRenderRes.extraProps : {};
renderProps = {
...renderProps,
...extraProps
};
}
providerReturn.render(renderProps);

@@ -1200,3 +169,3 @@ });

setTimeout(() => {
var _a, _b, _c, _d;
var _a, _b;
if ((_a = providerInfoRef.current) == null ? void 0 : _a.destroy) {

@@ -1207,13 +176,3 @@ context.LoggerInstance.log(

);
if (bridgeHook && ((_b = bridgeHook == null ? void 0 : bridgeHook.lifecycle) == null ? void 0 : _b.afterBridgeDestroy)) {
(_c = bridgeHook == null ? void 0 : bridgeHook.lifecycle) == null ? void 0 : _c.afterBridgeDestroy.emit({
moduleName,
dom: renderDom.current,
basename,
memoryRoute,
fallback,
...resProps
});
}
(_d = providerInfoRef.current) == null ? void 0 : _d.destroy({
(_b = providerInfoRef.current) == null ? void 0 : _b.destroy({
dom: renderDom.current

@@ -1225,7 +184,6 @@ });

}, []);
const rootComponentClassName = `${getRootDomDefaultClassName(moduleName)} ${props == null ? void 0 : props.className}`;
return /* @__PURE__ */ React.createElement(
"div",
{
className: rootComponentClassName,
className: props == null ? void 0 : props.className,
style: props == null ? void 0 : props.style,

@@ -1348,4 +306,4 @@ ref: rootRef

}
} catch (error2) {
throw error2;
} catch (error) {
throw error;
}

@@ -1387,3 +345,3 @@ });

function createBridgeComponent(bridgeInfo) {
return (params) => {
return () => {
const rootMap = /* @__PURE__ */ new Map();

@@ -1404,3 +362,2 @@ const RawComponent = (info) => {

async render(info) {
var _a, _b;
context.LoggerInstance.log(`createBridgeComponent render Info`, info);

@@ -1415,5 +372,2 @@ const {

} = info;
const beforeBridgeRender = (bridgeInfo == null ? void 0 : bridgeInfo.hooks) && (bridgeInfo == null ? void 0 : bridgeInfo.hooks.beforeBridgeRender) || ((_a = params == null ? void 0 : params.hooks) == null ? void 0 : _a.beforeBridgeRender);
const beforeBridgeRenderRes = beforeBridgeRender && beforeBridgeRender(info);
const extraProps = beforeBridgeRenderRes && typeof beforeBridgeRenderRes === "object" && (beforeBridgeRenderRes == null ? void 0 : beforeBridgeRenderRes.extraProps) ? beforeBridgeRenderRes == null ? void 0 : beforeBridgeRenderRes.extraProps : {};
const rootComponentWithErrorBoundary = (

@@ -1429,3 +383,3 @@ // set ErrorBoundary for RawComponent rendering error, usually caused by user app rendering error

},
propsInfo: { ...propsInfo, ...extraProps }
propsInfo
}

@@ -1448,15 +402,7 @@ ))

}
const afterBridgeRender = (bridgeInfo == null ? void 0 : bridgeInfo.hooks) && (bridgeInfo == null ? void 0 : bridgeInfo.hooks.afterBridgeDestroy) || ((_b = params == null ? void 0 : params.hooks) == null ? void 0 : _b.afterBridgeRender);
afterBridgeRender && afterBridgeRender(info);
},
async destroy(info) {
var _a, _b;
context.LoggerInstance.log(`createBridgeComponent destroy Info`, {
dom: info.dom
});
if ((bridgeInfo == null ? void 0 : bridgeInfo.hooks) && (bridgeInfo == null ? void 0 : bridgeInfo.hooks.beforeBridgeDestroy) && typeof (bridgeInfo == null ? void 0 : bridgeInfo.hooks.beforeBridgeDestroy) === "function") {
bridgeInfo.hooks.beforeBridgeDestroy(info);
}
const beforeBridgeDestroy = (bridgeInfo == null ? void 0 : bridgeInfo.hooks) && (bridgeInfo == null ? void 0 : bridgeInfo.hooks.beforeBridgeDestroy) || ((_a = params == null ? void 0 : params.hooks) == null ? void 0 : _a.beforeBridgeDestroy);
beforeBridgeDestroy && beforeBridgeDestroy(info);
if (context.atLeastReact18(React__namespace)) {

@@ -1469,4 +415,2 @@ const root = rootMap.get(info.dom);

}
const afterBridgeDestroy = (bridgeInfo == null ? void 0 : bridgeInfo.hooks) && (bridgeInfo == null ? void 0 : bridgeInfo.hooks.afterBridgeDestroy) || ((_b = params == null ? void 0 : params.hooks) == null ? void 0 : _b.afterBridgeDestroy);
afterBridgeDestroy && afterBridgeDestroy(info);
},

@@ -1473,0 +417,0 @@ rawComponent: bridgeInfo.rootComponent,

@@ -8,14 +8,7 @@ import { ComponentType } from 'react';

declare type BridgeHooks = {
beforeBridgeRender?: (params: RenderFnParams) => any;
afterBridgeRender?: (params: RenderFnParams) => any;
beforeBridgeDestroy?: (params: DestroyParams) => any;
afterBridgeDestroy?: (params: DestroyParams) => any;
};
export declare function createBridgeComponent<T>(bridgeInfo: ProviderFnParams<T>): (params: {
hooks?: BridgeHooks;
}) => {
render(info: RenderParams): Promise<void>;
destroy(info: DestroyParams): Promise<void>;
export declare function createBridgeComponent<T>(bridgeInfo: ProviderFnParams<T>): () => {
render(info: RenderFnParams & any): Promise<void>;
destroy(info: {
dom: HTMLElement;
}): Promise<void>;
rawComponent: React_2.ComponentType<T>;

@@ -32,6 +25,2 @@ __BRIDGE_FN__: (_args: T) => void;

declare type DestroyParams = {
dom: HTMLElement;
};
declare type ErrorBoundaryPropsWithComponent = ErrorBoundarySharedProps & {

@@ -64,3 +53,2 @@ fallback?: never;

render?: (App: React_2.ReactElement, id?: HTMLElement | string) => RootType | Promise<RootType>;
hooks?: BridgeHooks;
};

@@ -82,6 +70,4 @@

declare type RenderParams = RenderFnParams & any;
declare type RootType = HTMLElement | default_3.Root;
export { }

@@ -5,3 +5,2 @@ import * as React from "react";

import * as ReactRouterDOM from "react-router-dom";
import { getInstance } from "@module-federation/runtime";
import ReactDOM from "react-dom";

@@ -19,6 +18,6 @@ const ErrorBoundaryContext = createContext(null);

}
static getDerivedStateFromError(error2) {
static getDerivedStateFromError(error) {
return {
didCatch: true,
error: error2
error
};

@@ -28,5 +27,5 @@ }

const {
error: error2
error
} = this.state;
if (error2 !== null) {
if (error !== null) {
var _this$props$onReset, _this$props;

@@ -43,5 +42,5 @@ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {

}
componentDidCatch(error2, info) {
componentDidCatch(error, info) {
var _this$props$onError, _this$props2;
(_this$props$onError = (_this$props2 = this.props).onError) === null || _this$props$onError === void 0 ? void 0 : _this$props$onError.call(_this$props2, error2, info);
(_this$props$onError = (_this$props2 = this.props).onError) === null || _this$props$onError === void 0 ? void 0 : _this$props$onError.call(_this$props2, error, info);
}

@@ -74,3 +73,3 @@ componentDidUpdate(prevProps, prevState) {

didCatch,
error: error2
error
} = this.state;

@@ -80,3 +79,3 @@ let childToRender = children;

const props = {
error: error2,
error,
resetErrorBoundary: this.resetErrorBoundary

@@ -91,3 +90,3 @@ };

} else {
throw error2;
throw error;
}

@@ -98,3 +97,3 @@ }

didCatch,
error: error2,
error,
resetErrorBoundary: this.resetErrorBoundary

@@ -110,1022 +109,3 @@ }

}
const BROWSER_LOG_KEY = "FEDERATION_DEBUG";
const BROWSER_LOG_VALUE = "1";
function isBrowserEnv() {
return typeof window !== "undefined";
}
function isDebugMode() {
if (typeof process !== "undefined" && process.env && process.env["FEDERATION_DEBUG"]) {
return Boolean(process.env["FEDERATION_DEBUG"]);
}
return typeof FEDERATION_DEBUG !== "undefined" && Boolean(FEDERATION_DEBUG);
}
const DEBUG_LOG = "[ FEDERATION DEBUG ]";
function safeToString$1(info) {
try {
return JSON.stringify(info, null, 2);
} catch (e) {
return "";
}
}
function safeGetLocalStorageItem() {
try {
if (typeof window !== "undefined" && window.localStorage) {
return localStorage.getItem(BROWSER_LOG_KEY) === BROWSER_LOG_VALUE;
}
} catch (error2) {
return typeof document !== "undefined";
}
return false;
}
let Logger = class Logger2 {
info(msg, info) {
if (this.enable) {
const argsToString = safeToString$1(info) || "";
if (isBrowserEnv()) {
console.info(`%c ${this.identifier}: ${msg} ${argsToString}`, "color:#3300CC");
} else {
console.info("\x1B[34m%s", `${this.identifier}: ${msg} ${argsToString ? `
${argsToString}` : ""}`);
}
}
}
logOriginalInfo(...args) {
if (this.enable) {
if (isBrowserEnv()) {
console.info(`%c ${this.identifier}: OriginalInfo`, "color:#3300CC");
console.log(...args);
} else {
console.info(`%c ${this.identifier}: OriginalInfo`, "color:#3300CC");
console.log(...args);
}
}
}
constructor(identifier) {
this.enable = false;
this.identifier = identifier || DEBUG_LOG;
if (isBrowserEnv() && safeGetLocalStorageItem()) {
this.enable = true;
} else if (isDebugMode()) {
this.enable = true;
}
}
};
new Logger();
function _extends() {
_extends = Object.assign || function assign(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 _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;
}
function getBuilderId() {
return typeof FEDERATION_BUILD_IDENTIFIER !== "undefined" ? FEDERATION_BUILD_IDENTIFIER : "";
}
const LOG_CATEGORY = "[ Federation Runtime ]";
function assert(condition, msg) {
if (!condition) {
error(msg);
}
}
function error(msg) {
if (msg instanceof Error) {
msg.message = `${LOG_CATEGORY}: ${msg.message}`;
throw msg;
}
throw new Error(`${LOG_CATEGORY}: ${msg}`);
}
function warn(msg) {
if (msg instanceof Error) {
msg.message = `${LOG_CATEGORY}: ${msg.message}`;
console.warn(msg);
} else {
console.warn(`${LOG_CATEGORY}: ${msg}`);
}
}
function getFMId(remoteInfo) {
if ("version" in remoteInfo && remoteInfo.version) {
return `${remoteInfo.name}:${remoteInfo.version}`;
} else if ("entry" in remoteInfo && remoteInfo.entry) {
return `${remoteInfo.name}:${remoteInfo.entry}`;
} else {
return `${remoteInfo.name}`;
}
}
function isObject(val) {
return val && typeof val === "object";
}
const objectToString = Object.prototype.toString;
function isPlainObject(val) {
return objectToString.call(val) === "[object Object]";
}
const nativeGlobal = (() => {
try {
return new Function("return this")();
} catch (e) {
return globalThis;
}
})();
const Global = nativeGlobal;
function definePropertyGlobalVal(target, key, val) {
Object.defineProperty(target, key, {
value: val,
configurable: false,
writable: true
});
}
function includeOwnProperty(target, key) {
return Object.hasOwnProperty.call(target, key);
}
if (!includeOwnProperty(globalThis, "__GLOBAL_LOADING_REMOTE_ENTRY__")) {
definePropertyGlobalVal(globalThis, "__GLOBAL_LOADING_REMOTE_ENTRY__", {});
}
function setGlobalDefaultVal(target) {
var _target___FEDERATION__, _target___FEDERATION__1, _target___FEDERATION__2, _target___FEDERATION__3, _target___FEDERATION__4, _target___FEDERATION__5;
if (includeOwnProperty(target, "__VMOK__") && !includeOwnProperty(target, "__FEDERATION__")) {
definePropertyGlobalVal(target, "__FEDERATION__", target.__VMOK__);
}
if (!includeOwnProperty(target, "__FEDERATION__")) {
definePropertyGlobalVal(target, "__FEDERATION__", {
__GLOBAL_PLUGIN__: [],
__INSTANCES__: [],
moduleInfo: {},
__SHARE__: {},
__MANIFEST_LOADING__: {},
__PRELOADED_MAP__: /* @__PURE__ */ new Map()
});
definePropertyGlobalVal(target, "__VMOK__", target.__FEDERATION__);
}
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 ___PRELOADED_MAP__;
(___PRELOADED_MAP__ = (_target___FEDERATION__5 = target.__FEDERATION__).__PRELOADED_MAP__) != null ? ___PRELOADED_MAP__ : _target___FEDERATION__5.__PRELOADED_MAP__ = /* @__PURE__ */ new Map();
}
setGlobalDefaultVal(globalThis);
setGlobalDefaultVal(nativeGlobal);
function resetFederationGlobalInfo() {
globalThis.__FEDERATION__.__GLOBAL_PLUGIN__ = [];
globalThis.__FEDERATION__.__INSTANCES__ = [];
globalThis.__FEDERATION__.moduleInfo = {};
globalThis.__FEDERATION__.__SHARE__ = {};
globalThis.__FEDERATION__.__MANIFEST_LOADING__ = {};
}
function getGlobalFederationInstance(name, version) {
const buildId = getBuilderId();
return globalThis.__FEDERATION__.__INSTANCES__.find((GMInstance) => {
if (buildId && GMInstance.options.id === getBuilderId()) {
return true;
}
if (GMInstance.options.name === name && !GMInstance.options.version && !version) {
return true;
}
if (GMInstance.options.name === name && version && GMInstance.options.version === version) {
return true;
}
return false;
});
}
function setGlobalFederationInstance(FederationInstance) {
globalThis.__FEDERATION__.__INSTANCES__.push(FederationInstance);
}
function getGlobalFederationConstructor() {
return globalThis.__FEDERATION__.__DEBUG_CONSTRUCTOR__;
}
function setGlobalFederationConstructor(FederationConstructor, isDebug = isDebugMode()) {
if (isDebug) {
globalThis.__FEDERATION__.__DEBUG_CONSTRUCTOR__ = FederationConstructor;
globalThis.__FEDERATION__.__DEBUG_CONSTRUCTOR_VERSION__ = "0.6.11";
}
}
function getInfoWithoutType(target, key) {
if (typeof key === "string") {
const keyRes = target[key];
if (keyRes) {
return {
value: target[key],
key
};
} else {
const targetKeys = Object.keys(target);
for (const targetKey of targetKeys) {
const [targetTypeOrName, _] = targetKey.split(":");
const nKey = `${targetTypeOrName}:${key}`;
const typeWithKeyRes = target[nKey];
if (typeWithKeyRes) {
return {
value: typeWithKeyRes,
key: nKey
};
}
}
return {
value: void 0,
key
};
}
} else {
throw new Error("key must be string");
}
}
const getGlobalSnapshot = () => nativeGlobal.__FEDERATION__.moduleInfo;
const getTargetSnapshotInfoByModuleInfo = (moduleInfo, snapshot) => {
const moduleKey = getFMId(moduleInfo);
const getModuleInfo = getInfoWithoutType(snapshot, moduleKey).value;
if (getModuleInfo && !getModuleInfo.version && "version" in moduleInfo && moduleInfo["version"]) {
getModuleInfo.version = moduleInfo["version"];
}
if (getModuleInfo) {
return getModuleInfo;
}
if ("version" in moduleInfo && moduleInfo["version"]) {
const { version } = moduleInfo, resModuleInfo = _object_without_properties_loose(moduleInfo, [
"version"
]);
const moduleKeyWithoutVersion = getFMId(resModuleInfo);
const getModuleInfoWithoutVersion = getInfoWithoutType(nativeGlobal.__FEDERATION__.moduleInfo, moduleKeyWithoutVersion).value;
if ((getModuleInfoWithoutVersion == null ? void 0 : getModuleInfoWithoutVersion.version) === version) {
return getModuleInfoWithoutVersion;
}
}
return;
};
const getGlobalSnapshotInfoByModuleInfo = (moduleInfo) => getTargetSnapshotInfoByModuleInfo(moduleInfo, nativeGlobal.__FEDERATION__.moduleInfo);
const setGlobalSnapshotInfoByModuleInfo = (remoteInfo, moduleDetailInfo) => {
const moduleKey = getFMId(remoteInfo);
nativeGlobal.__FEDERATION__.moduleInfo[moduleKey] = moduleDetailInfo;
return nativeGlobal.__FEDERATION__.moduleInfo;
};
const addGlobalSnapshot = (moduleInfos) => {
nativeGlobal.__FEDERATION__.moduleInfo = _extends({}, nativeGlobal.__FEDERATION__.moduleInfo, moduleInfos);
return () => {
const keys = Object.keys(moduleInfos);
for (const key of keys) {
delete nativeGlobal.__FEDERATION__.moduleInfo[key];
}
};
};
const getRemoteEntryExports = (name, globalName) => {
const remoteEntryKey = globalName || `__FEDERATION_${name}:custom__`;
const entryExports = globalThis[remoteEntryKey];
return {
remoteEntryKey,
entryExports
};
};
const registerGlobalPlugins = (plugins) => {
const { __GLOBAL_PLUGIN__ } = nativeGlobal.__FEDERATION__;
plugins.forEach((plugin) => {
if (__GLOBAL_PLUGIN__.findIndex((p) => p.name === plugin.name) === -1) {
__GLOBAL_PLUGIN__.push(plugin);
} else {
warn(`The plugin ${plugin.name} has been registered.`);
}
});
};
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);
function registerPlugins(plugins, hookInstances) {
const globalPlugins = getGlobalHostPlugins();
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";
class SyncHook {
on(fn) {
if (typeof fn === "function") {
this.listeners.add(fn);
}
}
once(fn) {
const self = this;
this.on(function wrapper(...args) {
self.remove(wrapper);
return fn.apply(null, args);
});
}
emit(...data) {
let result;
if (this.listeners.size > 0) {
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 = /* @__PURE__ */ 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;
} else if (i < ls.length) {
return Promise.resolve(ls[i++].apply(null, data)).then(call);
} else {
return prev;
}
};
result = call();
}
return Promise.resolve(result);
}
}
function checkReturnData(originalData, returnedData) {
if (!isObject(returnedData)) {
return false;
}
if (originalData !== returnedData) {
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.");
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: registerPlugins2 }) {
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(registerPlugins2).forEach((pluginName) => {
assert(!this.registerPlugins[pluginName], `The plugin "${pluginName}" has a conflict and cannot be inherited.`);
this.applyPlugin(registerPlugins2[pluginName]);
});
}
constructor(lifecycle) {
this.registerPlugins = {};
this.lifecycle = lifecycle;
this.lifecycleKeys = Object.keys(lifecycle);
}
}
const buildIdentifier = "[0-9A-Za-z-]+";
const build = `(?:\\+(${buildIdentifier}(?:\\.${buildIdentifier})*))`;
const numericIdentifier = "0|[1-9]\\d*";
const numericIdentifierLoose = "[0-9]+";
const nonNumericIdentifier = "\\d*[a-zA-Z-][a-zA-Z0-9-]*";
const preReleaseIdentifierLoose = `(?:${numericIdentifierLoose}|${nonNumericIdentifier})`;
const preReleaseLoose = `(?:-?(${preReleaseIdentifierLoose}(?:\\.${preReleaseIdentifierLoose})*))`;
const preReleaseIdentifier = `(?:${numericIdentifier}|${nonNumericIdentifier})`;
const preRelease = `(?:-(${preReleaseIdentifier}(?:\\.${preReleaseIdentifier})*))`;
const xRangeIdentifier = `${numericIdentifier}|x|X|\\*`;
const xRangePlain = `[v=\\s]*(${xRangeIdentifier})(?:\\.(${xRangeIdentifier})(?:\\.(${xRangeIdentifier})(?:${preRelease})?${build}?)?)?`;
const hyphenRange = `^\\s*(${xRangePlain})\\s+-\\s+(${xRangePlain})\\s*$`;
const mainVersionLoose = `(${numericIdentifierLoose})\\.(${numericIdentifierLoose})\\.(${numericIdentifierLoose})`;
const loosePlain = `[v=\\s]*${mainVersionLoose}${preReleaseLoose}?${build}?`;
const gtlt = "((?:<|>)?=?)";
const comparatorTrim = `(\\s*)${gtlt}\\s*(${loosePlain}|${xRangePlain})`;
const loneTilde = "(?:~>?)";
const tildeTrim = `(\\s*)${loneTilde}\\s+`;
const loneCaret = "(?:\\^)";
const caretTrim = `(\\s*)${loneCaret}\\s+`;
const star = "(<|>)?=?\\s*\\*";
const caret = `^${loneCaret}${xRangePlain}$`;
const mainVersion = `(${numericIdentifier})\\.(${numericIdentifier})\\.(${numericIdentifier})`;
const fullPlain = `v?${mainVersion}${preRelease}?${build}?`;
const tilde = `^${loneTilde}${xRangePlain}$`;
const xRange = `^${gtlt}\\s*${xRangePlain}$`;
const comparator = `^${gtlt}\\s*(${fullPlain})$|^$`;
const gte0 = "^\\s*>=\\s*0.0.0\\s*$";
function parseRegex(source) {
return new RegExp(source);
}
function isXVersion(version) {
return !version || version.toLowerCase() === "x" || version === "*";
}
function pipe(...fns) {
return (x) => fns.reduce((v, f2) => f2(v), x);
}
function extractComparator(comparatorString) {
return comparatorString.match(parseRegex(comparator));
}
function combineVersion(major, minor, patch, preRelease2) {
const mainVersion2 = `${major}.${minor}.${patch}`;
if (preRelease2) {
return `${mainVersion2}-${preRelease2}`;
}
return mainVersion2;
}
function parseHyphen(range) {
return range.replace(parseRegex(hyphenRange), (_range, from, fromMajor, fromMinor, fromPatch, _fromPreRelease, _fromBuild, to, toMajor, toMinor, toPatch, toPreRelease) => {
if (isXVersion(fromMajor)) {
from = "";
} else if (isXVersion(fromMinor)) {
from = `>=${fromMajor}.0.0`;
} else if (isXVersion(fromPatch)) {
from = `>=${fromMajor}.${fromMinor}.0`;
} else {
from = `>=${from}`;
}
if (isXVersion(toMajor)) {
to = "";
} else if (isXVersion(toMinor)) {
to = `<${Number(toMajor) + 1}.0.0-0`;
} else if (isXVersion(toPatch)) {
to = `<${toMajor}.${Number(toMinor) + 1}.0-0`;
} else if (toPreRelease) {
to = `<=${toMajor}.${toMinor}.${toPatch}-${toPreRelease}`;
} else {
to = `<=${to}`;
}
return `${from} ${to}`.trim();
});
}
function parseComparatorTrim(range) {
return range.replace(parseRegex(comparatorTrim), "$1$2$3");
}
function parseTildeTrim(range) {
return range.replace(parseRegex(tildeTrim), "$1~");
}
function parseCaretTrim(range) {
return range.replace(parseRegex(caretTrim), "$1^");
}
function parseCarets(range) {
return range.trim().split(/\s+/).map((rangeVersion) => rangeVersion.replace(parseRegex(caret), (_, major, minor, patch, preRelease2) => {
if (isXVersion(major)) {
return "";
} else if (isXVersion(minor)) {
return `>=${major}.0.0 <${Number(major) + 1}.0.0-0`;
} else if (isXVersion(patch)) {
if (major === "0") {
return `>=${major}.${minor}.0 <${major}.${Number(minor) + 1}.0-0`;
} else {
return `>=${major}.${minor}.0 <${Number(major) + 1}.0.0-0`;
}
} else if (preRelease2) {
if (major === "0") {
if (minor === "0") {
return `>=${major}.${minor}.${patch}-${preRelease2} <${major}.${minor}.${Number(patch) + 1}-0`;
} else {
return `>=${major}.${minor}.${patch}-${preRelease2} <${major}.${Number(minor) + 1}.0-0`;
}
} else {
return `>=${major}.${minor}.${patch}-${preRelease2} <${Number(major) + 1}.0.0-0`;
}
} else {
if (major === "0") {
if (minor === "0") {
return `>=${major}.${minor}.${patch} <${major}.${minor}.${Number(patch) + 1}-0`;
} else {
return `>=${major}.${minor}.${patch} <${major}.${Number(minor) + 1}.0-0`;
}
}
return `>=${major}.${minor}.${patch} <${Number(major) + 1}.0.0-0`;
}
})).join(" ");
}
function parseTildes(range) {
return range.trim().split(/\s+/).map((rangeVersion) => rangeVersion.replace(parseRegex(tilde), (_, major, minor, patch, preRelease2) => {
if (isXVersion(major)) {
return "";
} else if (isXVersion(minor)) {
return `>=${major}.0.0 <${Number(major) + 1}.0.0-0`;
} else if (isXVersion(patch)) {
return `>=${major}.${minor}.0 <${major}.${Number(minor) + 1}.0-0`;
} else if (preRelease2) {
return `>=${major}.${minor}.${patch}-${preRelease2} <${major}.${Number(minor) + 1}.0-0`;
}
return `>=${major}.${minor}.${patch} <${major}.${Number(minor) + 1}.0-0`;
})).join(" ");
}
function parseXRanges(range) {
return range.split(/\s+/).map((rangeVersion) => rangeVersion.trim().replace(parseRegex(xRange), (ret, gtlt2, major, minor, patch, preRelease2) => {
const isXMajor = isXVersion(major);
const isXMinor = isXMajor || isXVersion(minor);
const isXPatch = isXMinor || isXVersion(patch);
if (gtlt2 === "=" && isXPatch) {
gtlt2 = "";
}
preRelease2 = "";
if (isXMajor) {
if (gtlt2 === ">" || gtlt2 === "<") {
return "<0.0.0-0";
} else {
return "*";
}
} else if (gtlt2 && isXPatch) {
if (isXMinor) {
minor = 0;
}
patch = 0;
if (gtlt2 === ">") {
gtlt2 = ">=";
if (isXMinor) {
major = Number(major) + 1;
minor = 0;
patch = 0;
} else {
minor = Number(minor) + 1;
patch = 0;
}
} else if (gtlt2 === "<=") {
gtlt2 = "<";
if (isXMinor) {
major = Number(major) + 1;
} else {
minor = Number(minor) + 1;
}
}
if (gtlt2 === "<") {
preRelease2 = "-0";
}
return `${gtlt2 + major}.${minor}.${patch}${preRelease2}`;
} else if (isXMinor) {
return `>=${major}.0.0${preRelease2} <${Number(major) + 1}.0.0-0`;
} else if (isXPatch) {
return `>=${major}.${minor}.0${preRelease2} <${major}.${Number(minor) + 1}.0-0`;
}
return ret;
})).join(" ");
}
function parseStar(range) {
return range.trim().replace(parseRegex(star), "");
}
function parseGTE0(comparatorString) {
return comparatorString.trim().replace(parseRegex(gte0), "");
}
function compareAtom(rangeAtom, versionAtom) {
rangeAtom = Number(rangeAtom) || rangeAtom;
versionAtom = Number(versionAtom) || versionAtom;
if (rangeAtom > versionAtom) {
return 1;
}
if (rangeAtom === versionAtom) {
return 0;
}
return -1;
}
function comparePreRelease(rangeAtom, versionAtom) {
const { preRelease: rangePreRelease } = rangeAtom;
const { preRelease: versionPreRelease } = versionAtom;
if (rangePreRelease === void 0 && Boolean(versionPreRelease)) {
return 1;
}
if (Boolean(rangePreRelease) && versionPreRelease === void 0) {
return -1;
}
if (rangePreRelease === void 0 && versionPreRelease === void 0) {
return 0;
}
for (let i = 0, n = rangePreRelease.length; i <= n; i++) {
const rangeElement = rangePreRelease[i];
const versionElement = versionPreRelease[i];
if (rangeElement === versionElement) {
continue;
}
if (rangeElement === void 0 && versionElement === void 0) {
return 0;
}
if (!rangeElement) {
return 1;
}
if (!versionElement) {
return -1;
}
return compareAtom(rangeElement, versionElement);
}
return 0;
}
function compareVersion(rangeAtom, versionAtom) {
return compareAtom(rangeAtom.major, versionAtom.major) || compareAtom(rangeAtom.minor, versionAtom.minor) || compareAtom(rangeAtom.patch, versionAtom.patch) || comparePreRelease(rangeAtom, versionAtom);
}
function eq(rangeAtom, versionAtom) {
return rangeAtom.version === versionAtom.version;
}
function compare(rangeAtom, versionAtom) {
switch (rangeAtom.operator) {
case "":
case "=":
return eq(rangeAtom, versionAtom);
case ">":
return compareVersion(rangeAtom, versionAtom) < 0;
case ">=":
return eq(rangeAtom, versionAtom) || compareVersion(rangeAtom, versionAtom) < 0;
case "<":
return compareVersion(rangeAtom, versionAtom) > 0;
case "<=":
return eq(rangeAtom, versionAtom) || compareVersion(rangeAtom, versionAtom) > 0;
case void 0: {
return true;
}
default:
return false;
}
}
function parseComparatorString(range) {
return pipe(
// handle caret
// ^ --> * (any, kinda silly)
// ^2, ^2.x, ^2.x.x --> >=2.0.0 <3.0.0-0
// ^2.0, ^2.0.x --> >=2.0.0 <3.0.0-0
// ^1.2, ^1.2.x --> >=1.2.0 <2.0.0-0
// ^1.2.3 --> >=1.2.3 <2.0.0-0
// ^1.2.0 --> >=1.2.0 <2.0.0-0
parseCarets,
// handle tilde
// ~, ~> --> * (any, kinda silly)
// ~2, ~2.x, ~2.x.x, ~>2, ~>2.x ~>2.x.x --> >=2.0.0 <3.0.0-0
// ~2.0, ~2.0.x, ~>2.0, ~>2.0.x --> >=2.0.0 <2.1.0-0
// ~1.2, ~1.2.x, ~>1.2, ~>1.2.x --> >=1.2.0 <1.3.0-0
// ~1.2.3, ~>1.2.3 --> >=1.2.3 <1.3.0-0
// ~1.2.0, ~>1.2.0 --> >=1.2.0 <1.3.0-0
parseTildes,
parseXRanges,
parseStar
)(range);
}
function parseRange(range) {
return pipe(
// handle hyphenRange
// `1.2.3 - 1.2.4` => `>=1.2.3 <=1.2.4`
parseHyphen,
// handle trim comparator
// `> 1.2.3 < 1.2.5` => `>1.2.3 <1.2.5`
parseComparatorTrim,
// handle trim tilde
// `~ 1.2.3` => `~1.2.3`
parseTildeTrim,
// handle trim caret
// `^ 1.2.3` => `^1.2.3`
parseCaretTrim
)(range.trim()).split(/\s+/).join(" ");
}
function satisfy(version, range) {
if (!version) {
return false;
}
const parsedRange = parseRange(range);
const parsedComparator = parsedRange.split(" ").map((rangeVersion) => parseComparatorString(rangeVersion)).join(" ");
const comparators = parsedComparator.split(/\s+/).map((comparator2) => parseGTE0(comparator2));
const extractedVersion = extractComparator(version);
if (!extractedVersion) {
return false;
}
const [, versionOperator, , versionMajor, versionMinor, versionPatch, versionPreRelease] = extractedVersion;
const versionAtom = {
operator: versionOperator,
version: combineVersion(versionMajor, versionMinor, versionPatch, versionPreRelease),
major: versionMajor,
minor: versionMinor,
patch: versionPatch,
preRelease: versionPreRelease == null ? void 0 : versionPreRelease.split(".")
};
for (const comparator2 of comparators) {
const extractedComparator = extractComparator(comparator2);
if (!extractedComparator) {
return false;
}
const [, rangeOperator, , rangeMajor, rangeMinor, rangePatch, rangePreRelease] = extractedComparator;
const rangeAtom = {
operator: rangeOperator,
version: combineVersion(rangeMajor, rangeMinor, rangePatch, rangePreRelease),
major: rangeMajor,
minor: rangeMinor,
patch: rangePatch,
preRelease: rangePreRelease == null ? void 0 : rangePreRelease.split(".")
};
if (!compare(rangeAtom, versionAtom)) {
return false;
}
}
return true;
}
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)}`)) {
return true;
} else {
return false;
}
}
const findVersion = (shareVersionMap, cb) => {
const callback = cb || function(prev, cur) {
return versionLt(prev, cur);
};
return Object.keys(shareVersionMap).reduce((prev, cur) => {
if (!prev) {
return cur;
}
if (callback(prev, cur)) {
return cur;
}
if (prev === "0") {
return cur;
}
return prev;
}, 0);
};
const isLoaded = (shared) => {
return Boolean(shared.loaded) || typeof shared.lib === "function";
};
function findSingletonVersionOrderByVersion(shareScopeMap, scope, pkgName) {
const versions = shareScopeMap[scope][pkgName];
const callback = function(prev, cur) {
return !isLoaded(versions[prev]) && versionLt(prev, cur);
};
return findVersion(shareScopeMap[scope][pkgName], callback);
}
function findSingletonVersionOrderByLoaded(shareScopeMap, scope, pkgName) {
const versions = shareScopeMap[scope][pkgName];
const callback = function(prev, cur) {
if (isLoaded(versions[cur])) {
if (isLoaded(versions[prev])) {
return Boolean(versionLt(prev, cur));
} else {
return true;
}
}
if (isLoaded(versions[prev])) {
return false;
}
return versionLt(prev, cur);
};
return findVersion(shareScopeMap[scope][pkgName], callback);
}
function getFindShareFunction(strategy) {
if (strategy === "loaded-first") {
return findSingletonVersionOrderByLoaded;
}
return findSingletonVersionOrderByVersion;
}
function getRegisteredShare(localShareScopeMap, pkgName, shareInfo, resolveShare) {
if (!localShareScopeMap) {
return;
}
const { shareConfig, scope = DEFAULT_SCOPE, strategy } = shareInfo;
const scopes = Array.isArray(scope) ? scope : [
scope
];
for (const sc of scopes) {
if (shareConfig && localShareScopeMap[sc] && localShareScopeMap[sc][pkgName]) {
const { requiredVersion } = shareConfig;
const findShareFunction = getFindShareFunction(strategy);
const maxOrSingletonVersion = findShareFunction(localShareScopeMap, sc, pkgName);
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);
}
}
return localShareScopeMap[sc][pkgName][maxOrSingletonVersion];
} else {
if (requiredVersion === false || requiredVersion === "*") {
return localShareScopeMap[sc][pkgName][maxOrSingletonVersion];
}
if (satisfy(maxOrSingletonVersion, 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();
}
}
}
function getGlobalShareScope() {
return Global.__FEDERATION__.__SHARE__;
}
var pluginHelper = /* @__PURE__ */ Object.freeze({
__proto__: null,
AsyncHook,
AsyncWaterfallHook,
PluginSystem,
SyncHook,
SyncWaterfallHook
});
const ShareUtils = {
getRegisteredShare,
getGlobalShareScope
};
const GlobalUtils = {
Global,
nativeGlobal,
resetFederationGlobalInfo,
getGlobalFederationInstance,
setGlobalFederationInstance,
getGlobalFederationConstructor,
setGlobalFederationConstructor,
getInfoWithoutType,
getGlobalSnapshot,
getTargetSnapshotInfoByModuleInfo,
getGlobalSnapshotInfoByModuleInfo,
setGlobalSnapshotInfoByModuleInfo,
addGlobalSnapshot,
getRemoteEntryExports,
registerGlobalPlugins,
getGlobalHostPlugins,
getPreloaded,
setPreloaded,
registerPlugins,
pluginHelper
};
var helpers = {
global: GlobalUtils,
share: ShareUtils
};
function registerBridgeLifeCycle() {
var _a;
const { registerPlugins: registerPlugins2, pluginHelper: pluginHelper2 } = helpers.global;
const host = getInstance();
const pluginSystem = new pluginHelper2.PluginSystem({
beforeBridgeRender: new pluginHelper2.SyncHook(),
afterBridgeRender: new pluginHelper2.SyncHook(),
beforeBridgeDestroy: new pluginHelper2.SyncHook(),
afterBridgeDestroy: new pluginHelper2.SyncHook()
});
if (host) {
registerPlugins2(
(_a = host == null ? void 0 : host.options) == null ? void 0 : _a.plugins,
[pluginSystem]
);
return pluginSystem;
}
return null;
}
const getModuleName = (id) => {
const idArray = id.split("/");
if (idArray.length < 2) {
return id;
}
return idArray[0] + "/" + idArray[1];
};
const getRootDomDefaultClassName = (moduleName) => {
const name = getModuleName(moduleName).replace(/\@/, "").replace(/\//, "-");
return `bridge-root-component-${name}`;
};
const RemoteAppWrapper = forwardRef(function(props, ref) {
const bridgeHook = registerBridgeLifeCycle();
const RemoteApp2 = () => {

@@ -1148,6 +128,5 @@ LoggerInstance.log(`RemoteAppWrapper RemoteApp props >>>`, { props });

const renderTimeout = setTimeout(() => {
var _a, _b;
const providerReturn = providerInfo();
providerInfoRef.current = providerReturn;
let renderProps = {
const renderProps = {
moduleName,

@@ -1165,12 +144,2 @@ dom: rootRef.current,

);
if (bridgeHook && ((_a = bridgeHook == null ? void 0 : bridgeHook.lifecycle) == null ? void 0 : _a.beforeBridgeRender)) {
const beforeBridgeRenderRes = (_b = bridgeHook == null ? void 0 : bridgeHook.lifecycle) == null ? void 0 : _b.beforeBridgeRender.emit({
...renderProps
});
const extraProps = beforeBridgeRenderRes && typeof beforeBridgeRenderRes === "object" && (beforeBridgeRenderRes == null ? void 0 : beforeBridgeRenderRes.extraProps) ? beforeBridgeRenderRes == null ? void 0 : beforeBridgeRenderRes.extraProps : {};
renderProps = {
...renderProps,
...extraProps
};
}
providerReturn.render(renderProps);

@@ -1181,3 +150,3 @@ });

setTimeout(() => {
var _a, _b, _c, _d;
var _a, _b;
if ((_a = providerInfoRef.current) == null ? void 0 : _a.destroy) {

@@ -1188,13 +157,3 @@ LoggerInstance.log(

);
if (bridgeHook && ((_b = bridgeHook == null ? void 0 : bridgeHook.lifecycle) == null ? void 0 : _b.afterBridgeDestroy)) {
(_c = bridgeHook == null ? void 0 : bridgeHook.lifecycle) == null ? void 0 : _c.afterBridgeDestroy.emit({
moduleName,
dom: renderDom.current,
basename,
memoryRoute,
fallback,
...resProps
});
}
(_d = providerInfoRef.current) == null ? void 0 : _d.destroy({
(_b = providerInfoRef.current) == null ? void 0 : _b.destroy({
dom: renderDom.current

@@ -1206,7 +165,6 @@ });

}, []);
const rootComponentClassName = `${getRootDomDefaultClassName(moduleName)} ${props == null ? void 0 : props.className}`;
return /* @__PURE__ */ React__default.createElement(
"div",
{
className: rootComponentClassName,
className: props == null ? void 0 : props.className,
style: props == null ? void 0 : props.style,

@@ -1329,4 +287,4 @@ ref: rootRef

}
} catch (error2) {
throw error2;
} catch (error) {
throw error;
}

@@ -1368,3 +326,3 @@ });

function createBridgeComponent(bridgeInfo) {
return (params) => {
return () => {
const rootMap = /* @__PURE__ */ new Map();

@@ -1385,3 +343,2 @@ const RawComponent = (info) => {

async render(info) {
var _a, _b;
LoggerInstance.log(`createBridgeComponent render Info`, info);

@@ -1396,5 +353,2 @@ const {

} = info;
const beforeBridgeRender = (bridgeInfo == null ? void 0 : bridgeInfo.hooks) && (bridgeInfo == null ? void 0 : bridgeInfo.hooks.beforeBridgeRender) || ((_a = params == null ? void 0 : params.hooks) == null ? void 0 : _a.beforeBridgeRender);
const beforeBridgeRenderRes = beforeBridgeRender && beforeBridgeRender(info);
const extraProps = beforeBridgeRenderRes && typeof beforeBridgeRenderRes === "object" && (beforeBridgeRenderRes == null ? void 0 : beforeBridgeRenderRes.extraProps) ? beforeBridgeRenderRes == null ? void 0 : beforeBridgeRenderRes.extraProps : {};
const rootComponentWithErrorBoundary = (

@@ -1410,3 +364,3 @@ // set ErrorBoundary for RawComponent rendering error, usually caused by user app rendering error

},
propsInfo: { ...propsInfo, ...extraProps }
propsInfo
}

@@ -1429,15 +383,7 @@ ))

}
const afterBridgeRender = (bridgeInfo == null ? void 0 : bridgeInfo.hooks) && (bridgeInfo == null ? void 0 : bridgeInfo.hooks.afterBridgeDestroy) || ((_b = params == null ? void 0 : params.hooks) == null ? void 0 : _b.afterBridgeRender);
afterBridgeRender && afterBridgeRender(info);
},
async destroy(info) {
var _a, _b;
LoggerInstance.log(`createBridgeComponent destroy Info`, {
dom: info.dom
});
if ((bridgeInfo == null ? void 0 : bridgeInfo.hooks) && (bridgeInfo == null ? void 0 : bridgeInfo.hooks.beforeBridgeDestroy) && typeof (bridgeInfo == null ? void 0 : bridgeInfo.hooks.beforeBridgeDestroy) === "function") {
bridgeInfo.hooks.beforeBridgeDestroy(info);
}
const beforeBridgeDestroy = (bridgeInfo == null ? void 0 : bridgeInfo.hooks) && (bridgeInfo == null ? void 0 : bridgeInfo.hooks.beforeBridgeDestroy) || ((_a = params == null ? void 0 : params.hooks) == null ? void 0 : _a.beforeBridgeDestroy);
beforeBridgeDestroy && beforeBridgeDestroy(info);
if (atLeastReact18(React)) {

@@ -1450,4 +396,2 @@ const root = rootMap.get(info.dom);

}
const afterBridgeDestroy = (bridgeInfo == null ? void 0 : bridgeInfo.hooks) && (bridgeInfo == null ? void 0 : bridgeInfo.hooks.afterBridgeDestroy) || ((_b = params == null ? void 0 : params.hooks) == null ? void 0 : _b.afterBridgeDestroy);
afterBridgeDestroy && afterBridgeDestroy(info);
},

@@ -1454,0 +398,0 @@ rawComponent: bridgeInfo.rootComponent,

@@ -68,3 +68,3 @@ "use strict";

const BrowserRouterInstance = createBrowserRouter(routers, {
basename: routerContextProps.basename || (router == null ? void 0 : router.basename),
basename: routerContextProps.basename,
future: router.future,

@@ -71,0 +71,0 @@ window: router.window

@@ -50,3 +50,3 @@ import React__default, { useContext } from "react";

const BrowserRouterInstance = createBrowserRouter(routers, {
basename: routerContextProps.basename || (router == null ? void 0 : router.basename),
basename: routerContextProps.basename,
future: router.future,

@@ -53,0 +53,0 @@ window: router.window

{
"name": "@module-federation/bridge-react",
"version": "0.0.0-next-20241021083129",
"version": "0.0.0-next-20241021084851",
"publishConfig": {

@@ -38,9 +38,8 @@ "access": "public"

"react-error-boundary": "^4.0.13",
"@module-federation/bridge-shared": "0.0.0-next-20241021083129"
"@module-federation/bridge-shared": "0.0.0-next-20241021084851"
},
"peerDependencies": {
"react": ">=17",
"react-dom": ">=17",
"react-router-dom": ">=4",
"@module-federation/runtime": "0.0.0-next-20241021083129"
"react": ">=16.9.0",
"react-dom": ">=16.9.0",
"react-router-dom": ">=4"
},

@@ -47,0 +46,0 @@ "devDependencies": {

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc