Skip to content

FSA-to-Node watcher bridge implementation#1266

Merged
streamich merged 3 commits into
masterfrom
fsa-to-node-watcher-bridge
Jul 7, 2026
Merged

FSA-to-Node watcher bridge implementation#1266
streamich merged 3 commits into
masterfrom
fsa-to-node-watcher-bridge

Conversation

@streamich

Copy link
Copy Markdown
Owner

No description provided.

Copilot AI review requested due to automatic review settings July 7, 2026 13:13
@streamich streamich merged commit 23e298a into master Jul 7, 2026
10 checks passed
@streamich streamich deleted the fsa-to-node-watcher-bridge branch July 7, 2026 13:18

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 by FileSystemObserver, plus wiring in FsaNodeFs.
  • Added FsaNodeStatWatcher (fs.watchFile) with polling based on File.lastModified and size, plus updated FsaNodeStats to carry mtime info when available.
  • Introduced options.FileSystemObserver injection (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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants