fix(glob): use cwd-relative search for ripgrep to fix directory prefix patterns
Ripgrep's --glob flag silently returns zero results when the search target is an absolute path and the pattern contains directory prefixes (e.g. 'apps/backend/**/*.ts' with '/project'). This is a known ripgrep behavior where glob matching fails against paths rooted at absolute arguments. Fix by running ripgrep with cwd set to the search path and '.' as the search target, matching how the find backend already operates. Ripgrep then sees relative paths internally, so directory-prefixed globs match correctly. Output paths are resolved back to absolute via resolve().
This commit is contained in:
parent
29d606241b
commit
418cf8529f
@ -1,3 +1,4 @@
|
|||||||
|
import { resolve } from "node:path"
|
||||||
import { spawn } from "bun"
|
import { spawn } from "bun"
|
||||||
import {
|
import {
|
||||||
resolveGrepCli,
|
resolveGrepCli,
|
||||||
@ -119,10 +120,9 @@ async function runRgFilesInternal(
|
|||||||
|
|
||||||
if (isRg) {
|
if (isRg) {
|
||||||
const args = buildRgArgs(options)
|
const args = buildRgArgs(options)
|
||||||
const paths = options.paths?.length ? options.paths : ["."]
|
cwd = options.paths?.[0] || "."
|
||||||
args.push(...paths)
|
args.push(".")
|
||||||
command = [cli.path, ...args]
|
command = [cli.path, ...args]
|
||||||
cwd = undefined
|
|
||||||
} else if (isWindows) {
|
} else if (isWindows) {
|
||||||
command = buildPowerShellCommand(options)
|
command = buildPowerShellCommand(options)
|
||||||
cwd = undefined
|
cwd = undefined
|
||||||
@ -177,7 +177,7 @@ async function runRgFilesInternal(
|
|||||||
|
|
||||||
let filePath: string
|
let filePath: string
|
||||||
if (isRg) {
|
if (isRg) {
|
||||||
filePath = line
|
filePath = cwd ? resolve(cwd, line) : line
|
||||||
} else if (isWindows) {
|
} else if (isWindows) {
|
||||||
filePath = line.trim()
|
filePath = line.trim()
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@ -29,12 +29,11 @@ export function createGlobTools(ctx: PluginInput): Record<string, ToolDefinition
|
|||||||
const runtimeCtx = context as Record<string, unknown>
|
const runtimeCtx = context as Record<string, unknown>
|
||||||
const dir = typeof runtimeCtx.directory === "string" ? runtimeCtx.directory : ctx.directory
|
const dir = typeof runtimeCtx.directory === "string" ? runtimeCtx.directory : ctx.directory
|
||||||
const searchPath = args.path ? resolve(dir, args.path) : dir
|
const searchPath = args.path ? resolve(dir, args.path) : dir
|
||||||
const paths = [searchPath]
|
|
||||||
|
|
||||||
const result = await runRgFiles(
|
const result = await runRgFiles(
|
||||||
{
|
{
|
||||||
pattern: args.pattern,
|
pattern: args.pattern,
|
||||||
paths,
|
paths: [searchPath],
|
||||||
},
|
},
|
||||||
cli
|
cli
|
||||||
)
|
)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user