From 86c55afcf6e4ca78a4c50c75a307eddd3d85c5e9 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Mon, 8 Feb 2021 13:42:31 -0800 Subject: [PATCH] [fix] node v10.0 lacks `fs.promises` In this node version, fall back to `util.promisify` of the callback version. Maybe fixes https://github.com/npm/cli/issues/2623. Maybe fixes https://github.com/npm/cli/issues/2652. Maybe fixes https://github.com/npm/cli/issues/2625. PR-URL: https://github.com/npm/run-script/pull/21 Credit: @ljharb Close: #21 Reviewed-by: @ruyadorno --- .github/workflows/ci.yml | 2 +- lib/is-server-package.js | 4 +++- test/is-server-package.js | 5 +++++ 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8188345..c2f7372 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 diff --git a/lib/is-server-package.js b/lib/is-server-package.js index 667a3c4..d168623 100644 --- a/lib/is-server-package.js +++ b/lib/is-server-package.js @@ -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 { diff --git a/test/is-server-package.js b/test/is-server-package.js index 5203913..5f80a5b 100644 --- a/test/is-server-package.js +++ b/test/is-server-package.js @@ -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 => { @@ -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 }})) +})