
Security News
Meet Socket at Black Hat and DEF CON 2025 in Las Vegas
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
check-dependency-version-consistency
Advanced tools
Ensures dependencies are on consistent versions across a monorepo.
This CLI tool enforces the following aspects of consistency across a monorepo with npm / pnpm / Yarn workspaces:
eslint
should specify the same version for it.package1
in a workspace depends on another package package2
in the workspace, package1
should request the current version of package2
.To install:
yarn add --dev check-dependency-version-consistency
To run, use this command and optionally pass the path to the workspace root (where the package.json
file containing workspaces
or pnpm-workspace.yaml
is located):
yarn check-dependency-version-consistency .
If there are no inconsistencies, the program will exit with success.
If there are any inconsistencies, the program will exit with failure and output the mismatching versions.
package.json
(workspace root):
{
"workspaces": ["*"],
"scripts": {
"lint": "npm-run-all --continue-on-error --aggregate-output --parallel \"lint:*\"",
"lint:dependency-versions": "check-dependency-version-consistency .",
"lint:dependency-versions:fix": "npm-run-all \"lint:dependency-versions --fix\""
},
"devDependencies": {
"check-dependency-version-consistency": "*",
"npm-run-all": "*"
}
}
package1/package.json
:
{
"name": "package1",
"devDependencies": {
"eslint": "^8.0.0"
},
"dependencies": {
"package2": "^0.0.0"
}
}
package2/package.json
:
{
"name": "package2",
"version": "1.0.0",
"devDependencies": {
"eslint": "^7.0.0"
}
}
package3/package.json
:
{
"name": "package3",
"devDependencies": {
"eslint": "^7.0.0"
}
}
Output:
Found 2 dependencies with mismatching versions across the workspace. Fix with `--fix`.
โโโโโโโโโโคโโโโโโโโโคโโโโโโโโโโโโโโโโโโโโโ
โ eslint โ Usages โ Packages โ
โโโโโโโโโโผโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโข
โ ^8.0.0 โ 1 โ package1 โ
โโโโโโโโโโผโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโข
โ ^7.0.0 โ 2 โ package2, package3 โ
โโโโโโโโโโงโโโโโโโโโงโโโโโโโโโโโโโโโโโโโโโ
โโโโโโโโโโโโคโโโโโโโโโคโโโโโโโโโโโ
โ package2 โ Usages โ Packages โ
โโโโโโโโโโโโผโโโโโโโโโผโโโโโโโโโโโข
โ 1.0.0 โ 1 โ package2 โ
โโโโโโโโโโโโผโโโโโโโโโผโโโโโโโโโโโข
โ ^0.0.0 โ 1 โ package1 โ
โโโโโโโโโโโโงโโโโโโโโโงโโโโโโโโโโโ
These options are available on the CLI and as parameters to the Node API.
Name | Description |
---|---|
--dep-type | Type of dependency to check (dependencies , devDependencies , optionalDependencies , peerDependencies (optional), resolutions ) (default: dependencies , devDependencies , optionalDependencies , resolutions ) (option can be repeated). |
--fix | Whether to autofix inconsistencies (using latest version present). |
--ignore-dep | Dependency to ignore mismatches for (option can be repeated). |
--ignore-dep-pattern | RegExp of dependency names to ignore mismatches for (option can be repeated). |
--ignore-package | Workspace package to ignore mismatches for (option can be repeated). |
--ignore-package-pattern | RegExp of package names to ignore mismatches for (option can be repeated). |
--ignore-path | Workspace-relative path of packages to ignore mismatches for (option can be repeated). |
--ignore-path-pattern | RegExp of workspace-relative path of packages to ignore mismatches for (option can be repeated). |
import { CDVC } from 'check-dependency-version-consistency';
const cdvc = new CDVC(path, options);
const result = cdvc.getDependency('eslint');
// Result could look like this:
const result = {
isFixable: true,
isMismatching: true,
name: 'eslint',
versions: [
{
packages: [{ pathRelative: 'packages/package1' }, { pathRelative: 'packages/package2' }],
version: '^7.0.0',
},
{
packages: [{ pathRelative: 'packages/package3' }],
version: '^8.0.0',
},
],
};
CDVC Class Constructor Parameter | Type | Description |
---|---|---|
path | string | Path to the workspace root (where the package.json file containing workspaces or pnpm-workspace.yaml is located). |
options | object | See Options. |
CDVC Class Member | Description |
---|---|
getDependencies() | Returns an array of all dependencies in the workspace. |
getDependency(name: string) | Returns an object with information about an individual dependency. |
hasMismatchingDependenciesFixable | true if there are any dependencies with mismatching versions that are autofixable. |
hasMismatchingDependenciesNotFixable | true if there are any dependencies with mismatching versions that are not autofixable. |
hasMismatchingDependencies | true if there are any dependencies with mismatching versions. |
toFixedSummary() | Returns a string summary of the mismatching dependency versions that were fixed (if the fix option was specified). |
toMismatchSummary() | Returns a string of human-readable tables describing the mismatching dependency versions. |
Dependency Object Property | Description |
---|---|
isFixable | true if the mismatching versions of this dependency are autofixable. |
isMismatching | true if there are multiple versions of this dependency. |
name | The dependency's name. |
versions | A list of the versions present of this dependency and the packages each is found in, in the form of: { version: string, packages: { pathRelative: string }[] } . |
See lib/cli.ts
for an example of how to use it.
FAQs
Ensures dependencies are on consistent versions across a monorepo.
The npm package check-dependency-version-consistency receives a total of 89,299 weekly downloads. As such, check-dependency-version-consistency popularity was classified as popular.
We found that check-dependency-version-consistency demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago.ย It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
Security News
CAI is a new open source AI framework that automates penetration testing tasks like scanning and exploitation up to 3,600ร faster than humans.
Security News
Deno 2.4 brings back bundling, improves dependency updates and telemetry, and makes the runtime more practical for real-world JavaScript projects.