Skip to content

Commit 8ad97f1

Browse files
committed
doc: address aduh95 review feedback on VFS docs
- Remove fd 10000 implementation detail from documentation - Move virtualCwd Worker threads example to Worker threads section
1 parent 976d0f8 commit 8ad97f1

File tree

1 file changed

+25
-31
lines changed

1 file changed

+25
-31
lines changed

doc/api/vfs.md

Lines changed: 25 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -654,31 +654,6 @@ const fs = require('node:fs');
654654
const content = fs.readFileSync('/project/src/index.js', 'utf8');
655655
```
656656

657-
### Using `virtualCwd` in Worker threads
658-
659-
Since `process.chdir()` is not available in Worker threads, you can use
660-
`RealFSProvider` to enable virtual working directory support:
661-
662-
```cjs
663-
const { Worker, isMainThread, parentPort } = require('node:worker_threads');
664-
const vfs = require('node:vfs');
665-
666-
if (isMainThread) {
667-
new Worker(__filename);
668-
} else {
669-
// In worker: mount real file system with virtualCwd enabled
670-
const realVfs = vfs.create(
671-
new vfs.RealFSProvider('/home/user/project'),
672-
{ virtualCwd: true },
673-
);
674-
realVfs.mount('/project');
675-
676-
// Now we can use virtual chdir in the worker
677-
realVfs.chdir('/project/src');
678-
console.log(realVfs.cwd()); // '/project/src'
679-
}
680-
```
681-
682657
### `realFSProvider.rootPath`
683658

684659
<!-- YAML
@@ -774,12 +749,6 @@ file system:
774749
* `stats.mtime`, `stats.ctime`, `stats.birthtime` are tracked per file
775750
* `stats.mode` includes the file type bits and permissions
776751

777-
### File descriptors
778-
779-
Virtual file descriptors start at 10000 to avoid conflicts with real operating
780-
system file descriptors. This allows the VFS to coexist with real file system
781-
operations without file descriptor collisions.
782-
783752
## Use with Single Executable Applications
784753

785754
When running as a Single Executable Application (SEA) with `"useVfs": true` in
@@ -900,6 +869,31 @@ if (isMainThread) {
900869
2. **Use `RealFSProvider`** - If the data exists on the real file system, use
901870
`RealFSProvider` in each worker to mount the same directory.
902871

872+
### Using `virtualCwd` in Worker threads
873+
874+
Since `process.chdir()` is not available in Worker threads, you can use
875+
`RealFSProvider` to enable virtual working directory support:
876+
877+
```cjs
878+
const { Worker, isMainThread, parentPort } = require('node:worker_threads');
879+
const vfs = require('node:vfs');
880+
881+
if (isMainThread) {
882+
new Worker(__filename);
883+
} else {
884+
// In worker: mount real file system with virtualCwd enabled
885+
const realVfs = vfs.create(
886+
new vfs.RealFSProvider('/home/user/project'),
887+
{ virtualCwd: true },
888+
);
889+
realVfs.mount('/project');
890+
891+
// Now we can use virtual chdir in the worker
892+
realVfs.chdir('/project/src');
893+
console.log(realVfs.cwd()); // '/project/src'
894+
}
895+
```
896+
903897
This limitation exists because implementing cross-thread VFS access would
904898
require moving the implementation to C++ with shared memory management, which
905899
significantly increases complexity. This may be addressed in future versions.

0 commit comments

Comments
 (0)