-
Notifications
You must be signed in to change notification settings - Fork 656
feat(fs/unstable): add open, openSync, and FsFile class #6524
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
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #6524 +/- ##
==========================================
- Coverage 95.21% 94.59% -0.63%
==========================================
Files 577 579 +2
Lines 43381 43708 +327
Branches 6487 6489 +2
==========================================
+ Hits 41307 41344 +37
- Misses 2034 2324 +290
Partials 40 40 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Uses a temporary file instead of `fs/testdata/copy_test.txt` for testing the `utime` method in an effort to avoid the time preservation error emitted from `copy(Sync)` functions during CI.
I apologize for the PR that I now realize, in hindsight, was probably a large number of lines of code to review in one PR. I should've made the commits much smaller and discussed with you a better commit approach before sending out this PR. If it helps in your review, @kt3k, I can either stub out the |
@jbronder Sorry for the delay in review. This PR looks in a good state. No need of splitting in my view. I'm going to review in more details soon. |
@jbronder I'll review in more details tomorrow |
fs/_node_fs_file.ts
Outdated
} | ||
|
||
async read(p: Uint8Array): Promise<number | null> { | ||
const nodeReadFd = this.#nodeUtil.promisify(this.#nodeFs.read); |
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 we store this function at this.#nodeReadFs
in the constructor? It feels like too much overhead to call promisify for each read
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.
Or maybe store in this function only when it's not initialized yet.
These notes were mistakes in upstream. See denoland/deno#28886
// This error is added to match the Deno runtime. Deno throws a `TypeError` | ||
// (os error 22) for this OpenOption combo. Under Node.js, the bitmask |
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.
Looks reasonable. Nice
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.
Looks nicely implemented and tested! Thank you for your contribution!
Thank you for looking over my PR and updating the promisified |
This PR adds
open
andopenSync
APIs to the@std/fs
package which are intended to mirror theDeno.open
andDeno.openSync
functions. In support of these APIs, theOpenOptions
type andgetOpenFsFlag
function are added to this PR.Also, since the
open(Sync)
APIs return anFsFile
object, theFsFile
interface,NodeFsFile
internal class to convert a Node.js file descriptor into anFsFile
instance as well as supporting runtime builtin module request functions are also added to this PR, (i.e.getNodeStream
,getNodeTty
, andgetNodeUtil
functions). Associated tests ofFsFile
methods are also added to this PR.Towards #6255.
Testing of the
open(Sync)
APIs are predominately intended to testOpenOptions
.Test of the
NodeFsFile
is intended to test the instance methods of these objects.Caveats regarding
NodeFsFile
implementationThe
NodeFsFile
does not include the following implementations with reasoning for omissions:seek(Sync)
: These methods rely on having theSeekMode
enum. At the time of submitting this PR, Node.js cannot process enum types without enabling the experimental flag--experimental-transform-types
in Node. Running Node.js with TS files only strips types for Node.js >= v23.6.0. For the purposes of passing CI, theSeekMode
enum andseek(Sync)
methods have been omitted.lock(Sync)
andunlock(Sync)
: These methods do not appear to have a direct Node.js equivalent. Based on the comments raised in issues from the Githubnodejs/node
repo: #49256, #54446, and #122 a Node.js equivalent may never materialize at all. To briefly summarize comments, the complexity of providing a cross-platformflock
implementation is driving the decision to not implement advisory file-locking in Node.js. As a result, anew Error("Method not implemented.")
is suggested to be thrown for these methods.setRaw
: Calling the Node.js version this method,setRawMode
, appears to require instantiating atty.ReadStream
object with the current underlying file descriptor. I'm currently running intoEAGAIN (errno 35)
errors on testing. It's likely that I need to spend more time on this method. In the meantime, anew Error("Method not implemented.")
is provided as a placeholder.The
Disposable
interface/protocol has been implemented in theNodeFsFile
class for users writing in TypeScript with Node.js such as using npm package liketsx
to run programs. Since theusing
keyword isn't recognized in Node.js yet, test cases have not been developed since Node runs tests in JavaScript and Explicit File Resource Management is currently at Stage 3.