@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.
Files changed (80) hide show
  1. package/CHANGELOG.md +39 -0
  2. package/__tests__/bridge.spec.tsx +10 -10
  3. package/__tests__/createLazyComponent.spec.tsx +209 -0
  4. package/__tests__/prefetch.spec.ts +156 -0
  5. package/__tests__/router.spec.tsx +3 -3
  6. package/__tests__/setupTests.ts +8 -0
  7. package/dist/{bridge-base-P6pEjY1q.js → bridge-base-BoshEggF.mjs} +1 -1
  8. package/dist/{bridge-base-BBH982Tz.cjs → bridge-base-UGCwcMnG.js} +1 -1
  9. package/dist/data-fetch-server-middleware.cjs.js +163 -0
  10. package/dist/data-fetch-server-middleware.d.ts +15 -0
  11. package/dist/data-fetch-server-middleware.es.js +164 -0
  12. package/dist/data-fetch-utils.cjs.js +24 -0
  13. package/dist/data-fetch-utils.d.ts +81 -0
  14. package/dist/data-fetch-utils.es.js +26 -0
  15. package/dist/index-C0fDZB5b.js +45 -0
  16. package/dist/index-CqxytsLY.mjs +46 -0
  17. package/dist/index.cjs.js +35 -9
  18. package/dist/index.d.ts +141 -1
  19. package/dist/index.es.js +39 -13
  20. package/dist/index.esm-BCeUd-x9.mjs +418 -0
  21. package/dist/index.esm-j_1sIRzg.js +417 -0
  22. package/dist/lazy-load-component-plugin-B80Ud11k.js +521 -0
  23. package/dist/lazy-load-component-plugin-_UbR2mWQ.mjs +522 -0
  24. package/dist/lazy-load-component-plugin.cjs.js +6 -0
  25. package/dist/lazy-load-component-plugin.d.ts +16 -0
  26. package/dist/lazy-load-component-plugin.es.js +6 -0
  27. package/dist/lazy-utils.cjs.js +24 -0
  28. package/dist/lazy-utils.d.ts +149 -0
  29. package/dist/lazy-utils.es.js +24 -0
  30. package/dist/plugin.d.ts +13 -4
  31. package/dist/prefetch-BaKIdUwP.js +1338 -0
  32. package/dist/prefetch-YpJYjpWC.mjs +1339 -0
  33. package/dist/router-v5.cjs.js +1 -1
  34. package/dist/router-v5.d.ts +9 -0
  35. package/dist/router-v5.es.js +1 -1
  36. package/dist/router-v6.cjs.js +1 -1
  37. package/dist/router-v6.d.ts +9 -0
  38. package/dist/router-v6.es.js +1 -1
  39. package/dist/router.cjs.js +1 -1
  40. package/dist/router.d.ts +9 -0
  41. package/dist/router.es.js +1 -1
  42. package/dist/utils-C4oPJV34.mjs +2016 -0
  43. package/dist/utils-iEVlDmyk.js +2015 -0
  44. package/dist/v18.cjs.js +1 -1
  45. package/dist/v18.d.ts +9 -0
  46. package/dist/v18.es.js +1 -1
  47. package/dist/v19.cjs.js +1 -1
  48. package/dist/v19.d.ts +9 -0
  49. package/dist/v19.es.js +1 -1
  50. package/jest.config.ts +21 -0
  51. package/package.json +48 -6
  52. package/project.json +4 -8
  53. package/src/index.ts +32 -1
  54. package/src/lazy/AwaitDataFetch.tsx +215 -0
  55. package/src/lazy/constant.ts +30 -0
  56. package/src/lazy/createLazyComponent.tsx +411 -0
  57. package/src/lazy/data-fetch/cache.ts +291 -0
  58. package/src/lazy/data-fetch/call-data-fetch.ts +13 -0
  59. package/src/lazy/data-fetch/data-fetch-server-middleware.ts +196 -0
  60. package/src/lazy/data-fetch/index.ts +16 -0
  61. package/src/lazy/data-fetch/inject-data-fetch.ts +109 -0
  62. package/src/lazy/data-fetch/prefetch.ts +106 -0
  63. package/src/lazy/data-fetch/runtime-plugin.ts +115 -0
  64. package/src/lazy/index.ts +35 -0
  65. package/src/lazy/logger.ts +6 -0
  66. package/src/lazy/types.ts +75 -0
  67. package/src/lazy/utils.ts +372 -0
  68. package/src/lazy/wrapNoSSR.tsx +10 -0
  69. package/src/plugins/lazy-load-component-plugin.spec.ts +21 -0
  70. package/src/plugins/lazy-load-component-plugin.ts +57 -0
  71. package/src/provider/plugin.ts +4 -4
  72. package/src/remote/component.tsx +3 -3
  73. package/src/remote/create.tsx +18 -5
  74. package/tsconfig.json +1 -1
  75. package/tsconfig.spec.json +26 -0
  76. package/vite.config.ts +13 -0
  77. package/vitest.config.ts +6 -1
  78. package/dist/index-Cv3p6r66.cjs +0 -235
  79. package/dist/index-D4yt7Udv.js +0 -236
  80. package/src/.eslintrc.js +0 -9
@@ -0,0 +1,149 @@
1
+ import { GlobalModuleInfo } from '@module-federation/sdk';
2
+ import { LRUCache } from 'lru-cache';
3
+ import { ManifestProvider } from '@module-federation/sdk';
4
+ import { ModuleFederation } from '@module-federation/runtime';
5
+ import { ModuleInfo } from '@module-federation/sdk';
6
+ import { PureEntryProvider } from '@module-federation/sdk';
7
+ import { RemoteEntryType } from '@module-federation/sdk';
8
+
9
+ declare interface CacheConfig {
10
+ maxSize?: number;
11
+ unstable_shouldDisable?: ({ request, }: {
12
+ request: Request;
13
+ }) => boolean | Promise<boolean>;
14
+ }
15
+
16
+ declare interface CacheItem<T> {
17
+ data: T;
18
+ timestamp: number;
19
+ isRevalidating?: boolean;
20
+ }
21
+
22
+ export declare function callAllDowngrade(): void;
23
+
24
+ export declare function callDowngrade(id: string, params?: DataFetchParams, remoteInfo?: NoSSRRemoteInfo): Promise<unknown>;
25
+
26
+ declare type DataFetch<T> = (params: DataFetchParams) => Promise<T>;
27
+
28
+ declare type DataFetchParams = {
29
+ isDowngrade: boolean;
30
+ _id?: string;
31
+ } & Record<string, unknown>;
32
+
33
+ export declare function fetchData(id: string, params: DataFetchParams, remoteInfo?: NoSSRRemoteInfo): Promise<unknown | undefined>;
34
+
35
+ export declare const flushDataFetch: () => void;
36
+
37
+ export declare function getDataFetchCache(): MF_DATA_FETCH_CACHE;
38
+
39
+ export declare const getDataFetchIdWithErrorMsgs: (errMsgs: string) => string | undefined;
40
+
41
+ export declare const getDataFetchInfo: ({ name, alias, id, remoteSnapshot, }: {
42
+ id: string;
43
+ name: string;
44
+ remoteSnapshot: GlobalModuleInfo[string];
45
+ alias?: string;
46
+ }) => {
47
+ dataFetchName: string;
48
+ dataFetchId: string;
49
+ dataFetchKey: string;
50
+ } | undefined;
51
+
52
+ export declare function getDataFetchItem(id: string): MF_DATA_FETCH_MAP_VALUE;
53
+
54
+ export declare function getDataFetchMap(): MF_DATA_FETCH_MAP;
55
+
56
+ export declare function getDataFetchMapKey(dataFetchInfo?: ReturnType<typeof getDataFetchInfo>, hostInfo?: {
57
+ name: string;
58
+ version?: string;
59
+ }): string | undefined;
60
+
61
+ export declare function getDowngradeTag(): MF_SSR_DOWNGRADE;
62
+
63
+ export declare function getLoadedRemoteInfos(id: string, instance: ModuleFederation | null): {
64
+ snapshot: ModuleInfo | ManifestProvider | PureEntryProvider | undefined;
65
+ expose: string;
66
+ alias?: string;
67
+ name: string;
68
+ version?: string;
69
+ buildVersion?: string;
70
+ entry: string;
71
+ type: RemoteEntryType;
72
+ entryGlobalName: string;
73
+ shareScope: string | string[];
74
+ } | undefined;
75
+
76
+ export declare function initDataFetchMap(): void;
77
+
78
+ export declare function isCSROnly(): boolean;
79
+
80
+ export declare function isDataLoaderExpose(exposeKey: string): boolean;
81
+
82
+ export declare function isServerEnv(): boolean;
83
+
84
+ export declare function loadDataFetchModule(instance: ModuleFederation, id: string): Promise<(params: DataFetchParams) => Promise<unknown>>;
85
+
86
+ declare type MF_DATA_FETCH_CACHE = {
87
+ cacheStore?: LRUCache<string, Map<string, CacheItem<any>>>;
88
+ tagKeyMap?: Map<string, Set<string>>;
89
+ cacheConfig?: CacheConfig;
90
+ };
91
+
92
+ declare type MF_DATA_FETCH_MAP = Record<string, MF_DATA_FETCH_MAP_VALUE>;
93
+
94
+ declare type MF_DATA_FETCH_MAP_VALUE = [
95
+ [
96
+ () => Promise<DataFetch<unknown>>,
97
+ MF_DATA_FETCH_TYPE,
98
+ Promise<DataFetch<unknown>>?
99
+ ],
100
+ MF_DATA_FETCH_MAP_VALUE_PROMISE_SET?,
101
+ MF_DATA_FETCH_STATUS?
102
+ ];
103
+
104
+ declare type MF_DATA_FETCH_MAP_VALUE_PROMISE_SET = [
105
+ Promise<unknown>,
106
+ ((data: unknown) => void)?,
107
+ ((err: unknown) => void)?
108
+ ];
109
+
110
+ declare const enum MF_DATA_FETCH_STATUS {
111
+ LOADED = 1,
112
+ LOADING = 2,
113
+ AWAIT = 0,
114
+ ERROR = 3
115
+ }
116
+
117
+ declare const enum MF_DATA_FETCH_TYPE {
118
+ FETCH_SERVER = 1,
119
+ FETCH_CLIENT = 2
120
+ }
121
+
122
+ declare type MF_SSR_DOWNGRADE = string[] | true | undefined;
123
+
124
+ declare type NoSSRRemoteInfo = {
125
+ name: string;
126
+ version: string;
127
+ ssrPublicPath: string;
128
+ ssrRemoteEntry: string;
129
+ globalName: string;
130
+ };
131
+
132
+ export declare function setDataFetchItemLoadedStatus(id: string): void;
133
+
134
+ export declare function setSSREnv({ fetchServerQuery, }: {
135
+ fetchServerQuery?: Record<string, unknown>;
136
+ }): void;
137
+
138
+ export declare const wrapDataFetchId: (id?: string) => string;
139
+
140
+ export { }
141
+
142
+
143
+ declare module '@module-federation/runtime-core' {
144
+ interface ModuleFederation {
145
+ createLazyComponent<T, E extends keyof T>(options: Omit<CreateLazyComponentOptions<T, E>, 'instance'>): ReturnType<typeof createLazyComponent<T, E>>;
146
+ prefetch(options: Omit<PrefetchOptions, 'instance'>): ReturnType<typeof prefetch>;
147
+ collectSSRAssets(options: Omit<Parameters<typeof collectSSRAssets>[0], 'instance'>): ReturnType<typeof collectSSRAssets>;
148
+ }
149
+ }
@@ -0,0 +1,24 @@
1
+ import "./index.esm-BCeUd-x9.mjs";
2
+ import { G, H, f, J, I, u, k, n, g, m, B, y, i, q, j, t, a, z, s, w } from "./utils-C4oPJV34.mjs";
3
+ export {
4
+ G as callAllDowngrade,
5
+ H as callDowngrade,
6
+ f as fetchData,
7
+ J as flushDataFetch,
8
+ I as getDataFetchCache,
9
+ u as getDataFetchIdWithErrorMsgs,
10
+ k as getDataFetchInfo,
11
+ n as getDataFetchItem,
12
+ g as getDataFetchMap,
13
+ m as getDataFetchMapKey,
14
+ B as getDowngradeTag,
15
+ y as getLoadedRemoteInfos,
16
+ i as initDataFetchMap,
17
+ q as isCSROnly,
18
+ j as isDataLoaderExpose,
19
+ t as isServerEnv,
20
+ a as loadDataFetchModule,
21
+ z as setDataFetchItemLoadedStatus,
22
+ s as setSSREnv,
23
+ w as wrapDataFetchId
24
+ };
package/dist/plugin.d.ts CHANGED
@@ -1,13 +1,22 @@
1
- import { FederationHost } from '@module-federation/runtime';
2
- import { FederationRuntimePlugin } from '@module-federation/runtime';
1
+ import { ModuleFederation } from '@module-federation/runtime';
2
+ import { ModuleFederationRuntimePlugin } from '@module-federation/runtime';
3
3
 
4
- declare function BridgeReactPlugin(): FederationRuntimePlugin;
4
+ declare function BridgeReactPlugin(): ModuleFederationRuntimePlugin;
5
5
  export default BridgeReactPlugin;
6
6
 
7
7
  export declare const federationRuntime: FederationRuntimeType;
8
8
 
9
9
  export declare type FederationRuntimeType = {
10
- instance: FederationHost | null;
10
+ instance: ModuleFederation | null;
11
11
  };
12
12
 
13
13
  export { }
14
+
15
+
16
+ declare module '@module-federation/runtime-core' {
17
+ interface ModuleFederation {
18
+ createLazyComponent<T, E extends keyof T>(options: Omit<CreateLazyComponentOptions<T, E>, 'instance'>): ReturnType<typeof createLazyComponent<T, E>>;
19
+ prefetch(options: Omit<PrefetchOptions, 'instance'>): ReturnType<typeof prefetch>;
20
+ collectSSRAssets(options: Omit<Parameters<typeof collectSSRAssets>[0], 'instance'>): ReturnType<typeof collectSSRAssets>;
21
+ }
22
+ }