Skip to content

Commit de06115

Browse files
cjihrigtargos
authored andcommitted
fs: make fs.promises non-enumerable
This prevents the experimental feature warning from being emitted in cases where fs.promises is not actually used. PR-URL: #20632Fixes: #20504 Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Сковорода Никита Андреевич <chalkerx@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com>
1 parent e06c587 commit de06115

2 files changed

Lines changed: 7 additions & 2 deletions

File tree

‎lib/fs.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ let warn = true;
7777

7878
Object.defineProperty(fs,'promises',{
7979
configurable: true,
80-
enumerable: true,
80+
enumerable: false,
8181
get(){
8282
if(warn){
8383
warn=false;

‎test/parallel/test-fs-promises.js‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ const assert = require('assert');
55
consttmpdir=require('../common/tmpdir');
66
constfixtures=require('../common/fixtures');
77
constpath=require('path');
8-
constfsPromises=require('fs').promises;
8+
constfs=require('fs');
9+
constfsPromises=fs.promises;
910
const{
1011
access,
1112
chmod,
@@ -38,6 +39,10 @@ const tmpDir = tmpdir.path;
3839

3940
common.crashOnUnhandledRejection();
4041

42+
// fs.promises should not be enumerable as long as it causes a warning to be
43+
// emitted.
44+
assert.strictEqual(Object.keys(fs).includes('promises'),false);
45+
4146
{
4247
access(__filename,'r')
4348
.then(common.mustCall())

0 commit comments

Comments
 (0)