@module-federation/bridge-react 0.0.0-next-20250223132729 → 0.0.0-next-20250224065053
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +9 -5
- package/dist/context-CRuF6Lwb.cjs +99 -0
- package/dist/context-xD9r7Htw.js +100 -0
- package/dist/index.cjs.js +89 -75
- package/dist/index.es.js +90 -76
- package/dist/router-v5.cjs.js +1 -1
- package/dist/router-v5.es.js +1 -1
- package/dist/router-v6.cjs.js +1 -1
- package/dist/router-v6.es.js +1 -1
- package/dist/router.cjs.js +1 -1
- package/dist/router.es.js +1 -1
- package/package.json +4 -4
- package/src/provider/create.tsx +3 -8
- package/src/remote/component.tsx +96 -82
- package/src/remote/create.tsx +1 -1
- package/dist/context-BwD5jfgB.cjs +0 -364
- package/dist/context-BwUPFSB2.js +0 -365
package/dist/router-v6.cjs.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
3
|
const React = require("react");
|
|
4
4
|
const ReactRouterDom$1 = require("react-router-dom/dist/index.js");
|
|
5
|
-
const context = require("./context-
|
|
5
|
+
const context = require("./context-CRuF6Lwb.cjs");
|
|
6
6
|
const ReactRouterDom = require("react-router-dom/dist/index.js");
|
|
7
7
|
function _interopNamespaceDefault(e) {
|
|
8
8
|
const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
|
package/dist/router-v6.es.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React__default, { useContext } from "react";
|
|
2
2
|
import * as ReactRouterDom$1 from "react-router-dom/dist/index.js";
|
|
3
|
-
import { R as RouterContext, L as LoggerInstance } from "./context-
|
|
3
|
+
import { R as RouterContext, L as LoggerInstance } from "./context-xD9r7Htw.js";
|
|
4
4
|
export * from "react-router-dom/dist/index.js";
|
|
5
5
|
function WraperRouter(props) {
|
|
6
6
|
const { basename, ...propsRes } = props;
|
package/dist/router.cjs.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
3
|
const React = require("react");
|
|
4
4
|
const ReactRouterDom = require("react-router-dom/");
|
|
5
|
-
const context = require("./context-
|
|
5
|
+
const context = require("./context-CRuF6Lwb.cjs");
|
|
6
6
|
function _interopNamespaceDefault(e) {
|
|
7
7
|
const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
|
|
8
8
|
if (e) {
|
package/dist/router.es.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React__default, { useContext } from "react";
|
|
2
2
|
import * as ReactRouterDom from "react-router-dom/";
|
|
3
3
|
export * from "react-router-dom/";
|
|
4
|
-
import { R as RouterContext, L as LoggerInstance } from "./context-
|
|
4
|
+
import { R as RouterContext, L as LoggerInstance } from "./context-xD9r7Htw.js";
|
|
5
5
|
function WrapperRouter(props) {
|
|
6
6
|
const { basename, ...propsRes } = props;
|
|
7
7
|
const routerContextProps = useContext(RouterContext) || {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@module-federation/bridge-react",
|
|
3
|
-
"version": "0.0.0-next-
|
|
3
|
+
"version": "0.0.0-next-20250224065053",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -46,8 +46,8 @@
|
|
|
46
46
|
"dependencies": {
|
|
47
47
|
"@loadable/component": "^5.16.4",
|
|
48
48
|
"react-error-boundary": "^4.1.2",
|
|
49
|
-
"@module-federation/bridge-shared": "0.0.0-next-
|
|
50
|
-
"@module-federation/sdk": "0.0.0-next-
|
|
49
|
+
"@module-federation/bridge-shared": "0.0.0-next-20250224065053",
|
|
50
|
+
"@module-federation/sdk": "0.0.0-next-20250224065053"
|
|
51
51
|
},
|
|
52
52
|
"peerDependencies": {
|
|
53
53
|
"react": ">=16.9.0",
|
|
@@ -68,7 +68,7 @@
|
|
|
68
68
|
"typescript": "^5.2.2",
|
|
69
69
|
"vite": "^5.2.14",
|
|
70
70
|
"vite-plugin-dts": "^4.3.0",
|
|
71
|
-
"@module-federation/runtime": "0.0.0-next-
|
|
71
|
+
"@module-federation/runtime": "0.0.0-next-20250224065053"
|
|
72
72
|
},
|
|
73
73
|
"scripts": {
|
|
74
74
|
"dev": "vite",
|
package/src/provider/create.tsx
CHANGED
|
@@ -86,13 +86,9 @@ export function createBridgeComponent<T>(bridgeInfo: ProviderFnParams<T>) {
|
|
|
86
86
|
bridgeInfo?.render(rootComponentWithErrorBoundary, dom),
|
|
87
87
|
).then((root: RootType) => rootMap.set(info.dom, root));
|
|
88
88
|
} else {
|
|
89
|
-
|
|
90
|
-
let root = rootMap.get(info.dom);
|
|
91
|
-
if (!root) {
|
|
92
|
-
root = createRoot(info.dom);
|
|
93
|
-
rootMap.set(info.dom, root);
|
|
94
|
-
}
|
|
89
|
+
const root = createRoot(info.dom);
|
|
95
90
|
root.render(rootComponentWithErrorBoundary);
|
|
91
|
+
rootMap.set(info.dom, root);
|
|
96
92
|
}
|
|
97
93
|
|
|
98
94
|
instance?.bridgeHook?.lifecycle?.afterBridgeRender?.emit(info) || {};
|
|
@@ -101,7 +97,6 @@ export function createBridgeComponent<T>(bridgeInfo: ProviderFnParams<T>) {
|
|
|
101
97
|
destroy(info: DestroyParams) {
|
|
102
98
|
LoggerInstance.debug(`createBridgeComponent destroy Info`, info);
|
|
103
99
|
const root = rootMap.get(info.dom);
|
|
104
|
-
console.log('--------createBridgeComponent destroy Info', info);
|
|
105
100
|
if (root) {
|
|
106
101
|
if ('unmount' in root) {
|
|
107
102
|
root.unmount();
|
|
@@ -110,7 +105,7 @@ export function createBridgeComponent<T>(bridgeInfo: ProviderFnParams<T>) {
|
|
|
110
105
|
}
|
|
111
106
|
rootMap.delete(info.dom);
|
|
112
107
|
}
|
|
113
|
-
instance?.bridgeHook?.lifecycle?.
|
|
108
|
+
instance?.bridgeHook?.lifecycle?.destroyBridge?.emit(info);
|
|
114
109
|
},
|
|
115
110
|
};
|
|
116
111
|
};
|
package/src/remote/component.tsx
CHANGED
|
@@ -40,98 +40,112 @@ const RemoteAppWrapper = forwardRef(function (
|
|
|
40
40
|
props: RemoteAppParams & RenderFnParams,
|
|
41
41
|
ref,
|
|
42
42
|
) {
|
|
43
|
-
const {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
const rootRef: React.MutableRefObject<HTMLDivElement | null> =
|
|
56
|
-
ref && 'current' in ref
|
|
57
|
-
? (ref as React.MutableRefObject<HTMLDivElement | null>)
|
|
58
|
-
: useRef(null);
|
|
59
|
-
|
|
60
|
-
const renderDom: React.MutableRefObject<HTMLElement | null> = useRef(null);
|
|
61
|
-
const providerInfoRef = useRef<any>(null);
|
|
62
|
-
const [initialized, setInitialized] = useState(false);
|
|
63
|
-
|
|
64
|
-
LoggerInstance.debug(`RemoteAppWrapper instance from props >>>`, instance);
|
|
65
|
-
|
|
66
|
-
// 初始化远程组件
|
|
67
|
-
useEffect(() => {
|
|
68
|
-
if (initialized) return;
|
|
69
|
-
|
|
70
|
-
const providerReturn = providerInfo();
|
|
71
|
-
providerInfoRef.current = providerReturn;
|
|
72
|
-
setInitialized(true);
|
|
73
|
-
|
|
74
|
-
return () => {
|
|
75
|
-
if (providerInfoRef.current?.destroy) {
|
|
76
|
-
LoggerInstance.debug(
|
|
77
|
-
`createRemoteComponent LazyComponent destroy >>>`,
|
|
78
|
-
{ moduleName, basename, dom: renderDom.current },
|
|
79
|
-
);
|
|
43
|
+
const RemoteApp = () => {
|
|
44
|
+
LoggerInstance.debug(`RemoteAppWrapper RemoteApp props >>>`, { props });
|
|
45
|
+
const {
|
|
46
|
+
moduleName,
|
|
47
|
+
memoryRoute,
|
|
48
|
+
basename,
|
|
49
|
+
providerInfo,
|
|
50
|
+
className,
|
|
51
|
+
style,
|
|
52
|
+
fallback,
|
|
53
|
+
...resProps
|
|
54
|
+
} = props;
|
|
80
55
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
fallback,
|
|
87
|
-
...resProps,
|
|
88
|
-
});
|
|
56
|
+
const instance = federationRuntime.instance;
|
|
57
|
+
const rootRef: React.MutableRefObject<HTMLDivElement | null> =
|
|
58
|
+
ref && 'current' in ref
|
|
59
|
+
? (ref as React.MutableRefObject<HTMLDivElement | null>)
|
|
60
|
+
: useRef(null);
|
|
89
61
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
dom: renderDom.current,
|
|
93
|
-
});
|
|
62
|
+
const renderDom: React.MutableRefObject<HTMLElement | null> = useRef(null);
|
|
63
|
+
const providerInfoRef = useRef<any>(null);
|
|
94
64
|
|
|
95
|
-
|
|
65
|
+
LoggerInstance.debug(`RemoteAppWrapper instance from props >>>`, instance);
|
|
66
|
+
|
|
67
|
+
useEffect(() => {
|
|
68
|
+
const renderTimeout = setTimeout(() => {
|
|
69
|
+
const providerReturn = providerInfo();
|
|
70
|
+
providerInfoRef.current = providerReturn;
|
|
71
|
+
|
|
72
|
+
let renderProps = {
|
|
96
73
|
moduleName,
|
|
97
|
-
dom:
|
|
74
|
+
dom: rootRef.current,
|
|
98
75
|
basename,
|
|
99
76
|
memoryRoute,
|
|
100
77
|
fallback,
|
|
101
78
|
...resProps,
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
79
|
+
};
|
|
80
|
+
renderDom.current = rootRef.current;
|
|
81
|
+
LoggerInstance.debug(
|
|
82
|
+
`createRemoteComponent LazyComponent render >>>`,
|
|
83
|
+
renderProps,
|
|
84
|
+
);
|
|
106
85
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
86
|
+
LoggerInstance.debug(
|
|
87
|
+
`createRemoteComponent LazyComponent hostInstance >>>`,
|
|
88
|
+
instance,
|
|
89
|
+
);
|
|
90
|
+
const beforeBridgeRenderRes =
|
|
91
|
+
instance?.bridgeHook?.lifecycle?.beforeBridgeRender?.emit(
|
|
92
|
+
renderProps,
|
|
93
|
+
) || {};
|
|
94
|
+
// @ts-ignore
|
|
95
|
+
renderProps = { ...renderProps, ...beforeBridgeRenderRes.extraProps };
|
|
96
|
+
providerReturn.render(renderProps);
|
|
97
|
+
instance?.bridgeHook?.lifecycle?.afterBridgeRender?.emit(renderProps);
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
return () => {
|
|
101
|
+
clearTimeout(renderTimeout);
|
|
102
|
+
setTimeout(() => {
|
|
103
|
+
if (providerInfoRef.current?.destroy) {
|
|
104
|
+
LoggerInstance.debug(
|
|
105
|
+
`createRemoteComponent LazyComponent destroy >>>`,
|
|
106
|
+
{ moduleName, basename, dom: renderDom.current },
|
|
107
|
+
);
|
|
108
|
+
|
|
109
|
+
instance?.bridgeHook?.lifecycle?.beforeBridgeDestroy?.emit({
|
|
110
|
+
moduleName,
|
|
111
|
+
dom: renderDom.current,
|
|
112
|
+
basename,
|
|
113
|
+
memoryRoute,
|
|
114
|
+
fallback,
|
|
115
|
+
...resProps,
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
providerInfoRef.current?.destroy({
|
|
119
|
+
moduleName,
|
|
120
|
+
dom: renderDom.current,
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
instance?.bridgeHook?.lifecycle?.afterBridgeDestroy?.emit({
|
|
124
|
+
moduleName,
|
|
125
|
+
dom: renderDom.current,
|
|
126
|
+
basename,
|
|
127
|
+
memoryRoute,
|
|
128
|
+
fallback,
|
|
129
|
+
...resProps,
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
};
|
|
134
|
+
}, []);
|
|
135
|
+
|
|
136
|
+
// bridge-remote-root
|
|
137
|
+
const rootComponentClassName = `${getRootDomDefaultClassName(moduleName)} ${props?.className}`;
|
|
138
|
+
return (
|
|
139
|
+
<div
|
|
140
|
+
className={rootComponentClassName}
|
|
141
|
+
style={props?.style}
|
|
142
|
+
ref={rootRef}
|
|
143
|
+
></div>
|
|
144
|
+
);
|
|
145
|
+
};
|
|
110
146
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
dom: rootRef.current,
|
|
114
|
-
basename,
|
|
115
|
-
memoryRoute,
|
|
116
|
-
fallback,
|
|
117
|
-
...resProps,
|
|
118
|
-
};
|
|
119
|
-
renderDom.current = rootRef.current;
|
|
120
|
-
|
|
121
|
-
const beforeBridgeRenderRes =
|
|
122
|
-
instance?.bridgeHook?.lifecycle?.beforeBridgeRender?.emit(renderProps) ||
|
|
123
|
-
{};
|
|
124
|
-
// @ts-ignore
|
|
125
|
-
renderProps = { ...renderProps, ...beforeBridgeRenderRes.extraProps };
|
|
126
|
-
providerInfoRef.current.render(renderProps);
|
|
127
|
-
instance?.bridgeHook?.lifecycle?.afterBridgeRender?.emit(renderProps);
|
|
128
|
-
}, [initialized, ...Object.values(props)]);
|
|
129
|
-
|
|
130
|
-
// bridge-remote-root
|
|
131
|
-
const rootComponentClassName = `${getRootDomDefaultClassName(moduleName)} ${className || ''}`;
|
|
132
|
-
return (
|
|
133
|
-
<div className={rootComponentClassName} style={style} ref={rootRef}></div>
|
|
134
|
-
);
|
|
147
|
+
(RemoteApp as any)['__APP_VERSION__'] = __APP_VERSION__;
|
|
148
|
+
return <RemoteApp />;
|
|
135
149
|
});
|
|
136
150
|
|
|
137
151
|
interface ExtraDataProps {
|
package/src/remote/create.tsx
CHANGED
|
@@ -100,9 +100,9 @@ export function createRemoteComponent<T, E extends keyof T>(
|
|
|
100
100
|
: {}
|
|
101
101
|
: {};
|
|
102
102
|
|
|
103
|
-
const LazyComponent = createLazyRemoteComponent(info);
|
|
104
103
|
return forwardRef<HTMLDivElement, ProviderParams & RawComponentType>(
|
|
105
104
|
(props, ref) => {
|
|
105
|
+
const LazyComponent = createLazyRemoteComponent(info);
|
|
106
106
|
return (
|
|
107
107
|
<ErrorBoundary FallbackComponent={info.fallback}>
|
|
108
108
|
<React.Suspense fallback={info.loading}>
|
|
@@ -1,364 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
const React = require("react");
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
-
var __export = (target, all) => {
|
|
8
|
-
for (var name in all)
|
|
9
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
-
};
|
|
11
|
-
var __copyProps = (to, from, except, desc) => {
|
|
12
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
-
for (let key of __getOwnPropNames(from))
|
|
14
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
-
}
|
|
17
|
-
return to;
|
|
18
|
-
};
|
|
19
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
-
var browser_exports = {};
|
|
21
|
-
__export(browser_exports, {
|
|
22
|
-
createLogger: () => createLogger2,
|
|
23
|
-
logger: () => logger
|
|
24
|
-
});
|
|
25
|
-
var browser = __toCommonJS(browser_exports);
|
|
26
|
-
var supportsSubstitutions = void 0;
|
|
27
|
-
var supportColor = () => {
|
|
28
|
-
if (typeof supportsSubstitutions !== "undefined") {
|
|
29
|
-
return supportsSubstitutions;
|
|
30
|
-
}
|
|
31
|
-
const originalConsoleLog = console.log;
|
|
32
|
-
try {
|
|
33
|
-
const testString = "color test";
|
|
34
|
-
const css = "color: red;";
|
|
35
|
-
supportsSubstitutions = false;
|
|
36
|
-
console.log = (...args) => {
|
|
37
|
-
if (args[0] === `%c${testString}` && args[1] === css) {
|
|
38
|
-
supportsSubstitutions = true;
|
|
39
|
-
}
|
|
40
|
-
};
|
|
41
|
-
console.log(`%c${testString}`, css);
|
|
42
|
-
} catch (e) {
|
|
43
|
-
supportsSubstitutions = false;
|
|
44
|
-
} finally {
|
|
45
|
-
console.log = originalConsoleLog;
|
|
46
|
-
}
|
|
47
|
-
return supportsSubstitutions;
|
|
48
|
-
};
|
|
49
|
-
var ansiToCss = {
|
|
50
|
-
"bold": "font-weight: bold;",
|
|
51
|
-
"red": "color: red;",
|
|
52
|
-
"green": "color: green;",
|
|
53
|
-
"orange": "color: orange;",
|
|
54
|
-
"dodgerblue": "color: dodgerblue;",
|
|
55
|
-
"magenta": "color: magenta;",
|
|
56
|
-
"gray": "color: gray;"
|
|
57
|
-
};
|
|
58
|
-
var formatter = (key) => supportColor() ? (input) => {
|
|
59
|
-
if (Array.isArray(input)) {
|
|
60
|
-
const [label, style] = input;
|
|
61
|
-
return [`%c${label.replace("%c", "")}`, style ? `${ansiToCss[key]}${style}` : `${ansiToCss[key] || ""}`];
|
|
62
|
-
}
|
|
63
|
-
return [`%c${String(input).replace("%c", "")}`, ansiToCss[key] || ""];
|
|
64
|
-
} : (input) => [String(input)];
|
|
65
|
-
var bold = formatter("bold");
|
|
66
|
-
var red = formatter("red");
|
|
67
|
-
var green = formatter("green");
|
|
68
|
-
var orange = formatter("orange");
|
|
69
|
-
var dodgerblue = formatter("dodgerblue");
|
|
70
|
-
var magenta = formatter("magenta");
|
|
71
|
-
formatter("gray");
|
|
72
|
-
function getLabel(type, logType, labels) {
|
|
73
|
-
let label = [""];
|
|
74
|
-
if ("label" in logType) {
|
|
75
|
-
const labelText = type !== "log" ? labels[type] : void 0;
|
|
76
|
-
label = [labelText || logType.label || ""];
|
|
77
|
-
if (logType.color) {
|
|
78
|
-
const colorResult = logType.color(label[0]);
|
|
79
|
-
if (Array.isArray(colorResult) && colorResult.length === 2) {
|
|
80
|
-
label = bold([colorResult[0], colorResult[1]]);
|
|
81
|
-
} else {
|
|
82
|
-
label = bold(colorResult[0] || "");
|
|
83
|
-
}
|
|
84
|
-
} else {
|
|
85
|
-
label = bold(label[0]);
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
label = label.filter(Boolean);
|
|
89
|
-
return label;
|
|
90
|
-
}
|
|
91
|
-
function finalLog(label, text, args, message) {
|
|
92
|
-
if (label.length) {
|
|
93
|
-
if (Array.isArray(message)) {
|
|
94
|
-
console.log(...label, ...message, ...args);
|
|
95
|
-
} else {
|
|
96
|
-
console.log(...label, text, ...args);
|
|
97
|
-
}
|
|
98
|
-
} else {
|
|
99
|
-
Array.isArray(message) ? console.log(...message) : console.log(text, ...args);
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
var LOG_LEVEL = {
|
|
103
|
-
error: 0,
|
|
104
|
-
warn: 1,
|
|
105
|
-
info: 2,
|
|
106
|
-
log: 3,
|
|
107
|
-
verbose: 4
|
|
108
|
-
};
|
|
109
|
-
var errorStackRegExp = /at\s.*:\d+:\d+[\s\)]*$/;
|
|
110
|
-
var anonymousErrorStackRegExp = /at\s.*\(<anonymous>\)$/;
|
|
111
|
-
var isErrorStackMessage = (message) => errorStackRegExp.test(message) || anonymousErrorStackRegExp.test(message);
|
|
112
|
-
function validateOptions(options) {
|
|
113
|
-
const validatedOptions = { ...options };
|
|
114
|
-
if (options.labels && typeof options.labels !== "object") {
|
|
115
|
-
throw new Error("Labels must be an object");
|
|
116
|
-
}
|
|
117
|
-
if (options.level && typeof options.level !== "string") {
|
|
118
|
-
throw new Error("Level must be a string");
|
|
119
|
-
}
|
|
120
|
-
return validatedOptions;
|
|
121
|
-
}
|
|
122
|
-
var createLogger$1 = (options = {}, { getLabel: getLabel2, handleError, finalLog: finalLog2, greet, LOG_TYPES: LOG_TYPES2 }) => {
|
|
123
|
-
const validatedOptions = validateOptions(options);
|
|
124
|
-
let maxLevel = validatedOptions.level || "log";
|
|
125
|
-
let customLabels = validatedOptions.labels || {};
|
|
126
|
-
let log = (type, message, ...args) => {
|
|
127
|
-
if (LOG_LEVEL[LOG_TYPES2[type].level] > LOG_LEVEL[maxLevel]) {
|
|
128
|
-
return;
|
|
129
|
-
}
|
|
130
|
-
if (message === void 0 || message === null) {
|
|
131
|
-
return console.log();
|
|
132
|
-
}
|
|
133
|
-
let logType = LOG_TYPES2[type];
|
|
134
|
-
let text = "";
|
|
135
|
-
const label = getLabel2(type, logType, customLabels);
|
|
136
|
-
if (message instanceof Error) {
|
|
137
|
-
if (message.stack) {
|
|
138
|
-
let [name, ...rest] = message.stack.split("\n");
|
|
139
|
-
if (name.startsWith("Error: ")) {
|
|
140
|
-
name = name.slice(7);
|
|
141
|
-
}
|
|
142
|
-
text = `${name}
|
|
143
|
-
${handleError(rest.join("\n"))}`;
|
|
144
|
-
} else {
|
|
145
|
-
text = message.message;
|
|
146
|
-
}
|
|
147
|
-
} else if (logType.level === "error" && typeof message === "string") {
|
|
148
|
-
let lines = message.split("\n");
|
|
149
|
-
text = lines.map((line) => isErrorStackMessage(line) ? handleError(line) : line).join("\n");
|
|
150
|
-
} else {
|
|
151
|
-
text = `${message}`;
|
|
152
|
-
}
|
|
153
|
-
finalLog2(label, text, args, message);
|
|
154
|
-
};
|
|
155
|
-
let logger2 = {
|
|
156
|
-
// greet
|
|
157
|
-
greet: (message) => log("log", greet(message))
|
|
158
|
-
};
|
|
159
|
-
Object.keys(LOG_TYPES2).forEach((key) => {
|
|
160
|
-
logger2[key] = (...args) => log(key, ...args);
|
|
161
|
-
});
|
|
162
|
-
Object.defineProperty(logger2, "level", {
|
|
163
|
-
get: () => maxLevel,
|
|
164
|
-
set(val) {
|
|
165
|
-
maxLevel = val;
|
|
166
|
-
}
|
|
167
|
-
});
|
|
168
|
-
Object.defineProperty(logger2, "labels", {
|
|
169
|
-
get: () => customLabels,
|
|
170
|
-
set(val) {
|
|
171
|
-
customLabels = val;
|
|
172
|
-
}
|
|
173
|
-
});
|
|
174
|
-
logger2.override = (customLogger) => {
|
|
175
|
-
Object.assign(logger2, customLogger);
|
|
176
|
-
};
|
|
177
|
-
return logger2;
|
|
178
|
-
};
|
|
179
|
-
var startColor = [189, 255, 243];
|
|
180
|
-
var endColor = [74, 194, 154];
|
|
181
|
-
var isWord = (char) => !/[\s\n]/.test(char);
|
|
182
|
-
function gradient(message) {
|
|
183
|
-
if (!supportColor()) {
|
|
184
|
-
return [message];
|
|
185
|
-
}
|
|
186
|
-
const chars = [...message];
|
|
187
|
-
const words = chars.filter(isWord);
|
|
188
|
-
const steps = words.length - 1;
|
|
189
|
-
if (steps === 0) {
|
|
190
|
-
console.log(`%c${message}`, `color: rgb(${startColor.join(",")}); font-weight: bold;`);
|
|
191
|
-
return [message];
|
|
192
|
-
}
|
|
193
|
-
let output = "";
|
|
194
|
-
let styles = [];
|
|
195
|
-
chars.forEach((char) => {
|
|
196
|
-
if (isWord(char)) {
|
|
197
|
-
const progress = words.indexOf(char) / steps;
|
|
198
|
-
const r = Math.round(startColor[0] + (endColor[0] - startColor[0]) * progress);
|
|
199
|
-
const g = Math.round(startColor[1] + (endColor[1] - startColor[1]) * progress);
|
|
200
|
-
const b = Math.round(startColor[2] + (endColor[2] - startColor[2]) * progress);
|
|
201
|
-
output += `%c${char}`;
|
|
202
|
-
styles.push(`color: rgb(${r},${g},${b}); font-weight: bold;`);
|
|
203
|
-
} else {
|
|
204
|
-
output += char;
|
|
205
|
-
}
|
|
206
|
-
});
|
|
207
|
-
return [output, ...styles];
|
|
208
|
-
}
|
|
209
|
-
var LOG_TYPES = {
|
|
210
|
-
// Level error
|
|
211
|
-
error: {
|
|
212
|
-
label: "error",
|
|
213
|
-
level: "error",
|
|
214
|
-
color: red
|
|
215
|
-
},
|
|
216
|
-
// Level warn
|
|
217
|
-
warn: {
|
|
218
|
-
label: "warn",
|
|
219
|
-
level: "warn",
|
|
220
|
-
color: orange
|
|
221
|
-
},
|
|
222
|
-
// Level info
|
|
223
|
-
info: {
|
|
224
|
-
label: "info",
|
|
225
|
-
level: "info",
|
|
226
|
-
color: dodgerblue
|
|
227
|
-
},
|
|
228
|
-
start: {
|
|
229
|
-
label: "start",
|
|
230
|
-
level: "info",
|
|
231
|
-
color: dodgerblue
|
|
232
|
-
},
|
|
233
|
-
ready: {
|
|
234
|
-
label: "ready",
|
|
235
|
-
level: "info",
|
|
236
|
-
color: green
|
|
237
|
-
},
|
|
238
|
-
success: {
|
|
239
|
-
label: "success",
|
|
240
|
-
level: "info",
|
|
241
|
-
color: green
|
|
242
|
-
},
|
|
243
|
-
// Level log
|
|
244
|
-
log: {
|
|
245
|
-
level: "log"
|
|
246
|
-
},
|
|
247
|
-
// Level debug
|
|
248
|
-
debug: {
|
|
249
|
-
label: "debug",
|
|
250
|
-
level: "verbose",
|
|
251
|
-
color: magenta
|
|
252
|
-
}
|
|
253
|
-
};
|
|
254
|
-
function createLogger2(options = {}) {
|
|
255
|
-
return createLogger$1(options, {
|
|
256
|
-
handleError: (msg) => msg,
|
|
257
|
-
getLabel,
|
|
258
|
-
gradient,
|
|
259
|
-
finalLog,
|
|
260
|
-
LOG_TYPES,
|
|
261
|
-
greet: (msg) => {
|
|
262
|
-
return gradient(msg);
|
|
263
|
-
}
|
|
264
|
-
});
|
|
265
|
-
}
|
|
266
|
-
var logger = createLogger2();
|
|
267
|
-
const BROWSER_LOG_KEY = "FEDERATION_DEBUG";
|
|
268
|
-
const BROWSER_LOG_VALUE = "1";
|
|
269
|
-
function isBrowserEnv() {
|
|
270
|
-
return typeof window !== "undefined";
|
|
271
|
-
}
|
|
272
|
-
function isBrowserDebug() {
|
|
273
|
-
try {
|
|
274
|
-
if (isBrowserEnv() && window.localStorage) {
|
|
275
|
-
return localStorage.getItem(BROWSER_LOG_KEY) === BROWSER_LOG_VALUE;
|
|
276
|
-
}
|
|
277
|
-
} catch (error) {
|
|
278
|
-
return false;
|
|
279
|
-
}
|
|
280
|
-
return false;
|
|
281
|
-
}
|
|
282
|
-
function isDebugMode() {
|
|
283
|
-
if (typeof process !== "undefined" && process.env && process.env["FEDERATION_DEBUG"]) {
|
|
284
|
-
return Boolean(process.env["FEDERATION_DEBUG"]);
|
|
285
|
-
}
|
|
286
|
-
if (typeof FEDERATION_DEBUG !== "undefined" && Boolean(FEDERATION_DEBUG)) {
|
|
287
|
-
return true;
|
|
288
|
-
}
|
|
289
|
-
return isBrowserDebug();
|
|
290
|
-
}
|
|
291
|
-
const PREFIX = "[ Module Federation ]";
|
|
292
|
-
function setDebug(loggerInstance) {
|
|
293
|
-
if (isDebugMode()) {
|
|
294
|
-
loggerInstance.level = "verbose";
|
|
295
|
-
}
|
|
296
|
-
}
|
|
297
|
-
function setPrefix(loggerInstance, prefix) {
|
|
298
|
-
loggerInstance.labels = {
|
|
299
|
-
warn: `${prefix} Warn`,
|
|
300
|
-
error: `${prefix} Error`,
|
|
301
|
-
success: `${prefix} Success`,
|
|
302
|
-
info: `${prefix} Info`,
|
|
303
|
-
ready: `${prefix} Ready`,
|
|
304
|
-
debug: `${prefix} Debug`
|
|
305
|
-
};
|
|
306
|
-
}
|
|
307
|
-
function createLogger(prefix) {
|
|
308
|
-
const loggerInstance = browser.createLogger({
|
|
309
|
-
labels: {
|
|
310
|
-
warn: `${PREFIX} Warn`,
|
|
311
|
-
error: `${PREFIX} Error`,
|
|
312
|
-
success: `${PREFIX} Success`,
|
|
313
|
-
info: `${PREFIX} Info`,
|
|
314
|
-
ready: `${PREFIX} Ready`,
|
|
315
|
-
debug: `${PREFIX} Debug`
|
|
316
|
-
}
|
|
317
|
-
});
|
|
318
|
-
setDebug(loggerInstance);
|
|
319
|
-
setPrefix(loggerInstance, prefix);
|
|
320
|
-
return loggerInstance;
|
|
321
|
-
}
|
|
322
|
-
createLogger(PREFIX);
|
|
323
|
-
const LoggerInstance = createLogger(
|
|
324
|
-
"[ Module Federation Bridge React ]"
|
|
325
|
-
);
|
|
326
|
-
function pathJoin(...args) {
|
|
327
|
-
const res = args.reduce((res2, path) => {
|
|
328
|
-
let nPath = path;
|
|
329
|
-
if (!nPath || typeof nPath !== "string") {
|
|
330
|
-
return res2;
|
|
331
|
-
}
|
|
332
|
-
if (nPath[0] !== "/") {
|
|
333
|
-
nPath = `/${nPath}`;
|
|
334
|
-
}
|
|
335
|
-
const lastIndex = nPath.length - 1;
|
|
336
|
-
if (nPath[lastIndex] === "/") {
|
|
337
|
-
nPath = nPath.substring(0, lastIndex);
|
|
338
|
-
}
|
|
339
|
-
return res2 + nPath;
|
|
340
|
-
}, "");
|
|
341
|
-
return res || "/";
|
|
342
|
-
}
|
|
343
|
-
const getModuleName = (id) => {
|
|
344
|
-
if (!id) {
|
|
345
|
-
return id;
|
|
346
|
-
}
|
|
347
|
-
const idArray = id.split("/");
|
|
348
|
-
if (idArray.length < 2) {
|
|
349
|
-
return id;
|
|
350
|
-
}
|
|
351
|
-
return idArray[0] + "/" + idArray[1];
|
|
352
|
-
};
|
|
353
|
-
const getRootDomDefaultClassName = (moduleName) => {
|
|
354
|
-
if (!moduleName) {
|
|
355
|
-
return "";
|
|
356
|
-
}
|
|
357
|
-
const name = getModuleName(moduleName).replace(/\@/, "").replace(/\//, "-");
|
|
358
|
-
return `bridge-root-component-${name}`;
|
|
359
|
-
};
|
|
360
|
-
const RouterContext = React.createContext(null);
|
|
361
|
-
exports.LoggerInstance = LoggerInstance;
|
|
362
|
-
exports.RouterContext = RouterContext;
|
|
363
|
-
exports.getRootDomDefaultClassName = getRootDomDefaultClassName;
|
|
364
|
-
exports.pathJoin = pathJoin;
|