From 2d2897855fa51d29cea2dbe7a3c0d3431cf6ebd9 Mon Sep 17 00:00:00 2001 From: James M Snell Date: Mon, 14 May 2018 16:25:27 -0700 Subject: [PATCH] fs: lazy load the promises impl MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PR-URL: https://github.com/nodejs/node/pull/20766 Reviewed-By: Joyee Cheung Reviewed-By: Michaƫl Zasso Reviewed-By: Minwoo Jung Reviewed-By: Tiancheng "Timothy" Gu Reviewed-By: Benjamin Gruenbaum Reviewed-By: Luigi Pinca Reviewed-By: Ruben Bridgewater --- lib/fs.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/fs.js b/lib/fs.js index 7d84b5bacafa94..fedd4dcdb54df2 100644 --- a/lib/fs.js +++ b/lib/fs.js @@ -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'); @@ -89,14 +88,18 @@ const { CHAR_BACKWARD_SLASH, } = require('internal/constants'); -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'); }