fix: escape () and [] in scan directory globs - #627
Conversation
|
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 4063450d96
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| ? dirs.flatMap(dir => normalizeScanDirs([dir], { | ||
| ...dirsScanOptions, | ||
| cwd: root, | ||
| })).map(dir => ({ ...dir, glob: escapeGlobPathChars(dir.glob) })) |
There was a problem hiding this comment.
Preserve user-supplied glob syntax when escaping paths
When dirs or dirsScanOptions.filePatterns intentionally contains parentheses or a character class (for example, dirs: ['src/[ab]'] or filePatterns: ['*.[jt]s']), this post-normalization replacement escapes that syntax along with the literal project-root portion. Both directory scanning and the precompiled HMR matchers then look for literal brackets/parentheses instead of the requested glob matches, so previously supported configurations stop discovering exports. Escape only the literal resolved path prefix while preserving the user-supplied glob expression.
Useful? React with 👍 / 👎.
4063450 to
2a0b3d6
Compare
Project paths like Code(Template) were treated as picomatch extglob groups, so dir scanning and HMR watchers matched nothing.
2a0b3d6 to
1982e87
Compare
The review pointed out that escaping the whole normalized glob breaks patterns the
user wrote deliberately: with `dirs: ['src/[ab]']` the character class became a
literal, so a directory named `[ab]` was required and `src/a` / `src/b` no longer
matched. Verified against unimport's normalizeScanDirs plus picomatch:
dirs: ['src/[ab]'] before escaping -> src/a/x.ts true, src/b/x.ts true
after escaping -> src/a/x.ts false, src/b/x.ts false
Escape only the root prefix instead. That part is a real filesystem path, so
parentheses and brackets in it are always literal; everything after it comes from
the user's own `dirs` entry and is left untouched.
Two tests added, both failing with the previous implementation:
- a character class in `dirs` still matches multiple directories
- the same under a project path containing parentheses, so both behaviours hold
at once
`npx vitest run`: 4 files, 46 tests, all passing.
Change-Id: I9be2a6c4c8122928e0d00373818a808eac174c62
Signed-off-by: tzh476 <tzh476@gmail.com>
Summary
()or[](e.g.Code(Template)) are treated as picomatch / tinyglobby syntax, sodirsscanning and Vite HMR watchers match nothing.normalizeScanDirsand scan the escaped globs directly.#419was closed without merge because the change needed to live next to glob resolution with an explanation;resolveGlobsExcludehas since moved intounimport, and feeding escaped paths back through it turns\into/.Fixes #416
Test plan
vitest run(44 tests)Code(Template)andCode[Template]scanuseSpecial; HMR matchers accept files underCode(Template)Made with Cursor