Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement recursive option in fs.readdir #7296

Merged
merged 7 commits into from
Nov 25, 2023
Merged

Conversation

Jarred-Sumner
Copy link
Collaborator

What does this PR do?

This implements support for readdir(path, {recursive: true})

import {readdir} from 'fs/promises';
const results = await readdir(__dirname, { recursive: true });
console.log(results) // ["a.js", "b/c.js" ...

How did you verify your code works?

There are tests.

Copy link
Contributor

github-actions bot commented Nov 24, 2023

@Jarred-Sumner 6 files with test failures on bun-darwin-aarch64:

  • test/integration/next/default-pages-dir/test/dev-server.test.ts
  • test/js/bun/glob/scan.test.ts
  • test/js/bun/test/mock-fn.test.js
  • test/js/bun/test/test-test.test.ts
  • test/js/bun/util/which.test.ts
  • test/js/web/worker.test.ts

View test output

#0928a3509cd95e32ee030f787737700aaffeedd5

Copy link
Contributor

github-actions bot commented Nov 24, 2023

✅ test failures on linux-x64 have been resolved.

#0928a3509cd95e32ee030f787737700aaffeedd5

Copy link
Contributor

github-actions bot commented Nov 24, 2023

@Jarred-Sumner 6 files with test failures on bun-darwin-x64:

  • test/js/bun/spawn/spawn-streaming-stdout.test.ts
  • test/js/bun/util/which.test.ts
  • test/js/node/fs/fs.test.ts
  • test/js/node/watch/fs.watchFile.test.ts
  • test/js/third_party/webpack/webpack.test.ts
  • test/js/web/timers/setTimeout.test.js

View test output

#0928a3509cd95e32ee030f787737700aaffeedd5

Copy link
Contributor

@Jarred-Sumner 7 files with test failures on bun-darwin-x64-baseline:

  • test/js/bun/spawn/spawn-streaming-stdout.test.ts
  • test/js/bun/util/filesink.test.ts
  • test/js/bun/util/which.test.ts
  • test/js/node/fs/fs.test.ts
  • test/js/node/watch/fs.watchFile.test.ts
  • test/js/third_party/webpack/webpack.test.ts
  • test/js/web/timers/setTimeout.test.js

View test output

#0928a3509cd95e32ee030f787737700aaffeedd5

ref: bun.Async.KeepAlive = .{},
tracker: JSC.AsyncTaskTracker,

// It's not 100% clear this one is necessary

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hi @Jarred-Sumner , wanted to know your opinion on comments like these?
are they cool for all code bases or you add these cause you're the owner.
Thanks for your great work!

@@ -2052,3 +2052,7 @@ pub fn exitThread() noreturn {
@panic("Unsupported platform");
}
}

pub fn outOfMemory() noreturn {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you for using this pattern.

Copy link
Member

@paperclover paperclover left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no meaningful comments, this looks good

};
var list = bun.default_allocator.create(ResultListEntry) catch bun.outOfMemory();
errdefer {
bun.default_allocator.destroy(list);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: is this code ever run?

Zig has errdefer, which evaluates the deferred expression on block exit path if and only if the function returned with an error from the block.

(there is no return error case)

}

if (comptime recursive) {
@panic("This code path should never be reached. It should only go through readdirWithEntriesRecursiveAsync.");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can this be @compileError?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried. But no, unfortunately

@Jarred-Sumner Jarred-Sumner merged commit 7f10622 into main Nov 25, 2023
20 of 28 checks passed
@Jarred-Sumner Jarred-Sumner deleted the jarred/readdir-recursive branch November 25, 2023 03:08
cirospaciari pushed a commit that referenced this pull request Nov 27, 2023
* Implement `fs.readdir(path, {recursive: true})` and `fs.readdirSync(path, {recursive: true})`

* Update node_fs.zig

* FIx memory leak in error code

* Add fail test

* Update readdir.mjs

* Update bun.zig

* Update readdir.mjs

---------

Co-authored-by: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com>
@NReilingh
Copy link
Contributor

NReilingh commented Dec 4, 2023

Doesn't this forget to update the type definitions? My LSP is complaining when I pass { recursive: true } on 1.0.15. I took a look at https://github.com/oven-sh/bun/blob/main/packages/bun-types/fs.d.ts and expect to see the recursive option alongside withFileTypes; only withFileTypes is present on the readdir/readdirSync calls.

ryoppippi pushed a commit to ryoppippi/bun that referenced this pull request Feb 1, 2024
* Implement `fs.readdir(path, {recursive: true})` and `fs.readdirSync(path, {recursive: true})`

* Update node_fs.zig

* FIx memory leak in error code

* Add fail test

* Update readdir.mjs

* Update bun.zig

* Update readdir.mjs

---------

Co-authored-by: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants