Skip to content

Commit c6f2b69

Browse files
authored
fix: treat glob the same as globstar (#147)
This makes `directory/*` work the same as `directory/**` to maintain backwards compatibility with previous versions of `npm pack`. Ref: npm/cli#5918
1 parent 29d52f2 commit c6f2b69

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

lib/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,8 @@ class PackWalker extends IgnoreWalker {
300300
file = file.slice(1)
301301
} else if (file.startsWith('./')) {
302302
file = file.slice(2)
303+
} else if (file.endsWith('/*')) {
304+
file = file.slice(0, -2)
303305
}
304306
const inverse = `!${file}`
305307
try {
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
'use strict'
2+
3+
const Arborist = require('@npmcli/arborist')
4+
const t = require('tap')
5+
const packlist = require('..')
6+
7+
const createTestdir = (...files) => t.testdir({
8+
'package.json': JSON.stringify({
9+
files,
10+
}),
11+
folder: {
12+
one: { file: 'one' },
13+
two: { file: 'two' },
14+
},
15+
folder1: {
16+
one: { file: 'one' },
17+
two: { file: 'two' },
18+
},
19+
})
20+
21+
t.test('package json directory glob', async (t) => {
22+
const pkgFiles = [
23+
'folder',
24+
'folder/',
25+
'folder/*',
26+
'folder/**',
27+
]
28+
29+
for (const files of pkgFiles) {
30+
await t.test(files, async t => {
31+
const pkg = createTestdir(files)
32+
const arborist = new Arborist({ path: pkg })
33+
const tree = await arborist.loadActual()
34+
const res = await packlist(tree)
35+
t.same(res, [
36+
'folder/one/file',
37+
'folder/two/file',
38+
'package.json',
39+
])
40+
})
41+
}
42+
})

0 commit comments

Comments
 (0)