@module-federation/modern-js 0.0.0-next-20250526062606 → 0.0.0-next-20250526074234
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/dist/cjs/cli/configPlugin.js +8 -6
- package/dist/cjs/cli/configPlugin.spec.js +3 -1
- package/dist/cjs/cli/index.js +3 -1
- package/dist/cjs/cli/mfRuntimePlugins/auto-fetch-data.js +98 -0
- package/dist/cjs/cli/server/data-fetch-server-plugin.js +192 -0
- package/dist/cjs/cli/ssrPlugin.js +30 -11
- package/dist/cjs/cli/utils.js +5 -0
- package/dist/cjs/constant.js +49 -2
- package/dist/cjs/{ssr-runtime/index.js → interfaces/global.js} +2 -8
- package/dist/cjs/{cli/logger.js → logger.js} +1 -1
- package/dist/cjs/runtime/AwaitDataFetch.js +144 -0
- package/dist/cjs/runtime/createRemoteComponent.js +327 -0
- package/dist/cjs/runtime/index.js +15 -3
- package/dist/cjs/{cli/constant.js → runtime/wrapNoSSR.js} +13 -6
- package/dist/cjs/ssr-runtime/{plugin.js → devPlugin.js} +9 -6
- package/dist/cjs/ssr-runtime/downgrade.js +114 -0
- package/dist/cjs/ssr-runtime/injectDataFetchFunctionPlugin.js +136 -0
- package/dist/cjs/utils/dataFetch.js +211 -0
- package/dist/cjs/utils/index.js +54 -0
- package/dist/esm/cli/configPlugin.js +9 -7
- package/dist/esm/cli/configPlugin.spec.js +3 -1
- package/dist/esm/cli/index.js +3 -1
- package/dist/esm/cli/mfRuntimePlugins/auto-fetch-data.js +74 -0
- package/dist/esm/cli/server/data-fetch-server-plugin.js +240 -0
- package/dist/esm/cli/ssrPlugin.js +27 -7
- package/dist/esm/cli/utils.js +4 -0
- package/dist/esm/constant.js +37 -1
- package/dist/esm/interfaces/global.js +0 -0
- package/dist/esm/{cli/logger.js → logger.js} +1 -1
- package/dist/esm/runtime/AwaitDataFetch.js +131 -0
- package/dist/esm/runtime/createRemoteComponent.js +417 -0
- package/dist/esm/runtime/index.js +13 -3
- package/dist/esm/runtime/wrapNoSSR.js +12 -0
- package/dist/esm/ssr-runtime/{plugin.js → devPlugin.js} +5 -2
- package/dist/esm/ssr-runtime/downgrade.js +150 -0
- package/dist/esm/ssr-runtime/injectDataFetchFunctionPlugin.js +177 -0
- package/dist/esm/utils/dataFetch.js +237 -0
- package/dist/esm/utils/index.js +28 -0
- package/dist/esm-node/cli/configPlugin.js +9 -7
- package/dist/esm-node/cli/configPlugin.spec.js +3 -1
- package/dist/esm-node/cli/index.js +3 -1
- package/dist/esm-node/cli/mfRuntimePlugins/auto-fetch-data.js +68 -0
- package/dist/esm-node/cli/server/data-fetch-server-plugin.js +162 -0
- package/dist/esm-node/cli/ssrPlugin.js +26 -7
- package/dist/esm-node/cli/utils.js +4 -0
- package/dist/esm-node/constant.js +37 -1
- package/dist/esm-node/interfaces/global.js +0 -0
- package/dist/esm-node/{cli/logger.js → logger.js} +1 -1
- package/dist/esm-node/runtime/AwaitDataFetch.js +109 -0
- package/dist/esm-node/runtime/createRemoteComponent.js +291 -0
- package/dist/esm-node/runtime/index.js +13 -3
- package/dist/esm-node/runtime/wrapNoSSR.js +11 -0
- package/dist/esm-node/ssr-runtime/{plugin.js → devPlugin.js} +5 -2
- package/dist/esm-node/ssr-runtime/downgrade.js +88 -0
- package/dist/esm-node/ssr-runtime/injectDataFetchFunctionPlugin.js +101 -0
- package/dist/esm-node/utils/dataFetch.js +166 -0
- package/dist/esm-node/utils/index.js +27 -0
- package/dist/types/cli/index.d.ts +1 -0
- package/dist/types/cli/mfRuntimePlugins/auto-fetch-data.d.ts +3 -0
- package/dist/types/cli/server/data-fetch-server-plugin.d.ts +3 -0
- package/dist/types/cli/utils.d.ts +1 -0
- package/dist/types/constant.d.ts +23 -0
- package/dist/types/interfaces/global.d.ts +27 -0
- package/dist/types/runtime/AwaitDataFetch.d.ts +19 -0
- package/dist/types/runtime/createRemoteComponent.d.ts +26 -0
- package/dist/types/runtime/index.d.ts +7 -2
- package/dist/types/runtime/wrapNoSSR.d.ts +9 -0
- package/dist/types/ssr-runtime/devPlugin.d.ts +2 -0
- package/dist/types/ssr-runtime/downgrade.d.ts +4 -0
- package/dist/types/ssr-runtime/injectDataFetchFunctionPlugin.d.ts +7 -0
- package/dist/types/types/index.d.ts +2 -0
- package/dist/types/utils/dataFetch.d.ts +26 -0
- package/dist/types/utils/index.d.ts +15 -0
- package/package.json +41 -17
- package/dist/cjs/runtime/createRemoteSSRComponent.js +0 -201
- package/dist/esm/cli/constant.js +0 -4
- package/dist/esm/runtime/createRemoteSSRComponent.js +0 -191
- package/dist/esm/ssr-runtime/index.js +0 -1
- package/dist/esm-node/cli/constant.js +0 -4
- package/dist/esm-node/runtime/createRemoteSSRComponent.js +0 -166
- package/dist/esm-node/ssr-runtime/index.js +0 -1
- package/dist/types/cli/constant.d.ts +0 -1
- package/dist/types/runtime/createRemoteSSRComponent.d.ts +0 -18
- package/dist/types/ssr-runtime/index.d.ts +0 -1
- package/dist/types/ssr-runtime/plugin.d.ts +0 -2
- /package/dist/types/{cli/logger.d.ts → logger.d.ts} +0 -0
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
import { isBrowserEnv, composeKeyWithSeparator } from "@module-federation/sdk";
|
|
2
|
+
import { isCSROnly } from "../utils";
|
|
3
|
+
import logger from "../logger";
|
|
4
|
+
import { callDowngrade, getDowngradeTag } from "../ssr-runtime/downgrade";
|
|
5
|
+
import { DOWNGRADE_KEY, MF_DATA_FETCH_STATUS, WRAP_DATA_FETCH_ID_IDENTIFIER } from "../constant";
|
|
6
|
+
import { DATA_FETCH_CLIENT_SUFFIX, DATA_FETCH_IDENTIFIER } from "@module-federation/rsbuild-plugin/constant";
|
|
7
|
+
const getDataFetchInfo = ({ name, alias, id, remoteSnapshot }) => {
|
|
8
|
+
if (!remoteSnapshot) {
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
if (!("modules" in remoteSnapshot)) {
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
const regex = new RegExp(`^${name}(/[^/].*|)$`);
|
|
15
|
+
const nameOrAlias = regex.test(id) ? name : alias || name;
|
|
16
|
+
const expose = id.replace(nameOrAlias, "");
|
|
17
|
+
let dataFetchName = "";
|
|
18
|
+
let dataFetchId = "";
|
|
19
|
+
if (expose.startsWith("/")) {
|
|
20
|
+
dataFetchName = `${expose.slice(1)}.${DATA_FETCH_IDENTIFIER}`;
|
|
21
|
+
dataFetchId = `${id}.${DATA_FETCH_IDENTIFIER}`;
|
|
22
|
+
} else if (expose === "") {
|
|
23
|
+
dataFetchName = DATA_FETCH_IDENTIFIER;
|
|
24
|
+
dataFetchId = `${id}/${DATA_FETCH_IDENTIFIER}`;
|
|
25
|
+
} else {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
if (!dataFetchName || !dataFetchId) {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
if (!remoteSnapshot.modules.find((module) => module.moduleName === dataFetchName)) {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
return {
|
|
35
|
+
dataFetchName,
|
|
36
|
+
dataFetchId
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
function initDataFetchMap() {
|
|
40
|
+
var _globalThis;
|
|
41
|
+
(_globalThis = globalThis).__MF_DATA_FETCH_MAP__ || (_globalThis.__MF_DATA_FETCH_MAP__ = {});
|
|
42
|
+
}
|
|
43
|
+
function getDataFetchItem(id) {
|
|
44
|
+
var _globalThis___MF_DATA_FETCH_MAP__;
|
|
45
|
+
return (_globalThis___MF_DATA_FETCH_MAP__ = globalThis.__MF_DATA_FETCH_MAP__) === null || _globalThis___MF_DATA_FETCH_MAP__ === void 0 ? void 0 : _globalThis___MF_DATA_FETCH_MAP__[id];
|
|
46
|
+
}
|
|
47
|
+
function getDataFetchMap() {
|
|
48
|
+
return globalThis.__MF_DATA_FETCH_MAP__;
|
|
49
|
+
}
|
|
50
|
+
const flushDataFetch = () => {
|
|
51
|
+
globalThis.__MF_DATA_FETCH_MAP__ = {};
|
|
52
|
+
globalThis[DOWNGRADE_KEY] = void 0;
|
|
53
|
+
};
|
|
54
|
+
function setDataFetchItemLoadedStatus(id) {
|
|
55
|
+
const dataFetchItem = getDataFetchItem(id);
|
|
56
|
+
if (!dataFetchItem) {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
dataFetchItem[2] = MF_DATA_FETCH_STATUS.LOADED;
|
|
60
|
+
}
|
|
61
|
+
const wrapDataFetchId = (id) => {
|
|
62
|
+
return `${WRAP_DATA_FETCH_ID_IDENTIFIER}${id}${WRAP_DATA_FETCH_ID_IDENTIFIER}`;
|
|
63
|
+
};
|
|
64
|
+
const getDataFetchIdWithErrorMsgs = (errMsgs) => {
|
|
65
|
+
const firstIdentifierIndex = errMsgs.indexOf(WRAP_DATA_FETCH_ID_IDENTIFIER);
|
|
66
|
+
if (firstIdentifierIndex === -1) {
|
|
67
|
+
return void 0;
|
|
68
|
+
}
|
|
69
|
+
const secondIdentifierIndex = errMsgs.indexOf(WRAP_DATA_FETCH_ID_IDENTIFIER, firstIdentifierIndex + WRAP_DATA_FETCH_ID_IDENTIFIER.length);
|
|
70
|
+
if (secondIdentifierIndex === -1) {
|
|
71
|
+
return void 0;
|
|
72
|
+
}
|
|
73
|
+
return errMsgs.substring(firstIdentifierIndex + WRAP_DATA_FETCH_ID_IDENTIFIER.length, secondIdentifierIndex);
|
|
74
|
+
};
|
|
75
|
+
async function fetchData(id, params, remoteInfo) {
|
|
76
|
+
const callFetchData = async () => {
|
|
77
|
+
const item = getDataFetchItem(id);
|
|
78
|
+
if (!item) {
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
const [fetchDataFnArr, ..._rest] = item;
|
|
82
|
+
const fetchDataFn = await fetchDataFnArr[2];
|
|
83
|
+
if (!fetchDataFn) {
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
return fetchDataFn(params);
|
|
87
|
+
};
|
|
88
|
+
if (isBrowserEnv()) {
|
|
89
|
+
var _dataFetchItem_;
|
|
90
|
+
const dataFetchItem = getDataFetchItem(id);
|
|
91
|
+
if (!dataFetchItem) {
|
|
92
|
+
throw new Error(`dataFetchItem not found, id: ${id}`);
|
|
93
|
+
}
|
|
94
|
+
if ((_dataFetchItem_ = dataFetchItem[1]) === null || _dataFetchItem_ === void 0 ? void 0 : _dataFetchItem_[0]) {
|
|
95
|
+
return dataFetchItem[1][0];
|
|
96
|
+
}
|
|
97
|
+
if (isCSROnly()) {
|
|
98
|
+
logger.debug("==========csr only!");
|
|
99
|
+
return callFetchData();
|
|
100
|
+
}
|
|
101
|
+
if (remoteInfo) {
|
|
102
|
+
return callDowngrade(id, params, remoteInfo);
|
|
103
|
+
}
|
|
104
|
+
const mfDowngrade = getDowngradeTag();
|
|
105
|
+
if (mfDowngrade) {
|
|
106
|
+
if (typeof mfDowngrade === "boolean") {
|
|
107
|
+
return callDowngrade(id, {
|
|
108
|
+
...params,
|
|
109
|
+
isDowngrade: true
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
if (mfDowngrade.includes(id)) {
|
|
113
|
+
return callDowngrade(id, {
|
|
114
|
+
...params,
|
|
115
|
+
isDowngrade: true
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
let res;
|
|
120
|
+
let rej;
|
|
121
|
+
const p = new Promise((resolve, reject) => {
|
|
122
|
+
res = resolve;
|
|
123
|
+
rej = reject;
|
|
124
|
+
});
|
|
125
|
+
dataFetchItem[1] = [
|
|
126
|
+
p,
|
|
127
|
+
res,
|
|
128
|
+
rej
|
|
129
|
+
];
|
|
130
|
+
dataFetchItem[2] = MF_DATA_FETCH_STATUS.AWAIT;
|
|
131
|
+
return dataFetchItem[1][0];
|
|
132
|
+
}
|
|
133
|
+
return callFetchData();
|
|
134
|
+
}
|
|
135
|
+
function getDataFetchMapKey(dataFetchInfo, hostInfo) {
|
|
136
|
+
if (!dataFetchInfo || !hostInfo) {
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
const { dataFetchId } = dataFetchInfo;
|
|
140
|
+
return composeKeyWithSeparator(dataFetchId, hostInfo.name, hostInfo.version);
|
|
141
|
+
}
|
|
142
|
+
async function loadDataFetchModule(instance, id) {
|
|
143
|
+
return instance.loadRemote(id).then((m) => {
|
|
144
|
+
if (m && typeof m === "object" && "fetchData" in m && typeof m.fetchData === "function") {
|
|
145
|
+
return m.fetchData;
|
|
146
|
+
}
|
|
147
|
+
throw new Error(`fetchData not found in remote ${id}, ${JSON.stringify(m)}`);
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
function isDataLoaderExpose(exposeKey) {
|
|
151
|
+
return exposeKey.endsWith(DATA_FETCH_IDENTIFIER) || exposeKey.endsWith(DATA_FETCH_CLIENT_SUFFIX);
|
|
152
|
+
}
|
|
153
|
+
export {
|
|
154
|
+
fetchData,
|
|
155
|
+
flushDataFetch,
|
|
156
|
+
getDataFetchIdWithErrorMsgs,
|
|
157
|
+
getDataFetchInfo,
|
|
158
|
+
getDataFetchItem,
|
|
159
|
+
getDataFetchMap,
|
|
160
|
+
getDataFetchMapKey,
|
|
161
|
+
initDataFetchMap,
|
|
162
|
+
isDataLoaderExpose,
|
|
163
|
+
loadDataFetchModule,
|
|
164
|
+
setDataFetchItemLoadedStatus,
|
|
165
|
+
wrapDataFetchId
|
|
166
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
function getLoadedRemoteInfos(id, instance) {
|
|
2
|
+
if (!instance) {
|
|
3
|
+
return;
|
|
4
|
+
}
|
|
5
|
+
const { name, expose } = instance.remoteHandler.idToRemoteMap[id] || {};
|
|
6
|
+
if (!name) {
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
const module = instance.moduleCache.get(name);
|
|
10
|
+
if (!module) {
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
const { remoteSnapshot } = instance.snapshotHandler.getGlobalRemoteInfo(module.remoteInfo);
|
|
14
|
+
return {
|
|
15
|
+
...module.remoteInfo,
|
|
16
|
+
snapshot: remoteSnapshot,
|
|
17
|
+
expose
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
function isCSROnly() {
|
|
21
|
+
return window._SSR_DATA === void 0;
|
|
22
|
+
}
|
|
23
|
+
export * from "./dataFetch";
|
|
24
|
+
export {
|
|
25
|
+
getLoadedRemoteInfos,
|
|
26
|
+
isCSROnly
|
|
27
|
+
};
|
|
@@ -3,3 +3,4 @@ import type { PluginOptions } from '../types';
|
|
|
3
3
|
export declare const moduleFederationPlugin: (userConfig?: PluginOptions) => CliPluginFuture<AppTools>;
|
|
4
4
|
export default moduleFederationPlugin;
|
|
5
5
|
export { createModuleFederationConfig } from '@module-federation/enhanced';
|
|
6
|
+
export type { FederationRuntimePlugin } from '@module-federation/enhanced/runtime';
|
|
@@ -3,3 +3,4 @@ export type ConfigType<T> = T extends 'webpack' ? webpack.Configuration : T exte
|
|
|
3
3
|
export declare const getIPV4: () => string;
|
|
4
4
|
export declare const isWebTarget: (target: string[] | string) => boolean;
|
|
5
5
|
export declare const skipByTarget: (target: string[] | string) => boolean;
|
|
6
|
+
export declare function isDev(): boolean;
|
package/dist/types/constant.d.ts
CHANGED
|
@@ -1,2 +1,25 @@
|
|
|
1
1
|
export declare const LOCALHOST = "localhost";
|
|
2
2
|
export declare const PLUGIN_IDENTIFIER = "[ Modern.js Module Federation ]";
|
|
3
|
+
export declare const DATA_FETCH_QUERY = "x-mf-data-fetch";
|
|
4
|
+
export declare const DATA_FETCH_ERROR_PREFIX = "caught the following error during dataFetch: ";
|
|
5
|
+
export declare const LOAD_REMOTE_ERROR_PREFIX = "caught the following error during loadRemote: ";
|
|
6
|
+
export declare const DOWNGRADE_KEY = "_mfSSRDowngrade";
|
|
7
|
+
export declare const DATA_FETCH_MAP_KEY = "__MF_DATA_FETCH_MAP__";
|
|
8
|
+
export declare const DATA_FETCH_FUNCTION = "_mfDataFetch";
|
|
9
|
+
export declare const FS_HREF = "_mfFSHref";
|
|
10
|
+
export declare const ERROR_TYPE: {
|
|
11
|
+
DATA_FETCH: number;
|
|
12
|
+
LOAD_REMOTE: number;
|
|
13
|
+
UNKNOWN: number;
|
|
14
|
+
};
|
|
15
|
+
export declare const WRAP_DATA_FETCH_ID_IDENTIFIER = "wrap_dfip_identifier";
|
|
16
|
+
export declare const enum MF_DATA_FETCH_TYPE {
|
|
17
|
+
FETCH_SERVER = 1,
|
|
18
|
+
FETCH_CLIENT = 2
|
|
19
|
+
}
|
|
20
|
+
export declare const enum MF_DATA_FETCH_STATUS {
|
|
21
|
+
LOADED = 1,
|
|
22
|
+
LOADING = 2,
|
|
23
|
+
AWAIT = 0,
|
|
24
|
+
ERROR = 3
|
|
25
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { MF_DATA_FETCH_TYPE, MF_DATA_FETCH_STATUS } from '../constant';
|
|
2
|
+
export type DataFetchParams = {
|
|
3
|
+
isDowngrade: boolean;
|
|
4
|
+
} & Record<string, unknown>;
|
|
5
|
+
export type DataFetch<T> = (params: DataFetchParams) => Promise<T>;
|
|
6
|
+
export type MF_DATA_FETCH_MAP_VALUE = [
|
|
7
|
+
[
|
|
8
|
+
() => Promise<DataFetch<unknown>>,
|
|
9
|
+
MF_DATA_FETCH_TYPE,
|
|
10
|
+
Promise<DataFetch<unknown>>?
|
|
11
|
+
],
|
|
12
|
+
[
|
|
13
|
+
Promise<unknown>,
|
|
14
|
+
((data: unknown) => void)?,
|
|
15
|
+
((err: unknown) => void)?
|
|
16
|
+
]?,
|
|
17
|
+
MF_DATA_FETCH_STATUS?
|
|
18
|
+
];
|
|
19
|
+
export type MF_DATA_FETCH_MAP = Record<string, MF_DATA_FETCH_MAP_VALUE>;
|
|
20
|
+
export type MF_SSR_DOWNGRADE = string[] | true | undefined;
|
|
21
|
+
export type NoSSRRemoteInfo = {
|
|
22
|
+
name: string;
|
|
23
|
+
version: string;
|
|
24
|
+
ssrPublicPath: string;
|
|
25
|
+
ssrRemoteEntry: string;
|
|
26
|
+
globalName: string;
|
|
27
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import React, { ReactNode } from 'react';
|
|
2
|
+
import type { DataFetchParams } from '../interfaces/global';
|
|
3
|
+
export type ErrorInfo = {
|
|
4
|
+
error: Error;
|
|
5
|
+
errorType: number;
|
|
6
|
+
dataFetchMapKey?: string;
|
|
7
|
+
};
|
|
8
|
+
export declare const transformError: (err: string | Error) => ErrorInfo;
|
|
9
|
+
export interface AwaitProps<T> {
|
|
10
|
+
resolve: T | Promise<T>;
|
|
11
|
+
loading?: ReactNode;
|
|
12
|
+
errorElement?: ReactNode | ((errorInfo: ErrorInfo) => ReactNode);
|
|
13
|
+
children: (data: T) => ReactNode;
|
|
14
|
+
params?: DataFetchParams;
|
|
15
|
+
}
|
|
16
|
+
export interface AwaitErrorHandlerProps<T = any> extends Omit<AwaitProps<T>, 'resolve'> {
|
|
17
|
+
resolve: () => T | string;
|
|
18
|
+
}
|
|
19
|
+
export declare function AwaitDataFetch<T>({ resolve, loading, errorElement, children, params, }: AwaitProps<T>): React.JSX.Element;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import React, { ReactNode } from 'react';
|
|
2
|
+
import type { ErrorInfo } from './AwaitDataFetch';
|
|
3
|
+
import type { DataFetchParams } from '../interfaces/global';
|
|
4
|
+
type IProps = {
|
|
5
|
+
id: string;
|
|
6
|
+
injectScript?: boolean;
|
|
7
|
+
injectLink?: boolean;
|
|
8
|
+
};
|
|
9
|
+
export type CreateRemoteComponentOptions<T, E extends keyof T> = {
|
|
10
|
+
loader: () => Promise<T>;
|
|
11
|
+
loading: React.ReactNode;
|
|
12
|
+
fallback: ReactNode | ((errorInfo: ErrorInfo) => ReactNode);
|
|
13
|
+
export?: E;
|
|
14
|
+
dataFetchParams?: DataFetchParams;
|
|
15
|
+
noSSR?: boolean;
|
|
16
|
+
};
|
|
17
|
+
type ReactKey = {
|
|
18
|
+
key?: React.Key | null;
|
|
19
|
+
};
|
|
20
|
+
export declare function collectSSRAssets(options: IProps): React.ReactNode[];
|
|
21
|
+
export declare function createRemoteComponent<T, E extends keyof T>(options: CreateRemoteComponentOptions<T, E>): (props: T[E] extends (...args: any) => any ? Parameters<T[E]>[0] extends undefined ? ReactKey : Parameters<T[E]>[0] & ReactKey : ReactKey) => React.JSX.Element;
|
|
22
|
+
/**
|
|
23
|
+
* @deprecated createRemoteSSRComponent is deprecated, please use createRemoteComponent instead!
|
|
24
|
+
*/
|
|
25
|
+
export declare function createRemoteSSRComponent<T, E extends keyof T>(options: CreateRemoteComponentOptions<T, E>): (props: T[E] extends (...args: any) => any ? Parameters<T[E]>[0] extends undefined ? ReactKey : Parameters<T[E]>[0] & ReactKey : ReactKey) => React.JSX.Element;
|
|
26
|
+
export {};
|
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
export * from '@module-federation/enhanced/runtime';
|
|
2
|
+
export type { DataFetchParams } from '../interfaces/global';
|
|
3
|
+
export { ERROR_TYPE } from '../constant';
|
|
2
4
|
export declare const kit: {
|
|
3
|
-
readonly createRemoteSSRComponent:
|
|
4
|
-
readonly
|
|
5
|
+
readonly createRemoteSSRComponent: typeof import("./createRemoteComponent").createRemoteSSRComponent;
|
|
6
|
+
readonly createRemoteComponent: typeof import("./createRemoteComponent").createRemoteComponent;
|
|
7
|
+
readonly collectSSRAssets: typeof import("./createRemoteComponent").collectSSRAssets;
|
|
8
|
+
readonly wrapNoSSR: typeof import("./wrapNoSSR").wrapNoSSR;
|
|
5
9
|
};
|
|
10
|
+
export { setSSREnv } from '../ssr-runtime/injectDataFetchFunctionPlugin';
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { createRemoteComponent } from './createRemoteComponent';
|
|
2
|
+
import type { CreateRemoteComponentOptions } from './createRemoteComponent';
|
|
3
|
+
export declare function wrapNoSSR<T, E extends keyof T>(createComponentFn: typeof createRemoteComponent<T, E>): (options: Omit<CreateRemoteComponentOptions<T, E>, "noSSR">) => (props: T[E] extends (...args: any) => any ? Parameters<T[E]>[0] extends undefined ? {
|
|
4
|
+
key?: import("react").Key | null;
|
|
5
|
+
} : Parameters<T[E]>[0] & {
|
|
6
|
+
key?: import("react").Key | null;
|
|
7
|
+
} : {
|
|
8
|
+
key?: import("react").Key | null;
|
|
9
|
+
}) => import("react").JSX.Element;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { DataFetchParams, MF_SSR_DOWNGRADE, NoSSRRemoteInfo } from '../interfaces/global';
|
|
2
|
+
export declare function getDowngradeTag(): MF_SSR_DOWNGRADE;
|
|
3
|
+
export declare function callAllDowngrade(): void;
|
|
4
|
+
export declare function callDowngrade(id: string, params?: DataFetchParams, remoteInfo?: NoSSRRemoteInfo): Promise<any>;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { RuntimePluginFuture } from '@modern-js/runtime';
|
|
2
|
+
export declare function setSSREnv({ fetchServerQuery, }: {
|
|
3
|
+
fetchServerQuery?: Record<string, unknown>;
|
|
4
|
+
}): void;
|
|
5
|
+
export declare const injectDataFetchFunctionPlugin: ({ fetchServerQuery, }: {
|
|
6
|
+
fetchServerQuery?: Record<string, unknown>;
|
|
7
|
+
}) => RuntimePluginFuture;
|
|
@@ -8,6 +8,7 @@ export interface PluginOptions {
|
|
|
8
8
|
distOutputDir?: string;
|
|
9
9
|
} | boolean;
|
|
10
10
|
remoteIpStrategy?: 'ipv4' | 'inherit';
|
|
11
|
+
fetchServerQuery?: Record<string, unknown>;
|
|
11
12
|
}
|
|
12
13
|
export interface InternalModernPluginOptions {
|
|
13
14
|
csrConfig?: moduleFederationPlugin.ModuleFederationPluginOptions;
|
|
@@ -18,5 +19,6 @@ export interface InternalModernPluginOptions {
|
|
|
18
19
|
nodePlugin?: BundlerPlugin;
|
|
19
20
|
remoteIpStrategy?: 'ipv4' | 'inherit';
|
|
20
21
|
userConfig?: PluginOptions;
|
|
22
|
+
fetchServerQuery?: Record<string, unknown>;
|
|
21
23
|
}
|
|
22
24
|
export type BundlerPlugin = WebpackModuleFederationPlugin | RspackModuleFederationPlugin;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { GlobalModuleInfo } from '@module-federation/sdk';
|
|
2
|
+
import type { DataFetchParams, MF_DATA_FETCH_MAP, NoSSRRemoteInfo } from '../interfaces/global';
|
|
3
|
+
import type { FederationHost } from '@module-federation/enhanced/runtime';
|
|
4
|
+
export declare const getDataFetchInfo: ({ name, alias, id, remoteSnapshot, }: {
|
|
5
|
+
id: string;
|
|
6
|
+
name: string;
|
|
7
|
+
remoteSnapshot: GlobalModuleInfo[string];
|
|
8
|
+
alias?: string;
|
|
9
|
+
}) => {
|
|
10
|
+
dataFetchName: string;
|
|
11
|
+
dataFetchId: string;
|
|
12
|
+
} | undefined;
|
|
13
|
+
export declare function initDataFetchMap(): void;
|
|
14
|
+
export declare function getDataFetchItem(id: string): import("../interfaces/global").MF_DATA_FETCH_MAP_VALUE;
|
|
15
|
+
export declare function getDataFetchMap(): MF_DATA_FETCH_MAP;
|
|
16
|
+
export declare const flushDataFetch: () => void;
|
|
17
|
+
export declare function setDataFetchItemLoadedStatus(id: string): void;
|
|
18
|
+
export declare const wrapDataFetchId: (id?: string) => string;
|
|
19
|
+
export declare const getDataFetchIdWithErrorMsgs: (errMsgs: string) => string | undefined;
|
|
20
|
+
export declare function fetchData(id: string, params: DataFetchParams, remoteInfo?: NoSSRRemoteInfo): Promise<unknown | undefined>;
|
|
21
|
+
export declare function getDataFetchMapKey(dataFetchInfo?: ReturnType<typeof getDataFetchInfo>, hostInfo?: {
|
|
22
|
+
name: string;
|
|
23
|
+
version?: string;
|
|
24
|
+
}): string | undefined;
|
|
25
|
+
export declare function loadDataFetchModule(instance: FederationHost, id: string): Promise<(params: DataFetchParams) => Promise<unknown>>;
|
|
26
|
+
export declare function isDataLoaderExpose(exposeKey: string): boolean;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { FederationHost } from '@module-federation/enhanced/runtime';
|
|
2
|
+
export declare function getLoadedRemoteInfos(id: string, instance: FederationHost | null): {
|
|
3
|
+
snapshot: import("@module-federation/sdk/.").ModuleInfo | import("@module-federation/sdk/.").ManifestProvider | import("@module-federation/sdk/.").PureEntryProvider | undefined;
|
|
4
|
+
expose: string;
|
|
5
|
+
alias?: string;
|
|
6
|
+
name: string;
|
|
7
|
+
version?: string;
|
|
8
|
+
buildVersion?: string;
|
|
9
|
+
entry: string;
|
|
10
|
+
type: import("@module-federation/sdk/.").RemoteEntryType;
|
|
11
|
+
entryGlobalName: string;
|
|
12
|
+
shareScope: string | string[];
|
|
13
|
+
} | undefined;
|
|
14
|
+
export declare function isCSROnly(): boolean;
|
|
15
|
+
export * from './dataFetch';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@module-federation/modern-js",
|
|
3
|
-
"version": "0.0.0-next-
|
|
3
|
+
"version": "0.0.0-next-20250526074234",
|
|
4
4
|
"files": [
|
|
5
5
|
"dist/",
|
|
6
6
|
"types.d.ts",
|
|
@@ -24,9 +24,13 @@
|
|
|
24
24
|
"types": "./dist/types/runtime/index.d.ts",
|
|
25
25
|
"default": "./dist/esm/runtime/index.js"
|
|
26
26
|
},
|
|
27
|
-
"./ssr-
|
|
28
|
-
"types": "./dist/types/ssr-runtime/
|
|
29
|
-
"default": "./dist/esm/ssr-runtime/
|
|
27
|
+
"./ssr-dev-plugin": {
|
|
28
|
+
"types": "./dist/types/ssr-runtime/devPlugin.d.ts",
|
|
29
|
+
"default": "./dist/esm/ssr-runtime/devPlugin.js"
|
|
30
|
+
},
|
|
31
|
+
"./ssr-inject-data-fetch-function-plugin": {
|
|
32
|
+
"types": "./dist/types/ssr-runtime/injectDataFetchFunctionPlugin.d.ts",
|
|
33
|
+
"default": "./dist/esm/ssr-runtime/injectDataFetchFunctionPlugin.js"
|
|
30
34
|
},
|
|
31
35
|
"./config-plugin": {
|
|
32
36
|
"types": "./dist/types/cli/configPlugin.d.ts",
|
|
@@ -48,10 +52,19 @@
|
|
|
48
52
|
"import": "./dist/esm/cli/mfRuntimePlugins/resolve-entry-ipv4.js",
|
|
49
53
|
"require": "./dist/esm/cli/mfRuntimePlugins/resolve-entry-ipv4.js"
|
|
50
54
|
},
|
|
55
|
+
"./auto-fetch-data": {
|
|
56
|
+
"types": "./dist/types/cli/mfRuntimePlugins/auto-fetch-data.d.ts",
|
|
57
|
+
"import": "./dist/esm/cli/mfRuntimePlugins/auto-fetch-data.js",
|
|
58
|
+
"require": "./dist/esm/cli/mfRuntimePlugins/auto-fetch-data.js"
|
|
59
|
+
},
|
|
51
60
|
"./inject-node-fetch": {
|
|
52
61
|
"types": "./dist/types/cli/mfRuntimePlugins/inject-node-fetch.d.ts",
|
|
53
62
|
"import": "./dist/esm/cli/mfRuntimePlugins/inject-node-fetch.js",
|
|
54
63
|
"require": "./dist/esm/cli/mfRuntimePlugins/inject-node-fetch.js"
|
|
64
|
+
},
|
|
65
|
+
"./data-fetch-server-plugin": {
|
|
66
|
+
"types": "./dist/types/cli/server/data-fetch-server-plugin.d.ts",
|
|
67
|
+
"default": "./dist/cjs/cli/server/data-fetch-server-plugin.js"
|
|
55
68
|
}
|
|
56
69
|
},
|
|
57
70
|
"typesVersions": {
|
|
@@ -74,8 +87,17 @@
|
|
|
74
87
|
"resolve-entry-ipv4": [
|
|
75
88
|
"./dist/types/cli/mfRuntimePlugins/resolve-entry-ipv4.d.ts"
|
|
76
89
|
],
|
|
90
|
+
"auto-fetch-data": [
|
|
91
|
+
"./dist/types/cli/mfRuntimePlugins/auto-fetch-data.d.ts"
|
|
92
|
+
],
|
|
77
93
|
"inject-node-fetch": [
|
|
78
94
|
"./dist/types/cli/mfRuntimePlugins/inject-node-fetch.d.ts"
|
|
95
|
+
],
|
|
96
|
+
"data-fetch-server-plugin": [
|
|
97
|
+
"./dist/types/cli/server/data-fetch-server-plugin.d.ts"
|
|
98
|
+
],
|
|
99
|
+
"ssr-inject-data-fetch-function-plugin": [
|
|
100
|
+
"./dist/types/cli/server/data-fetch-server-plugin.d.ts"
|
|
79
101
|
]
|
|
80
102
|
}
|
|
81
103
|
},
|
|
@@ -84,25 +106,27 @@
|
|
|
84
106
|
"author": "hanric <hanric.zhang@gmail.com>",
|
|
85
107
|
"license": "MIT",
|
|
86
108
|
"dependencies": {
|
|
87
|
-
"@modern-js/node-bundle-require": "2.
|
|
88
|
-
"@modern-js/utils": "2.
|
|
109
|
+
"@modern-js/node-bundle-require": "2.67.5",
|
|
110
|
+
"@modern-js/utils": "2.67.5",
|
|
89
111
|
"@swc/helpers": "0.5.13",
|
|
90
112
|
"node-fetch": "~3.3.0",
|
|
91
113
|
"react-error-boundary": "4.1.2",
|
|
92
|
-
"@module-federation/rsbuild-plugin": "0.0.0-next-
|
|
93
|
-
"@module-federation/enhanced": "0.0.0-next-
|
|
94
|
-
"@module-federation/
|
|
95
|
-
"@module-federation/
|
|
96
|
-
"@module-federation/
|
|
114
|
+
"@module-federation/rsbuild-plugin": "0.0.0-next-20250526074234",
|
|
115
|
+
"@module-federation/enhanced": "0.0.0-next-20250526074234",
|
|
116
|
+
"@module-federation/runtime": "0.0.0-next-20250526074234",
|
|
117
|
+
"@module-federation/node": "0.0.0-next-20250526074234",
|
|
118
|
+
"@module-federation/sdk": "0.0.0-next-20250526074234",
|
|
119
|
+
"@module-federation/cli": "0.0.0-next-20250526074234"
|
|
97
120
|
},
|
|
98
121
|
"devDependencies": {
|
|
99
122
|
"@rsbuild/core": "1.2.8",
|
|
100
|
-
"@modern-js/app-tools": "2.
|
|
101
|
-
"@modern-js/core": "2.
|
|
102
|
-
"@modern-js/module-tools": "2.
|
|
103
|
-
"@modern-js/runtime": "2.
|
|
104
|
-
"@modern-js/tsconfig": "2.
|
|
105
|
-
"@
|
|
123
|
+
"@modern-js/app-tools": "2.67.5",
|
|
124
|
+
"@modern-js/core": "2.67.5",
|
|
125
|
+
"@modern-js/module-tools": "2.67.5",
|
|
126
|
+
"@modern-js/runtime": "2.67.5",
|
|
127
|
+
"@modern-js/tsconfig": "2.67.5",
|
|
128
|
+
"@modern-js/server-runtime": "2.67.5",
|
|
129
|
+
"@module-federation/manifest": "0.0.0-next-20250526074234"
|
|
106
130
|
},
|
|
107
131
|
"peerDependencies": {
|
|
108
132
|
"react": ">=17",
|