From 5d756db5c89f983653a9adf7743991a57e72faed Mon Sep 17 00:00:00 2001 From: Ryan Zimmerman Date: Thu, 22 Apr 2021 16:22:56 -0400 Subject: [PATCH 1/2] Remove special handling of fs.promises Refs #886 --- lib/fs/index.js | 11 ++--------- lib/index.js | 9 --------- 2 files changed, 2 insertions(+), 18 deletions(-) diff --git a/lib/fs/index.js b/lib/fs/index.js index 93fe6a035..e460b747c 100644 --- a/lib/fs/index.js +++ b/lib/fs/index.js @@ -47,15 +47,8 @@ const api = [ return typeof fs[key] === 'function' }) -// Export all keys: -Object.keys(fs).forEach(key => { - if (key === 'promises') { - // fs.promises is a getter property that triggers ExperimentalWarning - // Don't re-export it here, the getter is defined in "lib/index.js" - return - } - exports[key] = fs[key] -}) +// Export cloned fs: +Object.assign(exports, fs) // Universalify async methods: api.forEach(method => { diff --git a/lib/index.js b/lib/index.js index d9468e699..cbc2aaec3 100644 --- a/lib/index.js +++ b/lib/index.js @@ -16,12 +16,3 @@ module.exports = { ...require('./path-exists'), ...require('./remove') } - -// Export fs.promises as a getter property so that we don't trigger -// ExperimentalWarning before fs.promises is actually accessed. -const fs = require('fs') -if (Object.getOwnPropertyDescriptor(fs, 'promises')) { - Object.defineProperty(module.exports, 'promises', { - get () { return fs.promises } - }) -} From f7d3942c246a670d5a56b8ebdb0c7d4167952f57 Mon Sep 17 00:00:00 2001 From: Ryan Zimmerman Date: Thu, 22 Apr 2021 16:28:23 -0400 Subject: [PATCH 2/2] Fix tests --- lib/__tests__/promise.test.js | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/lib/__tests__/promise.test.js b/lib/__tests__/promise.test.js index 09417fde4..31228bdf4 100644 --- a/lib/__tests__/promise.test.js +++ b/lib/__tests__/promise.test.js @@ -3,7 +3,6 @@ /* eslint-env mocha */ const assert = require('assert') -const fs = require('fs') const fse = require('..') const methods = [ @@ -24,11 +23,8 @@ describe('promise support', () => { }) }) - if (Object.getOwnPropertyDescriptor(fs, 'promises')) { - it('provides fse.promises API', () => { - const desc = Object.getOwnPropertyDescriptor(fse, 'promises') - assert.ok(desc) - assert.strictEqual(typeof desc.get, 'function') - }) - } + it('provides fse.promises API', () => { + assert.ok(fse.promises) + assert.strictEqual(typeof fse.promises.writeFile, 'function') + }) })