-
Notifications
You must be signed in to change notification settings - Fork 638
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
feat(fs/unstable): add readDirSync #6381
base: main
Are you sure you want to change the base?
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #6381 +/- ##
==========================================
- Coverage 96.23% 95.75% -0.48%
==========================================
Files 556 554 -2
Lines 42065 37209 -4856
Branches 6371 6358 -13
==========================================
- Hits 40481 35630 -4851
+ Misses 1544 1533 -11
- Partials 40 46 +6 ☔ View full report in Codecov by Sentry. |
CI is failing with Deno v1.x because One workaround is to use Does anyone have an idea to best handle this situation? |
I've only tried testing it on Deno v1.46.0, the function signatures are indeed different for // In the 1.x Deno namespace:
function readDirSync(path: string | URL): Iterable<DirEntry>
// In the 2.x Deno namespace:
function readDirSync(path: string | URL): IteratorObject<DirEntry> I suppose there's no real benefit to having After modifying the return type to import { readDirSync } from "./fs/unstable_read_dir.ts";
const dir = readDirSync("fs/testdata");
const partialList = dir.take(5).toArray();
console.log("partialList:", partialList); It probably doesn't help from a TypeScript perspective since the function signature does not semantically convey what the function does because of the return type differences. I can leave this on the back burner for now and make progress on other APIs and return to it. |
@@ -38,3 +41,40 @@ export async function* readDir(path: string | URL): AsyncIterable<DirEntry> { | |||
} | |||
} | |||
} | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about defining the type of IteratorObject
here?
interface IteratorObject<T> extends Iterable<T> {} | |
In Deno 1 (TypeScript 5.3 or lower), it should be treated as just a new type definition, and in Deno 2 (TypeScript 5.4 or higher), where IteratorObject
type exists, it should be treated as a merge of interface types and nothing should happen.
This PR adds the
readDirSync
API to@std/fs
, which is intended to mirror theDeno.readDirSync
function. The PR also adds additional@param
and@returns
documentation to thereadDir
API.Towards #6255 .