Skip to content

Commit

Permalink
fix: remove the unmaintained mkdirp dependency
Browse files Browse the repository at this point in the history
using fs.promises feature detection
  • Loading branch information
shinnn committed May 3, 2019
1 parent 6b93355 commit 491aebb
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 3 deletions.
6 changes: 4 additions & 2 deletions bin/c8.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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) => {
Expand Down
1 change: 1 addition & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 4 additions & 0 deletions test/fixtures/disable-fs-promises.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
const fs = require('fs');

Object.defineProperty(fs, 'promises', {value: undefined});
require('../../bin/c8.js');
20 changes: 20 additions & 0 deletions test/legacy-node.js
Original file line number Diff line number Diff line change
@@ -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'
])
})
})

0 comments on commit 491aebb

Please sign in to comment.