monocart-coverage-reports 2.13.2 → 3.0.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.
Files changed (68) hide show
  1. package/README.md +267 -114
  2. package/README.zh-Hans.md +268 -115
  3. package/lib/assets.js +6 -6
  4. package/lib/cli.js +191 -95
  5. package/lib/client/cdp-client.js +74 -43
  6. package/lib/client/coverage-client.js +24 -8
  7. package/lib/client/ws-session.js +115 -37
  8. package/lib/converter/ast-visitor.js +5 -7
  9. package/lib/converter/ast.js +6 -6
  10. package/lib/converter/collect-source-maps.js +9 -9
  11. package/lib/converter/converter.js +41 -115
  12. package/lib/converter/fake-source-coverage.js +64 -0
  13. package/lib/converter/find-original-range.js +3 -3
  14. package/lib/converter/flatten-source-maps.js +2 -4
  15. package/lib/converter/ignore.js +2 -4
  16. package/lib/converter/info-branch.js +5 -3
  17. package/lib/converter/info-function.js +5 -3
  18. package/lib/converter/info-statement.js +5 -3
  19. package/lib/converter/range-index.js +78 -0
  20. package/lib/converter/source-range-merge.js +103 -0
  21. package/lib/converter/untested.js +27 -55
  22. package/lib/default/options.js +13 -1
  23. package/lib/generate.js +44 -26
  24. package/lib/index.d.ts +52 -4
  25. package/lib/index.js +35 -41
  26. package/lib/istanbul/istanbul-summary.js +2 -2
  27. package/lib/istanbul/istanbul.js +35 -13
  28. package/lib/packages/chunks/chunk-RVOSNMVU.js +2 -0
  29. package/lib/packages/monocart-coverage-assets.js +4 -3
  30. package/lib/packages/monocart-coverage-converter.js +27 -0
  31. package/lib/packages/monocart-coverage-vendor.js +2 -41
  32. package/lib/packages/monocart-coverage-vendor.js.LICENSE +3 -221
  33. package/lib/platform/concurrency.js +47 -43
  34. package/lib/platform/share.js +1 -1
  35. package/lib/register/hooks.js +19 -13
  36. package/lib/register/register.js +5 -3
  37. package/lib/reports/codacy.js +3 -5
  38. package/lib/reports/codecov.js +3 -5
  39. package/lib/reports/console-details.js +5 -5
  40. package/lib/reports/console-summary.js +4 -4
  41. package/lib/reports/custom.js +8 -24
  42. package/lib/reports/markdown-details.js +4 -6
  43. package/lib/reports/markdown-summary.js +4 -6
  44. package/lib/reports/raw.js +10 -12
  45. package/lib/reports/v8-json.js +3 -5
  46. package/lib/reports/v8.js +3 -5
  47. package/lib/utils/dedupe.js +1 -1
  48. package/lib/utils/gc.js +30 -14
  49. package/lib/utils/markdown.js +2 -2
  50. package/lib/utils/merge/merge.js +2 -4
  51. package/lib/utils/merge/range-tree.js +1 -1
  52. package/lib/utils/request.js +85 -73
  53. package/lib/utils/snapshot.js +4 -4
  54. package/lib/utils/source-path.js +5 -5
  55. package/lib/utils/util.js +61 -41
  56. package/lib/v8/v8-summary.js +2 -4
  57. package/lib/v8/v8.js +11 -11
  58. package/migrate-to-3.md +175 -0
  59. package/package.json +153 -149
  60. package/skills/monocart-coverage-reports/SKILL.md +106 -0
  61. package/skills/monocart-coverage-reports/references/cli.md +108 -0
  62. package/skills/monocart-coverage-reports/references/collection.md +152 -0
  63. package/skills/monocart-coverage-reports/references/filtering-and-sourcemaps.md +170 -0
  64. package/skills/monocart-coverage-reports/references/reports-and-ci.md +219 -0
  65. package/skills/monocart-coverage-reports/references/repository-map.md +55 -0
  66. package/lib/index.mjs +0 -9
  67. package/lib/register/hooks.mjs +0 -3
  68. package/lib/register/register.mjs +0 -3
package/lib/index.js CHANGED
@@ -1,46 +1,41 @@
1
- const fs = require('fs');
2
- const path = require('path');
3
- const { pathToFileURL } = require('url');
4
- const EC = require('eight-colors');
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
+ import { pathToFileURL } from 'node:url';
4
+ import EC from 'eight-colors';
5
5
 
6
- const defaultOptions = require('./default/options.js');
7
- const Util = require('./utils/util.js');
6
+ import { defaultOptions } from './default/options.js';
7
+ import { Util } from './utils/util.js';
8
8
 
9
- const { initV8ListAndSourcemap } = require('./v8/v8.js');
10
- const {
9
+ import { initV8ListAndSourcemap } from './v8/v8.js';
10
+ import {
11
11
  getInputData, readFromDir, generateCoverageReports
12
- } = require('./generate.js');
13
- const { getSnapshot, diffSnapshot } = require('./utils/snapshot.js');
12
+ } from './generate.js';
13
+ import { getSnapshot, diffSnapshot } from './utils/snapshot.js';
14
14
 
15
- const WSSession = require('./client/ws-session.js');
16
- const CDPClient = require('./client/cdp-client.js');
15
+ import { WSSession } from './client/ws-session.js';
16
+ import { CDPClient } from './client/cdp-client.js';
17
+ import { CoverageClient } from './client/coverage-client.js';
17
18
 
18
19
  const resolveConfigOptions = async (configPath) => {
19
- // json format
20
- const ext = path.extname(configPath);
21
- if (ext === '.json' || configPath.slice(-2) === 'rc') {
22
- return JSON.parse(Util.readFileSync(configPath));
23
- }
24
-
25
- let configOptions;
26
- let err;
27
20
  try {
28
- configOptions = await import(pathToFileURL(configPath));
29
- } catch (ee) {
30
- err = ee;
31
- }
32
-
33
- if (err) {
34
- Util.logError(`ERROR: failed to load config "${configPath}": ${err && err.message} `);
35
- return;
36
- }
21
+ // json format
22
+ const ext = path.extname(configPath);
23
+ if (ext === '.json' || configPath.slice(-2) === 'rc') {
24
+ return JSON.parse(Util.readFileSync(configPath));
25
+ }
37
26
 
38
- // could be multiple level default
39
- while (configOptions && configOptions.default) {
40
- configOptions = configOptions.default;
27
+ let configOptions = await import(pathToFileURL(configPath));
28
+ // could be multiple level default
29
+ while (configOptions && configOptions.default) {
30
+ configOptions = configOptions.default;
31
+ }
32
+ return configOptions;
33
+ } catch (error) {
34
+ const message = error instanceof Error ? error.message : String(error);
35
+ throw new Error(`Failed to load config file "${configPath}": ${message}`, {
36
+ cause: error
37
+ });
41
38
  }
42
-
43
- return configOptions;
44
39
  };
45
40
 
46
41
  class CoverageReport {
@@ -237,7 +232,7 @@ class CoverageReport {
237
232
  const configPath = Util.findUpConfig(customConfigFile);
238
233
  if (!configPath) {
239
234
  if (customConfigFile) {
240
- Util.logError(`The config file does not exist: ${customConfigFile}`);
235
+ throw new Error(`The config file does not exist: ${customConfigFile}`);
241
236
  }
242
237
  // not found config
243
238
  return;
@@ -245,11 +240,7 @@ class CoverageReport {
245
240
 
246
241
  const configOptions = await resolveConfigOptions(configPath);
247
242
  if (!configOptions) {
248
- // failed to load config options
249
- if (customConfigFile) {
250
- Util.logError(`Failed to load config file: ${customConfigFile}`);
251
- }
252
- return;
243
+ throw new Error(`Failed to load config file: ${configPath}`);
253
244
  }
254
245
 
255
246
  Util.logInfo(`Loaded: ${EC.cyan(Util.relativePath(configPath))}`);
@@ -271,10 +262,13 @@ const MCR = function(options) {
271
262
  return new CoverageReport(options);
272
263
  };
273
264
  MCR.CoverageReport = CoverageReport;
265
+ MCR.CoverageClient = CoverageClient;
274
266
  MCR.getSnapshot = getSnapshot;
275
267
  MCR.diffSnapshot = diffSnapshot;
276
268
  MCR.WSSession = WSSession;
277
269
  MCR.CDPClient = CDPClient;
278
270
  MCR.Util = Util;
279
271
 
280
- module.exports = MCR;
272
+ export {
273
+ MCR as default, MCR, CoverageReport, CoverageClient, getSnapshot, diffSnapshot, WSSession, CDPClient, Util
274
+ };
@@ -1,4 +1,4 @@
1
- const istanbulLibReport = require('istanbul-lib-report');
1
+ import istanbulLibReport from 'istanbul-lib-report';
2
2
 
3
3
  const ReportBase = istanbulLibReport.ReportBase;
4
4
  class IstanbulSummary extends ReportBase {
@@ -70,4 +70,4 @@ class IstanbulSummary extends ReportBase {
70
70
  }
71
71
 
72
72
 
73
- module.exports = IstanbulSummary;
73
+ export { IstanbulSummary };
@@ -1,15 +1,15 @@
1
- const fs = require('fs');
2
- const path = require('path');
3
- const istanbulReports = require('istanbul-reports');
4
- const istanbulLibCoverage = require('istanbul-lib-coverage');
5
- const istanbulLibReport = require('istanbul-lib-report');
6
- const EC = require('eight-colors');
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
+ import { pathToFileURL } from 'node:url';
4
+ import istanbulLibCoverage from 'istanbul-lib-coverage';
5
+ import istanbulLibReport from 'istanbul-lib-report';
6
+ import EC from 'eight-colors';
7
7
 
8
- const Util = require('../utils/util.js');
9
- const IstanbulSummary = require('./istanbul-summary.js');
8
+ import { Util } from '../utils/util.js';
9
+ import { IstanbulSummary } from './istanbul-summary.js';
10
10
 
11
- const { initIstanbulSourcePath } = require('../utils/source-path.js');
12
- const { getUntestedList } = require('../converter/untested.js');
11
+ import { initIstanbulSourcePath } from '../utils/source-path.js';
12
+ import { getUntestedList } from '../converter/untested.js';
13
13
 
14
14
  const findHtmlPath = (outputDir) => {
15
15
  const defaultHtml = path.resolve(outputDir, 'index.html');
@@ -35,7 +35,29 @@ const findHtmlPath = (outputDir) => {
35
35
 
36
36
  };
37
37
 
38
- const saveIstanbulReports = (coverageData, fileSources, options) => {
38
+ const createIstanbulReport = async (name, options) => {
39
+ let reporter;
40
+ const isFile = path.isAbsolute(name) || name.startsWith('.');
41
+ // Built-in reports remain CommonJS dependencies; custom reports may be ESM.
42
+ if (!isFile) {
43
+ try {
44
+ reporter = await import(`istanbul-reports/lib/${name}/index.js`);
45
+ } catch (error) {
46
+ if (error.code !== 'ERR_MODULE_NOT_FOUND') {
47
+ throw error;
48
+ }
49
+ }
50
+ }
51
+ if (!reporter) {
52
+ // Native import() also handles CJS reporters without a separate loader.
53
+ const specifier = isFile ? pathToFileURL(path.resolve(name)).href : name;
54
+ reporter = await import(specifier);
55
+ }
56
+ const Reporter = reporter.default || reporter;
57
+ return new Reporter(options);
58
+ };
59
+
60
+ const saveIstanbulReports = async (coverageData, fileSources, options) => {
39
61
 
40
62
  coverageData = initIstanbulSourcePath(coverageData, fileSources, options);
41
63
 
@@ -96,7 +118,7 @@ const saveIstanbulReports = (coverageData, fileSources, options) => {
96
118
  if (istanbulGroup) {
97
119
  for (const [reportName, reportOptions] of istanbulGroup) {
98
120
  const t1 = Date.now();
99
- const report = istanbulReports.create(reportName, reportOptions);
121
+ const report = await createIstanbulReport(reportName, reportOptions);
100
122
  report.execute(context);
101
123
  Util.logTime(`${EC.magenta('├')} [generate] saved report: ${reportName}`, t1);
102
124
  }
@@ -163,7 +185,7 @@ const mergeIstanbulCoverage = async (dataList, options) => {
163
185
  return istanbulData;
164
186
  };
165
187
 
166
- module.exports = {
188
+ export {
167
189
  saveIstanbulReports,
168
190
  mergeIstanbulDataList,
169
191
  mergeIstanbulCoverage
@@ -0,0 +1,2 @@
1
+ import { createRequire } from 'node:module'; const require = createRequire(import.meta.url);
2
+ var g=Object.create;var f=Object.defineProperty;var h=Object.getOwnPropertyDescriptor;var i=Object.getOwnPropertyNames;var j=Object.getPrototypeOf,k=Object.prototype.hasOwnProperty;var m=(a=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(a,{get:(b,c)=>(typeof require<"u"?require:b)[c]}):a)(function(a){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+a+'" is not supported')});var n=(a,b)=>()=>{try{return b||a((b={exports:{}}).exports,b),b.exports}catch(c){throw b=0,c}};var l=(a,b,c,e)=>{if(b&&typeof b=="object"||typeof b=="function")for(let d of i(b))!k.call(a,d)&&d!==c&&f(a,d,{get:()=>b[d],enumerable:!(e=h(b,d))||e.enumerable});return a};var o=(a,b,c)=>(c=a!=null?g(j(a)):{},l(b||!a||!a.__esModule?f(c,"default",{value:a,enumerable:!0}):c,a));export{m as a,n as b,o as c};