Skip to content

Commit dd11a48

Browse files
committed
vfs: address review comments
- Use getLazy utility for lazy loading VirtualFileSystem and SEAProvider - Import getLazy from internal/util instead of manual ??= pattern
1 parent 2364402 commit dd11a48

2 files changed

Lines changed: 14 additions & 7 deletions

File tree

lib/internal/test_runner/mock/mock.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ const {
3434
} = require('internal/url');
3535
const {
3636
emitExperimentalWarning,
37+
getLazy,
3738
getStructuredStack,
3839
kEmptyObject,
3940
} = require('internal/util');
@@ -53,7 +54,9 @@ const { _load, _nodeModulePaths, _resolveFilename, isBuiltin } = Module;
5354
const { join } = require('path');
5455

5556
// Lazy-load VirtualFileSystem to avoid loading VFS code if fs mocking is not used
56-
let VirtualFileSystem;
57+
const lazyVirtualFileSystem = getLazy(
58+
() => require('internal/vfs/virtual_fs').VirtualFileSystem,
59+
);
5760
function kDefaultFunction() {}
5861
const enableModuleMocking = getOptionValue('--experimental-test-module-mocks');
5962
const kSupportedFormats = [
@@ -809,7 +812,7 @@ class MockTracker {
809812
validateObject(files, 'options.files');
810813
}
811814

812-
VirtualFileSystem ??= require('internal/vfs/virtual_fs').VirtualFileSystem;
815+
const VirtualFileSystem = lazyVirtualFileSystem();
813816
const vfs = new VirtualFileSystem({ __proto__: null, moduleHooks: true });
814817

815818
// Add initial files if provided

lib/internal/vfs/sea.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
'use strict';
22

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

66
// Lazy-loaded VFS
77
let cachedSeaVfs = null;
88

99
// Lazy-load VirtualFileSystem and SEAProvider to avoid loading VFS code if not needed
10-
let VirtualFileSystem;
11-
let SEAProvider;
10+
const lazyVirtualFileSystem = getLazy(
11+
() => require('internal/vfs/file_system').VirtualFileSystem,
12+
);
13+
const lazySEAProvider = getLazy(
14+
() => require('internal/vfs/providers/sea').SEAProvider,
15+
);
1216

1317
/**
1418
* Creates a VirtualFileSystem populated with SEA assets using the new Provider architecture.
@@ -23,8 +27,8 @@ function createSeaVfs(options = kEmptyObject) {
2327
return null;
2428
}
2529

26-
VirtualFileSystem ??= require('internal/vfs/file_system').VirtualFileSystem;
27-
SEAProvider ??= require('internal/vfs/providers/sea').SEAProvider;
30+
const VirtualFileSystem = lazyVirtualFileSystem();
31+
const SEAProvider = lazySEAProvider();
2832

2933
const prefix = options.prefix ?? '/sea';
3034
const moduleHooks = options.moduleHooks !== false;

0 commit comments

Comments
 (0)