Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce package size #16

Merged
merged 1 commit into from
May 15, 2024
Merged

Reduce package size #16

merged 1 commit into from
May 15, 2024

Conversation

scotttrinh
Copy link
Contributor

@scotttrinh scotttrinh commented May 10, 2024

Avoids bundling large files like the changelog into the distributed package.

Unpacked size: 45.5 kB -> 12.3 kB
Packaged size: 15.7 kB -> 5 kB

Before:

npm pack --dry-run
npm notice
npm notice 📦  shell-quote@1.8.1
npm notice === Tarball Contents ===
npm notice 493B   .eslintrc
npm notice 582B   .github/FUNDING.yml
npm notice 229B   .nycrc
npm notice 21.7kB CHANGELOG.md
npm notice 1.1kB  LICENSE
npm notice 3.6kB  README.md
npm notice 128B   example/env.js
npm notice 106B   example/op.js
npm notice 118B   example/parse.js
npm notice 109B   example/quote.js
npm notice 87B    index.js
npm notice 1.8kB  package.json
npm notice 5.2kB  parse.js
npm notice 457B   quote.js
npm notice 295B   security.md
npm notice 642B   test/comment.js
npm notice 483B   test/env_fn.js
npm notice 1.9kB  test/env.js
npm notice 3.1kB  test/op.js
npm notice 1.4kB  test/parse.js
npm notice 1.4kB  test/quote.js
npm notice 565B   test/set.js
npm notice === Tarball Details ===
npm notice name:          shell-quote
npm notice version:       1.8.1
npm notice filename:      shell-quote-1.8.1.tgz
npm notice package size:  15.7 kB
npm notice unpacked size: 45.4 kB
npm notice shasum:        1e24f9b8fdc41b7c006d3efa6a94a0fa37f84a71
npm notice integrity:     sha512-ahgRvFkK1QU7C[...]k7EfVOHB4N27g==
npm notice total files:   22
npm notice
shell-quote-1.8.1.tgz

After:

npm pack --dry-run
npm notice
npm notice 📦  shell-quote@1.8.1
npm notice === Tarball Contents ===
npm notice 1.1kB LICENSE
npm notice 3.6kB README.md
npm notice 87B   index.js
npm notice 1.8kB package.json
npm notice 5.2kB parse.js
npm notice 457B  quote.js
npm notice === Tarball Details ===
npm notice name:          shell-quote
npm notice version:       1.8.1
npm notice filename:      shell-quote-1.8.1.tgz
npm notice package size:  5.0 kB
npm notice unpacked size: 12.3 kB
npm notice shasum:        452f8420a04b0105f9ac07200a8a35270ce13802
npm notice integrity:     sha512-5OlDuabL6IX/F[...]MoW/nSy7BNO7g==
npm notice total files:   6
npm notice
shell-quote-1.8.1.tgz

After including tests back in the package contents:

npm notice
npm notice 📦  shell-quote@1.8.1
npm notice === Tarball Contents ===
npm notice 582B  .github/FUNDING.yml
npm notice 1.1kB LICENSE
npm notice 3.6kB README.md
npm notice 87B   index.js
npm notice 1.8kB package.json
npm notice 5.2kB parse.js
npm notice 457B  quote.js
npm notice 295B  security.md
npm notice 642B  test/comment.js
npm notice 483B  test/env_fn.js
npm notice 1.9kB test/env.js
npm notice 3.1kB test/op.js
npm notice 1.4kB test/parse.js
npm notice 1.4kB test/quote.js
npm notice 565B  test/set.js
npm notice === Tarball Details ===
npm notice name:          shell-quote                        
npm notice version:       1.8.1                              
npm notice filename:      shell-quote-1.8.1.tgz              
npm notice package size:  7.7 kB                             
npm notice unpacked size: 22.6 kB                            
npm notice shasum:        10ffd15b781fa40af0826200d9114e63962db220
npm notice integrity:     sha512-9patS5xjm4tgs[...]ZK2kBuKah+e7g==
npm notice total files:   15                                 
npm notice
shell-quote-1.8.1.tgz

Copy link
Owner

@ljharb ljharb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As written, this excludes way more than just the changelog - tests must always be included in the published package.

package.json Outdated Show resolved Hide resolved
@ljharb ljharb marked this pull request as draft May 10, 2024 21:28
@scotttrinh
Copy link
Contributor Author

tests must always be included in the published package.

While this is a perfectly fine stance to hold (your package after all!), I'm not sure I understand why a published package should include tests since consumers wouldn't be running tests for packages (most test dependencies would be dev dependencies, no?).

If you want files ignored, add them to the publishConfig.ignore list below.

Yeah, I considered that, but I thought it was better to allow-list than deny-list certain files. This package is used by a lot of other packages, so reducing the package size of this one package down will reduce packaging size and distribution bandwidth of the overall npm ecosystem a lot, so seems worth having the smallest reasonable package size.

I'll update to liberally use .npmignore and let me know your feedback on which files you absolutely think need to be included in the 14 million weekly downloads this package has 😅

@scotttrinh
Copy link
Contributor Author

Including the tests in the package contents makes the change less dramatic, but still an overall win at 50% savings:

Unpacked size: 45.5 kB -> 12.3 kB -> 22.6 kB
Packaged size: 15.7 kB -> 5 kB -> 7.7 kB

@scotttrinh scotttrinh requested a review from ljharb May 15, 2024 00:55
@scotttrinh scotttrinh marked this pull request as ready for review May 15, 2024 00:55
@ljharb
Copy link
Owner

ljharb commented May 15, 2024

Also, it’s not package authors’ responsibility to manage package size and distribution bandwidth, it’s npm’s, and npm has chosen not to consider this a priority (by implementing separate “full” vs “minimal” tarballs for a single package)

package.json Outdated Show resolved Hide resolved
package.json Show resolved Hide resolved
package.json Outdated Show resolved Hide resolved
@scotttrinh
Copy link
Contributor Author

Also, it’s not package authors’ responsibility to manage package size and distribution bandwidth, it’s npm’s, and npm has chosen not to consider this a priority (by implementing separate “full” vs “minimal” tarballs for a single package)

Man, I'm learning so much here: I can't find any reference about this anywhere either (my Google-fu is weak tonight...) and when I install shell-quote in my own environment, I get all of the included files.

Maybe the minimal change that we can both agree to here is excluding the changelog? But then again, if it's not the package author's responsibility, we can also just close this PR as won't fix, no hard feelings. 🤝

@scotttrinh scotttrinh requested a review from ljharb May 15, 2024 01:17
@scotttrinh
Copy link
Contributor Author

Latest changes:

Unpacked size: 45.5 kB -> 12.3 kB -> 22.6 kB -> 23.3 kB
Packaged size: 15.7 kB -> 5 kB -> 7.7 kB -> 8.0 kB

Copy link
Owner

@ljharb ljharb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’m fine with this change, thanks.

@ljharb ljharb merged commit 4044e7f into ljharb:main May 15, 2024
371 of 373 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants