Skip to content

Commit

Permalink
fix: treat glob the same as globstar (#147)
Browse files Browse the repository at this point in the history
This makes `directory/*` work the same as `directory/**` to maintain backwards compatibility with previous versions of `npm pack`.

Ref: npm/cli#5918
  • Loading branch information
lukekarrys committed Dec 7, 2022
1 parent 29d52f2 commit c6f2b69
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
42 changes: 42 additions & 0 deletions test/package-json-directory-glob.js
Original file line number Diff line number Diff line change
@@ -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',
])
})
}
})

0 comments on commit c6f2b69

Please sign in to comment.