@module-federation/modern-js 0.14.3 → 0.16.0
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 +18 -14
- 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 +100 -0
- package/dist/cjs/cli/server/data-fetch-server-plugin.js +189 -0
- package/dist/cjs/cli/ssrPlugin.js +33 -14
- 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 +19 -15
- 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 +76 -0
- package/dist/esm/cli/server/data-fetch-server-plugin.js +237 -0
- package/dist/esm/cli/ssrPlugin.js +28 -8
- 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 +19 -15
- 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 +70 -0
- package/dist/esm-node/cli/server/data-fetch-server-plugin.js +159 -0
- package/dist/esm-node/cli/ssrPlugin.js +27 -8
- 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/configPlugin.d.ts +1 -1
- 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 +37 -12
- package/dist/cjs/cli/manifest.js +0 -75
- package/dist/cjs/runtime/createRemoteSSRComponent.js +0 -201
- package/dist/esm/cli/constant.js +0 -4
- package/dist/esm/cli/manifest.js +0 -41
- 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/cli/manifest.js +0 -41
- 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/cli/manifest.d.ts +0 -2
- 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
|
+
};
|
|
@@ -7,7 +7,7 @@ import type { BundlerChainConfig } from '../interfaces/bundler';
|
|
|
7
7
|
export type ConfigType<T> = T extends 'webpack' ? webpack.Configuration : T extends 'rspack' ? Rspack.Configuration : never;
|
|
8
8
|
export declare function setEnv(enableSSR: boolean): void;
|
|
9
9
|
export declare const getMFConfig: (userConfig: PluginOptions) => Promise<moduleFederationPlugin.ModuleFederationPluginOptions>;
|
|
10
|
-
export declare const patchMFConfig: (mfConfig: moduleFederationPlugin.ModuleFederationPluginOptions, isServer: boolean, remoteIpStrategy?: "ipv4" | "inherit") => moduleFederationPlugin.ModuleFederationPluginOptions;
|
|
10
|
+
export declare const patchMFConfig: (mfConfig: moduleFederationPlugin.ModuleFederationPluginOptions, isServer: boolean, remoteIpStrategy?: "ipv4" | "inherit", enableSSR?: boolean) => moduleFederationPlugin.ModuleFederationPluginOptions;
|
|
11
11
|
export declare function addMyTypes2Ignored(chain: BundlerChainConfig, mfConfig: moduleFederationPlugin.ModuleFederationPluginOptions): void;
|
|
12
12
|
export declare function patchBundlerConfig(options: {
|
|
13
13
|
chain: BundlerChainConfig;
|
|
@@ -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.
|
|
3
|
+
"version": "0.16.0",
|
|
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,11 +52,20 @@
|
|
|
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"
|
|
55
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"
|
|
68
|
+
},
|
|
56
69
|
"./server": {
|
|
57
70
|
"types": "./dist/types/server/index.d.ts",
|
|
58
71
|
"default": "./dist/cjs/server/index.js"
|
|
@@ -78,9 +91,18 @@
|
|
|
78
91
|
"resolve-entry-ipv4": [
|
|
79
92
|
"./dist/types/cli/mfRuntimePlugins/resolve-entry-ipv4.d.ts"
|
|
80
93
|
],
|
|
94
|
+
"auto-fetch-data": [
|
|
95
|
+
"./dist/types/cli/mfRuntimePlugins/auto-fetch-data.d.ts"
|
|
96
|
+
],
|
|
81
97
|
"inject-node-fetch": [
|
|
82
98
|
"./dist/types/cli/mfRuntimePlugins/inject-node-fetch.d.ts"
|
|
83
99
|
],
|
|
100
|
+
"data-fetch-server-plugin": [
|
|
101
|
+
"./dist/types/cli/server/data-fetch-server-plugin.d.ts"
|
|
102
|
+
],
|
|
103
|
+
"ssr-inject-data-fetch-function-plugin": [
|
|
104
|
+
"./dist/types/ssr-runtime/injectDataFetchFunctionPlugin.d.ts"
|
|
105
|
+
],
|
|
84
106
|
"server": [
|
|
85
107
|
"./dist/types/server/index.d.ts"
|
|
86
108
|
]
|
|
@@ -91,26 +113,29 @@
|
|
|
91
113
|
"author": "hanric <hanric.zhang@gmail.com>",
|
|
92
114
|
"license": "MIT",
|
|
93
115
|
"dependencies": {
|
|
116
|
+
"@modern-js/utils": "2.67.5",
|
|
94
117
|
"@modern-js/node-bundle-require": "2.67.6",
|
|
95
118
|
"fs-extra": "11.3.0",
|
|
96
119
|
"lru-cache": "10.4.3",
|
|
97
|
-
"@swc/helpers": "0.5.
|
|
120
|
+
"@swc/helpers": "^0.5.17",
|
|
98
121
|
"node-fetch": "~3.3.0",
|
|
99
122
|
"react-error-boundary": "4.1.2",
|
|
100
|
-
"@module-federation/rsbuild-plugin": "0.
|
|
101
|
-
"@module-federation/enhanced": "0.
|
|
102
|
-
"@module-federation/
|
|
103
|
-
"@module-federation/
|
|
104
|
-
"@module-federation/
|
|
123
|
+
"@module-federation/rsbuild-plugin": "0.16.0",
|
|
124
|
+
"@module-federation/enhanced": "0.16.0",
|
|
125
|
+
"@module-federation/runtime": "0.16.0",
|
|
126
|
+
"@module-federation/node": "2.7.8",
|
|
127
|
+
"@module-federation/sdk": "0.16.0",
|
|
128
|
+
"@module-federation/cli": "0.16.0"
|
|
105
129
|
},
|
|
106
130
|
"devDependencies": {
|
|
107
|
-
"@
|
|
131
|
+
"@modern-js/core": "2.67.5",
|
|
132
|
+
"@rsbuild/core": "1.3.21",
|
|
108
133
|
"@modern-js/app-tools": "2.67.6",
|
|
109
134
|
"@modern-js/server-runtime": "2.67.6",
|
|
110
135
|
"@modern-js/module-tools": "2.67.6",
|
|
111
136
|
"@modern-js/runtime": "2.67.6",
|
|
112
137
|
"@modern-js/tsconfig": "2.67.6",
|
|
113
|
-
"@module-federation/manifest": "0.
|
|
138
|
+
"@module-federation/manifest": "0.16.0"
|
|
114
139
|
},
|
|
115
140
|
"peerDependencies": {
|
|
116
141
|
"react": ">=17",
|
package/dist/cjs/cli/manifest.js
DELETED
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __export = (target, all) => {
|
|
9
|
-
for (var name in all)
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
-
};
|
|
12
|
-
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
-
for (let key of __getOwnPropNames(from))
|
|
15
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
-
}
|
|
18
|
-
return to;
|
|
19
|
-
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
var manifest_exports = {};
|
|
30
|
-
__export(manifest_exports, {
|
|
31
|
-
updateStatsAndManifest: () => updateStatsAndManifest
|
|
32
|
-
});
|
|
33
|
-
module.exports = __toCommonJS(manifest_exports);
|
|
34
|
-
var import_path = __toESM(require("path"));
|
|
35
|
-
var import_fs_extra = __toESM(require("fs-extra"));
|
|
36
|
-
function mergeStats(browserStats, nodeStats) {
|
|
37
|
-
const ssrRemoteEntry = nodeStats.metaData.remoteEntry;
|
|
38
|
-
browserStats.metaData.ssrRemoteEntry = ssrRemoteEntry;
|
|
39
|
-
if ("publicPath" in browserStats.metaData) {
|
|
40
|
-
browserStats.metaData.ssrPublicPath = nodeStats.metaData.publicPath;
|
|
41
|
-
}
|
|
42
|
-
return browserStats;
|
|
43
|
-
}
|
|
44
|
-
function mergeManifest(browserManifest, nodeManifest) {
|
|
45
|
-
const ssrRemoteEntry = nodeManifest.metaData.remoteEntry;
|
|
46
|
-
browserManifest.metaData.ssrRemoteEntry = ssrRemoteEntry;
|
|
47
|
-
if ("publicPath" in browserManifest.metaData) {
|
|
48
|
-
browserManifest.metaData.ssrPublicPath = nodeManifest.metaData.publicPath;
|
|
49
|
-
}
|
|
50
|
-
return browserManifest;
|
|
51
|
-
}
|
|
52
|
-
function mergeStatsAndManifest(nodePlugin, browserPlugin) {
|
|
53
|
-
const nodeResourceInfo = nodePlugin.statsResourceInfo;
|
|
54
|
-
const browserResourceInfo = browserPlugin.statsResourceInfo;
|
|
55
|
-
if (!browserResourceInfo || !nodeResourceInfo || !browserResourceInfo.stats || !nodeResourceInfo.stats || !browserResourceInfo.manifest || !nodeResourceInfo.manifest) {
|
|
56
|
-
throw new Error("can not get browserResourceInfo or nodeResourceInfo");
|
|
57
|
-
}
|
|
58
|
-
const mergedStats = mergeStats(browserResourceInfo.stats.stats, nodeResourceInfo.stats.stats);
|
|
59
|
-
const mergedManifest = mergeManifest(browserResourceInfo.manifest.manifest, nodeResourceInfo.manifest.manifest);
|
|
60
|
-
return {
|
|
61
|
-
mergedStats,
|
|
62
|
-
mergedStatsFilePath: browserResourceInfo.stats.filename,
|
|
63
|
-
mergedManifest,
|
|
64
|
-
mergedManifestFilePath: browserResourceInfo.manifest.filename
|
|
65
|
-
};
|
|
66
|
-
}
|
|
67
|
-
function updateStatsAndManifest(nodePlugin, browserPlugin, outputDir) {
|
|
68
|
-
const { mergedStats, mergedStatsFilePath, mergedManifest, mergedManifestFilePath } = mergeStatsAndManifest(nodePlugin, browserPlugin);
|
|
69
|
-
import_fs_extra.default.writeFileSync(import_path.default.resolve(outputDir, mergedStatsFilePath), JSON.stringify(mergedStats, null, 2));
|
|
70
|
-
import_fs_extra.default.writeFileSync(import_path.default.resolve(outputDir, mergedManifestFilePath), JSON.stringify(mergedManifest, null, 2));
|
|
71
|
-
}
|
|
72
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
73
|
-
0 && (module.exports = {
|
|
74
|
-
updateStatsAndManifest
|
|
75
|
-
});
|