From de06115d18720755498fd871bccca837df024acb Mon Sep 17 00:00:00 2001 From: cjihrig Date: Wed, 9 May 2018 12:36:59 -0400 Subject: [PATCH] fs: make fs.promises non-enumerable MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This prevents the experimental feature warning from being emitted in cases where fs.promises is not actually used. PR-URL: https://github.com/nodejs/node/pull/20632 Fixes: https://github.com/nodejs/node/issues/20504 Reviewed-By: Michaël Zasso Reviewed-By: James M Snell Reviewed-By: Сковорода Никита Андреевич Reviewed-By: Joyee Cheung Reviewed-By: Luigi Pinca Reviewed-By: Gus Caplan Reviewed-By: Tiancheng "Timothy" Gu Reviewed-By: Rich Trott Reviewed-By: Daniel Bevenius --- lib/fs.js | 2 +- test/parallel/test-fs-promises.js | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/fs.js b/lib/fs.js index e9d878803ddffd..ed2a241e568cf5 100644 --- a/lib/fs.js +++ b/lib/fs.js @@ -77,7 +77,7 @@ let warn = true; Object.defineProperty(fs, 'promises', { configurable: true, - enumerable: true, + enumerable: false, get() { if (warn) { warn = false; diff --git a/test/parallel/test-fs-promises.js b/test/parallel/test-fs-promises.js index 43b5da700484ff..8f1d646bb0e01e 100644 --- a/test/parallel/test-fs-promises.js +++ b/test/parallel/test-fs-promises.js @@ -5,7 +5,8 @@ const assert = require('assert'); const tmpdir = require('../common/tmpdir'); const fixtures = require('../common/fixtures'); const path = require('path'); -const fsPromises = require('fs').promises; +const fs = require('fs'); +const fsPromises = fs.promises; const { access, chmod, @@ -38,6 +39,10 @@ const tmpDir = tmpdir.path; common.crashOnUnhandledRejection(); +// fs.promises should not be enumerable as long as it causes a warning to be +// emitted. +assert.strictEqual(Object.keys(fs).includes('promises'), false); + { access(__filename, 'r') .then(common.mustCall())