fs: lazy load the promises impl

PR-URL: https://github.com/nodejs/node/pull/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>
This commit is contained in:
James M Snell 2018-05-14 16:25:27 -07:00
parent 1d3759a33c
commit 11aea015ef

View File

@ -60,7 +60,6 @@ const { Readable, Writable } = require('stream');
const EventEmitter = require('events');
const { FSReqWrap, statValues, kFsStatsFieldsLength } = binding;
const { FSEvent } = process.binding('fs_event_wrap');
const promises = require('internal/fs/promises');
const internalFS = require('internal/fs/utils');
const { getPathFromURL } = require('internal/url');
const internalUtil = require('internal/util');
@ -91,14 +90,18 @@ const {
validateUint32
} = require('internal/validators');
let warn = true;
// Lazy loaded
let promises;
let promisesWarn = true;
Object.defineProperty(fs, 'promises', {
configurable: true,
enumerable: false,
get() {
if (warn) {
warn = false;
if (promisesWarn) {
promises = require('internal/fs/promises');
promisesWarn = false;
process.emitWarning('The fs.promises API is experimental',
'ExperimentalWarning');
}