@module-federation/bridge-react-webpack-plugin 0.0.0-next-20240826075118 → 0.0.0-next-20240826081819

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,17 +1,11 @@
1
1
  # @module-federation/bridge-react-webpack-plugin
2
2
 
3
- ## 0.0.0-next-20240826075118
4
-
5
- ### Patch Changes
6
-
7
- - @module-federation/sdk@0.0.0-next-20240826075118
8
-
9
- ## 0.5.2
3
+ ## 0.0.0-next-20240826081819
10
4
 
11
5
  ### Patch Changes
12
6
 
13
7
  - Updated dependencies [b90fa7d]
14
- - @module-federation/sdk@0.5.2
8
+ - @module-federation/sdk@0.0.0-next-20240826081819
15
9
 
16
10
  ## 0.5.1
17
11
 
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 = {};
@@ -1643,21 +1666,21 @@ const getBridgeRouterAlias = (originalAlias) => {
1643
1666
  const reactRouterDomVersion = userDependencies["react-router-dom"];
1644
1667
  let majorVersion = 0;
1645
1668
  let reactRouterDomPath = "";
1646
- if (reactRouterDomVersion) {
1647
- majorVersion = semver$1.major(
1648
- semver$1.coerce(reactRouterDomVersion || "0.0.0") ?? "0.0.0"
1649
- );
1669
+ if (originalAlias) {
1670
+ reactRouterDomPath = originalAlias;
1671
+ } else if (reactRouterDomVersion) {
1672
+ majorVersion = checkVersion(reactRouterDomVersion);
1650
1673
  reactRouterDomPath = require.resolve("react-router-dom");
1651
1674
  } else {
1652
1675
  reactRouterDomPath = require.resolve("react-router-dom");
1653
- const packageJsonPath = path.resolve(
1654
- reactRouterDomPath,
1655
- "../../package.json"
1656
- );
1676
+ }
1677
+ const packageJsonPath = findPackageJson(reactRouterDomPath);
1678
+ if (packageJsonPath) {
1657
1679
  const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, "utf-8"));
1658
- majorVersion = parseInt(packageJson.version.split(".")[0]);
1680
+ majorVersion = checkVersion(packageJson.version);
1681
+ } else {
1682
+ console.warn("Unable to find package.json for react-router-dom");
1659
1683
  }
1660
- reactRouterDomPath = originalAlias || reactRouterDomPath;
1661
1684
  if (majorVersion === 5) {
1662
1685
  bridgeRouterAlias = {
1663
1686
  "react-router-dom$": "@module-federation/bridge-react/dist/router-v5.es.js"
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 = {};
@@ -1621,21 +1644,21 @@ const getBridgeRouterAlias = (originalAlias) => {
1621
1644
  const reactRouterDomVersion = userDependencies["react-router-dom"];
1622
1645
  let majorVersion = 0;
1623
1646
  let reactRouterDomPath = "";
1624
- if (reactRouterDomVersion) {
1625
- majorVersion = semver$1.major(
1626
- semver$1.coerce(reactRouterDomVersion || "0.0.0") ?? "0.0.0"
1627
- );
1647
+ if (originalAlias) {
1648
+ reactRouterDomPath = originalAlias;
1649
+ } else if (reactRouterDomVersion) {
1650
+ majorVersion = checkVersion(reactRouterDomVersion);
1628
1651
  reactRouterDomPath = require.resolve("react-router-dom");
1629
1652
  } else {
1630
1653
  reactRouterDomPath = require.resolve("react-router-dom");
1631
- const packageJsonPath = path.resolve(
1632
- reactRouterDomPath,
1633
- "../../package.json"
1634
- );
1654
+ }
1655
+ const packageJsonPath = findPackageJson(reactRouterDomPath);
1656
+ if (packageJsonPath) {
1635
1657
  const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, "utf-8"));
1636
- majorVersion = parseInt(packageJson.version.split(".")[0]);
1658
+ majorVersion = checkVersion(packageJson.version);
1659
+ } else {
1660
+ console.warn("Unable to find package.json for react-router-dom");
1637
1661
  }
1638
- reactRouterDomPath = originalAlias || reactRouterDomPath;
1639
1662
  if (majorVersion === 5) {
1640
1663
  bridgeRouterAlias = {
1641
1664
  "react-router-dom$": "@module-federation/bridge-react/dist/router-v5.es.js"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@module-federation/bridge-react-webpack-plugin",
3
- "version": "0.0.0-next-20240826075118",
3
+ "version": "0.0.0-next-20240826081819",
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.0.0-next-20240826075118"
22
+ "@module-federation/sdk": "0.0.0-next-20240826081819"
23
23
  },
24
24
  "devDependencies": {
25
25
  "typescript": "^5.2.2",
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
+ 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
+ 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> => {
@@ -28,25 +56,22 @@ export const getBridgeRouterAlias = (
28
56
  let majorVersion = 0;
29
57
  let reactRouterDomPath = '';
30
58
 
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
- );
59
+ if (originalAlias) {
60
+ reactRouterDomPath = originalAlias;
61
+ } else if (reactRouterDomVersion) {
62
+ majorVersion = checkVersion(reactRouterDomVersion);
36
63
  reactRouterDomPath = require.resolve('react-router-dom');
37
64
  } else {
38
- // if react-router-dom version is not set, reslove react-router-dom to get the version
39
65
  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
66
  }
47
67
 
48
- // if react-router-dom path has set alias by user, use the originalAlias
49
- reactRouterDomPath = originalAlias || reactRouterDomPath;
68
+ const packageJsonPath = findPackageJson(reactRouterDomPath);
69
+ if (packageJsonPath) {
70
+ const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8'));
71
+ majorVersion = checkVersion(packageJson.version);
72
+ } else {
73
+ console.warn('Unable to find package.json for react-router-dom');
74
+ }
50
75
 
51
76
  if (majorVersion === 5) {
52
77
  bridgeRouterAlias = {