* Detects whether `filePath` is located inside a `node_modules/.bin` directory.
( filePath: string )
| 541 | * Detects whether `filePath` is located inside a `node_modules/.bin` directory. |
| 542 | */ |
| 543 | async function getNodeModulesBinDirectory( |
| 544 | filePath: string |
| 545 | ): Promise<string | null> { |
| 546 | const candidateDirectory = path.resolve(path.dirname(filePath)); |
| 547 | const directories = [candidateDirectory]; |
| 548 | |
| 549 | try { |
| 550 | const canonicalDirectory = await realpath(candidateDirectory); |
| 551 | |
| 552 | if (!directories.includes(canonicalDirectory)) { |
| 553 | directories.push(canonicalDirectory); |
| 554 | } |
| 555 | } catch {} |
| 556 | |
| 557 | for (const directory of directories) { |
| 558 | if ( |
| 559 | path.basename(directory) === '.bin' && |
| 560 | path.basename(path.dirname(directory)) === 'node_modules' |
| 561 | ) { |
| 562 | return directory; |
| 563 | } |
| 564 | } |
| 565 | |
| 566 | return null; |
| 567 | } |
| 568 | |
| 569 | /** |
| 570 | * Classifies a concrete PATH hit after command lookup. This catches local |
no test coverage detected