Skip to content

Commit 816e24e

Browse files
Update doc/api/vfs.md
Co-authored-by: Joyee Cheung <joyeec9h3@gmail.com>
1 parent b993d9e commit 816e24e

1 file changed

Lines changed: 10 additions & 6 deletions

File tree

doc/api/vfs.md

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -359,12 +359,16 @@ console.log(value); // 42
359359
myVfs.unmount();
360360
```
361361

362-
Module identity follows the path: `__filename` and `module.filename`
363-
are the plain absolute path of the module under the mount point, and
364-
`import.meta.url` is the corresponding `file:` URL, with no synthetic
365-
decorations. Importing the same virtual path repeatedly, including
366-
through `import.meta.resolve()`, yields the same module instance,
367-
exactly as for real files.
362+
CommonJS modules loaded from a mounted VFS are identified by their VFS paths
363+
that start with the mount point. This is reflected in, for example, `__filename` and
364+
`__dirname` in the module, or the errors stack traces involving functions from
365+
the VFS modules. ES modules in the VFS are similarly identified by the `file:` URL of
366+
their VFS paths and this is reflected in e.g. `import.meta.url`.
367+
368+
Like modules loaded from the real file system, modules loaded from the VFS are
369+
cached on the first load. When `require()` or `import()` is used to load an absolute
370+
path or URL that falls under the mounted VFS multiple times, the module is only loaded
371+
once and subsequent calls return the same instance.
368372

369373
Calling [`vfs.unmount()`][] invalidates the modules that were loaded
370374
from the mount point: a subsequent `require()` or `import` of a path

0 commit comments

Comments
 (0)