Open samardzicneo opened 5 months ago
You can already do that:
for example you can run ./configure --without-npm
--without-npm do not install the bundled npm (package manager)
--without-corepack do not install the bundled Corepack
--without-ssl build without SSL (disables crypto, https, inspector, etc.)
--without-node-options
Run ./configure --help
to see all the flags
You can already do that: for example you can run
./configure --without-npm
--without-npm do not install the bundled npm (package manager) --without-corepack do not install the bundled Corepack --without-ssl build without SSL (disables crypto, https, inspector, etc.) --without-node-options
Run
./configure --help
to see all the flags
Thanks for mentioning those, I'm aware that they exist. Unfortunately, those are basically the only ones available. There is no way to disable http, http2, https, quic, tcp, udp and most other core modules, or, say, compile without the REPL if that makes a difference.
I would be +1 for the addition if someone is interested in sending a PR
@marco-ippolito Unfortunately I'm not at all proficient in C/C++ and don't think I could implement such a thing without making a mess, but I'm gonna try to put something together anyways just to check the feasability and effectiveness of it. If I come up with anything, I'll post an update 👍🏼
I'm not even sure it would be possible. That would require modularizing many of the Node.js internals, which is a huge change.
But it would be awesome
I'm not even sure it would be possible. That would require modularizing many of the Node.js internals, which is a huge change.
Maybe so, and if you're willing to make a proposal/idea, go ahead, but it's no easy feat.
FWIW I've opened a proposal, and I'd love feedback on it.
“Everything is theoretically impossible, until it is done.” – Robert A. Heinlein
Add build-time flags to enable or disable core modules.
One of the main challenges with such an approach is that some internal modules depend on each other. Even if we were able to account for the transitive results of disabling one module for arbitrary core modules, we would then have an exponential number of configurations to support.
With some other languages, the best approach is often to compile everything and to then remove unused code during the linker phase. However, with JavaScript, this is much trickier than with, say, C/C++.
What is the problem this feature will solve?
When building Nodejs as a static library, it might be pointless to include all core modules in the resulting binary. Modules such as crypto, http, http2, http3, https, tls, tcp, udp, etc. all increase the binary size but might not be ever used.
What is the feature you are proposing to solve the problem?
Add build-time flags to enable or disable core modules.
What alternatives have you considered?
Just shipping the fat libnode dylib works fine but it's 90MB+ and that could be cut down pretty far by skipping unused core modules.