diff --git a/bin/c8.js b/bin/c8.js index 2a908458e..399c2aaee 100755 --- a/bin/c8.js +++ b/bin/c8.js @@ -3,7 +3,7 @@ const foreground = require('foreground-child') const { outputReport } = require('../lib/commands/report') -const mkdirp = require('mkdirp') +const { promises } = require('fs') const { promisify } = require('util') const rimraf = require('rimraf') const { @@ -25,7 +25,9 @@ async function run () { await promisify(rimraf)(argv.tempDirectory) } // allow c8 to run on Node 8 (coverage just won't work). - await promisify(mkdirp)(argv.tempDirectory) + if (promises) { + await promises.mkdir(argv.tempDirectory, { recursive: true }) + } process.env.NODE_V8_COVERAGE = argv.tempDirectory foreground(hideInstrumenterArgs(argv), async (done) => { diff --git a/package-lock.json b/package-lock.json index b0cb175b0..fac64c8c5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2505,6 +2505,7 @@ "version": "0.5.1", "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.1.tgz", "integrity": "sha1-MAV0OOrGz3+MR2fzhkjWaX11yQM=", + "dev": true, "requires": { "minimist": "0.0.8" } diff --git a/package.json b/package.json index 581edac66..e016a06f8 100644 --- a/package.json +++ b/package.json @@ -39,7 +39,6 @@ "istanbul-lib-coverage": "^2.0.1", "istanbul-lib-report": "^2.0.1", "istanbul-reports": "^2.0.0", - "mkdirp": "^0.5.1", "rimraf": "^2.6.2", "test-exclude": "^5.0.0", "v8-to-istanbul": "^3.1.1", diff --git a/test/fixtures/disable-fs-promises.js b/test/fixtures/disable-fs-promises.js new file mode 100644 index 000000000..0bbb0bd68 --- /dev/null +++ b/test/fixtures/disable-fs-promises.js @@ -0,0 +1,4 @@ +const fs = require('fs'); + +Object.defineProperty(fs, 'promises', {value: undefined}); +require('../../bin/c8.js'); diff --git a/test/legacy-node.js b/test/legacy-node.js new file mode 100644 index 000000000..08c649997 --- /dev/null +++ b/test/legacy-node.js @@ -0,0 +1,20 @@ +/* global describe, it */ + +const { execFile } = require('child_process') +const { mkdir } = require('fs').promises +const { join } = require('path') +const { promisify } = require('util') +const c8Path = require.resolve('./fixtures/disable-fs-promises') +const nodePath = process.execPath + +describe('c8 on Node.js < 10', () => { + it('doesn\'t crash', async () => { + await mkdir(join(__dirname, '..', 'tmp', 'legacy-nodejs')) + await promisify(execFile)(nodePath, [ + c8Path, + '--temp-directory=tmp/legacy-nodejs', + 'node', + '--version' + ]) + }) +})