Skip to content

⚡️ Performance: Replace glob package with built-in node:fs .glob #5962

Description

@JoshuaKGoldberg

Performance Suggestion Checklist

Overview

Mocha right now uses glob internally for file pattern shell matching. Node.js >=22 has its own fs.glob + https://nodejs.org/api/fs.html#fspromisesglobpattern-options that we could use to remove that dependency altogether. That would make Mocha have a smaller node_modules/ install size and be more in line with what is now the first-party Node.js way to do globs.

Proposal: let's do this as part of Mocha 13? Note that it'd require dropping support for Node.js 20 as a breaking change.

Validations

I set up a basic reproduction in https://github.com/JoshuaKGoldberg/repros/tree/mocha-dependencies-with-and-without-glob. Tl;dr:

  • Without: 4.9M
  • With: 10M

That's quite the savings!

Additional Info

See #5785 for past discussion around replacing glob. The previous suggestion was to use a much smaller glob library, i.e. tinyglobby. We'd resolved not to take on #5785 because:

  • tinyglobby has known missing support for some edge cases handled by glob (which partially explains why glob is larger!)
  • Node.js 20 just exited LTS, so the big glob change is no longer blocked on LTS major version support (just now-non-LTS)

Metadata

Metadata

Assignees

No one assigned

    Labels

    semver-majorimplementation requires increase of "major" version number; "breaking changes"status: accepting prsMocha can use your help with this one!type: performancePerformance improvements

    Type

    No type

    Projects

    Status
    No status

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions