Skip to content

Commit a465b65

Browse files
shinnnbcoe
authored andcommitted
fix: remove the unmaintained mkdirp dependency (bcoe#91)
1 parent a27b694 commit a465b65

File tree

5 files changed

+36
-4
lines changed

5 files changed

+36
-4
lines changed

bin/c8.js

+9-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
const foreground = require('foreground-child')
55
const { outputReport } = require('../lib/commands/report')
6-
const mkdirp = require('mkdirp')
6+
const { promises } = require('fs')
77
const { promisify } = require('util')
88
const rimraf = require('rimraf')
99
const {
@@ -21,12 +21,18 @@ async function run () {
2121
].indexOf(argv._[0]) !== -1) {
2222
argv = buildYargs(true).parse(process.argv.slice(2))
2323
} else {
24+
// fs.promises was not added until Node.js v10.0.0, if it doesn't
25+
// exist, assume we're Node.js v8.x and skip coverage.
26+
if (!promises) {
27+
foreground(hideInstrumenterArgs(argv))
28+
return
29+
}
30+
2431
if (argv.clean) {
2532
await promisify(rimraf)(argv.tempDirectory)
2633
}
27-
// allow c8 to run on Node 8 (coverage just won't work).
28-
await promisify(mkdirp)(argv.tempDirectory)
2934

35+
await promises.mkdir(argv.tempDirectory, { recursive: true })
3036
process.env.NODE_V8_COVERAGE = argv.tempDirectory
3137
foreground(hideInstrumenterArgs(argv), async (done) => {
3238
try {

package-lock.json

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
"istanbul-lib-coverage": "^2.0.1",
4040
"istanbul-lib-report": "^2.0.1",
4141
"istanbul-reports": "^2.0.0",
42-
"mkdirp": "^0.5.1",
4342
"rimraf": "^2.6.2",
4443
"test-exclude": "^5.0.0",
4544
"v8-to-istanbul": "^3.1.1",

test/fixtures/disable-fs-promises.js

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
const fs = require('fs');
2+
3+
Object.defineProperty(fs, 'promises', {value: undefined});
4+
require('../../bin/c8.js');

test/legacy-node.js

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/* global describe, it */
2+
3+
const { execFile } = require('child_process')
4+
const { existsSync } = require('fs')
5+
const { join } = require('path')
6+
const { promisify } = require('util')
7+
const c8Path = require.resolve('./fixtures/disable-fs-promises')
8+
9+
describe('c8 on Node.js < 10', () => {
10+
it('skip coverage', async () => {
11+
const tmp = join(__dirname, '..', 'tmp', 'legacy-nodejs')
12+
13+
await promisify(execFile)(process.execPath, [
14+
c8Path,
15+
`--temp-directory=${__filename}`,
16+
process.execPath,
17+
'--version'
18+
])
19+
20+
existsSync(tmp).should.equal(false)
21+
})
22+
})

0 commit comments

Comments
 (0)