Fix: match unique --target names after cwd absolutizing

Live and other helpers resolve --target against cwd before context.mjs sees it. Treat a missing single-segment path the same as a bare workspace name so those callers still select the unique child.

AI assistance: Cursor Grok 4.6 implemented this change.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Abdul Wahab
2026-09-02 12:05:40 +05:00
co-authored by Cursor
parent 40d7edc073
commit 839fbe5d4a
2 changed files with 48 additions and 3 deletions
+9 -3
View File
@@ -255,10 +255,16 @@ function resolveTargetPath(cwd, targetPath) {
}
function findUniqueBareTarget(cwd, targetPath) {
if (path.isAbsolute(targetPath) || /[\\/]/.test(targetPath)) return null;
const repoRoot = findMonorepoRoot(path.resolve(cwd));
const absCwd = path.resolve(cwd);
const abs = path.isAbsolute(targetPath) ? targetPath : path.resolve(absCwd, targetPath);
const rel = path.relative(absCwd, abs);
if (!rel || rel.startsWith('..') || path.isAbsolute(rel)) return null;
const segments = rel.split(path.sep).filter(Boolean);
if (segments.length !== 1) return null;
const name = segments[0];
const repoRoot = findMonorepoRoot(absCwd);
if (!repoRoot) return null;
const matches = discoverTargetCandidates(repoRoot).filter((candidate) => candidate.name === targetPath);
const matches = discoverTargetCandidates(repoRoot).filter((candidate) => candidate.name === name);
if (matches.length !== 1) return null;
return path.resolve(repoRoot, matches[0].path);
}