giget icon indicating copy to clipboard operation
giget copied to clipboard

Reduce dependencies for programmatic usage

Open bluwy opened this issue 5 months ago • 2 comments

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?

bluwy avatar Oct 01 '25 02:10 bluwy

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_PROXY when HTTP_PROXY env exists by forking process (or guide users using it as workaround)

pi0 avatar Oct 01 '25 07:10 pi0

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.

bluwy avatar Oct 01 '25 10:10 bluwy

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

pi0 avatar Jan 20 '26 13:01 pi0

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.

bluwy avatar Jan 20 '26 13:01 bluwy