Skip to content

Commit a198ada

Browse files
westy92Alan Shaw
authored andcommitted
feat: ignore dependencies via globs (#144)
* Ignore dependencies via globs. * Update devDependencies. * chore: update travis config * fix: standard dependency version * chore: appease linter * fix: travis config latest -> stable :rolleyes:
1 parent c29013f commit a198ada

6 files changed

Lines changed: 49 additions & 7 deletions

File tree

.travis.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ cache:
66
git:
77
depth: 5
88
node_js:
9-
- 8
109
- 10
10+
- 12
11+
- "stable"
1112
after_script:
1213
- npm run coveralls

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,13 +154,13 @@ Use `-p, --package` to specify the path to your package.json.
154154

155155
### Ignore dependencies
156156

157-
To tell david to ignore dependencies, add a `david.ignore` property to your `package.json` which lists the dependencies david should ignore. If using david programmatically you can also pass this as an option. e.g.
157+
To tell david to ignore dependencies, add a `david.ignore` property to your `package.json` which lists the dependencies david should ignore. If using david programmatically you can also pass this as an option. Globs are also supported. e.g.
158158

159159
**package.json**
160160
```json
161161
{
162162
"david": {
163-
"ignore": ["async", "underscore"]
163+
"ignore": ["async", "underscore", "@types/*"]
164164
}
165165
}
166166
```

bin/usage.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Options:
1414
-v, --version Print version number and exit.
1515
-r, --registry The npm registry URL.
1616
[default: "https://registry.npmjs.org/"]
17-
-i, --ignore List of dependencies to ignore.
17+
-i, --ignore List of dependency names or globs to ignore.
1818
--error404 If dependency not found, halt with an error code.
1919
--errorSCM If dependency version is a source control URL, halt with an
2020
error code.

lib/david.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* Licensed under the MIT license.
77
*/
88

9+
var multimatch = require('multimatch')
910
var parallel = require('async/parallel')
1011
var semver = require('semver')
1112
var Version = require('./version')
@@ -84,7 +85,7 @@ function depType (opts) {
8485
* @param {Boolean} [opts.error.E404] Error on 404s
8586
* @param {Boolean} [opts.versions] For each dependency, return the available versions
8687
* @param {Boolean} [opts.rangeVersions] For each dependency, return the available versions for the range specified in the package.json
87-
* @param {Array} [opts.ignore] List of dependency names to ignore
88+
* @param {Array} [opts.ignore] List of dependency names or globs to ignore
8889
* @param {Function} cb Function that receives the results
8990
*/
9091
function getDependencies (manifest, opts, cb) {
@@ -116,7 +117,7 @@ function getDependencies (manifest, opts, cb) {
116117

117118
var tasks = depNames.map(function (depName) {
118119
return function (cb) {
119-
if (opts.ignore.indexOf(depName) > -1) {
120+
if (multimatch(depName, opts.ignore).length > 0) {
120121
return cb()
121122
}
122123

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
"cli-table": "^0.3.1",
3131
"exit": "^0.1.2",
3232
"minimist": "^1.1.0",
33+
"multimatch": "^2.1.0",
3334
"npm": "^6.10.2",
3435
"semver": "^6.3.0",
3536
"xtend": "^4.0.0"
@@ -40,7 +41,7 @@
4041
"jshint": "^2.10.2",
4142
"rewire": "^4.0.1",
4243
"rimraf": "^2.6.3",
43-
"standard": "^13.1.0",
44+
"standard": "^14.3.1",
4445
"tape": "^4.11.0"
4546
},
4647
"engines": {

test/david.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,45 @@ test('Test getDependencies returns an empty object when passed a manifest with n
4747
})
4848
})
4949

50+
test('Test getDependencies ignores specified packages', function (t) {
51+
t.plan(4)
52+
53+
var manifest = {
54+
dependencies: {
55+
testDepName: '~0.0.2',
56+
testDepName2: '~0.3.2'
57+
}
58+
}
59+
60+
david.getDependencies(manifest, { ignore: ['testDepName'] }, function (err, deps) {
61+
t.equal(err, undefined)
62+
t.ok(deps)
63+
t.ok(deps.testDepName2)
64+
t.strictEqual(Object.keys(deps).length, 1)
65+
t.end()
66+
})
67+
})
68+
69+
test('Test getDependencies ignores specified package glob', function (t) {
70+
t.plan(4)
71+
72+
var manifest = {
73+
dependencies: {
74+
testDepName: '~0.0.2',
75+
testDepName2: '~0.3.2',
76+
testOtherName: '~1.0.2'
77+
}
78+
}
79+
80+
david.getDependencies(manifest, { ignore: ['testDep*'] }, function (err, deps) {
81+
t.equal(err, undefined)
82+
t.ok(deps)
83+
t.ok(deps.testOtherName)
84+
t.strictEqual(Object.keys(deps).length, 1)
85+
t.end()
86+
})
87+
})
88+
5089
test('Test getUpdatedDependencies returns an empty object when passed a manifest with no dependencies', function (t) {
5190
t.plan(3)
5291

0 commit comments

Comments
 (0)