Reduce dependencies for programmatic usage
Describe the feature
Context: https://bsky.app/profile/pi0.io/post/3m22qguxfm22w
Currently they're a few libraries that only utilizes the programmatic downloadTemplate API, e.g. create-astro, create-hono, @storybook/cli, etc. However, they don't require some CLI deps like citty, consola, etc, or also not need nypm to install dependencies.
It would be nice to be able to trim them, or have a separate programmatic core package, or any solution in mind to support this case. Understandably, the deps currently isn't a lot nor large in size (2MB total), but as create-* CLIs, reducing as much as possible helps users to start projects quickly.
I've made a "core package" fork at https://github.com/bluwy/giget-core for create-astro that may be used as inspiration. I took some changes a bit to the extreme, but maybe some parts can be ported back here.
Additional information
- [x] Would you be willing to help implement this feature?
For context, we initially made giget for nuxi init, which was a zero dep CLI and with only giget.downloadTemplate export bundled + native fetch; it is ~ 95kB / 31kB gzip (bundlejs).
Speed for create-* CLIs matters a lot, and for this, making sure they are zero dependency is important; otherwise, lots of extra files like type declarations and this case, unrelated deps will still be pulled in.
Proxy support is also important for starter users from restricted regions when they need a VPN to access GitHub.
I think we can do better still for the next major without many compromises to also benefit cases dep used as an external dep for create-clis.
- consola might be replaced with a simple console
- We can bundle/tree-shake citty, nypm, defu, and pathe
- To use native fetch, we can somehow force
NODE_USE_ENV_PROXYwhenHTTP_PROXYenv exists by forking process (or guide users using it as workaround)
For defu, couldn't we use spreads (or just manual assignments), and for pathe use node:path? I personally prefer to not bundle dependencies unless only a small portion of it is used, and it seems like the library is using much of citty and nypm. It's also not possible to treeshake away nypm as it's behind a dynamic install option if the downstream create-* CLI decides to bundle everything.
For proxies, I agree that we should keep support for it. I'd do the same for my fork if the support wasn't too complex, but I haven't revisited it recently.
giget@v3 now reduced to ~146kB with almost all previous features!
Bundling sometimes significantly helps to reduce total install size.
Biggest chunk in deps is still tar (v7) now taking ~96kB!!! But I still trust it more as it is very widely audited.
4.0K dist/_chunks/libs/chownr.mjs
8.0K dist/_chunks/libs/citty.mjs
20K dist/_chunks/libs/@isaacs
8.0K dist/_chunks/libs/minizlib.mjs
20K dist/_chunks/libs/nypm.mjs
64K dist/_chunks/libs/tar.mjs
Nice! For tar, I've been using modern-tar and it seems to be working well. That said I'm using several majors behind.. but it works 😬 I need to find some time to update it.