-
-
Notifications
You must be signed in to change notification settings - Fork 797
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
26 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import fs from "fs/promises" | ||
import path from "path" | ||
|
||
type Filter = (name: string, dir: string) => boolean | ||
|
||
export async function readdirRecursive(root: string, filter?: Filter, dir = ""): Promise<string[]> { | ||
const absoluteDir = path.resolve(root, dir) | ||
const dirStats = await fs.stat(absoluteDir) | ||
|
||
if (dirStats.isDirectory()) { | ||
let entries = await fs.readdir(absoluteDir) | ||
|
||
if (filter) { | ||
entries = entries.filter((name) => filter(name, dir)) | ||
} | ||
|
||
const recursiveList = await Promise.all( | ||
entries.map((name) => readdirRecursive(root, filter, path.join(dir, name))), | ||
) | ||
return recursiveList.flat(Infinity) as string[] | ||
} else { | ||
return [dir] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3908,11 +3908,6 @@ | |
dependencies: | ||
"@types/node" "*" | ||
|
||
"@types/[email protected]": | ||
version "1.0.0" | ||
resolved "https://registry.yarnpkg.com/@types/fs-readdir-recursive/-/fs-readdir-recursive-1.0.0.tgz#404f77bdadc6b90cccd3f04d15f6dd85cdde38ef" | ||
integrity sha512-1w3aDEWvddRoBCPm3hdGehNovSvqwe30dxplDH5bjZXoMCDVbntkbNENxfyScS4kYsovJYcwLPxJ9gjN/hh2Xg== | ||
|
||
"@types/glob-stream@*": | ||
version "6.1.0" | ||
resolved "https://registry.yarnpkg.com/@types/glob-stream/-/glob-stream-6.1.0.tgz#7ede8a33e59140534f8d8adfb8ac9edfb31897bc" | ||
|
@@ -9548,11 +9543,6 @@ fs-mkdirp-stream@^1.0.0: | |
graceful-fs "^4.1.11" | ||
through2 "^2.0.3" | ||
|
||
[email protected]: | ||
version "1.1.0" | ||
resolved "https://registry.yarnpkg.com/fs-readdir-recursive/-/fs-readdir-recursive-1.1.0.tgz#e32fc030a2ccee44a6b5371308da54be0b397d27" | ||
integrity sha512-GNanXlVr2pf02+sPN40XN8HG+ePaNcvM0q5mZBd668Obwb0yD5GiUbZOFgwn8kGMY6I3mdyDJzieUy3PTYyTRA== | ||
|
||
fs-write-stream-atomic@^1.0.8: | ||
version "1.0.10" | ||
resolved "https://registry.yarnpkg.com/fs-write-stream-atomic/-/fs-write-stream-atomic-1.0.10.tgz#b47df53493ef911df75731e70a9ded0189db40c9" | ||
|