From 5d9442a024622327fdb7b4c158bb10a6d3461931 Mon Sep 17 00:00:00 2001 From: Joyee Cheung Date: Thu, 20 May 2021 02:30:47 +0800 Subject: [PATCH] lib: load internal/fs/watchers and internal/fs/read_file_context early So that they are included in the builtin snapshot PR-URL: https://github.com/nodejs/node/pull/38737 Refs: https://github.com/nodejs/node/issues/35711 Reviewed-By: Anna Henningsen --- lib/fs.js | 11 +++-------- test/parallel/test-bootstrap-modules.js | 1 + 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/lib/fs.js b/lib/fs.js index 310397bbed39e1..46209a3f4d58c0 100644 --- a/lib/fs.js +++ b/lib/fs.js @@ -138,13 +138,14 @@ const { validateInteger, } = require('internal/validators'); +const watchers = require('internal/fs/watchers'); +const ReadFileContext = require('internal/fs/read_file_context'); + let truncateWarn = true; let fs; // Lazy loaded let promises = null; -let watchers; -let ReadFileContext; let ReadStream; let WriteStream; let rimraf; @@ -369,8 +370,6 @@ function checkAborted(signal, callback) { function readFile(path, options, callback) { callback = maybeCallback(callback || options); options = getOptions(options, { flag: 'r' }); - if (!ReadFileContext) - ReadFileContext = require('internal/fs/read_file_context'); const context = new ReadFileContext(callback, options.encoding); context.isUserFd = isFd(path); // File descriptor ownership @@ -2234,8 +2233,6 @@ function watch(filename, options, listener) { if (options.recursive === undefined) options.recursive = false; if (options.recursive && !(isOSX || isWindows)) throw new ERR_FEATURE_UNAVAILABLE_ON_PLATFORM('watch recursively'); - if (!watchers) - watchers = require('internal/fs/watchers'); const watcher = new watchers.FSWatcher(); watcher[watchers.kFSWatchStart](filename, options.persistent, @@ -2301,8 +2298,6 @@ function watchFile(filename, options, listener) { stat = statWatchers.get(filename); if (stat === undefined) { - if (!watchers) - watchers = require('internal/fs/watchers'); stat = new watchers.StatWatcher(options.bigint); stat[watchers.kFSStatWatcherStart](filename, options.persistent, options.interval); diff --git a/test/parallel/test-bootstrap-modules.js b/test/parallel/test-bootstrap-modules.js index 32ccba5653c3b8..89bed5f55fcc7f 100644 --- a/test/parallel/test-bootstrap-modules.js +++ b/test/parallel/test-bootstrap-modules.js @@ -56,6 +56,7 @@ const expectedModules = new Set([ 'NativeModule internal/fs/dir', 'NativeModule internal/fs/utils', 'NativeModule internal/fs/promises', + 'NativeModule internal/fs/read_file_context', 'NativeModule internal/fs/rimraf', 'NativeModule internal/fs/watchers', 'NativeModule internal/heap_utils',