Skip to content

fix: escape () and [] in scan directory globs - #627

Open
tzh476 wants to merge 1 commit into
unplugin:mainfrom
tzh476:fix/escape-scan-dir-glob-special-chars
Open

fix: escape () and [] in scan directory globs#627
tzh476 wants to merge 1 commit into
unplugin:mainfrom
tzh476:fix/escape-scan-dir-glob-special-chars

Conversation

@tzh476

@tzh476 tzh476 commented Aug 17, 2026

Copy link
Copy Markdown

Summary

  • Directory names containing () or [] (e.g. Code(Template)) are treated as picomatch / tinyglobby syntax, so dirs scanning and Vite HMR watchers match nothing.
  • Escape those characters after normalizeScanDirs and scan the escaped globs directly. #419 was closed without merge because the change needed to live next to glob resolution with an explanation; resolveGlobsExclude has since moved into unimport, and feeding escaped paths back through it turns \ into /.

Fixes #416

Test plan

  • vitest run (44 tests)
  • New coverage: project root Code(Template) and Code[Template] scan useSpecial; HMR matchers accept files under Code(Template)

Made with Cursor

@bolt-new-by-stackblitz

Copy link
Copy Markdown

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread src/core/ctx.ts
? dirs.flatMap(dir => normalizeScanDirs([dir], {
...dirsScanOptions,
cwd: root,
})).map(dir => ({ ...dir, glob: escapeGlobPathChars(dir.glob) }))

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

@tzh476
tzh476 force-pushed the fix/escape-scan-dir-glob-special-chars branch from 4063450 to 2a0b3d6 Compare August 17, 2026 16:28
Project paths like Code(Template) were treated as picomatch extglob
groups, so dir scanning and HMR watchers matched nothing.
@tzh476
tzh476 force-pushed the fix/escape-scan-dir-glob-special-chars branch from 2a0b3d6 to 1982e87 Compare August 17, 2026 16:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Directory with special characters does not work correctly

1 participant