Skip to content

Commit

Permalink
Fix fs.promises ExperimentalWarning on Node 10.1.0 (#578)
Browse files Browse the repository at this point in the history
  • Loading branch information
bajtos authored and RyanZim committed May 9, 2018
1 parent 7d36349 commit 2ffb64c
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
10 changes: 10 additions & 0 deletions lib/__tests__/promise.test.js
Expand Up @@ -2,6 +2,8 @@

/* eslint-env mocha */

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

const methods = [
Expand All @@ -22,4 +24,12 @@ describe('promise support', () => {
fse[method]().catch(() => done())
})
})

if (Object.getOwnPropertyDescriptor(fs, 'promises')) {
it('provides fse.promises API', () => {
const desc = Object.getOwnPropertyDescriptor(fse, 'promises')
assert.ok(desc)
assert.equal(typeof desc.get, 'function')
})
}
})
5 changes: 5 additions & 0 deletions lib/fs/index.js
Expand Up @@ -46,6 +46,11 @@ const api = [

// 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]
})

Expand Down
9 changes: 9 additions & 0 deletions lib/index.js
Expand Up @@ -17,3 +17,12 @@ module.exports = Object.assign(
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 2ffb64c

Please sign in to comment.