monocart-coverage-reports 2.5.6 → 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.
@@ -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;
@@ -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 (typeof sourcePathHandler !== 'function') {
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 (typeof sourcePathHandler === 'function') {
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,7 +4,7 @@ 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');
7
+ const { getSourcePath, getSourcePathHandler } = require('../utils/source-path.js');
8
8
  const { mergeScriptCovs, minimatch } = require('../packages/monocart-coverage-vendor.js');
9
9
  const { collectSourceMaps } = require('../converter/collect-source-maps.js');
10
10
  const version = require('../../package.json').version;
@@ -78,7 +78,7 @@ const initV8ListAndSourcemap = async (v8list, options) => {
78
78
 
79
79
  // do not change original v8list, to work for multiple APIs
80
80
 
81
- const sourcePathHandler = options.sourcePath;
81
+ const sourcePathHandler = getSourcePathHandler(options);
82
82
 
83
83
  // init id, sourcePath
84
84
  v8list = v8list.map((item, i) => {
@@ -119,7 +119,7 @@ const initV8ListAndSourcemap = async (v8list, options) => {
119
119
 
120
120
  // resolve source path
121
121
  let sourcePath = getSourcePath(data.url, i + 1, data.type);
122
- if (typeof sourcePathHandler === 'function') {
122
+ if (sourcePathHandler) {
123
123
  const newSourcePath = sourcePathHandler(sourcePath, data.url);
124
124
  if (typeof newSourcePath === 'string' && newSourcePath) {
125
125
  sourcePath = newSourcePath;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "monocart-coverage-reports",
3
- "version": "2.5.6",
3
+ "version": "2.5.7",
4
4
  "description": "Monocart coverage reports",
5
5
  "main": "./lib/index.js",
6
6
  "bin": {