@module-federation/bridge-react-webpack-plugin 0.5.2 → 0.6.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/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # @module-federation/bridge-react-webpack-plugin
2
2
 
3
+ ## 0.6.0
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [1d9bb77]
8
+ - @module-federation/sdk@0.6.0
9
+
3
10
  ## 0.5.2
4
11
 
5
12
  ### Patch Changes
@@ -0,0 +1,71 @@
1
+ {
2
+ "name": "react-router-dom",
3
+ "version": "5.3.4",
4
+ "description": "DOM bindings for React Router",
5
+ "homepage": "https://reactrouter.com/",
6
+ "repository": {
7
+ "url": "https://github.com/remix-run/react-router.git",
8
+ "type": "git",
9
+ "directory": "packages/react-router-dom"
10
+ },
11
+ "license": "MIT",
12
+ "author": "Remix Software <hello@remix.run>",
13
+ "files": [
14
+ "LICENSE",
15
+ "README.md",
16
+ "BrowserRouter.js",
17
+ "HashRouter.js",
18
+ "Link.js",
19
+ "MemoryRouter.js",
20
+ "NavLink.js",
21
+ "Prompt.js",
22
+ "Redirect.js",
23
+ "Route.js",
24
+ "Router.js",
25
+ "StaticRouter.js",
26
+ "Switch.js",
27
+ "cjs",
28
+ "es",
29
+ "esm",
30
+ "index.js",
31
+ "generatePath.js",
32
+ "matchPath.js",
33
+ "modules/*.js",
34
+ "modules/utils/*.js",
35
+ "withRouter.js",
36
+ "warnAboutDeprecatedCJSRequire.js",
37
+ "umd"
38
+ ],
39
+ "main": "index.js",
40
+ "module": "esm/react-router-dom.js",
41
+ "sideEffects": false,
42
+ "scripts": {
43
+ "build": "rollup -c",
44
+ "lint": "eslint modules"
45
+ },
46
+ "peerDependencies": {
47
+ "react": ">=15"
48
+ },
49
+ "dependencies": {
50
+ "@babel/runtime": "^7.12.13",
51
+ "history": "^4.9.0",
52
+ "loose-envify": "^1.3.1",
53
+ "prop-types": "^15.6.2",
54
+ "react-router": "5.3.4",
55
+ "tiny-invariant": "^1.0.2",
56
+ "tiny-warning": "^1.0.0"
57
+ },
58
+ "browserify": {
59
+ "transform": [
60
+ "loose-envify"
61
+ ]
62
+ },
63
+ "keywords": [
64
+ "react",
65
+ "router",
66
+ "route",
67
+ "routing",
68
+ "history",
69
+ "link"
70
+ ]
71
+ }
@@ -0,0 +1,49 @@
1
+ {
2
+ "name": "react-router-dom",
3
+ "version": "6.22.3",
4
+ "description": "Declarative routing for React web 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-dom"
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-dom.production.min.js",
23
+ "module": "./dist/index.js",
24
+ "types": "./dist/index.d.ts",
25
+ "dependencies": {
26
+ "@remix-run/router": "1.15.3",
27
+ "react-router": "6.22.3"
28
+ },
29
+ "devDependencies": {
30
+ "react": "^18.2.0",
31
+ "react-dom": "^18.2.0"
32
+ },
33
+ "peerDependencies": {
34
+ "react": ">=16.8",
35
+ "react-dom": ">=16.8"
36
+ },
37
+ "files": [
38
+ "dist/",
39
+ "CHANGELOG.md",
40
+ "LICENSE.md",
41
+ "README.md",
42
+ "server.d.ts",
43
+ "server.js",
44
+ "server.mjs"
45
+ ],
46
+ "engines": {
47
+ "node": ">=14.0.0"
48
+ }
49
+ }
@@ -0,0 +1,71 @@
1
+ import path from 'node:path';
2
+ import {
3
+ checkVersion,
4
+ findPackageJson,
5
+ getBridgeRouterAlias,
6
+ } from '../src/utis';
7
+
8
+ const resolveRouterV5 = path.resolve(
9
+ __dirname,
10
+ '../__tests__/mockRouterDir/router-v5/react-router-dom',
11
+ );
12
+ const resolveRouterV5_PkgPath = path.resolve(
13
+ __dirname,
14
+ '../__tests__/mockRouterDir/router-v5/react-router-dom/package.json',
15
+ );
16
+ const resolveRouterV6 = path.resolve(
17
+ __dirname,
18
+ '../__tests__/mockRouterDir/router-v6/react-router-dom/dist/main.js',
19
+ );
20
+ const resolveRouterV6_PkgPath = path.resolve(
21
+ __dirname,
22
+ '../__tests__/mockRouterDir/router-v6/react-router-dom/package.json',
23
+ );
24
+
25
+ describe('test checkVersion: should return the correct major version for react-router-dom', () => {
26
+ it('should return 5', () => {
27
+ expect(checkVersion('5.0.0')).toBe(5);
28
+ });
29
+
30
+ it('should return 5', () => {
31
+ expect(checkVersion('^5.0.0')).toBe(5);
32
+ });
33
+
34
+ it('should return 6', () => {
35
+ expect(checkVersion('6.0.0')).toBe(6);
36
+ });
37
+
38
+ it('should return 6', () => {
39
+ expect(checkVersion('~6.0.0')).toBe(6);
40
+ });
41
+
42
+ it('should return 6', () => {
43
+ expect(checkVersion('^6.0.0')).toBe(6);
44
+ });
45
+ });
46
+
47
+ describe('test findPackageJson: should return the correct package.json path for react-router-dom v5 and v6', () => {
48
+ it('should return the package.json path', () => {
49
+ expect(findPackageJson(resolveRouterV5)).toBe(resolveRouterV5_PkgPath);
50
+ expect(findPackageJson(resolveRouterV6)).toBe(resolveRouterV6_PkgPath);
51
+ });
52
+ });
53
+
54
+ describe('test getBridgeRouterAlias: should return the correct alias for react-router-dom v5 and v6', () => {
55
+ it('should return the correct alias for router v5', () => {
56
+ const res = getBridgeRouterAlias(resolveRouterV5);
57
+ expect(res).toEqual({
58
+ 'react-router-dom$':
59
+ '@module-federation/bridge-react/dist/router-v5.es.js',
60
+ 'react-router-dom/index.js': resolveRouterV5,
61
+ });
62
+ });
63
+
64
+ it('should return the correct alias for router v6', () => {
65
+ const res = getBridgeRouterAlias(resolveRouterV6);
66
+ expect(res).toEqual({
67
+ 'react-router-dom$':
68
+ '@module-federation/bridge-react/dist/router-v6.es.js',
69
+ });
70
+ });
71
+ });
package/dist/index.cjs.js CHANGED
@@ -1625,6 +1625,29 @@ var semver = {
1625
1625
  rcompareIdentifiers: identifiers.rcompareIdentifiers
1626
1626
  };
1627
1627
  const semver$1 = /* @__PURE__ */ getDefaultExportFromCjs(semver);
1628
+ const checkVersion = (version) => {
1629
+ const versionMatch = version.match(/\d.*/);
1630
+ if (!versionMatch)
1631
+ return 0;
1632
+ const cleanVersion = versionMatch[0];
1633
+ if (semver$1.gte(cleanVersion, "5.0.0") && semver$1.lt(cleanVersion, "6.0.0")) {
1634
+ return 5;
1635
+ } else if (semver$1.gte(cleanVersion, "6.0.0")) {
1636
+ return 6;
1637
+ }
1638
+ return 0;
1639
+ };
1640
+ const findPackageJson = (startPath) => {
1641
+ let currentPath = startPath;
1642
+ while (currentPath !== path.parse(currentPath).root) {
1643
+ const packageJsonPath = path.join(currentPath, "package.json");
1644
+ if (fs.existsSync(packageJsonPath)) {
1645
+ return packageJsonPath;
1646
+ }
1647
+ currentPath = path.dirname(currentPath);
1648
+ }
1649
+ return null;
1650
+ };
1628
1651
  const getBridgeRouterAlias = (originalAlias) => {
1629
1652
  const userPackageJsonPath = path.resolve(process.cwd(), "package.json");
1630
1653
  let userDependencies = {};
@@ -1637,54 +1660,51 @@ const getBridgeRouterAlias = (originalAlias) => {
1637
1660
  ...userPackageJson.devDependencies
1638
1661
  };
1639
1662
  }
1640
- const hasBridgeReact = "@module-federation/bridge-react" in userDependencies;
1641
1663
  let bridgeRouterAlias = {};
1642
- if (hasBridgeReact) {
1643
- const reactRouterDomVersion = userDependencies["react-router-dom"];
1644
- let majorVersion = 0;
1645
- let reactRouterDomPath = "";
1646
- if (reactRouterDomVersion) {
1647
- majorVersion = semver$1.major(
1648
- semver$1.coerce(reactRouterDomVersion || "0.0.0") ?? "0.0.0"
1649
- );
1650
- reactRouterDomPath = require.resolve("react-router-dom");
1651
- } else {
1652
- reactRouterDomPath = require.resolve("react-router-dom");
1653
- const packageJsonPath = path.resolve(
1654
- reactRouterDomPath,
1655
- "../../package.json"
1656
- );
1657
- const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, "utf-8"));
1658
- majorVersion = parseInt(packageJson.version.split(".")[0]);
1659
- }
1660
- reactRouterDomPath = originalAlias || reactRouterDomPath;
1661
- if (majorVersion === 5) {
1664
+ let majorVersion = 0;
1665
+ let reactRouterDomPath = "";
1666
+ const reactRouterDomVersion = userDependencies["react-router-dom"];
1667
+ if (originalAlias) {
1668
+ reactRouterDomPath = originalAlias;
1669
+ } else if (reactRouterDomVersion) {
1670
+ majorVersion = checkVersion(reactRouterDomVersion);
1671
+ reactRouterDomPath = require.resolve("react-router-dom");
1672
+ } else {
1673
+ reactRouterDomPath = require.resolve("react-router-dom");
1674
+ }
1675
+ const packageJsonPath = findPackageJson(reactRouterDomPath);
1676
+ if (packageJsonPath) {
1677
+ const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, "utf-8"));
1678
+ majorVersion = checkVersion(packageJson.version);
1679
+ } else {
1680
+ console.warn("Unable to find package.json for react-router-dom");
1681
+ }
1682
+ if (majorVersion === 5) {
1683
+ bridgeRouterAlias = {
1684
+ "react-router-dom$": "@module-federation/bridge-react/dist/router-v5.es.js"
1685
+ };
1686
+ try {
1687
+ require.resolve("react-router-dom/index.js");
1688
+ } catch (error) {
1662
1689
  bridgeRouterAlias = {
1663
- "react-router-dom$": "@module-federation/bridge-react/dist/router-v5.es.js"
1690
+ ...bridgeRouterAlias,
1691
+ "react-router-dom/index.js": reactRouterDomPath
1664
1692
  };
1665
- try {
1666
- require.resolve("react-router-dom/index.js");
1667
- } catch (error) {
1668
- bridgeRouterAlias = {
1669
- ...bridgeRouterAlias,
1670
- "react-router-dom/index.js": reactRouterDomPath
1671
- };
1672
- }
1673
- } else if (majorVersion === 6) {
1693
+ }
1694
+ } else if (majorVersion === 6) {
1695
+ bridgeRouterAlias = {
1696
+ "react-router-dom$": "@module-federation/bridge-react/dist/router-v6.es.js"
1697
+ };
1698
+ try {
1699
+ require.resolve("react-router-dom/dist/index.js");
1700
+ } catch (error) {
1674
1701
  bridgeRouterAlias = {
1675
- "react-router-dom$": "@module-federation/bridge-react/dist/router-v6.es.js"
1702
+ ...bridgeRouterAlias,
1703
+ "react-router-dom/dist/index.js": reactRouterDomPath
1676
1704
  };
1677
- try {
1678
- require.resolve("react-router-dom/dist/index.js");
1679
- } catch (error) {
1680
- bridgeRouterAlias = {
1681
- ...bridgeRouterAlias,
1682
- "react-router-dom/dist/index.js": reactRouterDomPath
1683
- };
1684
- }
1685
- } else {
1686
- console.warn("react-router-dom version is not supported");
1687
1705
  }
1706
+ } else {
1707
+ console.warn("react-router-dom version is not supported");
1688
1708
  }
1689
1709
  console.log(
1690
1710
  "<<<<<<<<<<<<< bridgeRouterAlias >>>>>>>>>>>>>",
package/dist/index.es.js CHANGED
@@ -1603,6 +1603,29 @@ var semver = {
1603
1603
  rcompareIdentifiers: identifiers.rcompareIdentifiers
1604
1604
  };
1605
1605
  const semver$1 = /* @__PURE__ */ getDefaultExportFromCjs(semver);
1606
+ const checkVersion = (version) => {
1607
+ const versionMatch = version.match(/\d.*/);
1608
+ if (!versionMatch)
1609
+ return 0;
1610
+ const cleanVersion = versionMatch[0];
1611
+ if (semver$1.gte(cleanVersion, "5.0.0") && semver$1.lt(cleanVersion, "6.0.0")) {
1612
+ return 5;
1613
+ } else if (semver$1.gte(cleanVersion, "6.0.0")) {
1614
+ return 6;
1615
+ }
1616
+ return 0;
1617
+ };
1618
+ const findPackageJson = (startPath) => {
1619
+ let currentPath = startPath;
1620
+ while (currentPath !== path.parse(currentPath).root) {
1621
+ const packageJsonPath = path.join(currentPath, "package.json");
1622
+ if (fs.existsSync(packageJsonPath)) {
1623
+ return packageJsonPath;
1624
+ }
1625
+ currentPath = path.dirname(currentPath);
1626
+ }
1627
+ return null;
1628
+ };
1606
1629
  const getBridgeRouterAlias = (originalAlias) => {
1607
1630
  const userPackageJsonPath = path.resolve(process.cwd(), "package.json");
1608
1631
  let userDependencies = {};
@@ -1615,54 +1638,51 @@ const getBridgeRouterAlias = (originalAlias) => {
1615
1638
  ...userPackageJson.devDependencies
1616
1639
  };
1617
1640
  }
1618
- const hasBridgeReact = "@module-federation/bridge-react" in userDependencies;
1619
1641
  let bridgeRouterAlias = {};
1620
- if (hasBridgeReact) {
1621
- const reactRouterDomVersion = userDependencies["react-router-dom"];
1622
- let majorVersion = 0;
1623
- let reactRouterDomPath = "";
1624
- if (reactRouterDomVersion) {
1625
- majorVersion = semver$1.major(
1626
- semver$1.coerce(reactRouterDomVersion || "0.0.0") ?? "0.0.0"
1627
- );
1628
- reactRouterDomPath = require.resolve("react-router-dom");
1629
- } else {
1630
- reactRouterDomPath = require.resolve("react-router-dom");
1631
- const packageJsonPath = path.resolve(
1632
- reactRouterDomPath,
1633
- "../../package.json"
1634
- );
1635
- const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, "utf-8"));
1636
- majorVersion = parseInt(packageJson.version.split(".")[0]);
1637
- }
1638
- reactRouterDomPath = originalAlias || reactRouterDomPath;
1639
- if (majorVersion === 5) {
1642
+ let majorVersion = 0;
1643
+ let reactRouterDomPath = "";
1644
+ const reactRouterDomVersion = userDependencies["react-router-dom"];
1645
+ if (originalAlias) {
1646
+ reactRouterDomPath = originalAlias;
1647
+ } else if (reactRouterDomVersion) {
1648
+ majorVersion = checkVersion(reactRouterDomVersion);
1649
+ reactRouterDomPath = require.resolve("react-router-dom");
1650
+ } else {
1651
+ reactRouterDomPath = require.resolve("react-router-dom");
1652
+ }
1653
+ const packageJsonPath = findPackageJson(reactRouterDomPath);
1654
+ if (packageJsonPath) {
1655
+ const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, "utf-8"));
1656
+ majorVersion = checkVersion(packageJson.version);
1657
+ } else {
1658
+ console.warn("Unable to find package.json for react-router-dom");
1659
+ }
1660
+ if (majorVersion === 5) {
1661
+ bridgeRouterAlias = {
1662
+ "react-router-dom$": "@module-federation/bridge-react/dist/router-v5.es.js"
1663
+ };
1664
+ try {
1665
+ require.resolve("react-router-dom/index.js");
1666
+ } catch (error) {
1640
1667
  bridgeRouterAlias = {
1641
- "react-router-dom$": "@module-federation/bridge-react/dist/router-v5.es.js"
1668
+ ...bridgeRouterAlias,
1669
+ "react-router-dom/index.js": reactRouterDomPath
1642
1670
  };
1643
- try {
1644
- require.resolve("react-router-dom/index.js");
1645
- } catch (error) {
1646
- bridgeRouterAlias = {
1647
- ...bridgeRouterAlias,
1648
- "react-router-dom/index.js": reactRouterDomPath
1649
- };
1650
- }
1651
- } else if (majorVersion === 6) {
1671
+ }
1672
+ } else if (majorVersion === 6) {
1673
+ bridgeRouterAlias = {
1674
+ "react-router-dom$": "@module-federation/bridge-react/dist/router-v6.es.js"
1675
+ };
1676
+ try {
1677
+ require.resolve("react-router-dom/dist/index.js");
1678
+ } catch (error) {
1652
1679
  bridgeRouterAlias = {
1653
- "react-router-dom$": "@module-federation/bridge-react/dist/router-v6.es.js"
1680
+ ...bridgeRouterAlias,
1681
+ "react-router-dom/dist/index.js": reactRouterDomPath
1654
1682
  };
1655
- try {
1656
- require.resolve("react-router-dom/dist/index.js");
1657
- } catch (error) {
1658
- bridgeRouterAlias = {
1659
- ...bridgeRouterAlias,
1660
- "react-router-dom/dist/index.js": reactRouterDomPath
1661
- };
1662
- }
1663
- } else {
1664
- console.warn("react-router-dom version is not supported");
1665
1683
  }
1684
+ } else {
1685
+ console.warn("react-router-dom version is not supported");
1666
1686
  }
1667
1687
  console.log(
1668
1688
  "<<<<<<<<<<<<< bridgeRouterAlias >>>>>>>>>>>>>",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@module-federation/bridge-react-webpack-plugin",
3
- "version": "0.5.2",
3
+ "version": "0.6.0",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -19,7 +19,7 @@
19
19
  "dependencies": {
20
20
  "semver": "7.6.3",
21
21
  "@types/semver": "7.5.8",
22
- "@module-federation/sdk": "0.5.2"
22
+ "@module-federation/sdk": "0.6.0"
23
23
  },
24
24
  "devDependencies": {
25
25
  "typescript": "^5.2.2",
package/project.json CHANGED
@@ -11,6 +11,18 @@
11
11
  "npm run build --prefix packages/bridge/bridge-react-webpack-plugin"
12
12
  ]
13
13
  }
14
+ },
15
+ "test": {
16
+ "executor": "nx:run-commands",
17
+ "options": {
18
+ "parallel": false,
19
+ "commands": [
20
+ {
21
+ "command": "vitest run -c packages/bridge/bridge-react-webpack-plugin/vitest.config.ts",
22
+ "forwardAllArgs": false
23
+ }
24
+ ]
25
+ }
14
26
  }
15
27
  },
16
28
  "tags": ["type:pkg"]
package/src/utis.ts CHANGED
@@ -2,6 +2,34 @@ import fs from 'node:fs';
2
2
  import path from 'node:path';
3
3
  import semver from 'semver';
4
4
 
5
+ export const checkVersion = (version: string) => {
6
+ // Extract the version number starting from the first digit
7
+ const versionMatch = version.match(/\d.*/);
8
+ if (!versionMatch) return 0;
9
+
10
+ const cleanVersion = versionMatch[0];
11
+
12
+ if (semver.gte(cleanVersion, '5.0.0') && semver.lt(cleanVersion, '6.0.0')) {
13
+ return 5;
14
+ } else if (semver.gte(cleanVersion, '6.0.0')) {
15
+ return 6;
16
+ }
17
+
18
+ return 0;
19
+ };
20
+
21
+ export const findPackageJson = (startPath: string): string | null => {
22
+ let currentPath = startPath;
23
+ while (currentPath !== path.parse(currentPath).root) {
24
+ const packageJsonPath = path.join(currentPath, 'package.json');
25
+ if (fs.existsSync(packageJsonPath)) {
26
+ return packageJsonPath;
27
+ }
28
+ currentPath = path.dirname(currentPath);
29
+ }
30
+ return null;
31
+ };
32
+
5
33
  export const getBridgeRouterAlias = (
6
34
  originalAlias: string,
7
35
  ): Record<string, string> => {
@@ -18,69 +46,63 @@ export const getBridgeRouterAlias = (
18
46
  };
19
47
  }
20
48
 
21
- const hasBridgeReact = '@module-federation/bridge-react' in userDependencies;
22
-
23
49
  let bridgeRouterAlias = {};
24
- // user install @module-federation/bridge-react package or set bridgeReactRouterDomAlias
25
- if (hasBridgeReact) {
26
- // user install react-router-dom package
27
- const reactRouterDomVersion = userDependencies['react-router-dom'];
28
- let majorVersion = 0;
29
- let reactRouterDomPath = '';
50
+ let majorVersion = 0;
51
+ let reactRouterDomPath = '';
30
52
 
31
- // if react-router-dom version is set, use the version in package.json
32
- if (reactRouterDomVersion) {
33
- majorVersion = semver.major(
34
- semver.coerce(reactRouterDomVersion || '0.0.0') ?? '0.0.0',
35
- );
36
- reactRouterDomPath = require.resolve('react-router-dom');
37
- } else {
38
- // if react-router-dom version is not set, reslove react-router-dom to get the version
39
- reactRouterDomPath = require.resolve('react-router-dom');
40
- const packageJsonPath = path.resolve(
41
- reactRouterDomPath,
42
- '../../package.json',
43
- );
44
- const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8'));
45
- majorVersion = parseInt(packageJson.version.split('.')[0]);
46
- }
53
+ const reactRouterDomVersion = userDependencies['react-router-dom'];
54
+
55
+ if (originalAlias) {
56
+ reactRouterDomPath = originalAlias;
57
+ } else if (reactRouterDomVersion) {
58
+ majorVersion = checkVersion(reactRouterDomVersion);
59
+ reactRouterDomPath = require.resolve('react-router-dom');
60
+ } else {
61
+ reactRouterDomPath = require.resolve('react-router-dom');
62
+ }
47
63
 
48
- // if react-router-dom path has set alias by user, use the originalAlias
49
- reactRouterDomPath = originalAlias || reactRouterDomPath;
64
+ const packageJsonPath = findPackageJson(reactRouterDomPath);
50
65
 
51
- if (majorVersion === 5) {
66
+ if (packageJsonPath) {
67
+ const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8'));
68
+ majorVersion = checkVersion(packageJson.version);
69
+ } else {
70
+ console.warn('Unable to find package.json for react-router-dom');
71
+ }
72
+
73
+ if (majorVersion === 5) {
74
+ bridgeRouterAlias = {
75
+ 'react-router-dom$':
76
+ '@module-federation/bridge-react/dist/router-v5.es.js',
77
+ };
78
+ try {
79
+ require.resolve('react-router-dom/index.js');
80
+ } catch (error) {
81
+ // if react-router-dom/index.js cannot be resolved, set the alias to origin reactRouterDomPath
52
82
  bridgeRouterAlias = {
53
- 'react-router-dom$':
54
- '@module-federation/bridge-react/dist/router-v5.es.js',
83
+ ...bridgeRouterAlias,
84
+ 'react-router-dom/index.js': reactRouterDomPath,
55
85
  };
56
- try {
57
- require.resolve('react-router-dom/index.js');
58
- } catch (error) {
59
- // if react-router-dom/index.js cannot be resolved, set the alias to origin reactRouterDomPath
60
- bridgeRouterAlias = {
61
- ...bridgeRouterAlias,
62
- 'react-router-dom/index.js': reactRouterDomPath,
63
- };
64
- }
65
- } else if (majorVersion === 6) {
86
+ }
87
+ } else if (majorVersion === 6) {
88
+ bridgeRouterAlias = {
89
+ 'react-router-dom$':
90
+ '@module-federation/bridge-react/dist/router-v6.es.js',
91
+ };
92
+
93
+ try {
94
+ require.resolve('react-router-dom/dist/index.js');
95
+ } catch (error) {
96
+ // if react-router-dom/dist/index.js cannot be resolved, set the alias to origin reactRouterDomPath
66
97
  bridgeRouterAlias = {
67
- 'react-router-dom$':
68
- '@module-federation/bridge-react/dist/router-v6.es.js',
98
+ ...bridgeRouterAlias,
99
+ 'react-router-dom/dist/index.js': reactRouterDomPath,
69
100
  };
70
-
71
- try {
72
- require.resolve('react-router-dom/dist/index.js');
73
- } catch (error) {
74
- // if react-router-dom/dist/index.js cannot be resolved, set the alias to origin reactRouterDomPath
75
- bridgeRouterAlias = {
76
- ...bridgeRouterAlias,
77
- 'react-router-dom/dist/index.js': reactRouterDomPath,
78
- };
79
- }
80
- } else {
81
- console.warn('react-router-dom version is not supported');
82
101
  }
102
+ } else {
103
+ console.warn('react-router-dom version is not supported');
83
104
  }
105
+
84
106
  console.log(
85
107
  '<<<<<<<<<<<<< bridgeRouterAlias >>>>>>>>>>>>>',
86
108
  bridgeRouterAlias,
@@ -0,0 +1,22 @@
1
+ import { defineConfig } from 'vitest/config';
2
+ import { nxViteTsPaths } from '@nx/vite/plugins/nx-tsconfig-paths.plugin';
3
+ import path from 'path';
4
+ export default defineConfig({
5
+ define: {
6
+ __DEV__: true,
7
+ __TEST__: true,
8
+ __BROWSER__: false,
9
+ __VERSION__: '"unknown"',
10
+ __APP_VERSION__: '"0.0.0"',
11
+ },
12
+ plugins: [nxViteTsPaths()],
13
+ test: {
14
+ environment: 'jsdom',
15
+ include: [
16
+ path.resolve(__dirname, '__tests__/*.spec.ts'),
17
+ path.resolve(__dirname, '__tests__/*.spec.tsx'),
18
+ ],
19
+ globals: true,
20
+ testTimeout: 10000,
21
+ },
22
+ });