File tree Expand file tree Collapse file tree 3 files changed +24
-0
lines changed Expand file tree Collapse file tree 3 files changed +24
-0
lines changed Original file line number Diff line number Diff line change 2
2
3
3
/* eslint-env mocha */
4
4
5
+ const assert = require ( 'assert' )
6
+ const fs = require ( 'fs' )
5
7
const fse = require ( '..' )
6
8
7
9
const methods = [
@@ -22,4 +24,12 @@ describe('promise support', () => {
22
24
fse [ method ] ( ) . catch ( ( ) => done ( ) )
23
25
} )
24
26
} )
27
+
28
+ if ( Object . getOwnPropertyDescriptor ( fs , 'promises' ) ) {
29
+ it ( 'provides fse.promises API' , ( ) => {
30
+ const desc = Object . getOwnPropertyDescriptor ( fse , 'promises' )
31
+ assert . ok ( desc )
32
+ assert . equal ( typeof desc . get , 'function' )
33
+ } )
34
+ }
25
35
} )
Original file line number Diff line number Diff line change @@ -46,6 +46,11 @@ const api = [
46
46
47
47
// Export all keys:
48
48
Object . keys ( fs ) . forEach ( key => {
49
+ if ( key === 'promises' ) {
50
+ // fs.promises is a getter property that triggers ExperimentalWarning
51
+ // Don't re-export it here, the getter is defined in "lib/index.js"
52
+ return
53
+ }
49
54
exports [ key ] = fs [ key ]
50
55
} )
51
56
Original file line number Diff line number Diff line change @@ -17,3 +17,12 @@ module.exports = Object.assign(
17
17
require ( './path-exists' ) ,
18
18
require ( './remove' )
19
19
)
20
+
21
+ // Export fs.promises as a getter property so that we don't trigger
22
+ // ExperimentalWarning before fs.promises is actually accessed.
23
+ const fs = require ( 'fs' )
24
+ if ( Object . getOwnPropertyDescriptor ( fs , 'promises' ) ) {
25
+ Object . defineProperty ( module . exports , 'promises' , {
26
+ get ( ) { return fs . promises }
27
+ } )
28
+ }
You can’t perform that action at this time.
0 commit comments