-
-
Notifications
You must be signed in to change notification settings - Fork 34.6k
Virtual File System for Node.js #61478
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
mcollina
wants to merge
39
commits into
nodejs:main
Choose a base branch
from
mcollina:vfs
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+11,072
−13
Open
Changes from all commits
Commits
Show all changes
39 commits
Select commit
Hold shift + click to select a range
28ac77e
fs: add virtual file system support
mcollina c35f783
vfs: add Windows path compatibility
mcollina 27a7fa6
sea: support VFS in embedderRequire
mcollina 17ba78e
test: add tmpdir.refresh() to SEA VFS test
mcollina d501c7b
test: update SEA VFS test for new buildSEA API
mcollina 956295e
vfs: add provider-based architecture and node:vfs module
mcollina d207441
vfs: remove backward compat methods, use standard fs API
mcollina cef55ed
vfs: address review comments
mcollina 38f5110
vfs: fix lint errors
mcollina 37d40a2
vfs: fix lint errors
mcollina 2364402
vfs: remove public createSEA()
mcollina dd11a48
vfs: address review comments
mcollina 2fff415
doc: address review comments on VFS documentation
mcollina b82cc48
doc: clarify virtualCwd behavior in Worker threads
mcollina ad601c8
vfs: add RealFSProvider for mounting real directories
mcollina b9ab348
tools: add VFS types to doc type-parser
mcollina d930079
doc: use REPLACEME for version placeholders in vfs.md
mcollina 3388e9d
doc: add security warnings and symlink documentation to vfs.md
mcollina 22c3842
vfs: address code review feedback from @jasnell
mcollina 3de6a3f
vfs: add overlay mode for selective file interception
mcollina 7c9dac5
vfs: add tests and fix appendFile, add readonly checks
mcollina 9560062
fs: remove createVirtual, use node:vfs instead
mcollina 826d4ae
vfs: add watch and watchFile support
mcollina abe6d08
vfs: improve test coverage for watch implementation
mcollina 51def85
vfs: remove unused utility functions from module_hooks
mcollina d6db585
vfs: add test for symlink target creation after symlink
mcollina a4514bc
doc: add worker thread limitations to VFS documentation
mcollina dae621c
doc: clarify VFS accepts same types as fs module
mcollina ab1d435
vfs: remove unused entries.js, add error tests
mcollina 94b014b
vfs: remove unused exports from fd.js and stats.js
mcollina 0b81588
vfs: remove unused VirtualFD methods
mcollina 612abc3
vfs: remove more unused VirtualFD code
mcollina 5e80b9e
vfs: address Aviv's review comments
mcollina b58eafd
test: improve VFS code coverage
mcollina 8e20926
Update lib/internal/vfs/module_hooks.js
mcollina 7acfa2e
Update lib/internal/vfs/module_hooks.js
mcollina 237fd14
vfs: address aduh95 review comments
mcollina 2531ff5
vfs: remove SEAProvider export and hasSeaAssets
mcollina a6b0f29
vfs: remove addFile and addDirectory methods
mcollina File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -174,6 +174,89 @@ const raw = getRawAsset('a.jpg'); | |
| See documentation of the [`sea.getAsset()`][], [`sea.getAssetAsBlob()`][], | ||
| [`sea.getRawAsset()`][] and [`sea.getAssetKeys()`][] APIs for more information. | ||
|
|
||
| ### Virtual File System (VFS) for assets | ||
|
|
||
| > Stability: 1 - Experimental | ||
| Instead of using the `node:sea` API to access individual assets, you can use | ||
| the Virtual File System (VFS) to access bundled assets through standard `fs` | ||
| APIs. The VFS automatically populates itself with all assets defined in the | ||
| SEA configuration and mounts them at a virtual path (default: `/sea`). | ||
|
|
||
| To use the VFS with SEA: | ||
|
|
||
| ```cjs | ||
| const fs = require('node:fs'); | ||
| const sea = require('node:sea'); | ||
|
|
||
| // Get the SEA VFS (returns null if not running as SEA) | ||
| const vfs = sea.getVfs(); | ||
|
|
||
| if (vfs) { | ||
| // Now you can use standard fs APIs to read bundled assets | ||
| const config = JSON.parse(fs.readFileSync('/sea/config.json', 'utf8')); | ||
| const data = fs.readFileSync('/sea/data/file.txt'); | ||
|
|
||
| // Directory operations work too | ||
| const files = fs.readdirSync('/sea/assets'); | ||
|
|
||
| // Check if a bundled file exists | ||
| if (fs.existsSync('/sea/optional.json')) { | ||
| // ... | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| The VFS supports the following `fs` operations on bundled assets: | ||
|
|
||
| * `readFileSync()` / `readFile()` / `promises.readFile()` | ||
| * `statSync()` / `stat()` / `promises.stat()` | ||
| * `lstatSync()` / `lstat()` / `promises.lstat()` | ||
| * `readdirSync()` / `readdir()` / `promises.readdir()` | ||
| * `existsSync()` | ||
| * `realpathSync()` / `realpath()` / `promises.realpath()` | ||
| * `accessSync()` / `access()` / `promises.access()` | ||
| * `openSync()` / `open()` - for reading | ||
| * `createReadStream()` | ||
|
|
||
| #### Loading modules from VFS in SEA | ||
|
|
||
| Once the VFS is initialized with `sea.getVfs()`, you can use `require()` directly | ||
| with absolute VFS paths: | ||
|
|
||
| ```cjs | ||
| const sea = require('node:sea'); | ||
|
|
||
| // Initialize VFS - this must be called first | ||
| sea.getVfs(); | ||
|
|
||
| // Now you can require bundled modules directly | ||
| const myModule = require('/sea/lib/mymodule.js'); | ||
| const utils = require('/sea/utils/helpers.js'); | ||
| ``` | ||
|
|
||
| The SEA's `require()` function automatically detects VFS paths (paths starting | ||
| with the VFS mount point, e.g., `/sea/`) and loads modules from the virtual | ||
| file system. | ||
|
|
||
| #### Custom mount prefix | ||
|
|
||
| By default, the VFS is mounted at `/sea`. You can specify a custom prefix | ||
| when initializing the VFS: | ||
|
|
||
| ```cjs | ||
| const fs = require('node:fs'); | ||
| const sea = require('node:sea'); | ||
|
|
||
| const vfs = sea.getSeaVfs({ prefix: '/app' }); | ||
|
|
||
| // Assets are now accessible under /app | ||
| const config = fs.readFileSync('/app/config.json', 'utf8'); | ||
| ``` | ||
|
|
||
| Note: `sea.getVfs()` returns a singleton. The `prefix` option is only used | ||
| on the first call; subsequent calls return the same cached instance. | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: would prefer it to throw if a different |
||
|
|
||
| ### Startup snapshot support | ||
|
|
||
| The `useSnapshot` field can be used to enable startup snapshot support. In this | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: I'd separate these just slightly to ensure clarity. Otherwise the nested
readFileSyncgets a bit lost.