Skip to content

Commit 2d28978

Browse files
jasnellMylesBorins
authored andcommitted
fs: lazy load the promises impl
PR-URL: #20766 Reviewed-By: Joyee Cheung <[email protected]> Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Minwoo Jung <[email protected]> Reviewed-By: Tiancheng "Timothy" Gu <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]>
1 parent dc30d36 commit 2d28978

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

lib/fs.js

+7-4
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ const { Readable, Writable } = require('stream');
6060
const EventEmitter = require('events');
6161
const { FSReqWrap, statValues, kFsStatsFieldsLength } = binding;
6262
const { FSEvent } = process.binding('fs_event_wrap');
63-
const promises = require('internal/fs/promises');
6463
const internalFS = require('internal/fs/utils');
6564
const { getPathFromURL } = require('internal/url');
6665
const internalUtil = require('internal/util');
@@ -89,14 +88,18 @@ const {
8988
CHAR_BACKWARD_SLASH,
9089
} = require('internal/constants');
9190

92-
let warn = true;
91+
// Lazy loaded
92+
let promises;
93+
94+
let promisesWarn = true;
9395

9496
Object.defineProperty(fs, 'promises', {
9597
configurable: true,
9698
enumerable: false,
9799
get() {
98-
if (warn) {
99-
warn = false;
100+
if (promisesWarn) {
101+
promises = require('internal/fs/promises');
102+
promisesWarn = false;
100103
process.emitWarning('The fs.promises API is experimental',
101104
'ExperimentalWarning');
102105
}

0 commit comments

Comments
 (0)