c8 7.3.4 → 7.5.0
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 +22 -0
- package/README.md +12 -2
- package/lib/parse-args.js +1 -1
- package/lib/report.js +15 -13
- package/lib/source-map-from-file.js +85 -10
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,28 @@
|
|
|
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.5.0](https://www.github.com/bcoe/c8/compare/v7.4.0...v7.5.0) (2021-02-01)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Features
|
|
9
|
+
|
|
10
|
+
* **all:** handle base64 inline source maps ([#283](https://www.github.com/bcoe/c8/issues/283)) ([3f12dd4](https://www.github.com/bcoe/c8/commit/3f12dd4cd4b903b396c60c9c6d76cdf990ec6cbe))
|
|
11
|
+
|
|
12
|
+
## [7.4.0](https://www.github.com/bcoe/c8/compare/v7.3.5...v7.4.0) (2020-12-31)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
### Features
|
|
16
|
+
|
|
17
|
+
* support ignore start/stop comment ([#273](https://www.github.com/bcoe/c8/issues/273)) ([90949fa](https://www.github.com/bcoe/c8/commit/90949fa2deac7fccb9fc4b83ecca70f4de025ae9)), closes [#271](https://www.github.com/bcoe/c8/issues/271)
|
|
18
|
+
* use debuglog rather than console.warn ([#279](https://www.github.com/bcoe/c8/issues/279)) ([7c04a4d](https://www.github.com/bcoe/c8/commit/7c04a4dc47ee9496d89fcae9062da24a6f642f39))
|
|
19
|
+
|
|
20
|
+
### [7.3.5](https://www.github.com/bcoe/c8/compare/v7.3.4...v7.3.5) (2020-10-25)
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
### Bug Fixes
|
|
24
|
+
|
|
25
|
+
* **v8-to-istanbul:** fixes shebang handling/ignore behavior ([#267](https://www.github.com/bcoe/c8/issues/267)) ([21cd41f](https://www.github.com/bcoe/c8/commit/21cd41f5ed2b7b3ef81bbad2ae57b531934915cc))
|
|
26
|
+
|
|
5
27
|
### [7.3.4](https://www.github.com/bcoe/c8/compare/v7.3.3...v7.3.4) (2020-10-15)
|
|
6
28
|
|
|
7
29
|
|
package/README.md
CHANGED
|
@@ -64,7 +64,7 @@ To ignore lines, blocks, and functions, use the special comment:
|
|
|
64
64
|
|
|
65
65
|
`/* c8 ignore next */`.
|
|
66
66
|
|
|
67
|
-
### Ignoring the next
|
|
67
|
+
### Ignoring the next line
|
|
68
68
|
|
|
69
69
|
```js
|
|
70
70
|
const myVariable = 99
|
|
@@ -72,7 +72,7 @@ const myVariable = 99
|
|
|
72
72
|
if (process.platform === 'win32') console.info('hello world')
|
|
73
73
|
```
|
|
74
74
|
|
|
75
|
-
### Ignoring the next N
|
|
75
|
+
### Ignoring the next N lines
|
|
76
76
|
|
|
77
77
|
```js
|
|
78
78
|
const myVariable = 99
|
|
@@ -82,6 +82,16 @@ if (process.platform === 'win32') {
|
|
|
82
82
|
}
|
|
83
83
|
```
|
|
84
84
|
|
|
85
|
+
### Ignoring all lines until told
|
|
86
|
+
|
|
87
|
+
```js
|
|
88
|
+
/* c8 ignore start */
|
|
89
|
+
function dontMindMe() {
|
|
90
|
+
// ...
|
|
91
|
+
}
|
|
92
|
+
/* c8 ignore stop */
|
|
93
|
+
```
|
|
94
|
+
|
|
85
95
|
### Ignoring a block on the current line
|
|
86
96
|
|
|
87
97
|
```js
|
package/lib/parse-args.js
CHANGED
|
@@ -126,7 +126,7 @@ function buildYargs (withCommands = false) {
|
|
|
126
126
|
}
|
|
127
127
|
|
|
128
128
|
function hideInstrumenterArgs (yargv) {
|
|
129
|
-
|
|
129
|
+
let argv = process.argv.slice(1)
|
|
130
130
|
argv = argv.slice(argv.indexOf(yargv._[0]))
|
|
131
131
|
if (argv[0][0] === '-') {
|
|
132
132
|
argv.unshift(process.execPath)
|
package/lib/report.js
CHANGED
|
@@ -9,6 +9,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')
|
|
11
11
|
const isCjsEsmBridgeCov = require('./is-cjs-esm-bridge')
|
|
12
|
+
const util = require('util')
|
|
13
|
+
const debuglog = util.debuglog('c8')
|
|
12
14
|
|
|
13
15
|
class Report {
|
|
14
16
|
constructor ({
|
|
@@ -53,7 +55,7 @@ class Report {
|
|
|
53
55
|
}
|
|
54
56
|
|
|
55
57
|
async run () {
|
|
56
|
-
|
|
58
|
+
const context = libReport.createContext({
|
|
57
59
|
dir: this.reportsDirectory,
|
|
58
60
|
watermarks: this.watermarks,
|
|
59
61
|
coverageMap: await this.getCoverageMapFromAllCoverageFiles()
|
|
@@ -103,7 +105,7 @@ class Report {
|
|
|
103
105
|
map.merge(converter.toIstanbul())
|
|
104
106
|
}
|
|
105
107
|
} catch (err) {
|
|
106
|
-
|
|
108
|
+
debuglog(`file: ${v8ScriptCov.url} error: ${err.stack}`)
|
|
107
109
|
}
|
|
108
110
|
}
|
|
109
111
|
|
|
@@ -183,8 +185,8 @@ class Report {
|
|
|
183
185
|
if (ext === '.js' || ext === '.ts' || ext === '.mjs') {
|
|
184
186
|
const stat = statSync(fullPath)
|
|
185
187
|
const sourceMap = getSourceMapFromFile(fullPath)
|
|
186
|
-
if (sourceMap
|
|
187
|
-
this.sourceMapCache[`file://${fullPath}`] = { data:
|
|
188
|
+
if (sourceMap) {
|
|
189
|
+
this.sourceMapCache[`file://${fullPath}`] = { data: sourceMap }
|
|
188
190
|
}
|
|
189
191
|
emptyReports.push({
|
|
190
192
|
scriptId: 0,
|
|
@@ -225,18 +227,18 @@ class Report {
|
|
|
225
227
|
* @private
|
|
226
228
|
*/
|
|
227
229
|
_loadReports () {
|
|
228
|
-
const
|
|
229
|
-
|
|
230
|
-
return files.map((f) => {
|
|
230
|
+
const reports = []
|
|
231
|
+
for (const file of readdirSync(this.tempDirectory)) {
|
|
231
232
|
try {
|
|
232
|
-
|
|
233
|
-
resolve(this.tempDirectory,
|
|
233
|
+
reports.push(JSON.parse(readFileSync(
|
|
234
|
+
resolve(this.tempDirectory, file),
|
|
234
235
|
'utf8'
|
|
235
|
-
))
|
|
236
|
+
)))
|
|
236
237
|
} catch (err) {
|
|
237
|
-
|
|
238
|
+
debuglog(`${err.stack}`)
|
|
238
239
|
}
|
|
239
|
-
}
|
|
240
|
+
}
|
|
241
|
+
return reports
|
|
240
242
|
}
|
|
241
243
|
|
|
242
244
|
/**
|
|
@@ -268,7 +270,7 @@ class Report {
|
|
|
268
270
|
v8ScriptCov.url = furi.toSysPath(v8ScriptCov.url)
|
|
269
271
|
fileIndex.add(v8ScriptCov.url)
|
|
270
272
|
} catch (err) {
|
|
271
|
-
|
|
273
|
+
debuglog(`${err.stack}`)
|
|
272
274
|
continue
|
|
273
275
|
}
|
|
274
276
|
}
|
|
@@ -1,5 +1,34 @@
|
|
|
1
|
-
|
|
1
|
+
/*
|
|
2
|
+
* Copyright Node.js contributors. All rights reserved.
|
|
3
|
+
*
|
|
4
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5
|
+
* of this software and associated documentation files (the "Software"), to
|
|
6
|
+
* deal in the Software without restriction, including without limitation the
|
|
7
|
+
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
|
8
|
+
* sell copies of the Software, and to permit persons to whom the Software is
|
|
9
|
+
* furnished to do so, subject to the following conditions:
|
|
10
|
+
*
|
|
11
|
+
* The above copyright notice and this permission notice shall be included in
|
|
12
|
+
* all copies or substantial portions of the Software.
|
|
13
|
+
*
|
|
14
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
16
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
17
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
18
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
19
|
+
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
|
20
|
+
* IN THE SOFTWARE.
|
|
21
|
+
*/
|
|
22
|
+
// TODO(bcoe): this logic is ported from Node.js' internal source map
|
|
23
|
+
// helpers:
|
|
24
|
+
// https://github.com/nodejs/node/blob/master/lib/internal/source_map/source_map_cache.js
|
|
25
|
+
// we should to upstream and downstream fixes.
|
|
26
|
+
|
|
2
27
|
const { readFileSync } = require('fs')
|
|
28
|
+
const { fileURLToPath, pathToFileURL } = require('url')
|
|
29
|
+
const util = require('util')
|
|
30
|
+
const debuglog = util.debuglog('c8')
|
|
31
|
+
|
|
3
32
|
/**
|
|
4
33
|
* Extract the sourcemap url from a source file
|
|
5
34
|
* reference: https://sourcemaps.info/spec.html
|
|
@@ -7,18 +36,64 @@ const { readFileSync } = require('fs')
|
|
|
7
36
|
* @returns {String} full path to source map file
|
|
8
37
|
* @private
|
|
9
38
|
*/
|
|
10
|
-
function getSourceMapFromFile (
|
|
11
|
-
const fileBody = readFileSync(
|
|
12
|
-
const sourceMapLineRE =
|
|
39
|
+
function getSourceMapFromFile (filename) {
|
|
40
|
+
const fileBody = readFileSync(filename).toString()
|
|
41
|
+
const sourceMapLineRE = /\/[*/]#\s+sourceMappingURL=(?<sourceMappingURL>[^\s]+)/
|
|
13
42
|
const results = fileBody.match(sourceMapLineRE)
|
|
14
43
|
if (results !== null) {
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
44
|
+
const sourceMappingURL = results.groups.sourceMappingURL
|
|
45
|
+
const sourceMap = dataFromUrl(pathToFileURL(filename), sourceMappingURL)
|
|
46
|
+
return sourceMap
|
|
47
|
+
} else {
|
|
48
|
+
return null
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function dataFromUrl (sourceURL, sourceMappingURL) {
|
|
53
|
+
try {
|
|
54
|
+
const url = new URL(sourceMappingURL)
|
|
55
|
+
switch (url.protocol) {
|
|
56
|
+
case 'data:':
|
|
57
|
+
return sourceMapFromDataUrl(url.pathname)
|
|
58
|
+
default:
|
|
59
|
+
return null
|
|
60
|
+
}
|
|
61
|
+
} catch (err) {
|
|
62
|
+
debuglog(err)
|
|
63
|
+
// If no scheme is present, we assume we are dealing with a file path.
|
|
64
|
+
const mapURL = new URL(sourceMappingURL, sourceURL).href
|
|
65
|
+
return sourceMapFromFile(mapURL)
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function sourceMapFromFile (mapURL) {
|
|
70
|
+
try {
|
|
71
|
+
const content = readFileSync(fileURLToPath(mapURL), 'utf8')
|
|
72
|
+
return JSON.parse(content)
|
|
73
|
+
} catch (err) {
|
|
74
|
+
debuglog(err)
|
|
75
|
+
return null
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// data:[<mediatype>][;base64],<data> see:
|
|
80
|
+
// https://tools.ietf.org/html/rfc2397#section-2
|
|
81
|
+
function sourceMapFromDataUrl (url) {
|
|
82
|
+
const { 0: format, 1: data } = url.split(',')
|
|
83
|
+
const splitFormat = format.split(';')
|
|
84
|
+
const contentType = splitFormat[0]
|
|
85
|
+
const base64 = splitFormat[splitFormat.length - 1] === 'base64'
|
|
86
|
+
if (contentType === 'application/json') {
|
|
87
|
+
const decodedData = base64 ? Buffer.from(data, 'base64').toString('utf8') : data
|
|
88
|
+
try {
|
|
89
|
+
return JSON.parse(decodedData)
|
|
90
|
+
} catch (err) {
|
|
91
|
+
debuglog(err)
|
|
92
|
+
return null
|
|
21
93
|
}
|
|
94
|
+
} else {
|
|
95
|
+
debuglog(`unexpected content-type ${contentType}`)
|
|
96
|
+
return null
|
|
22
97
|
}
|
|
23
98
|
}
|
|
24
99
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "c8",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.5.0",
|
|
4
4
|
"description": "output coverage reports using Node.js' built in coverage",
|
|
5
5
|
"main": "./index.js",
|
|
6
6
|
"types": "./index.d.ts",
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
"istanbul-reports": "^3.0.2",
|
|
44
44
|
"rimraf": "^3.0.0",
|
|
45
45
|
"test-exclude": "^6.0.0",
|
|
46
|
-
"v8-to-istanbul": "^
|
|
46
|
+
"v8-to-istanbul": "^7.1.0",
|
|
47
47
|
"yargs": "^16.0.0",
|
|
48
48
|
"yargs-parser": "^20.0.0"
|
|
49
49
|
},
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
"chai": "^4.2.0",
|
|
52
52
|
"chai-jest-snapshot": "^2.0.0",
|
|
53
53
|
"mocha": "^8.1.3",
|
|
54
|
-
"standard": "^
|
|
54
|
+
"standard": "^16.0.3",
|
|
55
55
|
"ts-node": "^9.0.0",
|
|
56
56
|
"typescript": "^4.0.0"
|
|
57
57
|
},
|