monocart-reporter 1.7.13 → 2.0.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.
Files changed (42) hide show
  1. package/README.md +10 -26
  2. package/lib/generate-data.js +7 -19
  3. package/lib/generate-report.js +13 -6
  4. package/lib/index.d.ts +82 -53
  5. package/lib/index.js +1 -4
  6. package/lib/index.mjs +0 -1
  7. package/lib/packages/monocart-common.js +1 -0
  8. package/lib/packages/monocart-network.js +1 -0
  9. package/lib/packages/monocart-reporter.js +1 -0
  10. package/lib/packages/monocart-vendor.js +22 -0
  11. package/lib/platform/share.js +0 -5
  12. package/lib/plugins/audit/audit.js +2 -2
  13. package/lib/plugins/coverage/coverage.js +77 -256
  14. package/lib/plugins/network/network.js +17 -13
  15. package/lib/plugins/state/client.js +1 -1
  16. package/lib/plugins/state/state.js +1 -1
  17. package/lib/utils/parse-source.js +1 -1
  18. package/lib/utils/util.js +25 -38
  19. package/lib/visitor.js +6 -26
  20. package/package.json +10 -8
  21. package/lib/plugins/coverage/converter/collect-source-maps.js +0 -194
  22. package/lib/plugins/coverage/converter/converter.js +0 -565
  23. package/lib/plugins/coverage/converter/dedupe.js +0 -110
  24. package/lib/plugins/coverage/converter/find-original-range.js +0 -581
  25. package/lib/plugins/coverage/converter/info-branch.js +0 -30
  26. package/lib/plugins/coverage/converter/info-function.js +0 -29
  27. package/lib/plugins/coverage/converter/info-line.js +0 -20
  28. package/lib/plugins/coverage/converter/position-mapping.js +0 -183
  29. package/lib/plugins/coverage/converter/source-path.js +0 -140
  30. package/lib/plugins/coverage/istanbul/istanbul-summary.js +0 -49
  31. package/lib/plugins/coverage/istanbul/istanbul.js +0 -171
  32. package/lib/plugins/coverage/v8/v8-summary.js +0 -80
  33. package/lib/plugins/coverage/v8/v8.js +0 -260
  34. package/lib/runtime/monocart-code-viewer.js +0 -1
  35. package/lib/runtime/monocart-common.js +0 -1
  36. package/lib/runtime/monocart-coverage.js +0 -14
  37. package/lib/runtime/monocart-formatter.js +0 -1
  38. package/lib/runtime/monocart-network.js +0 -1
  39. package/lib/runtime/monocart-reporter.js +0 -1
  40. package/lib/runtime/monocart-v8.js +0 -1
  41. package/lib/runtime/monocart-vendor.js +0 -22
  42. package/lib/utils/decode-mappings.js +0 -49
@@ -1,581 +0,0 @@
1
-
2
- const findMapping = (list, offset) => {
3
- let start = 0;
4
- let end = list.length - 1;
5
- while (end - start > 1) {
6
- const i = Math.floor((start + end) * 0.5);
7
- const item = list[i];
8
- if (offset < item.generatedOffset) {
9
- end = i;
10
- continue;
11
- }
12
- if (offset > item.generatedOffset) {
13
- start = i;
14
- continue;
15
- }
16
- return list[i];
17
- }
18
- // last two items, less is start
19
- const endItem = list[end];
20
- if (offset < endItem.generatedOffset) {
21
- return list[start];
22
- }
23
- return list[end];
24
-
25
- };
26
-
27
- const findOffsetMapping = (generatedState, offset) => {
28
-
29
- const decodedMappings = generatedState.decodedMappings;
30
-
31
- // possible no length
32
- if (!decodedMappings.length) {
33
- return;
34
- }
35
-
36
- const mapping = findMapping(decodedMappings, offset);
37
-
38
- const generatedOffset = mapping.generatedOffset;
39
-
40
- // not found, allow > last, not allow < first
41
- if (offset < generatedOffset) {
42
- return;
43
- }
44
-
45
- // exact matched no need fix
46
- const exact = generatedOffset === offset;
47
-
48
- return {
49
- ... mapping,
50
- // could be fixed if not exact matched
51
- column: mapping.originalColumn,
52
- exact
53
- };
54
- };
55
-
56
- const findNextOriginalDiffMapping = (originalState, mapping) => {
57
- const decodedMappings = originalState.decodedMappings;
58
- const { originalIndex, originalOffset } = mapping;
59
-
60
- let i = originalIndex + 1;
61
- const l = decodedMappings.length;
62
- while (i < l) {
63
- const item = decodedMappings[i];
64
- // sometimes next is same line/column
65
- if (item.originalOffset > originalOffset) {
66
- return item;
67
- }
68
- i += 1;
69
- }
70
- };
71
-
72
- const findNextGeneratedDiffMapping = (generatedState, mapping) => {
73
- const decodedMappings = generatedState.decodedMappings;
74
- const i = mapping.generatedIndex + 1;
75
- const l = decodedMappings.length;
76
- if (i < l) {
77
- return decodedMappings[i];
78
- }
79
- };
80
-
81
- const getGeneratedText = (mapping, generatedState) => {
82
-
83
- const generatedText = mapping.generatedText;
84
- if (typeof generatedText === 'string') {
85
- return generatedText;
86
- }
87
-
88
- let text = '';
89
-
90
- const { positionMapping } = generatedState;
91
- const nextMapping = findNextGeneratedDiffMapping(generatedState, mapping);
92
- if (nextMapping) {
93
- text = positionMapping.getSlice(mapping.generatedOffset, nextMapping.generatedOffset);
94
- } else {
95
- // to the end
96
- text = positionMapping.getSlice(mapping.generatedOffset);
97
- }
98
-
99
- // never cross line
100
- if (mapping.generatedEndOffset) {
101
- const len = mapping.generatedEndOffset - mapping.generatedOffset;
102
- text = text.slice(0, len);
103
- }
104
-
105
- // keep cache
106
- mapping.generatedText = text;
107
-
108
- return text;
109
-
110
- };
111
-
112
- const getOriginalText = (mapping, originalState) => {
113
-
114
- const originalText = mapping.originalText;
115
- if (typeof originalText === 'string') {
116
- return originalText;
117
- }
118
-
119
- let text = '';
120
-
121
- const { positionMapping } = originalState;
122
- const nextMapping = findNextOriginalDiffMapping(originalState, mapping);
123
- if (nextMapping) {
124
- text = positionMapping.getSlice(mapping.originalOffset, nextMapping.originalOffset);
125
- } else {
126
- // to the end
127
- text = positionMapping.getSlice(mapping.originalOffset);
128
- }
129
-
130
- // the last two items could have same line and column
131
- // so can NOT pre-calculate original end offset, just search new line with regex
132
-
133
- // never cross line
134
- const newLineIndex = text.search(/\r?\n/);
135
- if (newLineIndex !== -1) {
136
- text = text.slice(0, newLineIndex);
137
- }
138
-
139
- // keep cache
140
- mapping.originalText = text;
141
-
142
- return text;
143
- };
144
-
145
- // ========================================================================================================
146
-
147
- const getBlockStartPosition = (originalText) => {
148
- // start block characters
149
-
150
- // originalText: 'argument) {',
151
- // generatedLeft: 'o',
152
- // generatedRight: '&&'
153
-
154
- // function/block could be started with {(
155
- const startBlockIndex = originalText.search(/[<{(]/);
156
- if (startBlockIndex !== -1) {
157
- return startBlockIndex;
158
- }
159
-
160
- // end a block
161
- const list = ['>', '}', ')'];
162
- for (const s of list) {
163
- const endBlockIndex = originalText.lastIndexOf(s);
164
- if (endBlockIndex !== -1) {
165
- return endBlockIndex + 1;
166
- }
167
- }
168
-
169
- return -1;
170
- };
171
-
172
- const getBlockEndPosition = (originalText) => {
173
- // generatedText: 'e),',
174
- // generatedPos: 2,
175
- // originalText: 'prop))'
176
-
177
- // generatedText: ' = false)',
178
- // generatedPos: 8,
179
- // originalText: '=false"'
180
-
181
- // generatedText: '), 1 /* TEXT */)])])) : (0,vue__...)("v-if", true)], 6 /* CLASS, STYLE */);',
182
- // generatedPos: 17,
183
- // originalText: ' }}</slot>'
184
-
185
- const list = ['>', '}', ')'];
186
- for (const s of list) {
187
- const endBlockIndex = originalText.lastIndexOf(s);
188
- if (endBlockIndex !== -1) {
189
- return endBlockIndex + 1;
190
- }
191
- }
192
-
193
- const startBlockIndex = originalText.search(/[<{(]/);
194
- if (startBlockIndex !== -1) {
195
- return startBlockIndex;
196
- }
197
-
198
- return -1;
199
- };
200
-
201
- const getOriginalStartPosition = (originalText, generatedText, generatedPos) => {
202
-
203
- if (!originalText.length) {
204
- return 0;
205
- }
206
-
207
- if (originalText === generatedText) {
208
- return generatedPos;
209
- }
210
-
211
- // ============================
212
- // left matched
213
-
214
- // originalText: '1;',
215
- // generatedText: '1;else',
216
- // generatedLeft: '1;'
217
-
218
- const generatedLeft = generatedText.slice(0, generatedPos);
219
- if (originalText.startsWith(generatedLeft)) {
220
- return generatedLeft.length;
221
- }
222
-
223
- // ============================
224
- // no case for right
225
- // const generatedRight = generatedText.slice(generatedPos);
226
- // if (originalText.endsWith(generatedRight)) {
227
- // return originalText.length - generatedRight.length;
228
- // }
229
-
230
- // ============================
231
- // starts with original text (few case possible useless)
232
-
233
- // generatedText "(void 0, void 0, void 0, function* () {"
234
- // originalText " {"
235
-
236
- // generatedLen: 1629,
237
- // generatedText: '__exports__);\r\n\r\n/***/ }),\r\n\r\n/***/ "./packages/v8',
238
- // generatedPos: 489,
239
- // originalText: '__exports__',
240
-
241
- // original less, generated more
242
- // const includeIndex = generatedText.indexOf(originalText);
243
- // if (includeIndex !== -1) {
244
-
245
- // console.log('=================== includeIndex', includeIndex, generatedPos);
246
- // console.log(JSON.stringify(generatedText.slice(0, originalText.length + includeIndex + 10)));
247
- // console.log(JSON.stringify(originalText));
248
-
249
- // if (includeIndex >= generatedPos) {
250
- // return 0;
251
- // }
252
-
253
- // return originalText.length;
254
- // }
255
-
256
- // ============================
257
- // {} () <>
258
- const blockIndex = getBlockStartPosition(originalText);
259
- if (blockIndex !== -1) {
260
- return blockIndex;
261
- }
262
-
263
- // ============================
264
- // end characters
265
-
266
- // ends with ">" in vue
267
- // <span v-if="data.distFile">
268
-
269
- // originalText: '">',
270
- // generatedText: ' ? ((0,vue__.openBlock)(), '
271
-
272
- // originalMethod?.apply
273
- // originalText: '?.' no ?
274
-
275
- const indexEndBlock = originalText.search(/(?<=[;,:"'\s])/);
276
- if (indexEndBlock !== -1) {
277
- return indexEndBlock;
278
- }
279
-
280
- // console.log('====================================================================');
281
- // console.log('start position can NOT be fixed');
282
- // console.log({
283
- // generatedText,
284
- // generatedPos,
285
- // originalText
286
- // // originalPos
287
- // });
288
-
289
- // ============================
290
- // can NOT be fixed
291
- // using original column
292
- return 0;
293
- };
294
-
295
- const getOriginalEndPosition = (originalText, generatedText, generatedPos) => {
296
-
297
- if (!originalText.length) {
298
- return 0;
299
- }
300
-
301
- if (originalText === generatedText) {
302
- return generatedPos;
303
- }
304
-
305
- // ============================
306
- // {} () <>
307
- const blockIndex = getBlockEndPosition(originalText);
308
- if (blockIndex !== -1) {
309
- return blockIndex;
310
- }
311
-
312
- // console.log('====================================================================');
313
- // console.log('end position can NOT be fixed');
314
- // console.log({
315
- // generatedText,
316
- // generatedPos,
317
- // originalText
318
- // // originalPos
319
- // });
320
-
321
- // ============================
322
- // can NOT be fixed
323
- // to the line end
324
- return originalText.length;
325
- };
326
-
327
- // ========================================================================================================
328
-
329
- const fixStartColumn = (startMapping, range, generatedState, originalState) => {
330
- // exact matched no need fix
331
- if (startMapping.exact) {
332
- // originalColumn is the column
333
- return;
334
- }
335
-
336
- // fix column
337
- const originalColumn = startMapping.originalColumn;
338
-
339
- const originalText = getOriginalText(startMapping, originalState);
340
- const generatedText = getGeneratedText(startMapping, generatedState);
341
-
342
- // actual generatedOffset < range startOffset
343
- const generatedPos = range.startOffset - startMapping.generatedOffset;
344
-
345
- const originalPos = getOriginalStartPosition(originalText, generatedText, generatedPos);
346
-
347
- // if (originalState.sourcePath.endsWith('src/components/report.vue') && range.count === 0) {
348
- // console.log('====================================================================');
349
- // console.log('fix startMapping', originalState.sourcePath);
350
- // console.log(startMapping);
351
- // console.log({
352
- // generatedPos,
353
- // originalPos
354
- // });
355
- // }
356
-
357
- // failed if originalPos = 0
358
- startMapping.column = originalColumn + originalPos;
359
-
360
- };
361
-
362
- // ========================================================================================================
363
-
364
- const fixEndColumn = (endMapping, range, startMapping, generatedState, originalState) => {
365
-
366
- const originalColumn = endMapping.originalColumn;
367
-
368
- // exact matched, but already -1 so need +1
369
- if (endMapping.exact) {
370
- endMapping.column = originalColumn + 1;
371
- return;
372
- }
373
-
374
- // ================================
375
- // diff line, to the line end
376
- if (endMapping.originalLine !== startMapping.originalLine) {
377
- endMapping.column = Infinity;
378
- return;
379
- }
380
-
381
- // ================================
382
- // in the same line
383
-
384
- const originalText = getOriginalText(endMapping, originalState);
385
-
386
- // exclusive, need exclude some end strings
387
- if (!endMapping.exclusive) {
388
- endMapping.column = originalColumn + originalText.length;
389
- return;
390
- }
391
-
392
-
393
- const generatedText = getGeneratedText(endMapping, generatedState);
394
-
395
- // actual generatedOffset < range endOffset
396
- const generatedPos = range.endOffset - endMapping.generatedOffset;
397
-
398
- const originalPos = getOriginalEndPosition(originalText, generatedText, generatedPos);
399
-
400
- // if (originalState.sourcePath.endsWith('v8/src/app.vue') && range.count === 0) {
401
- // console.log('====================================================================');
402
- // console.log('fix endMapping', originalState.sourcePath);
403
- // console.log(startMapping, endMapping);
404
- // const generatedLen = generatedText.length;
405
- // const gt = generatedLen > 50 ? generatedText.slice(0, 50) : generatedText;
406
- // console.log({
407
- // generatedLen,
408
- // generatedText: gt,
409
- // generatedPos,
410
- // originalText,
411
- // originalPos
412
- // });
413
- // }
414
-
415
- // failed if originalPos = 0
416
- endMapping.column = originalColumn + originalPos;
417
-
418
- };
419
-
420
- // ========================================================================================================
421
-
422
- const isOffsetCrossLine = (startMapping, offset) => {
423
- const { exact, generatedEndOffset } = startMapping;
424
- if (!exact && generatedEndOffset) {
425
- if (offset >= generatedEndOffset) {
426
- return true;
427
- }
428
- }
429
- return false;
430
- };
431
-
432
- const findStartMapping = (range, generatedState, originalMap) => {
433
-
434
- // startOffset: inclusive
435
- const startOffset = range.startOffset;
436
-
437
- const startMapping = findOffsetMapping(generatedState, startOffset);
438
- if (!startMapping) {
439
- return;
440
- }
441
-
442
- // check end offset for start mapping only
443
- // start mapping is inclusive, do not allow cross line
444
- // but end mapping is exclusive and offset do -1, possible no mapping found, do not check it
445
- if (isOffsetCrossLine(startMapping, startOffset)) {
446
- // try next mapping if its offset in the range
447
- const nextMapping = findNextGeneratedDiffMapping(generatedState, startMapping);
448
- if (!nextMapping) {
449
- return;
450
- }
451
-
452
- // ignore out of range
453
- if (nextMapping.generatedOffset >= range.endOffset) {
454
- return;
455
- }
456
-
457
- // if (startMapping.sourceIndex === 1 && range.count === 0) {
458
- // console.log('=========================================================');
459
- // console.log('find next start');
460
- // console.log(startMapping, nextMapping, range);
461
- // }
462
-
463
- // exact and column
464
- Object.assign(startMapping, nextMapping, {
465
- exact: true,
466
- column: nextMapping.originalColumn
467
- });
468
-
469
- }
470
-
471
-
472
- // check source first, sourceIndex could be undefined
473
- const sourceIndex = startMapping.sourceIndex;
474
-
475
- const originalState = originalMap.get(sourceIndex);
476
- if (!originalState) {
477
- return;
478
- }
479
-
480
- return {
481
- startMapping,
482
- originalState
483
- };
484
- };
485
-
486
-
487
- const findEndMapping = (range, generatedState, startMapping) => {
488
-
489
- // endOffset: exclusive
490
- const endOffset = range.endOffset;
491
-
492
- // there could be some comments before end mapping even exact matched
493
- const endMapping = findOffsetMapping(generatedState, endOffset - 1);
494
- if (!endMapping) {
495
- return;
496
- }
497
-
498
- // cross file ignore
499
- if (endMapping.sourceIndex !== startMapping.sourceIndex) {
500
- return;
501
- }
502
-
503
- // still exclusive
504
- const exclusiveMapping = findOffsetMapping(generatedState, endOffset);
505
- if (exclusiveMapping && exclusiveMapping.originalOffset === endMapping.originalOffset) {
506
- endMapping.exclusive = true;
507
- }
508
-
509
- return endMapping;
510
- };
511
-
512
- const findOriginalRange = (range, generatedState, originalMap) => {
513
-
514
- // startOffset: inclusive
515
- // endOffset: exclusive
516
-
517
- const startResult = findStartMapping(range, generatedState, originalMap);
518
- if (!startResult) {
519
- return;
520
- }
521
- const { startMapping, originalState } = startResult;
522
-
523
- // ==================================================================================
524
- // if (originalState.sourcePath.endsWith('app/app.module.ts')) {
525
- // originalState.showLog = true;
526
- // console.log('============================================================');
527
- // console.log(originalState.sourcePath);
528
- // console.log(range);
529
- // } else {
530
- // originalState.showLog = false;
531
- // }
532
- // ==================================================================================
533
-
534
- const endMapping = findEndMapping(range, generatedState, startMapping);
535
- if (!endMapping) {
536
- return;
537
- }
538
-
539
- // fix start
540
- fixStartColumn(startMapping, range, generatedState, originalState);
541
-
542
- // fix end
543
- fixEndColumn(endMapping, range, startMapping, generatedState, originalState);
544
-
545
- const positionMapping = originalState.positionMapping;
546
- const originalStart = positionMapping.locationToOffset({
547
- line: startMapping.originalLine + 1,
548
- column: startMapping.column
549
- });
550
- const originalEnd = positionMapping.locationToOffset({
551
- line: endMapping.originalLine + 1,
552
- column: endMapping.column
553
- });
554
-
555
- // range start greater than end
556
- if (originalStart >= originalEnd) {
557
- // console.log(`start >= end: ${originalState.sourcePath}`);
558
- // console.log(range, originalRange);
559
- return;
560
- }
561
-
562
- const originalRange = {
563
- startOffset: originalStart,
564
- endOffset: originalEnd,
565
- count: range.count
566
- };
567
-
568
- // if (originalState.showLog) {
569
- // console.log('startMapping and endMapping:');
570
- // console.log(startMapping, endMapping);
571
- // console.log(originalStart, originalEnd);
572
- // }
573
-
574
- return {
575
- originalRange,
576
- originalState
577
- };
578
-
579
- };
580
-
581
- module.exports = findOriginalRange;
@@ -1,30 +0,0 @@
1
- module.exports = class InfoBranch {
2
- constructor(sLoc, eLoc, count) {
3
- this.startLine = sLoc.line;
4
- this.startColumn = sLoc.column;
5
- this.endLine = eLoc.line;
6
- this.endColumn = eLoc.column;
7
- this.count = count;
8
- }
9
-
10
- generate() {
11
- const location = {
12
- start: {
13
- line: this.startLine,
14
- column: this.startColumn
15
- },
16
- end: {
17
- line: this.endLine,
18
- column: this.endColumn
19
- }
20
- };
21
- return {
22
- type: 'branch',
23
- line: this.startLine,
24
- loc: location,
25
- locations: [{
26
- ... location
27
- }]
28
- };
29
- }
30
- };
@@ -1,29 +0,0 @@
1
- module.exports = class InfoFunction {
2
- constructor(sLoc, eLoc, count, name) {
3
- this.startLine = sLoc.line;
4
- this.startColumn = sLoc.column;
5
- this.endLine = eLoc.line;
6
- this.endColumn = eLoc.column;
7
- this.count = count;
8
- this.name = name || '(anonymous)';
9
- }
10
-
11
- generate() {
12
- const loc = {
13
- start: {
14
- line: this.startLine,
15
- column: this.startColumn
16
- },
17
- end: {
18
- line: this.endLine,
19
- column: this.endColumn
20
- }
21
- };
22
- return {
23
- name: this.name,
24
- decl: loc,
25
- loc: loc,
26
- line: this.startLine
27
- };
28
- }
29
- };
@@ -1,20 +0,0 @@
1
- module.exports = class InfoLine {
2
- constructor(line, column, count = 1) {
3
- this.line = line;
4
- this.column = column;
5
- this.count = count;
6
- }
7
-
8
- generate() {
9
- return {
10
- start: {
11
- line: this.line,
12
- column: 0
13
- },
14
- end: {
15
- line: this.line,
16
- column: this.column
17
- }
18
- };
19
- }
20
- };