Skip to content

Commit 27063b5

Browse files
committed
vfs: gate node:vfs behind --experimental-vfs flag
Adds an --experimental-vfs runtime option that gates loading of the node:vfs builtin module, matching the pattern used by node:quic and node:stream/iter. Without the flag, require('node:vfs') / import 'node:vfs' throw ERR_UNKNOWN_BUILTIN_MODULE. All VFS test files are updated to pass --experimental-vfs. Assisted-by: Claude-Opus4.7
1 parent 9a1ca04 commit 27063b5

61 files changed

Lines changed: 132 additions & 9 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

doc/api/cli.md

Lines changed: 12 additions & 0 deletions

doc/api/vfs.md

Lines changed: 2 additions & 1 deletion

lib/internal/bootstrap/realm.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ const schemelessBlockList = new SafeSet([
133133
'vfs',
134134
]);
135135
// Modules that will only be enabled at run time.
136-
const experimentalModuleList = new SafeSet(['ffi', 'sqlite', 'quic', 'stream/iter', 'zlib/iter']);
136+
const experimentalModuleList = new SafeSet(['ffi', 'sqlite', 'quic', 'stream/iter', 'zlib/iter', 'vfs']);
137137

138138
// Set up process.binding() and process._linkedBinding().
139139
{

lib/internal/process/pre_execution.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ function prepareExecution(options) {
117117
setupFFI();
118118
setupSQLite();
119119
setupStreamIter();
120+
setupVfs();
120121
setupQuic();
121122
setupWebStorage();
122123
setupWebsocket();
@@ -421,6 +422,15 @@ function setupQuic() {
421422
BuiltinModule.allowRequireByUsers('quic');
422423
}
423424

425+
function setupVfs() {
426+
if (!getOptionValue('--experimental-vfs')) {
427+
return;
428+
}
429+
430+
const { BuiltinModule } = require('internal/bootstrap/realm');
431+
BuiltinModule.allowRequireByUsers('vfs');
432+
}
433+
424434
function setupWebStorage() {
425435
if (getEmbedderOptions().noBrowserGlobals ||
426436
!getOptionValue('--experimental-webstorage')) {

src/node_options.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -610,6 +610,10 @@ EnvironmentOptionsParser::EnvironmentOptionsParser() {
610610
"experimental iterable streams API (node:stream/iter)",
611611
&EnvironmentOptions::experimental_stream_iter,
612612
kAllowedInEnvvar);
613+
AddOption("--experimental-vfs",
614+
"experimental node:vfs module",
615+
&EnvironmentOptions::experimental_vfs,
616+
kAllowedInEnvvar);
613617
AddOption("--experimental-quic",
614618
#ifndef OPENSSL_NO_QUIC
615619
"experimental QUIC support",

src/node_options.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ class EnvironmentOptions : public Options {
132132
bool experimental_websocket = true;
133133
bool experimental_sqlite = HAVE_SQLITE;
134134
bool experimental_stream_iter = EXPERIMENTALS_DEFAULT_VALUE;
135+
bool experimental_vfs = EXPERIMENTALS_DEFAULT_VALUE;
135136
bool webstorage = HAVE_SQLITE;
136137
bool experimental_quic = EXPERIMENTALS_DEFAULT_VALUE;
137138
std::string localstorage_file;

test/parallel/test-vfs-access-modes.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// Flags: --experimental-vfs
12
'use strict';
23

34
// access / accessSync honour the R_OK / W_OK / X_OK / F_OK mode bits and

test/parallel/test-vfs-append-write.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// Flags: --experimental-vfs
12
'use strict';
23

34
// writeSync in append mode must append, not overwrite.

test/parallel/test-vfs-bigint-position.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// Flags: --experimental-vfs
12
'use strict';
23

34
// VFS readSync should accept a BigInt position parameter.

test/parallel/test-vfs-callback-api.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// Flags: --experimental-vfs
12
'use strict';
23

34
// Exercise the VFS callback-style async API on every method.

0 commit comments

Comments
 (0)