Skip to content

Commit 9560062

Browse files
committed
fs: remove createVirtual, use node:vfs instead
- Remove fs.createVirtual() from lib/fs.js - Remove VFS documentation section from doc/api/fs.md (lives in vfs.md) - Update all VFS tests to use require('node:vfs').create()
1 parent 7c9dac5 commit 9560062

13 files changed

+325
-929
lines changed

doc/api/fs.md

Lines changed: 0 additions & 590 deletions
Large diffs are not rendered by default.

lib/fs.js

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3207,20 +3207,6 @@ function globSync(pattern, options) {
32073207
return new Glob(pattern, options).globSync();
32083208
}
32093209

3210-
const lazyVfs = getLazy(() => require('internal/vfs/file_system').VirtualFileSystem);
3211-
3212-
/**
3213-
* Creates a new virtual file system instance.
3214-
* @param {object} [options] Configuration options
3215-
* @param {boolean} [options.fallthrough] Whether to fall through to real fs on miss
3216-
* @param {boolean} [options.moduleHooks] Whether to enable require/import hooks
3217-
* @returns {VirtualFileSystem}
3218-
*/
3219-
function createVirtual(options) {
3220-
const VirtualFileSystem = lazyVfs();
3221-
return new VirtualFileSystem(options);
3222-
}
3223-
32243210
module.exports = fs = {
32253211
appendFile,
32263212
appendFileSync,
@@ -3237,7 +3223,6 @@ module.exports = fs = {
32373223
cp,
32383224
cpSync,
32393225
createReadStream,
3240-
createVirtual,
32413226
createWriteStream,
32423227
exists,
32433228
existsSync,

test/parallel/test-vfs-basic.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,19 @@
22

33
require('../common');
44
const assert = require('assert');
5-
const fs = require('fs');
5+
const vfs = require('node:vfs');
66

7-
// Test that VirtualFileSystem can be created via fs.createVirtual()
7+
// Test that VirtualFileSystem can be created via vfs.create()
88
{
9-
const myVfs = fs.createVirtual();
9+
const myVfs = vfs.create();
1010
assert.ok(myVfs);
1111
assert.strictEqual(typeof myVfs.writeFileSync, 'function');
1212
assert.strictEqual(myVfs.mounted, false);
1313
}
1414

1515
// Test adding and reading a static file
1616
{
17-
const myVfs = fs.createVirtual();
17+
const myVfs = vfs.create();
1818
myVfs.mkdirSync('/test', { recursive: true });
1919
myVfs.writeFileSync('/test/file.txt', 'hello world');
2020

@@ -33,7 +33,7 @@ const fs = require('fs');
3333

3434
// Test statSync
3535
{
36-
const myVfs = fs.createVirtual();
36+
const myVfs = vfs.create();
3737
myVfs.mkdirSync('/test/dir', { recursive: true });
3838
myVfs.writeFileSync('/test/file.txt', 'content');
3939

@@ -54,7 +54,7 @@ const fs = require('fs');
5454

5555
// Test readdirSync
5656
{
57-
const myVfs = fs.createVirtual();
57+
const myVfs = vfs.create();
5858
myVfs.mkdirSync('/dir/subdir', { recursive: true });
5959
myVfs.writeFileSync('/dir/a.txt', 'a');
6060
myVfs.writeFileSync('/dir/b.txt', 'b');
@@ -89,7 +89,7 @@ const fs = require('fs');
8989

9090
// Test removing entries
9191
{
92-
const myVfs = fs.createVirtual();
92+
const myVfs = vfs.create();
9393
myVfs.mkdirSync('/test', { recursive: true });
9494
myVfs.writeFileSync('/test/file.txt', 'content');
9595

@@ -105,7 +105,7 @@ const fs = require('fs');
105105

106106
// Test mount mode
107107
{
108-
const myVfs = fs.createVirtual();
108+
const myVfs = vfs.create();
109109
myVfs.mkdirSync('/data', { recursive: true });
110110
myVfs.writeFileSync('/data/file.txt', 'mounted content');
111111

@@ -124,7 +124,7 @@ const fs = require('fs');
124124

125125
// Test internalModuleStat (used by Module._stat)
126126
{
127-
const myVfs = fs.createVirtual();
127+
const myVfs = vfs.create();
128128
myVfs.mkdirSync('/dir', { recursive: true });
129129
myVfs.writeFileSync('/module.js', 'module.exports = {}');
130130

@@ -135,7 +135,7 @@ const fs = require('fs');
135135

136136
// Test reading directory as file throws EISDIR
137137
{
138-
const myVfs = fs.createVirtual();
138+
const myVfs = vfs.create();
139139
myVfs.mkdirSync('/mydir', { recursive: true });
140140

141141
assert.throws(() => {
@@ -145,7 +145,7 @@ const fs = require('fs');
145145

146146
// Test realpathSync
147147
{
148-
const myVfs = fs.createVirtual();
148+
const myVfs = vfs.create();
149149
myVfs.mkdirSync('/test', { recursive: true });
150150
myVfs.writeFileSync('/test/file.txt', 'content');
151151

test/parallel/test-vfs-chdir-worker.js

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22

33
const common = require('../common');
44
const assert = require('assert');
5-
const fs = require('fs');
5+
const vfs = require('node:vfs');
66
const { Worker, isMainThread, parentPort, workerData } = require('worker_threads');
77

88
if (isMainThread) {
99
// Test 1: Verify that VFS setup in main thread doesn't automatically apply to workers
1010
{
11-
const vfs = fs.createVirtual({ virtualCwd: true });
12-
vfs.mkdirSync('/project', { recursive: true });
13-
vfs.mount('/virtual');
11+
const myVfs = vfs.create({ virtualCwd: true });
12+
myVfs.mkdirSync('/project', { recursive: true });
13+
myVfs.mount('/virtual');
1414

1515
// Set virtual cwd in main thread
1616
process.chdir('/virtual/project');
@@ -29,7 +29,7 @@ if (isMainThread) {
2929

3030
worker.on('exit', common.mustCall((code) => {
3131
assert.strictEqual(code, 0);
32-
vfs.unmount();
32+
myVfs.unmount();
3333
}));
3434
}
3535

@@ -75,30 +75,30 @@ if (isMainThread) {
7575
parentPort.postMessage({ cwd: process.cwd() });
7676
} else if (test === 'worker-independent-vfs') {
7777
// Set up VFS independently in worker
78-
const vfs = fs.createVirtual({ virtualCwd: true });
79-
vfs.mkdirSync('/data', { recursive: true });
80-
vfs.mount('/worker-virtual');
78+
const myVfs = vfs.create({ virtualCwd: true });
79+
myVfs.mkdirSync('/data', { recursive: true });
80+
myVfs.mount('/worker-virtual');
8181

8282
process.chdir('/worker-virtual/data');
8383
const cwd = process.cwd();
8484

85-
vfs.unmount();
85+
myVfs.unmount();
8686

8787
parentPort.postMessage({ success: true, cwd });
8888
} else if (test === 'worker-create-vfs') {
8989
// Test VFS creation and chdir in worker
90-
const vfs = fs.createVirtual({ virtualCwd: true });
91-
vfs.mkdirSync('/project/src', { recursive: true });
92-
vfs.mount('/');
90+
const myVfs = vfs.create({ virtualCwd: true });
91+
myVfs.mkdirSync('/project/src', { recursive: true });
92+
myVfs.mount('/');
9393

94-
vfs.chdir('/project/src');
94+
myVfs.chdir('/project/src');
9595

9696
parentPort.postMessage({
9797
success: true,
98-
virtualCwdEnabled: vfs.virtualCwdEnabled,
99-
vfsCwd: vfs.cwd(),
98+
virtualCwdEnabled: myVfs.virtualCwdEnabled,
99+
vfsCwd: myVfs.cwd(),
100100
});
101101

102-
vfs.unmount();
102+
myVfs.unmount();
103103
}
104104
}

0 commit comments

Comments
 (0)