monocart-coverage-reports 2.5.5 → 2.5.7
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/README.md +43 -6
- package/lib/cli.js +94 -15
- package/lib/converter/collect-source-maps.js +12 -22
- package/lib/converter/converter.js +23 -7
- package/lib/index.d.ts +31 -10
- package/lib/istanbul/istanbul.js +2 -2
- package/lib/packages/monocart-coverage-vendor.js +46 -55
- package/lib/utils/request.js +62 -0
- package/lib/utils/source-path.js +25 -2
- package/lib/utils/util.js +3 -0
- package/lib/v8/v8.js +29 -9
- package/package.json +3 -2
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
const http = require('http');
|
|
2
|
+
const https = require('https');
|
|
3
|
+
|
|
4
|
+
// minimal http request for get sourcemap json
|
|
5
|
+
const request = (options) => {
|
|
6
|
+
|
|
7
|
+
const url = `${options.url}`;
|
|
8
|
+
// console.log('request', url);
|
|
9
|
+
|
|
10
|
+
return new Promise((resolve) => {
|
|
11
|
+
|
|
12
|
+
const HTTP = url.startsWith('https') ? https : http;
|
|
13
|
+
|
|
14
|
+
HTTP.get(url, (res) => {
|
|
15
|
+
const { statusCode } = res;
|
|
16
|
+
|
|
17
|
+
// Any 2xx status code signals a successful response but here we're only checking for 200.
|
|
18
|
+
if (statusCode !== 200) {
|
|
19
|
+
// Consume response data to free up memory
|
|
20
|
+
res.resume();
|
|
21
|
+
const resErr = new Error(`Request Failed. Status Code: ${statusCode}`);
|
|
22
|
+
resolve([resErr, null]);
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
res.setEncoding('utf8');
|
|
27
|
+
|
|
28
|
+
let rawData = '';
|
|
29
|
+
res.on('data', (chunk) => {
|
|
30
|
+
rawData += chunk;
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
res.on('end', () => {
|
|
34
|
+
|
|
35
|
+
let dataErr;
|
|
36
|
+
let data = rawData;
|
|
37
|
+
|
|
38
|
+
// parse json
|
|
39
|
+
const contentType = res.headers['content-type'];
|
|
40
|
+
if ((/^application\/json/).test(contentType)) {
|
|
41
|
+
try {
|
|
42
|
+
data = JSON.parse(rawData);
|
|
43
|
+
} catch (e) {
|
|
44
|
+
dataErr = e;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
res.data = data;
|
|
49
|
+
resolve([dataErr, res]);
|
|
50
|
+
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
}).on('error', (httpErr) => {
|
|
54
|
+
|
|
55
|
+
resolve([httpErr, null]);
|
|
56
|
+
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
});
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
module.exports = request;
|
package/lib/utils/source-path.js
CHANGED
|
@@ -72,10 +72,32 @@ const getSourceType = (sourcePath) => {
|
|
|
72
72
|
return type;
|
|
73
73
|
};
|
|
74
74
|
|
|
75
|
+
|
|
76
|
+
// ========================================================================================================
|
|
77
|
+
|
|
78
|
+
const getSourcePathHandler = (options) => {
|
|
79
|
+
const input = options.sourcePath;
|
|
80
|
+
if (typeof input === 'function') {
|
|
81
|
+
return input;
|
|
82
|
+
}
|
|
83
|
+
// object replace key with value
|
|
84
|
+
if (input && typeof input === 'object') {
|
|
85
|
+
const keys = Object.keys(input).filter((k) => typeof input[k] === 'string');
|
|
86
|
+
if (keys.length) {
|
|
87
|
+
return (filePath) => {
|
|
88
|
+
keys.forEach((k) => {
|
|
89
|
+
filePath = filePath.replace(k, input[k]);
|
|
90
|
+
});
|
|
91
|
+
return filePath;
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
|
|
75
97
|
// ========================================================================================================
|
|
76
98
|
|
|
77
99
|
const initIstanbulSourcePath = (coverageData, fileSources, sourcePathHandler) => {
|
|
78
|
-
if (
|
|
100
|
+
if (!sourcePathHandler) {
|
|
79
101
|
return coverageData;
|
|
80
102
|
}
|
|
81
103
|
|
|
@@ -121,7 +143,7 @@ const initSourceMapSourcePath = (sourceMap, fileUrls, sourcePathHandler) => {
|
|
|
121
143
|
const sourceUrl = mergeSourceRoot(sourceRoot, sourceName);
|
|
122
144
|
|
|
123
145
|
let sourcePath = getSourcePath(sourceUrl, i + 1);
|
|
124
|
-
if (
|
|
146
|
+
if (sourcePathHandler) {
|
|
125
147
|
const newSourcePath = sourcePathHandler(sourcePath, sourceUrl);
|
|
126
148
|
if (typeof newSourcePath === 'string' && newSourcePath) {
|
|
127
149
|
sourcePath = newSourcePath;
|
|
@@ -137,6 +159,7 @@ const initSourceMapSourcePath = (sourceMap, fileUrls, sourcePathHandler) => {
|
|
|
137
159
|
module.exports = {
|
|
138
160
|
getSourcePath,
|
|
139
161
|
getSourceType,
|
|
162
|
+
getSourcePathHandler,
|
|
140
163
|
initIstanbulSourcePath,
|
|
141
164
|
initSourceMapSourcePath
|
|
142
165
|
};
|
package/lib/utils/util.js
CHANGED
|
@@ -7,6 +7,7 @@ const crypto = require('crypto');
|
|
|
7
7
|
const EC = require('eight-colors');
|
|
8
8
|
const CG = require('console-grid');
|
|
9
9
|
const Share = require('../platform/share.js');
|
|
10
|
+
const request = require('./request.js');
|
|
10
11
|
const { deflateSync } = require('lz-utils');
|
|
11
12
|
|
|
12
13
|
const { acornWalk, supportsColor } = require('../packages/monocart-coverage-vendor.js');
|
|
@@ -25,6 +26,8 @@ const Util = {
|
|
|
25
26
|
|
|
26
27
|
root: process.cwd(),
|
|
27
28
|
|
|
29
|
+
request,
|
|
30
|
+
|
|
28
31
|
relativePath: function(p, root) {
|
|
29
32
|
p = `${p}`;
|
|
30
33
|
root = `${root || Util.root}`;
|
package/lib/v8/v8.js
CHANGED
|
@@ -4,9 +4,9 @@ const EC = require('eight-colors');
|
|
|
4
4
|
const Util = require('../utils/util.js');
|
|
5
5
|
const { getV8Summary } = require('./v8-summary.js');
|
|
6
6
|
const { dedupeFlatRanges } = require('../utils/dedupe.js');
|
|
7
|
-
const { getSourcePath } = require('../utils/source-path.js');
|
|
8
|
-
const { mergeScriptCovs } = require('../packages/monocart-coverage-vendor.js');
|
|
9
|
-
const collectSourceMaps = require('../converter/collect-source-maps.js');
|
|
7
|
+
const { getSourcePath, getSourcePathHandler } = require('../utils/source-path.js');
|
|
8
|
+
const { mergeScriptCovs, minimatch } = require('../packages/monocart-coverage-vendor.js');
|
|
9
|
+
const { collectSourceMaps } = require('../converter/collect-source-maps.js');
|
|
10
10
|
const version = require('../../package.json').version;
|
|
11
11
|
|
|
12
12
|
const getWrapperSource = (offset, source) => {
|
|
@@ -23,18 +23,38 @@ const getWrapperSource = (offset, source) => {
|
|
|
23
23
|
return startStr + source;
|
|
24
24
|
};
|
|
25
25
|
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
-
// filter list first
|
|
26
|
+
const getEntryFilter = (options) => {
|
|
29
27
|
const entryFilter = options.entryFilter;
|
|
30
28
|
if (typeof entryFilter === 'function') {
|
|
31
|
-
|
|
29
|
+
return entryFilter;
|
|
32
30
|
}
|
|
33
31
|
|
|
32
|
+
if (entryFilter && typeof entryFilter === 'string') {
|
|
33
|
+
return (entry) => {
|
|
34
|
+
return minimatch(entry.url, entryFilter);
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return () => true;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
const initV8ListAndSourcemap = async (v8list, options) => {
|
|
42
|
+
|
|
43
|
+
// entry filter
|
|
44
|
+
const entryFilter = getEntryFilter(options);
|
|
45
|
+
|
|
34
46
|
// filter no source or text
|
|
35
47
|
// init type and css source from text
|
|
36
48
|
// keep functions
|
|
37
49
|
v8list = v8list.filter((item) => {
|
|
50
|
+
|
|
51
|
+
// filter entry
|
|
52
|
+
if (!entryFilter(item)) {
|
|
53
|
+
// console.log('-', item.url);
|
|
54
|
+
return false;
|
|
55
|
+
}
|
|
56
|
+
// console.log(item.url);
|
|
57
|
+
|
|
38
58
|
if (typeof item.source === 'string' && item.functions) {
|
|
39
59
|
item.type = 'js';
|
|
40
60
|
return true;
|
|
@@ -58,7 +78,7 @@ const initV8ListAndSourcemap = async (v8list, options) => {
|
|
|
58
78
|
|
|
59
79
|
// do not change original v8list, to work for multiple APIs
|
|
60
80
|
|
|
61
|
-
const sourcePathHandler = options
|
|
81
|
+
const sourcePathHandler = getSourcePathHandler(options);
|
|
62
82
|
|
|
63
83
|
// init id, sourcePath
|
|
64
84
|
v8list = v8list.map((item, i) => {
|
|
@@ -99,7 +119,7 @@ const initV8ListAndSourcemap = async (v8list, options) => {
|
|
|
99
119
|
|
|
100
120
|
// resolve source path
|
|
101
121
|
let sourcePath = getSourcePath(data.url, i + 1, data.type);
|
|
102
|
-
if (
|
|
122
|
+
if (sourcePathHandler) {
|
|
103
123
|
const newSourcePath = sourcePathHandler(sourcePath, data.url);
|
|
104
124
|
if (typeof newSourcePath === 'string' && newSourcePath) {
|
|
105
125
|
sourcePath = newSourcePath;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "monocart-coverage-reports",
|
|
3
|
-
"version": "2.5.
|
|
3
|
+
"version": "2.5.7",
|
|
4
4
|
"description": "Monocart coverage reports",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"bin": {
|
|
@@ -67,10 +67,11 @@
|
|
|
67
67
|
},
|
|
68
68
|
"devDependencies": {
|
|
69
69
|
"commander": "^12.0.0",
|
|
70
|
-
"eslint": "^8.
|
|
70
|
+
"eslint": "^8.57.0",
|
|
71
71
|
"eslint-config-plus": "^1.0.6",
|
|
72
72
|
"eslint-plugin-html": "^8.0.0",
|
|
73
73
|
"eslint-plugin-vue": "^9.22.0",
|
|
74
|
+
"minimatch": "^9.0.3",
|
|
74
75
|
"stylelint": "^15.11.0",
|
|
75
76
|
"stylelint-config-plus": "^1.0.4",
|
|
76
77
|
"supports-color": "^9.4.0"
|