From 9cb1dbf04ae025b5f77266ad683f31fcf636f7d4 Mon Sep 17 00:00:00 2001 From: isaacs Date: Wed, 21 Oct 2020 15:57:55 -0700 Subject: [PATCH] Strip slashes from package files list results Fix: npm/cli#2007 --- index.js | 2 + ...p-slash-from-package-files-list-entries.js | 55 +++++++++++++++++++ 2 files changed, 57 insertions(+) create mode 100644 test/strip-slash-from-package-files-list-entries.js diff --git a/index.js b/index.js index 0ab0387..cf87b18 100644 --- a/index.js +++ b/index.js @@ -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) }) diff --git a/test/strip-slash-from-package-files-list-entries.js b/test/strip-slash-from-package-files-list-entries.js new file mode 100644 index 0000000..c9e0070 --- /dev/null +++ b/test/strip-slash-from-package-files-list-entries.js @@ -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' + ])) +})