npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@masnagam/npm-diet

v0.4.0

Published

A tool to help keeping your package slim

Downloads

4

Readme

@masnagam/npm-diet

A tool to help keeping your package slim

npm version Build Status Build status Codacy Badge Maintainability Test Coverage

npm-diet is a CLI tool comprised of several commands which can be used for analyzing the total size of NPM packages installed.

npm-diet can not be used for analyzing the size of a web application bundle. Try to use the following tools for such purpose.

Installation

$ npm install -g @masnagam/npm-diet

How does this work?

Very simple:

  1. Install specified packages using npm install
  2. Correct installed packages using npm ls --parseable
  3. Traverse directories in each package, and compute the sum of file sizes

See lib/analyze/measure.js.

Limitations

There are some limitations at this moment:

  • npm-diet measure does not take account of sizes of directories
  • npm-diet measure does not compute actual sizes on disk

Typical usages

Show a brief summary of an analysis:

$ npm-diet measure del | npm-diet summary
#PKGS  SIZE       #FILES  #DUPS  DUP      %DUP
-----  ---------  ------  -----  -------  ------
   30  885.02 KB     178      1  6.80 KB  0.77 %

Show details of duplicates:

$ npm-diet measure del | npm-diet show dup --package-path
PACKAGE     SIZE     %SIZE     #FILES  PATH
----------  -------  --------  ------  -------------------------------------
[email protected]  8.11 KB                 4  node_modules/pify
----------  -------  --------  ------  -------------------------------------
[email protected]  6.80 KB  100.00 %       4  node_modules/globby/node_modules/pify
----------  -------  --------  ------  -------------------------------------
TOTAL 1     6.80 KB  100.00 %       4

Show the top 3 packages in descending order of size:

$ npm-diet measure livereload | npm-diet show measure --top=3
PACKAGE            SIZE       %SIZE    #FILES
-----------------  ---------  -------  ------
[email protected]   750.73 KB  14.25 %      19
[email protected]         408.59 KB   7.75 %      46
[email protected]  328.75 KB   6.24 %      26
-----------------  ---------  -------  ------
TOP 3                1.45 MB  28.24 %      91
TOTAL 205            5.15 MB             1306

Specify multiple packages:

$ npm-diet measure mocha chai sinon | npm-diet summary
#PKGS  SIZE      #FILES  #DUPS  DUP        %DUP
-----  --------  ------  -----  ---------  ------
  134  15.16 MB    2252     13  326.00 KB  2.10 %

Process the analysis result with jq:

$ npm-diet measure commander | jq '.packages[].files[] | .path, .size'
"CHANGELOG.md"
11086
"LICENSE"
1098
"Readme.md"
12783
"index.js"
27883
"package.json"
1834
"typings/index.d.ts"
8508

Use a package.json file for analysis:

$ cat package.json
{
  ...
  "dependencies": {
    "npm-run-all": "^4.1.3",
    "rimraf": "^2.6.2"
  }
}

$ npm-diet pkg-deps package.json | npm-diet measure --stdin | \
    npm-diet summary
#PKGS  SIZE     #FILES  #DUPS  DUP  %DUP
-----  -------  ------  -----  ---  ------
   66  1.40 MB     596      0  0 B  0.00 %

Replace rimraf with del:

$ echo '["npm-run-all","rimraf"]' | \
    npm-diet measure --stdin _rimraf del | npm-diet summary
#PKGS  SIZE     #FILES  #DUPS  DUP       %DUP
-----  -------  ------  -----  --------  ------
   85  2.11 MB     720      3  22.43 KB  1.04 %

Show delta values between two package sets:

$ (npm-diet measure chalk ; npm-diet measure colors) | \
    npm-diet delta --stdin | npm-diet summary
LABEL             #PKGS  %PKGS     SIZE       %SIZE     #FILES  %FILES
----------------  -----  --------  ---------  --------  ------  --------
BASELINE (chalk)      7             90.44 KB                38
SUBJECT (colors)      1             37.53 KB                21
----------------  -----  --------  ---------  --------  ------  --------
DELTA                -6  -85.71 %  -52.91 KB  -58.51 %     -17  -44.74 %

Show details of a delta analysis:

$ (npm-diet measure mini-lr ; npm-diet measure tiny-lr) | \
    npm-diet delta --stdin | npm-diet show delta --top=3
INCREASE                SIZE       %SIZE    #FILES
----------------------  ---------  -------  ------
[email protected]           206.88 KB  70.85 %  41
[email protected]              19.22 KB   6.58 %   13
[email protected]             18.22 KB   6.24 %   14
----------------------  ---------  -------  ------
TOP 3                   244.32 KB  83.67 %  68
TOTAL 9                 292.00 KB           113

DECREASE                SIZE       %SIZE    #FILES
----------------------  ---------  -------  ------
[email protected]       325.28 KB  43.68 %  27
[email protected]          184.85 KB  24.82 %  6
[email protected]      47.31 KB   6.35 %   10
----------------------  ---------  -------  ------
TOP 3                   557.44 KB  74.85 %  43
TOTAL 16                744.73 KB           131

COMMON                  SIZE       %SIZE    #FILES
----------------------  ---------  -------  ------
[email protected]     88.21 KB   16.61 %  14
[email protected]                73.40 KB   13.82 %  18
[email protected]  66.26 KB   12.48 %  18
----------------------  ---------  -------  ------
TOP 3                   227.88 KB  42.91 %  50
TOTAL 15                531.02 KB           157

Data Models

The following data structures are still under consideration. They may be changed in the near future.

Measure Analysis

{
  "type": "measure",
  "specs": [ ... ],    // list of package specifiers
  "numPkgs": 1,        // the number of packages
  "size": 61750,       // sum of package sizes
  "numFiles": 6,       // sum of the numbers of files
  "packages": [ ... ]  // list of packages
}

Delta Analysis

{
  "type": "delta",
  "baseline": { ... },  // analysis of the baseline package set
  "subject": { ... },   // analysis of the subject package set
  "delta": { ... },     // delta values (metrics withtout `packages`)
  "increase": { ... },  // metrics of added packages
  "decrease": { ... },  // metrics of removed packages
  "common": { ... }     // metrics of common packages
}

Duplicate Analysis

{
  "type": "duplicate",
  "specs": [ ... ],      // list of package specifiers
  "numPkgs": 2,          // the number of duplicate packages
  "size": 14955,         // sum of duplicate sizes
  "numFiles": 8,         // sum of the numbers of files
  "duplicates": [ ... ]  // list of duplicates
}

Package Specifier

{
  "name": "@masnagam/npm-diet",  // package name
  "detail": "*"                  // semver, url or local path
}

Metrics

Subsequent analysers may add other metrics.

{
  "numPkgs": 1,        // the number of packages
  "size": 61750,       // sum of package sizes
  "numFiles": 6,       // sum of the numbers of files
  "packages": [ ... ]  // list of packages
}

Duplicate

{
  "name": "pify",      // name
  "size": 14955,       // sum of duplicate sizes
  "numFiles": 8,       // sum of the number of files
  "packages": [ ... ]  // list of packages
}

Package

{
  "name": "commander",              // name
  "version": "2.16.2",              // version
  "size": 61750,                    // sum of file sizes
  "files": [ ... ],                 // list of files
  "path": "node_modules/commander"  // relative path to the package
}

File

{
  "path": "CHANGELOG.md",  // relative path from the package dir
  "size": 10068            // file size in bytes
}

Great predecessors

License

This software is distributed under the Apache license 2.0. See LICENSE file for details.