Skip to content

Commit 7307626

Browse files
authored
chore: Remove cp-file module (#1230)
This slightly reduces the amount of code nyc loads by using the core fs.copyFile function. Clarify `package.json#engines` to show that node.js 8.9.0 (LTS) is the oldest supported release.
1 parent dfd629d commit 7307626

File tree

4 files changed

+20
-44
lines changed

4 files changed

+20
-44
lines changed

index.js

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
/* global __coverage__ */
44

55
const cachingTransform = require('caching-transform')
6-
const cpFile = require('cp-file')
76
const findCacheDir = require('find-cache-dir')
87
const fs = require('./lib/fs-promises')
98
const os = require('os')
@@ -225,13 +224,23 @@ class NYC {
225224

226225
const concurrency = output ? os.cpus().length : 1
227226
if (this.config.completeCopy && output) {
227+
const files = await glob(path.resolve(input, '**'), {
228+
dot: true,
229+
nodir: true,
230+
ignore: ['**/.git', '**/.git/**', path.join(output, '**')]
231+
})
232+
const destDirs = new Set(
233+
files.map(src => path.dirname(path.join(output, path.relative(input, src))))
234+
)
235+
236+
await pMap(
237+
destDirs,
238+
dir => mkdirp(dir),
239+
{ concurrency }
240+
)
228241
await pMap(
229-
await glob(path.resolve(input, '**'), {
230-
dot: true,
231-
nodir: true,
232-
ignore: ['**/.git', '**/.git/**', path.join(output, '**')]
233-
}),
234-
src => cpFile(src, path.join(output, path.relative(input, src))),
242+
files,
243+
src => fs.copyFile(src, path.join(output, path.relative(input, src))),
235244
{ concurrency }
236245
)
237246
}

package-lock.json

Lines changed: 2 additions & 33 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@
5959
"@istanbuljs/schema": "^0.1.1",
6060
"caching-transform": "^4.0.0",
6161
"convert-source-map": "^1.7.0",
62-
"cp-file": "^7.0.0",
6362
"decamelize": "^1.2.0",
6463
"find-cache-dir": "=3.0.0",
6564
"find-up": "^4.1.0",
@@ -96,7 +95,7 @@
9695
"which": "^2.0.1"
9796
},
9897
"engines": {
99-
"node": ">=8"
98+
"node": ">=8.9"
10099
},
101100
"homepage": "https://istanbul.js.org/",
102101
"repository": {

test/instrument.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ const { promisify } = require('util')
66

77
const t = require('tap')
88
const makeDir = require('make-dir')
9-
const cpFile = require('cp-file')
109
const isWindows = require('is-windows')()
1110
const rimraf = promisify(require('rimraf'))
1211

@@ -243,7 +242,7 @@ t.test('can write files in place with --in-place switch', async t => {
243242
const sourceDir = path.resolve(fixturesCLI, 'instrument-inplace')
244243
await makeDir(outputDir)
245244
await Promise.all(['package.json', 'file1.js', 'file2.js'].map(
246-
file => cpFile(path.join(sourceDir, file), path.join(outputDir, file))
245+
file => fs.copyFile(path.join(sourceDir, file), path.join(outputDir, file))
247246
))
248247

249248
const { status } = await runNYC({

0 commit comments

Comments
 (0)