Skip to content

Commit

Permalink
BREAKING: Remove special handling of fs.promises (#890)
Browse files Browse the repository at this point in the history
* Remove special handling of fs.promises

Refs #886

* Fix tests
  • Loading branch information
RyanZim committed Apr 30, 2021
1 parent d8c93b8 commit 05d2e93
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 26 deletions.
12 changes: 4 additions & 8 deletions lib/__tests__/promise.test.js
Expand Up @@ -3,7 +3,6 @@
/* eslint-env mocha */

const assert = require('assert')
const fs = require('fs')
const fse = require('..')

const methods = [
Expand All @@ -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')
})
})
11 changes: 2 additions & 9 deletions lib/fs/index.js
Expand Up @@ -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 => {
Expand Down
9 changes: 0 additions & 9 deletions lib/index.js
Expand Up @@ -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 }
})
}

0 comments on commit 05d2e93

Please sign in to comment.