Skip to content

Cleanup of the Netlify CLI #156

Open

Description

@v1rtl

Currently it has 107 direct dependencies, and many more non-direct. It's worth cleaning them up.

Modules that can be replaced with other modules:

  • chalk -> picocolors (mainly a size win)
  • chokidar v3 -> v4 upgrade, -11 deps (if I remember correctly)
  • find-up -> empathic, -7 deps
  • dot-prop -> dlv + dset, might be that only one is needed
  • execa -> tinyexec

Modules that can be removed in favor of 1-3 lines of code:

  • is-stream
  • p-filter:
const filteredItems = await Promise.all(
  items.map(async (item) => {
    const shouldKeep = await someAsyncCondition(item); // Replace with your async condition
    return shouldKeep ? item : null;
  })
).then((results) => results.filter((item) => item !== null));
  • p-map, probably could be replaced with Promise.all
  • p-wait-for:
const waitFor = async (condition, interval = 100) => {
  while (!(await condition())) {
    await new Promise((resolve) => setTimeout(resolve, interval));
  }
};
  • through2-filter:
const { Transform } = require('node:stream');

const filterStream = new Transform({
  decodeStrings: false,
  transform(chunk, encoding, callback) {
    if (chunk.includes('foo')) { // Example filter condition
      this.push(chunk);
    }
    callback();
  },
});

process.stdin
  .pipe(filterStream)
  .pipe(process.stdout);
  • from2-array:
const { Readable } = require('node:stream');

const arrayToStream = (array) => {
  return new Readable({
    objectMode: true,
    read() {
      array.forEach((item) => this.push(item));
      this.push(null);
    },
  });
};
  • tempy -> os.tmpdir() + fs.createFile / fs.mkdir
  • hasha -> crypto.createHash('sha512').digest()

PRs:

Activity

  1. pralkarz commented on Jan 28, 2025

    @pralkarz

    Another suggestion: ora -> nanospinner/picospinner.

    Some dev dependencies could be dropped too:

    • is-ci simply exposes a function from ci-info, so it's redundant given that the latter is a regular dependency
    • fs-extra -> node:fs
    • strip-ansi -> node:util (stripVTControlCharacters)
  2. 43081j commented on Jan 28, 2025

    @43081j
    Collaborator

    good issue 🙌

    cc @sarahetter

    another interesting one to look at, but much bigger job, would be moving from express to something like polka (or another fast/light alternative)

    there's a few modern, lightweight node web servers floating around these days. using one could improve the dev server performance and overall CLI size i imagine

  3. v1rtl commented on Jan 28, 2025

    @v1rtl
    Author

    good issue 🙌

    cc @sarahetter

    another interesting one to look at, but much bigger job, would be moving from express to something like polka (or another fast/light alternative)

    there's a few modern, lightweight node web servers floating around these days. using one could improve the dev server performance and overall CLI size i imagine

    shameless plug of tinyhttp, in case you need a smoother transition from express, rather than going hardcore with polka

  4. v1rtl commented on Jan 29, 2025

    @v1rtl
    Author

    Seems like this PR is also related, it bumps a lot of deps and shrinks the lockfile heavily

    netlify/cli#7008

  5. benmccann commented on Jan 29, 2025

    @benmccann
    Collaborator

    Moving to polka is quite easy. It's API compatible with express. You just have to be sure to use the version tagged with next (currently 1.0.0-next.28). The latest version, which is pre-1.0 has a different API. We've been using the next version in SvelteKit and have a good experience with it.

  6. benmccann commented on Jan 29, 2025

    @benmccann
    Collaborator

    Also wanted to mention since this issue doesn't yet that the package we're talking about here is netlify-cli: https://npmgraph.js.org/?q=netlify-cli

    I wonder if it's necessary for it to depend on both fastify and express?

  7. added
    umbrella issue
    on Jan 29, 2025
  8. v1rtl commented on Jan 29, 2025

    @v1rtl
    Author

    Moving to polka is quite easy. It's API compatible with express. You just have to be sure to use the version tagged with next (currently 1.0.0-next.28). The latest version, which is pre-1.0 has a different API. We've been using the next version in SvelteKit and have a good experience with it.

    depends on how they use it. If they use a lot of different request / response extensions, it's not that easy. If it's just res.send and res.json, then yes I agree it's better to move to Polka

  9. sarahetter commented on Jan 29, 2025

    @sarahetter

    Hey all! Thanks for all your investigation here. I'm excited about the potential work & cleanup! ✨

    For the immediate future hold off on submitting PRs as we're actively scoping out a larger project in the netlify-cli and don't want to have any throw-away work.

    I'll keep this issue updated when we have more information.

  10. serhalp commented on Feb 20, 2025

    @serhalp

    👋🏼 Thanks so much for looking into this, folks! I've been working on the Netlify CLI lately and this has been helpful. Let me provide a quick update (and get this collated for my own sake):

    The ones with no comments I'll be knocking out soon I think. But if anyone here feels like grabbing any of them, by all means please go ahead and just give me a heads up! 🙌🏼

    btw if you happen to have any tips about any of these (they're untyped, so we'd love to get rid of them anyway) please let me know 😄:

  11. v1rtl commented on Feb 20, 2025

    @v1rtl
    Author

    I don't think it's worth moving from express to fastify tbh, it's a standalone framework and isn't meant to be consumed by libraries/tools directly. I'd use either polka or tinyhttp. I could send a PR with migrating to tinyhttp if you'd like

  12. Fuzzyma commented on Feb 20, 2025

    @Fuzzyma
    Contributor

    If you need glob support for chokidar, I can release my chokidar-glob package. You would be the first consumer tho. But all tests pass

  13. 43081j commented on Feb 20, 2025

    @43081j
    Collaborator

    thanks a lot for getting the list together @serhalp 🙏

    there's a lot of low hanging fruit on there, easy wins. we should churn those out first and can figure out the larger stuff like express later (though i think you'll have got through most yourself soon)

    depending on the usage of express inside the CLI, i would agree polka or tinyhttp will probably do nicely

    If you need glob support for chokidar, I can release my chokidar-glob package. You would be the first consumer tho. But all tests pass

    i think we should hold off on this until it has been proven out elsewhere. but you raise a point, we should be doing that very soon as we need to unblock the various projects in need of it

  14. benmccann commented on Feb 20, 2025

    @benmccann
    Collaborator

    I noticed a couple of dependencies that could be upgraded to cleanup the graph a bit. E.g. upgrading @vercel/nft would help a fair amount as I've been working on cleaning that up for the past several months

    You can see a list of everything outdated here: https://npmgraph.js.org/?q=netlify-cli#color=outdated

  15. serhalp commented on Feb 21, 2025

    @serhalp

    I don't think it's worth moving from express to fastify tbh, it's a standalone framework and isn't meant to be consumed by libraries/tools directly. I'd use either polka or tinyhttp. I could send a PR with migrating to tinyhttp if you'd like

    @talentlessguy Sounds great, I won't decline that offer! 😄 Even better if it happens to remove the untyped express-logging dep, since I need to tackle that soon too.

  16. 18 remaining items

  17. benmccann commented on Jul 24, 2025

    @benmccann
    Collaborator

    precinct is 76 dependencies and is only called once. It could probably be replaced with something like zimmerframe
    archiver is 64 dependencies is used just once to zip a file and I'd imagine there's a lighter alternative for it as well
    qs is 18 dependencies and should be able to be replaced with something like picoquery (or neoqs if that doesn't work)

  18. 43081j commented on Jul 25, 2025

    @43081j
    Collaborator
  19. 43081j commented on Jul 30, 2025

    @43081j
    Collaborator

    i've updated the gist with a whole bunch of things

    i've tried to add links to the ones that are already done

    if anyone wants to pick up the others, feel free! most are easy

  20. benmccann commented on Aug 6, 2025

    @benmccann
    Collaborator

    @serhalp I was wondering if it might be possible to split the CLI into multiple packages that the CLI consumes? In SvelteKit, we need the serve functionality for our integration tests to ensure that we've built a properly working Netlify app, but we don't need the other commands that the CLI offers. It'd be really nice for us if there were a way to just invoke the serve piece directly. Currently the CLI has 847 dependencies and I'd really like to find a way to avoid needing to install the ones we don't need

  21. serhalp commented on Aug 7, 2025

    @serhalp

    @benmccann hmm, well, in a way we've sort of recently done that in order to build our new Vite plugin. we haven't split it by command but rather we've split all the Netlify platform emulation logic out of CLI into their own packages and then wrapped all those in a new @netlify/dev package: https://github.com/netlify/primitives/tree/main/packages/dev. so far we're using it in our new vite plugin and in our new nuxt module (and we're slowly pulling it back in netlify-cli of course). we're very curious to hear about new use cases! could this be one?

    (we may want to move this discussion elsewhere to avoid derailing the e18e stuff here)

  22. v1rtl commented on Aug 7, 2025

    @v1rtl
    Author

    BTW I'm also working on remove fetch and AC polyfills, but seems like there's some errors in integration tests that I am not sure how to properly resolve, specifically:

    • bad port error (that usually comes from binding on ports disallowed by fetch spec)
    • multipart body comparison, that one I should probably just change the assertions (I already changed it slightly to match the header pattern rather than literal value). built-in fetch randomizes multipart boundary unlike node-fetch
    • random fetch failed with no error description

    netlify/cli#7357

  23. 43081j commented on Aug 7, 2025

    @43081j
    Collaborator

    @outslept just moving the conversation from the gist here

    can you explain the path-scurry/symlink/glob stuff a little more? i didn't quite follow

    we can tell tinyglobby to follow symlinks, can we not? then just archive the results as if they were real files

  24. outslept commented on Aug 7, 2025

    @outslept

    @43081j Great that you tagged me because I was mentally coming back to this. Here's a breakdown for everyone not coming from gist.

    We're talking about netlify/build repo, the current archiver usage in zip-it-and-ship-it does full zip creation with archiver('zip'), the problematic part for replacement is the symlink handling where we check stat.isSymbolicLink() and either call archive.symlink() for symlinks or archive.file() for regular files. From my research there are no libraries that provide anything for working with symlinks in zip creation context (I may be wrong in this). I considered this a blocker and decided to dig deeper into how other projects solve this.

    That's when I discovered VSCode's vsce and how they work with symlinks. Instead of preserving symlinks in the zip file, they use glob('**/*', { follow: true }) to collect files with symlinks already resolved to real files, then use yazl to archive those real files as regular entries.

    The key insight is moving symlink resolution from the archiving phase to the collection phase. You're right about being able to use follow symlinks from tinyglobby. I got fixated on the issue title and mistakenly thought it was a blocker, but that issue doesn't actually affect this use case.

    For context, zip-it-and-ship-it is the core lib behind Netlify Functions - it bundles Node.js, Go, and Rust functions for deployment on AWS Lambda.

    The remaining question is: in this specific case should we preserve symlinks as symlinks in the zip archive, or resolve them to real files during collection phase? I don't know all the depth in this topic and don't wanna break things as it's a different approach to handle symlinks if we compare it to the current one. Completely different..

  25. outslept commented on Aug 7, 2025

    @outslept

    Also worth noting - if this happens, it would be one of the biggest bundle size reductions from the discussion:

    archiver - 6.7MB total size + 73 dependencies
    yazl - 73.77KB total size + 1 dependency

    That's a ~98.9% size reduction 😱

  26. 43081j commented on Aug 7, 2025

    @43081j
    Collaborator

    i understand now 👍

    if we switch to tinyglobby and yazl, we would have to store the files rather than symlinks

    if it's an easy enough change, its probably good to open a draft PR in the netlify repo. If its a lot of effort, an issue would be enough for now. just so we can discuss with the netlify folks if its acceptable to no longer archive links as-is.

  27. benmccann commented on Aug 7, 2025

    @benmccann
    Collaborator

    Really excited to see the work happening towards removing archiver from zip-it-and-ship-it!

    @netlify/dev sounds like a great alternative to netlify serve! I'll continue that discussion in netlify/primitives#406

    Here are some more ideas in the meantime:

    • ipx could probably replace listhen with something lighter like srvx. If staying on listhen it could be cleaned up a bit (Replace clipboardy with lighter alternative unjs/listhen#202)
    • It'd be nice if unstorage and ipx could both drop ofetch. All LTS versions of Node support fetch now
    • It would be nice to see if @parcel/watcher could switch from micromatch to the underlying picomatch. We've seen in tinyglobby that picomatch is just fine for everyone in the real world and have never run into someone needing the functionality in micromatch. Or perhaps it should be replaced by chokidar, which would probably dedupe better
    • We should replace @whatwg-node/server in @netlify/dev-utils. We already have a few other HTTP servers in netlify/build, so don't need yet another
    • I suspect there's a lighter alternative to ajv and better-ajv-errors in @netlify/edge-bundler

    Also, it seems we need to use fix: rather than chore: if we want these changes to be released. My change removing qs has not been released and I'm guessing this is why

  28. pi0 commented on Aug 7, 2025

    @pi0

    Some notes re unjs related deps:

    • I plan a major version of IPX to migrate to the web APIs
      • srvx cli is almost matching all functions we need and is ~100kb install size
    • ofetch is not a fetch polyfill. We certainly drop node-fetch-native sub-dep in the next major (it is 790kB of 890kB, so dropping it makes it much lighter). But likely somehow need dependency on undici for features like Unix socket and proxy
      • (really wish Node.js team would be convienced to at least vendor and export Agent from undici it would save whole ecosystem)
  29. v1rtl commented on Aug 7, 2025

    @v1rtl
    Author

    seconding the ofetch part. Removing node-fetch and others is not as easy when there's usage of http agents and proxies. AFAIK you can't pass a specific agent to node-fetch-native tho, at least I couldn't manage to.

  30. pi0 commented on Aug 7, 2025

    @pi0

    @talentlessguy Feel free to open an issue in node-fetch-native it is strange if you couldn’t pass (legacy node-fetch) agent to it.

    I had briefly talked with undici maintainers. They are (sadly) unlikely to make it ESM/treeshakable to only pick Agent part at least anytime soon. Likely we should make it an optional dep for users need it. (but at least good news recent Node.js 24 supports proxy env)

  31. benmccann commented on Oct 12, 2025

    @benmccann
    Collaborator

    jsonwebtoken could be replaced with jose

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    umbrella issue

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions