From 50d2f76075642a87e81aa16bbf1c3381d80a91fa Mon Sep 17 00:00:00 2001 From: Dylan Conway <35280289+dylan-conway@users.noreply.github.com> Date: Sun, 8 Sep 2024 00:56:21 -0700 Subject: [PATCH] fix(pack): don't automatically include `CHANGELOG` when `files` is populated (#13789) --- src/cli/pack_command.zig | 4 +-- test/cli/install/bun-pack.test.ts | 43 +++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 3 deletions(-) diff --git a/src/cli/pack_command.zig b/src/cli/pack_command.zig index 02605e4f5554e5..ee41c8ddaac5a0 100644 --- a/src/cli/pack_command.zig +++ b/src/cli/pack_command.zig @@ -334,9 +334,7 @@ pub const PackCommand = struct { eql(entry_name, "LICENSE") or eql(entry_name, "LICENCE") or eql(entry_name, "README") or - entry_name.len > "README.".len and eql(entry_name[0.."README.".len], "README.") or - eql(entry_name, "CHANGELOG") or - entry_name.len > "CHANGELOG.".len and eql(entry_name[0.."CHANGELOG.".len], "CHANGELOG."))) + entry_name.len > "README.".len and eql(entry_name[0.."README.".len], "README."))) included = true; } diff --git a/test/cli/install/bun-pack.test.ts b/test/cli/install/bun-pack.test.ts index 49b538e722c75f..f9aa414179af66 100644 --- a/test/cli/install/bun-pack.test.ts +++ b/test/cli/install/bun-pack.test.ts @@ -763,6 +763,49 @@ describe("bundledDependnecies", () => { }); describe("files", () => { + test("CHANGELOG is not included by default", async () => { + await Promise.all([ + write( + join(packageDir, "package.json"), + JSON.stringify({ + name: "pack-files-changelog", + version: "1.1.1", + files: ["lib"], + }), + ), + write(join(packageDir, "CHANGELOG.md"), "hello"), + write(join(packageDir, "lib", "index.js"), "console.log('hello ./lib/index.js')"), + ]); + + await pack(packageDir, bunEnv); + const tarball = readTarball(join(packageDir, "pack-files-changelog-1.1.1.tgz")); + expect(tarball.entries).toMatchObject([ + { "pathname": "package/package.json" }, + { "pathname": "package/lib/index.js" }, + ]); + }); + test("cannot exclude LICENSE", async () => { + await Promise.all([ + write( + join(packageDir, "package.json"), + JSON.stringify({ + name: "pack-files-license", + version: "1.1.1", + files: ["lib", "!LICENSE"], + }), + ), + write(join(packageDir, "LICENSE"), "hello"), + write(join(packageDir, "lib", "index.js"), "console.log('hello ./lib/index.js')"), + ]); + + await pack(packageDir, bunEnv); + const tarball = readTarball(join(packageDir, "pack-files-license-1.1.1.tgz")); + expect(tarball.entries).toMatchObject([ + { "pathname": "package/package.json" }, + { "pathname": "package/LICENSE" }, + { "pathname": "package/lib/index.js" }, + ]); + }); test("can include files and directories", async () => { await Promise.all([ write(