File tree Expand file tree Collapse file tree 2 files changed +19
-1
lines changed
Expand file tree Collapse file tree 2 files changed +19
-1
lines changed Original file line number Diff line number Diff line change @@ -188,9 +188,11 @@ are accessible through this virtual path.
188188const fs = require (' node:fs' );
189189
190190// Assets are automatically available at /sea when running as SEA
191- const config = JSON . parse ( fs .readFileSync (' /sea/config.json' , ' utf8' ) );
191+ const rawConfig = fs .readFileSync (' /sea/config.json' , ' utf8' );
192192const data = fs .readFileSync (' /sea/data/file.txt' );
193193
194+ const config = JSON .parse (rawConfig);
195+
194196// Directory operations work too
195197const files = fs .readdirSync (' /sea/assets' );
196198
Original file line number Diff line number Diff line change 22
33const { isSea, getAssetKeys } = internalBinding ( 'sea' ) ;
44const { kEmptyObject, getLazy } = require ( 'internal/util' ) ;
5+ const {
6+ codes : {
7+ ERR_INVALID_ARG_VALUE ,
8+ } ,
9+ } = require ( 'internal/errors' ) ;
510
611// Lazy-loaded VFS
712let cachedSeaVfs = null ;
13+ let cachedSeaVfsPrefix = null ;
814
915// Lazy-load VirtualFileSystem and SEAProvider to avoid loading VFS code if not needed
1016const lazyVirtualFileSystem = getLazy (
@@ -53,10 +59,20 @@ function createSeaVfs(options = kEmptyObject) {
5359 * This is a singleton that is lazily created on first access.
5460 * @param {object } [options] Configuration options (only used on first call)
5561 * @returns {VirtualFileSystem|null } The VFS instance, or null if not running as SEA
62+ * @throws {ERR_INVALID_ARG_VALUE } If called with a different prefix than the first call
5663 */
5764function getSeaVfs ( options ) {
65+ const prefix = options ?. prefix ?? '/sea' ;
66+
5867 if ( cachedSeaVfs === null ) {
5968 cachedSeaVfs = createSeaVfs ( options ) ;
69+ cachedSeaVfsPrefix = prefix ;
70+ } else if ( prefix !== cachedSeaVfsPrefix ) {
71+ throw new ERR_INVALID_ARG_VALUE (
72+ 'options.prefix' ,
73+ prefix ,
74+ `SEA VFS is already initialized with prefix '${ cachedSeaVfsPrefix } '` ,
75+ ) ;
6076 }
6177 return cachedSeaVfs ;
6278}
You can’t perform that action at this time.
0 commit comments