Skip to content

Commit d5217e7

Browse files
committed
sea: remove getVfs from public API
The SEA VFS is automatically initialized and mounted at /sea. Users can access bundled assets directly via standard fs operations without needing to call any initialization function.
1 parent b1416b8 commit d5217e7

5 files changed

Lines changed: 16 additions & 109 deletions

File tree

doc/api/single-executable-applications.md

Lines changed: 14 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -180,32 +180,23 @@ See documentation of the [`sea.getAsset()`][], [`sea.getAssetAsBlob()`][],
180180
181181
Instead of using the `node:sea` API to access individual assets, you can use
182182
the Virtual File System (VFS) to access bundled assets through standard `fs`
183-
APIs. The VFS automatically populates itself with all assets defined in the
184-
SEA configuration and mounts them at a virtual path (default: `/sea`).
185-
186-
To use the VFS with SEA:
183+
APIs. When running as a Single Executable Application, the VFS is automatically
184+
initialized and mounted at `/sea`. All assets defined in the SEA configuration
185+
are accessible through this virtual path.
187186

188187
```cjs
189188
const fs = require('node:fs');
190-
const sea = require('node:sea');
191-
192-
// Get the SEA VFS (returns null if not running as SEA)
193-
const vfs = sea.getVfs();
194189

195-
if (vfs) {
196-
// Now you can use standard fs APIs to read bundled assets
197-
const rawConfig = fs.readFileSync('/sea/config.json', 'utf8');
198-
const data = fs.readFileSync('/sea/data/file.txt');
199-
200-
cons config = JSON.parse(rawconfig);
190+
// Assets are automatically available at /sea when running as SEA
191+
const config = JSON.parse(fs.readFileSync('/sea/config.json', 'utf8'));
192+
const data = fs.readFileSync('/sea/data/file.txt');
201193

202-
// Directory operations work too
203-
const files = fs.readdirSync('/sea/assets');
194+
// Directory operations work too
195+
const files = fs.readdirSync('/sea/assets');
204196

205-
// Check if a bundled file exists
206-
if (fs.existsSync('/sea/optional.json')) {
207-
// ...
208-
}
197+
// Check if a bundled file exists
198+
if (fs.existsSync('/sea/optional.json')) {
199+
// ...
209200
}
210201
```
211202

@@ -223,41 +214,16 @@ The VFS supports the following `fs` operations on bundled assets:
223214

224215
#### Loading modules from VFS in SEA
225216

226-
Once the VFS is initialized with `sea.getVfs()`, you can use `require()` directly
227-
with absolute VFS paths:
217+
You can use `require()` directly with absolute VFS paths:
228218

229219
```cjs
230-
const sea = require('node:sea');
231-
232-
// Initialize VFS - this must be called first
233-
sea.getVfs();
234-
235-
// Now you can require bundled modules directly
220+
// Require bundled modules directly
236221
const myModule = require('/sea/lib/mymodule.js');
237222
const utils = require('/sea/utils/helpers.js');
238223
```
239224

240225
The SEA's `require()` function automatically detects VFS paths (paths starting
241-
with the VFS mount point, e.g., `/sea/`) and loads modules from the virtual
242-
file system.
243-
244-
#### Custom mount prefix
245-
246-
By default, the VFS is mounted at `/sea`. You can specify a custom prefix
247-
when initializing the VFS:
248-
249-
```cjs
250-
const fs = require('node:fs');
251-
const sea = require('node:sea');
252-
253-
const vfs = sea.getSeaVfs({ prefix: '/app' });
254-
255-
// Assets are now accessible under /app
256-
const config = fs.readFileSync('/app/config.json', 'utf8');
257-
```
258-
259-
Note: `sea.getVfs()` returns a singleton. The `prefix` option is only used
260-
on the first call; subsequent calls return the same cached instance.
226+
with `/sea/`) and loads modules from the virtual file system.
261227

262228
### Startup snapshot support
263229

lib/sea.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,15 +81,10 @@ function getAssetKeys() {
8181
return getAssetKeysInternal() || [];
8282
}
8383

84-
const {
85-
getSeaVfs: getVfs,
86-
} = require('internal/vfs/sea');
87-
8884
module.exports = {
8985
isSea,
9086
getAsset,
9187
getRawAsset,
9288
getAssetAsBlob,
9389
getAssetKeys,
94-
getVfs,
9590
};

test/fixtures/sea/vfs/sea.js

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,8 @@
11
'use strict';
22
const fs = require('fs');
3-
const sea = require('node:sea');
43
const assert = require('assert');
54

6-
// Test getSeaVfs() returns a VFS instance
7-
const vfs = sea.getVfs();
8-
assert.ok(vfs !== null, 'getSeaVfs() should not return null');
9-
console.log('getSeaVfs returned VFS instance');
10-
11-
// Test that the VFS is mounted at /sea by default
5+
// Test that the VFS is automatically mounted at /sea
126
// and contains our assets
137

148
// Read the config file through standard fs (via VFS hooks)
@@ -48,11 +42,4 @@ assert.strictEqual(mathModule.add(2, 3), 5, 'math.add should work');
4842
assert.strictEqual(mathModule.multiply(4, 5), 20, 'math.multiply should work');
4943
console.log('direct require from VFS tests passed');
5044

51-
// Test getSeaVfs with custom prefix
52-
const customVfs = sea.getVfs({ prefix: '/custom' });
53-
// Note: getSeaVfs is a singleton, so it returns the same instance
54-
// with the same mount point (/sea) regardless of options passed after first call
55-
assert.strictEqual(customVfs, vfs, 'Should return the same cached instance');
56-
console.log('Cached VFS instance test passed');
57-
5845
console.log('All SEA VFS tests passed!');

test/parallel/test-vfs-sea.js

Lines changed: 0 additions & 41 deletions
This file was deleted.

test/sea/test-single-executable-application-vfs.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict';
22

3-
// This tests the SEA VFS integration - sea.getVfs() and sea.hasAssets()
3+
// This tests the SEA VFS integration - automatic VFS mount at /sea
44

55
require('../common');
66

0 commit comments

Comments
 (0)