(text: string, cwd: string)
| 86 | * Pure. |
| 87 | */ |
| 88 | export function splitPathsAndText(text: string, cwd: string): { paths: FsPath[]; text: string } { |
| 89 | const paths: FsPath[] = []; |
| 90 | const seen = new Set<string>(); |
| 91 | const rawPathTokens: string[] = []; |
| 92 | for (const m of text.matchAll(PATH_TOKEN_RE)) { |
| 93 | const tok = m[0]!; |
| 94 | if (!looksLikePathToken(tok)) continue; |
| 95 | const cleaned = tok.replace(/^['"]|['"]$/g, ''); |
| 96 | const abs = resolvePath(cleaned, cwd); |
| 97 | if (seen.has(abs)) continue; |
| 98 | try { |
| 99 | const st = fsSync.statSync(abs); |
| 100 | const kind = st.isDirectory() ? 'dir' : st.isFile() ? 'file' : null; |
| 101 | if (!kind) continue; |
| 102 | seen.add(abs); |
| 103 | paths.push({ abs, kind, name: path.basename(abs) }); |
| 104 | rawPathTokens.push(tok); |
| 105 | } catch { /* doesn't exist — not a path */ } |
| 106 | } |
| 107 | let remainder = text; |
| 108 | for (const t of rawPathTokens) remainder = remainder.replace(t, ' '); |
| 109 | remainder = remainder.replace(/\s+/g, ' ').trim(); |
| 110 | return { paths, text: remainder }; |
| 111 | } |
| 112 | |
| 113 | /** |
| 114 | * Existing filesystem paths (files OR directories) referenced in `text`, resolved absolute. |
no test coverage detected