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

check-dependency-version-consistency

Package Overview
Dependencies
Maintainers
1
Versions
29
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

check-dependency-version-consistency - npm Package Compare versions

Comparing version 0.2.0 to 0.3.0

18

bin/check-dependency-version-consistency.ts

@@ -9,10 +9,16 @@ #!/usr/bin/env node

calculateMismatchingVersions,
filterOutIgnoredDependencies,
} from '../lib/dependency-versions';
import { mismatchingVersionsToOutputLines } from '../lib/output';
import { join } from 'path';
import type { PackageJson } from 'type-fest';
function getCurrentPackageVersion(): string {
return JSON.parse(
const packageJson: PackageJson = JSON.parse(
readFileSync(join(__dirname, '..', '..', 'package.json'), 'utf-8') // Relative to compiled version of this file in dist/bin
).version;
);
if (!packageJson.version) {
throw new Error('Could not find package.json `version`');
}
return packageJson.version;
}

@@ -22,3 +28,3 @@

function collect(value: string, previous: string[]) {
return previous.concat([value]);
return [...previous, value];
}

@@ -37,7 +43,7 @@

)
.action(function (path, options) {
.action(function (path, options: { ignoreDep: string[] }) {
// Calculate.
const dependencyVersions = calculateVersionsForEachDependency(path);
const mismatchingVersions = calculateMismatchingVersions(
dependencyVersions,
const mismatchingVersions = filterOutIgnoredDependencies(
calculateMismatchingVersions(dependencyVersions),
options.ignoreDep

@@ -44,0 +50,0 @@ );

# check-dependency-version-consistency
## v0.3.0 (2021-05-08)
#### :rocket: Enhancement
* [#88](https://github.com/bmish/check-dependency-version-consistency/pull/88) Exit with failure when unnecessarily specifying `--ignore-dep` CLI option ([@bmish](https://github.com/bmish))
#### :bug: Bug Fix
* [#95](https://github.com/bmish/check-dependency-version-consistency/pull/95) Add real package.json types from type-fest ([@bmish](https://github.com/bmish))
#### Committers: 1
- Bryan Mishkin ([@bmish](https://github.com/bmish))
## v0.2.0 (2021-03-13)

@@ -4,0 +16,0 @@

@@ -11,8 +11,12 @@ #!/usr/bin/env node

function getCurrentPackageVersion() {
return JSON.parse(fs_1.readFileSync(path_1.join(__dirname, '..', '..', 'package.json'), 'utf-8') // Relative to compiled version of this file in dist/bin
).version;
const packageJson = JSON.parse(fs_1.readFileSync(path_1.join(__dirname, '..', '..', 'package.json'), 'utf-8') // Relative to compiled version of this file in dist/bin
);
if (!packageJson.version) {
throw new Error('Could not find package.json `version`');
}
return packageJson.version;
}
// Used for collecting repeated CLI options into an array.
function collect(value, previous) {
return previous.concat([value]);
return [...previous, value];
}

@@ -28,3 +32,3 @@ // Setup CLI.

const dependencyVersions = dependency_versions_1.calculateVersionsForEachDependency(path);
const mismatchingVersions = dependency_versions_1.calculateMismatchingVersions(dependencyVersions, options.ignoreDep);
const mismatchingVersions = dependency_versions_1.filterOutIgnoredDependencies(dependency_versions_1.calculateMismatchingVersions(dependencyVersions), options.ignoreDep);
// Show output.

@@ -31,0 +35,0 @@ if (mismatchingVersions.length > 0) {

@@ -29,2 +29,3 @@ export declare type DependenciesToVersionsSeen = Map<string, {

export declare function calculateVersionsForEachDependency(root: string): DependenciesToVersionsSeen;
export declare function calculateMismatchingVersions(dependencyVersions: DependenciesToVersionsSeen, ignoreDeps?: string[]): MismatchingDependencyVersions;
export declare function calculateMismatchingVersions(dependencyVersions: DependenciesToVersionsSeen): MismatchingDependencyVersions;
export declare function filterOutIgnoredDependencies(mismatchingVersions: MismatchingDependencyVersions, ignoredDependencies: string[]): MismatchingDependencyVersions;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.calculateMismatchingVersions = exports.calculateVersionsForEachDependency = void 0;
exports.filterOutIgnoredDependencies = exports.calculateMismatchingVersions = exports.calculateVersionsForEachDependency = void 0;
const fs_1 = require("fs");

@@ -36,10 +36,10 @@ const workspace_1 = require("./workspace");

if (packageJson.dependencies) {
Object.keys(packageJson.dependencies).forEach((dependency) => {
recordDependencyVersion(dependenciesToVersionsSeen, dependency, title, packageJson.dependencies[dependency]);
});
for (const [dependency, dependencyVersion] of Object.entries(packageJson.dependencies)) {
recordDependencyVersion(dependenciesToVersionsSeen, dependency, title, dependencyVersion);
}
}
if (packageJson.devDependencies) {
Object.keys(packageJson.devDependencies).forEach((dependency) => {
recordDependencyVersion(dependenciesToVersionsSeen, dependency, title, packageJson.devDependencies[dependency]);
});
for (const [dependency, dependencyVersion] of Object.entries(packageJson.devDependencies)) {
recordDependencyVersion(dependenciesToVersionsSeen, dependency, title, dependencyVersion);
}
}

@@ -58,9 +58,6 @@ }

}
function calculateMismatchingVersions(dependencyVersions, ignoreDeps = []) {
function calculateMismatchingVersions(dependencyVersions) {
return [...dependencyVersions.keys()]
.sort()
.map((dependency) => {
if (ignoreDeps.includes(dependency)) {
return undefined;
}
const versionList = dependencyVersions.get(dependency);

@@ -88,1 +85,10 @@ /* istanbul ignore if */

exports.calculateMismatchingVersions = calculateMismatchingVersions;
function filterOutIgnoredDependencies(mismatchingVersions, ignoredDependencies) {
ignoredDependencies.forEach((ignoreDependency) => {
if (!mismatchingVersions.some((mismatchingVersion) => mismatchingVersion.dependency === ignoreDependency)) {
throw new Error(`Specified option '--ignore-dep ${ignoreDependency}', but no mismatches detected.`);
}
});
return mismatchingVersions.filter((mismatchingVersion) => !ignoredDependencies.includes(mismatchingVersion.dependency));
}
exports.filterOutIgnoredDependencies = filterOutIgnoredDependencies;

@@ -12,4 +12,5 @@ "use strict";

) {
return array.reduce((result, item, index) => result.concat(callback(item, index)), []);
return array.reduce((result, item, index) => result.concat(callback(item, index)), // eslint-disable-line unicorn/prefer-spread
[]);
}
exports.flatMap = flatMap;

@@ -32,4 +32,7 @@ "use strict";

}
if (!Array.isArray(workspacePackageJson.workspaces)) {
throw new TypeError('package.json `workspaces` is not a string array.');
}
return workspacePackageJson.workspaces;
}
exports.getWorkspaces = getWorkspaces;
import { readFileSync, existsSync } from 'fs';
import type { PackageJson } from 'type-fest';
import { getPackageJsonPaths } from './workspace';

@@ -61,6 +62,10 @@

const title = packageJsonPath.replace(`${root}/`, '');
const packageJson = JSON.parse(readFileSync(packageJsonPath, 'utf-8'));
const packageJson: PackageJson = JSON.parse(
readFileSync(packageJsonPath, 'utf-8')
);
if (packageJson.dependencies) {
Object.keys(packageJson.dependencies).forEach((dependency) => {
for (const [dependency, dependencyVersion] of Object.entries(
packageJson.dependencies
)) {
recordDependencyVersion(

@@ -70,9 +75,11 @@ dependenciesToVersionsSeen,

title,
packageJson.dependencies[dependency]
dependencyVersion
);
});
}
}
if (packageJson.devDependencies) {
Object.keys(packageJson.devDependencies).forEach((dependency) => {
for (const [dependency, dependencyVersion] of Object.entries(
packageJson.devDependencies
)) {
recordDependencyVersion(

@@ -82,5 +89,5 @@ dependenciesToVersionsSeen,

title,
packageJson.devDependencies[dependency]
dependencyVersion
);
});
}
}

@@ -107,4 +114,3 @@ }

export function calculateMismatchingVersions(
dependencyVersions: DependenciesToVersionsSeen,
ignoreDeps: string[] = []
dependencyVersions: DependenciesToVersionsSeen
): MismatchingDependencyVersions {

@@ -114,6 +120,2 @@ return [...dependencyVersions.keys()]

.map((dependency) => {
if (ignoreDeps.includes(dependency)) {
return undefined;
}
const versionList = dependencyVersions.get(dependency);

@@ -142,1 +144,23 @@ /* istanbul ignore if */

}
export function filterOutIgnoredDependencies(
mismatchingVersions: MismatchingDependencyVersions,
ignoredDependencies: string[]
): MismatchingDependencyVersions {
ignoredDependencies.forEach((ignoreDependency) => {
if (
!mismatchingVersions.some(
(mismatchingVersion) =>
mismatchingVersion.dependency === ignoreDependency
)
) {
throw new Error(
`Specified option '--ignore-dep ${ignoreDependency}', but no mismatches detected.`
);
}
});
return mismatchingVersions.filter(
(mismatchingVersion) =>
!ignoredDependencies.includes(mismatchingVersion.dependency)
);
}

@@ -10,5 +10,5 @@ // TODO: remove this and switch to native JavaScript `flatMap` once Node 12 is the minimum version we need to support.

return array.reduce(
(result, item, index) => result.concat(callback(item, index)),
(result, item, index) => result.concat(callback(item, index)), // eslint-disable-line unicorn/prefer-spread
[]
);
}

@@ -5,2 +5,3 @@ import { join } from 'path';

import { flatMap } from './js';
import type { PackageJson } from 'type-fest';

@@ -32,3 +33,3 @@ export function getPackageJsonPaths(root: string): string[] {

const workspacePackageJson = JSON.parse(
const workspacePackageJson: PackageJson = JSON.parse(
readFileSync(join(root, 'package.json'), 'utf-8')

@@ -43,3 +44,7 @@ );

if (!Array.isArray(workspacePackageJson.workspaces)) {
throw new TypeError('package.json `workspaces` is not a string array.');
}
return workspacePackageJson.workspaces;
}
{
"name": "check-dependency-version-consistency",
"version": "0.2.0",
"version": "0.3.0",
"description": "Ensures dependencies are on consistent versions across a monorepo.",

@@ -40,7 +40,8 @@ "keywords": [

"commander": "^7.0.0",
"globby": "^11.0.0"
"globby": "^11.0.0",
"type-fest": "^1.0.2"
},
"devDependencies": {
"@types/mocha": "^8.2.0",
"@types/node": "^14.6.2",
"@types/node": "^15.0.1",
"@typescript-eslint/eslint-plugin": "^4.0.1",

@@ -50,3 +51,3 @@ "@typescript-eslint/parser": "^4.0.1",

"eslint-plugin-node": "^11.1.0",
"eslint-plugin-square": "^17.0.0",
"eslint-plugin-square": "^19.0.2",
"markdownlint-cli": "^0.27.1",

@@ -53,0 +54,0 @@ "mocha": "^8.1.3",

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