Furthermore, it would be quite irritating if it started assuming specific file extensions are forbidden instead of using the explicit list provided by the author.
I ported it to bash really quick, as thats probably easier for people to drop into their dotfiles if they don't have a Golang env setup.
https://gist.github.com/gpittarelli/64d1e9b7c1a4af762ec467b1...
If we all just do our part and send a PR setting up .npmignore for one or two of these projects, maybe we won't need this anymore
https://www.npmjs.com/package/download-size
The tool is available online too:
Update: I see now it's written in go... :-P
That being said, it would be great if npm had some functionality around packaging only the necessary files for actually running the module and removing all unnecessary files (tests, source code, documentation) and have an opt-in option to install those.
Reading the code[1] it appears to delete directories and extensions based on a blacklist.
1. https://github.com/tj/node-prune/blob/master/prune.go#L15-L5...
Doesn't this also result in .d.ts files being removed? These are type declaration files (Kinda like C's .h files) that provide types for you without the file size overhead of the full TypeScript source.
I mean, kudos for helping push node module developers to make better use of `.npmignore` et al, but this project strikes me as overly snarky or even trolling...
Seems like what we really need is for some volunteers to tackle the most-installed packages on npm that publish with many extraneous files.
Hell, you could even automate it by writing a bot that (politely) points out likely-extraneous files and opens a pull request with changes to `.npmignore` to clean things up... Hmm... Weekend project brewing...
do the same job? Why project in go?
But these small-software situations amaze me. Someone with a node_modules problem will have readily available sh, node and maybe python. So why golang? What could those not do, or golang can do better to such extent that it trumps availability? Similarly there's a price to pay in terms of people contributing with a fix: who is interested in pruning node_modules and will send in a golang PR?
In other words, if a dev would prefer Java (specifically chosen because it exacerbates the startup time), would it still pass as ok? Luckily golang can compile to binaries but that implies you give up availability on the other end, now being confined to someone compiling and publishing on a regular basis, as opposed to just pushing a fix commit to a git url.
None of the above would be of importance if this would be a personal-quality repo with a note: hey i did this at 2am out of frustration, i chose the tools that i knew best, use it at your own risk, opensourced to share knowledge and to access it from my own projects, not as a "productified" software.
EDIT: I would much prefer a commenter's solution in sh for the reasons above but also readibility: https://gist.github.com/gpittarelli/64d1e9b7c1a4af762ec467b1... :clap:
// Copied from yarn (mostly).
I infer that TJ used `yarn autoclean` as a starting point for this.The caveats is that this won’t work 100% of the time. There will be a dependency deep down in the tree that needs to read a markdown file from the file system or something of that sort. These issues could be hard to debug if this tool doesn’t provide good visibility into what’s being deleted.
Glad to see more of his work!
Edit: It's Go lol.
Edit: lightened up (;
*
!dist/**/*