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

check-deps-versions

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

check-deps-versions - npm Package Compare versions

Comparing version 0.0.4 to 0.0.5

83

index.js

@@ -14,30 +14,69 @@ const findNearestFile = require('find-nearest-file');

const fs = require('fs');
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
const semver = require('semver');
const packageJson = require('package-json');
const localPackageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
const dependencies = localPackageJson.dependencies || {};
const devDependencies = localPackageJson.devDependencies || {};
const latestVersion = require('latest-version');
const getPackageUpdates = (packageName, localRange) =>
packageJson(packageName).then(result => {
const latestVersion = result['dist-tags'].latest;
const versions = Object.keys(result.versions);
const versionsInRange = versions.filter(version =>
semver.satisfies(version, localRange)
);
const getLatestVersions = (deps = {}) => {
const depsArray = Object.keys(deps);
const tasks = depsArray.map(latestVersion);
if (versionsInRange.length === 0) {
return {
error: `doesn't have versions in range ${localRange}`
};
}
return Promise.all(tasks)
.then(latestVersions => {
return latestVersions.reduce((result, latestVersion, index) => {
result[depsArray[index]] = latestVersion;
return result;
}, {});
});
if (versionsInRange.length > 1 || versionsInRange[0] !== latestVersion) {
return {
latest: latestVersion
};
}
return {};
});
const getDepsUpdates = deps => {
const packages = Object.keys(deps);
const tasks = packages.map(dep => getPackageUpdates(dep, deps[dep]));
return Promise.all(tasks).then(updates =>
updates.reduce((result, update, index) => {
if (update.error || update.latest) {
result[packages[index]] = update;
}
return result;
}, {})
);
};
const getLatestDependencies = getLatestVersions(packageJson.dependencies);
const getLatestDevDependencies = getLatestVersions(packageJson.devDependencies);
const printUpdates = (header, updates) => {
/* eslint-disable no-console */
console.log(header);
getLatestDependencies
.then(latestDependencies => {
console.log('Latest dependencies:\n', latestDependencies); // eslint-disable-line no-console
return getLatestDevDependencies;
const packageNames = Object.keys(updates);
if (packageNames.length === 0) {
console.log('\tok');
} else {
packageNames.forEach(package =>
console.log(`\t${package}: ${updates[package].error || updates[package].latest}`)
);
}
/* eslint-enable no-console */
};
getDepsUpdates(dependencies)
.then(depsUpdates => {
printUpdates('dependencies', depsUpdates);
return getDepsUpdates(devDependencies);
})
.then(latestDevDependencies => {
console.log('Latest devDependencies:\n', latestDevDependencies); // eslint-disable-line no-console
})
.catch(errorAndExit);
.then(devDepsUpdates => {
printUpdates('devDependencies', devDepsUpdates);
});
{
"name": "check-deps-versions",
"version": "0.0.4",
"version": "0.0.5",
"description": "Check if dependencies specified in package.json are up to date with the latest available versions.",

@@ -13,2 +13,3 @@ "repository": {

"build": "npm run lint",
"preversion": "npm run build",
"postversion": "git push && git push --tags"

@@ -21,3 +22,4 @@ },

"find-nearest-file": "^1.0.0",
"latest-version": "^2.0.0"
"package-json": "^2.4.0",
"semver": "^5.3.0"
},

@@ -37,2 +39,3 @@ "devDependencies": {

"versions",
"pkg",
"package",

@@ -44,5 +47,6 @@ "packages",

"compare",
"outdated"
"outdated",
"latest"
],
"license": "MIT"
}
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