You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm starting a new thread off of issue #1592 to talk specifically about undeprecating fs.existsSync.
fs.exists was correctly deprecated, for two reasons:
fs.exists doesn't use nodeback semantics; fs.access does.
exists/existsSync promises too much certainty. You can know that a file definitely does exist, but if you can't access it, there's no way to know whether that's because the file truly doesn't exist or because of some other problem (security, connection issues, etc.). access fixes the semantics.
So fs.access is better than fs.exists. (If you disagree, go argue the point in issue #1592.)
But fs.accessSync is worse than fs.existsSync. fs.accessSync does nothing if the file is accessible, and throws an exception when the file is inaccessible, requiring us to wrap it in a try/catch block, which means we can't use it in an if expression. It's pointless boilerplate for simple scripts.
I propose two alternatives:
Add a new fs.accessibleSync method, available only in synchronous mode, with this trivial implementation.
You might argue that this function is too trivial to be of use, but I bet that without this function in the standard library, it will be written and rewritten and rewritten thousands of times.
Undeprecate fs.existsSync, leaving fs.exists deprecated. This is the option I prefer, because it avoids cluttering the API.
As a synchronous script author I just want a boolean, and I don't really care what the function is called.
Can we reach some consensus around this, separating it from the exists vs. access semantics argument?
The text was updated successfully, but these errors were encountered:
I'm starting a new thread off of issue #1592 to talk specifically about undeprecating
fs.existsSync
.fs.exists
was correctly deprecated, for two reasons:fs.exists
doesn't use nodeback semantics;fs.access
does.exists
/existsSync
promises too much certainty. You can know that a file definitely does exist, but if you can't access it, there's no way to know whether that's because the file truly doesn't exist or because of some other problem (security, connection issues, etc.).access
fixes the semantics.So
fs.access
is better thanfs.exists
. (If you disagree, go argue the point in issue #1592.)But
fs.accessSync
is worse thanfs.existsSync
.fs.accessSync
does nothing if the file is accessible, and throws an exception when the file is inaccessible, requiring us to wrap it in a try/catch block, which means we can't use it in anif
expression. It's pointless boilerplate for simple scripts.I propose two alternatives:
fs.accessibleSync
method, available only in synchronous mode, with this trivial implementation.You might argue that this function is too trivial to be of use, but I bet that without this function in the standard library, it will be written and rewritten and rewritten thousands of times.
fs.existsSync
, leavingfs.exists
deprecated. This is the option I prefer, because it avoids cluttering the API.As a synchronous script author I just want a boolean, and I don't really care what the function is called.
Can we reach some consensus around this, separating it from the
exists
vs.access
semantics argument?The text was updated successfully, but these errors were encountered: