Skip to content

Commit 3b01878

Browse files
committed
fix: fix bridge-react-webpack-plugin unit tests failed
1 parent b727489 commit 3b01878

File tree

3 files changed

+88
-7
lines changed

3 files changed

+88
-7
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
{
2+
"name": "react-router",
3+
"version": "7.0.0",
4+
"description": "Declarative routing for React applications",
5+
"keywords": [
6+
"react",
7+
"router",
8+
"route",
9+
"routing",
10+
"history",
11+
"link"
12+
],
13+
"repository": {
14+
"type": "git",
15+
"url": "https://github.com/remix-run/react-router",
16+
"directory": "packages/react-router"
17+
},
18+
"license": "MIT",
19+
"author": "Remix Software <hello@remix.run>",
20+
"sideEffects": false,
21+
"main": "./dist/main.js",
22+
"unpkg": "./dist/umd/react-router.production.min.js",
23+
"module": "./dist/index.js",
24+
"types": "./dist/index.d.ts",
25+
"dependencies": {
26+
"@remix-run/router": "2.0.0"
27+
},
28+
"devDependencies": {
29+
"react": "^18.3.1",
30+
"react-dom": "^18.3.1"
31+
},
32+
"peerDependencies": {
33+
"react": ">=18.0.0",
34+
"react-dom": ">=18.0.0"
35+
},
36+
"files": [
37+
"dist/",
38+
"CHANGELOG.md",
39+
"LICENSE.md",
40+
"README.md"
41+
],
42+
"engines": {
43+
"node": ">=18.0.0"
44+
}
45+
}

packages/bridge/bridge-react-webpack-plugin/__tests__/utils.spec.ts

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
import path from 'node:path';
2-
import {
3-
checkVersion,
4-
findPackageJson,
5-
getBridgeRouterAlias,
6-
} from '../src/utis';
2+
import { checkVersion, findPackageJson } from '../src/utils';
3+
import { getBridgeRouterAlias } from '../src/router-alias';
74

85
const resolveRouterV5 = path.resolve(
96
__dirname,
@@ -21,6 +18,14 @@ const resolveRouterV6_PkgPath = path.resolve(
2118
__dirname,
2219
'../__tests__/mockRouterDir/router-v6/react-router-dom/package.json',
2320
);
21+
const resolveRouterV7 = path.resolve(
22+
__dirname,
23+
'../__tests__/mockRouterDir/router-v7/react-router',
24+
);
25+
const resolveRouterV7_PkgPath = path.resolve(
26+
__dirname,
27+
'../__tests__/mockRouterDir/router-v7/react-router/package.json',
28+
);
2429

2530
describe('test checkVersion: should return the correct major version for react-router-dom', () => {
2631
it('should return 5', () => {
@@ -42,16 +47,29 @@ describe('test checkVersion: should return the correct major version for react-r
4247
it('should return 6', () => {
4348
expect(checkVersion('^6.0.0')).toBe(6);
4449
});
50+
51+
it('should return 7', () => {
52+
expect(checkVersion('7.0.0')).toBe(7);
53+
});
54+
55+
it('should return 7', () => {
56+
expect(checkVersion('~7.0.0')).toBe(7);
57+
});
58+
59+
it('should return 7', () => {
60+
expect(checkVersion('^7.0.0')).toBe(7);
61+
});
4562
});
4663

47-
describe('test findPackageJson: should return the correct package.json path for react-router-dom v5 and v6', () => {
64+
describe('test findPackageJson: should return the correct package.json path for react-router-dom v5, v6 and react-router v7', () => {
4865
it('should return the package.json path', () => {
4966
expect(findPackageJson(resolveRouterV5)).toBe(resolveRouterV5_PkgPath);
5067
expect(findPackageJson(resolveRouterV6)).toBe(resolveRouterV6_PkgPath);
68+
expect(findPackageJson(resolveRouterV7)).toBe(resolveRouterV7_PkgPath);
5169
});
5270
});
5371

54-
describe('test getBridgeRouterAlias: should return the correct alias for react-router-dom v5 and v6', () => {
72+
describe('test getBridgeRouterAlias: should return the correct alias for react-router-dom v5, v6 and react-router v7', () => {
5573
it('should return the correct alias for router v5', () => {
5674
const res = getBridgeRouterAlias(resolveRouterV5);
5775
expect(res).toEqual({
@@ -66,6 +84,19 @@ describe('test getBridgeRouterAlias: should return the correct alias for react-r
6684
expect(res).toEqual({
6785
'react-router-dom$':
6886
'@module-federation/bridge-react/dist/router-v6.es.js',
87+
'react-router-dom/dist/index.js': resolveRouterV6,
88+
});
89+
});
90+
91+
it('should return the correct alias for router v7', () => {
92+
const res = getBridgeRouterAlias(resolveRouterV7);
93+
expect(res).toEqual({
94+
'react-router$': '@module-federation/bridge-react/dist/router-v7.es.js',
95+
'react-router-dom$':
96+
'@module-federation/bridge-react/dist/router-v7.es.js',
97+
'react-router/dist/development/index.js': resolveRouterV7,
98+
'react-router/dist/production/index.js': resolveRouterV7,
99+
'react-router-dom/dist/index.js': resolveRouterV7,
69100
});
70101
});
71102
});

packages/bridge/bridge-react-webpack-plugin/src/router-alias.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,14 @@ const createReactRouterV7Alias = (
2222
'react-router/dist/production/index.js': reactRouterDomPath,
2323
};
2424

25+
const legacyCompatibility: Record<string, string> = {
26+
'react-router-dom/dist/index.js': reactRouterDomPath,
27+
};
28+
2529
return {
2630
...baseAlias,
2731
...resolvedDistPaths,
32+
...legacyCompatibility,
2833
};
2934
};
3035

0 commit comments

Comments
 (0)