diff --git a/cli/standalone/virtual_fs.rs b/cli/standalone/virtual_fs.rs index ee91b9f7fe..0d39f8e958 100644 --- a/cli/standalone/virtual_fs.rs +++ b/cli/standalone/virtual_fs.rs @@ -787,7 +787,6 @@ impl FileBackedVfs { .entries .iter() .map(|entry| FsDirEntry { - parent_path: path.to_string_lossy().into_owned(), name: entry.name().to_string(), is_file: matches!(entry, VfsEntry::File(_)), is_directory: matches!(entry, VfsEntry::Dir(_)), diff --git a/ext/fs/interface.rs b/ext/fs/interface.rs index 6036f82284..cb6fc4f639 100644 --- a/ext/fs/interface.rs +++ b/ext/fs/interface.rs @@ -69,10 +69,10 @@ pub enum FsFileType { Junction, } +/// WARNING: This is part of the public JS Deno API. #[derive(Serialize)] #[serde(rename_all = "camelCase")] pub struct FsDirEntry { - pub parent_path: String, pub name: String, pub is_file: bool, pub is_directory: bool, diff --git a/ext/fs/std_fs.rs b/ext/fs/std_fs.rs index 79f66cc4bf..c501b8928e 100644 --- a/ext/fs/std_fs.rs +++ b/ext/fs/std_fs.rs @@ -814,7 +814,6 @@ fn read_dir(path: &Path) -> FsResult> { }; } Some(FsDirEntry { - parent_path: path.to_string_lossy().to_string(), name, is_file: method_or_false!(is_file), is_directory: method_or_false!(is_dir), diff --git a/ext/node/polyfills/_fs/_fs_dirent.ts b/ext/node/polyfills/_fs/_fs_dirent.ts index 0f80fc135c..d4ad6bb430 100644 --- a/ext/node/polyfills/_fs/_fs_dirent.ts +++ b/ext/node/polyfills/_fs/_fs_dirent.ts @@ -2,7 +2,7 @@ import { notImplemented } from "ext:deno_node/_utils.ts"; export default class Dirent { - constructor(private entry: Deno.DirEntry) {} + constructor(private entry: Deno.DirEntry & { parentPath: string }) {} isBlockDevice(): boolean { notImplemented("Deno does not yet support identification of block devices"); diff --git a/ext/node/polyfills/_fs/_fs_readdir.ts b/ext/node/polyfills/_fs/_fs_readdir.ts index f8c0a59d69..3b314227dc 100644 --- a/ext/node/polyfills/_fs/_fs_readdir.ts +++ b/ext/node/polyfills/_fs/_fs_readdir.ts @@ -11,7 +11,7 @@ import { getValidatedPath } from "ext:deno_node/internal/fs/utils.mjs"; import { Buffer } from "node:buffer"; import { promisify } from "ext:deno_node/internal/util.mjs"; -function toDirent(val: Deno.DirEntry): Dirent { +function toDirent(val: Deno.DirEntry & { parentPath: string }): Dirent { return new Dirent(val); } @@ -67,13 +67,15 @@ export function readdir( } try { - asyncIterableToCallback(Deno.readDir(path.toString()), (val, done) => { + path = path.toString(); + asyncIterableToCallback(Deno.readDir(path), (val, done) => { if (typeof path !== "string") return; if (done) { callback(null, result); return; } if (options?.withFileTypes) { + val.parentPath = path; result.push(toDirent(val)); } else result.push(decode(val.name)); }, (e) => { @@ -130,8 +132,10 @@ export function readdirSync( } try { - for (const file of Deno.readDirSync(path.toString())) { + path = path.toString(); + for (const file of Deno.readDirSync(path)) { if (options?.withFileTypes) { + file.parentPath = path; result.push(toDirent(file)); } else result.push(decode(file.name)); }