Skip to content

vfs: add vfs.mounted() - #66116

Closed
pipobscure wants to merge 1 commit into
nodejs:mainfrom
pipobscure:vfs-mounted
Closed

pipobscure wants to merge 1 commit into
nodejs:mainfrom
pipobscure:vfs-mounted

Conversation

@pipobscure

Copy link
Copy Markdown
Contributor

There was no way to find out which virtual file systems are mounted. That matters most for mounts a program did not make itself: those created by --vfs-mount and --vfs-load at startup, and the assets of a single executable application.

Add vfs.mounted(), which returns the VirtualFileSystem instances currently mounted in the calling thread, in the order they were mounted. A new array is returned on each call, so mutating it does not affect the mounts.

There was no way to find out which virtual file systems are mounted.
That matters most for mounts a program did not make itself: those
created by --vfs-mount and --vfs-load at startup, and the assets of a
single executable application.

Add vfs.mounted(), which returns the VirtualFileSystem instances
currently mounted in the calling thread, in the order they were
mounted. A new array is returned on each call, so mutating it does
not affect the mounts.

Signed-off-by: Philipp Dunkel <pip@pipobscure.com>
@nodejs-github-bot nodejs-github-bot added needs-ci PRs that need a full CI run. vfs Issues and PRs related to the virtual filesystem subsystem. labels Sep 18, 2026
@pipobscure
pipobscure marked this pull request as ready for review September 18, 2026 20:40
@bakkot

bakkot commented Sep 18, 2026

Copy link
Copy Markdown
Contributor

(Moving the conversation from the other thread)

I really don't like that these aren't named. There's plenty of ways to handle duplicate names, the most obvious being to simply abort, or to define some precedence order (last-wins, except that NODE_OPTIONS always takes precedent over CLI, say). Naming programmatically created volumes is also easy; you just programmatically create names.

But iterating over every mount poking at the contents to see if they're what you want is not very appealing. Nor is having to maintain a mapping between the order in which the --vfs-mount arguments were passed and the actual place you need to look, especially given that adding a new one in NODE_OPTIONS bumps all the CLI ones.

@pipobscure

pipobscure commented Sep 18, 2026

Copy link
Copy Markdown
Contributor Author

What would you think about this:

In the VFS Provider creation you have the optional specifying of a name that's attached to the provider.
Then the CLI syntax would benode --vfs-mount [name=]<target> as in the name is again optional.
require('node:vfs').mounted() would still return VirtualFilesystem objects, but since that gives you access to the provider they could also have a vfs.name property that gets the name out.

This would be fairly easy to retrofit and still maintain all the characteristics I care about as well.

If that's something that you'd be on board with, I'd be happy to add that as a new PR. (This one wouldn't really be affected)

@codecov

codecov Bot commented Sep 18, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.27%. Comparing base (dd5dfb5) to head (588a7fd).

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #66116   +/-   ##
=======================================
  Coverage   90.27%   90.27%           
=======================================
  Files         790      790           
  Lines      271651   271667   +16     
  Branches    51842    51849    +7     
=======================================
+ Hits       245228   245243   +15     
+ Misses      16928    16925    -3     
- Partials     9495     9499    +4     
Files with missing lines Coverage Δ
lib/internal/vfs/setup.js 87.13% <100.00%> (+0.16%) ⬆️
lib/vfs.js 100.00% <100.00%> (ø)

... and 17 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-ci PRs that need a full CI run. vfs Issues and PRs related to the virtual filesystem subsystem.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants