Skip to content

Commit

Permalink
fix: revert accidentally added parentPath on DirEntry (#24438)
Browse files Browse the repository at this point in the history
Reverts the accidentally added `.parentPath` on dir entries in
https://github.com/denoland/deno/pull/24257/files

This should not have been added to the public api and is not documented.
  • Loading branch information
dsherret committed Jul 5, 2024
1 parent f396b3d commit d91215d
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 7 deletions.
1 change: 0 additions & 1 deletion cli/standalone/virtual_fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(_)),
Expand Down
2 changes: 1 addition & 1 deletion ext/fs/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 0 additions & 1 deletion ext/fs/std_fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -814,7 814,6 @@ fn read_dir(path: &Path) -> FsResult<Vec<FsDirEntry>> {
};
}
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),
Expand Down
2 changes: 1 addition & 1 deletion ext/node/polyfills/_fs/_fs_dirent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
10 changes: 7 additions & 3 deletions ext/node/polyfills/_fs/_fs_readdir.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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) => {
Expand Down Expand Up @@ -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));
}
Expand Down

0 comments on commit d91215d

Please sign in to comment.