-
-
Notifications
You must be signed in to change notification settings - Fork 33.2k
fs: add async glob and make it (async) iteratable #48594
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
Conversation
} | ||
let val; | ||
try { | ||
val = await readdir(path, { __proto__: null, withFileTypes: true }); |
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.
use opendir
instead of readdir
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.
and yield the results or just opendir? because yielding the result will cause incomplete cache
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.
then it probably makes sense to use readdir
for the first iteration
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 will it solve the issue? on further iterations we should get from the cache and not use opendir
anyway...
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.
I meant first iteration of the feature
lib/internal/fs/glob.js
Outdated
children = await this.#cache.readdir(fullpath); | ||
} | ||
|
||
for (let i = 0; i < children.length; i++) { |
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.
children = await this.#cache.readdir(fullpath); | |
} | |
for (let i = 0; i < children.length; i++) { | |
children = this.#cache.opendir(fullpath); | |
} | |
for await (let i = 0; i < children.length; i++) { |
changing to opendir
will require this
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.
what about the cache?
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.
doing that we will have incomplete cache
lib/internal/fs/glob.js
Outdated
for (const index of pattern.indexes) { | ||
// For each child, check potential patterns | ||
if (this.#cache.seen(entryPath, pattern, index) || this.#cache.seen(entryPath, pattern, index + 1)) { | ||
// TODO - fix this not finish the addSubPatterns |
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.
@MoLow any JS trick to finish the called generator?
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.
test the return value of addFromChildren
for (const entry of children) {
const result = this.addFromChildren(entry, path, fullpath, pattern, last, isLast);
if (result === null) {
return;
}
yield result;
}
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.
addFromChildren
is a generator by itself so I need to get the value from it so I thought if you have another way
lib/internal/fs/glob.js
Outdated
this.#cache.addToStatCache(join(fullpath, entry.name), entry); | ||
const children = await this.#cache.readdir(fullpath); | ||
|
||
for (const entry of children) { |
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.
dont use for of
, since the prototype can be tampered
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.
can I use for of
for going over generator
or do I need to handle all the state by myself?
Extracted from:
Cc @MoLow