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

Node compat: fs.Dirent does not have path member #7358

Closed
NReilingh opened this issue Nov 28, 2023 · 2 comments · Fixed by #11135
Closed

Node compat: fs.Dirent does not have path member #7358

NReilingh opened this issue Nov 28, 2023 · 2 comments · Fixed by #11135
Assignees
Labels
bug Something isn't working good first issue Something that would be good for new contributors node.js Compatibility with Node.js APIs quick fix Something that can be fixed with low effort, but high impact

Comments

@NReilingh
Copy link
Contributor

What version of Bun is running?

1.0.12+85c997513

What platform is your computer?

Darwin 22.6.0 arm64 arm

What steps can reproduce the bug?

// repro.js
const fs = require('fs');

const result = fs.readdirSync('/private/tmp', { withFileTypes: true });

console.log(result[0].path, result[0].name);

What is the expected behavior?

% node repro.js
/private/tmp someTempFile

What do you see instead?

% bun repro.js
undefined someTempFile

Additional information

fs.Dirent is documented here: https://nodejs.org/api/fs.html#class-fsdirent

This type is returned from methods on fs.Dir, as well as fs.readdir() and fs.readdirsync() when withFileTypes option is true.

@NReilingh NReilingh added the bug Something isn't working label Nov 28, 2023
@Electroid Electroid added node.js Compatibility with Node.js APIs good first issue Something that would be good for new contributors labels Nov 28, 2023
@NReilingh
Copy link
Contributor Author

Also note: the new .readdir() { recursive: true } feature that dropped in 1.0.15 does not match node's behavior when { withFileTypes: true } option is also included.

// Node
> console.log(fs.readdirSync('./', { withFileTypes: true, recursive: true }))
[
  Dirent { name: 'ret', path: './', [Symbol(type)]: 2 },
  Dirent { name: 'fileone', path: 'ret', [Symbol(type)]: 1 },
  Dirent { name: 'filetwo', path: 'ret', [Symbol(type)]: 1 },
  Dirent { name: 'sub', path: 'ret', [Symbol(type)]: 2 },
  Dirent { name: 'child', path: 'ret/sub', [Symbol(type)]: 2 },
  Dirent { name: 'filethree', path: 'ret/sub', [Symbol(type)]: 1 }
]

Bun's output for this call has the full joined path in each name property.

@NReilingh
Copy link
Contributor Author

I haven't yet figured this out, but am working on it:

main...NReilingh:bun:direntry-paths

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Something that would be good for new contributors node.js Compatibility with Node.js APIs quick fix Something that can be fixed with low effort, but high impact
Projects
None yet
4 participants