Skip to content

Commit 2d28978

Browse files
jasnellMylesBorins
authored andcommitted
fs: lazy load the promises impl
PR-URL: #20766 Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Minwoo Jung <minwoo@nodesource.com> Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
1 parent dc30d36 commit 2d28978

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

‎lib/fs.js‎

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

92-
letwarn=true;
91+
// Lazy loaded
92+
letpromises;
93+
94+
letpromisesWarn=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)