monocart-coverage-reports 2.7.0 → 2.7.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/README.md CHANGED
@@ -324,9 +324,10 @@ Options:
324
324
  - `mcr.config.json` - json format
325
325
  - `.mcrrc.js`
326
326
  - `.mcrrc` - json format
327
- - `mcr.config.ts` - it requires `NODE_OPTIONS="--loader ts-node/esm"`
327
+ - `mcr.config.ts`
328
328
 
329
329
  - Working with `ts-node`, see [mcr-ts-node](https://github.com/cenfun/mcr-ts-node)
330
+ - Working with `tsx`, see [mcr-tsx](https://github.com/cenfun/mcr-tsx)
330
331
 
331
332
  ## Compare Reports
332
333
  | | Istanbul | V8 | V8 to Istanbul |
@@ -54,22 +54,37 @@ const getSourceMapUrl = (content, url) => {
54
54
  }
55
55
  };
56
56
 
57
- const resolveSourcesContent = (sources, url) => {
58
- const list = [];
59
- for (const file of sources) {
57
+ const resolveSourcesContent = (data, url) => {
58
+
59
+ const { sources, sourcesContent } = data;
60
+
61
+ let failed = false;
62
+ sources.forEach((file, i) => {
63
+ if (typeof sourcesContent[i] === 'string') {
64
+ return;
65
+ }
66
+
60
67
  const sourceUrl = Util.resolveUrl(file, url);
61
68
  if (sourceUrl) {
62
- const sourcePath = sourceUrl.toString();
69
+ let sourcePath = sourceUrl.toString();
70
+ // could be no `file:`
63
71
  if (sourcePath.startsWith('file:')) {
64
- const content = Util.readFileSync(path.resolve(fileURLToPath(sourcePath)));
65
- list.push(content);
66
- continue;
72
+ sourcePath = fileURLToPath(sourcePath);
73
+ }
74
+ const content = Util.readFileSync(path.resolve(sourcePath));
75
+ if (typeof content === 'string') {
76
+ sourcesContent[i] = content;
77
+ return;
67
78
  }
68
79
  }
80
+
69
81
  Util.logDebug(EC.red(`failed to load source content ${file}`));
70
- }
71
- if (list.length === sources.length) {
72
- return list;
82
+ failed = true;
83
+ });
84
+
85
+
86
+ if (!failed) {
87
+ return data;
73
88
  }
74
89
  };
75
90
 
@@ -85,17 +100,19 @@ const resolveSourceMap = (data, url) => {
85
100
  return;
86
101
  }
87
102
 
88
- // exists sources content
89
- if (sourcesContent && sourcesContent.length === sources.length) {
90
- return data;
103
+ // check sources content
104
+ if (sourcesContent) {
105
+ // all should be string, could be [null]
106
+ const contents = sourcesContent.filter((content) => typeof content === 'string');
107
+ if (contents.length === sources.length) {
108
+ return data;
109
+ }
110
+ } else {
111
+ data.sourcesContent = [];
91
112
  }
92
113
 
93
114
  // load sources content by sources
94
- const contents = resolveSourcesContent(sources, url);
95
- if (contents) {
96
- data.sourcesContent = contents;
97
- return data;
98
- }
115
+ return resolveSourcesContent(data, url);
99
116
 
100
117
  };
101
118
 
@@ -1069,12 +1069,12 @@ const generateCoverageForDist = (state) => {
1069
1069
 
1070
1070
  const unpackSourceMap = (state, options) => {
1071
1071
 
1072
- const { sourceMap } = state;
1072
+ const { sourceMap, sourcePath } = state;
1073
1073
 
1074
1074
  // keep original urls
1075
1075
  const fileUrls = {};
1076
1076
  const sourcePathHandler = getSourcePathHandler(options);
1077
- initSourceMapSourcePath(sourceMap, fileUrls, sourcePathHandler);
1077
+ initSourceMapSourcePath(sourceMap, fileUrls, sourcePath, sourcePathHandler);
1078
1078
  state.fileUrls = fileUrls;
1079
1079
 
1080
1080
  // ===============================================
package/lib/index.d.ts CHANGED
@@ -255,7 +255,7 @@ declare namespace MCR {
255
255
  *
256
256
  * {object} Replace key with value.
257
257
  * */
258
- sourcePath?: ((filePath: string) => string) | {
258
+ sourcePath?: ((filePath: string, info: any) => string) | {
259
259
  [key: string]: string;
260
260
  };
261
261
 
@@ -119,7 +119,7 @@ const initIstanbulSourcePath = (coverageData, fileSources, sourcePathHandler) =>
119
119
  }
120
120
 
121
121
  // new source path, second is source url
122
- const newSourcePath = sourcePathHandler(sourcePath, '');
122
+ const newSourcePath = sourcePathHandler(sourcePath, item);
123
123
  if (typeof newSourcePath === 'string' && newSourcePath) {
124
124
  sourcePath = newSourcePath;
125
125
  }
@@ -148,7 +148,7 @@ const mergeSourceRoot = (sourceRoot, sourceName) => {
148
148
  return sourceRoot + sourceName;
149
149
  };
150
150
 
151
- const initSourceMapSourcePath = (sourceMap, fileUrls, sourcePathHandler) => {
151
+ const initSourceMapSourcePath = (sourceMap, fileUrls, distFile, sourcePathHandler) => {
152
152
  // reset sourceRoot
153
153
  const sourceRoot = sourceMap.sourceRoot || '';
154
154
  sourceMap.sourceRoot = '';
@@ -165,7 +165,11 @@ const initSourceMapSourcePath = (sourceMap, fileUrls, sourcePathHandler) => {
165
165
 
166
166
  let sourcePath = getSourcePath(sourceUrl, i + 1);
167
167
  if (sourcePathHandler) {
168
- const newSourcePath = sourcePathHandler(sourcePath, sourceUrl);
168
+ // sourcePath could be a filename only, may using distFile to get full path
169
+ const newSourcePath = sourcePathHandler(sourcePath, {
170
+ url: sourceUrl,
171
+ distFile
172
+ });
169
173
  if (typeof newSourcePath === 'string' && newSourcePath) {
170
174
  sourcePath = newSourcePath;
171
175
  }
package/lib/v8/v8.js CHANGED
@@ -144,7 +144,7 @@ const initV8ListAndSourcemap = async (v8list, options) => {
144
144
  // resolve source path
145
145
  let sourcePath = getSourcePath(data.url, i + 1, data.type);
146
146
  if (sourcePathHandler) {
147
- const newSourcePath = sourcePathHandler(sourcePath, data.url);
147
+ const newSourcePath = sourcePathHandler(sourcePath, data);
148
148
  if (typeof newSourcePath === 'string' && newSourcePath) {
149
149
  sourcePath = newSourcePath;
150
150
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "monocart-coverage-reports",
3
- "version": "2.7.0",
3
+ "version": "2.7.1",
4
4
  "description": "Code coverage tool to generate native V8 reports or Istanbul reports.",
5
5
  "main": "./lib/index.js",
6
6
  "bin": {
@@ -58,22 +58,22 @@
58
58
  "url": "git+https://github.com/cenfun/monocart-coverage-reports.git"
59
59
  },
60
60
  "dependencies": {
61
- "console-grid": "~2.2.2",
62
- "eight-colors": "~1.3.0",
63
- "istanbul-lib-coverage": "~3.2.2",
64
- "istanbul-lib-report": "~3.0.1",
65
- "istanbul-reports": "~3.1.7",
66
- "lz-utils": "~2.0.2",
67
- "monocart-code-viewer": "~1.1.2",
68
- "monocart-formatter": "~2.3.2",
69
- "turbogrid": "~3.0.13"
61
+ "console-grid": "^2.2.2",
62
+ "eight-colors": "^1.3.0",
63
+ "istanbul-lib-coverage": "^3.2.2",
64
+ "istanbul-lib-report": "^3.0.1",
65
+ "istanbul-reports": "^3.1.7",
66
+ "lz-utils": "^2.0.2",
67
+ "monocart-code-viewer": "^1.1.2",
68
+ "monocart-formatter": "^2.3.2",
69
+ "turbogrid": "^3.0.13"
70
70
  },
71
71
  "devDependencies": {
72
72
  "commander": "^12.0.0",
73
73
  "eslint": "^8.57.0",
74
74
  "eslint-config-plus": "^1.0.6",
75
75
  "eslint-plugin-html": "^8.0.0",
76
- "eslint-plugin-vue": "^9.22.0",
76
+ "eslint-plugin-vue": "^9.23.0",
77
77
  "minimatch": "^9.0.3",
78
78
  "stylelint": "^16.2.1",
79
79
  "stylelint-config-plus": "^1.1.0",