Skip to content

Commit b7e16cd

Browse files
hershmirecoreyfarrell
authored andcommitted
feat: Support turning off node_modules default exclude via flag (#912)
1 parent 3eb0e37 commit b7e16cd

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

index.js

+1
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ function NYC (config) {
5858
cwd: this.cwd,
5959
include: config.include,
6060
exclude: config.exclude,
61+
excludeNodeModules: config.excludeNodeModules !== false,
6162
extension: this.extensions
6263
})
6364

lib/config-util.js

+6
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,12 @@ Config.buildYargs = function (cwd) {
8989
description: 'should exclude logic be performed after the source-map remaps filenames?',
9090
global: false
9191
})
92+
.option('exclude-node-modules', {
93+
default: true,
94+
type: 'boolean',
95+
describe: 'whether or not to exclude all node_module folders (i.e. **/node_modules/**) by default',
96+
global: false
97+
})
9298
.option('include', {
9399
alias: 'n',
94100
default: [],

test/src/nyc-tap.js

+14
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,20 @@ describe('nyc', function () {
123123
nyc.exclude.shouldInstrument('/cwd/foo/bar/__tests__/foo.js', './__tests__/foo.js').should.equal(false)
124124
})
125125

126+
it('should allow turning off default node_modules exclude', function () {
127+
var nyc = new NYC(configUtil.buildYargs('/cwd').parse([
128+
'--exclude-node-modules', 'false',
129+
'--exclude=**/__tests__/**',
130+
'--exclude=node_modules/**'
131+
]))
132+
// For this test, only excluding root node_modules. Local node_modules are allowed, but we
133+
// still exclude matching items inside of local node_modules.
134+
nyc.exclude.shouldInstrument('/cwd/foo', 'foo').should.equal(true)
135+
nyc.exclude.shouldInstrument('/cwd/node_modules/bar', 'node_modules/bar').should.equal(false)
136+
nyc.exclude.shouldInstrument('/cwd/foo/node_modules/bar', 'foo/node_modules/bar').should.equal(true)
137+
nyc.exclude.shouldInstrument('/cwd/foo/node_modules/bar/__tests__/baz.js', 'foo/node_modules/bar/__tests__/baz.js').should.equal(false)
138+
})
139+
126140
it('should exclude appropriately with config.exclude', function () {
127141
var nyc = new NYC(configUtil.buildYargs(fixtures).parse())
128142

0 commit comments

Comments
 (0)