Live data from Hacker News

Show HN: Node.js node_modules file pruning

github.com

41–50 of 66 posts

Re: Show HN: Node.js node_modules file pruning

#42

Usually I don't care about what language an executable is written in. After all, as a user I'm just interested in whether it executes or not. 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…

Man it's free code, you're reading into this far too much.

Re: Show HN: Node.js node_modules file pruning

#43
post #15

Love it. Saved 600MB... and test cases still passed :) 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

Great. I wrapped your script into npm package https://www.npmjs.com/package/node-prune

Re: Show HN: Node.js node_modules file pruning

#44

Shouldn't this be handled entirely by npm? If these files are unnecessary why do they get downloaded in the first place?

No it should NOT be handled by npm. Imagine some npm project really needs those files. Like module that is rendering markdown files to html. If npm would be that "smart" to strip your .md files, you would be pissed and blame npm. NPM is awesome as is. It's developer responsibility to write proper .npmignore, because only him/her knows what can be excluded.

Re: Show HN: Node.js node_modules file pruning

#45

No disrespect to TJ (he did many awesome projects I use almost daily), but wouldn't simple: 'find node_modules -not -regex ".*.[js,json]" -delete' do the same job? Why project in go?

Maybe it's meta satire :D

ok then my comment can be forgotten. :D

Re: Show HN: Node.js node_modules file pruning

#46
post #43
post #15

Love it. Saved 600MB... and test cases still passed :) 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

Great. I wrapped your script into npm package https://www.npmjs.com/package/node-prune

And here is a project that helps you decide upfront if you should rely on that bloated module:

https://www.npmjs.com/package/download-size

The tool is available online too:

https://arve0.github.io/npm-download-size/

Re: Show HN: Node.js node_modules file pruning

#47
post #14

Awesome idea. Especially if you’re packaging your projects via something like Docker this can shave hundreds of megabytes. (Even if you’re using the Docker layer cache, any change to your dependencies will bust the entire node_modules cache.) 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 th…

you're looking for `yarn autoclean`. they have `.yarncleanrc` IIRC

Re: Show HN: Node.js node_modules file pruning

#48

Usually I don't care about what language an executable is written in. After all, as a user I'm just interested in whether it executes or not. 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…

Man it's free code, you're reading into this far too much.

I'm trying really hard to see what price has to do with anything I've said.

Re: Show HN: Node.js node_modules file pruning

#49
post #2

Rather than two giant 440px high images consisting of tiny text in the readme I'd quite love to read exactly what it does and why. Does it prune files in modules that are not needed? If so what heuristics does it use to prune files? Or does it prune modules that are not needed? Reading the code[1] it appears to delete directories and extensions based on a blacklist. 1. https://github.com/tj/node-prune/blob/master/pru…

It looks like it removes the files necessary for "npm install" assuming that the module will do npm install immediately when you install it. This is not true for all cases though..which is why the files should be kept around. Disk space is cheap. This isn't bad for deployments though.

It's especially good for deployments to AWS Lambda.
Post reply on HN