Socket
Socket
Sign inDemoInstall

npm-check-updates

Package Overview
Dependencies
Maintainers
1
Versions
470
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

npm-check-updates - npm Package Compare versions

Comparing version 1.3.0 to 1.5.0

.travis.yml

34

lib/npm-check-updates.js

@@ -1,19 +0,1 @@

// npm-check-updates
// Tomas Junnonen (c) 2013
//
// Checks a package.json file for updated NPM packages that are *not*
// satisfied by the current package.json dependency declarations.
//
// Example output:
// Dependency "express" could be updated to "3.3.x" (latest is 3.3.8)
//
// Optionally automatically upgrades the dependencies in package.json
// while maintaining your existing versioning policy.
//
// Example:
// Your package.json: "express": "3.2.x."
// Latest version upstream is 3.3.8
// package.json after upgrade: "express": "3.3.x"
//
var program = require('commander');

@@ -81,3 +63,7 @@ var async = require('async');

current: function (callback) {
vm.getCurrentDependencies(packageFile, callback);
vm.getCurrentDependencies(packageFile, {
filter: program.filter,
prod: program.prod,
dev: program.dev
}, callback);
},

@@ -110,3 +96,3 @@ installed: function (callback) {

} else {
print("\nRun 'npm-check-updates -u' to upgrade your package.json automatically");
print("\nRun with '-u' to upgrade your package.json");
}

@@ -137,3 +123,6 @@ }

.usage('[options] <package.json or dir>')
.option('-d, --dev', 'check only devDependencies')
.option('-f, --filter <packages>', 'list or regex of package names to search (all others will be ignored)')
.option('-g, --global', 'check global packages instead of in the current project')
.option('-p, --prod', 'check only dependencies (not devDependencies)')
.option('-s, --silent', "don't output anything")

@@ -206,1 +195,6 @@ .option('-u, --upgrade', 'upgrade package.json dependencies to match latest versions (maintaining existing policy)')

}
// Splits a string on whitespace
function splitList(str) {
return str.split(/[\s,]+/);
}

@@ -5,2 +5,4 @@ var npm = require('npm');

var semver = require('semver');
var _ = require('lodash');
var cint = require('cint');

@@ -122,2 +124,5 @@ var npmIsInitialized = false;

/**
* Get constraints (>, >=, <, <=) and empty spaces at the front of the version
*/
function getVersionConstraints(declaration) {

@@ -157,8 +162,52 @@ var constraints = "";

* @param packageFile path to package.json
* @param options.filter List or regex of package names to search
* @param callback Called with (error, {dependencyName: version} collection)
*/
function getCurrentDependencies(packageFile, callback) {
function getCurrentDependencies(packageFile, options, callback) {
readJson(packageFile, null, false, function (error, json) {
var allDependencies = json ? mergeObjects(json.dependencies, json.devDependencies) : null;
if(error) {
return callback(error);
}
else if(!json) {
return callback(new Error('package.json does not contain valid json'))
}
var allDependencies = {};
if (options.prod || !options.dev) {
allDependencies = mergeObjects(allDependencies, json.dependencies);
}
if (options.dev || (!options.prod && !options.dev)) {
allDependencies = mergeObjects(allDependencies, json.devDependencies);
}
if(options.filter) {
var filterPackages;
// RegExp filter
if(typeof options.filter === 'string' && options.filter[0] === '/' && options.filter[options.filter.length-1] === '/') {
var regexp = new RegExp(options.filter.slice(1, options.filter.length-1));
filterPackages = regexp.test.bind(regexp);
}
// string filter
else if(typeof options.filter === 'string') {
var packages = options.filter.split(/[\s,]+/);
filterPackages = _.contains.bind(_, packages);
}
// array filter
else if(Array.isArray(options.filter)) {
filterPackages = _.contains.bind(_, options.filter)
}
else {
return callback(new Error('Invalid packages filter. Must be a RegExp, array, or comma-or-space-delimited list.'))
}
// only include the dependencies that pass the filter
// (limit the arity to 1 to avoid passing the value)
allDependencies = cint.filterObject(allDependencies, cint.aritize(filterPackages, 1));
}
callback(error, allDependencies);

@@ -165,0 +214,0 @@ });

{
"name": "npm-check-updates",
"version": "1.3.0",
"author": "Tomas Junnonen <tomas1@gmail.com>",
"description": "Find newer versions of dependencies than what your package.json allows",
"keywords": ["npm", "check", "find", "discover", "updates", "upgrades", "dependencies", "package.json", "updater", "version", "management"],
"dependencies": {
"npm": "2.1.x",
"commander": "2.5.x",
"async": "0.9.x",
"read-package-json": "1.2.x",
"semver": "4.1.x"
},
"devDependencies": {
"should": "4.3.x"
},
"main": "./lib/npm-check-updates",
"bin": {
"npm-check-updates": "./bin/npm-check-updates"
},
"repository": {
"type": "git",
"url": "https://github.com/tjunnone/npm-check-updates.git"
},
"homepage": "https://github.com/tjunnone/npm-check-updates"
"name": "npm-check-updates",
"version": "1.5.0",
"author": "Tomas Junnonen <tomas1@gmail.com>",
"description": "Find newer versions of dependencies than what your package.json allows",
"keywords": [
"npm",
"check",
"find",
"discover",
"updates",
"upgrades",
"dependencies",
"package.json",
"updater",
"version",
"management"
],
"preferglobal": true,
"main": "./lib/npm-check-updates",
"scripts": {
"test": "mocha"
},
"bin": {
"npm-check-updates": "./bin/npm-check-updates"
},
"repository": {
"type": "git",
"url": "https://github.com/tjunnone/npm-check-updates.git"
},
"homepage": "https://github.com/tjunnone/npm-check-updates",
"dependencies": {
"async": "0.9.x",
"cint": "^8.0.1",
"commander": "2.5.x",
"lodash": "^2.4.1",
"npm": "2.1.x",
"read-package-json": "1.2.x",
"semver": "4.1.x"
},
"devDependencies": {
"mocha": "^2.0.1",
"should": "4.3.x"
}
}
npm-check-updates
=================
npm-check-updates is a tool that allows you to **find all updates to
dependencies** in your Node.js project, regardless of any version
npm-check-updates is a tool that allows you to **find the latest versions of
dependencies**, regardless of any version
constraints in your package.json file (unlike npm itself).
Optionally, npm-check-updates can also upgrade your package.json file to
satisfy the latest available versions, all while **maintaining your
npm-check-updates can optionally upgrade your package.json file to
use the latest available versions, all while **maintaining your
existing semantic versioning policies**.

@@ -15,4 +15,3 @@

npm-check-updates can also show you all available **updates to your globally
installed packages**.
View the [options](#options) for global, dev-only, prod-only, or filtering by package name.

@@ -22,11 +21,6 @@ Motivation

[Package.json best practices](http://blog.nodejitsu.com/package-dependencies-done-right)
recommends maintaining dependencies using a [semantic versioning](http://semver.org/)
policy. In practice you do this by specifying a "1.2.x" style dependency
in your package.json, whereby patch-level updates are automatically allowed
but major and minor releases require manual verification.
[Package.json best practices](http://blog.nodejitsu.com/package-dependencies-done-right) recommends maintaining dependencies using a [semantic versioning](http://semver.org/) policy. In practice you do this by specifying a "1.2.x" style dependency in your package.json, whereby patch-level updates are automatically allowed but major and minor releases require manual verification.
Unfortunately, it then becomes your responsibility to find out about new
package releases, for example by using "npm info" command one package at a time,
or by visiting project pages.
package releases, for example by using "npm info" command one package at a time, or by visiting project pages.

@@ -40,3 +34,3 @@ Whatever your versioning policy, npm-check-updates will make keeping your

```
```sh
npm install -g npm-check-updates

@@ -49,3 +43,3 @@ ```

Show any new dependencies for the project in the current directory:
```
```sh
$ npm-check-updates

@@ -56,14 +50,7 @@

Run 'npm-check-updates -u' to upgrade your package.json automatically
Run with '-u' to upgrade your package.json
```
Check global npm packages for updates:
```
$ npm-check-updates -g
"mocha" can be updated to version 1.12.1
```
Upgrade a project's package.json:
```
```sh
$ npm-check-updates -u

@@ -76,8 +63,30 @@

Now simply perform the usual "npm update" and verify that your project
works with the upgraded versions.
Filter by package name:
```sh
$ npm-check-updates -f mocha,should # string
$ npm-check-updates -f /^((?!gulp-).)*$/ # regex
```
Options
--------------
-d, --dev check only devDependencies
-h, --help output usage information
-f, --filter <packages> list or regex of package names to search (all others
will be ignored)
-g, --global check global packages instead of in the current project
-p, --prod check only dependencies (not devDependencies) don't
-s, --silent output anything
-u, --upgrade upgrade package.json dependencies to match latest
versions (maintaining existing policy)
-V, --version output the version number
History
--------------
- 1.5
- Add prod and dev only options
- 1.4
- Add package filtering option
- Add mocha as npm test script
- 1.3

@@ -118,2 +127,3 @@ - Handle private packages and NPM errors

Please [file an issue on github](https://github.com/tjunnone/npm-check-updates/issues).
Pull requests are welcome :)
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