c8 7.6.0 → 7.7.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +28 -0
- package/index.d.ts +4 -3
- package/lib/commands/report.js +1 -0
- package/lib/parse-args.js +6 -0
- package/lib/report.js +34 -10
- package/package.json +4 -5
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,34 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
|
4
4
|
|
|
5
|
+
### [7.7.3](https://www.github.com/bcoe/c8/compare/v7.7.2...v7.7.3) (2021-06-03)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
* **deps:** v8-to-istanbul with fix for Windows paths ([#311](https://www.github.com/bcoe/c8/issues/311)) ([ef1b875](https://www.github.com/bcoe/c8/commit/ef1b8757f5f9c664cf63cfce753e93b92057cab5))
|
|
11
|
+
|
|
12
|
+
### [7.7.2](https://www.github.com/bcoe/c8/compare/v7.7.1...v7.7.2) (2021-05-02)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
### Bug Fixes
|
|
16
|
+
|
|
17
|
+
* address bugs with source remapping on Windows ([#301](https://www.github.com/bcoe/c8/issues/301)) ([c817902](https://www.github.com/bcoe/c8/commit/c81790262f843c01b3d14390fde81dbdbcf2226f))
|
|
18
|
+
|
|
19
|
+
### [7.7.1](https://www.github.com/bcoe/c8/compare/v7.7.0...v7.7.1) (2021-04-07)
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
### Bug Fixes
|
|
23
|
+
|
|
24
|
+
* **types:** add excludeAfterRemap and allowExternal ([#297](https://www.github.com/bcoe/c8/issues/297)) ([e32a53f](https://www.github.com/bcoe/c8/commit/e32a53ff050b5faf740da4e9c3fb08e70e29d60d))
|
|
25
|
+
|
|
26
|
+
## [7.7.0](https://www.github.com/bcoe/c8/compare/v7.6.0...v7.7.0) (2021-03-30)
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
### Features
|
|
30
|
+
|
|
31
|
+
* introduce --exclude-after-remap flag ([#293](https://www.github.com/bcoe/c8/issues/293)) ([53c4234](https://www.github.com/bcoe/c8/commit/53c42347e0ed4eb29e37b84d40768eed89bf9eb0)), closes [#224](https://www.github.com/bcoe/c8/issues/224)
|
|
32
|
+
|
|
5
33
|
## [7.6.0](https://www.github.com/bcoe/c8/compare/v7.5.0...v7.6.0) (2021-02-17)
|
|
6
34
|
|
|
7
35
|
|
package/index.d.ts
CHANGED
|
@@ -2,8 +2,9 @@ export type Watermark = [number, number];
|
|
|
2
2
|
|
|
3
3
|
export declare class Report {
|
|
4
4
|
constructor(opts: {
|
|
5
|
-
exclude?:
|
|
6
|
-
|
|
5
|
+
exclude?: string | string[],
|
|
6
|
+
excludeAfterRemap?: boolean,
|
|
7
|
+
include?: string | string[],
|
|
7
8
|
reporter: string[],
|
|
8
9
|
reportsDirectory?: string,
|
|
9
10
|
tempDirectory?: string,
|
|
@@ -18,7 +19,7 @@ export declare class Report {
|
|
|
18
19
|
resolve?: string,
|
|
19
20
|
all?: boolean,
|
|
20
21
|
src?: Array<string>,
|
|
21
|
-
allowExternal
|
|
22
|
+
allowExternal?: boolean
|
|
22
23
|
})
|
|
23
24
|
run(): Promise<void>;
|
|
24
25
|
}
|
package/lib/commands/report.js
CHANGED
|
@@ -13,6 +13,7 @@ exports.outputReport = async function (argv) {
|
|
|
13
13
|
const report = Report({
|
|
14
14
|
include: argv.include,
|
|
15
15
|
exclude: argv.exclude,
|
|
16
|
+
excludeAfterRemap: argv.excludeAfterRemap,
|
|
16
17
|
reporter: Array.isArray(argv.reporter) ? argv.reporter : [argv.reporter],
|
|
17
18
|
reportsDirectory: argv['reports-dir'],
|
|
18
19
|
tempDirectory: argv.tempDirectory,
|
package/lib/parse-args.js
CHANGED
|
@@ -26,6 +26,12 @@ function buildYargs (withCommands = false) {
|
|
|
26
26
|
default: defaultExclude,
|
|
27
27
|
describe: 'a list of specific files and directories that should be excluded from coverage (glob patterns are supported)'
|
|
28
28
|
})
|
|
29
|
+
.option('exclude-after-remap', {
|
|
30
|
+
alias: 'a',
|
|
31
|
+
type: 'boolean',
|
|
32
|
+
default: false,
|
|
33
|
+
describe: 'apply exclude logic to files after they are remapped by a source-map'
|
|
34
|
+
})
|
|
29
35
|
.option('include', {
|
|
30
36
|
alias: 'n',
|
|
31
37
|
default: [],
|
package/lib/report.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
const Exclude = require('test-exclude')
|
|
2
|
-
const furi = require('furi')
|
|
3
2
|
const libCoverage = require('istanbul-lib-coverage')
|
|
4
3
|
const libReport = require('istanbul-lib-report')
|
|
5
4
|
const reports = require('istanbul-reports')
|
|
6
5
|
const { readdirSync, readFileSync, statSync } = require('fs')
|
|
7
6
|
const { isAbsolute, resolve, extname } = require('path')
|
|
7
|
+
const { pathToFileURL, fileURLToPath } = require('url')
|
|
8
8
|
const getSourceMapFromFile = require('./source-map-from-file')
|
|
9
9
|
// TODO: switch back to @c88/v8-coverage once patch is landed.
|
|
10
10
|
const v8toIstanbul = require('v8-to-istanbul')
|
|
@@ -15,6 +15,7 @@ const debuglog = util.debuglog('c8')
|
|
|
15
15
|
class Report {
|
|
16
16
|
constructor ({
|
|
17
17
|
exclude,
|
|
18
|
+
excludeAfterRemap,
|
|
18
19
|
include,
|
|
19
20
|
reporter,
|
|
20
21
|
reportsDirectory,
|
|
@@ -38,6 +39,7 @@ class Report {
|
|
|
38
39
|
include: include,
|
|
39
40
|
relativePath: !allowExternal
|
|
40
41
|
})
|
|
42
|
+
this.excludeAfterRemap = excludeAfterRemap
|
|
41
43
|
this.omitRelative = omitRelative
|
|
42
44
|
this.sourceMapCache = {}
|
|
43
45
|
this.wrapperLength = wrapperLength
|
|
@@ -88,7 +90,11 @@ class Report {
|
|
|
88
90
|
try {
|
|
89
91
|
const sources = this._getSourceMap(v8ScriptCov)
|
|
90
92
|
const path = resolve(this.resolve, v8ScriptCov.url)
|
|
91
|
-
const converter = v8toIstanbul(path, this.wrapperLength, sources)
|
|
93
|
+
const converter = v8toIstanbul(path, this.wrapperLength, sources, (path) => {
|
|
94
|
+
if (this.excludeAfterRemap) {
|
|
95
|
+
return !this.exclude.shouldInstrument(path)
|
|
96
|
+
}
|
|
97
|
+
})
|
|
92
98
|
await converter.load()
|
|
93
99
|
|
|
94
100
|
if (resultCountPerPath.has(path)) {
|
|
@@ -133,8 +139,8 @@ class Report {
|
|
|
133
139
|
*/
|
|
134
140
|
_getSourceMap (v8ScriptCov) {
|
|
135
141
|
const sources = {}
|
|
136
|
-
|
|
137
|
-
|
|
142
|
+
const sourceMapAndLineLengths = this.sourceMapCache[pathToFileURL(v8ScriptCov.url).href]
|
|
143
|
+
if (sourceMapAndLineLengths) {
|
|
138
144
|
// See: https://github.com/nodejs/node/pull/34305
|
|
139
145
|
if (!sourceMapAndLineLengths.data) return
|
|
140
146
|
sources.sourceMap = {
|
|
@@ -167,7 +173,7 @@ class Report {
|
|
|
167
173
|
for (const v8ProcessCov of this._loadReports()) {
|
|
168
174
|
if (this._isCoverageObject(v8ProcessCov)) {
|
|
169
175
|
if (v8ProcessCov['source-map-cache']) {
|
|
170
|
-
Object.assign(this.sourceMapCache, v8ProcessCov['source-map-cache'])
|
|
176
|
+
Object.assign(this.sourceMapCache, this._normalizeSourceMapCache(v8ProcessCov['source-map-cache']))
|
|
171
177
|
}
|
|
172
178
|
v8ProcessCovs.push(this._normalizeProcessCov(v8ProcessCov, fileIndex))
|
|
173
179
|
}
|
|
@@ -188,7 +194,7 @@ class Report {
|
|
|
188
194
|
const stat = statSync(fullPath)
|
|
189
195
|
const sourceMap = getSourceMapFromFile(fullPath)
|
|
190
196
|
if (sourceMap) {
|
|
191
|
-
this.sourceMapCache[
|
|
197
|
+
this.sourceMapCache[pathToFileURL(fullPath)] = { data: sourceMap }
|
|
192
198
|
}
|
|
193
199
|
emptyReports.push({
|
|
194
200
|
scriptId: 0,
|
|
@@ -269,20 +275,38 @@ class Report {
|
|
|
269
275
|
}
|
|
270
276
|
if (/^file:\/\//.test(v8ScriptCov.url)) {
|
|
271
277
|
try {
|
|
272
|
-
v8ScriptCov.url =
|
|
278
|
+
v8ScriptCov.url = fileURLToPath(v8ScriptCov.url)
|
|
273
279
|
fileIndex.add(v8ScriptCov.url)
|
|
274
280
|
} catch (err) {
|
|
275
281
|
debuglog(`${err.stack}`)
|
|
276
282
|
continue
|
|
277
283
|
}
|
|
278
284
|
}
|
|
279
|
-
if (this.
|
|
280
|
-
(
|
|
281
|
-
|
|
285
|
+
if ((!this.omitRelative || isAbsolute(v8ScriptCov.url))) {
|
|
286
|
+
if (this.excludeAfterRemap || this.exclude.shouldInstrument(v8ScriptCov.url)) {
|
|
287
|
+
result.push(v8ScriptCov)
|
|
288
|
+
}
|
|
282
289
|
}
|
|
283
290
|
}
|
|
284
291
|
return { result }
|
|
285
292
|
}
|
|
293
|
+
|
|
294
|
+
/**
|
|
295
|
+
* Normalizes a V8 source map cache.
|
|
296
|
+
*
|
|
297
|
+
* This function normalizes file URLs to a system-independent format.
|
|
298
|
+
*
|
|
299
|
+
* @param v8SourceMapCache V8 source map cache to normalize.
|
|
300
|
+
* @return {v8SourceMapCache} Normalized V8 source map cache.
|
|
301
|
+
* @private
|
|
302
|
+
*/
|
|
303
|
+
_normalizeSourceMapCache (v8SourceMapCache) {
|
|
304
|
+
const cache = {}
|
|
305
|
+
for (const fileURL of Object.keys(v8SourceMapCache)) {
|
|
306
|
+
cache[pathToFileURL(fileURLToPath(fileURL)).href] = v8SourceMapCache[fileURL]
|
|
307
|
+
}
|
|
308
|
+
return cache
|
|
309
|
+
}
|
|
286
310
|
}
|
|
287
311
|
|
|
288
312
|
module.exports = function (opts) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "c8",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.7.3",
|
|
4
4
|
"description": "output coverage reports using Node.js' built in coverage",
|
|
5
5
|
"main": "./index.js",
|
|
6
6
|
"types": "./index.d.ts",
|
|
@@ -37,15 +37,14 @@
|
|
|
37
37
|
"@istanbuljs/schema": "^0.1.2",
|
|
38
38
|
"find-up": "^5.0.0",
|
|
39
39
|
"foreground-child": "^2.0.0",
|
|
40
|
-
"furi": "^2.0.0",
|
|
41
40
|
"istanbul-lib-coverage": "^3.0.0",
|
|
42
41
|
"istanbul-lib-report": "^3.0.0",
|
|
43
42
|
"istanbul-reports": "^3.0.2",
|
|
44
43
|
"rimraf": "^3.0.0",
|
|
45
44
|
"test-exclude": "^6.0.0",
|
|
46
|
-
"v8-to-istanbul": "^
|
|
47
|
-
"yargs": "^16.
|
|
48
|
-
"yargs-parser": "^20.
|
|
45
|
+
"v8-to-istanbul": "^8.0.0",
|
|
46
|
+
"yargs": "^16.2.0",
|
|
47
|
+
"yargs-parser": "^20.2.7"
|
|
49
48
|
},
|
|
50
49
|
"devDependencies": {
|
|
51
50
|
"chai": "^4.2.0",
|