(targets: Array<string>, cwd: string)
| 206 | * - Explicit files are included directly (if not a binary extension). |
| 207 | */ |
| 208 | export async function resolveTargetPaths(targets: Array<string>, cwd: string): Promise<Array<string>> { |
| 209 | const seen = new Set<string>(); |
| 210 | const files: Array<string> = []; |
| 211 | |
| 212 | async function addFile(absPath: string) { |
| 213 | if (seen.has(absPath)) return; |
| 214 | seen.add(absPath); |
| 215 | files.push(absPath); |
| 216 | } |
| 217 | |
| 218 | async function addPath(absPath: string) { |
| 219 | let stat; |
| 220 | try { |
| 221 | stat = await fs.stat(absPath); |
| 222 | } catch { |
| 223 | return; // path doesn't exist — silently skip |
| 224 | } |
| 225 | if (stat.isDirectory()) { |
| 226 | for (const f of await walkDirectoryAll(absPath)) { |
| 227 | await addFile(f); |
| 228 | } |
| 229 | } else if (stat.isFile()) { |
| 230 | const ext = path.extname(absPath).toLowerCase(); |
| 231 | if (!BINARY_EXTENSIONS.has(ext)) { |
| 232 | await addFile(absPath); |
| 233 | } |
| 234 | } |
| 235 | } |
| 236 | |
| 237 | for (const target of targets) { |
| 238 | if (GLOB_CHARS.test(target)) { |
| 239 | // Expand glob pattern; paths returned by fsGlob are relative to cwd |
| 240 | for await (const match of fs.glob(target, { cwd })) { |
| 241 | await addPath(path.resolve(cwd, match)); |
| 242 | } |
| 243 | } else { |
| 244 | await addPath(path.resolve(cwd, target)); |
| 245 | } |
| 246 | } |
| 247 | |
| 248 | return files; |
| 249 | } |
| 250 | |
| 251 | /** |
| 252 | * Scans a single file for occurrences of any of the provided sensitive values. |
no test coverage detected