Skip to content

Commit

Permalink
Strip slashes from package files list results
Browse files Browse the repository at this point in the history
  • Loading branch information
isaacs committed Oct 21, 2020
1 parent 3d1edd5 commit 9cb1dbf
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
2 changes: 2 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,11 +234,13 @@ const npmWalker = Class => class Walker extends Class {
for (const {negate, fileList} of results) {
if (negate) {
fileList.forEach(f => {
f = f.replace(/\/+$/, '')
set.delete(f)
negates.add(f)
})
} else {
fileList.forEach(f => {
f = f.replace(/\/+$/, '')
set.add(f)
negates.delete(f)
})
Expand Down
55 changes: 55 additions & 0 deletions test/strip-slash-from-package-files-list-entries.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
const t = require('tap')
const packlist = require('../')
t.test('should strip / from package.json files array entry results', t => {
const path = t.testdir({
'package.json': JSON.stringify({
files: [
// include without slash, then exclude with it
'somedir',
'!somedir/',

// other way around
'otherdir/',
'!otherdir',

// now including it that way
'!incldir/',
'incldir',

// exclude without slash, then include with it
'!dist',
'dist/',
'!dist/foo/*.src'
]
}),
otherdir: {
donotinclude: ''
},
somedir: {
donotinclude: ''
},
incldir: {
yesinclude: ''
},
foo: '',
dist: {
foo: {
'foo.src': '',
'foo.result': ''
},
bar: '',
baz: {
boo: '',
'boo.src': ''
}
}
})
return packlist({path}).then(res => t.strictSame(res, [
'dist/bar',
'dist/baz/boo',
'incldir/yesinclude',
'package.json',
'dist/foo/foo.result',
'dist/baz/boo.src'
]))
})

0 comments on commit 9cb1dbf

Please sign in to comment.