@module-federation/bridge-react 0.16.0 → 0.17.1
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 +39 -0
- package/__tests__/bridge.spec.tsx +10 -10
- package/__tests__/createLazyComponent.spec.tsx +209 -0
- package/__tests__/prefetch.spec.ts +156 -0
- package/__tests__/router.spec.tsx +3 -3
- package/__tests__/setupTests.ts +8 -0
- package/dist/{bridge-base-P6pEjY1q.js → bridge-base-BoshEggF.mjs} +1 -1
- package/dist/{bridge-base-BBH982Tz.cjs → bridge-base-UGCwcMnG.js} +1 -1
- package/dist/data-fetch-server-middleware.cjs.js +163 -0
- package/dist/data-fetch-server-middleware.d.ts +15 -0
- package/dist/data-fetch-server-middleware.es.js +164 -0
- package/dist/data-fetch-utils.cjs.js +24 -0
- package/dist/data-fetch-utils.d.ts +81 -0
- package/dist/data-fetch-utils.es.js +26 -0
- package/dist/index-C0fDZB5b.js +45 -0
- package/dist/index-CqxytsLY.mjs +46 -0
- package/dist/index.cjs.js +35 -9
- package/dist/index.d.ts +141 -1
- package/dist/index.es.js +39 -13
- package/dist/index.esm-BCeUd-x9.mjs +418 -0
- package/dist/index.esm-j_1sIRzg.js +417 -0
- package/dist/lazy-load-component-plugin-B80Ud11k.js +521 -0
- package/dist/lazy-load-component-plugin-_UbR2mWQ.mjs +522 -0
- package/dist/lazy-load-component-plugin.cjs.js +6 -0
- package/dist/lazy-load-component-plugin.d.ts +16 -0
- package/dist/lazy-load-component-plugin.es.js +6 -0
- package/dist/lazy-utils.cjs.js +24 -0
- package/dist/lazy-utils.d.ts +149 -0
- package/dist/lazy-utils.es.js +24 -0
- package/dist/plugin.d.ts +13 -4
- package/dist/prefetch-BaKIdUwP.js +1338 -0
- package/dist/prefetch-YpJYjpWC.mjs +1339 -0
- package/dist/router-v5.cjs.js +1 -1
- package/dist/router-v5.d.ts +9 -0
- package/dist/router-v5.es.js +1 -1
- package/dist/router-v6.cjs.js +1 -1
- package/dist/router-v6.d.ts +9 -0
- package/dist/router-v6.es.js +1 -1
- package/dist/router.cjs.js +1 -1
- package/dist/router.d.ts +9 -0
- package/dist/router.es.js +1 -1
- package/dist/utils-C4oPJV34.mjs +2016 -0
- package/dist/utils-iEVlDmyk.js +2015 -0
- package/dist/v18.cjs.js +1 -1
- package/dist/v18.d.ts +9 -0
- package/dist/v18.es.js +1 -1
- package/dist/v19.cjs.js +1 -1
- package/dist/v19.d.ts +9 -0
- package/dist/v19.es.js +1 -1
- package/jest.config.ts +21 -0
- package/package.json +48 -6
- package/project.json +4 -8
- package/src/index.ts +32 -1
- package/src/lazy/AwaitDataFetch.tsx +215 -0
- package/src/lazy/constant.ts +30 -0
- package/src/lazy/createLazyComponent.tsx +411 -0
- package/src/lazy/data-fetch/cache.ts +291 -0
- package/src/lazy/data-fetch/call-data-fetch.ts +13 -0
- package/src/lazy/data-fetch/data-fetch-server-middleware.ts +196 -0
- package/src/lazy/data-fetch/index.ts +16 -0
- package/src/lazy/data-fetch/inject-data-fetch.ts +109 -0
- package/src/lazy/data-fetch/prefetch.ts +106 -0
- package/src/lazy/data-fetch/runtime-plugin.ts +115 -0
- package/src/lazy/index.ts +35 -0
- package/src/lazy/logger.ts +6 -0
- package/src/lazy/types.ts +75 -0
- package/src/lazy/utils.ts +372 -0
- package/src/lazy/wrapNoSSR.tsx +10 -0
- package/src/plugins/lazy-load-component-plugin.spec.ts +21 -0
- package/src/plugins/lazy-load-component-plugin.ts +57 -0
- package/src/provider/plugin.ts +4 -4
- package/src/remote/component.tsx +3 -3
- package/src/remote/create.tsx +18 -5
- package/tsconfig.json +1 -1
- package/tsconfig.spec.json +26 -0
- package/vite.config.ts +13 -0
- package/vitest.config.ts +6 -1
- package/dist/index-Cv3p6r66.cjs +0 -235
- package/dist/index-D4yt7Udv.js +0 -236
- package/src/.eslintrc.js +0 -9
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { MiddlewareHandler } from 'hono';
|
|
2
|
+
|
|
3
|
+
declare const dataFetchServerMiddleware: MiddlewareHandler;
|
|
4
|
+
export default dataFetchServerMiddleware;
|
|
5
|
+
|
|
6
|
+
export { }
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
declare module '@module-federation/runtime-core' {
|
|
10
|
+
interface ModuleFederation {
|
|
11
|
+
createLazyComponent<T, E extends keyof T>(options: Omit<CreateLazyComponentOptions<T, E>, 'instance'>): ReturnType<typeof createLazyComponent<T, E>>;
|
|
12
|
+
prefetch(options: Omit<PrefetchOptions, 'instance'>): ReturnType<typeof prefetch>;
|
|
13
|
+
collectSSRAssets(options: Omit<Parameters<typeof collectSSRAssets>[0], 'instance'>): ReturnType<typeof collectSSRAssets>;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import { D as DATA_FETCH_QUERY, l as logger, g as getDataFetchMap, i as initDataFetchMap, M as MF_DATA_FETCH_STATUS, f as fetchData, a as loadDataFetchModule } from "./utils-C4oPJV34.mjs";
|
|
2
|
+
import { M as MANIFEST_EXT, S as SEPARATOR } from "./index.esm-BCeUd-x9.mjs";
|
|
3
|
+
function wrapSetTimeout(targetPromise, delay = 2e4, id) {
|
|
4
|
+
if (targetPromise && typeof targetPromise.then === "function") {
|
|
5
|
+
return new Promise((resolve, reject) => {
|
|
6
|
+
const timeoutId = setTimeout(() => {
|
|
7
|
+
logger.warn(`Data fetch for ID ${id} timed out after 20 seconds.`);
|
|
8
|
+
reject(new Error(`Data fetch for ID ${id} timed out after 20 seconds`));
|
|
9
|
+
}, delay);
|
|
10
|
+
targetPromise.then((value) => {
|
|
11
|
+
clearTimeout(timeoutId);
|
|
12
|
+
resolve(value);
|
|
13
|
+
}).catch((err) => {
|
|
14
|
+
clearTimeout(timeoutId);
|
|
15
|
+
reject(err);
|
|
16
|
+
});
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
function addProtocol(url) {
|
|
21
|
+
if (url.startsWith("//")) {
|
|
22
|
+
return "https:" + url;
|
|
23
|
+
}
|
|
24
|
+
return url;
|
|
25
|
+
}
|
|
26
|
+
const getDecodeQuery = (url, name) => {
|
|
27
|
+
const res = url.searchParams.get(name);
|
|
28
|
+
if (!res) {
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
return decodeURIComponent(res);
|
|
32
|
+
};
|
|
33
|
+
const dataFetchServerMiddleware = async (ctx, next) => {
|
|
34
|
+
var _a, _b, _c;
|
|
35
|
+
let url;
|
|
36
|
+
let dataFetchKey;
|
|
37
|
+
let params;
|
|
38
|
+
let remoteInfo;
|
|
39
|
+
try {
|
|
40
|
+
url = new URL(ctx.req.url);
|
|
41
|
+
dataFetchKey = getDecodeQuery(url, DATA_FETCH_QUERY);
|
|
42
|
+
params = JSON.parse(getDecodeQuery(url, "params") || "{}");
|
|
43
|
+
const remoteInfoQuery = getDecodeQuery(url, "remoteInfo");
|
|
44
|
+
remoteInfo = remoteInfoQuery ? JSON.parse(remoteInfoQuery) : null;
|
|
45
|
+
} catch (e) {
|
|
46
|
+
logger.error("fetch data from server, error: ", e);
|
|
47
|
+
return next();
|
|
48
|
+
}
|
|
49
|
+
if (!dataFetchKey) {
|
|
50
|
+
return next();
|
|
51
|
+
}
|
|
52
|
+
logger.log("fetch data from server, dataFetchKey: ", dataFetchKey);
|
|
53
|
+
logger.debug(
|
|
54
|
+
"fetch data from server, moduleInfo: ",
|
|
55
|
+
(_a = globalThis.__FEDERATION__) == null ? void 0 : _a.moduleInfo
|
|
56
|
+
);
|
|
57
|
+
try {
|
|
58
|
+
const dataFetchMap = getDataFetchMap();
|
|
59
|
+
if (!dataFetchMap) {
|
|
60
|
+
initDataFetchMap();
|
|
61
|
+
}
|
|
62
|
+
const fetchDataPromise = (_b = dataFetchMap[dataFetchKey]) == null ? void 0 : _b[1];
|
|
63
|
+
logger.debug(
|
|
64
|
+
"fetch data from server, fetchDataPromise: ",
|
|
65
|
+
fetchDataPromise
|
|
66
|
+
);
|
|
67
|
+
if (fetchDataPromise && ((_c = dataFetchMap[dataFetchKey]) == null ? void 0 : _c[2]) !== MF_DATA_FETCH_STATUS.ERROR) {
|
|
68
|
+
const targetPromise = fetchDataPromise[0];
|
|
69
|
+
const wrappedPromise = wrapSetTimeout(targetPromise, 2e4, dataFetchKey);
|
|
70
|
+
if (wrappedPromise) {
|
|
71
|
+
const res = await wrappedPromise;
|
|
72
|
+
logger.log("fetch data from server, fetchDataPromise res: ", res);
|
|
73
|
+
return ctx.json(res);
|
|
74
|
+
}
|
|
75
|
+
logger.error(
|
|
76
|
+
`Expected a Promise from fetchDataPromise[0] for dataFetchKey ${dataFetchKey}, but received:`,
|
|
77
|
+
targetPromise,
|
|
78
|
+
"Will try call new dataFetch again..."
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
if (remoteInfo) {
|
|
82
|
+
try {
|
|
83
|
+
const hostInstance2 = globalThis.__FEDERATION__.__INSTANCES__[0];
|
|
84
|
+
const remoteEntry = `${addProtocol(remoteInfo.ssrPublicPath) + remoteInfo.ssrRemoteEntry}`;
|
|
85
|
+
if (!hostInstance2) {
|
|
86
|
+
throw new Error("host instance not found!");
|
|
87
|
+
}
|
|
88
|
+
const remote = hostInstance2.options.remotes.find(
|
|
89
|
+
(remote2) => remote2.name === remoteInfo.name
|
|
90
|
+
);
|
|
91
|
+
logger.debug("find remote: ", JSON.stringify(remote));
|
|
92
|
+
if (!remote) {
|
|
93
|
+
hostInstance2.registerRemotes([
|
|
94
|
+
{
|
|
95
|
+
name: remoteInfo.name,
|
|
96
|
+
entry: remoteEntry,
|
|
97
|
+
entryGlobalName: remoteInfo.globalName
|
|
98
|
+
}
|
|
99
|
+
]);
|
|
100
|
+
} else if (!("entry" in remote) || !remote.entry.includes(MANIFEST_EXT)) {
|
|
101
|
+
const { hostGlobalSnapshot, remoteSnapshot } = hostInstance2.snapshotHandler.getGlobalRemoteInfo(remoteInfo);
|
|
102
|
+
logger.debug(
|
|
103
|
+
"find hostGlobalSnapshot: ",
|
|
104
|
+
JSON.stringify(hostGlobalSnapshot)
|
|
105
|
+
);
|
|
106
|
+
logger.debug("find remoteSnapshot: ", JSON.stringify(remoteSnapshot));
|
|
107
|
+
if (!hostGlobalSnapshot || !remoteSnapshot) {
|
|
108
|
+
if ("version" in remote) {
|
|
109
|
+
delete remote.version;
|
|
110
|
+
}
|
|
111
|
+
remote.entry = remoteEntry;
|
|
112
|
+
remote.entryGlobalName = remoteInfo.globalName;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
} catch (e) {
|
|
116
|
+
ctx.status(500);
|
|
117
|
+
return ctx.text(
|
|
118
|
+
`failed to fetch ${remoteInfo.name} data, error:
|
|
119
|
+
${e}`
|
|
120
|
+
);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
const dataFetchItem = dataFetchMap[dataFetchKey];
|
|
124
|
+
logger.debug("fetch data from server, dataFetchItem: ", dataFetchItem);
|
|
125
|
+
if (dataFetchItem) {
|
|
126
|
+
const callFetchDataPromise = fetchData(dataFetchKey, {
|
|
127
|
+
...params,
|
|
128
|
+
isDowngrade: !remoteInfo,
|
|
129
|
+
_id: dataFetchKey
|
|
130
|
+
});
|
|
131
|
+
const wrappedPromise = wrapSetTimeout(
|
|
132
|
+
callFetchDataPromise,
|
|
133
|
+
2e4,
|
|
134
|
+
dataFetchKey
|
|
135
|
+
);
|
|
136
|
+
if (wrappedPromise) {
|
|
137
|
+
const res = await wrappedPromise;
|
|
138
|
+
logger.log("fetch data from server, dataFetchItem res: ", res);
|
|
139
|
+
return ctx.json(res);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
const remoteId = dataFetchKey.split(SEPARATOR)[0];
|
|
143
|
+
const hostInstance = globalThis.__FEDERATION__.__INSTANCES__[0];
|
|
144
|
+
if (!hostInstance) {
|
|
145
|
+
throw new Error("host instance not found!");
|
|
146
|
+
}
|
|
147
|
+
const dataFetchFn = await loadDataFetchModule(hostInstance, remoteId);
|
|
148
|
+
const data = await dataFetchFn({
|
|
149
|
+
...params,
|
|
150
|
+
isDowngrade: !remoteInfo,
|
|
151
|
+
_id: dataFetchKey
|
|
152
|
+
});
|
|
153
|
+
logger.log("fetch data from server, loadDataFetchModule res: ", data);
|
|
154
|
+
return ctx.json(data);
|
|
155
|
+
} catch (e) {
|
|
156
|
+
logger.error("server plugin data fetch error: ", e);
|
|
157
|
+
ctx.status(500);
|
|
158
|
+
return ctx.text(`failed to fetch ${remoteInfo.name} data, error:
|
|
159
|
+
${e}`);
|
|
160
|
+
}
|
|
161
|
+
};
|
|
162
|
+
export {
|
|
163
|
+
dataFetchServerMiddleware as default
|
|
164
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const lazyUtils = require("./utils-iEVlDmyk.js");
|
|
4
|
+
const prefetch = require("./prefetch-BaKIdUwP.js");
|
|
5
|
+
async function callDataFetch() {
|
|
6
|
+
const dataFetch = globalThis[lazyUtils.DATA_FETCH_FUNCTION];
|
|
7
|
+
if (dataFetch) {
|
|
8
|
+
await Promise.all(
|
|
9
|
+
dataFetch.map(async (options) => {
|
|
10
|
+
await prefetch.dataFetchFunction(options);
|
|
11
|
+
})
|
|
12
|
+
);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
exports.CacheSize = lazyUtils.CacheSize;
|
|
16
|
+
exports.CacheTime = lazyUtils.CacheTime;
|
|
17
|
+
exports.cache = lazyUtils.cache;
|
|
18
|
+
exports.clearStore = lazyUtils.clearStore;
|
|
19
|
+
exports.configureCache = lazyUtils.configureCache;
|
|
20
|
+
exports.generateKey = lazyUtils.generateKey;
|
|
21
|
+
exports.revalidateTag = lazyUtils.revalidateTag;
|
|
22
|
+
exports.injectDataFetch = prefetch.injectDataFetch;
|
|
23
|
+
exports.prefetch = prefetch.prefetch;
|
|
24
|
+
exports.callDataFetch = callDataFetch;
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { getInstance } from '@module-federation/runtime';
|
|
2
|
+
|
|
3
|
+
export declare function cache<T>(fn: DataFetch<T>, options?: CacheOptions): DataFetch<T>;
|
|
4
|
+
|
|
5
|
+
declare interface CacheConfig {
|
|
6
|
+
maxSize?: number;
|
|
7
|
+
unstable_shouldDisable?: ({ request, }: {
|
|
8
|
+
request: Request;
|
|
9
|
+
}) => boolean | Promise<boolean>;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
declare interface CacheOptions {
|
|
13
|
+
tag?: string | string[];
|
|
14
|
+
maxAge?: number;
|
|
15
|
+
revalidate?: number;
|
|
16
|
+
getKey?: <Args extends any[]>(...args: Args) => string;
|
|
17
|
+
onCache?: (info: CacheStatsInfo) => boolean;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export declare const CacheSize: {
|
|
21
|
+
readonly KB: 1024;
|
|
22
|
+
readonly MB: number;
|
|
23
|
+
readonly GB: number;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export declare interface CacheStatsInfo {
|
|
27
|
+
status: CacheStatus;
|
|
28
|
+
key: string | symbol;
|
|
29
|
+
params: DataFetchParams;
|
|
30
|
+
result: any;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export declare type CacheStatus = 'hit' | 'stale' | 'miss';
|
|
34
|
+
|
|
35
|
+
export declare const CacheTime: {
|
|
36
|
+
readonly SECOND: 1000;
|
|
37
|
+
readonly MINUTE: number;
|
|
38
|
+
readonly HOUR: number;
|
|
39
|
+
readonly DAY: number;
|
|
40
|
+
readonly WEEK: number;
|
|
41
|
+
readonly MONTH: number;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
export declare function callDataFetch(): Promise<void>;
|
|
45
|
+
|
|
46
|
+
export declare function clearStore(): void;
|
|
47
|
+
|
|
48
|
+
export declare function configureCache(config: CacheConfig): void;
|
|
49
|
+
|
|
50
|
+
declare type DataFetch<T> = (params: DataFetchParams) => Promise<T>;
|
|
51
|
+
|
|
52
|
+
declare type DataFetchParams = {
|
|
53
|
+
isDowngrade: boolean;
|
|
54
|
+
_id?: string;
|
|
55
|
+
} & Record<string, unknown>;
|
|
56
|
+
|
|
57
|
+
export declare function generateKey(dataFetchOptions: DataFetchParams): string;
|
|
58
|
+
|
|
59
|
+
export declare function injectDataFetch(): void;
|
|
60
|
+
|
|
61
|
+
export declare function prefetch(options: PrefetchOptions): Promise<void>;
|
|
62
|
+
|
|
63
|
+
export declare type PrefetchOptions = {
|
|
64
|
+
id: string;
|
|
65
|
+
instance: ReturnType<typeof getInstance>;
|
|
66
|
+
dataFetchParams?: DataFetchParams;
|
|
67
|
+
preloadComponentResource?: boolean;
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
export declare function revalidateTag(tag: string): void;
|
|
71
|
+
|
|
72
|
+
export { }
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
declare module '@module-federation/runtime-core' {
|
|
76
|
+
interface ModuleFederation {
|
|
77
|
+
createLazyComponent<T, E extends keyof T>(options: Omit<CreateLazyComponentOptions<T, E>, 'instance'>): ReturnType<typeof createLazyComponent<T, E>>;
|
|
78
|
+
prefetch(options: Omit<PrefetchOptions, 'instance'>): ReturnType<typeof prefetch>;
|
|
79
|
+
collectSSRAssets(options: Omit<Parameters<typeof collectSSRAssets>[0], 'instance'>): ReturnType<typeof collectSSRAssets>;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { x as DATA_FETCH_FUNCTION } from "./utils-C4oPJV34.mjs";
|
|
2
|
+
import { C, b, e, h, c, d, r } from "./utils-C4oPJV34.mjs";
|
|
3
|
+
import { d as dataFetchFunction } from "./prefetch-YpJYjpWC.mjs";
|
|
4
|
+
import { i, p } from "./prefetch-YpJYjpWC.mjs";
|
|
5
|
+
async function callDataFetch() {
|
|
6
|
+
const dataFetch = globalThis[DATA_FETCH_FUNCTION];
|
|
7
|
+
if (dataFetch) {
|
|
8
|
+
await Promise.all(
|
|
9
|
+
dataFetch.map(async (options) => {
|
|
10
|
+
await dataFetchFunction(options);
|
|
11
|
+
})
|
|
12
|
+
);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
export {
|
|
16
|
+
C as CacheSize,
|
|
17
|
+
b as CacheTime,
|
|
18
|
+
e as cache,
|
|
19
|
+
callDataFetch,
|
|
20
|
+
h as clearStore,
|
|
21
|
+
c as configureCache,
|
|
22
|
+
d as generateKey,
|
|
23
|
+
i as injectDataFetch,
|
|
24
|
+
p as prefetch,
|
|
25
|
+
r as revalidateTag
|
|
26
|
+
};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const React = require("react");
|
|
3
|
+
const index_esm = require("./index.esm-j_1sIRzg.js");
|
|
4
|
+
const RouterContext = React.createContext(null);
|
|
5
|
+
const LoggerInstance = index_esm.createLogger(
|
|
6
|
+
"[ Module Federation Bridge React ]"
|
|
7
|
+
);
|
|
8
|
+
function pathJoin(...args) {
|
|
9
|
+
const res = args.reduce((res2, path) => {
|
|
10
|
+
let nPath = path;
|
|
11
|
+
if (!nPath || typeof nPath !== "string") {
|
|
12
|
+
return res2;
|
|
13
|
+
}
|
|
14
|
+
if (nPath[0] !== "/") {
|
|
15
|
+
nPath = `/${nPath}`;
|
|
16
|
+
}
|
|
17
|
+
const lastIndex = nPath.length - 1;
|
|
18
|
+
if (nPath[lastIndex] === "/") {
|
|
19
|
+
nPath = nPath.substring(0, lastIndex);
|
|
20
|
+
}
|
|
21
|
+
return res2 + nPath;
|
|
22
|
+
}, "");
|
|
23
|
+
return res || "/";
|
|
24
|
+
}
|
|
25
|
+
const getModuleName = (id) => {
|
|
26
|
+
if (!id) {
|
|
27
|
+
return id;
|
|
28
|
+
}
|
|
29
|
+
const idArray = id.split("/");
|
|
30
|
+
if (idArray.length < 2) {
|
|
31
|
+
return id;
|
|
32
|
+
}
|
|
33
|
+
return idArray[0] + "/" + idArray[1];
|
|
34
|
+
};
|
|
35
|
+
const getRootDomDefaultClassName = (moduleName) => {
|
|
36
|
+
if (!moduleName) {
|
|
37
|
+
return "";
|
|
38
|
+
}
|
|
39
|
+
const name = getModuleName(moduleName).replace(/\@/, "").replace(/\//, "-");
|
|
40
|
+
return `bridge-root-component-${name}`;
|
|
41
|
+
};
|
|
42
|
+
exports.LoggerInstance = LoggerInstance;
|
|
43
|
+
exports.RouterContext = RouterContext;
|
|
44
|
+
exports.getRootDomDefaultClassName = getRootDomDefaultClassName;
|
|
45
|
+
exports.pathJoin = pathJoin;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import React__default from "react";
|
|
2
|
+
import { c as createLogger } from "./index.esm-BCeUd-x9.mjs";
|
|
3
|
+
const RouterContext = React__default.createContext(null);
|
|
4
|
+
const LoggerInstance = createLogger(
|
|
5
|
+
"[ Module Federation Bridge React ]"
|
|
6
|
+
);
|
|
7
|
+
function pathJoin(...args) {
|
|
8
|
+
const res = args.reduce((res2, path) => {
|
|
9
|
+
let nPath = path;
|
|
10
|
+
if (!nPath || typeof nPath !== "string") {
|
|
11
|
+
return res2;
|
|
12
|
+
}
|
|
13
|
+
if (nPath[0] !== "/") {
|
|
14
|
+
nPath = `/${nPath}`;
|
|
15
|
+
}
|
|
16
|
+
const lastIndex = nPath.length - 1;
|
|
17
|
+
if (nPath[lastIndex] === "/") {
|
|
18
|
+
nPath = nPath.substring(0, lastIndex);
|
|
19
|
+
}
|
|
20
|
+
return res2 + nPath;
|
|
21
|
+
}, "");
|
|
22
|
+
return res || "/";
|
|
23
|
+
}
|
|
24
|
+
const getModuleName = (id) => {
|
|
25
|
+
if (!id) {
|
|
26
|
+
return id;
|
|
27
|
+
}
|
|
28
|
+
const idArray = id.split("/");
|
|
29
|
+
if (idArray.length < 2) {
|
|
30
|
+
return id;
|
|
31
|
+
}
|
|
32
|
+
return idArray[0] + "/" + idArray[1];
|
|
33
|
+
};
|
|
34
|
+
const getRootDomDefaultClassName = (moduleName) => {
|
|
35
|
+
if (!moduleName) {
|
|
36
|
+
return "";
|
|
37
|
+
}
|
|
38
|
+
const name = getModuleName(moduleName).replace(/\@/, "").replace(/\//, "-");
|
|
39
|
+
return `bridge-root-component-${name}`;
|
|
40
|
+
};
|
|
41
|
+
export {
|
|
42
|
+
LoggerInstance as L,
|
|
43
|
+
RouterContext as R,
|
|
44
|
+
getRootDomDefaultClassName as g,
|
|
45
|
+
pathJoin as p
|
|
46
|
+
};
|
package/dist/index.cjs.js
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const bridgeBase = require("./bridge-base-
|
|
3
|
+
const bridgeBase = require("./bridge-base-UGCwcMnG.js");
|
|
4
4
|
const ReactDOM = require("react-dom");
|
|
5
5
|
const React = require("react");
|
|
6
|
-
const index = require("./index-
|
|
6
|
+
const index = require("./index-C0fDZB5b.js");
|
|
7
7
|
const ReactRouterDOM = require("react-router-dom");
|
|
8
8
|
const plugin = require("./plugin.cjs.js");
|
|
9
|
+
const lazyLoadComponentPlugin = require("./lazy-load-component-plugin-B80Ud11k.js");
|
|
10
|
+
const lazyUtils = require("./utils-iEVlDmyk.js");
|
|
11
|
+
const dataFetchUtils = require("./data-fetch-utils.cjs.js");
|
|
12
|
+
const prefetch = require("./prefetch-BaKIdUwP.js");
|
|
9
13
|
function _interopNamespaceDefault(e2) {
|
|
10
14
|
const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
|
|
11
15
|
if (e2) {
|
|
@@ -83,7 +87,7 @@ const RemoteAppWrapper = React.forwardRef(function(props, ref) {
|
|
|
83
87
|
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
84
88
|
if ((_a = providerInfoRef.current) == null ? void 0 : _a.destroy) {
|
|
85
89
|
index.LoggerInstance.debug(
|
|
86
|
-
`
|
|
90
|
+
`createRemoteAppComponent LazyComponent destroy >>>`,
|
|
87
91
|
{ moduleName, basename, dom: renderDom.current }
|
|
88
92
|
);
|
|
89
93
|
(_d = (_c = (_b = instance == null ? void 0 : instance.bridgeHook) == null ? void 0 : _b.lifecycle) == null ? void 0 : _c.beforeBridgeDestroy) == null ? void 0 : _d.emit({
|
|
@@ -171,7 +175,7 @@ function withRouterData(WrappedComponent) {
|
|
|
171
175
|
}
|
|
172
176
|
}
|
|
173
177
|
}
|
|
174
|
-
index.LoggerInstance.debug(`
|
|
178
|
+
index.LoggerInstance.debug(`createRemoteAppComponent withRouterData >>>`, {
|
|
175
179
|
...props,
|
|
176
180
|
basename,
|
|
177
181
|
routerContextVal,
|
|
@@ -183,7 +187,7 @@ function withRouterData(WrappedComponent) {
|
|
|
183
187
|
React.useEffect(() => {
|
|
184
188
|
if (pathname !== "" && pathname !== location.pathname) {
|
|
185
189
|
index.LoggerInstance.debug(
|
|
186
|
-
`
|
|
190
|
+
`createRemoteAppComponent dispatchPopstateEnv >>>`,
|
|
187
191
|
{
|
|
188
192
|
name: props.name,
|
|
189
193
|
pathname: location.pathname
|
|
@@ -204,7 +208,7 @@ const RemoteApp = withRouterData(RemoteAppWrapper);
|
|
|
204
208
|
function createLazyRemoteComponent(info) {
|
|
205
209
|
const exportName = (info == null ? void 0 : info.export) || "default";
|
|
206
210
|
return React.lazy(async () => {
|
|
207
|
-
index.LoggerInstance.debug(`
|
|
211
|
+
index.LoggerInstance.debug(`createRemoteAppComponent LazyComponent create >>>`, {
|
|
208
212
|
lazyComponent: info.loader,
|
|
209
213
|
exportName
|
|
210
214
|
});
|
|
@@ -212,7 +216,7 @@ function createLazyRemoteComponent(info) {
|
|
|
212
216
|
const m = await info.loader();
|
|
213
217
|
const moduleName = m && m[Symbol.for("mf_module_id")];
|
|
214
218
|
index.LoggerInstance.debug(
|
|
215
|
-
`
|
|
219
|
+
`createRemoteAppComponent LazyComponent loadRemote info >>>`,
|
|
216
220
|
{ name: moduleName, module: m, exportName }
|
|
217
221
|
);
|
|
218
222
|
const exportFn = m[exportName];
|
|
@@ -235,7 +239,7 @@ function createLazyRemoteComponent(info) {
|
|
|
235
239
|
};
|
|
236
240
|
} else {
|
|
237
241
|
index.LoggerInstance.debug(
|
|
238
|
-
`
|
|
242
|
+
`createRemoteAppComponent LazyComponent module not found >>>`,
|
|
239
243
|
{ name: moduleName, module: m, exportName }
|
|
240
244
|
);
|
|
241
245
|
throw Error(
|
|
@@ -249,7 +253,7 @@ function createLazyRemoteComponent(info) {
|
|
|
249
253
|
}
|
|
250
254
|
});
|
|
251
255
|
}
|
|
252
|
-
function
|
|
256
|
+
function createRemoteAppComponent(info) {
|
|
253
257
|
const LazyComponent = createLazyRemoteComponent(info);
|
|
254
258
|
return React.forwardRef((props, ref) => {
|
|
255
259
|
return /* @__PURE__ */ React.createElement(
|
|
@@ -261,5 +265,27 @@ function createRemoteComponent(info) {
|
|
|
261
265
|
);
|
|
262
266
|
});
|
|
263
267
|
}
|
|
268
|
+
function createRemoteComponent(info) {
|
|
269
|
+
index.LoggerInstance.warn(
|
|
270
|
+
`createRemoteAppComponent is deprecated, please use createRemoteAppComponent instead!`
|
|
271
|
+
);
|
|
272
|
+
return createRemoteAppComponent(info);
|
|
273
|
+
}
|
|
274
|
+
exports.autoFetchDataPlugin = lazyLoadComponentPlugin.autoFetchData;
|
|
275
|
+
exports.collectSSRAssets = lazyLoadComponentPlugin.collectSSRAssets;
|
|
276
|
+
exports.createLazyComponent = lazyLoadComponentPlugin.createLazyComponent;
|
|
277
|
+
exports.lazyLoadComponentPlugin = lazyLoadComponentPlugin.lazyLoadComponentPlugin;
|
|
278
|
+
exports.CacheSize = lazyUtils.CacheSize;
|
|
279
|
+
exports.CacheTime = lazyUtils.CacheTime;
|
|
280
|
+
exports.ERROR_TYPE = lazyUtils.ERROR_TYPE;
|
|
281
|
+
exports.cache = lazyUtils.cache;
|
|
282
|
+
exports.clearStore = lazyUtils.clearStore;
|
|
283
|
+
exports.configureCache = lazyUtils.configureCache;
|
|
284
|
+
exports.generateKey = lazyUtils.generateKey;
|
|
285
|
+
exports.revalidateTag = lazyUtils.revalidateTag;
|
|
286
|
+
exports.setSSREnv = lazyUtils.setSSREnv;
|
|
287
|
+
exports.callDataFetch = dataFetchUtils.callDataFetch;
|
|
288
|
+
exports.prefetch = prefetch.prefetch;
|
|
264
289
|
exports.createBridgeComponent = createBridgeComponent;
|
|
290
|
+
exports.createRemoteAppComponent = createRemoteAppComponent;
|
|
265
291
|
exports.createRemoteComponent = createRemoteComponent;
|