fix(glob): match the pattern relative to the path base dir, not the project root#2978
fix(glob): match the pattern relative to the path base dir, not the project root#2978Tatlatat wants to merge 2 commits into
Conversation
The glob tool documents its path argument as "Base directory to walk … The pattern matches relative to this path." But globFiles walked from startAbs while testing the pattern against the path relative to ctx.rootDir. So glob(path: "src", pattern: "*.ts") compared "src/index.ts" to "*.ts", matched nothing, and returned "(no matches)" even though index.ts matches *.ts relative to src. Match against a path relative to startAbs (the walk root) while keeping the displayed result relative to rootDir, so output still shows "src/index.ts". When no path is given (startAbs == rootDir) behavior is unchanged. Add a test that globbing *.ts under path "src" finds src/index.ts.
|
Thanks for the thorough investigation and clean fix — the diagnosis is spot-on for the TypeScript implementation. Worth noting: the main codebase has since been rewritten in Go, and the Go A few suggestions:
Nice catch overall. The single-line fix is exactly right. |
Per review feedback: add a case where path is an absolute directory (the match must still resolve relative to it) and a path "." case confirming top-level *.ts matches while nested files are not pulled in by the non-recursive pattern.
|
Thanks for the careful review! Added both edge-case tests in the same describe block:
On scope: agreed this is v1-only — the Go rewrite's |
What
The
globtool documents itspathargument as "Base directory to walk … Thepattern matches relative to this path." But
globFileswalked fromstartAbswhile testing the pattern against the path relative to
ctx.rootDir(projectroot).
So
glob(path: "src", pattern: "*.ts")compared"src/index.ts"against"*.ts", matched nothing, and returned(no matches)— even thoughindex.tsmatches
*.tsrelative tosrc.Fix
Match against a path relative to
startAbs(the walk root), while keeping thedisplayed result relative to
rootDirso output still showssrc/index.ts:When no
pathis given (startAbs == rootDir) behavior is unchanged.Test
Added a case: globbing
*.tsunderpath: "src"findssrc/index.tsand doesnot return
(no matches). Verified it fails on the old code and passes on thefix (123 filesystem-tool tests pass).
Verification
npx vitest run tests/filesystem-tools.test.ts(123 passed);biome checkclean on the changed files.