Giter VIP home page Giter VIP logo

package-config-checker's Introduction

Package Config Checker

npm package

Tells you things about your dependencies and transitive dependencies.

Usage

npm install -g package-config-checker
Usage: package-config-checker <show> [options]

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

Show:
  -f, --files    show presence of files config or .npmignore
  -r, --recent   show recently updated dependencies

Show Flags

You must specify at least one thing to show.

-f, --files

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.

-r, --recent

Shows the 10 most recently published dependencies - use this if you have a hunch you just got broken by a transitive dependency.

Example

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

$ package-config-checker -f -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

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

Forkers

matheuss

package-config-checker's Issues

False positive scenario: packages with ineffective packaging config

Example: eslint-config-standard has the following.npmignore:

node_modules

  1. node_modules is ignored by default, so .npmignore doesn't really do anything here
  2. The npm package contains a test/ directory, but it's given a green tick because .npmignore exists - having a test/ or tests/ directory should probably always be a negative result (and we should probably have a place to keep a list of prominent repos with module authors who disagree with that ๐Ÿ‘Œ)

Doesn't handle `npm link`'d dependencies

If I have a dependency npm link'd into my node_modules folder, this tool throws. It should ignore those dependencies.

/usr/local/lib/node_modules/package-config-checker/bin/package-config-checker.js:10
var fileExists = require('file-exists')
      ^

TypeError: Path must be a string. Received undefined
    at assertPath (path.js:8:11)
    at Object.posix.join (path.js:479:5)
    at check (/usr/local/lib/node_modules/package-config-checker/bin/package-config-checker.js:65:28)
    at /usr/local/lib/node_modules/package-config-checker/bin/package-config-checker.js:75:5
    at Array.forEach (native)
    at check (/usr/local/lib/node_modules/package-config-checker/bin/package-config-checker.js:74:34)
    at /usr/local/lib/node_modules/package-config-checker/bin/package-config-checker.js:75:5
    at Array.forEach (native)
    at check (/usr/local/lib/node_modules/package-config-checker/bin/package-config-checker.js:74:34)
    at /usr/local/lib/node_modules/package-config-checker/bin/package-config-checker.js:75:5

Only report packages with extraneous files

When listing the packages, I see that quite a few faulty ones (examples, all the lodash.XXX) do not have any extraneous dependencies files, yet no files setting or .npmignore.

Example: the content of node_modules/lodash.find is:

โ”œโ”€โ”€ index.js
โ”œโ”€โ”€ LICENSE
โ”œโ”€โ”€ package.json
โ””โ”€โ”€ README.md

I suggest not reporting those as faulty by default, and to add an option to report those.

Thanks for the tool :)

Add engine checking

  • Check the minimum effective engines based on all your dependencies - log it once at the end with all the packages it applies to
  • Warn if the current package's engines are lower than the effective engines of its dependencies and transitive dependencies

Path error

Trying out your package for first time and am receiving following error

path.js:7
    throw new TypeError('Path must be a string. Received ' + inspect(path));
    ^

TypeError: Path must be a string. Received undefined
    at assertPath (path.js:7:11)
    at Object.join (path.js:1253:7)
    at check (/Users/mikeerickson/.nvm/versions/node/v5.9.1/lib/node_modules/package-config-checker/bin/package-config-checker.js:65:28)
    at /Users/mikeerickson/.nvm/versions/node/v5.9.1/lib/node_modules/package-config-checker/bin/package-config-checker.js:75:5
    at Array.forEach (native)
    at check (/Users/mikeerickson/.nvm/versions/node/v5.9.1/lib/node_modules/package-config-checker/bin/package-config-checker.js:74:34)
    at /Users/mikeerickson/.nvm/versions/node/v5.9.1/lib/node_modules/package-config-checker/bin/package-config-checker.js:75:5
    at Array.forEach (native)
    at check (/Users/mikeerickson/.nvm/versions/node/v5.9.1/lib/node_modules/package-config-checker/bin/package-config-checker.js:74:34)
    at /Users/mikeerickson/.nvm/versions/node/v5.9.1/lib/node_modules/package-config-checker/bin/package-config-checker.js:54:3
 โœ˜ ๎‚ฐ ~/Documents/Projects/angular-sandbox ๎‚  master ๎‚ฐ
 $

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.