Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose a function that returns whether a file path matches the glob #64

Open
sapphi-red opened this issue Oct 21, 2024 · 7 comments
Open
Labels
enhancement New feature or request

Comments

@sapphi-red
Copy link

In Vite, when a file is updated, we check whether that file is included in the glob to know whether the file containing a glob has to be updated.

Links to relevant code

https://github.com/vitejs/vite/blob/802839d48335a69eb15f71f2cd816d0b6e4d3556/packages/vite/src/node/plugins/importMetaGlob.ts#L66-L81
https://github.com/vitejs/vite/blob/802839d48335a69eb15f71f2cd816d0b6e4d3556/packages/vite/src/node/plugins/importMetaGlob.ts#L89-L106

I guess Vite cannot simply use picomatch as tinyglobby has more features. It would be nice if tinyglobby exposes a function that returns whether a file path matches the glob.

import { globMatcher } from 'tinyglobby';

const match = globMatcher(['files/*.ts', '!**/*.d.ts'], { cwd: 'src' }); // pass in the same options

const result = match('files/bar.ts') // pass the file path
expect(result).toBe(true)
@SuperchupuDev SuperchupuDev added the enhancement New feature or request label Oct 21, 2024
@SuperchupuDev
Copy link
Owner

will consider adding it, meanwhile do you have any examples of previous work in other glob libraries?

@sapphi-red
Copy link
Author

fast-glob uses micromatch and node-glob uses minimatch and both does not extend any features related to matching IIUC, so in these cases those libraries can be used.
globby extends some features but does not provide a function like this.

@ghiscoding
Copy link

for an example, maybe take a look at the matcher lib and its isMatch function which returns a boolean, see their implementation here, side note, matcher was created by the same globby author.

@SuperchupuDev
Copy link
Owner

SuperchupuDev commented Oct 25, 2024

fast-glob uses micromatch and node-glob uses minimatch and both does not extend any features related to matching IIUC, so in these cases those libraries can be used. globby extends some features but does not provide a function like this.

just wondering, what are the exclusive features that you need that tinyglobby has but picomatch doesn't? it uses it under the hood. i can try to implement this but it might take a while until i can focus on it

@sapphi-red
Copy link
Author

what are the exclusive features that you need that tinyglobby has but picomatch doesn't?

I think it's mainly braces expansion support.

@SuperchupuDev
Copy link
Owner

SuperchupuDev commented Oct 25, 2024

tinyglobby supports the same braces expansion picomatch does, which despite its readme saying it's not supported, in practice it actually supports nearly all usecases except for range increments {01..10..2} which to be fair i haven't ever seen used in the wild. if range increments are really needed it's probably possible to add it to tinyglobby though (with the expandRange picomatch option)

@sapphi-red
Copy link
Author

Ah, I see. Then, I think I can use picomatch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants