Repository navigation
Closed
Labels
Description
Is there an existing issue for this?
- I have searched the existing issues
This issue exists in the latest npm version
- I am using the latest npm
Current Behavior
With npm 10 files: ["dist-*"] does not include dist-es or dist-es/index.js. This is changed from npm 8, not clearly documented, and inconsistent with other patterns.
Expected Behavior
I expect the same behavior as npm 8. I don't see anything in the change logs that would explain this difference.
npm pack now follows a strict order of operations when applying ignore rules. If a files array is present in the package.json, then rules in .gitignore and .npmignore files from the root will be ignored.
This bug occurs when there's only a files array, there's no .gitignore or .npmignore to ignore (or respect in npm 8)
Steps To Reproduce
Setup a test project
.
├── dist-cjs
│ └── index.js
├── dist-es
│ └── index.js
├── dist-other.js
└── package.json
# package.json
{ "name": "test", "version": "1.0.0" }This test script will print the differences between files included by npm 8 and 10
#!/bin/bash
set -euo pipefail
patterns=('null' '[]' '["*"]' '["dist-*"]' '["dist-**"]' '["dist-*/*.js"]')
for files in "${patterns[@]}"; do
npm pkg set files="$files" --json
echo "8 ($files) 10 ($files) both"
comm \
<(npx npm@8 pack --dry-run --json | jq '.[].files[].path' -r) \
<(npx npm@10 pack --dry-run --json | jq '.[].files[].path' -r)
doneResults
8 (null) | 10 (null) | both
| | dist-cjs/index.js
| | dist-es/index.js
| | dist-other.js
| | package.json
8 ([]) | 10 ([]) | both
| | package.json
8 (["*"]) | 10 (["*"]) | both
| | dist-cjs/index.js
| | dist-es/index.js
| | dist-other.js
| | package.json
8 (["dist-*"]) | 10 (["dist-*"]) | both
dist-cjs/index.js | |
dist-es/index.js | |
| | dist-other.js
| | package.json
8 (["dist-*/"]) | 10 (["dist-*/"]) | both
dist-cjs/index.js | |
dist-es/index.js | |
| | package.json
8 (["dist-**"]) | 10 (["dist-**"]) | both
dist-cjs/index.js | |
dist-es/index.js | |
| | dist-other.js
| | package.json
8 (["dist-**/"]) | 10 (["dist-**/"]) | both
dist-cjs/index.js | |
dist-es/index.js | |
| | package.json
8 (["dist-*/*.js"]) | 10 (["dist-*/*.js"]) | both
| | dist-cjs/index.js
| | dist-es/index.js
| | package.json
Environment
- npm: 10.7.0 (vs 8.19.4)
- Node.js: 22.00
- OS Name: Ubuntu
- System Model Name: N/A
- npm config:
; node bin location =~/.local/share/rtx/installs/node/22.0.0/bin/node
; node version = v22.0.0
; npm local prefix = /tmp/npm-pack-test
; npm version = 10.5.1
; cwd = /tmp/npm-pack-test
; HOME = ~
; Run `npm config ls -l` to show all defaults.Reacted by johnpyp
Activity
everett1992 commentedon May 13, 2024
It seems like npm 10 will only treat exactly
*as a directory wildcard, so*orlib/*will match directories, butdist-*or*.tswill only match files.everett1992 commentedon May 13, 2024
Okay, there's a closed npm/cli issue saying it's fixed #6164, and a npm-packlist issue tracking other packlist changes npm/npm-packlist#152
The fix they reference npm/npm-packlist#147 suggests that packlist should treat
*the same as**, howeverdist-**/doesn't matchdist-es/index.jseither.everett1992 commentedon May 13, 2024
interestingly
dist-*/*does match and has the same packlist between 8 and 10.wraithgar commentedon May 13, 2024
Yes it's not very well documented, but the way "globstar" is treated got aligned more with standard glob implementations quite some time ago. Not sure what the long term solution will be here, obviously trying to "patch" back the old behavior has been buggy. Your best bet is to fix your globs.
wraithgar commentedon May 13, 2024
Added a note to our v11 roadmap to unwind all of these hacks.
everett1992 commentedon May 13, 2024
I'm in the position of upgrading the company wide npm version, this is one of the few changes that's causing wide spread differences. It's mainly a matter of documenting the change and explaining how to write equivalent npm 10 patterns.
I thin npm 8's
["dist-*"]needs to become["dist-*", "dist-*/**"]everett1992 commentedon May 13, 2024
What does 'unwind all of these hacks' mean? Make it more like npm 8, or make it ' aligned more with standard glob implementations'?
IMO npm 8's behavior is not unaligned with standard globs.
dist-*should includedist-cjs/index.jsfor the same reason thatdist-cjsincludesdist-cjs/index.jsin npm 10 - it matcheddist-cjsfolder and recursively included everything in it.An analogy, echo shows that dist-* only matches direct children
But when you give those arguments to
findit recurses and finds the descendants.Here's another example comparing npm 8 and 10, this time without using
*patterns. The directory patterndist-esmatches the files in the dir in both versions. But passing the brace patterndist-{es,cjs}which expands to"dist-es", "dist-cjs"only matches files in the directories in npm 8.wraithgar commentedon May 13, 2024
It means no longer work around the default
node-globbehavior. The decision was made at the time to try to work around them because the changes weren't well documented at the time. In hindsight this was probably less ideal than adding notes to the changelog to let folks know about the new behavior.wraithgar commentedon May 13, 2024
For what it's worth
finddoes not use "glob".lsdoes. Compare the difference betweenls *andls */*everett1992 commentedon May 13, 2024
That is my point,
dist-*expands todist-esanddist-cjs, then npm checks those directories recursively, like find does. The expansion is flat and doesn't rely on globstar behavior.files: ["dist-es", "dist-cjs"]will includedist-es/index.js, butfiles: ["dist-{es,cjs}"]won't, even tho it expands to the same thing.I think npm 8's pattern matching was good. Requiring explicit recursive patterns would be okay.
dist-cjsbeing recursive whiledist-*is not, is bad.dist-*anddist-esboth matchingdist-es/index.jsis good (npm 8)dist-esmatchingdist-es/index.jswhiledist-*does is bad (npm 10)dist-*anddist-esnot matchingdist-es/index.jsis ok (maybe what you're proposing for npm 11?)dist-*/**anddist-es/**both matchingdist-es/index.jsis ok (maybe what you're proposing for npm 11?)wraithgar commentedon May 14, 2024
Yes those last two would be what npm 11 does.
everett1992 commentedon May 14, 2024
Will those changes apply to .gitignore and .npmignore?
So
.npmignorebuildwon't exclude every file underbuildin npm 11?ljharb commentedon May 14, 2024
buildshould absolutely match bothbuildandbuild/**/*, just like it does for git.everett1992 commentedon May 14, 2024
So will there be different pattern rules for .npmignore and
files?dist-*in .gitignore or .npmignore will exclude everything underdist-cjs/, whiledist-*in package.json files would only include a literal file likedist-other.jswhile not includingdist-cjs/directories contents?I much prefer npm 8's and .gitignore's "if a pattern matches a directory, it's files are matched" behavior to the proposed "a
filespattern must exactly match the path to a file".wraithgar commentedon May 14, 2024
These questions show just how wanting we are for a proper spec here. I don't have answers today. The way it works now is not working. That's the only answer I have today.
wraithgar commentedon May 14, 2024
If you look through the history of especially
map-workspacesandnpm-packlistyou'll see just how buggy the changes fromglobhave made npm. We have to work around the new behavior in every instance now, and doing it like that is almost guaranteed to produce bugs.everett1992 commentedon May 14, 2024
I'm happy to help out with spec/doc/test writing or discussion.
Not sure if this falls under the same umbrella, but I found that symlinks are treated differently between 8 and 10. LMK if I should create a different issue.
Neither 8 or 10 will recursively include files from a symlink that matches the pattern.
npm 8 will match files inside a link, as long as the pattern reaches past the link, but npm 10 won't.
npm 8 will also work with patterns, I think this is the same behavior as before.
npm 10 won't match a file under a symlink even when the exact path is given.
The behavior is the same with an internal link, like
link -> ./dist-es. I'm less sure about what the right behavior is here.everett1992 commentedon May 17, 2024
A co worker found an odd behavior with directories named cvs. In this case I can't explain how either npm 8 or 10 is behaving. I understand the CVS is ignored by default, but it's not on the list of files that can't be included (docs)
"cvs"patterns, but 8 won't.dist/cvspattern.dist/cvs/index.jspattern but npm 10 won't.npm-debug.log is also inconsistent, and differently than cvs.
wraithgar commentedon May 17, 2024
https://github.com/npm/npm-packlist/blob/cb4a823cd42d50475a8e1e7582b95b15766f5ca2/lib/index.js#L25
everett1992 commentedon May 17, 2024
It's on the default ignore list, but it's not on the "can't include" list.
Why doesn't
**/CVS/**includedist/CVS/index.jsin npm 10?Why doesn't
dist/CVSincludedist/CVS/index.jsin npm 10?owlstronaut commentedon Jun 18, 2026
fixed in npm 12