From cdcc22574037df687dc170b1a177347cc5ce1fdf Mon Sep 17 00:00:00 2001 From: "Benjamin E. Coe" Date: Mon, 7 Oct 2019 10:48:28 -0700 Subject: [PATCH] fix: fs.promises was not introduced until 10 (#67) --- lib/v8-to-istanbul.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/v8-to-istanbul.js b/lib/v8-to-istanbul.js index 0182d71f..cc73355e 100644 --- a/lib/v8-to-istanbul.js +++ b/lib/v8-to-istanbul.js @@ -5,9 +5,14 @@ const { dirname, join } = require('path') const CovBranch = require('./branch') const CovFunction = require('./function') const CovSource = require('./source') -const { readFile } = require('fs').promises +const compatError = Error(`requires Node.js ${require('../package.json').engines.node}`) +let readFile = () => { throw compatError } +try { + readFile = require('fs').promises.readFile +} catch (_err) { + // most likely we're on an older version of Node.js. +} const { SourceMapConsumer } = require('source-map') - const isOlderNode10 = /^v10\.(([0-9]\.)|(1[0-5]\.))/u.test(process.version) // Injected when Node.js is loading script into isolate pre Node 10.16.x.