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

Đang mở
#10,260 1 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 2 ngày

@1AbdullahButt đang làm issue này rồi.

Từ ngày 8/11/2026.

  • #304 của @1AbdullahButt — đang mở

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
66/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
javascript, node.js
Lĩnh vực
build-system, tooling

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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/

Ngôn ngữ chính
JavaScript
Star
10.3k
Fork
5k
Merge trung bình
4 ngày 11 giờ
Pull request đã merge (30 ngày)
26

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của npm/cli

Tất cả issue của npm/cli

Issue tương tự

Thêm issue về JavaScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.