Skip to content

Commit

Permalink
lib: load internal/fs/watchers and internal/fs/read_file_context early
Browse files Browse the repository at this point in the history
So that they are included in the builtin snapshot

PR-URL: #38737
Refs: #35711
Reviewed-By: Anna Henningsen <anna@addaleax.net>
  • Loading branch information
joyeecheung committed May 27, 2021
1 parent 39b0f4f commit 9e42b4d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 8 deletions.
11 changes: 3 additions & 8 deletions lib/fs.js
Expand Up @@ -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;
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions test/parallel/test-bootstrap-modules.js
Expand Up @@ -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',
Expand Down

0 comments on commit 9e42b4d

Please sign in to comment.