Skip to content

Commit

Permalink
[fix] node v10.0 lacks fs.promises
Browse files Browse the repository at this point in the history
In this node version, fall back to `util.promisify` of the callback version.

Maybe fixes #2623. Maybe fixes #2652. Maybe fixes #2625.
  • Loading branch information
ljharb committed Feb 8, 2021
1 parent 595080b commit dc2ca45
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Expand Up @@ -7,7 +7,7 @@ jobs:
strategy:
fail-fast: false
matrix:
node-version: [10.x, 12.x, 14.x]
node-version: ['10.0', 10.x, '12.0', 12.x, '14.0', 14.x]
platform:
- os: ubuntu-latest
shell: bash
Expand Down
4 changes: 3 additions & 1 deletion lib/utils/reify-finish.js
@@ -1,7 +1,9 @@
const reifyOutput = require('./reify-output.js')
const npm = require('../npm.js')
const ini = require('ini')
const {writeFile} = require('fs').promises
const util = require('util')
const fs = require('fs')
const { writeFile } = fs.promises || { writeFile: util.promisify(fs.writeFile) }
const {resolve} = require('path')

const reifyFinish = async arb => {
Expand Down
8 changes: 8 additions & 0 deletions test/lib/utils/reify-finish.js
Expand Up @@ -78,3 +78,11 @@ t.test('should write if everything above passes', async t => {
const data = fs.readFileSync(`${path}/npmrc`, 'utf8').replace(/\r\n/g, '\n')
t.matchSnapshot(data, 'written config')
})

t.test('works without fs.promises', async t => {
t.doesNotThrow(() => requireInject('../../../lib/utils/reify-finish.js', {
fs: { ...fs, promises: null },
'../../../lib/npm.js': npm,
'../../../lib/utils/reify-output.js': reifyOutput,
}))
})

0 comments on commit dc2ca45

Please sign in to comment.