Skip to content

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

@sapphi-red

Description

@sapphi-red

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions