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 npm/cli#2623. Maybe fixes npm/cli#2652. Maybe fixes npm/cli#2625.

PR-URL: #21
Credit: @ljharb
Close: #21
Reviewed-by: @ruyadorno
  • Loading branch information
ljharb authored and ruyadorno committed Feb 10, 2021
1 parent 2a59d9b commit 86c55af
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ jobs:
build:
strategy:
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/is-server-package.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
const { stat } = require('fs').promises
const util = require('util')
const fs = require('fs')
const { stat } = fs.promises || { stat: util.promisify(fs.stat) }
const { resolve } = require('path')
module.exports = async path => {
try {
Expand Down
5 changes: 5 additions & 0 deletions test/is-server-package.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const t = require('tap')
const requireInject = require('require-inject')
const isServerPackage = require('../lib/is-server-package.js')

t.test('returns true if server.js present', async t => {
Expand All @@ -19,3 +20,7 @@ t.test('returns false if server.js not a file', async t => {
})
t.equal(await isServerPackage(path), false)
})

t.test('works without fs.promises', async t => {
t.doesNotThrow(() => requireInject('../lib/is-server-package', { fs: { ...require('fs'), promises: null }}))
})

0 comments on commit 86c55af

Please sign in to comment.