c8 7.4.0 → 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 +7 -0
- package/lib/report.js +2 -2
- package/lib/source-map-from-file.js +85 -10
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,13 @@
|
|
|
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
|
+
|
|
5
12
|
## [7.4.0](https://www.github.com/bcoe/c8/compare/v7.3.5...v7.4.0) (2020-12-31)
|
|
6
13
|
|
|
7
14
|
|
package/lib/report.js
CHANGED
|
@@ -185,8 +185,8 @@ class Report {
|
|
|
185
185
|
if (ext === '.js' || ext === '.ts' || ext === '.mjs') {
|
|
186
186
|
const stat = statSync(fullPath)
|
|
187
187
|
const sourceMap = getSourceMapFromFile(fullPath)
|
|
188
|
-
if (sourceMap
|
|
189
|
-
this.sourceMapCache[`file://${fullPath}`] = { data:
|
|
188
|
+
if (sourceMap) {
|
|
189
|
+
this.sourceMapCache[`file://${fullPath}`] = { data: sourceMap }
|
|
190
190
|
}
|
|
191
191
|
emptyReports.push({
|
|
192
192
|
scriptId: 0,
|
|
@@ -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
|
|