monocart-coverage-reports 2.8.0 → 2.8.1
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/lib/cli.js +1 -0
- package/lib/converter/converter.js +2 -5
- package/lib/default/options.js +3 -0
- package/lib/index.d.ts +3 -0
- package/lib/istanbul/istanbul.js +2 -4
- package/lib/utils/source-path.js +22 -14
- package/lib/v8/v8.js +7 -5
- package/package.json +1 -1
package/lib/cli.js
CHANGED
|
@@ -192,6 +192,7 @@ program
|
|
|
192
192
|
|
|
193
193
|
.option('-o, --outputDir <dir>', 'output dir for reports')
|
|
194
194
|
.option('-i, --inputDir <dir>', 'input dir for merging raw files')
|
|
195
|
+
.option('-b, --baseDir <dir>', 'base dir for normalizing path')
|
|
195
196
|
|
|
196
197
|
.option('-a, --all <dir>', 'include all files from dir')
|
|
197
198
|
|
|
@@ -16,9 +16,7 @@ const { getIgnoredRanges } = require('./ignore.js');
|
|
|
16
16
|
const {
|
|
17
17
|
sortRanges, dedupeCountRanges, mergeRangesWith
|
|
18
18
|
} = require('../utils/dedupe.js');
|
|
19
|
-
const {
|
|
20
|
-
getSourceType, getSourcePathHandler, initSourceMapSourcePath
|
|
21
|
-
} = require('../utils/source-path.js');
|
|
19
|
+
const { getSourceType, initSourceMapSourcesPath } = require('../utils/source-path.js');
|
|
22
20
|
const { decode, minimatch } = require('../packages/monocart-coverage-vendor.js');
|
|
23
21
|
|
|
24
22
|
const InfoBranch = require('./info-branch.js');
|
|
@@ -1111,8 +1109,7 @@ const unpackSourceMap = (state, options) => {
|
|
|
1111
1109
|
|
|
1112
1110
|
// keep original urls
|
|
1113
1111
|
const fileUrls = {};
|
|
1114
|
-
|
|
1115
|
-
initSourceMapSourcePath(sourceMap, fileUrls, sourcePath, sourcePathHandler);
|
|
1112
|
+
initSourceMapSourcesPath(fileUrls, sourceMap, sourcePath, options);
|
|
1116
1113
|
state.fileUrls = fileUrls;
|
|
1117
1114
|
|
|
1118
1115
|
// ===============================================
|
package/lib/default/options.js
CHANGED
|
@@ -24,6 +24,9 @@ module.exports = {
|
|
|
24
24
|
// {string|string[]} input raw dir(s)
|
|
25
25
|
inputDir: null,
|
|
26
26
|
|
|
27
|
+
// {string} base dir for normalizing the relative source path, defaults to cwd
|
|
28
|
+
baseDir: null,
|
|
29
|
+
|
|
27
30
|
// (V8 only) {function} A filter function to execute for each element in the V8 list.
|
|
28
31
|
// entryFilter: (entry) => {
|
|
29
32
|
// if (entry.url.indexOf('googleapis.com') !== -1) {
|
package/lib/index.d.ts
CHANGED
|
@@ -230,6 +230,9 @@ declare namespace MCR {
|
|
|
230
230
|
/** {string|string[]} input raw dir(s) */
|
|
231
231
|
inputDir?: string | string[];
|
|
232
232
|
|
|
233
|
+
/** {string} base dir for normalizing the relative source path, defaults to cwd */
|
|
234
|
+
baseDir?: string;
|
|
235
|
+
|
|
233
236
|
/** (V8 only)
|
|
234
237
|
*
|
|
235
238
|
* {string} `minimatch` pattern for entry url;
|
package/lib/istanbul/istanbul.js
CHANGED
|
@@ -7,7 +7,7 @@ const istanbulLibReport = require('istanbul-lib-report');
|
|
|
7
7
|
const Util = require('../utils/util.js');
|
|
8
8
|
const IstanbulSummary = require('./istanbul-summary.js');
|
|
9
9
|
|
|
10
|
-
const {
|
|
10
|
+
const { initIstanbulSourcePath } = require('../utils/source-path.js');
|
|
11
11
|
|
|
12
12
|
const findHtmlPath = (outputDir) => {
|
|
13
13
|
const defaultHtml = path.resolve(outputDir, 'index.html');
|
|
@@ -129,9 +129,7 @@ const mergeIstanbulCoverage = (dataList) => {
|
|
|
129
129
|
const initIstanbulData = (istanbulData, options) => {
|
|
130
130
|
|
|
131
131
|
const fileSources = options.fileSources || {};
|
|
132
|
-
const
|
|
133
|
-
|
|
134
|
-
const coverageData = initIstanbulSourcePath(istanbulData, fileSources, sourcePathHandler);
|
|
132
|
+
const coverageData = initIstanbulSourcePath(istanbulData, fileSources, options);
|
|
135
133
|
|
|
136
134
|
return {
|
|
137
135
|
fileSources,
|
package/lib/utils/source-path.js
CHANGED
|
@@ -21,7 +21,8 @@ const filterPath = (str) => {
|
|
|
21
21
|
return ls.join('/');
|
|
22
22
|
};
|
|
23
23
|
|
|
24
|
-
|
|
24
|
+
// eslint-disable-next-line complexity
|
|
25
|
+
const normalizeSourcePath = (url, baseDir, index = '', type = '') => {
|
|
25
26
|
|
|
26
27
|
// no url for anonymous
|
|
27
28
|
if (!url) {
|
|
@@ -32,7 +33,7 @@ const getSourcePath = (url, index = '', type = '') => {
|
|
|
32
33
|
|
|
33
34
|
// already is file url
|
|
34
35
|
if (url.startsWith('file:')) {
|
|
35
|
-
const relPath = Util.relativePath(fileURLToPath(url));
|
|
36
|
+
const relPath = Util.relativePath(fileURLToPath(url), baseDir);
|
|
36
37
|
return filterPath(relPath);
|
|
37
38
|
}
|
|
38
39
|
|
|
@@ -54,7 +55,7 @@ const getSourcePath = (url, index = '', type = '') => {
|
|
|
54
55
|
|
|
55
56
|
// could be path
|
|
56
57
|
const fileUrl = pathToFileURL(url).toString();
|
|
57
|
-
const relPath = Util.relativePath(fileURLToPath(fileUrl));
|
|
58
|
+
const relPath = Util.relativePath(fileURLToPath(fileUrl), baseDir);
|
|
58
59
|
return filterPath(relPath);
|
|
59
60
|
|
|
60
61
|
};
|
|
@@ -75,7 +76,7 @@ const getSourceType = (sourcePath) => {
|
|
|
75
76
|
|
|
76
77
|
// ========================================================================================================
|
|
77
78
|
|
|
78
|
-
const
|
|
79
|
+
const getSourcePathReplacer = (options) => {
|
|
79
80
|
const input = options.sourcePath;
|
|
80
81
|
if (typeof input === 'function') {
|
|
81
82
|
return input;
|
|
@@ -96,8 +97,10 @@ const getSourcePathHandler = (options) => {
|
|
|
96
97
|
|
|
97
98
|
// ========================================================================================================
|
|
98
99
|
|
|
99
|
-
const initIstanbulSourcePath = (coverageData, fileSources,
|
|
100
|
-
|
|
100
|
+
const initIstanbulSourcePath = (coverageData, fileSources, options) => {
|
|
101
|
+
|
|
102
|
+
const sourcePathReplacer = getSourcePathReplacer(options);
|
|
103
|
+
if (!sourcePathReplacer) {
|
|
101
104
|
return coverageData;
|
|
102
105
|
}
|
|
103
106
|
|
|
@@ -119,7 +122,7 @@ const initIstanbulSourcePath = (coverageData, fileSources, sourcePathHandler) =>
|
|
|
119
122
|
}
|
|
120
123
|
|
|
121
124
|
// new source path, second is source url
|
|
122
|
-
const newSourcePath =
|
|
125
|
+
const newSourcePath = sourcePathReplacer(sourcePath, item);
|
|
123
126
|
if (typeof newSourcePath === 'string' && newSourcePath) {
|
|
124
127
|
sourcePath = newSourcePath;
|
|
125
128
|
}
|
|
@@ -180,16 +183,21 @@ const resolveSourceUrl = (sourceName, sourceRoot) => {
|
|
|
180
183
|
return sourceUrl;
|
|
181
184
|
};
|
|
182
185
|
|
|
183
|
-
const
|
|
186
|
+
const initSourceMapSourcesPath = (fileUrls, sourceMap, distFile, options) => {
|
|
187
|
+
|
|
188
|
+
const baseDir = options.baseDir;
|
|
189
|
+
const sourcePathReplacer = getSourcePathReplacer(options);
|
|
184
190
|
|
|
185
191
|
sourceMap.sources = sourceMap.sources.map((sourceName, i) => {
|
|
186
192
|
|
|
187
193
|
const sourceUrl = resolveSourceUrl(sourceName, sourceMap.sourceRoot);
|
|
188
194
|
|
|
189
|
-
let sourcePath =
|
|
190
|
-
|
|
195
|
+
let sourcePath = normalizeSourcePath(sourceUrl, baseDir, i + 1);
|
|
196
|
+
// console.log(sourceUrl, sourcePath);
|
|
197
|
+
|
|
198
|
+
if (sourcePathReplacer) {
|
|
191
199
|
// sourcePath could be a filename only, may using distFile to get full path
|
|
192
|
-
const newSourcePath =
|
|
200
|
+
const newSourcePath = sourcePathReplacer(sourcePath, {
|
|
193
201
|
url: sourceUrl,
|
|
194
202
|
distFile
|
|
195
203
|
});
|
|
@@ -208,9 +216,9 @@ module.exports = {
|
|
|
208
216
|
// for unit test
|
|
209
217
|
resolveSourceUrl,
|
|
210
218
|
|
|
211
|
-
|
|
219
|
+
normalizeSourcePath,
|
|
212
220
|
getSourceType,
|
|
213
|
-
|
|
221
|
+
getSourcePathReplacer,
|
|
214
222
|
initIstanbulSourcePath,
|
|
215
|
-
|
|
223
|
+
initSourceMapSourcesPath
|
|
216
224
|
};
|
package/lib/v8/v8.js
CHANGED
|
@@ -3,7 +3,7 @@ const EC = require('eight-colors');
|
|
|
3
3
|
const Util = require('../utils/util.js');
|
|
4
4
|
const { getV8Summary } = require('./v8-summary.js');
|
|
5
5
|
const { dedupeFlatRanges } = require('../utils/dedupe.js');
|
|
6
|
-
const {
|
|
6
|
+
const { normalizeSourcePath, getSourcePathReplacer } = require('../utils/source-path.js');
|
|
7
7
|
const { mergeScriptCovs, minimatch } = require('../packages/monocart-coverage-vendor.js');
|
|
8
8
|
const { collectSourceMaps } = require('../converter/collect-source-maps.js');
|
|
9
9
|
const version = require('../../package.json').version;
|
|
@@ -109,7 +109,9 @@ const initV8ListAndSourcemap = async (v8list, options) => {
|
|
|
109
109
|
}
|
|
110
110
|
}
|
|
111
111
|
|
|
112
|
-
const
|
|
112
|
+
const sourcePathReplacer = getSourcePathReplacer(options);
|
|
113
|
+
|
|
114
|
+
const baseDir = options.baseDir;
|
|
113
115
|
|
|
114
116
|
// init id, sourcePath
|
|
115
117
|
v8list = v8list.map((entry, i) => {
|
|
@@ -149,9 +151,9 @@ const initV8ListAndSourcemap = async (v8list, options) => {
|
|
|
149
151
|
}
|
|
150
152
|
|
|
151
153
|
// resolve source path
|
|
152
|
-
let sourcePath =
|
|
153
|
-
if (
|
|
154
|
-
const newSourcePath =
|
|
154
|
+
let sourcePath = normalizeSourcePath(data.url, baseDir, i + 1, data.type);
|
|
155
|
+
if (sourcePathReplacer) {
|
|
156
|
+
const newSourcePath = sourcePathReplacer(sourcePath, data);
|
|
155
157
|
if (typeof newSourcePath === 'string' && newSourcePath) {
|
|
156
158
|
sourcePath = newSourcePath;
|
|
157
159
|
}
|