Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@module-federation/bridge-react-webpack-plugin

Package Overview
Dependencies
Maintainers
8
Versions
256
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@module-federation/bridge-react-webpack-plugin - npm Package Compare versions

Comparing version 0.5.2 to 0.6.0

__tests__/mockRouterDir/router-v5/react-router-dom/package.json

7

CHANGELOG.md
# @module-federation/bridge-react-webpack-plugin
## 0.6.0
### Patch Changes
- Updated dependencies [1d9bb77]
- @module-federation/sdk@0.6.0
## 0.5.2

@@ -4,0 +11,0 @@

104

dist/index.cjs.js

@@ -1628,2 +1628,25 @@ "use strict";

const semver$1 = /* @__PURE__ */ getDefaultExportFromCjs(semver);
const checkVersion = (version) => {
const versionMatch = version.match(/\d.*/);
if (!versionMatch)
return 0;
const cleanVersion = versionMatch[0];
if (semver$1.gte(cleanVersion, "5.0.0") && semver$1.lt(cleanVersion, "6.0.0")) {
return 5;
} else if (semver$1.gte(cleanVersion, "6.0.0")) {
return 6;
}
return 0;
};
const findPackageJson = (startPath) => {
let currentPath = startPath;
while (currentPath !== path.parse(currentPath).root) {
const packageJsonPath = path.join(currentPath, "package.json");
if (fs.existsSync(packageJsonPath)) {
return packageJsonPath;
}
currentPath = path.dirname(currentPath);
}
return null;
};
const getBridgeRouterAlias = (originalAlias) => {

@@ -1641,50 +1664,47 @@ const userPackageJsonPath = path.resolve(process.cwd(), "package.json");

}
const hasBridgeReact = "@module-federation/bridge-react" in userDependencies;
let bridgeRouterAlias = {};
if (hasBridgeReact) {
const reactRouterDomVersion = userDependencies["react-router-dom"];
let majorVersion = 0;
let reactRouterDomPath = "";
if (reactRouterDomVersion) {
majorVersion = semver$1.major(
semver$1.coerce(reactRouterDomVersion || "0.0.0") ?? "0.0.0"
);
reactRouterDomPath = require.resolve("react-router-dom");
} else {
reactRouterDomPath = require.resolve("react-router-dom");
const packageJsonPath = path.resolve(
reactRouterDomPath,
"../../package.json"
);
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, "utf-8"));
majorVersion = parseInt(packageJson.version.split(".")[0]);
}
reactRouterDomPath = originalAlias || reactRouterDomPath;
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 +1711,0 @@ console.log(

@@ -1606,2 +1606,25 @@ var __defProp = Object.defineProperty;

const semver$1 = /* @__PURE__ */ getDefaultExportFromCjs(semver);
const checkVersion = (version) => {
const versionMatch = version.match(/\d.*/);
if (!versionMatch)
return 0;
const cleanVersion = versionMatch[0];
if (semver$1.gte(cleanVersion, "5.0.0") && semver$1.lt(cleanVersion, "6.0.0")) {
return 5;
} else if (semver$1.gte(cleanVersion, "6.0.0")) {
return 6;
}
return 0;
};
const findPackageJson = (startPath) => {
let currentPath = startPath;
while (currentPath !== path.parse(currentPath).root) {
const packageJsonPath = path.join(currentPath, "package.json");
if (fs.existsSync(packageJsonPath)) {
return packageJsonPath;
}
currentPath = path.dirname(currentPath);
}
return null;
};
const getBridgeRouterAlias = (originalAlias) => {

@@ -1619,50 +1642,47 @@ const userPackageJsonPath = path.resolve(process.cwd(), "package.json");

}
const hasBridgeReact = "@module-federation/bridge-react" in userDependencies;
let bridgeRouterAlias = {};
if (hasBridgeReact) {
const reactRouterDomVersion = userDependencies["react-router-dom"];
let majorVersion = 0;
let reactRouterDomPath = "";
if (reactRouterDomVersion) {
majorVersion = semver$1.major(
semver$1.coerce(reactRouterDomVersion || "0.0.0") ?? "0.0.0"
);
reactRouterDomPath = require.resolve("react-router-dom");
} else {
reactRouterDomPath = require.resolve("react-router-dom");
const packageJsonPath = path.resolve(
reactRouterDomPath,
"../../package.json"
);
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, "utf-8"));
majorVersion = parseInt(packageJson.version.split(".")[0]);
}
reactRouterDomPath = originalAlias || reactRouterDomPath;
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");
}

@@ -1669,0 +1689,0 @@ console.log(

{
"name": "@module-federation/bridge-react-webpack-plugin",
"version": "0.5.2",
"version": "0.6.0",
"publishConfig": {

@@ -22,3 +22,3 @@ "access": "public"

"@types/semver": "7.5.8",
"@module-federation/sdk": "0.5.2"
"@module-federation/sdk": "0.6.0"
},

@@ -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 @@ },

@@ -5,2 +5,30 @@ import fs from 'node:fs';

export const checkVersion = (version: string) => {
// Extract the version number starting from the first digit
const versionMatch = version.match(/\d.*/);
if (!versionMatch) return 0;
const cleanVersion = versionMatch[0];
if (semver.gte(cleanVersion, '5.0.0') && semver.lt(cleanVersion, '6.0.0')) {
return 5;
} else if (semver.gte(cleanVersion, '6.0.0')) {
return 6;
}
return 0;
};
export const findPackageJson = (startPath: string): string | null => {
let currentPath = startPath;
while (currentPath !== path.parse(currentPath).root) {
const packageJsonPath = path.join(currentPath, 'package.json');
if (fs.existsSync(packageJsonPath)) {
return packageJsonPath;
}
currentPath = path.dirname(currentPath);
}
return null;
};
export const getBridgeRouterAlias = (

@@ -22,65 +50,59 @@ originalAlias: string,

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 react-router-dom version is set, use the version in package.json
if (reactRouterDomVersion) {
majorVersion = semver.major(
semver.coerce(reactRouterDomVersion || '0.0.0') ?? '0.0.0',
);
reactRouterDomPath = require.resolve('react-router-dom');
} else {
// if react-router-dom version is not set, reslove react-router-dom to get the version
reactRouterDomPath = require.resolve('react-router-dom');
const packageJsonPath = path.resolve(
reactRouterDomPath,
'../../package.json',
);
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8'));
majorVersion = parseInt(packageJson.version.split('.')[0]);
}
const reactRouterDomVersion = userDependencies['react-router-dom'];
// if react-router-dom path has set alias by user, use the originalAlias
reactRouterDomPath = originalAlias || reactRouterDomPath;
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(

@@ -87,0 +109,0 @@ '<<<<<<<<<<<<< bridgeRouterAlias >>>>>>>>>>>>>',

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc