@module-federation/bridge-react 0.0.0-feat-support-bridge-react-router-v7-20251015102312

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 (100) hide show
  1. package/CHANGELOG.md +670 -0
  2. package/LICENSE +21 -0
  3. package/README.md +131 -0
  4. package/__tests__/bridge.spec.tsx +160 -0
  5. package/__tests__/createLazyComponent.spec.tsx +209 -0
  6. package/__tests__/prefetch.spec.ts +156 -0
  7. package/__tests__/router.spec.tsx +82 -0
  8. package/__tests__/setupTests.ts +8 -0
  9. package/__tests__/util.ts +36 -0
  10. package/dist/bridge-base-29j7dZKh.mjs +201 -0
  11. package/dist/bridge-base-CTNdBioh.js +216 -0
  12. package/dist/data-fetch-server-middleware.cjs.js +163 -0
  13. package/dist/data-fetch-server-middleware.d.ts +15 -0
  14. package/dist/data-fetch-server-middleware.es.js +164 -0
  15. package/dist/data-fetch-utils.cjs.js +24 -0
  16. package/dist/data-fetch-utils.d.ts +81 -0
  17. package/dist/data-fetch-utils.es.js +26 -0
  18. package/dist/index-Dm-M9ouh.mjs +46 -0
  19. package/dist/index-DqCpgmgH.js +45 -0
  20. package/dist/index.cjs.js +293 -0
  21. package/dist/index.d.ts +274 -0
  22. package/dist/index.es.js +276 -0
  23. package/dist/index.esm-CzoIcLts.js +459 -0
  24. package/dist/index.esm-JLwyxgUK.mjs +460 -0
  25. package/dist/lazy-load-component-plugin-B4fdMQTL.js +521 -0
  26. package/dist/lazy-load-component-plugin-ijw36GA0.mjs +522 -0
  27. package/dist/lazy-load-component-plugin.cjs.js +6 -0
  28. package/dist/lazy-load-component-plugin.d.ts +16 -0
  29. package/dist/lazy-load-component-plugin.es.js +6 -0
  30. package/dist/lazy-utils.cjs.js +24 -0
  31. package/dist/lazy-utils.d.ts +149 -0
  32. package/dist/lazy-utils.es.js +24 -0
  33. package/dist/plugin.cjs.js +14 -0
  34. package/dist/plugin.d.ts +22 -0
  35. package/dist/plugin.es.js +14 -0
  36. package/dist/prefetch-Bgm31z9s.js +1272 -0
  37. package/dist/prefetch-DjeoxOeZ.mjs +1273 -0
  38. package/dist/router-v5.cjs.js +55 -0
  39. package/dist/router-v5.d.ts +18 -0
  40. package/dist/router-v5.es.js +32 -0
  41. package/dist/router-v6.cjs.js +84 -0
  42. package/dist/router-v6.d.ts +20 -0
  43. package/dist/router-v6.es.js +61 -0
  44. package/dist/router-v7.cjs.js +83 -0
  45. package/dist/router-v7.d.ts +20 -0
  46. package/dist/router-v7.es.js +61 -0
  47. package/dist/router.cjs.js +82 -0
  48. package/dist/router.d.ts +20 -0
  49. package/dist/router.es.js +60 -0
  50. package/dist/utils-0HFFqmd4.js +2015 -0
  51. package/dist/utils-BTpxHmva.mjs +2016 -0
  52. package/dist/v18.cjs.js +15 -0
  53. package/dist/v18.d.ts +114 -0
  54. package/dist/v18.es.js +15 -0
  55. package/dist/v19.cjs.js +15 -0
  56. package/dist/v19.d.ts +115 -0
  57. package/dist/v19.es.js +15 -0
  58. package/jest.config.ts +21 -0
  59. package/package.json +144 -0
  60. package/project.json +23 -0
  61. package/src/index.ts +45 -0
  62. package/src/lazy/AwaitDataFetch.tsx +215 -0
  63. package/src/lazy/constant.ts +30 -0
  64. package/src/lazy/createLazyComponent.tsx +411 -0
  65. package/src/lazy/data-fetch/cache.ts +291 -0
  66. package/src/lazy/data-fetch/call-data-fetch.ts +13 -0
  67. package/src/lazy/data-fetch/data-fetch-server-middleware.ts +196 -0
  68. package/src/lazy/data-fetch/index.ts +16 -0
  69. package/src/lazy/data-fetch/inject-data-fetch.ts +109 -0
  70. package/src/lazy/data-fetch/prefetch.ts +112 -0
  71. package/src/lazy/data-fetch/runtime-plugin.ts +115 -0
  72. package/src/lazy/index.ts +35 -0
  73. package/src/lazy/logger.ts +6 -0
  74. package/src/lazy/types.ts +75 -0
  75. package/src/lazy/utils.ts +372 -0
  76. package/src/lazy/wrapNoSSR.tsx +10 -0
  77. package/src/modern-app-env.d.ts +2 -0
  78. package/src/plugins/lazy-load-component-plugin.spec.ts +21 -0
  79. package/src/plugins/lazy-load-component-plugin.ts +57 -0
  80. package/src/provider/context.tsx +4 -0
  81. package/src/provider/plugin.ts +22 -0
  82. package/src/provider/versions/bridge-base.tsx +127 -0
  83. package/src/provider/versions/legacy.ts +87 -0
  84. package/src/provider/versions/v18.ts +47 -0
  85. package/src/provider/versions/v19.ts +48 -0
  86. package/src/remote/component.tsx +211 -0
  87. package/src/remote/create.tsx +103 -0
  88. package/src/router/default.tsx +73 -0
  89. package/src/router/v5.tsx +43 -0
  90. package/src/router/v6.tsx +74 -0
  91. package/src/router/v7.tsx +75 -0
  92. package/src/types.ts +147 -0
  93. package/src/utils/index.ts +44 -0
  94. package/src/v18.ts +9 -0
  95. package/src/v19.ts +9 -0
  96. package/tsconfig.json +42 -0
  97. package/tsconfig.node.json +11 -0
  98. package/tsconfig.spec.json +26 -0
  99. package/vite.config.ts +106 -0
  100. package/vitest.config.ts +27 -0
package/vite.config.ts ADDED
@@ -0,0 +1,106 @@
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
+ plugin: path.resolve(__dirname, 'src/provider/plugin.ts'),
24
+ router: path.resolve(__dirname, 'src/router/default.tsx'),
25
+ 'router-v5': path.resolve(__dirname, 'src/router/v5.tsx'),
26
+ 'router-v6': path.resolve(__dirname, 'src/router/v6.tsx'),
27
+ 'router-v7': path.resolve(__dirname, 'src/router/v7.tsx'),
28
+ v18: path.resolve(__dirname, 'src/v18.ts'),
29
+ v19: path.resolve(__dirname, 'src/v19.ts'),
30
+ 'lazy-load-component-plugin': path.resolve(
31
+ __dirname,
32
+ 'src/plugins/lazy-load-component-plugin.ts',
33
+ ),
34
+ 'data-fetch-server-middleware': path.resolve(
35
+ __dirname,
36
+ 'src/lazy/data-fetch/data-fetch-server-middleware.ts',
37
+ ),
38
+ 'lazy-utils': path.resolve(__dirname, 'src/lazy/utils.ts'),
39
+ 'data-fetch-utils': path.resolve(
40
+ __dirname,
41
+ 'src/lazy/data-fetch/index.ts',
42
+ ),
43
+ },
44
+ formats: ['cjs', 'es'],
45
+ fileName: (format, entryName) => `${entryName}.${format}.js`,
46
+ },
47
+ rollupOptions: {
48
+ external: [
49
+ ...perDepsKeys,
50
+ '@remix-run/router',
51
+ /react-dom\/.*/,
52
+ 'react-router',
53
+ 'react-router/',
54
+ 'react-router/index.js',
55
+ 'react-router/dist/index.js',
56
+ 'react-router/dist/development/index.js',
57
+ 'react-router/dist/production/index.js',
58
+ /^react-router\/.*/,
59
+ 'react-router-dom/',
60
+ 'react-router-dom/index.js',
61
+ 'react-router-dom/dist/index.js',
62
+ ],
63
+ plugins: [
64
+ {
65
+ name: 'modify-output-plugin',
66
+ generateBundle(options, bundle) {
67
+ for (const fileName in bundle) {
68
+ const chunk = bundle[fileName];
69
+ if (fileName.includes('router-v6') && chunk.type === 'chunk') {
70
+ chunk.code = chunk.code.replace(
71
+ // Match 'react-router-dom/' followed by single quotes, double quotes, or backticks, replacing only 'react-router-dom/' to react-router-v6 dist file structure
72
+ /react-router-dom\/(?=[\'\"\`])/g,
73
+ 'react-router-dom/dist/index.js',
74
+ );
75
+ }
76
+
77
+ if (fileName.includes('router-v7') && chunk.type === 'chunk') {
78
+ // Replace 'react-router' with the correct v7 dist path
79
+ chunk.code = chunk.code.replace(
80
+ /from\s+['"`]react-router['"`]/g,
81
+ "from 'react-router/dist/development/index.js'",
82
+ );
83
+ chunk.code = chunk.code.replace(
84
+ /export\s+\*\s+from\s+['"`]react-router['"`]/g,
85
+ "export * from 'react-router/dist/development/index.js'",
86
+ );
87
+ }
88
+
89
+ if (fileName.includes('router-v5') && chunk.type === 'chunk') {
90
+ chunk.code = chunk.code.replace(
91
+ // Match 'react-router-dom/' followed by single quotes, double quotes, or backticks, replacing only 'react-router-dom/' to react-router-v5 dist file structure
92
+ /react-router-dom\/(?=[\'\"\`])/g,
93
+ 'react-router-dom/index.js',
94
+ );
95
+ }
96
+ }
97
+ },
98
+ },
99
+ ],
100
+ },
101
+ minify: false,
102
+ },
103
+ define: {
104
+ __APP_VERSION__: JSON.stringify(packageJson.version),
105
+ },
106
+ });
@@ -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
+ });