Fixed a bug where you would receive relative paths by default while asking for contents of a dir

This commit is contained in:
Christian Risi 2025-07-04 09:00:39 +00:00
parent 67c8e9c31d
commit 7f5d5ba1b1

View File

@ -158,17 +158,28 @@ export function hashUtil(data: BinaryLike) {
return hash
}
export async function listFiles(path: string, recursive?: boolean): Promise<string[]> {
export async function listFiles(path: string, recursive?: boolean, relative?: boolean,): Promise<string[]> {
if (!recursive) {
recursive = false
}
if (!relative) {
relative = false
}
if (!await isDir(path)) {
// UGLY: be specific
throw new Error("This is not a directory")
}
return await Node.readdir(path, {recursive: recursive})
const relativePaths = await Node.readdir(path, {recursive: recursive})
if (relative) {
return relativePaths
}
return relativePaths.map( (_path) => {
return `${path}/${_path}`
})
}