dep-validate
dep-validate is a tool used to verify the ranges on your npm dependencies. It can be used from the command line, from JavaScript, or from Gulp. It's available on npm, so just install it via:
# for gulp/node usage
$ npm install --save-dev dep-validate
# for command line usage
$ npm install -g dep-validate
Command Line Usage
Super easy, it's just the same interface as the JavaScript library (read up).
$ dep-validate --dependencies '~' --devDependencies '^' --exclude pkg1 --exclude pkg2 --hardcoded=allow --only production --only development --packageFile ./package.json
The exit code will be a 1
in case of error, with a chart displaying errors. It'll be 0
on success with no output.
Library Usages
You can use the JavaScript library either directly in Node.js or via Gulp:
JavaScript Interface
All options are shown below and are the defaults (so they're used if not provided). The only exception is file
, which will resolve the current package.json
(by reading upwards in directory).
var dv = require('dep-validate');
var opts = {
allowHardcoded: true,
dependencies: '~',
devDependencies: '^',
exluded: [ 'my-package' ],
packageFile: './package.json',
only: [ 'production', 'development' ]
}
var results = dv.validate(opts);
if (dv.hasErrors(results)) {
dv.log(results);
}
dv.pipe(opts, function (err) {
})
Gulp
var dv = require('dep-validate');
var gulp = require('gulp');
gulp.task('deps:validate', function () {
gulp.src('./package.json', { read: false })
.pipe(dv.gulp());
})
In addition to the options accepted by the JavaScript interface, .gulp()
can also accept a failOnError
option which will cause your Gulp task to cause an error if your dependencies do not satisfy your rules.