Skip to content

Commit 1300143

Browse files
committed
vfs: only initialize SEA VFS when assets exist
1 parent 0feeed4 commit 1300143

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

lib/internal/main/embedding.js

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

217+
// Initialize SEA VFS before running the main script so fs hooks are active
218+
if (isLoadingSea) {
219+
initSeaVfs();
220+
}
221+
217222
if (format === moduleFormats.kCommonJS) {
218223
return embedderRunCjs(content, filename);
219224
} 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)