Skip to content

Commit bffba9a

Browse files
committed
vfs: only initialize SEA VFS when assets exist
1 parent 3ca8f54 commit bffba9a

2 files changed

Lines changed: 13 additions & 2 deletions

File tree

lib/internal/main/embedding.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,11 @@ function embedderRunEntryPoint(content, format, filename) {
195195
format ||= moduleFormats.kCommonJS;
196196
filename ||= process.execPath;
197197

198+
// Initialize SEA VFS before running the main script so fs hooks are active
199+
if (isLoadingSea) {
200+
initSeaVfs();
201+
}
202+
198203
if (format === moduleFormats.kCommonJS) {
199204
return embedderRunCjs(content, filename);
200205
} else if (format === moduleFormats.kModule) {

lib/internal/vfs/sea.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict';
22

3-
const { isSea } = internalBinding('sea');
3+
const { isSea, getAssetKeys } = internalBinding('sea');
44
const { kEmptyObject, getLazy } = require('internal/util');
55

66
// Lazy-loaded VFS
@@ -20,13 +20,19 @@ const lazySEAProvider = getLazy(
2020
* @param {object} [options] Configuration options
2121
* @param {string} [options.prefix] Mount point prefix for SEA assets
2222
* @param {boolean} [options.moduleHooks] Whether to enable require/import hooks
23-
* @returns {VirtualFileSystem|null} The VFS instance, or null if not running as SEA
23+
* @returns {VirtualFileSystem|null} The VFS instance, or null if not running as SEA or no assets
2424
*/
2525
function createSeaVfs(options = kEmptyObject) {
2626
if (!isSea()) {
2727
return null;
2828
}
2929

30+
// Only create VFS if there are VFS assets
31+
const keys = getAssetKeys();
32+
if (!keys || keys.length === 0) {
33+
return null;
34+
}
35+
3036
const VirtualFileSystem = lazyVirtualFileSystem();
3137
const SEAProvider = lazySEAProvider();
3238

0 commit comments

Comments
 (0)