@module-federation/bridge-react 0.0.0-docs-remove-invalid-lark-link-20251205062649
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/CHANGELOG.md +728 -0
- package/LICENSE +21 -0
- package/README.md +131 -0
- package/__tests__/bridge.spec.tsx +160 -0
- package/__tests__/createLazyComponent.spec.tsx +209 -0
- package/__tests__/prefetch.spec.ts +156 -0
- package/__tests__/router.spec.tsx +82 -0
- package/__tests__/setupTests.ts +8 -0
- package/__tests__/util.ts +36 -0
- package/dist/base.cjs.js +29 -0
- package/dist/base.d.ts +311 -0
- package/dist/base.es.js +30 -0
- package/dist/bridge-base-CPSTBjEp.mjs +211 -0
- package/dist/bridge-base-RStDxH71.js +226 -0
- package/dist/createHelpers-B_L612IN.js +190 -0
- package/dist/createHelpers-Ui5pt7je.mjs +191 -0
- package/dist/data-fetch-server-middleware.cjs.js +163 -0
- package/dist/data-fetch-server-middleware.d.ts +15 -0
- package/dist/data-fetch-server-middleware.es.js +164 -0
- package/dist/data-fetch-utils.cjs.js +24 -0
- package/dist/data-fetch-utils.d.ts +81 -0
- package/dist/data-fetch-utils.es.js +26 -0
- package/dist/index-DRSBaSu3.js +45 -0
- package/dist/index-DyQNwY2M.mjs +46 -0
- package/dist/index.cjs.js +125 -0
- package/dist/index.d.ts +299 -0
- package/dist/index.es.js +109 -0
- package/dist/index.esm-BWaKho-8.js +491 -0
- package/dist/index.esm-CPwSeCvw.mjs +492 -0
- package/dist/lazy-load-component-plugin-CSRkMmKF.js +521 -0
- package/dist/lazy-load-component-plugin-DXqhuywC.mjs +522 -0
- package/dist/lazy-load-component-plugin.cjs.js +6 -0
- package/dist/lazy-load-component-plugin.d.ts +16 -0
- package/dist/lazy-load-component-plugin.es.js +6 -0
- package/dist/lazy-utils.cjs.js +24 -0
- package/dist/lazy-utils.d.ts +149 -0
- package/dist/lazy-utils.es.js +24 -0
- package/dist/plugin.cjs.js +14 -0
- package/dist/plugin.d.ts +22 -0
- package/dist/plugin.es.js +14 -0
- package/dist/prefetch-A3QkU5oZ.js +1272 -0
- package/dist/prefetch-zMJL79zx.mjs +1273 -0
- package/dist/router-v5.cjs.js +55 -0
- package/dist/router-v5.d.ts +18 -0
- package/dist/router-v5.es.js +32 -0
- package/dist/router-v6.cjs.js +84 -0
- package/dist/router-v6.d.ts +20 -0
- package/dist/router-v6.es.js +61 -0
- package/dist/router-v7.cjs.js +83 -0
- package/dist/router-v7.d.ts +20 -0
- package/dist/router-v7.es.js +61 -0
- package/dist/router.cjs.js +82 -0
- package/dist/router.d.ts +20 -0
- package/dist/router.es.js +60 -0
- package/dist/utils-dUgb9Jkm.mjs +2016 -0
- package/dist/utils-tM9yE73c.js +2015 -0
- package/dist/v18.cjs.js +15 -0
- package/dist/v18.d.ts +114 -0
- package/dist/v18.es.js +15 -0
- package/dist/v19.cjs.js +15 -0
- package/dist/v19.d.ts +115 -0
- package/dist/v19.es.js +15 -0
- package/jest.config.ts +21 -0
- package/package.json +173 -0
- package/project.json +23 -0
- package/src/base.ts +50 -0
- package/src/index.ts +50 -0
- package/src/lazy/AwaitDataFetch.tsx +215 -0
- package/src/lazy/constant.ts +30 -0
- package/src/lazy/createLazyComponent.tsx +411 -0
- package/src/lazy/data-fetch/cache.ts +291 -0
- package/src/lazy/data-fetch/call-data-fetch.ts +13 -0
- package/src/lazy/data-fetch/data-fetch-server-middleware.ts +196 -0
- package/src/lazy/data-fetch/index.ts +16 -0
- package/src/lazy/data-fetch/inject-data-fetch.ts +109 -0
- package/src/lazy/data-fetch/prefetch.ts +112 -0
- package/src/lazy/data-fetch/runtime-plugin.ts +115 -0
- package/src/lazy/index.ts +35 -0
- package/src/lazy/logger.ts +6 -0
- package/src/lazy/types.ts +75 -0
- package/src/lazy/utils.ts +372 -0
- package/src/lazy/wrapNoSSR.tsx +10 -0
- package/src/modern-app-env.d.ts +2 -0
- package/src/plugins/lazy-load-component-plugin.spec.ts +21 -0
- package/src/plugins/lazy-load-component-plugin.ts +57 -0
- package/src/provider/context.tsx +4 -0
- package/src/provider/plugin.ts +22 -0
- package/src/provider/versions/bridge-base.tsx +150 -0
- package/src/provider/versions/legacy.ts +87 -0
- package/src/provider/versions/v18.ts +47 -0
- package/src/provider/versions/v19.ts +48 -0
- package/src/remote/RemoteAppWrapper.tsx +108 -0
- package/src/remote/base-component/component.tsx +2 -0
- package/src/remote/base-component/create.tsx +23 -0
- package/src/remote/base-component/index.tsx +10 -0
- package/src/remote/createHelpers.tsx +130 -0
- package/src/remote/router-component/component.tsx +104 -0
- package/src/remote/router-component/create.tsx +23 -0
- package/src/remote/router-component/index.tsx +10 -0
- package/src/router/default.tsx +73 -0
- package/src/router/v5.tsx +43 -0
- package/src/router/v6.tsx +74 -0
- package/src/router/v7.tsx +75 -0
- package/src/types.ts +147 -0
- package/src/utils/index.ts +44 -0
- package/src/v18.ts +9 -0
- package/src/v19.ts +9 -0
- package/tsconfig.json +42 -0
- package/tsconfig.node.json +11 -0
- package/tsconfig.spec.json +26 -0
- package/vite.config.ts +112 -0
- package/vitest.config.ts +27 -0
|
@@ -0,0 +1,44 @@
|
|
|
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
ADDED
package/src/v19.ts
ADDED
package/tsconfig.json
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
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
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
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
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { defineConfig } from 'vitest/config';
|
|
2
|
+
import { nxViteTsPaths } from '@nx/vite/plugins/nx-tsconfig-paths.plugin';
|
|
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(), nxViteTsPaths()],
|
|
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
|
+
});
|