Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exporting the depcheck ‘special’ property so it can be used in the op… #9

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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).
Expand Down
9 changes: 5 additions & 4 deletions lib/gulpDepcheck.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';

const _ = require('lodash'),
depcheck = require('depcheck'),
gutil = require('gulp-util');

const PluginError = gutil.PluginError;
Expand All @@ -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,
Expand All @@ -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 || [];
Expand Down Expand Up @@ -71,4 +70,6 @@ const gulpDepcheck = function (options) {
};
};

gulpDepcheck.special = depcheck.special;

module.exports = gulpDepcheck;
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
{
"name": "Golo Roden",
"email": "[email protected]"
},
{
"name": "Eric Johnson",
"email": "[email protected]"
}
],
"main": "lib/gulpDepcheck.js",
Expand Down
6 changes: 6 additions & 0 deletions test/units/gulpDepcheckTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
});