Skip to content

Commit

Permalink
fs: make fs.promises non-enumerable
Browse files Browse the repository at this point in the history
This prevents the experimental feature warning from being emitted
in cases where fs.promises is not actually used.

PR-URL: #20632
Fixes: #20504
Reviewed-By: Michaël Zasso <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Сковорода Никита Андреевич <[email protected]>
Reviewed-By: Joyee Cheung <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Gus Caplan <[email protected]>
Reviewed-By: Tiancheng "Timothy" Gu <[email protected]>
Reviewed-By: Rich Trott <[email protected]>
Reviewed-By: Daniel Bevenius <[email protected]>
  • Loading branch information
cjihrig authored and targos committed May 12, 2018
1 parent e06c587 commit de06115
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ let warn = true;

Object.defineProperty(fs, 'promises', {
configurable: true,
enumerable: true,
enumerable: false,
get() {
if (warn) {
warn = false;
Expand Down
7 changes: 6 additions & 1 deletion test/parallel/test-fs-promises.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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())
Expand Down

0 comments on commit de06115

Please sign in to comment.