@module-federation/bridge-react-webpack-plugin
Advanced tools
Comparing version 0.0.0-next-20240826081819 to 0.0.0-next-20240827062238
# @module-federation/bridge-react-webpack-plugin | ||
## 0.0.0-next-20240826081819 | ||
## 0.0.0-next-20240827062238 | ||
### Patch Changes | ||
- Updated dependencies [1d9bb77] | ||
- @module-federation/sdk@0.0.0-next-20240827062238 | ||
## 0.5.2 | ||
### Patch Changes | ||
- Updated dependencies [b90fa7d] | ||
- @module-federation/sdk@0.0.0-next-20240826081819 | ||
- @module-federation/sdk@0.5.2 | ||
@@ -10,0 +17,0 @@ ## 0.5.1 |
@@ -1663,50 +1663,47 @@ "use strict"; | ||
} | ||
const hasBridgeReact = "@module-federation/bridge-react" in userDependencies; | ||
let bridgeRouterAlias = {}; | ||
if (hasBridgeReact) { | ||
const reactRouterDomVersion = userDependencies["react-router-dom"]; | ||
let majorVersion = 0; | ||
let reactRouterDomPath = ""; | ||
if (originalAlias) { | ||
reactRouterDomPath = originalAlias; | ||
} else if (reactRouterDomVersion) { | ||
majorVersion = checkVersion(reactRouterDomVersion); | ||
reactRouterDomPath = require.resolve("react-router-dom"); | ||
} else { | ||
reactRouterDomPath = require.resolve("react-router-dom"); | ||
} | ||
const packageJsonPath = findPackageJson(reactRouterDomPath); | ||
if (packageJsonPath) { | ||
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, "utf-8")); | ||
majorVersion = checkVersion(packageJson.version); | ||
} else { | ||
console.warn("Unable to find package.json for react-router-dom"); | ||
} | ||
if (majorVersion === 5) { | ||
let majorVersion = 0; | ||
let reactRouterDomPath = ""; | ||
const reactRouterDomVersion = userDependencies["react-router-dom"]; | ||
if (originalAlias) { | ||
reactRouterDomPath = originalAlias; | ||
} else if (reactRouterDomVersion) { | ||
majorVersion = checkVersion(reactRouterDomVersion); | ||
reactRouterDomPath = require.resolve("react-router-dom"); | ||
} else { | ||
reactRouterDomPath = require.resolve("react-router-dom"); | ||
} | ||
const packageJsonPath = findPackageJson(reactRouterDomPath); | ||
if (packageJsonPath) { | ||
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, "utf-8")); | ||
majorVersion = checkVersion(packageJson.version); | ||
} else { | ||
console.warn("Unable to find package.json for react-router-dom"); | ||
} | ||
if (majorVersion === 5) { | ||
bridgeRouterAlias = { | ||
"react-router-dom$": "@module-federation/bridge-react/dist/router-v5.es.js" | ||
}; | ||
try { | ||
require.resolve("react-router-dom/index.js"); | ||
} catch (error) { | ||
bridgeRouterAlias = { | ||
"react-router-dom$": "@module-federation/bridge-react/dist/router-v5.es.js" | ||
...bridgeRouterAlias, | ||
"react-router-dom/index.js": reactRouterDomPath | ||
}; | ||
try { | ||
require.resolve("react-router-dom/index.js"); | ||
} catch (error) { | ||
bridgeRouterAlias = { | ||
...bridgeRouterAlias, | ||
"react-router-dom/index.js": reactRouterDomPath | ||
}; | ||
} | ||
} else if (majorVersion === 6) { | ||
} | ||
} else if (majorVersion === 6) { | ||
bridgeRouterAlias = { | ||
"react-router-dom$": "@module-federation/bridge-react/dist/router-v6.es.js" | ||
}; | ||
try { | ||
require.resolve("react-router-dom/dist/index.js"); | ||
} catch (error) { | ||
bridgeRouterAlias = { | ||
"react-router-dom$": "@module-federation/bridge-react/dist/router-v6.es.js" | ||
...bridgeRouterAlias, | ||
"react-router-dom/dist/index.js": reactRouterDomPath | ||
}; | ||
try { | ||
require.resolve("react-router-dom/dist/index.js"); | ||
} catch (error) { | ||
bridgeRouterAlias = { | ||
...bridgeRouterAlias, | ||
"react-router-dom/dist/index.js": reactRouterDomPath | ||
}; | ||
} | ||
} else { | ||
console.warn("react-router-dom version is not supported"); | ||
} | ||
} else { | ||
console.warn("react-router-dom version is not supported"); | ||
} | ||
@@ -1713,0 +1710,0 @@ console.log( |
@@ -1641,50 +1641,47 @@ var __defProp = Object.defineProperty; | ||
} | ||
const hasBridgeReact = "@module-federation/bridge-react" in userDependencies; | ||
let bridgeRouterAlias = {}; | ||
if (hasBridgeReact) { | ||
const reactRouterDomVersion = userDependencies["react-router-dom"]; | ||
let majorVersion = 0; | ||
let reactRouterDomPath = ""; | ||
if (originalAlias) { | ||
reactRouterDomPath = originalAlias; | ||
} else if (reactRouterDomVersion) { | ||
majorVersion = checkVersion(reactRouterDomVersion); | ||
reactRouterDomPath = require.resolve("react-router-dom"); | ||
} else { | ||
reactRouterDomPath = require.resolve("react-router-dom"); | ||
} | ||
const packageJsonPath = findPackageJson(reactRouterDomPath); | ||
if (packageJsonPath) { | ||
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, "utf-8")); | ||
majorVersion = checkVersion(packageJson.version); | ||
} else { | ||
console.warn("Unable to find package.json for react-router-dom"); | ||
} | ||
if (majorVersion === 5) { | ||
let majorVersion = 0; | ||
let reactRouterDomPath = ""; | ||
const reactRouterDomVersion = userDependencies["react-router-dom"]; | ||
if (originalAlias) { | ||
reactRouterDomPath = originalAlias; | ||
} else if (reactRouterDomVersion) { | ||
majorVersion = checkVersion(reactRouterDomVersion); | ||
reactRouterDomPath = require.resolve("react-router-dom"); | ||
} else { | ||
reactRouterDomPath = require.resolve("react-router-dom"); | ||
} | ||
const packageJsonPath = findPackageJson(reactRouterDomPath); | ||
if (packageJsonPath) { | ||
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, "utf-8")); | ||
majorVersion = checkVersion(packageJson.version); | ||
} else { | ||
console.warn("Unable to find package.json for react-router-dom"); | ||
} | ||
if (majorVersion === 5) { | ||
bridgeRouterAlias = { | ||
"react-router-dom$": "@module-federation/bridge-react/dist/router-v5.es.js" | ||
}; | ||
try { | ||
require.resolve("react-router-dom/index.js"); | ||
} catch (error) { | ||
bridgeRouterAlias = { | ||
"react-router-dom$": "@module-federation/bridge-react/dist/router-v5.es.js" | ||
...bridgeRouterAlias, | ||
"react-router-dom/index.js": reactRouterDomPath | ||
}; | ||
try { | ||
require.resolve("react-router-dom/index.js"); | ||
} catch (error) { | ||
bridgeRouterAlias = { | ||
...bridgeRouterAlias, | ||
"react-router-dom/index.js": reactRouterDomPath | ||
}; | ||
} | ||
} else if (majorVersion === 6) { | ||
} | ||
} else if (majorVersion === 6) { | ||
bridgeRouterAlias = { | ||
"react-router-dom$": "@module-federation/bridge-react/dist/router-v6.es.js" | ||
}; | ||
try { | ||
require.resolve("react-router-dom/dist/index.js"); | ||
} catch (error) { | ||
bridgeRouterAlias = { | ||
"react-router-dom$": "@module-federation/bridge-react/dist/router-v6.es.js" | ||
...bridgeRouterAlias, | ||
"react-router-dom/dist/index.js": reactRouterDomPath | ||
}; | ||
try { | ||
require.resolve("react-router-dom/dist/index.js"); | ||
} catch (error) { | ||
bridgeRouterAlias = { | ||
...bridgeRouterAlias, | ||
"react-router-dom/dist/index.js": reactRouterDomPath | ||
}; | ||
} | ||
} else { | ||
console.warn("react-router-dom version is not supported"); | ||
} | ||
} else { | ||
console.warn("react-router-dom version is not supported"); | ||
} | ||
@@ -1691,0 +1688,0 @@ console.log( |
{ | ||
"name": "@module-federation/bridge-react-webpack-plugin", | ||
"version": "0.0.0-next-20240826081819", | ||
"version": "0.0.0-next-20240827062238", | ||
"publishConfig": { | ||
@@ -22,3 +22,3 @@ "access": "public" | ||
"@types/semver": "7.5.8", | ||
"@module-federation/sdk": "0.0.0-next-20240826081819" | ||
"@module-federation/sdk": "0.0.0-next-20240827062238" | ||
}, | ||
@@ -25,0 +25,0 @@ "devDependencies": { |
@@ -14,2 +14,14 @@ { | ||
} | ||
}, | ||
"test": { | ||
"executor": "nx:run-commands", | ||
"options": { | ||
"parallel": false, | ||
"commands": [ | ||
{ | ||
"command": "vitest run -c packages/bridge/bridge-react-webpack-plugin/vitest.config.ts", | ||
"forwardAllArgs": false | ||
} | ||
] | ||
} | ||
} | ||
@@ -16,0 +28,0 @@ }, |
101
src/utis.ts
@@ -5,3 +5,3 @@ import fs from 'node:fs'; | ||
const checkVersion = (version: string) => { | ||
export const checkVersion = (version: string) => { | ||
// Extract the version number starting from the first digit | ||
@@ -22,3 +22,3 @@ const versionMatch = version.match(/\d.*/); | ||
const findPackageJson = (startPath: string): string | null => { | ||
export const findPackageJson = (startPath: string): string | null => { | ||
let currentPath = startPath; | ||
@@ -51,62 +51,59 @@ while (currentPath !== path.parse(currentPath).root) { | ||
const hasBridgeReact = '@module-federation/bridge-react' in userDependencies; | ||
let bridgeRouterAlias = {}; | ||
// user install @module-federation/bridge-react package or set bridgeReactRouterDomAlias | ||
if (hasBridgeReact) { | ||
// user install react-router-dom package | ||
const reactRouterDomVersion = userDependencies['react-router-dom']; | ||
let majorVersion = 0; | ||
let reactRouterDomPath = ''; | ||
let majorVersion = 0; | ||
let reactRouterDomPath = ''; | ||
if (originalAlias) { | ||
reactRouterDomPath = originalAlias; | ||
} else if (reactRouterDomVersion) { | ||
majorVersion = checkVersion(reactRouterDomVersion); | ||
reactRouterDomPath = require.resolve('react-router-dom'); | ||
} else { | ||
reactRouterDomPath = require.resolve('react-router-dom'); | ||
} | ||
const reactRouterDomVersion = userDependencies['react-router-dom']; | ||
const packageJsonPath = findPackageJson(reactRouterDomPath); | ||
if (packageJsonPath) { | ||
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8')); | ||
majorVersion = checkVersion(packageJson.version); | ||
} else { | ||
console.warn('Unable to find package.json for react-router-dom'); | ||
} | ||
if (originalAlias) { | ||
reactRouterDomPath = originalAlias; | ||
} else if (reactRouterDomVersion) { | ||
majorVersion = checkVersion(reactRouterDomVersion); | ||
reactRouterDomPath = require.resolve('react-router-dom'); | ||
} else { | ||
reactRouterDomPath = require.resolve('react-router-dom'); | ||
} | ||
if (majorVersion === 5) { | ||
const packageJsonPath = findPackageJson(reactRouterDomPath); | ||
if (packageJsonPath) { | ||
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8')); | ||
majorVersion = checkVersion(packageJson.version); | ||
} else { | ||
console.warn('Unable to find package.json for react-router-dom'); | ||
} | ||
if (majorVersion === 5) { | ||
bridgeRouterAlias = { | ||
'react-router-dom$': | ||
'@module-federation/bridge-react/dist/router-v5.es.js', | ||
}; | ||
try { | ||
require.resolve('react-router-dom/index.js'); | ||
} catch (error) { | ||
// if react-router-dom/index.js cannot be resolved, set the alias to origin reactRouterDomPath | ||
bridgeRouterAlias = { | ||
'react-router-dom$': | ||
'@module-federation/bridge-react/dist/router-v5.es.js', | ||
...bridgeRouterAlias, | ||
'react-router-dom/index.js': reactRouterDomPath, | ||
}; | ||
try { | ||
require.resolve('react-router-dom/index.js'); | ||
} catch (error) { | ||
// if react-router-dom/index.js cannot be resolved, set the alias to origin reactRouterDomPath | ||
bridgeRouterAlias = { | ||
...bridgeRouterAlias, | ||
'react-router-dom/index.js': reactRouterDomPath, | ||
}; | ||
} | ||
} else if (majorVersion === 6) { | ||
} | ||
} else if (majorVersion === 6) { | ||
bridgeRouterAlias = { | ||
'react-router-dom$': | ||
'@module-federation/bridge-react/dist/router-v6.es.js', | ||
}; | ||
try { | ||
require.resolve('react-router-dom/dist/index.js'); | ||
} catch (error) { | ||
// if react-router-dom/dist/index.js cannot be resolved, set the alias to origin reactRouterDomPath | ||
bridgeRouterAlias = { | ||
'react-router-dom$': | ||
'@module-federation/bridge-react/dist/router-v6.es.js', | ||
...bridgeRouterAlias, | ||
'react-router-dom/dist/index.js': reactRouterDomPath, | ||
}; | ||
try { | ||
require.resolve('react-router-dom/dist/index.js'); | ||
} catch (error) { | ||
// if react-router-dom/dist/index.js cannot be resolved, set the alias to origin reactRouterDomPath | ||
bridgeRouterAlias = { | ||
...bridgeRouterAlias, | ||
'react-router-dom/dist/index.js': reactRouterDomPath, | ||
}; | ||
} | ||
} else { | ||
console.warn('react-router-dom version is not supported'); | ||
} | ||
} else { | ||
console.warn('react-router-dom version is not supported'); | ||
} | ||
console.log( | ||
@@ -113,0 +110,0 @@ '<<<<<<<<<<<<< bridgeRouterAlias >>>>>>>>>>>>>', |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
130658
17
3849
+ Added@module-federation/sdk@0.0.0-next-20240827062238(transitive)
- Removed@module-federation/sdk@0.0.0-next-20240826081819(transitive)