purescript / spago

🍝 PureScript package manager and build tool
BSD 3-Clause "New" or "Revised" License
792 stars 132 forks source link

glob/fsWalk: early exclusion of non-matching directories #1251

Closed Blugatroff closed 4 months ago

Blugatroff commented 4 months ago

Description of the change

For glob patterns with a fixed prefix, fsWalk will now no longer traverse directories whose contents obviously cannot match, because the directory path doesn't match the fixed prefix of the pattern.

For example, previously, globbing for .spago/p/tailrec-6.1.0/**/*.purs would traverse every directory (apart from those in a .gitignore, although in the case of globbing for something in .spago, that's not of much help). Now only directories whose relative path starts with .spago/p/tailrec-6.1.0 would be recursed into.

To determine the longest fixed prefix of a glob pattern, i used the scan function from picomatch, which is already a dependency of micromatch.

Fix #1243 as per https://github.com/purescript/spago/issues/1243#issuecomment-2211732428

Checklist:

P.S.: the above checks are not compulsory to get a change merged, so you may skip them. However, taking care of them will result in less work for the maintainers and will be much appreciated 😊