FSA-to-Node watcher bridge implementation#1266
Merged
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
Implements fs.watch and fs.watchFile support for the FSA-to-Node adapter by bridging to FileSystemObserver (for event-based watching) and adding a polling-based stat watcher (for watchFile).
Changes:
- Added
FsaNodeFsWatcher(fs.watch) powered byFileSystemObserver, plus wiring inFsaNodeFs. - Added
FsaNodeStatWatcher(fs.watchFile) with polling based onFile.lastModifiedandsize, plus updatedFsaNodeStatsto carry mtime info when available. - Introduced
options.FileSystemObserverinjection (with global fallback) and added tests for watch/watchFile and observer resolution.
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/fs-fsa-to-node/src/types.ts | Adds FsaNodeFsOptions to allow injecting a FileSystemObserver constructor. |
| packages/fs-fsa-to-node/src/index.ts | Exports the new watcher class from the package entrypoint. |
| packages/fs-fsa-to-node/src/FsaNodeStatWatcher.ts | New polling-based implementation for watchFile semantics. |
| packages/fs-fsa-to-node/src/FsaNodeStats.ts | Extends stats to populate time fields from an optional mtimeMs. |
| packages/fs-fsa-to-node/src/FsaNodeFsWatcher.ts | New FileSystemObserver-backed watcher used by fs.watch. |
| packages/fs-fsa-to-node/src/FsaNodeFs.ts | Implements watchFile, unwatchFile, and watch; exposes watcher classes on FsaNodeFs. |
| packages/fs-fsa-to-node/src/FsaNodeCore.ts | Adds observer resolution (options.FileSystemObserver → global fallback) and a throwing accessor. |
| packages/fs-fsa-to-node/src/tests/watchFile.test.ts | Adds coverage for watchFile/unwatchFile behaviors and edge cases. |
| packages/fs-fsa-to-node/src/tests/watch.test.ts | Adds coverage for watch behaviors, recursive mode, buffer encoding, and async startup errors. |
| packages/fs-fsa-to-node/src/tests/FsaNodeFs.test.ts | Tests options.FileSystemObserver precedence and fallback behavior. |
Comment on lines
+899
to
+906
| const watchOpts: opts.IWatchOptions = | ||
| typeof options === 'string' ? { encoding: options as BufferEncoding } : options || {}; | ||
| const { persistent = true, recursive = false, encoding = 'utf8' } = watchOpts; | ||
| const Observer = this.getFileSystemObserverOrThrow(); | ||
| const watcher = new FsaNodeFsWatcher(Observer, (folder, name) => this.getFileOrDir(folder, name, 'watch')); | ||
| watcher.start(filename, persistent, recursive, encoding as BufferEncoding); | ||
| if (listener) watcher.addListener('change', listener); | ||
| return watcher; |
Comment on lines
+34
to
+46
| public start( | ||
| path: misc.PathLike, | ||
| persistent: boolean = true, | ||
| recursive: boolean = false, | ||
| encoding: BufferEncoding = 'utf8', | ||
| ): void { | ||
| this.filename = String(path); | ||
| this.encoding = encoding; | ||
| const [folder, name] = pathToLocation(this.filename); | ||
| this.basename = name; | ||
| const observer = new this.Observer(records => this.onRecords(records)); | ||
| this.observer = observer; | ||
| this.resolveHandle(folder, name) |
Comment on lines
+90
to
+104
| public close(): void { | ||
| if (this.closed) return; | ||
| this.closed = true; | ||
| this.observer?.disconnect(); | ||
| this.observer = undefined; | ||
| queueMicrotask(() => this.emit('close')); | ||
| } | ||
|
|
||
| public ref(): this { | ||
| return this; | ||
| } | ||
|
|
||
| public unref(): this { | ||
| return this; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.