diff --git a/lib/index.js b/lib/index.js index 91606e4..2d6504d 100644 --- a/lib/index.js +++ b/lib/index.js @@ -300,6 +300,8 @@ class PackWalker extends IgnoreWalker { file = file.slice(1) } else if (file.startsWith('./')) { file = file.slice(2) + } else if (file.endsWith('/*')) { + file = file.slice(0, -2) } const inverse = `!${file}` try { diff --git a/test/package-json-directory-glob.js b/test/package-json-directory-glob.js new file mode 100644 index 0000000..48b228d --- /dev/null +++ b/test/package-json-directory-glob.js @@ -0,0 +1,42 @@ +'use strict' + +const Arborist = require('@npmcli/arborist') +const t = require('tap') +const packlist = require('..') + +const createTestdir = (...files) => t.testdir({ + 'package.json': JSON.stringify({ + files, + }), + folder: { + one: { file: 'one' }, + two: { file: 'two' }, + }, + folder1: { + one: { file: 'one' }, + two: { file: 'two' }, + }, +}) + +t.test('package json directory glob', async (t) => { + const pkgFiles = [ + 'folder', + 'folder/', + 'folder/*', + 'folder/**', + ] + + for (const files of pkgFiles) { + await t.test(files, async t => { + const pkg = createTestdir(files) + const arborist = new Arborist({ path: pkg }) + const tree = await arborist.loadActual() + const res = await packlist(tree) + t.same(res, [ + 'folder/one/file', + 'folder/two/file', + 'package.json', + ]) + }) + } +})