@module-federation/modern-js 0.0.0-next-20250526033636 → 0.0.0-next-20250526035905

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.
Files changed (82) hide show
  1. package/dist/cjs/cli/configPlugin.js +6 -8
  2. package/dist/cjs/cli/configPlugin.spec.js +1 -3
  3. package/dist/cjs/{runtime/wrapNoSSR.js → cli/constant.js} +6 -13
  4. package/dist/cjs/{logger.js → cli/logger.js} +1 -1
  5. package/dist/cjs/cli/ssrPlugin.js +11 -27
  6. package/dist/cjs/cli/utils.js +0 -5
  7. package/dist/cjs/constant.js +2 -49
  8. package/dist/cjs/runtime/createRemoteSSRComponent.js +210 -0
  9. package/dist/cjs/runtime/index.js +2 -11
  10. package/dist/cjs/{interfaces/global.js → ssr-runtime/index.js} +8 -2
  11. package/dist/cjs/ssr-runtime/{devPlugin.js → plugin.js} +6 -9
  12. package/dist/esm/cli/configPlugin.js +7 -9
  13. package/dist/esm/cli/configPlugin.spec.js +1 -3
  14. package/dist/esm/cli/constant.js +4 -0
  15. package/dist/esm/{logger.js → cli/logger.js} +1 -1
  16. package/dist/esm/cli/ssrPlugin.js +7 -24
  17. package/dist/esm/cli/utils.js +0 -4
  18. package/dist/esm/constant.js +1 -37
  19. package/dist/esm/runtime/createRemoteSSRComponent.js +263 -0
  20. package/dist/esm/runtime/index.js +2 -10
  21. package/dist/esm/ssr-runtime/index.js +1 -0
  22. package/dist/esm/ssr-runtime/{devPlugin.js → plugin.js} +2 -5
  23. package/dist/esm-node/cli/configPlugin.js +7 -9
  24. package/dist/esm-node/cli/configPlugin.spec.js +1 -3
  25. package/dist/esm-node/cli/constant.js +4 -0
  26. package/dist/esm-node/{logger.js → cli/logger.js} +1 -1
  27. package/dist/esm-node/cli/ssrPlugin.js +7 -23
  28. package/dist/esm-node/cli/utils.js +0 -4
  29. package/dist/esm-node/constant.js +1 -37
  30. package/dist/esm-node/runtime/createRemoteSSRComponent.js +175 -0
  31. package/dist/esm-node/runtime/index.js +2 -10
  32. package/dist/esm-node/ssr-runtime/index.js +1 -0
  33. package/dist/esm-node/ssr-runtime/{devPlugin.js → plugin.js} +2 -5
  34. package/dist/types/cli/constant.d.ts +1 -0
  35. package/dist/types/cli/index.d.ts +0 -1
  36. package/dist/types/cli/utils.d.ts +0 -1
  37. package/dist/types/constant.d.ts +0 -23
  38. package/dist/types/runtime/createRemoteSSRComponent.d.ts +19 -0
  39. package/dist/types/runtime/index.d.ts +2 -6
  40. package/dist/types/ssr-runtime/index.d.ts +1 -0
  41. package/dist/types/ssr-runtime/plugin.d.ts +2 -0
  42. package/package.json +17 -41
  43. package/dist/cjs/cli/mfRuntimePlugins/auto-fetch-data.js +0 -98
  44. package/dist/cjs/cli/server/data-fetch-server-plugin.js +0 -192
  45. package/dist/cjs/runtime/AwaitDataFetch.js +0 -144
  46. package/dist/cjs/runtime/createRemoteComponent.js +0 -327
  47. package/dist/cjs/ssr-runtime/downgrade.js +0 -108
  48. package/dist/cjs/ssr-runtime/injectDataFetchFunctionPlugin.js +0 -128
  49. package/dist/cjs/utils/dataFetch.js +0 -211
  50. package/dist/cjs/utils/index.js +0 -54
  51. package/dist/esm/cli/mfRuntimePlugins/auto-fetch-data.js +0 -74
  52. package/dist/esm/cli/server/data-fetch-server-plugin.js +0 -240
  53. package/dist/esm/interfaces/global.js +0 -0
  54. package/dist/esm/runtime/AwaitDataFetch.js +0 -131
  55. package/dist/esm/runtime/createRemoteComponent.js +0 -417
  56. package/dist/esm/runtime/wrapNoSSR.js +0 -12
  57. package/dist/esm/ssr-runtime/downgrade.js +0 -143
  58. package/dist/esm/ssr-runtime/injectDataFetchFunctionPlugin.js +0 -168
  59. package/dist/esm/utils/dataFetch.js +0 -237
  60. package/dist/esm/utils/index.js +0 -28
  61. package/dist/esm-node/cli/mfRuntimePlugins/auto-fetch-data.js +0 -68
  62. package/dist/esm-node/cli/server/data-fetch-server-plugin.js +0 -162
  63. package/dist/esm-node/interfaces/global.js +0 -0
  64. package/dist/esm-node/runtime/AwaitDataFetch.js +0 -109
  65. package/dist/esm-node/runtime/createRemoteComponent.js +0 -291
  66. package/dist/esm-node/runtime/wrapNoSSR.js +0 -11
  67. package/dist/esm-node/ssr-runtime/downgrade.js +0 -82
  68. package/dist/esm-node/ssr-runtime/injectDataFetchFunctionPlugin.js +0 -94
  69. package/dist/esm-node/utils/dataFetch.js +0 -166
  70. package/dist/esm-node/utils/index.js +0 -27
  71. package/dist/types/cli/mfRuntimePlugins/auto-fetch-data.d.ts +0 -3
  72. package/dist/types/cli/server/data-fetch-server-plugin.d.ts +0 -3
  73. package/dist/types/interfaces/global.d.ts +0 -27
  74. package/dist/types/runtime/AwaitDataFetch.d.ts +0 -19
  75. package/dist/types/runtime/createRemoteComponent.d.ts +0 -26
  76. package/dist/types/runtime/wrapNoSSR.d.ts +0 -9
  77. package/dist/types/ssr-runtime/devPlugin.d.ts +0 -2
  78. package/dist/types/ssr-runtime/downgrade.d.ts +0 -4
  79. package/dist/types/ssr-runtime/injectDataFetchFunctionPlugin.d.ts +0 -2
  80. package/dist/types/utils/dataFetch.d.ts +0 -26
  81. package/dist/types/utils/index.d.ts +0 -15
  82. /package/dist/types/{logger.d.ts → cli/logger.d.ts} +0 -0
@@ -1,166 +0,0 @@
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
- };
@@ -1,27 +0,0 @@
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
- };
@@ -1,3 +0,0 @@
1
- import type { FederationRuntimePlugin } from '@module-federation/enhanced/runtime';
2
- declare const autoFetchData: () => FederationRuntimePlugin;
3
- export default autoFetchData;
@@ -1,3 +0,0 @@
1
- import type { ServerPlugin } from '@modern-js/server-runtime';
2
- declare const dataFetchServePlugin: () => ServerPlugin;
3
- export default dataFetchServePlugin;
@@ -1,27 +0,0 @@
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
- };
@@ -1,19 +0,0 @@
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;
@@ -1,26 +0,0 @@
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,9 +0,0 @@
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;
@@ -1,2 +0,0 @@
1
- import type { RuntimePluginFuture } from '@modern-js/runtime';
2
- export declare const mfSSRDevPlugin: () => RuntimePluginFuture;
@@ -1,4 +0,0 @@
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>;
@@ -1,2 +0,0 @@
1
- import type { RuntimePluginFuture } from '@modern-js/runtime';
2
- export declare const injectDataFetchFunctionPlugin: () => RuntimePluginFuture;
@@ -1,26 +0,0 @@
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;
@@ -1,15 +0,0 @@
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';
File without changes