From b09f47fe3bd031d5692b97457340187751d77dbb Mon Sep 17 00:00:00 2001 From: Luke Karrys Date: Tue, 6 Dec 2022 18:22:05 -0700 Subject: [PATCH 1/3] wip: failing test --- test/package-json-directory-glob.js | 41 +++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 test/package-json-directory-glob.js diff --git a/test/package-json-directory-glob.js b/test/package-json-directory-glob.js new file mode 100644 index 0000000..9ec87f6 --- /dev/null +++ b/test/package-json-directory-glob.js @@ -0,0 +1,41 @@ +'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/**', + ] + + 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', + ]) + }) + } +}) From f903ebaa336289ea3fd3d4ff790d90965c9b087e Mon Sep 17 00:00:00 2001 From: Luke Karrys Date: Tue, 6 Dec 2022 18:26:28 -0700 Subject: [PATCH 2/3] quick fix? --- lib/index.js | 2 ++ 1 file changed, 2 insertions(+) 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 { From 9cc59edb79b3a30f37a705a2048c76afd670232b Mon Sep 17 00:00:00 2001 From: Luke Karrys Date: Tue, 6 Dec 2022 19:00:49 -0700 Subject: [PATCH 3/3] try no slash too --- test/package-json-directory-glob.js | 1 + 1 file changed, 1 insertion(+) diff --git a/test/package-json-directory-glob.js b/test/package-json-directory-glob.js index 9ec87f6..48b228d 100644 --- a/test/package-json-directory-glob.js +++ b/test/package-json-directory-glob.js @@ -20,6 +20,7 @@ const createTestdir = (...files) => t.testdir({ t.test('package json directory glob', async (t) => { const pkgFiles = [ + 'folder', 'folder/', 'folder/*', 'folder/**',