npm / npm

This repository is moving to: https://github.com/npm/cli

Home Page:http://npm.community

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Get sizes of installed packages

davej opened this issue · comments

With npm 2.x, I could do easily go into the node-modules folder and inspect a folder to find out the modules' size on disk. With npm 3 and flat deps this isn't possible (it's not that unusual for the node_modules dir of a large project to have 1,000+ directories).

This isn't a big problem for most node applications but when using something like Electron it's important to have a handle on the size of modules so that you can keep the final binary size as small as possible.

Possible API:

> npm size
└── standard@3.13.2     1.54MB
└── fix-path@1.1.0      2.34MB
└── mkdirp@0.5.1        0.43MB
└── node-uuid@1.4.3     1.11MB
> npm size --depth=1
└─┬ standard@3.13.2     1.54MB
│ ├── deglob@1.0.1      0.33MB
│ ├── dezalgo@1.0.3     0.82MB
│ └── ...               x.xxMB
└─┬ fix-path@1.1.0      2.31MB
  ├── ...               x.xxMB
  └── ...               x.xxMB
> npm size standard
└─┬ standard@4.5.4           1.54MB
  ├─┬ deglob@1.0.1           0.33MB
  │ ├─┬ glob@5.0.15          0.11MB
  │ │ ├─┬ inflight@1.0.4     0.04MB
  │ │ │ └── wrappy@1.0.1     0.03MB
  │ │ ├── inherits@2.0.1     0.07MB

Related to #4638, although the scope of this issue is larger.

Another thought on this... it would be best to right-align the module size. That would make it much easier to read and compare sizes. For example.

└── standard@3.13.2       1.54MB
└── fix-path@1.1.0      112.34MB

Well this is in the works: #9920

Thanks @kenany, after looking at #9920 it looks like npm ls --with-sizes is probably better than adding a new size sub-command. It looks like that PR only supports npm install though (not npm ls).

I put together https://github.com/mikermcneil/kit#kit-deps as a stopgap for this in case it's helpful for anyone (cc @davej)

(see also @siddharthkp's cost-of-modules! If you're interested in a rich, deliberate report rather than incidental estimation, his is way better than mine. Also, mine only works on NPM 2... so yeah. There's that.)

@mikermcneil Thanks for the mention! ❤

Also, if you're more interested in the size impact of a module post bundling and minifying, rather than its size on disk, I wrote a small online utility that can tell you that-
https://cost-of-modules.herokuapp.com (not related to @siddharthkp 's awesome package)

EDIT: It's now moved to https://bundlephobia.com

Could you not just use du -sh node_modules or du -sh node_modules/<pkg-name> ?
Assume there's a Windows equivalent too.

@blockspeed

From cost-of-modules readme:

With npm 2.x, it was easy to find how much space is each of your dependencies taking. You could just look at the size of each directory in node_modules

Exactly what you suggested. But,

With npm 3, the packages are installed in flat manner, so it isn't so straightforward.

You will not get the next level dependencies, because it's all flat.

We're closing this issue as it has gone thirty days without activity. In our experience if an issue has gone thirty days without any activity then it's unlikely to be addressed. In the case of bug reports, often the underlying issue will be addressed but finding related issues is quite difficult and often incomplete.

If this was a bug report and it is still relevant then we encourage you to open it again as a new issue. If this was a feature request then you should feel free to open it again, or even better open a PR.

For more information about our new issue aging policies and why we've instituted them please see our blog post.

For those interested, I've created npm-download-size which resolves dependencies and calculates size for tarballs without downloading any packages. The total size of all tarballs gives you a good estimate if a given package is bloated.

The cli tool can be used like this:

$ download-size request
request@2.83.0: 1.08 MiB