diff --git a/README.md b/README.md index df6b74a..f4bcb0d 100644 --- a/README.md +++ b/README.md @@ -38,6 +38,17 @@ gulp.task('depcheck', depcheck({ })); ``` +Access [special depcheck parsers](https://github.com/depcheck/depcheck#special) via the `special` property. Pass them as options to recognize the dependencies outside of the normal syntax. + +```javascript +gulp.task('depcheck', depcheck({ + specials : [ + depcheck.special.babel, + depcheck.special.webpack + ] +})); +``` + ### Configuring the report By default, gulp-depcheck fails on any issue it finds. From time to time you might want to adjust this, e.g. to allow unused packages in the `devDependencies` section of your `package.json` file, or to only report packages that are missing from your `package.json` file. @@ -61,6 +72,21 @@ If you want to configure the version of depcheck to use explicitly provide a ref Additionally, you are allowed to set a default value for the directories to ignore. For that use the `ignoreDirsDefault` property and hand over the names of the directories to ignore as an array. The default value is `['node_modules', 'bower_components']`. +Note that if you use a custom version of depcheck you must pass any special parsers explicitly. + +```javascript +const depcheck = require('gulp-depcheck'), + myCustomDepcheck = require('depcheck'); + +gulp.task('depcheck', depcheck({ + depcheck : myCustomDepcheck, + specials : [ + myCustomDepcheck.special.babel, + myCustomDepcheck.special.webpack + ] +})); +``` + ## Running the build To build this module use [roboter](https://www.npmjs.com/package/roboter). diff --git a/lib/gulpDepcheck.js b/lib/gulpDepcheck.js index e04d733..3c05c2f 100644 --- a/lib/gulpDepcheck.js +++ b/lib/gulpDepcheck.js @@ -1,6 +1,7 @@ 'use strict'; const _ = require('lodash'), + depcheck = require('depcheck'), gutil = require('gulp-util'); const PluginError = gutil.PluginError; @@ -14,9 +15,7 @@ const pluginError = function (message) { const gulpDepcheck = function (options) { options = options || {}; - /* eslint-disable global-require */ - const depcheck = options.depcheck || require('depcheck'); - /* eslint-enable global-require */ + const depcheckInstance = options.hasOwnProperty('depcheck') ? options.depcheck : depcheck; const ignoreMissing = options.missing === false, ignoreUnusedDependencies = options.dependencies === false, @@ -39,7 +38,7 @@ const gulpDepcheck = function (options) { return function () { return new Promise((resolve, reject) => { - depcheck(process.cwd(), options, unused => { + depcheckInstance(process.cwd(), options, unused => { const missing = ignoreMissing ? [] : Object.keys(unused.missing || {}), unusedDependencies = ignoreUnusedDependencies ? [] : unused.dependencies || [], unusedDevDependencies = ignoreUnusedDevDependencies ? [] : unused.devDependencies || []; @@ -71,4 +70,6 @@ const gulpDepcheck = function (options) { }; }; +gulpDepcheck.special = depcheck.special; + module.exports = gulpDepcheck; diff --git a/package.json b/package.json index 9af1133..0730b37 100644 --- a/package.json +++ b/package.json @@ -10,6 +10,10 @@ { "name": "Golo Roden", "email": "golo.roden@thenativeweb.io" + }, + { + "name": "Eric Johnson", + "email": "edj.boston@gmail.com" } ], "main": "lib/gulpDepcheck.js", diff --git a/test/units/gulpDepcheckTests.js b/test/units/gulpDepcheckTests.js index 0a2883f..eddda36 100644 --- a/test/units/gulpDepcheckTests.js +++ b/test/units/gulpDepcheckTests.js @@ -314,4 +314,10 @@ suite('gulpDepcheck', () => { }).is.not.throwing(); done(); }); + + test('returns a special property that is an object.', done => { + assert.that(depcheck.special).is.not.undefined(); + assert.that(depcheck.special).is.ofType('object'); + done(); + }); });