Skip to content

node:fs — implement fs.watch / watchFile / promises.watch (plus cp, readlink, truncate, utimes) #28

Closed

Description

@hassidan

Summary

node:fs in v0.10.5 covers sync, callback and promise APIs (readFile, createReadStream, realpath, symlink, chmod, mkdtemp, opendir, lstat, …) but fs.watch, fs.watchFile, fs.unwatchFile and fs.promises.watch are absent (crates/slice-engine/src/preludes/node_builtins.rs, verified at a0c723e).

Why it matters

File watching is the entry point for dev servers, hot-reload loops, log tailers and config reloaders. Many npm packages (chokidar, nodemon, vite, tsx --watch, pino rotation plugins) call fs.watch directly and currently throw TypeError: fs.watch is not a function.

Proposal

  • Implement fs.watch(path, [options], listener) returning an FSWatcher (EventEmitter with change/rename/error/close, .close(), .ref()/.unref()).
  • Implement fs.watchFile/unwatchFile (polling, Stats objects).
  • Implement fs.promises.watch() as an async iterator.
  • Back it with the notify crate already used by slice run --watch, and route events through runtime/event_loop.rs.
  • Gate watched paths with the existing FsCap read allow-list; a watcher on a non-permitted path should fail with the same FsReadDenied error as readFile.
  • VFS semantics: watchers should fire for in-memory VFS writes as well as host-disk writes, otherwise slice test time-travel rollbacks produce silent inconsistencies.

Also missing in node:fs

fs.cp, fs.readlink, fs.truncate, fs.utimes (+ sync/promises variants). These are smaller and could ship in the same change.

Activity

  1. siktec-lab commented on Nov 9, 2026

    @siktec-lab
    Collaborator

    Addressed in #41 (�0.10.6).

    • statSync (�igint/ hrowIfNoEntry), lstatSync,
      ealpathSync, chmodSync, chownSync, �ccessSync, opendirSync, and createReadStream/createWriteStream were already implemented in Slice's copy-on-write VFS.
    • Added the remaining functions (cpSync/cp,
      eadlinkSync/
      eadlink, runcateSync/ runcate, utimesSync/utimes, lutimesSync/lutimes, watch/watchFile/unwatchFile, and s.promises.* equivalents) backed by the in-memory CoW VFS with zero cold-start overhead.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions