@module-federation/bridge-react 2.6.0 → 2.8.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.
Files changed (90) hide show
  1. package/dist/base.cjs.js +4 -4
  2. package/dist/base.d.ts +8 -311
  3. package/dist/base.es.js +5 -5
  4. package/dist/{bridge-base-CIOXqUYV.mjs → bridge-base-BaKy6CY_.mjs} +25 -92
  5. package/dist/{bridge-base-HLp3d7aF.js → bridge-base-Ch33UJuN.js} +25 -91
  6. package/dist/{createHelpers-DNBacpxb.js → createHelpers-19BP0xtB.js} +2 -3
  7. package/dist/{createHelpers-BY5Uj9_Z.mjs → createHelpers-BSHeKyd-.mjs} +2 -3
  8. package/dist/data-fetch-server-middleware.cjs.js +1 -1
  9. package/dist/data-fetch-server-middleware.d.ts +1 -15
  10. package/dist/data-fetch-server-middleware.es.js +1 -1
  11. package/dist/data-fetch-utils.cjs.js +2 -2
  12. package/dist/data-fetch-utils.d.ts +1 -81
  13. package/dist/data-fetch-utils.es.js +4 -4
  14. package/dist/data-fetch.cjs.js +3 -3
  15. package/dist/data-fetch.d.ts +4 -140
  16. package/dist/data-fetch.es.js +3 -3
  17. package/dist/error-boundary.d.ts +17 -0
  18. package/dist/error-boundary.spec.d.ts +1 -0
  19. package/dist/index.cjs.js +4 -4
  20. package/dist/index.d.ts +12 -299
  21. package/dist/index.es.js +5 -5
  22. package/dist/lazy/AwaitDataFetch.d.ts +24 -0
  23. package/dist/lazy/constant.d.ts +26 -0
  24. package/dist/lazy/createLazyComponent.d.ts +28 -0
  25. package/dist/lazy/data-fetch/cache.d.ts +34 -0
  26. package/dist/lazy/data-fetch/cache.spec.d.ts +1 -0
  27. package/dist/lazy/data-fetch/call-data-fetch.d.ts +1 -0
  28. package/dist/lazy/data-fetch/data-fetch-server-middleware.d.ts +3 -0
  29. package/dist/lazy/data-fetch/index.d.ts +6 -0
  30. package/dist/lazy/data-fetch/inject-data-fetch.d.ts +4 -0
  31. package/dist/lazy/data-fetch/prefetch.d.ts +9 -0
  32. package/dist/lazy/data-fetch/runtime-plugin.d.ts +3 -0
  33. package/dist/lazy/index.d.ts +9 -0
  34. package/dist/lazy/logger.d.ts +2 -0
  35. package/dist/lazy/types.d.ts +60 -0
  36. package/dist/lazy/utils.d.ts +48 -0
  37. package/dist/lazy/wrapNoSSR.d.ts +9 -0
  38. package/dist/{lazy-load-component-plugin-BYI941I2.mjs → lazy-load-component-plugin-DEu-DfZt.mjs} +2 -2
  39. package/dist/{lazy-load-component-plugin-DG4e3Tib.js → lazy-load-component-plugin-FKp6nQa-.js} +2 -2
  40. package/dist/lazy-load-component-plugin.cjs.js +2 -2
  41. package/dist/lazy-load-component-plugin.d.ts +2 -16
  42. package/dist/lazy-load-component-plugin.es.js +2 -2
  43. package/dist/lazy-utils.cjs.js +1 -1
  44. package/dist/lazy-utils.d.ts +1 -149
  45. package/dist/lazy-utils.es.js +2 -2
  46. package/dist/plugin.d.ts +2 -22
  47. package/dist/plugins/lazy-load-component-plugin.d.ts +12 -0
  48. package/dist/plugins/lazy-load-component-plugin.spec.d.ts +1 -0
  49. package/dist/{prefetch-DzO9_QQ-.mjs → prefetch-CTZuFBqh.mjs} +387 -16
  50. package/dist/{prefetch-CG2l-06N.js → prefetch-D66kL1aM.js} +387 -16
  51. package/dist/provider/context.d.ts +3 -0
  52. package/dist/provider/plugin.d.ts +7 -0
  53. package/dist/provider/versions/bridge-base.d.ts +5 -0
  54. package/dist/provider/versions/legacy.d.ts +26 -0
  55. package/dist/provider/versions/v18.d.ts +19 -0
  56. package/dist/provider/versions/v19.d.ts +21 -0
  57. package/dist/remote/RemoteAppWrapper.d.ts +7 -0
  58. package/dist/remote/base-component/component.d.ts +2 -0
  59. package/dist/remote/base-component/create.d.ts +9 -0
  60. package/dist/remote/base-component/index.d.ts +5 -0
  61. package/dist/remote/createHelpers.d.ts +17 -0
  62. package/dist/remote/router-component/component.d.ts +8 -0
  63. package/dist/remote/router-component/create.d.ts +9 -0
  64. package/dist/remote/router-component/index.d.ts +5 -0
  65. package/dist/router/default.d.ts +7 -0
  66. package/dist/router/v5.d.ts +4 -0
  67. package/dist/router/v6.d.ts +7 -0
  68. package/dist/router/v7.d.ts +6 -0
  69. package/dist/router-v5.d.ts +1 -17
  70. package/dist/router-v6.d.ts +1 -20
  71. package/dist/router-v7.d.ts +1 -19
  72. package/dist/router.d.ts +1 -20
  73. package/dist/shared/size-limited-cache.d.ts +29 -0
  74. package/dist/shared/size-limited-cache.spec.d.ts +1 -0
  75. package/dist/size-limited-cache.cjs.js +82 -0
  76. package/dist/size-limited-cache.d.ts +1 -0
  77. package/dist/size-limited-cache.es.js +82 -0
  78. package/dist/types.d.ts +137 -0
  79. package/dist/utils/index.d.ts +4 -0
  80. package/dist/utils-5dGErM3C.js +588 -0
  81. package/dist/utils-BBP3hEeV.mjs +589 -0
  82. package/dist/v18.cjs.js +1 -1
  83. package/dist/v18.d.ts +3 -114
  84. package/dist/v18.es.js +1 -1
  85. package/dist/v19.cjs.js +1 -1
  86. package/dist/v19.d.ts +3 -115
  87. package/dist/v19.es.js +1 -1
  88. package/package.json +20 -13
  89. package/dist/utils-CFTy4LVE.js +0 -2029
  90. package/dist/utils-DGS4pYp8.mjs +0 -2030
@@ -0,0 +1,6 @@
1
+ import React from 'react';
2
+ declare function WraperRouter(props: Record<string, unknown>): React.JSX.Element;
3
+ declare function WraperRouterProvider(props: Record<string, unknown>): React.JSX.Element;
4
+ export * from 'react-router';
5
+ export { WraperRouter as BrowserRouter };
6
+ export { WraperRouterProvider as RouterProvider };
@@ -1,17 +1 @@
1
- import { default as default_2 } from 'react';
2
-
3
- export declare function BrowserRouter(props: Record<string, unknown>): default_2.JSX.Element;
4
-
5
-
6
- export * from "react-router-dom/";
7
-
8
- export { }
9
-
10
-
11
- declare module '@module-federation/runtime-core' {
12
- interface ModuleFederation {
13
- createLazyComponent<T, E extends keyof T>(options: Omit<CreateLazyComponentOptions<T, E>, 'instance'>): ReturnType<typeof createLazyComponent<T, E>>;
14
- prefetch(options: Omit<PrefetchOptions, 'instance'>): ReturnType<typeof prefetch>;
15
- collectSSRAssets(options: Omit<Parameters<typeof collectSSRAssets>[0], 'instance'>): ReturnType<typeof collectSSRAssets>;
16
- }
17
- }
1
+ export * from './router/v5';
@@ -1,20 +1 @@
1
- import { default as default_2 } from 'react';
2
- import * as ReactRouterDom from 'react-router-dom/dist/index.js';
3
-
4
- export declare function BrowserRouter(props: Parameters<typeof ReactRouterDom.BrowserRouter>[0] | Parameters<typeof ReactRouterDom.MemoryRouter>[0]): default_2.JSX.Element;
5
-
6
- export declare function RouterProvider(props: Parameters<typeof ReactRouterDom.RouterProvider>[0]): default_2.JSX.Element;
7
-
8
-
9
- export * from "react-router-dom/";
10
-
11
- export { }
12
-
13
-
14
- declare module '@module-federation/runtime-core' {
15
- interface ModuleFederation {
16
- createLazyComponent<T, E extends keyof T>(options: Omit<CreateLazyComponentOptions<T, E>, 'instance'>): ReturnType<typeof createLazyComponent<T, E>>;
17
- prefetch(options: Omit<PrefetchOptions, 'instance'>): ReturnType<typeof prefetch>;
18
- collectSSRAssets(options: Omit<Parameters<typeof collectSSRAssets>[0], 'instance'>): ReturnType<typeof collectSSRAssets>;
19
- }
20
- }
1
+ export * from './router/v6';
@@ -1,19 +1 @@
1
- import { default as default_2 } from 'react';
2
-
3
- export declare function BrowserRouter(props: Record<string, unknown>): default_2.JSX.Element;
4
-
5
- export declare function RouterProvider(props: Record<string, unknown>): default_2.JSX.Element;
6
-
7
-
8
- export * from "react-router";
9
-
10
- export { }
11
-
12
-
13
- declare module '@module-federation/runtime-core' {
14
- interface ModuleFederation {
15
- createLazyComponent<T, E extends keyof T>(options: Omit<CreateLazyComponentOptions<T, E>, 'instance'>): ReturnType<typeof createLazyComponent<T, E>>;
16
- prefetch(options: Omit<PrefetchOptions, 'instance'>): ReturnType<typeof prefetch>;
17
- collectSSRAssets(options: Omit<Parameters<typeof collectSSRAssets>[0], 'instance'>): ReturnType<typeof collectSSRAssets>;
18
- }
19
- }
1
+ export * from './router/v7';
package/dist/router.d.ts CHANGED
@@ -1,20 +1 @@
1
- import { default as default_2 } from 'react';
2
- import * as ReactRouterDom from 'react-router-dom/';
3
-
4
- export declare function BrowserRouter(props: Parameters<typeof ReactRouterDom.BrowserRouter>[0] | Parameters<typeof ReactRouterDom.MemoryRouter>[0]): default_2.JSX.Element;
5
-
6
- export declare function RouterProvider(props: Parameters<typeof ReactRouterDom.RouterProvider>[0]): default_2.JSX.Element;
7
-
8
-
9
- export * from "react-router-dom/";
10
-
11
- export { }
12
-
13
-
14
- declare module '@module-federation/runtime-core' {
15
- interface ModuleFederation {
16
- createLazyComponent<T, E extends keyof T>(options: Omit<CreateLazyComponentOptions<T, E>, 'instance'>): ReturnType<typeof createLazyComponent<T, E>>;
17
- prefetch(options: Omit<PrefetchOptions, 'instance'>): ReturnType<typeof prefetch>;
18
- collectSSRAssets(options: Omit<Parameters<typeof collectSSRAssets>[0], 'instance'>): ReturnType<typeof collectSSRAssets>;
19
- }
20
- }
1
+ export * from './router/default';
@@ -0,0 +1,29 @@
1
+ export interface SizeLimitedCacheOptions<K, V> {
2
+ maxSize: number;
3
+ sizeCalculation?: (value: V, key: K) => number;
4
+ }
5
+ export interface SizeLimitedCacheSetOptions {
6
+ size?: number;
7
+ }
8
+ /**
9
+ * A small, size-aware least-recently-used cache.
10
+ *
11
+ * This intentionally implements only the operations used by federation
12
+ * packages. Reading or checking an entry refreshes its recency.
13
+ */
14
+ export declare class SizeLimitedCache<K, V> {
15
+ readonly maxSize: number;
16
+ private readonly entries;
17
+ private readonly sizeCalculation?;
18
+ private currentSize;
19
+ constructor(options: SizeLimitedCacheOptions<K, V>);
20
+ get size(): number;
21
+ get calculatedSize(): number;
22
+ get(key: K): V | undefined;
23
+ has(key: K): boolean;
24
+ set(key: K, value: V, options?: SizeLimitedCacheSetOptions): this;
25
+ delete(key: K): boolean;
26
+ clear(): void;
27
+ private refresh;
28
+ private evictUntilWithinLimit;
29
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,82 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
4
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
5
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
6
+ class SizeLimitedCache {
7
+ constructor(options) {
8
+ __publicField(this, "maxSize");
9
+ __publicField(this, "entries", /* @__PURE__ */ new Map());
10
+ __publicField(this, "sizeCalculation");
11
+ __publicField(this, "currentSize", 0);
12
+ if (!Number.isInteger(options.maxSize) || options.maxSize <= 0) {
13
+ throw new TypeError("maxSize must be a positive integer");
14
+ }
15
+ this.maxSize = options.maxSize;
16
+ this.sizeCalculation = options.sizeCalculation;
17
+ }
18
+ get size() {
19
+ return this.entries.size;
20
+ }
21
+ get calculatedSize() {
22
+ return this.currentSize;
23
+ }
24
+ get(key) {
25
+ const entry = this.entries.get(key);
26
+ if (!entry) {
27
+ return void 0;
28
+ }
29
+ this.refresh(key, entry);
30
+ return entry.value;
31
+ }
32
+ has(key) {
33
+ const entry = this.entries.get(key);
34
+ if (!entry) {
35
+ return false;
36
+ }
37
+ this.refresh(key, entry);
38
+ return true;
39
+ }
40
+ set(key, value, options = {}) {
41
+ var _a;
42
+ const entrySize = options.size ?? ((_a = this.sizeCalculation) == null ? void 0 : _a.call(this, value, key)) ?? 1;
43
+ if (!Number.isInteger(entrySize) || entrySize <= 0) {
44
+ throw new TypeError("entry size must be a positive integer");
45
+ }
46
+ this.delete(key);
47
+ if (entrySize > this.maxSize) {
48
+ return this;
49
+ }
50
+ this.entries.set(key, { value, size: entrySize });
51
+ this.currentSize += entrySize;
52
+ this.evictUntilWithinLimit();
53
+ return this;
54
+ }
55
+ delete(key) {
56
+ const entry = this.entries.get(key);
57
+ if (!entry) {
58
+ return false;
59
+ }
60
+ this.currentSize -= entry.size;
61
+ return this.entries.delete(key);
62
+ }
63
+ clear() {
64
+ this.entries.clear();
65
+ this.currentSize = 0;
66
+ }
67
+ refresh(key, entry) {
68
+ this.entries.delete(key);
69
+ this.entries.set(key, entry);
70
+ }
71
+ evictUntilWithinLimit() {
72
+ while (this.currentSize > this.maxSize) {
73
+ const oldest = this.entries.keys().next();
74
+ if (oldest.done) {
75
+ this.currentSize = 0;
76
+ return;
77
+ }
78
+ this.delete(oldest.value);
79
+ }
80
+ }
81
+ }
82
+ exports.SizeLimitedCache = SizeLimitedCache;
@@ -0,0 +1 @@
1
+ export * from './shared/size-limited-cache';
@@ -0,0 +1,82 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
4
+ class SizeLimitedCache {
5
+ constructor(options) {
6
+ __publicField(this, "maxSize");
7
+ __publicField(this, "entries", /* @__PURE__ */ new Map());
8
+ __publicField(this, "sizeCalculation");
9
+ __publicField(this, "currentSize", 0);
10
+ if (!Number.isInteger(options.maxSize) || options.maxSize <= 0) {
11
+ throw new TypeError("maxSize must be a positive integer");
12
+ }
13
+ this.maxSize = options.maxSize;
14
+ this.sizeCalculation = options.sizeCalculation;
15
+ }
16
+ get size() {
17
+ return this.entries.size;
18
+ }
19
+ get calculatedSize() {
20
+ return this.currentSize;
21
+ }
22
+ get(key) {
23
+ const entry = this.entries.get(key);
24
+ if (!entry) {
25
+ return void 0;
26
+ }
27
+ this.refresh(key, entry);
28
+ return entry.value;
29
+ }
30
+ has(key) {
31
+ const entry = this.entries.get(key);
32
+ if (!entry) {
33
+ return false;
34
+ }
35
+ this.refresh(key, entry);
36
+ return true;
37
+ }
38
+ set(key, value, options = {}) {
39
+ var _a;
40
+ const entrySize = options.size ?? ((_a = this.sizeCalculation) == null ? void 0 : _a.call(this, value, key)) ?? 1;
41
+ if (!Number.isInteger(entrySize) || entrySize <= 0) {
42
+ throw new TypeError("entry size must be a positive integer");
43
+ }
44
+ this.delete(key);
45
+ if (entrySize > this.maxSize) {
46
+ return this;
47
+ }
48
+ this.entries.set(key, { value, size: entrySize });
49
+ this.currentSize += entrySize;
50
+ this.evictUntilWithinLimit();
51
+ return this;
52
+ }
53
+ delete(key) {
54
+ const entry = this.entries.get(key);
55
+ if (!entry) {
56
+ return false;
57
+ }
58
+ this.currentSize -= entry.size;
59
+ return this.entries.delete(key);
60
+ }
61
+ clear() {
62
+ this.entries.clear();
63
+ this.currentSize = 0;
64
+ }
65
+ refresh(key, entry) {
66
+ this.entries.delete(key);
67
+ this.entries.set(key, entry);
68
+ }
69
+ evictUntilWithinLimit() {
70
+ while (this.currentSize > this.maxSize) {
71
+ const oldest = this.entries.keys().next();
72
+ if (oldest.done) {
73
+ this.currentSize = 0;
74
+ return;
75
+ }
76
+ this.delete(oldest.value);
77
+ }
78
+ }
79
+ }
80
+ export {
81
+ SizeLimitedCache
82
+ };
@@ -0,0 +1,137 @@
1
+ import * as React from 'react';
2
+ export type ErrorFallbackProps = {
3
+ error: unknown;
4
+ resetErrorBoundary: (...args: unknown[]) => void;
5
+ };
6
+ /**
7
+ * Options for creating a React root
8
+ */
9
+ export interface CreateRootOptions {
10
+ identifierPrefix?: string;
11
+ onRecoverableError?: (error: unknown) => void;
12
+ transitionCallbacks?: unknown;
13
+ }
14
+ /**
15
+ * Interface for a React root object
16
+ */
17
+ export interface Root {
18
+ render(children: React.ReactNode): void;
19
+ unmount(): void;
20
+ }
21
+ /**
22
+ * Type for a root element, which can be either an HTMLElement or a React root
23
+ */
24
+ export type RootType = HTMLElement | Root;
25
+ /**
26
+ * Parameters for the render function
27
+ */
28
+ export interface RenderParams {
29
+ moduleName?: string;
30
+ basename?: string;
31
+ memoryRoute?: {
32
+ entryPath: string;
33
+ initialState?: Record<string, unknown>;
34
+ };
35
+ dom: HTMLElement;
36
+ /**
37
+ * Options to pass to createRoot for React 18 and 19
38
+ * @example
39
+ * {
40
+ * identifierPrefix: 'app-',
41
+ * onRecoverableError: (err) => console.error(err)
42
+ * }
43
+ */
44
+ rootOptions?: CreateRootOptions;
45
+ [key: string]: unknown;
46
+ }
47
+ /**
48
+ * Parameters for the destroy function
49
+ */
50
+ export interface DestroyParams {
51
+ moduleName: string;
52
+ dom: HTMLElement;
53
+ }
54
+ /**
55
+ * Parameters for the provider function
56
+ */
57
+ export interface ProviderParams {
58
+ moduleName?: string;
59
+ basename?: string;
60
+ memoryRoute?: {
61
+ entryPath: string;
62
+ initialState?: Record<string, unknown>;
63
+ };
64
+ style?: React.CSSProperties;
65
+ className?: string;
66
+ }
67
+ /**
68
+ * Parameters for the render function, extending ProviderParams
69
+ */
70
+ export interface RenderFnParams extends ProviderParams {
71
+ dom: HTMLElement;
72
+ fallback?: React.ComponentType<{
73
+ error: Error;
74
+ }>;
75
+ [key: string]: unknown;
76
+ }
77
+ /**
78
+ * Parameters for the provider function
79
+ */
80
+ export interface ProviderFnParams<T> {
81
+ rootComponent: React.ComponentType<T>;
82
+ render?: (App: React.ReactElement, id?: HTMLElement | string) => RootType | Promise<RootType>;
83
+ createRoot?: (container: Element | DocumentFragment, options?: CreateRootOptions) => Root;
84
+ /**
85
+ * Default options to pass to createRoot for React 18 and 19
86
+ * These options will be used when creating a root unless overridden by rootOptions in render params
87
+ * @example
88
+ * {
89
+ * identifierPrefix: 'app-',
90
+ * onRecoverableError: (err) => console.error(err)
91
+ * }
92
+ */
93
+ defaultRootOptions?: CreateRootOptions;
94
+ }
95
+ /**
96
+ * Parameters for the remote component
97
+ */
98
+ export interface RemoteComponentProps<T = Record<string, unknown>> {
99
+ props?: T;
100
+ fallback?: React.ComponentType<{
101
+ error: Error;
102
+ }>;
103
+ loading?: React.ReactNode;
104
+ [key: string]: unknown;
105
+ }
106
+ /**
107
+ * Parameters for the remote component loader
108
+ */
109
+ export interface RemoteComponentParams<T = Record<string, unknown>, E extends keyof T = keyof T> {
110
+ loader: () => Promise<T>;
111
+ loading: React.ReactNode;
112
+ fallback: React.ComponentType<{
113
+ error: Error;
114
+ }>;
115
+ export?: E;
116
+ props?: T;
117
+ }
118
+ /**
119
+ * Interface for a remote module provider
120
+ */
121
+ export interface RemoteModule {
122
+ provider: () => {
123
+ render: (info: RenderFnParams) => void;
124
+ destroy: (info: {
125
+ dom: any;
126
+ }) => void;
127
+ };
128
+ }
129
+ /**
130
+ * Parameters for a remote app component
131
+ */
132
+ export interface RemoteAppParams extends ProviderParams {
133
+ moduleName: string;
134
+ providerInfo: NonNullable<RemoteModule['provider']>;
135
+ exportName: string | number | symbol;
136
+ fallback: React.ComponentType<ErrorFallbackProps>;
137
+ }
@@ -0,0 +1,4 @@
1
+ export declare const LoggerInstance: import("@module-federation/sdk").Logger;
2
+ export declare function pathJoin(...args: string[]): string;
3
+ export declare const getModuleName: (id: string) => string;
4
+ export declare const getRootDomDefaultClassName: (moduleName: string) => string;