monocart-coverage-reports 2.10.9 → 2.11.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/utils/util.js CHANGED
@@ -3,6 +3,7 @@ const { writeFile, readFile } = require('fs/promises');
3
3
  const path = require('path');
4
4
  const os = require('os');
5
5
  const crypto = require('crypto');
6
+
6
7
  const EC = require('eight-colors');
7
8
  const CG = require('console-grid');
8
9
  const acornWalk = require('acorn-walk');
@@ -11,6 +12,8 @@ const Share = require('../platform/share.js');
11
12
  const request = require('./request.js');
12
13
  const version = require('../../package.json').version;
13
14
  const markdownGrid = require('./markdown.js');
15
+ const { mergeV8Coverage } = require('./merge/merge.js');
16
+ const gc = require('./gc.js');
14
17
 
15
18
  const {
16
19
  findUpSync, supportsColor, minimatch
@@ -34,6 +37,11 @@ const Util = {
34
37
 
35
38
  request,
36
39
  markdownGrid,
40
+ mergeV8Coverage,
41
+
42
+ forceGC: () => {
43
+ gc();
44
+ },
37
45
 
38
46
  relativePath: function(p, root) {
39
47
  p = `${p}`;
@@ -464,6 +472,13 @@ const Util = {
464
472
  }
465
473
  },
466
474
 
475
+ readJson: async (jsonPath) => {
476
+ const content = await Util.readFile(jsonPath);
477
+ if (content) {
478
+ return JSON.parse(content);
479
+ }
480
+ },
481
+
467
482
  writeFileSync: function(filePath, content) {
468
483
  if (!fs.existsSync(filePath)) {
469
484
  const p = path.dirname(filePath);
@@ -854,8 +869,28 @@ const Util = {
854
869
  console.log(`[MCR] ${message} before ${lengthBefore} => after ${lengthAfter}`);
855
870
  },
856
871
 
872
+ setGC: (threshold) => {
873
+ if (!Util.isNum(threshold)) {
874
+ threshold = 1024;
875
+ }
876
+ Util.gcThreshold = threshold;
877
+ },
878
+
879
+ getMemory: () => {
880
+ const { heapUsed } = process.memoryUsage();
881
+ const memory = parseFloat((heapUsed / 1024 ** 2).toFixed(1));
882
+ return memory;
883
+ },
884
+
857
885
  // time is debug level, fix the log info, for checking snapshot
858
886
  logTime: (message, time_start) => {
887
+
888
+ // memory gc
889
+ let memory = Util.getMemory();
890
+ if (Util.gcThreshold && Util.gcThreshold < memory) {
891
+ Util.forceGC();
892
+ }
893
+
859
894
  if (Util.loggingLevel < Util.loggingLevels.debug && !process.env.MCR_LOG_TIME) {
860
895
  return;
861
896
  }
@@ -863,9 +898,7 @@ const Util = {
863
898
  const durationH = Util.TF(duration);
864
899
  const ls = [`[MCR] ${message}`];
865
900
 
866
- // memory
867
- const { heapUsed } = process.memoryUsage();
868
- const memory = parseFloat((heapUsed / 1024 ** 2).toFixed(1));
901
+ memory = Util.getMemory();
869
902
  ls.push(` (memory: ${memory}MB)`);
870
903
 
871
904
  // time
package/lib/v8/v8.js CHANGED
@@ -1,5 +1,4 @@
1
1
  const EC = require('eight-colors');
2
- const { mergeScriptCovs } = require('@bcoe/v8-coverage');
3
2
  const Util = require('../utils/util.js');
4
3
  const { getV8Summary } = require('./v8-summary.js');
5
4
  const { dedupeFlatRanges } = require('../utils/dedupe.js');
@@ -165,30 +164,29 @@ const mergeCssRanges = (itemList) => {
165
164
  // ranges: [ {start, end} ]
166
165
  const ranges = dedupeFlatRanges(concatRanges);
167
166
 
168
- resolve(ranges || []);
167
+ resolve(ranges);
169
168
  });
170
169
  };
171
170
 
172
- const mergeJsFunctions = (itemList) => {
173
- return new Promise((resolve) => {
174
-
175
- const res = mergeScriptCovs(itemList);
176
- const functions = res && res.functions;
177
-
178
- resolve(functions || []);
179
- });
171
+ const mergeJsFunctions = async (itemList) => {
172
+ const res = await Util.mergeV8Coverage(itemList);
173
+ return res.functions;
180
174
  };
181
175
 
182
- const mergeV8Coverage = async (dataList, sourceCache, options) => {
176
+ const mergeV8DataList = async (dataList, options) => {
177
+ const allList = dataList.map((d) => d.data).flat();
183
178
 
184
- let allList = [];
185
- dataList.forEach((d) => {
186
- allList = allList.concat(d.data);
179
+ // separate coverage and empty items
180
+ const coverageList = [];
181
+ const allEmptyList = [];
182
+ allList.forEach((it) => {
183
+ if (it.empty) {
184
+ allEmptyList.push(it);
185
+ } else {
186
+ coverageList.push(it);
187
+ }
187
188
  });
188
189
 
189
- // remove empty items
190
- const coverageList = allList.filter((it) => !it.empty);
191
-
192
190
  // connect all functions and ranges
193
191
  const itemMap = {};
194
192
  const sourcePathMap = {};
@@ -222,7 +220,7 @@ const mergeV8Coverage = async (dataList, sourceCache, options) => {
222
220
 
223
221
  // first time filter for empty, (not for sources)
224
222
  // empty and not in item map
225
- const emptyList = allList.filter((it) => it.empty).filter((it) => {
223
+ const emptyList = allEmptyList.filter((it) => {
226
224
  if (itemMap[it.id]) {
227
225
  return false;
228
226
  }
@@ -232,8 +230,15 @@ const mergeV8Coverage = async (dataList, sourceCache, options) => {
232
230
  return true;
233
231
  });
234
232
 
235
- // empty list + merged list
236
- const mergedList = emptyList.concat(Object.values(itemMap));
233
+ // merged list + empty list
234
+ const mergedList = Object.values(itemMap).concat(emptyList);
235
+
236
+ return mergedList;
237
+ };
238
+
239
+ const mergeV8Coverage = async (dataList, sourceCache, options) => {
240
+
241
+ const mergedList = await mergeV8DataList(dataList, options);
237
242
 
238
243
  // try to load coverage and source by id
239
244
  for (const entry of mergedList) {
@@ -253,6 +258,9 @@ const mergeV8Coverage = async (dataList, sourceCache, options) => {
253
258
 
254
259
  }
255
260
 
261
+ // GC
262
+ sourceCache.clear();
263
+
256
264
  return mergedList;
257
265
  };
258
266
 
@@ -329,6 +337,7 @@ const saveV8Report = async (v8list, options, istanbulReportPath) => {
329
337
 
330
338
  module.exports = {
331
339
  initV8ListAndSourcemap,
340
+ mergeV8DataList,
332
341
  mergeV8Coverage,
333
342
  saveV8Report
334
343
  };
package/package.json CHANGED
@@ -1,115 +1,118 @@
1
- {
2
- "name": "monocart-coverage-reports",
3
- "version": "2.10.9",
4
- "description": "A code coverage tool to generate native V8 reports or Istanbul reports.",
5
- "main": "./lib/index.js",
6
- "bin": {
7
- "mcr": "./lib/cli.js"
8
- },
9
- "exports": {
10
- ".": {
11
- "types": "./lib/index.d.ts",
12
- "import": "./lib/index.mjs",
13
- "require": "./lib/index.js"
14
- },
15
- "./register": {
16
- "import": "./lib/register/register.mjs",
17
- "require": "./lib/register/register.js"
18
- },
19
- "./converter": "./lib/converter/converter.js",
20
- "./util": "./lib/utils/util.js",
21
- "./package.json": "./package.json"
22
- },
23
- "types": "./lib/index.d.ts",
24
- "scripts": {
25
- "build-test": "node ./test/build/build-test.js",
26
- "build": "npx sf lint && npx sf b -p && npm run build-test",
27
- "test-unit": "mocha --parallel test/unit/*.test.js",
28
- "test-node-env": "cross-env NODE_V8_COVERAGE=.temp/v8-coverage-env node ./test/test-node-env.js && node ./test/generate-report.js",
29
- "test-node-api": "cross-env NODE_V8_COVERAGE=.temp/v8-coverage-api node ./test/test-node-api.js",
30
- "test-node-ins": "node ./test/test-node-ins.js",
31
- "test-node-cdp": "node --inspect=9229 ./test/test-node-cdp.js",
32
- "test-node-vm": "node ./test/test-node-vm.js",
33
- "test-node-koa": "node ./test/test-node-koa.js",
34
- "test-node-fgc": "node ./test/test-node-fgc.js",
35
- "test-node": "node ./test/test.js --node",
36
- "test-istanbul": "node ./test/test-istanbul.js",
37
- "test-v8": "node ./test/test-v8.js",
38
- "test-puppeteer": "node ./test/test-puppeteer.js",
39
- "test-anonymous": "node ./test/test-anonymous.js",
40
- "test-css": "node ./test/test-css.js",
41
- "test-minify": "node ./test/test-minify.js",
42
- "test-esbuild": "node ./test/test-esbuild.js",
43
- "test-rollup": "node ./test/test-rollup.js",
44
- "test-sections": "node ./test/test-sections.js",
45
- "test-swc": "node ./test/test-swc.js",
46
- "test-v8-and-istanbul": "node ./test/test-v8-and-istanbul.js",
47
- "test-browser": "node ./test/test.js --browser",
48
- "test-cli": "npx mcr node ./test/specs/node.test.js -c test/mcr.config.cli.js",
49
- "test-tsx": "npx mcr tsx ./test/specs/tsx.test.ts -c test/mcr.config.tsx.js",
50
- "test-demo": "node ./test/test-demo.js",
51
- "test-merge": "node ./test/test-merge.js",
52
- "test-merge-istanbul": "node ./test/test-merge-istanbul.js",
53
- "test-client": "node ./test/test-client.js",
54
- "test-all": "node ./test/test.js",
55
- "test-pr": "node --inspect=9230 ./test/test-pr.js",
56
- "test": "npm run test-unit && npx mcr npm run test-all -c test/mcr.config.mcr.js && node ./scripts/docs.js",
57
- "test:snap": "cross-env TEST_SNAPSHOT=true npm run test",
58
- "dev": "npx sf d app",
59
- "open": "node ./scripts/open.js",
60
- "eol": "git rm -rf --cached . && git reset --hard HEAD",
61
- "patch": "npm version patch && npm run build && npm run test && npm publish",
62
- "beta": "npm version prerelease --preid=beta && npm run build && npm run test && npm publish --tag beta"
63
- },
64
- "workspaces": [
65
- "test"
66
- ],
67
- "files": [
68
- "lib",
69
- "README.zh-Hans.md"
70
- ],
71
- "license": "MIT",
72
- "repository": {
73
- "type": "git",
74
- "url": "git+https://github.com/cenfun/monocart-coverage-reports.git"
75
- },
76
- "dependencies": {
77
- "@bcoe/v8-coverage": "^0.2.3",
78
- "@jridgewell/sourcemap-codec": "^1.5.0",
79
- "acorn": "^8.12.1",
80
- "acorn-loose": "^8.4.0",
81
- "acorn-walk": "^8.3.4",
82
- "commander": "^12.1.0",
83
- "console-grid": "^2.2.2",
84
- "eight-colors": "^1.3.0",
85
- "foreground-child": "^3.3.0",
86
- "istanbul-lib-coverage": "^3.2.2",
87
- "istanbul-lib-report": "^3.0.1",
88
- "istanbul-reports": "^3.1.7",
89
- "lz-utils": "^2.1.0",
90
- "monocart-locator": "^1.0.2"
91
- },
92
- "devDependencies": {
93
- "async-tick": "^1.0.0",
94
- "convert-source-map": "^2.0.0",
95
- "diff-sequences": "^29.6.3",
96
- "esbuild": "^0.23.1",
97
- "eslint": "~9.10.0",
98
- "eslint-config-plus": "^2.0.2",
99
- "eslint-plugin-html": "^8.1.1",
100
- "eslint-plugin-vue": "^9.28.0",
101
- "find-up": "^7.0.0",
102
- "minimatch": "^9.0.5",
103
- "monocart-code-viewer": "^1.1.4",
104
- "monocart-formatter": "^3.0.0",
105
- "postcss": "^8.4.47",
106
- "starfall-cli": "^2.0.20",
107
- "stylelint": "^16.9.0",
108
- "stylelint-config-plus": "^1.1.3",
109
- "supports-color": "^9.4.0",
110
- "tsx": "^4.19.1",
111
- "turbogrid": "^3.2.0",
112
- "vine-ui": "^3.1.16",
113
- "ws": "^8.18.0"
114
- }
115
- }
1
+ {
2
+ "name": "monocart-coverage-reports",
3
+ "version": "2.11.1",
4
+ "description": "A code coverage tool to generate native V8 reports or Istanbul reports.",
5
+ "main": "./lib/index.js",
6
+ "bin": {
7
+ "mcr": "./lib/cli.js"
8
+ },
9
+ "exports": {
10
+ ".": {
11
+ "types": "./lib/index.d.ts",
12
+ "import": "./lib/index.mjs",
13
+ "require": "./lib/index.js"
14
+ },
15
+ "./register": {
16
+ "import": "./lib/register/register.mjs",
17
+ "require": "./lib/register/register.js"
18
+ },
19
+ "./converter": "./lib/converter/converter.js",
20
+ "./util": "./lib/utils/util.js",
21
+ "./package.json": "./package.json"
22
+ },
23
+ "types": "./lib/index.d.ts",
24
+ "scripts": {
25
+ "build-test": "node ./test/build/build-test.js",
26
+ "build": "npx sf lint && npx sf b -p && npm run build-test",
27
+ "test-unit": "mocha --parallel test/unit/*.test.js",
28
+ "test-node-env": "cross-env NODE_V8_COVERAGE=.temp/v8-coverage-env node ./test/test-node-env.js && node ./test/generate-report.js",
29
+ "test-node-api": "cross-env NODE_V8_COVERAGE=.temp/v8-coverage-api node ./test/test-node-api.js",
30
+ "test-node-ins": "node ./test/test-node-ins.js",
31
+ "test-node-cdp": "node --inspect=9229 ./test/test-node-cdp.js",
32
+ "test-node-vm": "node ./test/test-node-vm.js",
33
+ "test-node-koa": "node ./test/test-node-koa.js",
34
+ "test-node-fgc": "node ./test/test-node-fgc.js",
35
+ "test-node": "node ./test/test.js --node",
36
+ "test-istanbul": "node ./test/test-istanbul.js",
37
+ "test-v8": "node ./test/test-v8.js",
38
+ "test-puppeteer": "node ./test/test-puppeteer.js",
39
+ "test-anonymous": "node ./test/test-anonymous.js",
40
+ "test-css": "node ./test/test-css.js",
41
+ "test-minify": "node ./test/test-minify.js",
42
+ "test-esbuild": "node ./test/test-esbuild.js",
43
+ "test-rollup": "node ./test/test-rollup.js",
44
+ "test-sections": "node ./test/test-sections.js",
45
+ "test-swc": "node ./test/test-swc.js",
46
+ "test-v8-and-istanbul": "node ./test/test-v8-and-istanbul.js",
47
+ "test-browser": "node ./test/test.js --browser",
48
+ "test-cli": "npx mcr node ./test/specs/node.test.js -c test/mcr.config.cli.js",
49
+ "test-tsx": "npx mcr tsx ./test/specs/tsx.test.ts -c test/mcr.config.tsx.js",
50
+ "test-demo": "node ./test/test-demo.js",
51
+ "test-merge": "node ./test/test-merge.js",
52
+ "test-merge-istanbul": "node ./test/test-merge-istanbul.js",
53
+ "test-merge-v8": "node ./test/test-merge-v8.js",
54
+ "test-client": "node ./test/test-client.js",
55
+ "test-all": "node ./test/test.js",
56
+ "test-pr": "node --inspect=9230 ./test/test-pr.js",
57
+ "test": "npm run test-unit && npx mcr npm run test-all -c test/mcr.config.mcr.js && node ./scripts/docs.js",
58
+ "test:snap": "cross-env TEST_SNAPSHOT=true npm run test",
59
+ "dev": "npx sf d app",
60
+ "open": "node ./scripts/open.js",
61
+ "eol": "git rm -rf --cached . && git reset --hard HEAD",
62
+ "patch": "npm run build && npm run test && npx sf publish patch -r",
63
+ "beta": "npm version prerelease --preid=beta && npm run build && npm run test && npm publish --tag beta"
64
+ },
65
+ "workspaces": [
66
+ "test"
67
+ ],
68
+ "files": [
69
+ "lib",
70
+ "README.zh-Hans.md"
71
+ ],
72
+ "license": "MIT",
73
+ "repository": {
74
+ "type": "git",
75
+ "url": "git+https://github.com/cenfun/monocart-coverage-reports.git"
76
+ },
77
+ "dependencies": {
78
+ "acorn": "^8.12.1",
79
+ "acorn-loose": "^8.4.0",
80
+ "acorn-walk": "^8.3.4",
81
+ "commander": "^12.1.0",
82
+ "console-grid": "^2.2.2",
83
+ "eight-colors": "^1.3.1",
84
+ "foreground-child": "^3.3.0",
85
+ "istanbul-lib-coverage": "^3.2.2",
86
+ "istanbul-lib-report": "^3.0.1",
87
+ "istanbul-reports": "^3.1.7",
88
+ "lz-utils": "^2.1.0",
89
+ "monocart-locator": "^1.0.2"
90
+ },
91
+ "devDependencies": {
92
+ "@bcoe/v8-coverage": "^0.2.3",
93
+ "@jridgewell/sourcemap-codec": "^1.5.0",
94
+ "async-tick": "^1.0.0",
95
+ "convert-source-map": "^2.0.0",
96
+ "diff-sequences": "^29.6.3",
97
+ "esbuild": "^0.24.0",
98
+ "eslint": "~9.12.0",
99
+ "eslint-config-plus": "^2.0.2",
100
+ "eslint-plugin-html": "^8.1.2",
101
+ "eslint-plugin-vue": "^9.28.0",
102
+ "find-up": "^7.0.0",
103
+ "minimatch": "^9.0.5",
104
+ "monocart-code-viewer": "^1.1.4",
105
+ "monocart-formatter": "^3.0.0",
106
+ "node-stream-zip": "^1.15.0",
107
+ "postcss": "^8.4.47",
108
+ "starfall-cli": "^2.0.20",
109
+ "stylelint": "^16.9.0",
110
+ "stylelint-config-plus": "^1.1.3",
111
+ "supports-color": "^9.4.0",
112
+ "tsx": "^4.19.1",
113
+ "turbogrid": "^3.2.0",
114
+ "vine-ui": "^3.1.16",
115
+ "ws": "^8.18.0",
116
+ "yazl": "^2.5.1"
117
+ }
118
+ }