npms-io / npms-www

The https://npms.io website
MIT License
245 stars 35 forks source link

[Feature Request] Display package size #219

Open styfle opened 6 years ago

styfle commented 6 years ago

I am considering writing a tool to do this because it might be outside the scope of this project.

There is already https://bundlephobia.com which is great for front end dependencies that get bundled with webpack but it doesn't tell you about the size of dev dependencies such as test frameworks.

There is already a request to add this to npmjs.com here: https://github.com/npm/www/issues/197

Is this a feature that could be used by npms.io? (forgive me if this is the wrong repo)

satazor commented 6 years ago

Yes we could! We actually have downloaders that are able to download the source code as well as the published code: https://github.com/npms-io/npms-analyzer/tree/master/lib/analyze/download

If there's a module that could receive a directory (that contains the code as well as the package.json) and calculate the bundle size, it would be easy to add the feature.

styfle commented 6 years ago

@satazor Thanks for the response!

I am actually working on code now to be able to do this but wanted to make sure I wasn't re-inventing the wheel! https://github.com/styfle/packagephobia

I started going for a web app to make it similar to bundlephobia but really all it does is act as an API for the module you just described.

Would you like me to break out the logic that computes the size into a separate package so you can save the size in your own database?

styfle commented 6 years ago

Here's what I came up with: https://github.com/styfle/packagephobia

styfle commented 6 years ago

@satazor The API is now available 🎉

You can use the npm package name and version (cached result):

https://packagephobia.com/api.json?p=next@5.1.0

Or simply the npm package name which will automatically use the latest version (never cached):

https://packagephobia.com/api.json?p=next

Will this work for npms.io to display a size?

styfle commented 6 years ago

@satazor Do you want to call the API when building stats? How can we move forward with this? Thanks 😄