Skip to content

Commit 05d2e93

Browse files
authored
BREAKING: Remove special handling of fs.promises (#890)
* Remove special handling of fs.promises Refs #886 * Fix tests
1 parent d8c93b8 commit 05d2e93

File tree

3 files changed

+6
-26
lines changed

3 files changed

+6
-26
lines changed

lib/__tests__/promise.test.js

+4-8
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
/* eslint-env mocha */
44

55
const assert = require('assert')
6-
const fs = require('fs')
76
const fse = require('..')
87

98
const methods = [
@@ -24,11 +23,8 @@ describe('promise support', () => {
2423
})
2524
})
2625

27-
if (Object.getOwnPropertyDescriptor(fs, 'promises')) {
28-
it('provides fse.promises API', () => {
29-
const desc = Object.getOwnPropertyDescriptor(fse, 'promises')
30-
assert.ok(desc)
31-
assert.strictEqual(typeof desc.get, 'function')
32-
})
33-
}
26+
it('provides fse.promises API', () => {
27+
assert.ok(fse.promises)
28+
assert.strictEqual(typeof fse.promises.writeFile, 'function')
29+
})
3430
})

lib/fs/index.js

+2-9
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,8 @@ const api = [
4747
return typeof fs[key] === 'function'
4848
})
4949

50-
// Export all keys:
51-
Object.keys(fs).forEach(key => {
52-
if (key === 'promises') {
53-
// fs.promises is a getter property that triggers ExperimentalWarning
54-
// Don't re-export it here, the getter is defined in "lib/index.js"
55-
return
56-
}
57-
exports[key] = fs[key]
58-
})
50+
// Export cloned fs:
51+
Object.assign(exports, fs)
5952

6053
// Universalify async methods:
6154
api.forEach(method => {

lib/index.js

-9
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,3 @@ module.exports = {
1616
...require('./path-exists'),
1717
...require('./remove')
1818
}
19-
20-
// Export fs.promises as a getter property so that we don't trigger
21-
// ExperimentalWarning before fs.promises is actually accessed.
22-
const fs = require('fs')
23-
if (Object.getOwnPropertyDescriptor(fs, 'promises')) {
24-
Object.defineProperty(module.exports, 'promises', {
25-
get () { return fs.promises }
26-
})
27-
}

0 commit comments

Comments
 (0)