[BUG] npm 12 pack/publish drops files named like `[slug].js` that match a `files` glob

未关闭
#10,260 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 2 天内回复

@1AbdullahButt 已经在做这个了。

开始于 2026年11月8日。

  • #304 来自 @1AbdullahButt —— 未关闭

评估

难度
3/5
预计耗时
1-2 天
新手友好度
66/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃

调研方向

The report points to processPackage in npm-packlist/lib/index.js, where globSync results are added as ignore rules. Start by reading that code and the packlist tests for files patterns; reproduce with the provided [slug].js example. Done means npm pack includes filenames with glob characters when they match a files entry, with regression coverage for the reported case.

由索引模型根据 Issue 内容生成。

描述

Bug Priority 2 regression:12.x ws:libnpmpack
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
This is not just a request to bump a dependency for a CVE
  • This is not solely a request to bump a dependency for a CVE
Current Behavior

With npm 12, a file whose name contains [ ] (or { }, or an extglob like +(a)) is left out of the tarball even though a files entry matches it. Route files such as [slug].js, [id].vue or [...all].astro are the common case. npm 11 packs them.

Expected Behavior

Every file matched by a files glob is packed, whatever characters its name contains.

Steps To Reproduce
mkdir -p rep/dist/blog && cd rep
echo '{"name":"rep","version":"1.0.0","files":["dist/**/*.js"]}' > package.json
echo x > dist/index.js
echo x > 'dist/blog/[slug].js'
npm pack --dry-run 2>&1 | grep -E 'B (dist|package)'

npm 12.2.2:

npm notice 2B dist/index.js
npm notice 58B package.json

npm 11.20.0 (and pnpm 12.18.0, bun 1.4.4):

npm notice 2B dist/blog/[slug].js
npm notice 2B dist/index.js
npm notice 58B package.json

Escaping does not help either: "files": ["app/\\[locale\\]/page.js"] also packs nothing from app/[locale]/.

Environment
  • npm: 12.2.2 (bundles npm-packlist 11.3.0, same as npm-packlist main at d1eed617 and npm/cli latest at ab930df8)
  • Node.js: 26.13.0
  • OS Name: Debian, Linux 6.1

Likely cause: processPackage in npm-packlist lib/index.js expands each files entry with globSync and then pushes the matched path back as an ignore rule (!/${rel}) without escaping it, so ignore-walk reads [slug] as a character class and {a,b} as a brace expansion, and the rule no longer matches the file it came from.

Credit: https://ucsbplse.github.io/

主要语言
JavaScript
星标
10.3k
派生
5k
平均合并
4 天 11 小时
30 天内合并 PR
26

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

npm/cli 的其他 Issue

查看 npm/cli 的全部 Issue

相似的 Issue

更多 JavaScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。