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

[meta] Remove non-essential files from npm package #77

Closed
wants to merge 1 commit into from

Conversation

david-allison
Copy link

@david-allison david-allison commented Feb 4, 2025

This change leads to a ~3x reduction in package size, and ~5x reduction in on-disk size via using https://docs.npmjs.com/cli/v11/configuring-npm/package-json#files

I noticed minimist 1.2.8 looked larger than necessary in node_modules:

Screenshot 2025-02-04 at 12 39 47

Context

Before this change, the npmignore package was used to generate a .npmignore file from the .gitignore of the repo.

The files that this misses are below, and an allowlist approach seemed more maintainable, given index.js is the only file you use.

Change introducing this: f81ece6

Change

Removes:

  • .github/
  • example/
  • test/
  • .eslintrc
  • .nycrc
  • CHANGELOG.md
    • Some people online say that this would still be included. The output of npm pack --dry-run disagrees

Testing

npm pack --dry-run

Before

note: output changed a little since making the commit message

npm notice === Tarball Contents === 
npm notice 598B   .eslintrc             
npm notice 592B   .github/FUNDING.yml   
npm notice 229B   .nycrc                
npm notice 22.1kB CHANGELOG.md          
npm notice 1.1kB  LICENSE               
npm notice 3.8kB  README.md             
npm notice 91B    example/parse.js      
npm notice 99B    example/parse.mjs     
npm notice 6.3kB  index.js              
npm notice 1.7kB  package.json          
npm notice 1.0kB  test/all_bool.js      
npm notice 2.4kB  test/array.js         
npm notice 3.6kB  test/bool.js          
npm notice 1.2kB  test/dash.js          
npm notice 713B   test/default_bool.js  
npm notice 766B   test/dotted.js        
npm notice 660B   test/kv_short.js      
npm notice 649B   test/long.js          
npm notice 792B   test/num.js           
npm notice 237B   test/parse_modified.js
npm notice 4.1kB  test/parse.js         
npm notice 2.2kB  test/proto.js         
npm notice 1.3kB  test/short.js         
npm notice 312B   test/stop_early.js    
npm notice 2.1kB  test/unknown.js       
npm notice 194B   test/whitespace.js    
npm notice === Tarball Details === 
npm notice name:          minimist                                
npm notice version:       1.2.8                                   
npm notice filename:      minimist-1.2.8.tgz                      
npm notice package size:  16.6 kB                                 
npm notice unpacked size: 59.0 kB                                 
npm notice shasum:        832f0fdc2f2fa34eae9f83aeaf4915251605ce76
npm notice integrity:     sha512-PxfINY93zIY6y[...]h9nt9UIkIOm9A==
npm notice total files:   26     

After

npm notice === Tarball Contents === 
npm notice 1.1kB LICENSE     
npm notice 3.8kB README.md   
npm notice 6.3kB index.js    
npm notice 1.6kB package.json
npm notice === Tarball Details === 
npm notice name:          minimist                                
npm notice version:       1.2.8
npm notice filename:      minimist-1.2.8.tgz
npm notice package size:  4.9 kB
npm notice unpacked size: 12.9 kB
npm notice shasum:        4a3e9fcc22cc0dd250705d0991913dd4b414a062
npm notice integrity:     sha512-6N2v+Q/KAOLab[...]W8lvhg4jUI69A==
npm notice total files:   4

~3x reduction in package size. ~5x reduction in on-disk size

https://docs.npmjs.com/cli/v11/configuring-npm/package-json#files

Reverts minimistjs@f81ece6
Removes:

* .github/
* example/
* test/
* .eslintrc
* .nycrc
* CHANGELOG.md

```
npm pack --dry-run
```

**Before**

```
=== Tarball Details ===
package size:  16.6 kB
unpacked size: 59.0 kB
total files:   26
```

**After**

```
=== Tarball Contents ===
1.1kB LICENSE
3.8kB README.md
6.3kB index.js
1.6kB package.json
=== Tarball Details ===
package size:  4.9 kB
unpacked size: 12.9 kB
total files:   4
```
Copy link
Member

@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.

The tests are very necessarily published to npm; npm explore foo && npm install && npm test should always work.

Separately, the files field is dangerous and should never be used - the proper way to control what gets published is an npmignore file.

@ljharb
Copy link
Member

ljharb commented Feb 4, 2025

Duplicate of #73.

@ljharb ljharb closed this Feb 4, 2025
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