Skip to content

Commit 26fe07e

Browse files
committed
Exporting the depcheck ‘special’ property so it can be used in the options
1 parent b322f86 commit 26fe07e

File tree

3 files changed

+36
-3
lines changed

3 files changed

+36
-3
lines changed

README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,17 @@ gulp.task('depcheck', depcheck({
3838
}));
3939
```
4040

41+
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.
42+
43+
```javascript
44+
gulp.task('depcheck', depcheck({
45+
specials : [
46+
depcheck.special.babel,
47+
depcheck.special.webpack
48+
]
49+
}));
50+
```
51+
4152
### Configuring the report
4253

4354
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
6172

6273
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']`.
6374

75+
Note that if you use a custom version of depcheck you must pass any special parsers explicitly.
76+
77+
```javascript
78+
const depcheck = require('gulp-depcheck');
79+
const myCustomDepcheck = require('depcheck');
80+
81+
gulp.task('depcheck', depcheck({
82+
depcheck : myCustomDepcheck,
83+
specials : [
84+
myCustomDepcheck.special.babel,
85+
myCustomDepcheck.special.webpack
86+
]
87+
}));
88+
```
89+
6490
## Running the build
6591

6692
To build this module use [roboter](https://www.npmjs.com/package/roboter).

lib/gulpDepcheck.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use strict';
22

33
const _ = require('lodash'),
4+
dc = require('depcheck'),
45
gutil = require('gulp-util');
56

67
const PluginError = gutil.PluginError;
@@ -14,9 +15,7 @@ const pluginError = function (message) {
1415
const gulpDepcheck = function (options) {
1516
options = options || {};
1617

17-
/* eslint-disable global-require */
18-
const depcheck = options.depcheck || require('depcheck');
19-
/* eslint-enable global-require */
18+
const depcheck = options.hasOwnProperty('depcheck') ? options.depcheck : dc;
2019

2120
const ignoreMissing = options.missing === false,
2221
ignoreUnusedDependencies = options.dependencies === false,
@@ -71,4 +70,6 @@ const gulpDepcheck = function (options) {
7170
};
7271
};
7372

73+
gulpDepcheck.special = dc.special;
74+
7475
module.exports = gulpDepcheck;

test/units/gulpDepcheckTests.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,4 +314,10 @@ suite('gulpDepcheck', () => {
314314
}).is.not.throwing();
315315
done();
316316
});
317+
318+
test('returns a special property that is an object.', done => {
319+
assert.that(depcheck.special).is.not.undefined();
320+
assert.that(depcheck.special).is.ofType('object');
321+
done();
322+
});
317323
});

0 commit comments

Comments
 (0)