(dir: string)
| 645 | export const ERR_SYMLINK_IN_RECURSIVE_READDIR = |
| 646 | 'ERR_SYMLINK_IN_RECURSIVE_READDIR' |
| 647 | export async function recursiveReaddir(dir: string): Promise<string[]> { |
| 648 | if (!fs.existsSync(dir)) { |
| 649 | return [] |
| 650 | } |
| 651 | let dirents: fs.Dirent[] |
| 652 | try { |
| 653 | dirents = await fsp.readdir(dir, { withFileTypes: true }) |
| 654 | } catch (e) { |
| 655 | if (e.code === 'EACCES') { |
| 656 | // Ignore permission errors |
| 657 | return [] |
| 658 | } |
| 659 | throw e |
| 660 | } |
| 661 | if (dirents.some((dirent) => dirent.isSymbolicLink())) { |
| 662 | const err: any = new Error( |
| 663 | 'Symbolic links are not supported in recursiveReaddir', |
| 664 | ) |
| 665 | err.code = ERR_SYMLINK_IN_RECURSIVE_READDIR |
| 666 | throw err |
| 667 | } |
| 668 | const files = await Promise.all( |
| 669 | dirents.map((dirent) => { |
| 670 | const res = path.resolve(dir, dirent.name) |
| 671 | return dirent.isDirectory() ? recursiveReaddir(res) : normalizePath(res) |
| 672 | }), |
| 673 | ) |
| 674 | return files.flat(1) |
| 675 | } |
| 676 | |
| 677 | // `fs.realpathSync.native` resolves differently in Windows network drive, |
| 678 | // causing file read errors. skip for now. |
no test coverage detected