MCPcopy
hub / github.com/vitejs/vite / recursiveReaddir

Function recursiveReaddir

packages/vite/src/node/utils.ts:647–675  ·  view source on GitHub ↗
(dir: string)

Source from the content-addressed store, hash-verified

645export const ERR_SYMLINK_IN_RECURSIVE_READDIR =
646 'ERR_SYMLINK_IN_RECURSIVE_READDIR'
647export 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.

Callers 1

initPublicFilesFunction · 0.90

Calls 2

normalizePathFunction · 0.85
resolveMethod · 0.65

Tested by

no test coverage detected