-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
What is ts.sys.readDirectory
even supposed to do?
#46788
Comments
@rbuckton in #46673, @weswigham said you might have some general context on this. |
Unfortunately For one, it assumes the Each result that it matches is pre-combined with
Finally, Essentially, |
For what it's worth I was rather surprised that I had to do all this in my readDirectory(directoryName, extensions, excludePaths, includePaths, depth)
{
return from(new DirectoryStream(directoryName, { recursive: true }))
.where(it => !it.isDirectory)
.where(it => extensions.includes(FS.extensionOf(it.fullPath)))
.where(it => {
// implicitly exclude node_modules, etc.
return !from(TS.commonPackageFolders)
.any(dirName => it.fullPath.includes(`${dirName}/`) && !it.fullPath.includes("@types/"));
})
.where(it => !FS.match(it.fullPath, excludePaths))
.where(it => FS.match(it.fullPath, includePaths))
.select(it => it.fullPath)
.toArray();
} I expected to just have to return a dumb directory listing, but it seems that The compiler API really needs to be documented better. I would take a stab, but even I'm not confident I have all the intricacies right and I don't want to mislead people. |
Following up on #46673 (comment), I started a more thorough investigation of
ts.matchFiles
(which is justts.sys.readDirectory
without the system host) and discovered that even its long-standing behavior prior to 4.4 is confusing and probably undesigned. Consider this file system:Things tend to work as expected if you do three things: (1) use relative paths, (2) read the same directory as your CWD, and (3) don’t use any
includes
that access a sibling folder with"../"
. If you start doing those things, especially in combination, the behavior is a bit unpredictable.Let’s start with a simple example where I think things are working as intended:
Note that the entries are relative to our CWD / the directory we’re reading (which one? We don’t know yet because they’re the same), but without the leading
./
. This seems probably intentional because it matches the format offs.readdir
. Also, replacing the first argument with the empty string yields the same results.Ok, let’s see what happens if we
include
something outside of the directory we’re reading:No change. This seems to make sense with the name
readDirectory
. Now let’s find out whether our results are relative to our CWD or to the directory we’re reading. We’llcd
up a level first:Interesting—they’re relative to our CWD, not the directory we’re reading, which is a divergence from
fs.readdir
. Does this mean we can now getincludes
outside of the directory we’re reading?Yes it does!
readDirectory
can return results outside of the target directory, but not outside the CWD. This seems very odd to me. Let’scd
back intoa
and try absolute paths:Absolute in, absolute out. Quite possibly an accident? Now for the final test, an absolute input path with an
includes
outside the CWD:👀
The text was updated successfully, but these errors were encountered: