Skip to content

Commit

Permalink
perf: use fs.readdirSync with withFileTypes
Browse files Browse the repository at this point in the history
  • Loading branch information
anonrig committed Jul 6, 2023
1 parent a17f07a commit 254de17
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions packages/next/src/server/lib/recursive-readdir-sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,12 @@ export function recursiveReadDirSync(
/** Used to replace the initial path, only the relative path is left, it's faster than path.relative. */
rootDir = dir
): string[] {
const result = fs.readdirSync(dir)
const result = fs.readdirSync(dir, { withFileTypes: true })

result.forEach((part: string) => {
const absolutePath = join(dir, part)
const pathStat = fs.statSync(absolutePath)
result.forEach((part: fs.Dirent) => {
const absolutePath = join(dir, part.path)

if (pathStat.isDirectory()) {
if (part.isDirectory()) {
recursiveReadDirSync(absolutePath, arr, rootDir)
return
}
Expand Down

0 comments on commit 254de17

Please sign in to comment.