Skip to content

Commit

Permalink
fs: lazy load the promises impl
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
jasnell authored and MylesBorins committed May 22, 2018
1 parent dc30d36 commit 2d28978
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions lib/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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');
}
Expand Down

0 comments on commit 2d28978

Please sign in to comment.