Skip to content

Commit 61be027

Browse files
committed
vfs: keep --experimental-vfs negatable
Keep VFS enabled by default while allowing the negated flag to disable node:vfs exposure and --vfs-load. Assisted-by: pi Signed-off-by: Matteo Collina <hello@matteocollina.com>
1 parent 538d522 commit 61be027

9 files changed

Lines changed: 78 additions & 19 deletions

File tree

‎doc/api/cli.md‎

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2350,6 +2350,18 @@ changes:
23502350

23512351
Disable the experimental [`node:sqlite`][] module.
23522352

2353+
### `--no-experimental-vfs`
2354+
2355+
<!-- YAML
2356+
added: v26.4.0
2357+
changes:
2358+
- version: REPLACEME
2359+
pr-url: https://github.com/nodejs/node/pull/66318
2360+
description: VFS is unflagged but still experimental.
2361+
-->
2362+
2363+
Disable the experimental [`node:vfs`][] module and `--vfs-load`.
2364+
23532365
### `--no-experimental-webstorage`
23542366

23552367
<!-- YAML
@@ -3895,7 +3907,9 @@ May be given at most once.
38953907

38963908
Mounts `source` as a virtual file system ([`node:vfs`][]), and runs the entry
38973909
point and all subsequent `require()`/`import` resolution against that mount
3898-
rather than the real file system. The mount is placed at a reserved mount point
3910+
rather than the real file system. This option is unavailable when
3911+
`--no-experimental-vfs` disables [`node:vfs`][]. The mount is placed at a
3912+
reserved mount point
38993913
assigned by Node.js, so it never shadows real paths and no target can be
39003914
chosen. The entry point is taken from the mount the same way `node <directory>`
39013915
takes one: the mount's own `package.json` `"main"`, or `index.js`. Any
@@ -4301,6 +4315,7 @@ one is included in the list below.
43014315
* `--no-experimental-global-navigator`
43024316
* `--no-experimental-sqlite`
43034317
* `--no-experimental-strip-types`
4318+
* `--no-experimental-vfs`
43044319
* `--no-experimental-webstorage`
43054320
* `--no-extra-info-on-fatal-exception`
43064321
* `--no-force-async-hooks-checks`

‎doc/node.1‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1230,6 +1230,9 @@ Legacy alias for \fB--no-require-module\fR.
12301230
.It Fl -no-experimental-sqlite
12311231
Disable the experimental \fBnode:sqlite\fR module.
12321232
.
1233+
.It Fl -no-experimental-vfs
1234+
Disable the experimental \fBnode:vfs\fR module and \fB--vfs-load\fR.
1235+
.
12331236
.It Fl -no-experimental-webstorage
12341237
Disable \fBWeb Storage\fR support.
12351238
.
@@ -1973,7 +1976,9 @@ Print node's version.
19731976
May be given at most once.
19741977
Mounts \fBsource\fR as a virtual file system (\fBnode:vfs\fR), and runs the entry
19751978
point and all subsequent \fBrequire()\fR/\fBimport\fR resolution against that mount
1976-
rather than the real file system. The mount is placed at a reserved mount point
1979+
rather than the real file system. This option is unavailable when
1980+
\fB--no-experimental-vfs\fR disables \fBnode:vfs\fR. The mount is placed at a
1981+
reserved mount point
19771982
assigned by Node.js, so it never shadows real paths and no target can be
19781983
chosen. The entry point is taken from the mount the same way \fBnode <directory>\fR
19791984
takes one: the mount's own \fBpackage.json\fR \fB"main"\fR, or \fBindex.js\fR. Any
@@ -2338,6 +2343,8 @@ one is included in the list below.
23382343
.It
23392344
\fB--no-experimental-strip-types\fR
23402345
.It
2346+
\fB--no-experimental-vfs\fR
2347+
.It
23412348
\fB--no-experimental-webstorage\fR
23422349
.It
23432350
\fB--no-extra-info-on-fatal-exception\fR

‎lib/internal/bootstrap/realm.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ const builtinModulePolicies = [
207207
['stream/iter', false, '--experimental-stream-iter'],
208208
['test', true, null],
209209
['test/reporters', true, null],
210-
['vfs', true, null],
210+
['vfs', true, '--experimental-vfs'],
211211
['zlib/iter', false, '--experimental-stream-iter'],
212212
];
213213

‎src/node.cc‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1118,6 +1118,9 @@ static ExitCode InitializeNodeWithArgsInternal(
11181118
// count below needs the arguments the command line itself gave.
11191119
{
11201120
auto* env_options = per_process::cli_options->per_isolate->per_env.get();
1121+
if (!env_options->experimental_vfs && env_options->vfs_load) {
1122+
errors->push_back("--vfs-load requires node:vfs to be enabled");
1123+
}
11211124
// A second --vfs-load would silently replace the first, and the option
11221125
// itself cannot say how often it was given; count it in the node options
11231126
// the command line yielded.

‎src/node_options.cc‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -808,11 +808,11 @@ EnvironmentOptionsParser::EnvironmentOptionsParser() {
808808
NoOp{},
809809
#endif
810810
kAllowedInEnvvar);
811-
// Retained as a no-op for compatibility; node:vfs is no longer gated.
812811
AddOption("--experimental-vfs",
813-
"",
812+
"experimental node:vfs module",
814813
BOOL_FIELD(experimental_vfs),
815-
kAllowedInEnvvar);
814+
kAllowedInEnvvar,
815+
true);
816816
// Choosing the entry point is the command line's alone: an environment
817817
// variable must not be able to redirect what a `node <args>` invocation runs,
818818
// so this is rejected in NODE_OPTIONS. The source and whether to run from it

‎src/node_options.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ class EnvironmentOptions : public Options {
215215
DEFINE_BOOL_FIELD(experimental_websocket) = true;
216216
DEFINE_BOOL_FIELD(experimental_sqlite) = HAVE_SQLITE;
217217
DEFINE_BOOL_FIELD(experimental_stream_iter) = EXPERIMENTALS_DEFAULT_VALUE;
218-
DEFINE_BOOL_FIELD(experimental_vfs) = EXPERIMENTALS_DEFAULT_VALUE;
218+
DEFINE_BOOL_FIELD(experimental_vfs) = true;
219219
DEFINE_BOOL_FIELD(vfs_load) = false;
220220
DEFINE_BOOL_FIELD(webstorage) = HAVE_SQLITE;
221221
DEFINE_BOOL_FIELD(experimental_dtls) = EXPERIMENTALS_DEFAULT_VALUE;

‎test/parallel/test-module-builtin-experimental.js‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,13 @@ if (common.hasFFI) {
5151
], { status: 0 });
5252
}
5353

54+
// node:vfs is enabled by default and can be disabled with
55+
// --no-experimental-vfs.
56+
spawnSyncAndAssert(process.execPath, [
57+
'--no-experimental-vfs',
58+
'-e', `const m = require('node:module'); if (m.builtinModules.includes('node:vfs')) process.exit(1); try { require('node:vfs'); } catch (e) { if (e.code === 'ERR_UNKNOWN_BUILTIN_MODULE') process.exit(0); } process.exit(1);`,
59+
], { status: 0 });
60+
5461
const schemeOnlyBuiltins = ['node:test', 'node:sea', 'node:vfs'];
5562
if (common.hasFFI) {
5663
schemeOnlyBuiltins.push('node:ffi');

‎test/parallel/test-vfs-flag.js‎

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use strict';
22

3-
// node:vfs is available without an experimental flag. The old flag remains a
4-
// no-op for compatibility, and the module remains available with --no- form.
3+
// node:vfs is available without an experimental flag. The old positive flag
4+
// remains accepted for compatibility, and --no-experimental-vfs disables it.
55

66
require('../common');
77
const { spawnSyncAndAssert } = require('../common/child_process');
@@ -28,14 +28,25 @@ const { spawnSyncAndAssert } = require('../common/child_process');
2828
});
2929
}
3030

31-
// The old flag is accepted for compatibility but no longer gates the module.
32-
for (const flag of ['--experimental-vfs', '--no-experimental-vfs']) {
33-
spawnSyncAndAssert(process.execPath, [
34-
flag,
35-
'-p',
36-
'require("node:module").builtinModules.includes("node:vfs")',
37-
], { stdout: 'true\n', stderr: '' });
38-
}
31+
// The old positive flag is accepted for compatibility but no longer gates the
32+
// module.
33+
spawnSyncAndAssert(process.execPath, [
34+
'--experimental-vfs',
35+
'-p',
36+
'require("node:module").builtinModules.includes("node:vfs")',
37+
], { stdout: 'true\n', stderr: '' });
38+
39+
// --no-experimental-vfs disables node:vfs.
40+
spawnSyncAndAssert(process.execPath, [
41+
'--no-experimental-vfs',
42+
'-p',
43+
'require("node:module").builtinModules.includes("node:vfs")',
44+
], { stdout: 'false\n', stderr: '' });
45+
46+
spawnSyncAndAssert(process.execPath, [
47+
'--no-experimental-vfs',
48+
'-e', 'require("node:vfs")',
49+
], { status: 1, stderr: /ERR_UNKNOWN_BUILTIN_MODULE/ });
3950

4051
// Bare `vfs` (no node: scheme) remains unavailable.
4152
spawnSyncAndAssert(process.execPath, [

‎test/parallel/test-vfs-load.js‎

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,15 @@ function envArg(flag, value) {
4949
assert.match(res.stdout, /hello from inside the mount/);
5050
}
5151

52+
// --no-experimental-vfs disables --vfs-load.
53+
{
54+
const dir = fixture('disabled');
55+
fs.mkdirSync(dir, { recursive: true });
56+
const res = run(['--no-experimental-vfs', `--vfs-load=${dir}`]);
57+
assert.notStrictEqual(res.status, 0);
58+
assert.match(res.stderr, /--vfs-load requires node:vfs to be enabled/);
59+
}
60+
5261
// A provider registered by a -r (CommonJS) preload backs a custom file format.
5362
{
5463
const providerModule = fixture('provider.js');
@@ -318,8 +327,8 @@ if (hasNodeOptions) {
318327
}
319328
}
320329

321-
// The old --experimental-vfs option remains accepted in NODE_OPTIONS, but no
322-
// longer gates --vfs-load.
330+
// The old --experimental-vfs option remains accepted in NODE_OPTIONS. Its
331+
// positive form no longer gates --vfs-load, and its negated form disables it.
323332
if (hasNodeOptions) {
324333
const dir = fixture('env-flag-cli-load');
325334
fs.mkdirSync(dir, { recursive: true });
@@ -331,6 +340,13 @@ if (hasNodeOptions) {
331340
});
332341
assert.strictEqual(res.status, 0, res.stderr);
333342
assert.match(res.stdout, /ran/);
343+
344+
const disabled = spawnSync(process.execPath, [`--vfs-load=${dir}`], {
345+
encoding: 'utf8',
346+
env: { ...process.env, NODE_OPTIONS: '--no-experimental-vfs' },
347+
});
348+
assert.notStrictEqual(disabled.status, 0);
349+
assert.match(disabled.stderr, /--vfs-load requires node:vfs to be enabled/);
334350
}
335351

336352
// Under --vfs-load the entry point comes from the mount, so no positional

0 commit comments

Comments
 (0)