@module-federation/bridge-react 2.3.2 → 2.4.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/base.cjs.js +2 -2
- package/dist/base.es.js +2 -2
- package/dist/data-fetch-utils.cjs.js +1 -1
- package/dist/data-fetch-utils.es.js +2 -2
- package/dist/index.cjs.js +2 -2
- package/dist/index.es.js +2 -2
- package/dist/{lazy-load-component-plugin-CqxENGBE.mjs → lazy-load-component-plugin-Bf_HsMyF.mjs} +1 -1
- package/dist/{lazy-load-component-plugin-ZC6dhtcT.js → lazy-load-component-plugin-DZDwZ0Kz.js} +1 -1
- package/dist/lazy-load-component-plugin.cjs.js +2 -2
- package/dist/lazy-load-component-plugin.es.js +2 -2
- package/dist/{prefetch-CFKA0dZg.mjs → prefetch-ByDYONsx.mjs} +14 -7
- package/dist/{prefetch-8e8pqiSo.js → prefetch-DYFX9hl9.js} +14 -7
- package/package.json +9 -5
- package/.turbo/turbo-build.log +0 -85
- package/CHANGELOG.md +0 -833
- package/__tests__/bridge.spec.tsx +0 -160
- package/__tests__/createLazyComponent.spec.tsx +0 -209
- package/__tests__/prefetch.spec.ts +0 -156
- package/__tests__/router.spec.tsx +0 -82
- package/__tests__/setupTests.ts +0 -8
- package/__tests__/util.ts +0 -36
- package/jest.config.ts +0 -21
- package/src/base.ts +0 -50
- package/src/index.ts +0 -50
- package/src/lazy/AwaitDataFetch.tsx +0 -217
- package/src/lazy/constant.ts +0 -30
- package/src/lazy/createLazyComponent.tsx +0 -411
- package/src/lazy/data-fetch/cache.ts +0 -291
- package/src/lazy/data-fetch/call-data-fetch.ts +0 -13
- package/src/lazy/data-fetch/data-fetch-server-middleware.ts +0 -196
- package/src/lazy/data-fetch/index.ts +0 -16
- package/src/lazy/data-fetch/inject-data-fetch.ts +0 -109
- package/src/lazy/data-fetch/prefetch.ts +0 -112
- package/src/lazy/data-fetch/runtime-plugin.ts +0 -115
- package/src/lazy/index.ts +0 -35
- package/src/lazy/logger.ts +0 -6
- package/src/lazy/types.ts +0 -75
- package/src/lazy/utils.ts +0 -375
- package/src/lazy/wrapNoSSR.tsx +0 -10
- package/src/modern-app-env.d.ts +0 -2
- package/src/plugins/lazy-load-component-plugin.spec.ts +0 -21
- package/src/plugins/lazy-load-component-plugin.ts +0 -57
- package/src/provider/context.tsx +0 -4
- package/src/provider/plugin.ts +0 -22
- package/src/provider/versions/bridge-base.tsx +0 -153
- package/src/provider/versions/legacy.ts +0 -87
- package/src/provider/versions/v18.ts +0 -47
- package/src/provider/versions/v19.ts +0 -48
- package/src/remote/RemoteAppWrapper.tsx +0 -108
- package/src/remote/base-component/component.tsx +0 -2
- package/src/remote/base-component/create.tsx +0 -23
- package/src/remote/base-component/index.tsx +0 -10
- package/src/remote/createHelpers.tsx +0 -132
- package/src/remote/router-component/component.tsx +0 -104
- package/src/remote/router-component/create.tsx +0 -23
- package/src/remote/router-component/index.tsx +0 -10
- package/src/router/default.tsx +0 -73
- package/src/router/v5.tsx +0 -43
- package/src/router/v6.tsx +0 -74
- package/src/router/v7.tsx +0 -75
- package/src/types.ts +0 -147
- package/src/utils/index.ts +0 -44
- package/src/v18.ts +0 -9
- package/src/v19.ts +0 -9
- package/tsconfig.json +0 -42
- package/tsconfig.node.json +0 -11
- package/tsconfig.spec.json +0 -26
- package/vite.config.ts +0 -112
- package/vitest.config.ts +0 -27
package/src/router/v5.tsx
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import React, { useContext } from 'react';
|
|
2
|
-
// The upper alias react-router-dom$ into this file avoids the loop
|
|
3
|
-
// @ts-ignore
|
|
4
|
-
import * as ReactRouterDom from 'react-router-dom/index.js';
|
|
5
|
-
import { RouterContext } from '../provider/context';
|
|
6
|
-
import { LoggerInstance } from '../utils';
|
|
7
|
-
|
|
8
|
-
function WraperRouter(props: Record<string, unknown>) {
|
|
9
|
-
const { basename, ...propsRes } = props;
|
|
10
|
-
const routerContextProps = useContext(RouterContext) || {};
|
|
11
|
-
const MemoryRouter =
|
|
12
|
-
ReactRouterDom.MemoryRouter as unknown as React.ComponentType<any>;
|
|
13
|
-
const BrowserRouter =
|
|
14
|
-
ReactRouterDom.BrowserRouter as unknown as React.ComponentType<any>;
|
|
15
|
-
|
|
16
|
-
LoggerInstance.debug(`WraperRouter info >>>`, {
|
|
17
|
-
...routerContextProps,
|
|
18
|
-
routerContextProps,
|
|
19
|
-
WraperRouterProps: props,
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
if (routerContextProps?.memoryRoute) {
|
|
23
|
-
return (
|
|
24
|
-
<MemoryRouter
|
|
25
|
-
{...props}
|
|
26
|
-
initialEntries={[routerContextProps?.memoryRoute.entryPath]}
|
|
27
|
-
/>
|
|
28
|
-
);
|
|
29
|
-
}
|
|
30
|
-
return (
|
|
31
|
-
<BrowserRouter
|
|
32
|
-
{...propsRes}
|
|
33
|
-
basename={routerContextProps?.basename || basename}
|
|
34
|
-
/>
|
|
35
|
-
);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
// @ts-ignore
|
|
39
|
-
// because export directly from react-router-dom/index.js will cause build falied.
|
|
40
|
-
// it will be replace by react-router-dom/index.js in building phase
|
|
41
|
-
export * from 'react-router-dom/';
|
|
42
|
-
|
|
43
|
-
export { WraperRouter as BrowserRouter };
|
package/src/router/v6.tsx
DELETED
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
import React, { useContext } from 'react';
|
|
2
|
-
// The upper alias react-router-dom$ into this file avoids the loop
|
|
3
|
-
import * as ReactRouterDom from 'react-router-dom/dist/index.js';
|
|
4
|
-
import { RouterContext } from '../provider/context';
|
|
5
|
-
import { LoggerInstance } from '../utils';
|
|
6
|
-
|
|
7
|
-
function WraperRouter(
|
|
8
|
-
props:
|
|
9
|
-
| Parameters<typeof ReactRouterDom.BrowserRouter>[0]
|
|
10
|
-
| Parameters<typeof ReactRouterDom.MemoryRouter>[0],
|
|
11
|
-
) {
|
|
12
|
-
const { basename, ...propsRes } = props;
|
|
13
|
-
const routerContextProps = useContext(RouterContext) || {};
|
|
14
|
-
|
|
15
|
-
LoggerInstance.debug(`WraperRouter info >>>`, {
|
|
16
|
-
...routerContextProps,
|
|
17
|
-
routerContextProps,
|
|
18
|
-
WraperRouterProps: props,
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
if (routerContextProps?.memoryRoute) {
|
|
22
|
-
return (
|
|
23
|
-
<ReactRouterDom.MemoryRouter
|
|
24
|
-
{...props}
|
|
25
|
-
initialEntries={[routerContextProps?.memoryRoute.entryPath]}
|
|
26
|
-
/>
|
|
27
|
-
);
|
|
28
|
-
}
|
|
29
|
-
return (
|
|
30
|
-
<ReactRouterDom.BrowserRouter
|
|
31
|
-
{...propsRes}
|
|
32
|
-
basename={routerContextProps?.basename || basename}
|
|
33
|
-
/>
|
|
34
|
-
);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
function WraperRouterProvider(
|
|
38
|
-
props: Parameters<typeof ReactRouterDom.RouterProvider>[0],
|
|
39
|
-
) {
|
|
40
|
-
const { router, ...propsRes } = props;
|
|
41
|
-
const routerContextProps = useContext(RouterContext) || {};
|
|
42
|
-
const routers = router.routes;
|
|
43
|
-
LoggerInstance.debug(`WraperRouterProvider info >>>`, {
|
|
44
|
-
...routerContextProps,
|
|
45
|
-
routerContextProps,
|
|
46
|
-
WraperRouterProviderProps: props,
|
|
47
|
-
router,
|
|
48
|
-
});
|
|
49
|
-
const RouterProvider = (ReactRouterDom as any)['Router' + 'Provider'];
|
|
50
|
-
const createMemoryRouter = (ReactRouterDom as any)['create' + 'MemoryRouter'];
|
|
51
|
-
const createBrowserRouter = (ReactRouterDom as any)[
|
|
52
|
-
'create' + 'BrowserRouter'
|
|
53
|
-
];
|
|
54
|
-
|
|
55
|
-
if (routerContextProps.memoryRoute) {
|
|
56
|
-
const MemeoryRouterInstance = createMemoryRouter(routers, {
|
|
57
|
-
initialEntries: [routerContextProps?.memoryRoute.entryPath],
|
|
58
|
-
});
|
|
59
|
-
return <RouterProvider router={MemeoryRouterInstance} />;
|
|
60
|
-
} else {
|
|
61
|
-
const BrowserRouterInstance = createBrowserRouter(routers, {
|
|
62
|
-
// In host app, the routerContextProps is {}, so we should use router.basename as fallback
|
|
63
|
-
basename: routerContextProps.basename || router.basename,
|
|
64
|
-
future: router.future,
|
|
65
|
-
window: router.window,
|
|
66
|
-
});
|
|
67
|
-
return <RouterProvider {...propsRes} router={BrowserRouterInstance} />;
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
// export * from 'react-router-dom/dist/index.js';
|
|
72
|
-
export * from 'react-router-dom/';
|
|
73
|
-
export { WraperRouter as BrowserRouter };
|
|
74
|
-
export { WraperRouterProvider as RouterProvider };
|
package/src/router/v7.tsx
DELETED
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import React, { useContext } from 'react';
|
|
2
|
-
// The upper alias react-router$ into this file avoids the loop
|
|
3
|
-
// React Router v7 uses different dist structure, we'll import from the main entry
|
|
4
|
-
import * as ReactRouterDom from 'react-router';
|
|
5
|
-
import { RouterContext } from '../provider/context';
|
|
6
|
-
import { LoggerInstance } from '../utils';
|
|
7
|
-
|
|
8
|
-
function WraperRouter(props: Record<string, unknown>) {
|
|
9
|
-
const { basename, ...propsRes } = props;
|
|
10
|
-
const routerContextProps = useContext(RouterContext) || {};
|
|
11
|
-
const MemoryRouter =
|
|
12
|
-
ReactRouterDom.MemoryRouter as unknown as React.ComponentType<any>;
|
|
13
|
-
const BrowserRouter =
|
|
14
|
-
ReactRouterDom.BrowserRouter as unknown as React.ComponentType<any>;
|
|
15
|
-
|
|
16
|
-
LoggerInstance.debug(`WraperRouter info >>>`, {
|
|
17
|
-
...routerContextProps,
|
|
18
|
-
routerContextProps,
|
|
19
|
-
WraperRouterProps: props,
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
if (routerContextProps?.memoryRoute) {
|
|
23
|
-
return (
|
|
24
|
-
<MemoryRouter
|
|
25
|
-
{...props}
|
|
26
|
-
initialEntries={[routerContextProps?.memoryRoute.entryPath]}
|
|
27
|
-
/>
|
|
28
|
-
);
|
|
29
|
-
}
|
|
30
|
-
return (
|
|
31
|
-
<BrowserRouter
|
|
32
|
-
{...propsRes}
|
|
33
|
-
basename={routerContextProps?.basename || basename}
|
|
34
|
-
/>
|
|
35
|
-
);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
function WraperRouterProvider(props: Record<string, unknown>) {
|
|
39
|
-
const { router, ...propsRes } = props as { router: any };
|
|
40
|
-
const routerContextProps = useContext(RouterContext) || {};
|
|
41
|
-
const routers = router.routes;
|
|
42
|
-
LoggerInstance.debug(`WraperRouterProvider info >>>`, {
|
|
43
|
-
...routerContextProps,
|
|
44
|
-
routerContextProps,
|
|
45
|
-
WraperRouterProviderProps: props,
|
|
46
|
-
router,
|
|
47
|
-
});
|
|
48
|
-
const RouterProvider = (ReactRouterDom as any)[
|
|
49
|
-
'Router' + 'Provider'
|
|
50
|
-
] as React.ComponentType<any>;
|
|
51
|
-
const createMemoryRouter = (ReactRouterDom as any)['create' + 'MemoryRouter'];
|
|
52
|
-
const createBrowserRouter = (ReactRouterDom as any)[
|
|
53
|
-
'create' + 'BrowserRouter'
|
|
54
|
-
];
|
|
55
|
-
|
|
56
|
-
if (routerContextProps.memoryRoute) {
|
|
57
|
-
const MemeoryRouterInstance = createMemoryRouter(routers, {
|
|
58
|
-
initialEntries: [routerContextProps?.memoryRoute.entryPath],
|
|
59
|
-
});
|
|
60
|
-
return <RouterProvider router={MemeoryRouterInstance} />;
|
|
61
|
-
} else {
|
|
62
|
-
const BrowserRouterInstance = createBrowserRouter(routers, {
|
|
63
|
-
// In host app, the routerContextProps is {}, so we should use router.basename as fallback
|
|
64
|
-
basename: routerContextProps.basename || router.basename,
|
|
65
|
-
future: router.future,
|
|
66
|
-
window: router.window,
|
|
67
|
-
});
|
|
68
|
-
return <RouterProvider {...propsRes} router={BrowserRouterInstance} />;
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
// Export all from react-router for v7 compatibility
|
|
73
|
-
export * from 'react-router';
|
|
74
|
-
export { WraperRouter as BrowserRouter };
|
|
75
|
-
export { WraperRouterProvider as RouterProvider };
|
package/src/types.ts
DELETED
|
@@ -1,147 +0,0 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
|
-
import { ErrorBoundaryPropsWithComponent } from 'react-error-boundary';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Options for creating a React root
|
|
6
|
-
*/
|
|
7
|
-
export interface CreateRootOptions {
|
|
8
|
-
identifierPrefix?: string;
|
|
9
|
-
onRecoverableError?: (error: unknown) => void;
|
|
10
|
-
transitionCallbacks?: unknown;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Interface for a React root object
|
|
15
|
-
*/
|
|
16
|
-
export interface Root {
|
|
17
|
-
render(children: React.ReactNode): void;
|
|
18
|
-
unmount(): void;
|
|
19
|
-
}
|
|
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
|
-
/**
|
|
27
|
-
* Parameters for the render function
|
|
28
|
-
*/
|
|
29
|
-
export interface RenderParams {
|
|
30
|
-
moduleName?: string;
|
|
31
|
-
basename?: string;
|
|
32
|
-
memoryRoute?: {
|
|
33
|
-
entryPath: string;
|
|
34
|
-
initialState?: Record<string, unknown>;
|
|
35
|
-
};
|
|
36
|
-
dom: HTMLElement;
|
|
37
|
-
/**
|
|
38
|
-
* Options to pass to createRoot for React 18 and 19
|
|
39
|
-
* @example
|
|
40
|
-
* {
|
|
41
|
-
* identifierPrefix: 'app-',
|
|
42
|
-
* onRecoverableError: (err) => console.error(err)
|
|
43
|
-
* }
|
|
44
|
-
*/
|
|
45
|
-
rootOptions?: CreateRootOptions;
|
|
46
|
-
[key: string]: unknown;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* Parameters for the destroy function
|
|
51
|
-
*/
|
|
52
|
-
export interface DestroyParams {
|
|
53
|
-
moduleName: string;
|
|
54
|
-
dom: HTMLElement;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* Parameters for the provider function
|
|
59
|
-
*/
|
|
60
|
-
export interface ProviderParams {
|
|
61
|
-
moduleName?: string;
|
|
62
|
-
basename?: string;
|
|
63
|
-
memoryRoute?: {
|
|
64
|
-
entryPath: string;
|
|
65
|
-
initialState?: Record<string, unknown>;
|
|
66
|
-
};
|
|
67
|
-
style?: React.CSSProperties;
|
|
68
|
-
className?: string;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* Parameters for the render function, extending ProviderParams
|
|
73
|
-
*/
|
|
74
|
-
export interface RenderFnParams extends ProviderParams {
|
|
75
|
-
dom: HTMLElement;
|
|
76
|
-
fallback?: React.ComponentType<{ error: Error }>;
|
|
77
|
-
[key: string]: unknown;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
/**
|
|
81
|
-
* Parameters for the provider function
|
|
82
|
-
*/
|
|
83
|
-
export interface ProviderFnParams<T> {
|
|
84
|
-
rootComponent: React.ComponentType<T>;
|
|
85
|
-
render?: (
|
|
86
|
-
App: React.ReactElement,
|
|
87
|
-
id?: HTMLElement | string,
|
|
88
|
-
) => RootType | Promise<RootType>;
|
|
89
|
-
createRoot?: (
|
|
90
|
-
container: Element | DocumentFragment,
|
|
91
|
-
options?: CreateRootOptions,
|
|
92
|
-
) => Root;
|
|
93
|
-
/**
|
|
94
|
-
* Default options to pass to createRoot for React 18 and 19
|
|
95
|
-
* These options will be used when creating a root unless overridden by rootOptions in render params
|
|
96
|
-
* @example
|
|
97
|
-
* {
|
|
98
|
-
* identifierPrefix: 'app-',
|
|
99
|
-
* onRecoverableError: (err) => console.error(err)
|
|
100
|
-
* }
|
|
101
|
-
*/
|
|
102
|
-
defaultRootOptions?: CreateRootOptions;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
/**
|
|
106
|
-
* Parameters for the remote component
|
|
107
|
-
*/
|
|
108
|
-
export interface RemoteComponentProps<T = Record<string, unknown>> {
|
|
109
|
-
props?: T;
|
|
110
|
-
fallback?: React.ComponentType<{ error: Error }>;
|
|
111
|
-
loading?: React.ReactNode;
|
|
112
|
-
[key: string]: unknown;
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
/**
|
|
116
|
-
* Parameters for the remote component loader
|
|
117
|
-
*/
|
|
118
|
-
export interface RemoteComponentParams<
|
|
119
|
-
T = Record<string, unknown>,
|
|
120
|
-
E extends keyof T = keyof T,
|
|
121
|
-
> {
|
|
122
|
-
loader: () => Promise<T>;
|
|
123
|
-
loading: React.ReactNode;
|
|
124
|
-
fallback: React.ComponentType<{ error: Error }>;
|
|
125
|
-
export?: E;
|
|
126
|
-
props?: T;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
/**
|
|
130
|
-
* Interface for a remote module provider
|
|
131
|
-
*/
|
|
132
|
-
export interface RemoteModule {
|
|
133
|
-
provider: () => {
|
|
134
|
-
render: (info: RenderFnParams) => void;
|
|
135
|
-
destroy: (info: { dom: any }) => void;
|
|
136
|
-
};
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
/**
|
|
140
|
-
* Parameters for a remote app component
|
|
141
|
-
*/
|
|
142
|
-
export interface RemoteAppParams extends ProviderParams {
|
|
143
|
-
moduleName: string;
|
|
144
|
-
providerInfo: NonNullable<RemoteModule['provider']>;
|
|
145
|
-
exportName: string | number | symbol;
|
|
146
|
-
fallback: ErrorBoundaryPropsWithComponent['FallbackComponent'];
|
|
147
|
-
}
|
package/src/utils/index.ts
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { createLogger } from '@module-federation/sdk';
|
|
2
|
-
|
|
3
|
-
export const LoggerInstance = createLogger(
|
|
4
|
-
'[ Module Federation Bridge React ]',
|
|
5
|
-
);
|
|
6
|
-
|
|
7
|
-
export function pathJoin(...args: string[]) {
|
|
8
|
-
const res = args.reduce((res, path: string) => {
|
|
9
|
-
let nPath = path;
|
|
10
|
-
if (!nPath || typeof nPath !== 'string') {
|
|
11
|
-
return res;
|
|
12
|
-
}
|
|
13
|
-
if (nPath[0] !== '/') {
|
|
14
|
-
nPath = `/${nPath}`;
|
|
15
|
-
}
|
|
16
|
-
const lastIndex = nPath.length - 1;
|
|
17
|
-
if (nPath[lastIndex] === '/') {
|
|
18
|
-
nPath = nPath.substring(0, lastIndex);
|
|
19
|
-
}
|
|
20
|
-
return res + nPath;
|
|
21
|
-
}, '');
|
|
22
|
-
return res || '/';
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export const getModuleName = (id: string) => {
|
|
26
|
-
if (!id) {
|
|
27
|
-
return id;
|
|
28
|
-
}
|
|
29
|
-
// separate module name without detailed module path
|
|
30
|
-
// @vmok-e2e/edenx-demo-app2/button -> @vmok-e2e/edenx-demo-app2
|
|
31
|
-
const idArray = id.split('/');
|
|
32
|
-
if (idArray.length < 2) {
|
|
33
|
-
return id;
|
|
34
|
-
}
|
|
35
|
-
return idArray[0] + '/' + idArray[1];
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
export const getRootDomDefaultClassName = (moduleName: string) => {
|
|
39
|
-
if (!moduleName) {
|
|
40
|
-
return '';
|
|
41
|
-
}
|
|
42
|
-
const name = getModuleName(moduleName).replace(/\@/, '').replace(/\//, '-');
|
|
43
|
-
return `bridge-root-component-${name}`;
|
|
44
|
-
};
|
package/src/v18.ts
DELETED
package/src/v19.ts
DELETED
package/tsconfig.json
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"useDefineForClassFields": true,
|
|
4
|
-
|
|
5
|
-
/* Bundler mode */
|
|
6
|
-
"allowImportingTsExtensions": true,
|
|
7
|
-
"resolveJsonModule": true,
|
|
8
|
-
|
|
9
|
-
"declarationDir": "./dist/types",
|
|
10
|
-
"rootDir": "./src",
|
|
11
|
-
"module": "commonjs",
|
|
12
|
-
"target": "es2015",
|
|
13
|
-
|
|
14
|
-
/* Linting */
|
|
15
|
-
"noUnusedLocals": true,
|
|
16
|
-
"noUnusedParameters": true,
|
|
17
|
-
"noFallthroughCasesInSwitch": true,
|
|
18
|
-
"declaration": true,
|
|
19
|
-
"emitDeclarationOnly": true,
|
|
20
|
-
"outDir": "dist",
|
|
21
|
-
"skipLibCheck": true,
|
|
22
|
-
"strict": true,
|
|
23
|
-
"moduleResolution": "node",
|
|
24
|
-
"lib": ["esnext", "dom"],
|
|
25
|
-
"jsx": "preserve",
|
|
26
|
-
"esModuleInterop": true,
|
|
27
|
-
"allowSyntheticDefaultImports": true,
|
|
28
|
-
"sourceMap": true,
|
|
29
|
-
"baseUrl": ".",
|
|
30
|
-
"paths": {
|
|
31
|
-
"@/*": ["src/*"]
|
|
32
|
-
}
|
|
33
|
-
},
|
|
34
|
-
"include": [
|
|
35
|
-
"src/**/*.ts",
|
|
36
|
-
"src/**/*.tsx",
|
|
37
|
-
"src/**/*.vue",
|
|
38
|
-
"src/remoteApp.tsx",
|
|
39
|
-
"src/create.ts"
|
|
40
|
-
],
|
|
41
|
-
"references": [{ "path": "./tsconfig.node.json" }]
|
|
42
|
-
}
|
package/tsconfig.node.json
DELETED
package/tsconfig.spec.json
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"extends": "./tsconfig.json",
|
|
3
|
-
"compilerOptions": {
|
|
4
|
-
"outDir": "../../../dist/out-tsc",
|
|
5
|
-
"module": "commonjs",
|
|
6
|
-
"types": ["jest", "node", "@testing-library/jest-dom"],
|
|
7
|
-
"jsx": "react-jsx",
|
|
8
|
-
"noUnusedLocals": false,
|
|
9
|
-
"noUnusedParameters": false,
|
|
10
|
-
"skipLibCheck": true,
|
|
11
|
-
"esModuleInterop": true,
|
|
12
|
-
"allowSyntheticDefaultImports": true
|
|
13
|
-
},
|
|
14
|
-
"include": [
|
|
15
|
-
"**/*.test.ts",
|
|
16
|
-
"**/*.test.tsx",
|
|
17
|
-
"**/*.test.js",
|
|
18
|
-
"**/*.test.jsx",
|
|
19
|
-
"**/*.spec.ts",
|
|
20
|
-
"**/*.spec.tsx",
|
|
21
|
-
"**/*.spec.js",
|
|
22
|
-
"**/*.spec.jsx",
|
|
23
|
-
"**/*.d.ts",
|
|
24
|
-
"__tests__/**/*"
|
|
25
|
-
]
|
|
26
|
-
}
|
package/vite.config.ts
DELETED
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
import { defineConfig } from 'vite';
|
|
2
|
-
import path from 'path';
|
|
3
|
-
import dts from 'vite-plugin-dts';
|
|
4
|
-
import packageJson from './package.json';
|
|
5
|
-
|
|
6
|
-
const perDepsKeys = Object.keys(packageJson.peerDependencies);
|
|
7
|
-
|
|
8
|
-
export default defineConfig({
|
|
9
|
-
plugins: [
|
|
10
|
-
// 添加我们的自定义插件
|
|
11
|
-
dts({
|
|
12
|
-
rollupTypes: true,
|
|
13
|
-
bundledPackages: [
|
|
14
|
-
'@module-federation/bridge-shared',
|
|
15
|
-
'react-error-boundary',
|
|
16
|
-
],
|
|
17
|
-
}),
|
|
18
|
-
],
|
|
19
|
-
build: {
|
|
20
|
-
lib: {
|
|
21
|
-
entry: {
|
|
22
|
-
index: path.resolve(__dirname, 'src/index.ts'),
|
|
23
|
-
base: path.resolve(__dirname, 'src/base.ts'),
|
|
24
|
-
plugin: path.resolve(__dirname, 'src/provider/plugin.ts'),
|
|
25
|
-
router: path.resolve(__dirname, 'src/router/default.tsx'),
|
|
26
|
-
'router-v5': path.resolve(__dirname, 'src/router/v5.tsx'),
|
|
27
|
-
'router-v6': path.resolve(__dirname, 'src/router/v6.tsx'),
|
|
28
|
-
'router-v7': path.resolve(__dirname, 'src/router/v7.tsx'),
|
|
29
|
-
v18: path.resolve(__dirname, 'src/v18.ts'),
|
|
30
|
-
v19: path.resolve(__dirname, 'src/v19.ts'),
|
|
31
|
-
'lazy-load-component-plugin': path.resolve(
|
|
32
|
-
__dirname,
|
|
33
|
-
'src/plugins/lazy-load-component-plugin.ts',
|
|
34
|
-
),
|
|
35
|
-
'data-fetch-server-middleware': path.resolve(
|
|
36
|
-
__dirname,
|
|
37
|
-
'src/lazy/data-fetch/data-fetch-server-middleware.ts',
|
|
38
|
-
),
|
|
39
|
-
'lazy-utils': path.resolve(__dirname, 'src/lazy/utils.ts'),
|
|
40
|
-
'data-fetch-utils': path.resolve(
|
|
41
|
-
__dirname,
|
|
42
|
-
'src/lazy/data-fetch/index.ts',
|
|
43
|
-
),
|
|
44
|
-
},
|
|
45
|
-
formats: ['cjs', 'es'],
|
|
46
|
-
fileName: (format, entryName) => `${entryName}.${format}.js`,
|
|
47
|
-
},
|
|
48
|
-
rollupOptions: {
|
|
49
|
-
external: [
|
|
50
|
-
...perDepsKeys,
|
|
51
|
-
'@remix-run/router',
|
|
52
|
-
/react-dom\/.*/,
|
|
53
|
-
'react-router',
|
|
54
|
-
'react-router/',
|
|
55
|
-
'react-router/index.js',
|
|
56
|
-
'react-router/dist/index.js',
|
|
57
|
-
'react-router/dist/development/index.js',
|
|
58
|
-
'react-router/dist/production/index.js',
|
|
59
|
-
/^react-router\/.*/,
|
|
60
|
-
'react-router-dom/',
|
|
61
|
-
'react-router-dom/index.js',
|
|
62
|
-
'react-router-dom/dist/index.js',
|
|
63
|
-
],
|
|
64
|
-
plugins: [
|
|
65
|
-
{
|
|
66
|
-
name: 'modify-output-plugin',
|
|
67
|
-
generateBundle(options, bundle) {
|
|
68
|
-
for (const fileName in bundle) {
|
|
69
|
-
const chunk = bundle[fileName];
|
|
70
|
-
if (fileName.includes('router-v6') && chunk.type === 'chunk') {
|
|
71
|
-
chunk.code = chunk.code.replace(
|
|
72
|
-
// Match 'react-router-dom/' followed by single quotes, double quotes, or backticks, replacing only 'react-router-dom/' to react-router-v6 dist file structure
|
|
73
|
-
/react-router-dom\/(?=[\'\"\`])/g,
|
|
74
|
-
'react-router-dom/dist/index.js',
|
|
75
|
-
);
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
if (fileName.includes('router-v7') && chunk.type === 'chunk') {
|
|
79
|
-
// Replace 'react-router' with the correct v7 dist path based on environment
|
|
80
|
-
const isProduction = process.env.NODE_ENV === 'production';
|
|
81
|
-
const distPath = isProduction
|
|
82
|
-
? 'react-router/dist/production/index.js'
|
|
83
|
-
: 'react-router/dist/development/index.js';
|
|
84
|
-
|
|
85
|
-
chunk.code = chunk.code.replace(
|
|
86
|
-
/from\s+['"`]react-router['"`]/g,
|
|
87
|
-
`from '${distPath}'`,
|
|
88
|
-
);
|
|
89
|
-
chunk.code = chunk.code.replace(
|
|
90
|
-
/export\s+\*\s+from\s+['"`]react-router['"`]/g,
|
|
91
|
-
`export * from '${distPath}'`,
|
|
92
|
-
);
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
if (fileName.includes('router-v5') && chunk.type === 'chunk') {
|
|
96
|
-
chunk.code = chunk.code.replace(
|
|
97
|
-
// Match 'react-router-dom/' followed by single quotes, double quotes, or backticks, replacing only 'react-router-dom/' to react-router-v5 dist file structure
|
|
98
|
-
/react-router-dom\/(?=[\'\"\`])/g,
|
|
99
|
-
'react-router-dom/index.js',
|
|
100
|
-
);
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
},
|
|
104
|
-
},
|
|
105
|
-
],
|
|
106
|
-
},
|
|
107
|
-
minify: false,
|
|
108
|
-
},
|
|
109
|
-
define: {
|
|
110
|
-
__APP_VERSION__: JSON.stringify(packageJson.version),
|
|
111
|
-
},
|
|
112
|
-
});
|
package/vitest.config.ts
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { defineConfig } from 'vitest/config';
|
|
2
|
-
import tsconfigPaths from 'vite-tsconfig-paths';
|
|
3
|
-
import react from '@vitejs/plugin-react';
|
|
4
|
-
import path from 'path';
|
|
5
|
-
export default defineConfig({
|
|
6
|
-
define: {
|
|
7
|
-
__DEV__: true,
|
|
8
|
-
__TEST__: true,
|
|
9
|
-
__BROWSER__: false,
|
|
10
|
-
__VERSION__: '"unknown"',
|
|
11
|
-
__APP_VERSION__: '"0.0.0"',
|
|
12
|
-
},
|
|
13
|
-
resolve: {
|
|
14
|
-
extensions: ['.mjs', '.js', '.ts', '.jsx', '.tsx', '.json'],
|
|
15
|
-
},
|
|
16
|
-
plugins: [react(), tsconfigPaths()],
|
|
17
|
-
test: {
|
|
18
|
-
environment: 'jsdom',
|
|
19
|
-
include: [
|
|
20
|
-
path.resolve(__dirname, '__tests__/*.spec.ts'),
|
|
21
|
-
path.resolve(__dirname, '__tests__/*.spec.tsx'),
|
|
22
|
-
],
|
|
23
|
-
globals: true,
|
|
24
|
-
testTimeout: 10000,
|
|
25
|
-
setupFiles: [path.resolve(__dirname, '__tests__/setupTests.ts')],
|
|
26
|
-
},
|
|
27
|
-
});
|