Skip to content

Commit

Permalink
fix: remove the unmaintained mkdirp dependency (bcoe#91)
Browse files Browse the repository at this point in the history
  • Loading branch information
shinnn authored and bcoe committed May 5, 2019
1 parent 9d319cd commit c48348f
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 4 deletions.
12 changes: 9 additions & 3 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 @@ -21,12 +21,18 @@ async function run () {
].indexOf(argv._[0]) !== -1) {
argv = buildYargs(true).parse(process.argv.slice(2))
} else {
// fs.promises was not added until Node.js v10.0.0, if it doesn't
// exist, assume we're Node.js v8.x and skip coverage.
if (!promises) {
foreground(hideInstrumenterArgs(argv))
return
}

if (argv.clean) {
await promisify(rimraf)(argv.tempDirectory)
}
// allow c8 to run on Node 8 (coverage just won't work).
await promisify(mkdirp)(argv.tempDirectory)

await promises.mkdir(argv.tempDirectory, { recursive: true })
process.env.NODE_V8_COVERAGE = argv.tempDirectory
foreground(hideInstrumenterArgs(argv), async (done) => {
try {
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');
22 changes: 22 additions & 0 deletions test/legacy-node.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/* global describe, it */

const { execFile } = require('child_process')
const { existsSync } = require('fs')
const { join } = require('path')
const { promisify } = require('util')
const c8Path = require.resolve('./fixtures/disable-fs-promises')

describe('c8 on Node.js < 10', () => {
it('skip coverage', async () => {
const tmp = join(__dirname, '..', 'tmp', 'legacy-nodejs')

await promisify(execFile)(process.execPath, [
c8Path,
`--temp-directory=${__filename}`,
process.execPath,
'--version'
])

existsSync(tmp).should.equal(false)
})
})

0 comments on commit c48348f

Please sign in to comment.