fix(pack): Now dedups paths in package.json bin field

NI
2mo ago
+43-0

What does this PR do?

It dedups files during the pack operation.

The use case that wasn't handled before is when the same binary file can have many links pointing to it. Like one binary alias is full and human-readable, and the other is a short alias to access the same binary.

How did you verify your code works?

  • built local version
  • wrote and ran tests
  • packaged my ali-token-summary with the newly built bun and confirmed npm reports a smaller size
Before: bun pm pack --dry-run
bun pack v1.3.14 (0d9b296a)

packed 1.0KB package.json
packed 8.19KB README.md
packed 247.73KB dist/minified/index.mjs
packed 247.73KB dist/minified/index.mjs

ali-token-summary-0.1.4.tgz

Total files: 4
Shasum: f7166e56b063baf954f085e7594a96318b24f060
Integrity: sha512-PddeIzG52zmML[...]fiPrQerJa5djg==
Unpacked size: 0.50MB
Packed size: 164.59KB
After: /home/evadev/projects/bun/build/debug/bun-debug pm pack --dry-run
bun pack v1.3.14 (b3679c6af)
[loop] inc 2 + 1 = 3
[cachefs] openat(16[/home/evadev/projects/ali-token-summary], /home/evadev/projects/ali-token-summary/package.json) = 17[/home/evadev/projects/ali-token-summary/package.json]
[sys] close(17[/home/evadev/projects/ali-token-summary/package.json])
[cachefs] openat(16[/home/evadev/projects/ali-token-summary], /home/evadev/projects/ali-token-summary/tsconfig.json) = 17[/home/evadev/projects/ali-token-summary/tsconfig.json]
[sys] close(17[/home/evadev/projects/ali-token-summary/tsconfig.json])

packed 1.0KB package.json
packed 8.19KB README.md
packed 247.73KB dist/minified/index.mjs

ali-token-summary-0.1.4.tgz

Total files: 3
Shasum: b366115f9024a9f686f6b28830bc023fc93590ee
Integrity: sha512-CaytQG2xYs1g3[...]DdbGdtgYhMXdw==
Unpacked size: 256.94KB
Packed size: 84.28KB
$ curl -s https://registry.npmjs.org/ali-token-summary | fx 'Object.fromEntries(Object.entries(this.versions).map(([v, d]) => [v, d.dist.unpackedSize]))'
{
  "0.1.0": 507082,
  "0.1.1": 507058,
  "0.1.2": 507008,
  "0.1.3": 504675,
  "0.1.4": 256944
}