( name: string, pathEnv: string | undefined, platform: string, isFile: (p: string) => Promise<boolean>, )
| 263 | } |
| 264 | |
| 265 | async function findExecutablesOnPath( |
| 266 | name: string, |
| 267 | pathEnv: string | undefined, |
| 268 | platform: string, |
| 269 | isFile: (p: string) => Promise<boolean>, |
| 270 | ): Promise<readonly string[]> { |
| 271 | if (pathEnv === undefined || pathEnv.length === 0) return []; |
| 272 | const listSep = platform === 'win32' ? ';' : ':'; |
| 273 | const dirSep = platform === 'win32' ? '\\' : '/'; |
| 274 | const paths: string[] = []; |
| 275 | for (const rawDir of pathEnv.split(listSep)) { |
| 276 | const dir = rawDir.trim(); |
| 277 | if (dir.length === 0) continue; |
| 278 | if (platform === 'win32' && !isAbsoluteWindowsPath(dir)) continue; |
| 279 | const candidate = dir.endsWith(dirSep) ? `${dir}${name}` : `${dir}${dirSep}${name}`; |
| 280 | if (await isFile(candidate)) { |
| 281 | paths.push(candidate); |
| 282 | } |
| 283 | } |
| 284 | return platform === 'win32' ? dedupeWindowsPaths(paths) : paths; |
| 285 | } |
| 286 | |
| 287 | export async function execFileText( |
| 288 | file: string, |
no test coverage detected