@@ -63,7 +63,7 @@ shape of the [`node:fs`][] API. All paths are POSIX-style and absolute
6363
6464By default, the file tree is private to the VFS instance. To expose
6565it through the global ` node:fs ` module, ` require() ` , and ` import ` ,
66- call [ ` vfs.mount(prefix ) ` ] [ ] ; call [ ` vfs.unmount() ` ] [ ] (or rely on a
66+ call [ ` vfs.mount() ` ] [ ] ; call [ ` vfs.unmount() ` ] [ ] (or rely on a
6767` using ` declaration) to detach again.
6868
6969## ` vfs.create([provider][, options]) `
@@ -112,15 +112,12 @@ added: v26.4.0
112112 * ` emitExperimentalWarning ` {boolean} Whether to emit the experimental
113113 warning. ** Default:** ` true ` .
114114
115- ### ` vfs.mount([prefix] ) `
115+ ### ` vfs.mount() `
116116
117117<!-- YAML
118118added: REPLACEME
119119-->
120120
121- * ` prefix ` {string} A logical name for the mount inside the reserved
122- VFS namespace. Interpreted as a relative path; leading separators
123- are ignored. ** Default:** ` '/' ` .
124121* Returns: {string} The absolute mount point.
125122
126123Mounts the virtual file system and returns the resulting mount point.
@@ -129,33 +126,30 @@ After mounting, files in the VFS can be accessed through the
129126using paths under the returned mount point.
130127
131128Mount points always live inside a reserved namespace,
132- ` ${os.devNull}/vfs/layer- <layerId>/ ` . Because [ ` os.devNull ` ] [ ] is a
129+ ` ${os.devNull}/vfs/<layerId> ` . Because [ ` os.devNull ` ] [ ] is a
133130character device (POSIX) or a device-namespace path (Windows) that
134131cannot have child file system entries, no real file-system path can
135132exist under this namespace: virtual paths never conflate with (or
136133shadow) real paths, and the layer that owns a path is visible in the
137- path itself. The ` prefix ` argument is a purely logical name inside
138- the namespace. It is never resolved against the working directory,
139- and a prefix that attempts to escape the namespace (for example with
140- ` .. ` segments) throws ` ERR_INVALID_ARG_VALUE ` .
134+ path itself.
141135
142136``` cjs
143137const vfs = require (' node:vfs' );
144138const fs = require (' node:fs' );
145139
146140const myVfs = vfs .create ();
147141myVfs .writeFileSync (' /data.txt' , ' Hello' );
148- const mountPoint = myVfs .mount (' /virtual ' );
149- // e.g. '/dev/null/vfs/layer-0/virtual '
142+ const mountPoint = myVfs .mount ();
143+ // e.g. '/dev/null/vfs/0 '
150144
151145fs .readFileSync (` ${ mountPoint} /data.txt` , ' utf8' ); // 'Hello'
152146```
153147
154148Each ` VirtualFileSystem ` instance may be mounted at most once at a
155149time. Attempting to mount an already-mounted instance throws
156150` ERR_INVALID_STATE ` . Because each instance mounts inside its own
157- ` layer-<layerId> ` namespace, mounts from different instances can
158- never overlap, even when they use the same ` prefix ` .
151+ per-layer namespace, mounts from different instances can never
152+ overlap.
159153
160154The VFS supports the [ Explicit Resource Management] [ ] proposal. Use
161155a ` using ` declaration to unmount automatically when leaving scope:
@@ -168,7 +162,7 @@ let mountPoint;
168162{
169163 using myVfs = vfs .create ();
170164 myVfs .writeFileSync (' /data.txt' , ' Hello' );
171- mountPoint = myVfs .mount (' /virtual ' );
165+ mountPoint = myVfs .mount ();
172166
173167 fs .readFileSync (` ${ mountPoint} /data.txt` , ' utf8' ); // 'Hello'
174168} // VFS is automatically unmounted here
@@ -184,8 +178,7 @@ added: REPLACEME
184178
185179Unmounts the virtual file system. After unmounting, virtual files
186180are no longer reachable through ` node:fs ` , ` require() ` , or ` import ` .
187- The same instance may be mounted again, at the same or a different
188- prefix, by calling ` mount() ` .
181+ The same instance may be mounted again by calling ` mount() ` .
189182
190183This method is idempotent: calling ` unmount() ` on a VFS that is not
191184currently mounted has no effect.
@@ -209,7 +202,7 @@ added: REPLACEME
209202* {string | null}
210203
211204The current mount point as an absolute string (the value returned by
212- the last [ ` vfs.mount(prefix ) ` ] [ ] call), or ` null ` when the VFS is not
205+ the last [ ` vfs.mount() ` ] [ ] call), or ` null ` when the VFS is not
213206mounted.
214207
215208### ` vfs.layerId `
@@ -225,7 +218,7 @@ construction. The id is stable across `mount()` / `unmount()` cycles
225218for the lifetime of the instance, and is independent of the order in
226219which VFS layers are mounted.
227220
228- The layer id forms the ` layer- <id>` segment of the reserved mount
221+ The layer id forms the ` <id> ` segment of the reserved mount
229222namespace, so every path served by this instance carries the id, and
230223it appears in the ` NODE_DEBUG=vfs ` output for ` register ` and
231224` deregister ` events.
@@ -346,7 +339,7 @@ myVfs.mkdirSync('/lib');
346339myVfs .writeFileSync (' /lib/greet.js' , ' module.exports = () => "hi";' );
347340myVfs .writeFileSync (
348341 ' /lib/package.json' , ' {"main": "./greet.js"}' );
349- const mountPoint = myVfs .mount (' /virtual ' );
342+ const mountPoint = myVfs .mount ();
350343
351344const greet = require (` ${ mountPoint} /lib` );
352345console .log (greet ()); // 'hi'
@@ -364,7 +357,7 @@ import vfs from 'node:vfs';
364357
365358const myVfs = vfs .create ();
366359myVfs .writeFileSync (' /mod.mjs' , ' export const value = 42;' );
367- const mountPoint = myVfs .mount (' /virtual ' );
360+ const mountPoint = myVfs .mount ();
368361
369362const { value } = await import (
370363 pathToFileURL (` ${ mountPoint} /mod.mjs` ).href ,
@@ -524,5 +517,5 @@ fields use synthetic but stable values:
524517[ `fs.Stats` ] : fs.md#class-fsstats
525518[ `node:fs` ] : fs.md
526519[ `os.devNull` ] : os.md#osdevnull
527- [ `vfs.mount(prefix )` ] : #vfsmountprefix
520+ [ `vfs.mount()` ] : #vfsmount
528521[ `vfs.unmount()` ] : #vfsunmount
0 commit comments