Giter VIP home page Giter VIP logo

package-config-checker's Introduction

Package Config Checker

npm package

Checks if your npm dependencies (and transitive dependencies) have files config in package.json or have an .npmignore file to avoid including unnecessary files when your module is being packaged for publishing to the npm registry.

Since npm automatically whitelists certain essential files and blacklists common files which should not be included in module packages (such as source control directories, npm-debug.log and .DS_Store), submitting a Pull Request to one of your dependencies to add a files whitelist to its package.json is a quick and easy way to reduce the size of your - and everybody else's - npm install.

Usage

npm install -g package-config-checker
Usage: package-config-checker

Options:
  -h, --help     display this help message
  -d, --depth    max depth for checking dependency tree (default: โˆž)

Example

Checking package-config-checker's own direct dependencies as an example:

$ package-config-checker -d 0

[email protected] has been flagged as not having any configuration to control publishing.

Let's look at what was included in its npm packge:

$ ls -a node_modules/minimist/
./   .travis.yml  index.js  package.json     test/
../  example/     LICENSE   readme.markdown

It includes example/ and test/ directories, and a Travis CI config file, which most likely aren't required to use minimist. These take up an additional 18.2 KB of space, which isn't really a big deal in absolute terms.

Let's package the module up again and rename the resulting file so we can compare later.

$ cd node_modules/minimist/
$ npm pack
minimist-1.2.0.tgz
$ mv minimist-1.2.0.tgz minimist-1.2.0-pre.tgz

Now let's add suitable files config to package.json:

  "files": [
    "index.js"
  ],

If we repackage the module, npm will now use the files config.

Listing the contents of the new package shows an example of the default files npm whitelists in addition to the module-specific whitelist we provided:

$ npm pack
minimist-1.2.0.tgz
$ tar -tf minimist-1.2.0.tgz
package/package.json
package/LICENSE
package/index.js
package/readme.markdown

Now we can compare the before and after size of the package which would be published to npm:

$ ls *.tgz -l | awk '{print $9,$5}'
minimist-1.2.0.tgz 4300
minimist-1.2.0-pre.tgz 7984

That's approximately 3.6 KB less to download.

The bandwith and node_modules/ savings in this example are fairly insignificant per install, but at the time of writing minimist has been downloaded from npm 27,095,636 times in the last month.

The reduced package size would have resulted in a 93GB bandwith saving for the npm registry for that number of downloads.

Now that we've done the research, the final step is to create a Pull Request with the packaging config changes.

You can do this by editing package.json directly from the GitHub UI, which will fork the project for you in the background and let you create a Pull Request at the same time.

MIT Licensed

package-config-checker's People

Contributors

insin avatar matheuss avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.