Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: remove the unmaintained mkdirp dependency #91

Merged
merged 3 commits into from
May 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe just pull in semver a dependency and:

if (semver.lt('10.12.0', process.version)) {
  console.warn('native test coverage was not added to V8 until 10.12.0')
  foreground(hideInstrumenterArgs(argv))
  return
}

that way we're not relying on util.promisify not being back-ported.

👍 thanks for your work on this; I'll be back a bit later today.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that way we're not relying on util.promisify not being back-ported.

To be accurate, the API used for feature detection here is not util.promisify but fs.promises.

I can hardly imagine the Node.js team decides to back-port fs.promises to the maintenance LTS version.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perhaps just add a comment then:

// fs.promises was not added until Node v10.0.0, if it doesn't
// exist, assume we're Node v8.x and skip coverage.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)
})
})