Skip to content

Commit 5d9442a

Browse files
joyeecheungdanielleadams
authored andcommitted
lib: load internal/fs/watchers and internal/fs/read_file_context early
So that they are included in the builtin snapshot PR-URL: #38737 Refs: #35711 Reviewed-By: Anna Henningsen <[email protected]>
1 parent a1b0e64 commit 5d9442a

File tree

2 files changed

+4
-8
lines changed

2 files changed

+4
-8
lines changed

lib/fs.js

+3-8
Original file line numberDiff line numberDiff line change
@@ -138,13 +138,14 @@ const {
138138
validateInteger,
139139
} = require('internal/validators');
140140

141+
const watchers = require('internal/fs/watchers');
142+
const ReadFileContext = require('internal/fs/read_file_context');
143+
141144
let truncateWarn = true;
142145
let fs;
143146

144147
// Lazy loaded
145148
let promises = null;
146-
let watchers;
147-
let ReadFileContext;
148149
let ReadStream;
149150
let WriteStream;
150151
let rimraf;
@@ -369,8 +370,6 @@ function checkAborted(signal, callback) {
369370
function readFile(path, options, callback) {
370371
callback = maybeCallback(callback || options);
371372
options = getOptions(options, { flag: 'r' });
372-
if (!ReadFileContext)
373-
ReadFileContext = require('internal/fs/read_file_context');
374373
const context = new ReadFileContext(callback, options.encoding);
375374
context.isUserFd = isFd(path); // File descriptor ownership
376375

@@ -2234,8 +2233,6 @@ function watch(filename, options, listener) {
22342233
if (options.recursive === undefined) options.recursive = false;
22352234
if (options.recursive && !(isOSX || isWindows))
22362235
throw new ERR_FEATURE_UNAVAILABLE_ON_PLATFORM('watch recursively');
2237-
if (!watchers)
2238-
watchers = require('internal/fs/watchers');
22392236
const watcher = new watchers.FSWatcher();
22402237
watcher[watchers.kFSWatchStart](filename,
22412238
options.persistent,
@@ -2301,8 +2298,6 @@ function watchFile(filename, options, listener) {
23012298
stat = statWatchers.get(filename);
23022299

23032300
if (stat === undefined) {
2304-
if (!watchers)
2305-
watchers = require('internal/fs/watchers');
23062301
stat = new watchers.StatWatcher(options.bigint);
23072302
stat[watchers.kFSStatWatcherStart](filename,
23082303
options.persistent, options.interval);

test/parallel/test-bootstrap-modules.js

+1
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ const expectedModules = new Set([
5656
'NativeModule internal/fs/dir',
5757
'NativeModule internal/fs/utils',
5858
'NativeModule internal/fs/promises',
59+
'NativeModule internal/fs/read_file_context',
5960
'NativeModule internal/fs/rimraf',
6061
'NativeModule internal/fs/watchers',
6162
'NativeModule internal/heap_utils',

0 commit comments

Comments
 (0)