Skip to content

Commit

Permalink
fix(node:fs): fix fs.promises.opendir not having a path property (#…
Browse files Browse the repository at this point in the history
…7292)

Closes #4995
  • Loading branch information
samfundev authored and cirospaciari committed Nov 27, 2023
1 parent a211604 commit eb17654
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/js/node/fs.promises.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,13 @@ function cp(src, dest, options) {
// This is currently stubbed for Next.js support.
class Dir {
#entries: Dirent[];
constructor(e: Dirent[]) {
#path: string;
constructor(e: Dirent[], path: string) {
this.#entries = e;
this.#path = path;
}
get path() {
return this.#path;
}
readSync() {
return this.#entries.shift() ?? null;
Expand All @@ -127,7 +132,7 @@ class Dir {
}
async function opendir(dir: string) {
const entries = await fs.readdir(dir, { withFileTypes: true });
return new Dir(entries);
return new Dir(entries, dir);
}

export default {
Expand Down
4 changes: 4 additions & 0 deletions test/js/node/fs/fs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1871,6 +1871,10 @@ describe("fs/promises", () => {
expect(await exists(path)).toBe(false);
});
});

it("opendir should have a path property, issue#4995", async () => {
expect((await fs.promises.opendir(".")).path).toBe(".");
});
});

it("stat on a large file", () => {
Expand Down

0 comments on commit eb17654

Please sign in to comment.