Skip to content

Commit 38bf3ad

Browse files
committed
doc: add VFS limitations and cross-references
- Add "Limitations" section to vfs.md documenting unsupported features: native addons, child processes, worker threads, fs.watch polling, and SEA code caching - Add code caching limitations section to SEA VFS documentation - Add VFS support section to fs.md with example and link to vfs.md
1 parent bda370f commit 38bf3ad

File tree

3 files changed

+76
-0
lines changed

3 files changed

+76
-0
lines changed

doc/api/fs.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,36 @@ try {
121121
}
122122
```
123123

124+
## Virtual File System (VFS) support
125+
126+
<!-- YAML
127+
added: REPLACEME
128+
-->
129+
130+
> Stability: 1 - Experimental
131+
132+
The `fs` module can operate on virtual files when the [`node:vfs`][] module is
133+
used. When a virtual file system is mounted, `fs` operations on paths under
134+
the mount point are automatically routed to the VFS instead of the real file
135+
system.
136+
137+
```cjs
138+
const vfs = require('node:vfs');
139+
const fs = require('node:fs');
140+
141+
const myVfs = vfs.create();
142+
myVfs.writeFileSync('/data.txt', 'Hello from VFS');
143+
myVfs.mount('/virtual');
144+
145+
// This reads from the virtual file system
146+
fs.readFileSync('/virtual/data.txt', 'utf8'); // 'Hello from VFS'
147+
148+
myVfs.unmount();
149+
```
150+
151+
Not all `fs` operations are supported with VFS. See the [`node:vfs`][]
152+
documentation for the complete list of supported operations and limitations.
153+
124154
## Promises API
125155

126156
<!-- YAML
@@ -8773,6 +8803,7 @@ the file contents.
87738803
[`inotify(7)`]: https://man7.org/linux/man-pages/man7/inotify.7.html
87748804
[`kqueue(2)`]: https://www.freebsd.org/cgi/man.cgi?query=kqueue&sektion=2
87758805
[`minimatch`]: https://github.com/isaacs/minimatch
8806+
[`node:vfs`]: vfs.md
87768807
[`util.promisify()`]: util.md#utilpromisifyoriginal
87778808
[bigints]: https://tc39.github.io/proposal-bigint
87788809
[caveats]: #caveats

doc/api/single-executable-applications.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,14 @@ const utils = require('/sea/utils/helpers.js');
227227
The SEA's `require()` function automatically detects VFS paths (paths starting
228228
with `/sea/`) and loads modules from the virtual file system.
229229

230+
#### Code caching limitations
231+
232+
The `useCodeCache` option in the SEA configuration does not apply to modules
233+
loaded from the VFS. Code caching requires executing modules during the SEA
234+
build process to generate cached code, but VFS modules are only available at
235+
runtime after the SEA is built. If performance is critical, consider using
236+
`useCodeCache` for your main entry point and `useSnapshot` for initialization.
237+
230238
### Startup snapshot support
231239

232240
The `useSnapshot` field can be used to enable startup snapshot support. In this

doc/api/vfs.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,43 @@ console.log(greet('World')); // Hello, World!
131131
myVfs.unmount();
132132
```
133133

134+
## Limitations
135+
136+
The VFS has the following limitations:
137+
138+
### Native addons
139+
140+
Native addons (`.node` files) cannot be loaded from the VFS. Native addons
141+
must exist on the real file system because they are loaded by the operating
142+
system's dynamic linker, which cannot access virtual files.
143+
144+
### Child processes
145+
146+
Child processes spawned via `child_process.spawn()`, `child_process.exec()`,
147+
or similar methods cannot directly access VFS files. The child process runs
148+
in a separate address space and does not inherit the parent's VFS mounts.
149+
To share data with child processes, write files to the real file system or
150+
use inter-process communication.
151+
152+
### Worker threads
153+
154+
Each worker thread has its own independent VFS state. A VFS mounted in the
155+
main thread is not automatically available in worker threads. To use VFS in
156+
workers, create and mount a new VFS instance within each worker.
157+
158+
### fs.watch limitations
159+
160+
The `fs.watch()` and `fs.watchFile()` functions work with VFS files but use
161+
polling internally rather than native file system notifications, since VFS
162+
files exist only in memory.
163+
164+
### Code caching in SEA
165+
166+
When using VFS with Single Executable Applications, the `useCodeCache` option
167+
in the SEA configuration does not apply to modules loaded from the VFS. Code
168+
caching requires executing modules during the SEA build process, but VFS
169+
modules are only available at runtime.
170+
134171
## `vfs.create([provider][, options])`
135172

136173
<!-- YAML

0 commit comments

Comments
 (0)