vitest 0.0.98 → 0.0.99

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.
@@ -1,1416 +0,0 @@
1
- import { existsSync, promises } from 'fs';
2
- import { format } from 'util';
3
- import { r as relative } from './index-1488b423.js';
4
- import { d as notNullish, c } from './utils-70b78878.js';
5
- import { SourceMapConsumer } from 'source-map';
6
-
7
- function Diff() {}
8
- Diff.prototype = {
9
- diff: function diff(oldString, newString) {
10
- var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
11
- var callback = options.callback;
12
-
13
- if (typeof options === 'function') {
14
- callback = options;
15
- options = {};
16
- }
17
-
18
- this.options = options;
19
- var self = this;
20
-
21
- function done(value) {
22
- if (callback) {
23
- setTimeout(function () {
24
- callback(undefined, value);
25
- }, 0);
26
- return true;
27
- } else {
28
- return value;
29
- }
30
- } // Allow subclasses to massage the input prior to running
31
-
32
-
33
- oldString = this.castInput(oldString);
34
- newString = this.castInput(newString);
35
- oldString = this.removeEmpty(this.tokenize(oldString));
36
- newString = this.removeEmpty(this.tokenize(newString));
37
- var newLen = newString.length,
38
- oldLen = oldString.length;
39
- var editLength = 1;
40
- var maxEditLength = newLen + oldLen;
41
- var bestPath = [{
42
- newPos: -1,
43
- components: []
44
- }]; // Seed editLength = 0, i.e. the content starts with the same values
45
-
46
- var oldPos = this.extractCommon(bestPath[0], newString, oldString, 0);
47
-
48
- if (bestPath[0].newPos + 1 >= newLen && oldPos + 1 >= oldLen) {
49
- // Identity per the equality and tokenizer
50
- return done([{
51
- value: this.join(newString),
52
- count: newString.length
53
- }]);
54
- } // Main worker method. checks all permutations of a given edit length for acceptance.
55
-
56
-
57
- function execEditLength() {
58
- for (var diagonalPath = -1 * editLength; diagonalPath <= editLength; diagonalPath += 2) {
59
- var basePath = void 0;
60
-
61
- var addPath = bestPath[diagonalPath - 1],
62
- removePath = bestPath[diagonalPath + 1],
63
- _oldPos = (removePath ? removePath.newPos : 0) - diagonalPath;
64
-
65
- if (addPath) {
66
- // No one else is going to attempt to use this value, clear it
67
- bestPath[diagonalPath - 1] = undefined;
68
- }
69
-
70
- var canAdd = addPath && addPath.newPos + 1 < newLen,
71
- canRemove = removePath && 0 <= _oldPos && _oldPos < oldLen;
72
-
73
- if (!canAdd && !canRemove) {
74
- // If this path is a terminal then prune
75
- bestPath[diagonalPath] = undefined;
76
- continue;
77
- } // Select the diagonal that we want to branch from. We select the prior
78
- // path whose position in the new string is the farthest from the origin
79
- // and does not pass the bounds of the diff graph
80
-
81
-
82
- if (!canAdd || canRemove && addPath.newPos < removePath.newPos) {
83
- basePath = clonePath(removePath);
84
- self.pushComponent(basePath.components, undefined, true);
85
- } else {
86
- basePath = addPath; // No need to clone, we've pulled it from the list
87
-
88
- basePath.newPos++;
89
- self.pushComponent(basePath.components, true, undefined);
90
- }
91
-
92
- _oldPos = self.extractCommon(basePath, newString, oldString, diagonalPath); // If we have hit the end of both strings, then we are done
93
-
94
- if (basePath.newPos + 1 >= newLen && _oldPos + 1 >= oldLen) {
95
- return done(buildValues(self, basePath.components, newString, oldString, self.useLongestToken));
96
- } else {
97
- // Otherwise track this path as a potential candidate and continue.
98
- bestPath[diagonalPath] = basePath;
99
- }
100
- }
101
-
102
- editLength++;
103
- } // Performs the length of edit iteration. Is a bit fugly as this has to support the
104
- // sync and async mode which is never fun. Loops over execEditLength until a value
105
- // is produced.
106
-
107
-
108
- if (callback) {
109
- (function exec() {
110
- setTimeout(function () {
111
- // This should not happen, but we want to be safe.
112
-
113
- /* istanbul ignore next */
114
- if (editLength > maxEditLength) {
115
- return callback();
116
- }
117
-
118
- if (!execEditLength()) {
119
- exec();
120
- }
121
- }, 0);
122
- })();
123
- } else {
124
- while (editLength <= maxEditLength) {
125
- var ret = execEditLength();
126
-
127
- if (ret) {
128
- return ret;
129
- }
130
- }
131
- }
132
- },
133
- pushComponent: function pushComponent(components, added, removed) {
134
- var last = components[components.length - 1];
135
-
136
- if (last && last.added === added && last.removed === removed) {
137
- // We need to clone here as the component clone operation is just
138
- // as shallow array clone
139
- components[components.length - 1] = {
140
- count: last.count + 1,
141
- added: added,
142
- removed: removed
143
- };
144
- } else {
145
- components.push({
146
- count: 1,
147
- added: added,
148
- removed: removed
149
- });
150
- }
151
- },
152
- extractCommon: function extractCommon(basePath, newString, oldString, diagonalPath) {
153
- var newLen = newString.length,
154
- oldLen = oldString.length,
155
- newPos = basePath.newPos,
156
- oldPos = newPos - diagonalPath,
157
- commonCount = 0;
158
-
159
- while (newPos + 1 < newLen && oldPos + 1 < oldLen && this.equals(newString[newPos + 1], oldString[oldPos + 1])) {
160
- newPos++;
161
- oldPos++;
162
- commonCount++;
163
- }
164
-
165
- if (commonCount) {
166
- basePath.components.push({
167
- count: commonCount
168
- });
169
- }
170
-
171
- basePath.newPos = newPos;
172
- return oldPos;
173
- },
174
- equals: function equals(left, right) {
175
- if (this.options.comparator) {
176
- return this.options.comparator(left, right);
177
- } else {
178
- return left === right || this.options.ignoreCase && left.toLowerCase() === right.toLowerCase();
179
- }
180
- },
181
- removeEmpty: function removeEmpty(array) {
182
- var ret = [];
183
-
184
- for (var i = 0; i < array.length; i++) {
185
- if (array[i]) {
186
- ret.push(array[i]);
187
- }
188
- }
189
-
190
- return ret;
191
- },
192
- castInput: function castInput(value) {
193
- return value;
194
- },
195
- tokenize: function tokenize(value) {
196
- return value.split('');
197
- },
198
- join: function join(chars) {
199
- return chars.join('');
200
- }
201
- };
202
-
203
- function buildValues(diff, components, newString, oldString, useLongestToken) {
204
- var componentPos = 0,
205
- componentLen = components.length,
206
- newPos = 0,
207
- oldPos = 0;
208
-
209
- for (; componentPos < componentLen; componentPos++) {
210
- var component = components[componentPos];
211
-
212
- if (!component.removed) {
213
- if (!component.added && useLongestToken) {
214
- var value = newString.slice(newPos, newPos + component.count);
215
- value = value.map(function (value, i) {
216
- var oldValue = oldString[oldPos + i];
217
- return oldValue.length > value.length ? oldValue : value;
218
- });
219
- component.value = diff.join(value);
220
- } else {
221
- component.value = diff.join(newString.slice(newPos, newPos + component.count));
222
- }
223
-
224
- newPos += component.count; // Common case
225
-
226
- if (!component.added) {
227
- oldPos += component.count;
228
- }
229
- } else {
230
- component.value = diff.join(oldString.slice(oldPos, oldPos + component.count));
231
- oldPos += component.count; // Reverse add and remove so removes are output first to match common convention
232
- // The diffing algorithm is tied to add then remove output and this is the simplest
233
- // route to get the desired output with minimal overhead.
234
-
235
- if (componentPos && components[componentPos - 1].added) {
236
- var tmp = components[componentPos - 1];
237
- components[componentPos - 1] = components[componentPos];
238
- components[componentPos] = tmp;
239
- }
240
- }
241
- } // Special case handle for when one terminal is ignored (i.e. whitespace).
242
- // For this case we merge the terminal into the prior string and drop the change.
243
- // This is only available for string mode.
244
-
245
-
246
- var lastComponent = components[componentLen - 1];
247
-
248
- if (componentLen > 1 && typeof lastComponent.value === 'string' && (lastComponent.added || lastComponent.removed) && diff.equals('', lastComponent.value)) {
249
- components[componentLen - 2].value += lastComponent.value;
250
- components.pop();
251
- }
252
-
253
- return components;
254
- }
255
-
256
- function clonePath(path) {
257
- return {
258
- newPos: path.newPos,
259
- components: path.components.slice(0)
260
- };
261
- }
262
-
263
- //
264
- // Ranges and exceptions:
265
- // Latin-1 Supplement, 0080–00FF
266
- // - U+00D7 × Multiplication sign
267
- // - U+00F7 ÷ Division sign
268
- // Latin Extended-A, 0100–017F
269
- // Latin Extended-B, 0180–024F
270
- // IPA Extensions, 0250–02AF
271
- // Spacing Modifier Letters, 02B0–02FF
272
- // - U+02C7 ˇ &#711; Caron
273
- // - U+02D8 ˘ &#728; Breve
274
- // - U+02D9 ˙ &#729; Dot Above
275
- // - U+02DA ˚ &#730; Ring Above
276
- // - U+02DB ˛ &#731; Ogonek
277
- // - U+02DC ˜ &#732; Small Tilde
278
- // - U+02DD ˝ &#733; Double Acute Accent
279
- // Latin Extended Additional, 1E00–1EFF
280
-
281
- var extendedWordChars = /^[A-Za-z\xC0-\u02C6\u02C8-\u02D7\u02DE-\u02FF\u1E00-\u1EFF]+$/;
282
- var reWhitespace = /\S/;
283
- var wordDiff = new Diff();
284
-
285
- wordDiff.equals = function (left, right) {
286
- if (this.options.ignoreCase) {
287
- left = left.toLowerCase();
288
- right = right.toLowerCase();
289
- }
290
-
291
- return left === right || this.options.ignoreWhitespace && !reWhitespace.test(left) && !reWhitespace.test(right);
292
- };
293
-
294
- wordDiff.tokenize = function (value) {
295
- // All whitespace symbols except newline group into one token, each newline - in separate token
296
- var tokens = value.split(/([^\S\r\n]+|[()[\]{}'"\r\n]|\b)/); // Join the boundary splits that we do not consider to be boundaries. This is primarily the extended Latin character set.
297
-
298
- for (var i = 0; i < tokens.length - 1; i++) {
299
- // If we have an empty string in the next field and we have only word chars before and after, merge
300
- if (!tokens[i + 1] && tokens[i + 2] && extendedWordChars.test(tokens[i]) && extendedWordChars.test(tokens[i + 2])) {
301
- tokens[i] += tokens[i + 2];
302
- tokens.splice(i + 1, 2);
303
- i--;
304
- }
305
- }
306
-
307
- return tokens;
308
- };
309
-
310
- var lineDiff = new Diff();
311
-
312
- lineDiff.tokenize = function (value) {
313
- var retLines = [],
314
- linesAndNewlines = value.split(/(\n|\r\n)/); // Ignore the final empty token that occurs if the string ends with a new line
315
-
316
- if (!linesAndNewlines[linesAndNewlines.length - 1]) {
317
- linesAndNewlines.pop();
318
- } // Merge the content and line separators into single tokens
319
-
320
-
321
- for (var i = 0; i < linesAndNewlines.length; i++) {
322
- var line = linesAndNewlines[i];
323
-
324
- if (i % 2 && !this.options.newlineIsToken) {
325
- retLines[retLines.length - 1] += line;
326
- } else {
327
- if (this.options.ignoreWhitespace) {
328
- line = line.trim();
329
- }
330
-
331
- retLines.push(line);
332
- }
333
- }
334
-
335
- return retLines;
336
- };
337
-
338
- function diffLines(oldStr, newStr, callback) {
339
- return lineDiff.diff(oldStr, newStr, callback);
340
- }
341
-
342
- var sentenceDiff = new Diff();
343
-
344
- sentenceDiff.tokenize = function (value) {
345
- return value.split(/(\S.+?[.!?])(?=\s+|$)/);
346
- };
347
-
348
- var cssDiff = new Diff();
349
-
350
- cssDiff.tokenize = function (value) {
351
- return value.split(/([{}:;,]|\s+)/);
352
- };
353
-
354
- function _typeof(obj) {
355
- "@babel/helpers - typeof";
356
-
357
- if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
358
- _typeof = function (obj) {
359
- return typeof obj;
360
- };
361
- } else {
362
- _typeof = function (obj) {
363
- return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
364
- };
365
- }
366
-
367
- return _typeof(obj);
368
- }
369
-
370
- function _toConsumableArray(arr) {
371
- return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
372
- }
373
-
374
- function _arrayWithoutHoles(arr) {
375
- if (Array.isArray(arr)) return _arrayLikeToArray(arr);
376
- }
377
-
378
- function _iterableToArray(iter) {
379
- if (typeof Symbol !== "undefined" && Symbol.iterator in Object(iter)) return Array.from(iter);
380
- }
381
-
382
- function _unsupportedIterableToArray(o, minLen) {
383
- if (!o) return;
384
- if (typeof o === "string") return _arrayLikeToArray(o, minLen);
385
- var n = Object.prototype.toString.call(o).slice(8, -1);
386
- if (n === "Object" && o.constructor) n = o.constructor.name;
387
- if (n === "Map" || n === "Set") return Array.from(o);
388
- if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
389
- }
390
-
391
- function _arrayLikeToArray(arr, len) {
392
- if (len == null || len > arr.length) len = arr.length;
393
-
394
- for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
395
-
396
- return arr2;
397
- }
398
-
399
- function _nonIterableSpread() {
400
- throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
401
- }
402
-
403
- var objectPrototypeToString = Object.prototype.toString;
404
- var jsonDiff = new Diff(); // Discriminate between two lines of pretty-printed, serialized JSON where one of them has a
405
- // dangling comma and the other doesn't. Turns out including the dangling comma yields the nicest output:
406
-
407
- jsonDiff.useLongestToken = true;
408
- jsonDiff.tokenize = lineDiff.tokenize;
409
-
410
- jsonDiff.castInput = function (value) {
411
- var _this$options = this.options,
412
- undefinedReplacement = _this$options.undefinedReplacement,
413
- _this$options$stringi = _this$options.stringifyReplacer,
414
- stringifyReplacer = _this$options$stringi === void 0 ? function (k, v) {
415
- return typeof v === 'undefined' ? undefinedReplacement : v;
416
- } : _this$options$stringi;
417
- return typeof value === 'string' ? value : JSON.stringify(canonicalize(value, null, null, stringifyReplacer), stringifyReplacer, ' ');
418
- };
419
-
420
- jsonDiff.equals = function (left, right) {
421
- return Diff.prototype.equals.call(jsonDiff, left.replace(/,([\r\n])/g, '$1'), right.replace(/,([\r\n])/g, '$1'));
422
- };
423
- // object that is already on the "stack" of items being processed. Accepts an optional replacer
424
-
425
- function canonicalize(obj, stack, replacementStack, replacer, key) {
426
- stack = stack || [];
427
- replacementStack = replacementStack || [];
428
-
429
- if (replacer) {
430
- obj = replacer(key, obj);
431
- }
432
-
433
- var i;
434
-
435
- for (i = 0; i < stack.length; i += 1) {
436
- if (stack[i] === obj) {
437
- return replacementStack[i];
438
- }
439
- }
440
-
441
- var canonicalizedObj;
442
-
443
- if ('[object Array]' === objectPrototypeToString.call(obj)) {
444
- stack.push(obj);
445
- canonicalizedObj = new Array(obj.length);
446
- replacementStack.push(canonicalizedObj);
447
-
448
- for (i = 0; i < obj.length; i += 1) {
449
- canonicalizedObj[i] = canonicalize(obj[i], stack, replacementStack, replacer, key);
450
- }
451
-
452
- stack.pop();
453
- replacementStack.pop();
454
- return canonicalizedObj;
455
- }
456
-
457
- if (obj && obj.toJSON) {
458
- obj = obj.toJSON();
459
- }
460
-
461
- if (_typeof(obj) === 'object' && obj !== null) {
462
- stack.push(obj);
463
- canonicalizedObj = {};
464
- replacementStack.push(canonicalizedObj);
465
-
466
- var sortedKeys = [],
467
- _key;
468
-
469
- for (_key in obj) {
470
- /* istanbul ignore else */
471
- if (obj.hasOwnProperty(_key)) {
472
- sortedKeys.push(_key);
473
- }
474
- }
475
-
476
- sortedKeys.sort();
477
-
478
- for (i = 0; i < sortedKeys.length; i += 1) {
479
- _key = sortedKeys[i];
480
- canonicalizedObj[_key] = canonicalize(obj[_key], stack, replacementStack, replacer, _key);
481
- }
482
-
483
- stack.pop();
484
- replacementStack.pop();
485
- } else {
486
- canonicalizedObj = obj;
487
- }
488
-
489
- return canonicalizedObj;
490
- }
491
-
492
- var arrayDiff = new Diff();
493
-
494
- arrayDiff.tokenize = function (value) {
495
- return value.slice();
496
- };
497
-
498
- arrayDiff.join = arrayDiff.removeEmpty = function (value) {
499
- return value;
500
- };
501
-
502
- function structuredPatch(oldFileName, newFileName, oldStr, newStr, oldHeader, newHeader, options) {
503
- if (!options) {
504
- options = {};
505
- }
506
-
507
- if (typeof options.context === 'undefined') {
508
- options.context = 4;
509
- }
510
-
511
- var diff = diffLines(oldStr, newStr, options);
512
- diff.push({
513
- value: '',
514
- lines: []
515
- }); // Append an empty value to make cleanup easier
516
-
517
- function contextLines(lines) {
518
- return lines.map(function (entry) {
519
- return ' ' + entry;
520
- });
521
- }
522
-
523
- var hunks = [];
524
- var oldRangeStart = 0,
525
- newRangeStart = 0,
526
- curRange = [],
527
- oldLine = 1,
528
- newLine = 1;
529
-
530
- var _loop = function _loop(i) {
531
- var current = diff[i],
532
- lines = current.lines || current.value.replace(/\n$/, '').split('\n');
533
- current.lines = lines;
534
-
535
- if (current.added || current.removed) {
536
- var _curRange;
537
-
538
- // If we have previous context, start with that
539
- if (!oldRangeStart) {
540
- var prev = diff[i - 1];
541
- oldRangeStart = oldLine;
542
- newRangeStart = newLine;
543
-
544
- if (prev) {
545
- curRange = options.context > 0 ? contextLines(prev.lines.slice(-options.context)) : [];
546
- oldRangeStart -= curRange.length;
547
- newRangeStart -= curRange.length;
548
- }
549
- } // Output our changes
550
-
551
-
552
- (_curRange = curRange).push.apply(_curRange, _toConsumableArray(lines.map(function (entry) {
553
- return (current.added ? '+' : '-') + entry;
554
- }))); // Track the updated file position
555
-
556
-
557
- if (current.added) {
558
- newLine += lines.length;
559
- } else {
560
- oldLine += lines.length;
561
- }
562
- } else {
563
- // Identical context lines. Track line changes
564
- if (oldRangeStart) {
565
- // Close out any changes that have been output (or join overlapping)
566
- if (lines.length <= options.context * 2 && i < diff.length - 2) {
567
- var _curRange2;
568
-
569
- // Overlapping
570
- (_curRange2 = curRange).push.apply(_curRange2, _toConsumableArray(contextLines(lines)));
571
- } else {
572
- var _curRange3;
573
-
574
- // end the range and output
575
- var contextSize = Math.min(lines.length, options.context);
576
-
577
- (_curRange3 = curRange).push.apply(_curRange3, _toConsumableArray(contextLines(lines.slice(0, contextSize))));
578
-
579
- var hunk = {
580
- oldStart: oldRangeStart,
581
- oldLines: oldLine - oldRangeStart + contextSize,
582
- newStart: newRangeStart,
583
- newLines: newLine - newRangeStart + contextSize,
584
- lines: curRange
585
- };
586
-
587
- if (i >= diff.length - 2 && lines.length <= options.context) {
588
- // EOF is inside this hunk
589
- var oldEOFNewline = /\n$/.test(oldStr);
590
- var newEOFNewline = /\n$/.test(newStr);
591
- var noNlBeforeAdds = lines.length == 0 && curRange.length > hunk.oldLines;
592
-
593
- if (!oldEOFNewline && noNlBeforeAdds && oldStr.length > 0) {
594
- // special case: old has no eol and no trailing context; no-nl can end up before adds
595
- // however, if the old file is empty, do not output the no-nl line
596
- curRange.splice(hunk.oldLines, 0, '\');
597
- }
598
-
599
- if (!oldEOFNewline && !noNlBeforeAdds || !newEOFNewline) {
600
- curRange.push('\');
601
- }
602
- }
603
-
604
- hunks.push(hunk);
605
- oldRangeStart = 0;
606
- newRangeStart = 0;
607
- curRange = [];
608
- }
609
- }
610
-
611
- oldLine += lines.length;
612
- newLine += lines.length;
613
- }
614
- };
615
-
616
- for (var i = 0; i < diff.length; i++) {
617
- _loop(i);
618
- }
619
-
620
- return {
621
- oldFileName: oldFileName,
622
- newFileName: newFileName,
623
- oldHeader: oldHeader,
624
- newHeader: newHeader,
625
- hunks: hunks
626
- };
627
- }
628
- function formatPatch(diff) {
629
- var ret = [];
630
-
631
- if (diff.oldFileName == diff.newFileName) {
632
- ret.push('Index: ' + diff.oldFileName);
633
- }
634
-
635
- ret.push('===================================================================');
636
- ret.push('--- ' + diff.oldFileName + (typeof diff.oldHeader === 'undefined' ? '' : '\t' + diff.oldHeader));
637
- ret.push('+++ ' + diff.newFileName + (typeof diff.newHeader === 'undefined' ? '' : '\t' + diff.newHeader));
638
-
639
- for (var i = 0; i < diff.hunks.length; i++) {
640
- var hunk = diff.hunks[i]; // Unified Diff Format quirk: If the chunk size is 0,
641
- // the first number is one lower than one would expect.
642
- // https://www.artima.com/weblogs/viewpost.jsp?thread=164293
643
-
644
- if (hunk.oldLines === 0) {
645
- hunk.oldStart -= 1;
646
- }
647
-
648
- if (hunk.newLines === 0) {
649
- hunk.newStart -= 1;
650
- }
651
-
652
- ret.push('@@ -' + hunk.oldStart + ',' + hunk.oldLines + ' +' + hunk.newStart + ',' + hunk.newLines + ' @@');
653
- ret.push.apply(ret, hunk.lines);
654
- }
655
-
656
- return ret.join('\n') + '\n';
657
- }
658
- function createTwoFilesPatch(oldFileName, newFileName, oldStr, newStr, oldHeader, newHeader, options) {
659
- return formatPatch(structuredPatch(oldFileName, newFileName, oldStr, newStr, oldHeader, newHeader, options));
660
- }
661
- function createPatch(fileName, oldStr, newStr, oldHeader, newHeader, options) {
662
- return createTwoFilesPatch(fileName, fileName, oldStr, newStr, oldHeader, newHeader, options);
663
- }
664
-
665
- /* eslint-disable yoda */
666
-
667
- function isFullwidthCodePoint(codePoint) {
668
- if (!Number.isInteger(codePoint)) {
669
- return false;
670
- }
671
-
672
- // Code points are derived from:
673
- // https://unicode.org/Public/UNIDATA/EastAsianWidth.txt
674
- return codePoint >= 0x1100 && (
675
- codePoint <= 0x115F || // Hangul Jamo
676
- codePoint === 0x2329 || // LEFT-POINTING ANGLE BRACKET
677
- codePoint === 0x232A || // RIGHT-POINTING ANGLE BRACKET
678
- // CJK Radicals Supplement .. Enclosed CJK Letters and Months
679
- (0x2E80 <= codePoint && codePoint <= 0x3247 && codePoint !== 0x303F) ||
680
- // Enclosed CJK Letters and Months .. CJK Unified Ideographs Extension A
681
- (0x3250 <= codePoint && codePoint <= 0x4DBF) ||
682
- // CJK Unified Ideographs .. Yi Radicals
683
- (0x4E00 <= codePoint && codePoint <= 0xA4C6) ||
684
- // Hangul Jamo Extended-A
685
- (0xA960 <= codePoint && codePoint <= 0xA97C) ||
686
- // Hangul Syllables
687
- (0xAC00 <= codePoint && codePoint <= 0xD7A3) ||
688
- // CJK Compatibility Ideographs
689
- (0xF900 <= codePoint && codePoint <= 0xFAFF) ||
690
- // Vertical Forms
691
- (0xFE10 <= codePoint && codePoint <= 0xFE19) ||
692
- // CJK Compatibility Forms .. Small Form Variants
693
- (0xFE30 <= codePoint && codePoint <= 0xFE6B) ||
694
- // Halfwidth and Fullwidth Forms
695
- (0xFF01 <= codePoint && codePoint <= 0xFF60) ||
696
- (0xFFE0 <= codePoint && codePoint <= 0xFFE6) ||
697
- // Kana Supplement
698
- (0x1B000 <= codePoint && codePoint <= 0x1B001) ||
699
- // Enclosed Ideographic Supplement
700
- (0x1F200 <= codePoint && codePoint <= 0x1F251) ||
701
- // CJK Unified Ideographs Extension B .. Tertiary Ideographic Plane
702
- (0x20000 <= codePoint && codePoint <= 0x3FFFD)
703
- );
704
- }
705
-
706
- const ANSI_BACKGROUND_OFFSET = 10;
707
-
708
- const wrapAnsi16 = (offset = 0) => code => `\u001B[${code + offset}m`;
709
-
710
- const wrapAnsi256 = (offset = 0) => code => `\u001B[${38 + offset};5;${code}m`;
711
-
712
- const wrapAnsi16m = (offset = 0) => (red, green, blue) => `\u001B[${38 + offset};2;${red};${green};${blue}m`;
713
-
714
- function assembleStyles() {
715
- const codes = new Map();
716
- const styles = {
717
- modifier: {
718
- reset: [0, 0],
719
- // 21 isn't widely supported and 22 does the same thing
720
- bold: [1, 22],
721
- dim: [2, 22],
722
- italic: [3, 23],
723
- underline: [4, 24],
724
- overline: [53, 55],
725
- inverse: [7, 27],
726
- hidden: [8, 28],
727
- strikethrough: [9, 29]
728
- },
729
- color: {
730
- black: [30, 39],
731
- red: [31, 39],
732
- green: [32, 39],
733
- yellow: [33, 39],
734
- blue: [34, 39],
735
- magenta: [35, 39],
736
- cyan: [36, 39],
737
- white: [37, 39],
738
-
739
- // Bright color
740
- blackBright: [90, 39],
741
- redBright: [91, 39],
742
- greenBright: [92, 39],
743
- yellowBright: [93, 39],
744
- blueBright: [94, 39],
745
- magentaBright: [95, 39],
746
- cyanBright: [96, 39],
747
- whiteBright: [97, 39]
748
- },
749
- bgColor: {
750
- bgBlack: [40, 49],
751
- bgRed: [41, 49],
752
- bgGreen: [42, 49],
753
- bgYellow: [43, 49],
754
- bgBlue: [44, 49],
755
- bgMagenta: [45, 49],
756
- bgCyan: [46, 49],
757
- bgWhite: [47, 49],
758
-
759
- // Bright color
760
- bgBlackBright: [100, 49],
761
- bgRedBright: [101, 49],
762
- bgGreenBright: [102, 49],
763
- bgYellowBright: [103, 49],
764
- bgBlueBright: [104, 49],
765
- bgMagentaBright: [105, 49],
766
- bgCyanBright: [106, 49],
767
- bgWhiteBright: [107, 49]
768
- }
769
- };
770
-
771
- // Alias bright black as gray (and grey)
772
- styles.color.gray = styles.color.blackBright;
773
- styles.bgColor.bgGray = styles.bgColor.bgBlackBright;
774
- styles.color.grey = styles.color.blackBright;
775
- styles.bgColor.bgGrey = styles.bgColor.bgBlackBright;
776
-
777
- for (const [groupName, group] of Object.entries(styles)) {
778
- for (const [styleName, style] of Object.entries(group)) {
779
- styles[styleName] = {
780
- open: `\u001B[${style[0]}m`,
781
- close: `\u001B[${style[1]}m`
782
- };
783
-
784
- group[styleName] = styles[styleName];
785
-
786
- codes.set(style[0], style[1]);
787
- }
788
-
789
- Object.defineProperty(styles, groupName, {
790
- value: group,
791
- enumerable: false
792
- });
793
- }
794
-
795
- Object.defineProperty(styles, 'codes', {
796
- value: codes,
797
- enumerable: false
798
- });
799
-
800
- styles.color.close = '\u001B[39m';
801
- styles.bgColor.close = '\u001B[49m';
802
-
803
- styles.color.ansi = wrapAnsi16();
804
- styles.color.ansi256 = wrapAnsi256();
805
- styles.color.ansi16m = wrapAnsi16m();
806
- styles.bgColor.ansi = wrapAnsi16(ANSI_BACKGROUND_OFFSET);
807
- styles.bgColor.ansi256 = wrapAnsi256(ANSI_BACKGROUND_OFFSET);
808
- styles.bgColor.ansi16m = wrapAnsi16m(ANSI_BACKGROUND_OFFSET);
809
-
810
- // From https://github.com/Qix-/color-convert/blob/3f0e0d4e92e235796ccb17f6e85c72094a651f49/conversions.js
811
- Object.defineProperties(styles, {
812
- rgbToAnsi256: {
813
- value: (red, green, blue) => {
814
- // We use the extended greyscale palette here, with the exception of
815
- // black and white. normal palette only has 4 greyscale shades.
816
- if (red === green && green === blue) {
817
- if (red < 8) {
818
- return 16;
819
- }
820
-
821
- if (red > 248) {
822
- return 231;
823
- }
824
-
825
- return Math.round(((red - 8) / 247) * 24) + 232;
826
- }
827
-
828
- return 16 +
829
- (36 * Math.round(red / 255 * 5)) +
830
- (6 * Math.round(green / 255 * 5)) +
831
- Math.round(blue / 255 * 5);
832
- },
833
- enumerable: false
834
- },
835
- hexToRgb: {
836
- value: hex => {
837
- const matches = /(?<colorString>[a-f\d]{6}|[a-f\d]{3})/i.exec(hex.toString(16));
838
- if (!matches) {
839
- return [0, 0, 0];
840
- }
841
-
842
- let {colorString} = matches.groups;
843
-
844
- if (colorString.length === 3) {
845
- colorString = colorString.split('').map(character => character + character).join('');
846
- }
847
-
848
- const integer = Number.parseInt(colorString, 16);
849
-
850
- return [
851
- (integer >> 16) & 0xFF,
852
- (integer >> 8) & 0xFF,
853
- integer & 0xFF
854
- ];
855
- },
856
- enumerable: false
857
- },
858
- hexToAnsi256: {
859
- value: hex => styles.rgbToAnsi256(...styles.hexToRgb(hex)),
860
- enumerable: false
861
- },
862
- ansi256ToAnsi: {
863
- value: code => {
864
- if (code < 8) {
865
- return 30 + code;
866
- }
867
-
868
- if (code < 16) {
869
- return 90 + (code - 8);
870
- }
871
-
872
- let red;
873
- let green;
874
- let blue;
875
-
876
- if (code >= 232) {
877
- red = (((code - 232) * 10) + 8) / 255;
878
- green = red;
879
- blue = red;
880
- } else {
881
- code -= 16;
882
-
883
- const remainder = code % 36;
884
-
885
- red = Math.floor(code / 36) / 5;
886
- green = Math.floor(remainder / 6) / 5;
887
- blue = (remainder % 6) / 5;
888
- }
889
-
890
- const value = Math.max(red, green, blue) * 2;
891
-
892
- if (value === 0) {
893
- return 30;
894
- }
895
-
896
- let result = 30 + ((Math.round(blue) << 2) | (Math.round(green) << 1) | Math.round(red));
897
-
898
- if (value === 2) {
899
- result += 60;
900
- }
901
-
902
- return result;
903
- },
904
- enumerable: false
905
- },
906
- rgbToAnsi: {
907
- value: (red, green, blue) => styles.ansi256ToAnsi(styles.rgbToAnsi256(red, green, blue)),
908
- enumerable: false
909
- },
910
- hexToAnsi: {
911
- value: hex => styles.ansi256ToAnsi(styles.hexToAnsi256(hex)),
912
- enumerable: false
913
- }
914
- });
915
-
916
- return styles;
917
- }
918
-
919
- const ansiStyles = assembleStyles();
920
-
921
- const astralRegex = /^[\uD800-\uDBFF][\uDC00-\uDFFF]$/;
922
-
923
- const ESCAPES = [
924
- '\u001B',
925
- '\u009B'
926
- ];
927
-
928
- const wrapAnsi = code => `${ESCAPES[0]}[${code}m`;
929
-
930
- const checkAnsi = (ansiCodes, isEscapes, endAnsiCode) => {
931
- let output = [];
932
- ansiCodes = [...ansiCodes];
933
-
934
- for (let ansiCode of ansiCodes) {
935
- const ansiCodeOrigin = ansiCode;
936
- if (ansiCode.includes(';')) {
937
- ansiCode = ansiCode.split(';')[0][0] + '0';
938
- }
939
-
940
- const item = ansiStyles.codes.get(Number.parseInt(ansiCode, 10));
941
- if (item) {
942
- const indexEscape = ansiCodes.indexOf(item.toString());
943
- if (indexEscape === -1) {
944
- output.push(wrapAnsi(isEscapes ? item : ansiCodeOrigin));
945
- } else {
946
- ansiCodes.splice(indexEscape, 1);
947
- }
948
- } else if (isEscapes) {
949
- output.push(wrapAnsi(0));
950
- break;
951
- } else {
952
- output.push(wrapAnsi(ansiCodeOrigin));
953
- }
954
- }
955
-
956
- if (isEscapes) {
957
- output = output.filter((element, index) => output.indexOf(element) === index);
958
-
959
- if (endAnsiCode !== undefined) {
960
- const fistEscapeCode = wrapAnsi(ansiStyles.codes.get(Number.parseInt(endAnsiCode, 10)));
961
- // TODO: Remove the use of `.reduce` here.
962
- // eslint-disable-next-line unicorn/no-array-reduce
963
- output = output.reduce((current, next) => next === fistEscapeCode ? [next, ...current] : [...current, next], []);
964
- }
965
- }
966
-
967
- return output.join('');
968
- };
969
-
970
- function sliceAnsi(string, begin, end) {
971
- const characters = [...string];
972
- const ansiCodes = [];
973
-
974
- let stringEnd = typeof end === 'number' ? end : characters.length;
975
- let isInsideEscape = false;
976
- let ansiCode;
977
- let visible = 0;
978
- let output = '';
979
-
980
- for (const [index, character] of characters.entries()) {
981
- let leftEscape = false;
982
-
983
- if (ESCAPES.includes(character)) {
984
- const code = /\d[^m]*/.exec(string.slice(index, index + 18));
985
- ansiCode = code && code.length > 0 ? code[0] : undefined;
986
-
987
- if (visible < stringEnd) {
988
- isInsideEscape = true;
989
-
990
- if (ansiCode !== undefined) {
991
- ansiCodes.push(ansiCode);
992
- }
993
- }
994
- } else if (isInsideEscape && character === 'm') {
995
- isInsideEscape = false;
996
- leftEscape = true;
997
- }
998
-
999
- if (!isInsideEscape && !leftEscape) {
1000
- visible++;
1001
- }
1002
-
1003
- if (!astralRegex.test(character) && isFullwidthCodePoint(character.codePointAt())) {
1004
- visible++;
1005
-
1006
- if (typeof end !== 'number') {
1007
- stringEnd++;
1008
- }
1009
- }
1010
-
1011
- if (visible > begin && visible <= stringEnd) {
1012
- output += character;
1013
- } else if (visible === begin && !isInsideEscape && ansiCode !== undefined) {
1014
- output = checkAnsi(ansiCodes);
1015
- } else if (visible >= stringEnd) {
1016
- output += checkAnsi(ansiCodes, true, ansiCode);
1017
- break;
1018
- }
1019
- }
1020
-
1021
- return output;
1022
- }
1023
-
1024
- function ansiRegex({onlyFirst = false} = {}) {
1025
- const pattern = [
1026
- '[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)',
1027
- '(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-ntqry=><~]))'
1028
- ].join('|');
1029
-
1030
- return new RegExp(pattern, onlyFirst ? undefined : 'g');
1031
- }
1032
-
1033
- function stripAnsi(string) {
1034
- if (typeof string !== 'string') {
1035
- throw new TypeError(`Expected a \`string\`, got \`${typeof string}\``);
1036
- }
1037
-
1038
- return string.replace(ansiRegex(), '');
1039
- }
1040
-
1041
- var emojiRegex = function () {
1042
- // https://mths.be/emoji
1043
- return /\uD83C\uDFF4\uDB40\uDC67\uDB40\uDC62(?:\uDB40\uDC77\uDB40\uDC6C\uDB40\uDC73|\uDB40\uDC73\uDB40\uDC63\uDB40\uDC74|\uDB40\uDC65\uDB40\uDC6E\uDB40\uDC67)\uDB40\uDC7F|(?:\uD83E\uDDD1\uD83C\uDFFF\u200D\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1|\uD83D\uDC69\uD83C\uDFFF\u200D\uD83E\uDD1D\u200D(?:\uD83D[\uDC68\uDC69]))(?:\uD83C[\uDFFB-\uDFFE])|(?:\uD83E\uDDD1\uD83C\uDFFE\u200D\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1|\uD83D\uDC69\uD83C\uDFFE\u200D\uD83E\uDD1D\u200D(?:\uD83D[\uDC68\uDC69]))(?:\uD83C[\uDFFB-\uDFFD\uDFFF])|(?:\uD83E\uDDD1\uD83C\uDFFD\u200D\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1|\uD83D\uDC69\uD83C\uDFFD\u200D\uD83E\uDD1D\u200D(?:\uD83D[\uDC68\uDC69]))(?:\uD83C[\uDFFB\uDFFC\uDFFE\uDFFF])|(?:\uD83E\uDDD1\uD83C\uDFFC\u200D\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1|\uD83D\uDC69\uD83C\uDFFC\u200D\uD83E\uDD1D\u200D(?:\uD83D[\uDC68\uDC69]))(?:\uD83C[\uDFFB\uDFFD-\uDFFF])|(?:\uD83E\uDDD1\uD83C\uDFFB\u200D\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1|\uD83D\uDC69\uD83C\uDFFB\u200D\uD83E\uDD1D\u200D(?:\uD83D[\uDC68\uDC69]))(?:\uD83C[\uDFFC-\uDFFF])|\uD83D\uDC68(?:\uD83C\uDFFB(?:\u200D(?:\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D\uD83D\uDC68(?:\uD83C[\uDFFB-\uDFFF])|\uD83D\uDC68(?:\uD83C[\uDFFB-\uDFFF]))|\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFC-\uDFFF])|[\u2695\u2696\u2708]\uFE0F|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD]))?|(?:\uD83C[\uDFFC-\uDFFF])\u200D\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D\uD83D\uDC68(?:\uD83C[\uDFFB-\uDFFF])|\uD83D\uDC68(?:\uD83C[\uDFFB-\uDFFF]))|\u200D(?:\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D)?\uD83D\uDC68|(?:\uD83D[\uDC68\uDC69])\u200D(?:\uD83D\uDC66\u200D\uD83D\uDC66|\uD83D\uDC67\u200D(?:\uD83D[\uDC66\uDC67]))|\uD83D\uDC66\u200D\uD83D\uDC66|\uD83D\uDC67\u200D(?:\uD83D[\uDC66\uDC67])|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFF\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFB-\uDFFE])|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFE\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFB-\uDFFD\uDFFF])|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFD\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFB\uDFFC\uDFFE\uDFFF])|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFC\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFB\uDFFD-\uDFFF])|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|(?:\uD83C\uDFFF\u200D[\u2695\u2696\u2708]|\uD83C\uDFFE\u200D[\u2695\u2696\u2708]|\uD83C\uDFFD\u200D[\u2695\u2696\u2708]|\uD83C\uDFFC\u200D[\u2695\u2696\u2708]|\u200D[\u2695\u2696\u2708])\uFE0F|\u200D(?:(?:\uD83D[\uDC68\uDC69])\u200D(?:\uD83D[\uDC66\uDC67])|\uD83D[\uDC66\uDC67])|\uD83C\uDFFF|\uD83C\uDFFE|\uD83C\uDFFD|\uD83C\uDFFC)?|(?:\uD83D\uDC69(?:\uD83C\uDFFB\u200D\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D(?:\uD83D[\uDC68\uDC69])|\uD83D[\uDC68\uDC69])|(?:\uD83C[\uDFFC-\uDFFF])\u200D\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D(?:\uD83D[\uDC68\uDC69])|\uD83D[\uDC68\uDC69]))|\uD83E\uDDD1(?:\uD83C[\uDFFB-\uDFFF])\u200D\uD83E\uDD1D\u200D\uD83E\uDDD1)(?:\uD83C[\uDFFB-\uDFFF])|\uD83D\uDC69\u200D\uD83D\uDC69\u200D(?:\uD83D\uDC66\u200D\uD83D\uDC66|\uD83D\uDC67\u200D(?:\uD83D[\uDC66\uDC67]))|\uD83D\uDC69(?:\u200D(?:\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D(?:\uD83D[\uDC68\uDC69])|\uD83D[\uDC68\uDC69])|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFF\u200D(?:\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\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uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFD\u200D(?:\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFC\u200D(?:\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFB\u200D(?:\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD]))|\uD83D\uDC69\u200D\uD83D\uDC66\u200D\uD83D\uDC66|\uD83D\uDC69\u200D\uD83D\uDC69\u200D(?:\uD83D[\uDC66\uDC67])|\uD83D\uDC69\u200D\uD83D\uDC67\u200D(?:\uD83D[\uDC66\uDC67])|(?:\uD83D\uDC41\uFE0F\u200D\uD83D\uDDE8|\uD83E\uDDD1(?:\uD83C\uDFFF\u200D[\u2695\u2696\u2708]|\uD83C\uDFFE\u200D[\u2695\u2696\u2708]|\uD83C\uDFFD\u200D[\u2695\u2696\u2708]|\uD83C\uDFFC\u200D[\u2695\u2696\u2708]|\uD83C\uDFFB\u200D[\u2695\u2696\u2708]|\u200D[\u2695\u2696\u2708])|\uD83D\uDC69(?:\uD83C\uDFFF\u200D[\u2695\u2696\u2708]|\uD83C\uDFFE\u200D[\u2695\u2696\u2708]|\uD83C\uDFFD\u200D[\u2695\u2696\u2708]|\uD83C\uDFFC\u200D[\u2695\u2696\u2708]|\uD83C\uDFFB\u200D[\u2695\u2696\u2708]|\u200D[\u2695\u2696\u2708])|\uD83D\uDE36\u200D\uD83C\uDF2B|\uD83C\uDFF3\uFE0F\u200D\u26A7|\uD83D\uDC3B\u200D\u2744|(?:(?:\uD83C[\uDFC3\uDFC4\uDFCA]|\uD83D[\uDC6E\uDC70\uDC71\uDC73\uDC77\uDC81\uDC82\uDC86\uDC87\uDE45-\uDE47\uDE4B\uDE4D\uDE4E\uDEA3\uDEB4-\uDEB6]|\uD83E[\uDD26\uDD35\uDD37-\uDD39\uDD3D\uDD3E\uDDB8\uDDB9\uDDCD-\uDDCF\uDDD4\uDDD6-\uDDDD])(?:\uD83C[\uDFFB-\uDFFF])|\uD83D\uDC6F|\uD83E[\uDD3C\uDDDE\uDDDF])\u200D[\u2640\u2642]|(?:\u26F9|\uD83C[\uDFCB\uDFCC]|\uD83D\uDD75)(?:\uFE0F|\uD83C[\uDFFB-\uDFFF])\u200D[\u2640\u2642]|\uD83C\uDFF4\u200D\u2620|(?:\uD83C[\uDFC3\uDFC4\uDFCA]|\uD83D[\uDC6E\uDC70\uDC71\uDC73\uDC77\uDC81\uDC82\uDC86\uDC87\uDE45-\uDE47\uDE4B\uDE4D\uDE4E\uDEA3\uDEB4-\uDEB6]|\uD83E[\uDD26\uDD35\uDD37-\uDD39\uDD3D\uDD3E\uDDB8\uDDB9\uDDCD-\uDDCF\uDDD4\uDDD6-\uDDDD])\u200D[\u2640\u2642]|[\xA9\xAE\u203C\u2049\u2122\u2139\u2194-\u2199\u21A9\u21AA\u2328\u23CF\u23ED-\u23EF\u23F1\u23F2\u23F8-\u23FA\u24C2\u25AA\u25AB\u25B6\u25C0\u25FB\u25FC\u2600-\u2604\u260E\u2611\u2618\u2620\u2622\u2623\u2626\u262A\u262E\u262F\u2638-\u263A\u2640\u2642\u265F\u2660\u2663\u2665\u2666\u2668\u267B\u267E\u2692\u2694-\u2697\u2699\u269B\u269C\u26A0\u26A7\u26B0\u26B1\u26C8\u26CF\u26D1\u26D3\u26E9\u26F0\u26F1\u26F4\u26F7\u26F8\u2702\u2708\u2709\u270F\u2712\u2714\u2716\u271D\u2721\u2733\u2734\u2744\u2747\u2763\u27A1\u2934\u2935\u2B05-\u2B07\u3030\u303D\u3297\u3299]|\uD83C[\uDD70\uDD71\uDD7E\uDD7F\uDE02\uDE37\uDF21\uDF24-\uDF2C\uDF36\uDF7D\uDF96\uDF97\uDF99-\uDF9B\uDF9E\uDF9F\uDFCD\uDFCE\uDFD4-\uDFDF\uDFF5\uDFF7]|\uD83D[\uDC3F\uDCFD\uDD49\uDD4A\uDD6F\uDD70\uDD73\uDD76-\uDD79\uDD87\uDD8A-\uDD8D\uDDA5\uDDA8\uDDB1\uDDB2\uDDBC\uDDC2-\uDDC4\uDDD1-\uDDD3\uDDDC-\uDDDE\uDDE1\uDDE3\uDDE8\uDDEF\uDDF3\uDDFA\uDECB\uDECD-\uDECF\uDEE0-\uDEE5\uDEE9\uDEF0\uDEF3])\uFE0F|\uD83C\uDFF3\uFE0F\u200D\uD83C\uDF08|\uD83D\uDC69\u200D\uD83D\uDC67|\uD83D\uDC69\u200D\uD83D\uDC66|\uD83D\uDE35\u200D\uD83D\uDCAB|\uD83D\uDE2E\u200D\uD83D\uDCA8|\uD83D\uDC15\u200D\uD83E\uDDBA|\uD83E\uDDD1(?:\uD83C\uDFFF|\uD83C\uDFFE|\uD83C\uDFFD|\uD83C\uDFFC|\uD83C\uDFFB)?|\uD83D\uDC69(?:\uD83C\uDFFF|\uD83C\uDFFE|\uD83C\uDFFD|\uD83C\uDFFC|\uD83C\uDFFB)?|\uD83C\uDDFD\uD83C\uDDF0|\uD83C\uDDF6\uD83C\uDDE6|\uD83C\uDDF4\uD83C\uDDF2|\uD83D\uDC08\u200D\u2B1B|\u2764\uFE0F\u200D(?:\uD83D\uDD25|\uD83E\uDE79)|\uD83D\uDC41\uFE0F|\uD83C\uDFF3\uFE0F|\uD83C\uDDFF(?:\uD83C[\uDDE6\uDDF2\uDDFC])|\uD83C\uDDFE(?:\uD83C[\uDDEA\uDDF9])|\uD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uDD36\uDD77\uDDB5\uDDB6\uDDBB\uDDD2\uDDD3\uDDD5])(?:\uD83C[\uDFFB-\uDFFF])|(?:[\u261D\u270C\u270D]|\uD83D[\uDD74\uDD90])(?:\uFE0F|\uD83C[\uDFFB-\uDFFF])|[\u270A\u270B]|\uD83C[\uDF85\uDFC2\uDFC7]|\uD83D[\uDC08\uDC15\uDC3B\uDC42\uDC43\uDC46-\uDC50\uDC66\uDC67\uDC6B-\uDC6D\uDC72\uDC74-\uDC76\uDC78\uDC7C\uDC83\uDC85\uDC8F\uDC91\uDCAA\uDD7A\uDD95\uDD96\uDE2E\uDE35\uDE36\uDE4C\uDE4F\uDEC0\uDECC]|\uD83E[\uDD0C\uDD0F\uDD18-\uDD1C\uDD1E\uDD1F\uDD30-\uDD34\uDD36\uDD77\uDDB5\uDDB6\uDDBB\uDDD2\uDDD3\uDDD5]|\uD83C[\uDFC3\uDFC4\uDFCA]|\uD83D[\uDC6E\uDC70\uDC71\uDC73\uDC77\uDC81\uDC82\uDC86\uDC87\uDE45-\uDE47\uDE4B\uDE4D\uDE4E\uDEA3\uDEB4-\uDEB6]|\uD83E[\uDD26\uDD35\uDD37-\uDD39\uDD3D\uDD3E\uDDB8\uDDB9\uDDCD-\uDDCF\uDDD4\uDDD6-\uDDDD]|\uD83D\uDC6F|\uD83E[\uDD3C\uDDDE\uDDDF]|[\u231A\u231B\u23E9-\u23EC\u23F0\u23F3\u25FD\u25FE\u2614\u2615\u2648-\u2653\u267F\u2693\u26A1\u26AA\u26AB\u26BD\u26BE\u26C4\u26C5\u26CE\u26D4\u26EA\u26F2\u26F3\u26F5\u26FA\u26FD\u2705\u2728\u274C\u274E\u2753-\u2755\u2757\u2795-\u2797\u27B0\u27BF\u2B1B\u2B1C\u2B50\u2B55]|\uD83C[\uDC04\uDCCF\uDD8E\uDD91-\uDD9A\uDE01\uDE1A\uDE2F\uDE32-\uDE36\uDE38-\uDE3A\uDE50\uDE51\uDF00-\uDF20\uDF2D-\uDF35\uDF37-\uDF7C\uDF7E-\uDF84\uDF86-\uDF93\uDFA0-\uDFC1\uDFC5\uDFC6\uDFC8\uDFC9\uDFCF-\uDFD3\uDFE0-\uDFF0\uDFF8-\uDFFF]|\uD83D[\uDC00-\uDC07\uDC09-\uDC14\uDC16-\uDC3A\uDC3C-\uDC3E\uDC40\uDC44\uDC45\uDC51-\uDC65\uDC6A\uDC79-\uDC7B\uDC7D-\uDC80\uDC84\uDC88-\uDC8E\uDC90\uDC92-\uDCA9\uDCAB-\uDCFC\uDCFF-\uDD3D\uDD4B-\uDD4E\uDD50-\uDD67\uDDA4\uDDFB-\uDE2D\uDE2F-\uDE34\uDE37-\uDE44\uDE48-\uDE4A\uDE80-\uDEA2\uDEA4-\uDEB3\uDEB7-\uDEBF\uDEC1-\uDEC5\uDED0-\uDED2\uDED5-\uDED7\uDEEB\uDEEC\uDEF4-\uDEFC\uDFE0-\uDFEB]|\uD83E[\uDD0D\uDD0E\uDD10-\uDD17\uDD1D\uDD20-\uDD25\uDD27-\uDD2F\uDD3A\uDD3F-\uDD45\uDD47-\uDD76\uDD78\uDD7A-\uDDB4\uDDB7\uDDBA\uDDBC-\uDDCB\uDDD0\uDDE0-\uDDFF\uDE70-\uDE74\uDE78-\uDE7A\uDE80-\uDE86\uDE90-\uDEA8\uDEB0-\uDEB6\uDEC0-\uDEC2\uDED0-\uDED6]|(?:[\u231A\u231B\u23E9-\u23EC\u23F0\u23F3\u25FD\u25FE\u2614\u2615\u2648-\u2653\u267F\u2693\u26A1\u26AA\u26AB\u26BD\u26BE\u26C4\u26C5\u26CE\u26D4\u26EA\u26F2\u26F3\u26F5\u26FA\u26FD\u2705\u270A\u270B\u2728\u274C\u274E\u2753-\u2755\u2757\u2795-\u2797\u27B0\u27BF\u2B1B\u2B1C\u2B50\u2B55]|\uD83C[\uDC04\uDCCF\uDD8E\uDD91-\uDD9A\uDDE6-\uDDFF\uDE01\uDE1A\uDE2F\uDE32-\uDE36\uDE38-\uDE3A\uDE50\uDE51\uDF00-\uDF20\uDF2D-\uDF35\uDF37-\uDF7C\uDF7E-\uDF93\uDFA0-\uDFCA\uDFCF-\uDFD3\uDFE0-\uDFF0\uDFF4\uDFF8-\uDFFF]|\uD83D[\uDC00-\uDC3E\uDC40\uDC42-\uDCFC\uDCFF-\uDD3D\uDD4B-\uDD4E\uDD50-\uDD67\uDD7A\uDD95\uDD96\uDDA4\uDDFB-\uDE4F\uDE80-\uDEC5\uDECC\uDED0-\uDED2\uDED5-\uDED7\uDEEB\uDEEC\uDEF4-\uDEFC\uDFE0-\uDFEB]|\uD83E[\uDD0C-\uDD3A\uDD3C-\uDD45\uDD47-\uDD78\uDD7A-\uDDCB\uDDCD-\uDDFF\uDE70-\uDE74\uDE78-\uDE7A\uDE80-\uDE86\uDE90-\uDEA8\uDEB0-\uDEB6\uDEC0-\uDEC2\uDED0-\uDED6])|(?:[#\*0-9\xA9\xAE\u203C\u2049\u2122\u2139\u2194-\u2199\u21A9\u21AA\u231A\u231B\u2328\u23CF\u23E9-\u23F3\u23F8-\u23FA\u24C2\u25AA\u25AB\u25B6\u25C0\u25FB-\u25FE\u2600-\u2604\u260E\u2611\u2614\u2615\u2618\u261D\u2620\u2622\u2623\u2626\u262A\u262E\u262F\u2638-\u263A\u2640\u2642\u2648-\u2653\u265F\u2660\u2663\u2665\u2666\u2668\u267B\u267E\u267F\u2692-\u2697\u2699\u269B\u269C\u26A0\u26A1\u26A7\u26AA\u26AB\u26B0\u26B1\u26BD\u26BE\u26C4\u26C5\u26C8\u26CE\u26CF\u26D1\u26D3\u26D4\u26E9\u26EA\u26F0-\u26F5\u26F7-\u26FA\u26FD\u2702\u2705\u2708-\u270D\u270F\u2712\u2714\u2716\u271D\u2721\u2728\u2733\u2734\u2744\u2747\u274C\u274E\u2753-\u2755\u2757\u2763\u2764\u2795-\u2797\u27A1\u27B0\u27BF\u2934\u2935\u2B05-\u2B07\u2B1B\u2B1C\u2B50\u2B55\u3030\u303D\u3297\u3299]|\uD83C[\uDC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DD1-\uDDDD])/g;
1044
- };
1045
-
1046
- function stringWidth(string) {
1047
- if (typeof string !== 'string' || string.length === 0) {
1048
- return 0;
1049
- }
1050
-
1051
- string = stripAnsi(string);
1052
-
1053
- if (string.length === 0) {
1054
- return 0;
1055
- }
1056
-
1057
- string = string.replace(emojiRegex(), ' ');
1058
-
1059
- let width = 0;
1060
-
1061
- for (let index = 0; index < string.length; index++) {
1062
- const codePoint = string.codePointAt(index);
1063
-
1064
- // Ignore control characters
1065
- if (codePoint <= 0x1F || (codePoint >= 0x7F && codePoint <= 0x9F)) {
1066
- continue;
1067
- }
1068
-
1069
- // Ignore combining characters
1070
- if (codePoint >= 0x300 && codePoint <= 0x36F) {
1071
- continue;
1072
- }
1073
-
1074
- // Surrogates
1075
- if (codePoint > 0xFFFF) {
1076
- index++;
1077
- }
1078
-
1079
- width += isFullwidthCodePoint(codePoint) ? 2 : 1;
1080
- }
1081
-
1082
- return width;
1083
- }
1084
-
1085
- function getIndexOfNearestSpace(string, wantedIndex, shouldSearchRight) {
1086
- if (string.charAt(wantedIndex) === ' ') {
1087
- return wantedIndex;
1088
- }
1089
-
1090
- for (let index = 1; index <= 3; index++) {
1091
- if (shouldSearchRight) {
1092
- if (string.charAt(wantedIndex + index) === ' ') {
1093
- return wantedIndex + index;
1094
- }
1095
- } else if (string.charAt(wantedIndex - index) === ' ') {
1096
- return wantedIndex - index;
1097
- }
1098
- }
1099
-
1100
- return wantedIndex;
1101
- }
1102
-
1103
- function cliTruncate(text, columns, options) {
1104
- options = {
1105
- position: 'end',
1106
- preferTruncationOnSpace: false,
1107
- truncationCharacter: '…',
1108
- ...options,
1109
- };
1110
-
1111
- const {position, space, preferTruncationOnSpace} = options;
1112
- let {truncationCharacter} = options;
1113
-
1114
- if (typeof text !== 'string') {
1115
- throw new TypeError(`Expected \`input\` to be a string, got ${typeof text}`);
1116
- }
1117
-
1118
- if (typeof columns !== 'number') {
1119
- throw new TypeError(`Expected \`columns\` to be a number, got ${typeof columns}`);
1120
- }
1121
-
1122
- if (columns < 1) {
1123
- return '';
1124
- }
1125
-
1126
- if (columns === 1) {
1127
- return truncationCharacter;
1128
- }
1129
-
1130
- const length = stringWidth(text);
1131
-
1132
- if (length <= columns) {
1133
- return text;
1134
- }
1135
-
1136
- if (position === 'start') {
1137
- if (preferTruncationOnSpace) {
1138
- const nearestSpace = getIndexOfNearestSpace(text, length - columns + 1, true);
1139
- return truncationCharacter + sliceAnsi(text, nearestSpace, length).trim();
1140
- }
1141
-
1142
- if (space === true) {
1143
- truncationCharacter += ' ';
1144
- }
1145
-
1146
- return truncationCharacter + sliceAnsi(text, length - columns + stringWidth(truncationCharacter), length);
1147
- }
1148
-
1149
- if (position === 'middle') {
1150
- if (space === true) {
1151
- truncationCharacter = ` ${truncationCharacter} `;
1152
- }
1153
-
1154
- const half = Math.floor(columns / 2);
1155
-
1156
- if (preferTruncationOnSpace) {
1157
- const spaceNearFirstBreakPoint = getIndexOfNearestSpace(text, half);
1158
- const spaceNearSecondBreakPoint = getIndexOfNearestSpace(text, length - (columns - half) + 1, true);
1159
- return sliceAnsi(text, 0, spaceNearFirstBreakPoint) + truncationCharacter + sliceAnsi(text, spaceNearSecondBreakPoint, length).trim();
1160
- }
1161
-
1162
- return (
1163
- sliceAnsi(text, 0, half)
1164
- + truncationCharacter
1165
- + sliceAnsi(text, length - (columns - half) + stringWidth(truncationCharacter), length)
1166
- );
1167
- }
1168
-
1169
- if (position === 'end') {
1170
- if (preferTruncationOnSpace) {
1171
- const nearestSpace = getIndexOfNearestSpace(text, columns - 1);
1172
- return sliceAnsi(text, 0, nearestSpace) + truncationCharacter;
1173
- }
1174
-
1175
- if (space === true) {
1176
- truncationCharacter = ` ${truncationCharacter}`;
1177
- }
1178
-
1179
- return sliceAnsi(text, 0, columns - stringWidth(truncationCharacter)) + truncationCharacter;
1180
- }
1181
-
1182
- throw new Error(`Expected \`options.position\` to be either \`start\`, \`middle\` or \`end\`, got ${position}`);
1183
- }
1184
-
1185
- const F_RIGHT = "\u2192";
1186
- const F_DOWN = "\u2193";
1187
- const F_DOWN_RIGHT = "\u21B3";
1188
- const F_POINTER = "\u276F";
1189
- const F_DOT = "\xB7";
1190
- const F_CHECK = "\u221A";
1191
- const F_CROSS = "\xD7";
1192
- const F_LONG_DASH = "\u23AF";
1193
-
1194
- async function printError(error, ctx) {
1195
- let e = error;
1196
- if (typeof error === "string") {
1197
- e = {
1198
- message: error.split(/\n/g)[0],
1199
- stack: error
1200
- };
1201
- }
1202
- const stackStr = e.stack || e.stackStr || "";
1203
- const stacks = parseStack(stackStr);
1204
- if (!stacks.length) {
1205
- ctx.console.error(e);
1206
- } else {
1207
- const nearest = stacks.find((stack) => {
1208
- return !stack.file.includes("vitest/dist") && ctx.server.moduleGraph.getModuleById(stack.file) && existsSync(stack.file);
1209
- });
1210
- printErrorMessage(e);
1211
- await printStack(ctx, stacks, nearest, async (s, pos) => {
1212
- if (s === nearest) {
1213
- const sourceCode = await promises.readFile(nearest.file, "utf-8");
1214
- ctx.console.log(c.yellow(generateCodeFrame(sourceCode, 4, pos)));
1215
- }
1216
- });
1217
- }
1218
- handleImportOutsideModuleError(stackStr, ctx);
1219
- if (e.showDiff)
1220
- displayDiff(e.actual, e.expected);
1221
- }
1222
- const esmErrors = [
1223
- "Cannot use import statement outside a module",
1224
- "Unexpected token 'export'"
1225
- ];
1226
- function handleImportOutsideModuleError(stack, ctx) {
1227
- if (!esmErrors.some((e) => stack.includes(e)))
1228
- return;
1229
- const path = stack.split("\n")[0].trim();
1230
- let name = path.split("/node_modules/").pop() || "";
1231
- if (name == null ? void 0 : name.startsWith("@"))
1232
- name = name.split("/").slice(0, 2).join("/");
1233
- else
1234
- name = name.split("/")[0];
1235
- ctx.console.error(c.yellow(`Module ${path} seems to be an ES Module but shipped in a CommonJS package. You might want to create an issue to the package ${c.bold(`"${name}"`)} asking them to ship the file in .mjs extension or add "type": "module" in their package.json.
1236
-
1237
- As a temporary workaround you can try to inline the package by updating your config:
1238
-
1239
- ` + c.gray(c.dim("// vitest.config.js")) + "\n" + c.green(`export default {
1240
- test: {
1241
- deps: {
1242
- inline: [
1243
- ${c.yellow(c.bold(`"${name}"`))}
1244
- ]
1245
- }
1246
- }
1247
- }
1248
- `)));
1249
- }
1250
- async function getSourcePos(ctx, nearest) {
1251
- const mod = ctx.server.moduleGraph.getModuleById(nearest.file);
1252
- const transformResult = mod == null ? void 0 : mod.ssrTransformResult;
1253
- const pos = await getOriginalPos(transformResult == null ? void 0 : transformResult.map, nearest);
1254
- return pos;
1255
- }
1256
- function displayDiff(actual, expected) {
1257
- console.error(c.gray(unifiedDiff(stringify(actual), stringify(expected))));
1258
- }
1259
- function printErrorMessage(error) {
1260
- const errorName = error.name || error.nameStr || "Unknown Error";
1261
- console.error(c.red(`${c.bold(errorName)}: ${error.message}`));
1262
- }
1263
- async function printStack(ctx, stack, highlight, onStack) {
1264
- if (!stack.length)
1265
- return;
1266
- for (const frame of stack) {
1267
- const pos = await getSourcePos(ctx, frame) || frame;
1268
- const color = frame === highlight ? c.yellow : c.gray;
1269
- const path = relative(ctx.config.root, frame.file);
1270
- if (!ctx.config.silent)
1271
- ctx.console.log(color(` ${c.dim(F_POINTER)} ${[frame.method, c.dim(`${path}:${pos.line}:${pos.column}`)].filter(Boolean).join(" ")}`));
1272
- await (onStack == null ? void 0 : onStack(frame, pos));
1273
- if (frame.file in ctx.state.filesMap)
1274
- break;
1275
- }
1276
- if (!ctx.config.silent)
1277
- ctx.console.log();
1278
- }
1279
- function getOriginalPos(map, { line, column }) {
1280
- return new Promise((resolve) => {
1281
- if (!map)
1282
- return resolve(null);
1283
- SourceMapConsumer.with(map, null, (consumer) => {
1284
- const pos = consumer.originalPositionFor({ line, column });
1285
- if (pos.line != null && pos.column != null)
1286
- resolve(pos);
1287
- else
1288
- resolve(null);
1289
- });
1290
- });
1291
- }
1292
- const splitRE = /\r?\n/;
1293
- function posToNumber(source, pos) {
1294
- if (typeof pos === "number")
1295
- return pos;
1296
- const lines = source.split(splitRE);
1297
- const { line, column } = pos;
1298
- let start = 0;
1299
- if (line > lines.length)
1300
- return source.length;
1301
- for (let i = 0; i < line - 1; i++)
1302
- start += lines[i].length + 1;
1303
- return start + column;
1304
- }
1305
- function generateCodeFrame(source, indent = 0, start = 0, end, range = 2) {
1306
- start = posToNumber(source, start);
1307
- end = end || start;
1308
- const lines = source.split(splitRE);
1309
- let count = 0;
1310
- let res = [];
1311
- function lineNo(no = "") {
1312
- return c.gray(`${String(no).padStart(3, " ")}| `);
1313
- }
1314
- for (let i = 0; i < lines.length; i++) {
1315
- count += lines[i].length + 1;
1316
- if (count >= start) {
1317
- for (let j = i - range; j <= i + range || end > count; j++) {
1318
- if (j < 0 || j >= lines.length)
1319
- continue;
1320
- const lineLength = lines[j].length;
1321
- if (lineLength > 200)
1322
- return "";
1323
- res.push(lineNo(j + 1) + cliTruncate(lines[j], process.stdout.columns - 5 - indent));
1324
- if (j === i) {
1325
- const pad = start - (count - lineLength);
1326
- const length = Math.max(1, end > count ? lineLength - pad : end - start);
1327
- res.push(lineNo() + " ".repeat(pad) + c.red("^".repeat(length)));
1328
- } else if (j > i) {
1329
- if (end > count) {
1330
- const length = Math.max(1, Math.min(end - count, lineLength));
1331
- res.push(lineNo() + c.red("^".repeat(length)));
1332
- }
1333
- count += lineLength + 1;
1334
- }
1335
- }
1336
- break;
1337
- }
1338
- }
1339
- if (indent)
1340
- res = res.map((line) => " ".repeat(indent) + line);
1341
- return res.join("\n");
1342
- }
1343
- function stringify(obj) {
1344
- return format(obj);
1345
- }
1346
- const stackFnCallRE = /at (.*) \((.+):(\d+):(\d+)\)$/;
1347
- const stackBarePathRE = /at ?(.*) (.+):(\d+):(\d+)$/;
1348
- function parseStack(stack) {
1349
- const lines = stack.split("\n");
1350
- const stackFrames = lines.map((raw) => {
1351
- const line = raw.trim();
1352
- const match = line.match(stackFnCallRE) || line.match(stackBarePathRE);
1353
- if (!match)
1354
- return null;
1355
- let file = match[2];
1356
- if (file.startsWith("file://"))
1357
- file = file.slice(7);
1358
- return {
1359
- method: match[1],
1360
- file: match[2],
1361
- line: parseInt(match[3]),
1362
- column: parseInt(match[4])
1363
- };
1364
- });
1365
- return stackFrames.filter(notNullish);
1366
- }
1367
- function unifiedDiff(actual, expected) {
1368
- if (actual === expected)
1369
- return "";
1370
- const diffLimit = 10;
1371
- const indent = " ";
1372
- let expectedLinesCount = 0;
1373
- let actualLinesCount = 0;
1374
- function cleanUp(line) {
1375
- if (line[0] === "+") {
1376
- if (expectedLinesCount >= diffLimit)
1377
- return;
1378
- expectedLinesCount++;
1379
- line = line[0] + " " + line.slice(1);
1380
- const isLastLine = expectedLinesCount === diffLimit;
1381
- return indent + c.red(`${formatLine(line)} ${isLastLine ? renderTruncateMessage(indent) : ""}`);
1382
- }
1383
- if (line[0] === "-") {
1384
- if (actualLinesCount >= diffLimit)
1385
- return;
1386
- actualLinesCount++;
1387
- line = line[0] + " " + line.slice(1);
1388
- const isLastLine = actualLinesCount === diffLimit;
1389
- return indent + c.green(`${formatLine(line)} ${isLastLine ? renderTruncateMessage(indent) : ""}`);
1390
- }
1391
- if (line.match(/@@/))
1392
- return "--";
1393
- if (line.match(/\\ No newline/))
1394
- return null;
1395
- return indent + " " + line;
1396
- }
1397
- const msg = createPatch("string", actual, expected);
1398
- const lines = msg.split("\n").splice(5);
1399
- return `
1400
- ${indent}${c.green("- expected")}
1401
- ${indent}${c.red("+ actual")}
1402
-
1403
- ${lines.map(cleanUp).filter(notBlank).join("\n")}`;
1404
- }
1405
- function formatLine(line) {
1406
- return cliTruncate(line, (process.stdout.columns || 40) - 1);
1407
- }
1408
- function renderTruncateMessage(indent) {
1409
- return `
1410
- ${indent}${c.dim("[...truncated]")}`;
1411
- }
1412
- function notBlank(line) {
1413
- return typeof line !== "undefined" && line !== null;
1414
- }
1415
-
1416
- export { F_POINTER as F, ansiStyles as a, stripAnsi as b, sliceAnsi as c, F_DOWN as d, F_LONG_DASH as e, F_DOWN_RIGHT as f, F_DOT as g, F_CHECK as h, F_CROSS as i, cliTruncate as j, F_RIGHT as k, printError as p, stringWidth as s, unifiedDiff as u };