(cwd: string)
| 417 | * phase and kept as diagnostics for not-found errors. |
| 418 | */ |
| 419 | export async function getLocalBinSearch(cwd: string): Promise<LocalBinSearch> { |
| 420 | const searchRoot = await getCanonicalPath(path.resolve(cwd)); |
| 421 | const ancestorSearch = await getAncestorDirectorySearch(searchRoot); |
| 422 | const skippedNodeModules: SkippedNodeModules[] = []; |
| 423 | const directories: string[] = []; |
| 424 | |
| 425 | for (const directory of ancestorSearch.directories) { |
| 426 | const nodeModulesDirectory = path.join(directory, 'node_modules'); |
| 427 | const parentDirectories = |
| 428 | ancestorSearch.stopReason === 'project-root-marker' |
| 429 | ? getDirectoriesBetween(ancestorSearch.stoppedAt, directory) |
| 430 | : getDirectoriesBetween(directory, searchRoot); |
| 431 | const skippedReason = await getSkippedNodeModulesReason( |
| 432 | nodeModulesDirectory, |
| 433 | parentDirectories |
| 434 | ); |
| 435 | |
| 436 | if (skippedReason) { |
| 437 | skippedNodeModules.push({ |
| 438 | directory: nodeModulesDirectory, |
| 439 | reason: skippedReason, |
| 440 | }); |
| 441 | continue; |
| 442 | } |
| 443 | |
| 444 | directories.push(path.join(nodeModulesDirectory, '.bin')); |
| 445 | } |
| 446 | |
| 447 | return { |
| 448 | directories, |
| 449 | diagnostics: { |
| 450 | searchRoot, |
| 451 | stoppedAt: ancestorSearch.stoppedAt, |
| 452 | stopReason: ancestorSearch.stopReason, |
| 453 | markerPath: ancestorSearch.markerPath, |
| 454 | skippedNodeModules, |
| 455 | }, |
| 456 | }; |
| 457 | } |
| 458 | |
| 459 | /** |
| 460 | * Walks ancestor directories until a project marker or filesystem root is hit. |
no test coverage detected