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

Fix recursing to find files in Node <18.17 #332

Merged
merged 3 commits into from
Feb 18, 2025
Merged

Fix recursing to find files in Node <18.17 #332

merged 3 commits into from
Feb 18, 2025

Conversation

trotzig
Copy link
Contributor

@trotzig trotzig commented Feb 18, 2025

The path and parentPath properties of a Dirent object isn't available until 18.17 and 18.20 respectively. To make our package compatible again with older Node versions, I'm switching out fs.readdir for glob.

The `path` and `parentPath` properties of a Dirent object isn't
available until 18.17 and 18.20 respectively. To make our package
compatible again with older Node versions, I'm switching out
`fs.readdir` for `glob`.

WIP because I can't figure out how to use the regular async version of
`glob`.
So that we will replicate the bug with using fs.readdir together with
dirent.paht.
@trotzig trotzig requested a review from lencioni February 18, 2025 16:38
@trotzig trotzig marked this pull request as draft February 18, 2025 16:38
@@ -11,7 +11,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
node: [18, 20, 22]
node: ['18.16.0', 20, 22]
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's update the engines field in package.json to match.

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh or maybe with this change we actually end up supporting back more so we can leave engines where it is at now.

withFileTypes: true,
recursive: true,
const files = Array.from(
await glob.sync('**/*', {
Copy link
Contributor

Choose a reason for hiding this comment

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

await glob.sync is a bit strange for a couple of reasons:

  1. globSync is a named export of the glob package, that I think we'd want instead of this if we want synchronous mode
  2. await a sync function is unnecessary
  3. Since we are in an async function can we use the async glob?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah I kept glob.sync because of issues locally. Turns out I hadn't yarn installed in a while.

`await glob.sync` is a bit strange for a couple of reasons:

1. `globSync` is a named export of the glob package, that I think we'd
   want instead of this if we want synchronous mode
2. `await` a sync function is unnecessary
3. Since we are in an async function can we use the async glob?

This seems to work fine for me, so I think we should make this change.
@lencioni lencioni changed the title WIP: Fix recursing to find files in Node <18.17 Fix recursing to find files in Node <18.17 Feb 18, 2025
@lencioni lencioni marked this pull request as ready for review February 18, 2025 16:57
@lencioni lencioni merged commit 4879b83 into main Feb 18, 2025
4 checks passed
@lencioni lencioni deleted the recursive-fix branch February 18, 2025 16:57
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.

2 participants