Skip to content

Commit cdc2a7a

Browse files
committed
doc: address vfs documentation review feedback
- Use JSON.stringify() instead of string literal in overlay example - Document multiple VirtualFileSystem instances interaction - Clarify mountPoint returns absolute path - Document unmount() is idempotent - Add Windows mount example with drive letters
1 parent 3d5e013 commit cdc2a7a

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

doc/api/vfs.md

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ const fs = require('node:fs');
6060

6161
// Overlay mode: only intercept files that exist in VFS
6262
const myVfs = vfs.create({ overlay: true });
63-
myVfs.writeFileSync('/etc/config.json', '{"mocked": true}');
63+
myVfs.writeFileSync('/etc/config.json', JSON.stringify({ mocked: true }));
6464
myVfs.mount('/');
6565

6666
// This reads from VFS (file exists in VFS)
@@ -203,6 +203,12 @@ added: REPLACEME
203203

204204
Creates a new `VirtualFileSystem` instance.
205205

206+
Multiple `VirtualFileSystem` instances can be created and used independently.
207+
Each instance maintains its own file tree and can be mounted at different
208+
paths. However, only one VFS can be mounted at a given path prefix at a time.
209+
If two VFS instances are mounted at overlapping paths (e.g., `/virtual` and
210+
`/virtual/sub`), the more specific path takes precedence for matching paths.
211+
206212
### `vfs.chdir(path)`
207213

208214
<!-- YAML
@@ -264,6 +270,19 @@ myVfs.mount('/virtual');
264270
require('node:fs').readFileSync('/virtual/data.txt', 'utf8'); // 'Hello'
265271
```
266272

273+
On Windows, mount paths use drive letters:
274+
275+
```cjs
276+
const vfs = require('node:vfs');
277+
278+
const myVfs = vfs.create();
279+
myVfs.writeFileSync('/data.txt', 'Hello');
280+
myVfs.mount('C:\\virtual');
281+
282+
// Now accessible as C:\virtual\data.txt
283+
require('node:fs').readFileSync('C:\\virtual\\data.txt', 'utf8'); // 'Hello'
284+
```
285+
267286
The VFS supports the [Explicit Resource Management][] proposal. Use the `using`
268287
declaration to automatically unmount when leaving scope:
269288

@@ -300,7 +319,7 @@ added: REPLACEME
300319

301320
* {string | null}
302321

303-
The current mount point, or `null` if not mounted.
322+
The current mount point as an absolute path, or `null` if not mounted.
304323

305324
### `vfs.overlay`
306325

@@ -357,6 +376,9 @@ accessible through the `fs` module. The VFS can be remounted at the same or a
357376
different path by calling `mount()` again. Unmounting also resets the virtual
358377
working directory if one was set.
359378

379+
This method is idempotent: calling `unmount()` on an already unmounted VFS
380+
has no effect.
381+
360382
### File System Methods
361383

362384
The `VirtualFileSystem` class provides methods that mirror the `fs` module API.

0 commit comments

Comments
 (0)