vitest 0.0.107 → 0.0.111
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/dist/_commonjsHelpers-c9e3b764.js +11 -0
- package/dist/cli.js +8 -9
- package/dist/{constants-82dad049.js → constants-2b0310b7.js} +1 -1
- package/dist/{error-e81aa23d.js → diff-66d6bb83.js} +51 -41
- package/dist/entry.js +37 -456
- package/dist/global-201fd559.js +20 -0
- package/dist/{index-77f19d39.js → index-2bb9fd4d.js} +12 -5
- package/dist/{index-84978a77.js → index-61c8686f.js} +1 -1
- package/dist/{index-8cc284f9.js → index-8ab26d25.js} +1768 -1563
- package/dist/{index-1ede1cc5.js → index-9f4b9905.js} +2 -6
- package/dist/index.d.ts +178 -19
- package/dist/index.js +6 -5
- package/dist/jest-mock-a57b745c.js +101 -0
- package/dist/{middleware-0c8d46aa.js → middleware-2028dfa0.js} +2 -4
- package/dist/node.d.ts +62 -1
- package/dist/node.js +6 -7
- package/dist/utils-cb6b1266.js +352 -0
- package/dist/utils.js +1 -3
- package/dist/vi-cb9e4e4e.js +1018 -0
- package/dist/worker.js +142 -72
- package/package.json +6 -6
- package/dist/global-0f4da031.js +0 -19
- package/dist/index-9e71c815.js +0 -12
- package/dist/suite-ff89a82e.js +0 -201
- package/dist/utils-92ec89d1.js +0 -814
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { c,
|
|
1
|
+
import { c, s as slash$1, i as isAbsolute, r as relative, d as dirname, b as basename, g as getFullName, a as getTests, f as getSuites, h as resolve, n as noop$1, t as toArray, j as hasFailed } from './utils-cb6b1266.js';
|
|
2
2
|
import { createServer, mergeConfig } from 'vite';
|
|
3
3
|
import path$a from 'path';
|
|
4
4
|
import process$1 from 'process';
|
|
@@ -7,10 +7,10 @@ import require$$0 from 'os';
|
|
|
7
7
|
import require$$0$1 from 'util';
|
|
8
8
|
import require$$0$2 from 'stream';
|
|
9
9
|
import require$$2 from 'events';
|
|
10
|
-
import { d as defaultInclude, a as defaultExclude, b as defaultPort, c as distDir, e as configFiles } from './constants-
|
|
10
|
+
import { d as defaultInclude, a as defaultExclude, b as defaultPort, c as distDir, e as configFiles } from './constants-2b0310b7.js';
|
|
11
11
|
import { performance } from 'perf_hooks';
|
|
12
|
-
import {
|
|
13
|
-
import { o as onetime, s as signalExit } from './index-
|
|
12
|
+
import { F as F_POINTER, a as F_DOWN, s as stripAnsi, b as F_LONG_DASH, c as F_DOWN_RIGHT, d as F_DOT, e as F_CHECK, f as F_CROSS, g as F_RIGHT, p as printError, h as stringWidth, i as ansiStyles, j as sliceAnsi, k as cliTruncate } from './diff-66d6bb83.js';
|
|
13
|
+
import { o as onetime, s as signalExit } from './index-61c8686f.js';
|
|
14
14
|
import { MessageChannel } from 'worker_threads';
|
|
15
15
|
import { pathToFileURL } from 'url';
|
|
16
16
|
import { Tinypool } from 'tinypool';
|
|
@@ -6750,1938 +6750,2135 @@ function addSnapshotResult(summary, result) {
|
|
|
6750
6750
|
summary.total += result.added + result.matched + result.unmatched + result.updated;
|
|
6751
6751
|
}
|
|
6752
6752
|
|
|
6753
|
-
|
|
6754
|
-
|
|
6755
|
-
|
|
6756
|
-
|
|
6757
|
-
|
|
6758
|
-
|
|
6759
|
-
|
|
6753
|
+
var charToInteger = {};
|
|
6754
|
+
var chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
|
|
6755
|
+
for (var i = 0; i < chars.length; i++) {
|
|
6756
|
+
charToInteger[chars.charCodeAt(i)] = i;
|
|
6757
|
+
}
|
|
6758
|
+
function encode(decoded) {
|
|
6759
|
+
var sourceFileIndex = 0; // second field
|
|
6760
|
+
var sourceCodeLine = 0; // third field
|
|
6761
|
+
var sourceCodeColumn = 0; // fourth field
|
|
6762
|
+
var nameIndex = 0; // fifth field
|
|
6763
|
+
var mappings = '';
|
|
6764
|
+
for (var i = 0; i < decoded.length; i++) {
|
|
6765
|
+
var line = decoded[i];
|
|
6766
|
+
if (i > 0)
|
|
6767
|
+
mappings += ';';
|
|
6768
|
+
if (line.length === 0)
|
|
6769
|
+
continue;
|
|
6770
|
+
var generatedCodeColumn = 0; // first field
|
|
6771
|
+
var lineMappings = [];
|
|
6772
|
+
for (var _i = 0, line_1 = line; _i < line_1.length; _i++) {
|
|
6773
|
+
var segment = line_1[_i];
|
|
6774
|
+
var segmentMappings = encodeInteger(segment[0] - generatedCodeColumn);
|
|
6775
|
+
generatedCodeColumn = segment[0];
|
|
6776
|
+
if (segment.length > 1) {
|
|
6777
|
+
segmentMappings +=
|
|
6778
|
+
encodeInteger(segment[1] - sourceFileIndex) +
|
|
6779
|
+
encodeInteger(segment[2] - sourceCodeLine) +
|
|
6780
|
+
encodeInteger(segment[3] - sourceCodeColumn);
|
|
6781
|
+
sourceFileIndex = segment[1];
|
|
6782
|
+
sourceCodeLine = segment[2];
|
|
6783
|
+
sourceCodeColumn = segment[3];
|
|
6784
|
+
}
|
|
6785
|
+
if (segment.length === 5) {
|
|
6786
|
+
segmentMappings += encodeInteger(segment[4] - nameIndex);
|
|
6787
|
+
nameIndex = segment[4];
|
|
6788
|
+
}
|
|
6789
|
+
lineMappings.push(segmentMappings);
|
|
6790
|
+
}
|
|
6791
|
+
mappings += lineMappings.join(',');
|
|
6792
|
+
}
|
|
6793
|
+
return mappings;
|
|
6794
|
+
}
|
|
6795
|
+
function encodeInteger(num) {
|
|
6796
|
+
var result = '';
|
|
6797
|
+
num = num < 0 ? (-num << 1) | 1 : num << 1;
|
|
6798
|
+
do {
|
|
6799
|
+
var clamped = num & 31;
|
|
6800
|
+
num >>>= 5;
|
|
6801
|
+
if (num > 0) {
|
|
6802
|
+
clamped |= 32;
|
|
6803
|
+
}
|
|
6804
|
+
result += chars[clamped];
|
|
6805
|
+
} while (num > 0);
|
|
6806
|
+
return result;
|
|
6807
|
+
}
|
|
6760
6808
|
|
|
6761
|
-
|
|
6762
|
-
|
|
6763
|
-
|
|
6764
|
-
}
|
|
6809
|
+
var BitSet = function BitSet(arg) {
|
|
6810
|
+
this.bits = arg instanceof BitSet ? arg.bits.slice() : [];
|
|
6811
|
+
};
|
|
6765
6812
|
|
|
6766
|
-
|
|
6767
|
-
|
|
6768
|
-
|
|
6813
|
+
BitSet.prototype.add = function add (n) {
|
|
6814
|
+
this.bits[n >> 5] |= 1 << (n & 31);
|
|
6815
|
+
};
|
|
6769
6816
|
|
|
6770
|
-
|
|
6817
|
+
BitSet.prototype.has = function has (n) {
|
|
6818
|
+
return !!(this.bits[n >> 5] & (1 << (n & 31)));
|
|
6771
6819
|
};
|
|
6772
6820
|
|
|
6773
|
-
|
|
6774
|
-
|
|
6775
|
-
|
|
6776
|
-
|
|
6821
|
+
var Chunk = function Chunk(start, end, content) {
|
|
6822
|
+
this.start = start;
|
|
6823
|
+
this.end = end;
|
|
6824
|
+
this.original = content;
|
|
6777
6825
|
|
|
6778
|
-
|
|
6826
|
+
this.intro = '';
|
|
6827
|
+
this.outro = '';
|
|
6779
6828
|
|
|
6780
|
-
|
|
6781
|
-
|
|
6782
|
-
|
|
6783
|
-
returnValue += ESC + x + 'C';
|
|
6784
|
-
}
|
|
6829
|
+
this.content = content;
|
|
6830
|
+
this.storeName = false;
|
|
6831
|
+
this.edited = false;
|
|
6785
6832
|
|
|
6786
|
-
|
|
6787
|
-
|
|
6788
|
-
|
|
6789
|
-
|
|
6790
|
-
}
|
|
6833
|
+
// we make these non-enumerable, for sanity while debugging
|
|
6834
|
+
Object.defineProperties(this, {
|
|
6835
|
+
previous: { writable: true, value: null },
|
|
6836
|
+
next: { writable: true, value: null }
|
|
6837
|
+
});
|
|
6838
|
+
};
|
|
6791
6839
|
|
|
6792
|
-
|
|
6840
|
+
Chunk.prototype.appendLeft = function appendLeft (content) {
|
|
6841
|
+
this.outro += content;
|
|
6793
6842
|
};
|
|
6794
6843
|
|
|
6795
|
-
|
|
6796
|
-
|
|
6797
|
-
|
|
6798
|
-
ansiEscapes.cursorBackward = (count = 1) => ESC + count + 'D';
|
|
6844
|
+
Chunk.prototype.appendRight = function appendRight (content) {
|
|
6845
|
+
this.intro = this.intro + content;
|
|
6846
|
+
};
|
|
6799
6847
|
|
|
6800
|
-
|
|
6801
|
-
|
|
6802
|
-
ansiEscapes.cursorRestorePosition = isTerminalApp ? '\u001B8' : ESC + 'u';
|
|
6803
|
-
ansiEscapes.cursorGetPosition = ESC + '6n';
|
|
6804
|
-
ansiEscapes.cursorNextLine = ESC + 'E';
|
|
6805
|
-
ansiEscapes.cursorPrevLine = ESC + 'F';
|
|
6806
|
-
ansiEscapes.cursorHide = ESC + '?25l';
|
|
6807
|
-
ansiEscapes.cursorShow = ESC + '?25h';
|
|
6848
|
+
Chunk.prototype.clone = function clone () {
|
|
6849
|
+
var chunk = new Chunk(this.start, this.end, this.original);
|
|
6808
6850
|
|
|
6809
|
-
|
|
6810
|
-
|
|
6851
|
+
chunk.intro = this.intro;
|
|
6852
|
+
chunk.outro = this.outro;
|
|
6853
|
+
chunk.content = this.content;
|
|
6854
|
+
chunk.storeName = this.storeName;
|
|
6855
|
+
chunk.edited = this.edited;
|
|
6811
6856
|
|
|
6812
|
-
|
|
6813
|
-
|
|
6814
|
-
}
|
|
6857
|
+
return chunk;
|
|
6858
|
+
};
|
|
6815
6859
|
|
|
6816
|
-
|
|
6817
|
-
|
|
6860
|
+
Chunk.prototype.contains = function contains (index) {
|
|
6861
|
+
return this.start < index && index < this.end;
|
|
6862
|
+
};
|
|
6863
|
+
|
|
6864
|
+
Chunk.prototype.eachNext = function eachNext (fn) {
|
|
6865
|
+
var chunk = this;
|
|
6866
|
+
while (chunk) {
|
|
6867
|
+
fn(chunk);
|
|
6868
|
+
chunk = chunk.next;
|
|
6818
6869
|
}
|
|
6870
|
+
};
|
|
6819
6871
|
|
|
6820
|
-
|
|
6872
|
+
Chunk.prototype.eachPrevious = function eachPrevious (fn) {
|
|
6873
|
+
var chunk = this;
|
|
6874
|
+
while (chunk) {
|
|
6875
|
+
fn(chunk);
|
|
6876
|
+
chunk = chunk.previous;
|
|
6877
|
+
}
|
|
6821
6878
|
};
|
|
6822
6879
|
|
|
6823
|
-
|
|
6824
|
-
|
|
6825
|
-
|
|
6826
|
-
|
|
6827
|
-
|
|
6828
|
-
|
|
6829
|
-
|
|
6830
|
-
ansiEscapes.scrollDown = ESC + 'T';
|
|
6880
|
+
Chunk.prototype.edit = function edit (content, storeName, contentOnly) {
|
|
6881
|
+
this.content = content;
|
|
6882
|
+
if (!contentOnly) {
|
|
6883
|
+
this.intro = '';
|
|
6884
|
+
this.outro = '';
|
|
6885
|
+
}
|
|
6886
|
+
this.storeName = storeName;
|
|
6831
6887
|
|
|
6832
|
-
|
|
6888
|
+
this.edited = true;
|
|
6833
6889
|
|
|
6834
|
-
|
|
6835
|
-
|
|
6836
|
-
// 1. Erases the screen (Only done in case `2` is not supported)
|
|
6837
|
-
// 2. Erases the whole screen including scrollback buffer
|
|
6838
|
-
// 3. Moves cursor to the top-left position
|
|
6839
|
-
// More info: https://www.real-world-systems.com/docs/ANSIcode.html
|
|
6840
|
-
`${ansiEscapes.eraseScreen}${ESC}3J${ESC}H`;
|
|
6890
|
+
return this;
|
|
6891
|
+
};
|
|
6841
6892
|
|
|
6842
|
-
|
|
6893
|
+
Chunk.prototype.prependLeft = function prependLeft (content) {
|
|
6894
|
+
this.outro = content + this.outro;
|
|
6895
|
+
};
|
|
6843
6896
|
|
|
6844
|
-
|
|
6845
|
-
|
|
6846
|
-
OSC,
|
|
6847
|
-
'8',
|
|
6848
|
-
SEP,
|
|
6849
|
-
SEP,
|
|
6850
|
-
url,
|
|
6851
|
-
BEL,
|
|
6852
|
-
text,
|
|
6853
|
-
OSC,
|
|
6854
|
-
'8',
|
|
6855
|
-
SEP,
|
|
6856
|
-
SEP,
|
|
6857
|
-
BEL
|
|
6858
|
-
].join('');
|
|
6897
|
+
Chunk.prototype.prependRight = function prependRight (content) {
|
|
6898
|
+
this.intro = content + this.intro;
|
|
6859
6899
|
};
|
|
6860
6900
|
|
|
6861
|
-
|
|
6862
|
-
|
|
6901
|
+
Chunk.prototype.split = function split (index) {
|
|
6902
|
+
var sliceIndex = index - this.start;
|
|
6863
6903
|
|
|
6864
|
-
|
|
6865
|
-
|
|
6866
|
-
}
|
|
6904
|
+
var originalBefore = this.original.slice(0, sliceIndex);
|
|
6905
|
+
var originalAfter = this.original.slice(sliceIndex);
|
|
6867
6906
|
|
|
6868
|
-
|
|
6869
|
-
returnValue += `;height=${options.height}`;
|
|
6870
|
-
}
|
|
6907
|
+
this.original = originalBefore;
|
|
6871
6908
|
|
|
6872
|
-
|
|
6873
|
-
|
|
6909
|
+
var newChunk = new Chunk(index, this.end, originalAfter);
|
|
6910
|
+
newChunk.outro = this.outro;
|
|
6911
|
+
this.outro = '';
|
|
6912
|
+
|
|
6913
|
+
this.end = index;
|
|
6914
|
+
|
|
6915
|
+
if (this.edited) {
|
|
6916
|
+
// TODO is this block necessary?...
|
|
6917
|
+
newChunk.edit('', false);
|
|
6918
|
+
this.content = '';
|
|
6919
|
+
} else {
|
|
6920
|
+
this.content = originalBefore;
|
|
6874
6921
|
}
|
|
6875
6922
|
|
|
6876
|
-
|
|
6923
|
+
newChunk.next = this.next;
|
|
6924
|
+
if (newChunk.next) { newChunk.next.previous = newChunk; }
|
|
6925
|
+
newChunk.previous = this;
|
|
6926
|
+
this.next = newChunk;
|
|
6927
|
+
|
|
6928
|
+
return newChunk;
|
|
6877
6929
|
};
|
|
6878
6930
|
|
|
6879
|
-
|
|
6880
|
-
|
|
6931
|
+
Chunk.prototype.toString = function toString () {
|
|
6932
|
+
return this.intro + this.content + this.outro;
|
|
6933
|
+
};
|
|
6881
6934
|
|
|
6882
|
-
|
|
6883
|
-
|
|
6935
|
+
Chunk.prototype.trimEnd = function trimEnd (rx) {
|
|
6936
|
+
this.outro = this.outro.replace(rx, '');
|
|
6937
|
+
if (this.outro.length) { return true; }
|
|
6884
6938
|
|
|
6885
|
-
|
|
6886
|
-
const hasY = typeof options.y !== 'undefined';
|
|
6887
|
-
if ((hasX || hasY) && !(hasX && hasY && typeof options.length !== 'undefined')) {
|
|
6888
|
-
throw new Error('`x`, `y` and `length` must be defined when `x` or `y` is defined');
|
|
6889
|
-
}
|
|
6939
|
+
var trimmed = this.content.replace(rx, '');
|
|
6890
6940
|
|
|
6891
|
-
|
|
6892
|
-
|
|
6893
|
-
|
|
6894
|
-
|
|
6895
|
-
if (options.length > 0) {
|
|
6896
|
-
returnValue +=
|
|
6897
|
-
(hasX ?
|
|
6898
|
-
[message, options.length, options.x, options.y] :
|
|
6899
|
-
[options.length, message]).join('|');
|
|
6900
|
-
} else {
|
|
6901
|
-
returnValue += message;
|
|
6941
|
+
if (trimmed.length) {
|
|
6942
|
+
if (trimmed !== this.content) {
|
|
6943
|
+
this.split(this.start + trimmed.length).edit('', undefined, true);
|
|
6902
6944
|
}
|
|
6945
|
+
return true;
|
|
6903
6946
|
|
|
6904
|
-
|
|
6947
|
+
} else {
|
|
6948
|
+
this.edit('', undefined, true);
|
|
6949
|
+
|
|
6950
|
+
this.intro = this.intro.replace(rx, '');
|
|
6951
|
+
if (this.intro.length) { return true; }
|
|
6905
6952
|
}
|
|
6906
6953
|
};
|
|
6907
6954
|
|
|
6908
|
-
|
|
6909
|
-
|
|
6910
|
-
|
|
6911
|
-
}, {alwaysLast: true});
|
|
6912
|
-
});
|
|
6955
|
+
Chunk.prototype.trimStart = function trimStart (rx) {
|
|
6956
|
+
this.intro = this.intro.replace(rx, '');
|
|
6957
|
+
if (this.intro.length) { return true; }
|
|
6913
6958
|
|
|
6914
|
-
|
|
6959
|
+
var trimmed = this.content.replace(rx, '');
|
|
6915
6960
|
|
|
6916
|
-
|
|
6961
|
+
if (trimmed.length) {
|
|
6962
|
+
if (trimmed !== this.content) {
|
|
6963
|
+
this.split(this.end - trimmed.length);
|
|
6964
|
+
this.edit('', undefined, true);
|
|
6965
|
+
}
|
|
6966
|
+
return true;
|
|
6917
6967
|
|
|
6918
|
-
|
|
6919
|
-
|
|
6920
|
-
|
|
6968
|
+
} else {
|
|
6969
|
+
this.edit('', undefined, true);
|
|
6970
|
+
|
|
6971
|
+
this.outro = this.outro.replace(rx, '');
|
|
6972
|
+
if (this.outro.length) { return true; }
|
|
6921
6973
|
}
|
|
6974
|
+
};
|
|
6922
6975
|
|
|
6923
|
-
|
|
6924
|
-
|
|
6976
|
+
var btoa = function () {
|
|
6977
|
+
throw new Error('Unsupported environment: `window.btoa` or `Buffer` should be supported.');
|
|
6925
6978
|
};
|
|
6979
|
+
if (typeof window !== 'undefined' && typeof window.btoa === 'function') {
|
|
6980
|
+
btoa = function (str) { return window.btoa(unescape(encodeURIComponent(str))); };
|
|
6981
|
+
} else if (typeof Buffer === 'function') {
|
|
6982
|
+
btoa = function (str) { return Buffer.from(str, 'utf-8').toString('base64'); };
|
|
6983
|
+
}
|
|
6926
6984
|
|
|
6927
|
-
|
|
6928
|
-
|
|
6929
|
-
|
|
6930
|
-
|
|
6985
|
+
var SourceMap = function SourceMap(properties) {
|
|
6986
|
+
this.version = 3;
|
|
6987
|
+
this.file = properties.file;
|
|
6988
|
+
this.sources = properties.sources;
|
|
6989
|
+
this.sourcesContent = properties.sourcesContent;
|
|
6990
|
+
this.names = properties.names;
|
|
6991
|
+
this.mappings = encode(properties.mappings);
|
|
6992
|
+
};
|
|
6931
6993
|
|
|
6932
|
-
|
|
6933
|
-
|
|
6934
|
-
writableStream.write('\u001B[?25l');
|
|
6994
|
+
SourceMap.prototype.toString = function toString () {
|
|
6995
|
+
return JSON.stringify(this);
|
|
6935
6996
|
};
|
|
6936
6997
|
|
|
6937
|
-
|
|
6938
|
-
|
|
6939
|
-
|
|
6998
|
+
SourceMap.prototype.toUrl = function toUrl () {
|
|
6999
|
+
return 'data:application/json;charset=utf-8;base64,' + btoa(this.toString());
|
|
7000
|
+
};
|
|
7001
|
+
|
|
7002
|
+
function guessIndent(code) {
|
|
7003
|
+
var lines = code.split('\n');
|
|
7004
|
+
|
|
7005
|
+
var tabbed = lines.filter(function (line) { return /^\t+/.test(line); });
|
|
7006
|
+
var spaced = lines.filter(function (line) { return /^ {2,}/.test(line); });
|
|
7007
|
+
|
|
7008
|
+
if (tabbed.length === 0 && spaced.length === 0) {
|
|
7009
|
+
return null;
|
|
6940
7010
|
}
|
|
6941
7011
|
|
|
6942
|
-
|
|
6943
|
-
|
|
6944
|
-
|
|
6945
|
-
|
|
7012
|
+
// More lines tabbed than spaced? Assume tabs, and
|
|
7013
|
+
// default to tabs in the case of a tie (or nothing
|
|
7014
|
+
// to go on)
|
|
7015
|
+
if (tabbed.length >= spaced.length) {
|
|
7016
|
+
return '\t';
|
|
6946
7017
|
}
|
|
6947
|
-
};
|
|
6948
7018
|
|
|
6949
|
-
|
|
6950
|
-
|
|
6951
|
-
|
|
6952
|
-
|
|
7019
|
+
// Otherwise, we need to guess the multiple
|
|
7020
|
+
var min = spaced.reduce(function (previous, current) {
|
|
7021
|
+
var numSpaces = /^ +/.exec(current)[0].length;
|
|
7022
|
+
return Math.min(numSpaces, previous);
|
|
7023
|
+
}, Infinity);
|
|
6953
7024
|
|
|
6954
|
-
|
|
6955
|
-
|
|
6956
|
-
const ANSI_CSI = '[';
|
|
6957
|
-
const ANSI_OSC = ']';
|
|
6958
|
-
const ANSI_SGR_TERMINATOR = 'm';
|
|
6959
|
-
const ANSI_ESCAPE_LINK = `${ANSI_OSC}8;;`;
|
|
7025
|
+
return new Array(min + 1).join(' ');
|
|
7026
|
+
}
|
|
6960
7027
|
|
|
6961
|
-
|
|
6962
|
-
|
|
7028
|
+
function getRelativePath(from, to) {
|
|
7029
|
+
var fromParts = from.split(/[/\\]/);
|
|
7030
|
+
var toParts = to.split(/[/\\]/);
|
|
6963
7031
|
|
|
6964
|
-
//
|
|
6965
|
-
// the extra characters added by ansi escape codes
|
|
6966
|
-
const wordLengths = string => string.split(' ').map(character => stringWidth(character));
|
|
7032
|
+
fromParts.pop(); // get dirname
|
|
6967
7033
|
|
|
6968
|
-
|
|
6969
|
-
|
|
6970
|
-
|
|
6971
|
-
|
|
7034
|
+
while (fromParts[0] === toParts[0]) {
|
|
7035
|
+
fromParts.shift();
|
|
7036
|
+
toParts.shift();
|
|
7037
|
+
}
|
|
6972
7038
|
|
|
6973
|
-
|
|
6974
|
-
|
|
6975
|
-
|
|
7039
|
+
if (fromParts.length) {
|
|
7040
|
+
var i = fromParts.length;
|
|
7041
|
+
while (i--) { fromParts[i] = '..'; }
|
|
7042
|
+
}
|
|
6976
7043
|
|
|
6977
|
-
|
|
6978
|
-
|
|
7044
|
+
return fromParts.concat(toParts).join('/');
|
|
7045
|
+
}
|
|
6979
7046
|
|
|
6980
|
-
|
|
6981
|
-
rows[rows.length - 1] += character;
|
|
6982
|
-
} else {
|
|
6983
|
-
rows.push(character);
|
|
6984
|
-
visible = 0;
|
|
6985
|
-
}
|
|
7047
|
+
var toString = Object.prototype.toString;
|
|
6986
7048
|
|
|
6987
|
-
|
|
6988
|
-
|
|
6989
|
-
|
|
6990
|
-
}
|
|
7049
|
+
function isObject(thing) {
|
|
7050
|
+
return toString.call(thing) === '[object Object]';
|
|
7051
|
+
}
|
|
6991
7052
|
|
|
6992
|
-
|
|
6993
|
-
|
|
6994
|
-
|
|
6995
|
-
isInsideEscape = false;
|
|
6996
|
-
isInsideLinkEscape = false;
|
|
6997
|
-
}
|
|
6998
|
-
} else if (character === ANSI_SGR_TERMINATOR) {
|
|
6999
|
-
isInsideEscape = false;
|
|
7000
|
-
}
|
|
7053
|
+
function getLocator(source) {
|
|
7054
|
+
var originalLines = source.split('\n');
|
|
7055
|
+
var lineOffsets = [];
|
|
7001
7056
|
|
|
7002
|
-
|
|
7057
|
+
for (var i = 0, pos = 0; i < originalLines.length; i++) {
|
|
7058
|
+
lineOffsets.push(pos);
|
|
7059
|
+
pos += originalLines[i].length + 1;
|
|
7060
|
+
}
|
|
7061
|
+
|
|
7062
|
+
return function locate(index) {
|
|
7063
|
+
var i = 0;
|
|
7064
|
+
var j = lineOffsets.length;
|
|
7065
|
+
while (i < j) {
|
|
7066
|
+
var m = (i + j) >> 1;
|
|
7067
|
+
if (index < lineOffsets[m]) {
|
|
7068
|
+
j = m;
|
|
7069
|
+
} else {
|
|
7070
|
+
i = m + 1;
|
|
7071
|
+
}
|
|
7003
7072
|
}
|
|
7073
|
+
var line = i - 1;
|
|
7074
|
+
var column = index - lineOffsets[line];
|
|
7075
|
+
return { line: line, column: column };
|
|
7076
|
+
};
|
|
7077
|
+
}
|
|
7004
7078
|
|
|
7005
|
-
|
|
7079
|
+
var Mappings = function Mappings(hires) {
|
|
7080
|
+
this.hires = hires;
|
|
7081
|
+
this.generatedCodeLine = 0;
|
|
7082
|
+
this.generatedCodeColumn = 0;
|
|
7083
|
+
this.raw = [];
|
|
7084
|
+
this.rawSegments = this.raw[this.generatedCodeLine] = [];
|
|
7085
|
+
this.pending = null;
|
|
7086
|
+
};
|
|
7006
7087
|
|
|
7007
|
-
|
|
7008
|
-
|
|
7009
|
-
|
|
7088
|
+
Mappings.prototype.addEdit = function addEdit (sourceIndex, content, loc, nameIndex) {
|
|
7089
|
+
if (content.length) {
|
|
7090
|
+
var segment = [this.generatedCodeColumn, sourceIndex, loc.line, loc.column];
|
|
7091
|
+
if (nameIndex >= 0) {
|
|
7092
|
+
segment.push(nameIndex);
|
|
7010
7093
|
}
|
|
7094
|
+
this.rawSegments.push(segment);
|
|
7095
|
+
} else if (this.pending) {
|
|
7096
|
+
this.rawSegments.push(this.pending);
|
|
7011
7097
|
}
|
|
7012
7098
|
|
|
7013
|
-
|
|
7014
|
-
|
|
7015
|
-
if (!visible && rows[rows.length - 1].length > 0 && rows.length > 1) {
|
|
7016
|
-
rows[rows.length - 2] += rows.pop();
|
|
7017
|
-
}
|
|
7099
|
+
this.advance(content);
|
|
7100
|
+
this.pending = null;
|
|
7018
7101
|
};
|
|
7019
7102
|
|
|
7020
|
-
|
|
7021
|
-
|
|
7022
|
-
|
|
7023
|
-
let last = words.length;
|
|
7103
|
+
Mappings.prototype.addUneditedChunk = function addUneditedChunk (sourceIndex, chunk, original, loc, sourcemapLocations) {
|
|
7104
|
+
var originalCharIndex = chunk.start;
|
|
7105
|
+
var first = true;
|
|
7024
7106
|
|
|
7025
|
-
while (
|
|
7026
|
-
if (
|
|
7027
|
-
|
|
7107
|
+
while (originalCharIndex < chunk.end) {
|
|
7108
|
+
if (this.hires || first || sourcemapLocations.has(originalCharIndex)) {
|
|
7109
|
+
this.rawSegments.push([this.generatedCodeColumn, sourceIndex, loc.line, loc.column]);
|
|
7028
7110
|
}
|
|
7029
7111
|
|
|
7030
|
-
|
|
7031
|
-
|
|
7112
|
+
if (original[originalCharIndex] === '\n') {
|
|
7113
|
+
loc.line += 1;
|
|
7114
|
+
loc.column = 0;
|
|
7115
|
+
this.generatedCodeLine += 1;
|
|
7116
|
+
this.raw[this.generatedCodeLine] = this.rawSegments = [];
|
|
7117
|
+
this.generatedCodeColumn = 0;
|
|
7118
|
+
first = true;
|
|
7119
|
+
} else {
|
|
7120
|
+
loc.column += 1;
|
|
7121
|
+
this.generatedCodeColumn += 1;
|
|
7122
|
+
first = false;
|
|
7123
|
+
}
|
|
7032
7124
|
|
|
7033
|
-
|
|
7034
|
-
return string;
|
|
7125
|
+
originalCharIndex += 1;
|
|
7035
7126
|
}
|
|
7036
7127
|
|
|
7037
|
-
|
|
7128
|
+
this.pending = null;
|
|
7038
7129
|
};
|
|
7039
7130
|
|
|
7040
|
-
|
|
7041
|
-
|
|
7042
|
-
// 'hard' will never allow a string to take up more than columns characters
|
|
7043
|
-
//
|
|
7044
|
-
// 'soft' allows long words to expand past the column length
|
|
7045
|
-
const exec = (string, columns, options = {}) => {
|
|
7046
|
-
if (options.trim !== false && string.trim() === '') {
|
|
7047
|
-
return '';
|
|
7048
|
-
}
|
|
7049
|
-
|
|
7050
|
-
let returnValue = '';
|
|
7051
|
-
let escapeCode;
|
|
7052
|
-
let escapeUrl;
|
|
7131
|
+
Mappings.prototype.advance = function advance (str) {
|
|
7132
|
+
if (!str) { return; }
|
|
7053
7133
|
|
|
7054
|
-
|
|
7055
|
-
let rows = [''];
|
|
7134
|
+
var lines = str.split('\n');
|
|
7056
7135
|
|
|
7057
|
-
|
|
7058
|
-
|
|
7059
|
-
|
|
7136
|
+
if (lines.length > 1) {
|
|
7137
|
+
for (var i = 0; i < lines.length - 1; i++) {
|
|
7138
|
+
this.generatedCodeLine++;
|
|
7139
|
+
this.raw[this.generatedCodeLine] = this.rawSegments = [];
|
|
7060
7140
|
}
|
|
7141
|
+
this.generatedCodeColumn = 0;
|
|
7142
|
+
}
|
|
7061
7143
|
|
|
7062
|
-
|
|
7144
|
+
this.generatedCodeColumn += lines[lines.length - 1].length;
|
|
7145
|
+
};
|
|
7063
7146
|
|
|
7064
|
-
|
|
7065
|
-
if (rowLength >= columns && (options.wordWrap === false || options.trim === false)) {
|
|
7066
|
-
// If we start with a new word but the current row length equals the length of the columns, add a new row
|
|
7067
|
-
rows.push('');
|
|
7068
|
-
rowLength = 0;
|
|
7069
|
-
}
|
|
7147
|
+
var n = '\n';
|
|
7070
7148
|
|
|
7071
|
-
|
|
7072
|
-
|
|
7073
|
-
|
|
7074
|
-
|
|
7075
|
-
|
|
7149
|
+
var warned = {
|
|
7150
|
+
insertLeft: false,
|
|
7151
|
+
insertRight: false,
|
|
7152
|
+
storeName: false
|
|
7153
|
+
};
|
|
7076
7154
|
|
|
7077
|
-
|
|
7078
|
-
|
|
7079
|
-
const remainingColumns = (columns - rowLength);
|
|
7080
|
-
const breaksStartingThisLine = 1 + Math.floor((lengths[index] - remainingColumns - 1) / columns);
|
|
7081
|
-
const breaksStartingNextLine = Math.floor((lengths[index] - 1) / columns);
|
|
7082
|
-
if (breaksStartingNextLine < breaksStartingThisLine) {
|
|
7083
|
-
rows.push('');
|
|
7084
|
-
}
|
|
7155
|
+
var MagicString = function MagicString(string, options) {
|
|
7156
|
+
if ( options === void 0 ) options = {};
|
|
7085
7157
|
|
|
7086
|
-
|
|
7087
|
-
continue;
|
|
7088
|
-
}
|
|
7158
|
+
var chunk = new Chunk(0, string.length, string);
|
|
7089
7159
|
|
|
7090
|
-
|
|
7091
|
-
|
|
7092
|
-
|
|
7093
|
-
|
|
7094
|
-
|
|
7160
|
+
Object.defineProperties(this, {
|
|
7161
|
+
original: { writable: true, value: string },
|
|
7162
|
+
outro: { writable: true, value: '' },
|
|
7163
|
+
intro: { writable: true, value: '' },
|
|
7164
|
+
firstChunk: { writable: true, value: chunk },
|
|
7165
|
+
lastChunk: { writable: true, value: chunk },
|
|
7166
|
+
lastSearchedChunk: { writable: true, value: chunk },
|
|
7167
|
+
byStart: { writable: true, value: {} },
|
|
7168
|
+
byEnd: { writable: true, value: {} },
|
|
7169
|
+
filename: { writable: true, value: options.filename },
|
|
7170
|
+
indentExclusionRanges: { writable: true, value: options.indentExclusionRanges },
|
|
7171
|
+
sourcemapLocations: { writable: true, value: new BitSet() },
|
|
7172
|
+
storedNames: { writable: true, value: {} },
|
|
7173
|
+
indentStr: { writable: true, value: guessIndent(string) }
|
|
7174
|
+
});
|
|
7095
7175
|
|
|
7096
|
-
|
|
7097
|
-
|
|
7176
|
+
this.byStart[0] = chunk;
|
|
7177
|
+
this.byEnd[string.length] = chunk;
|
|
7178
|
+
};
|
|
7098
7179
|
|
|
7099
|
-
|
|
7100
|
-
|
|
7101
|
-
|
|
7102
|
-
}
|
|
7180
|
+
MagicString.prototype.addSourcemapLocation = function addSourcemapLocation (char) {
|
|
7181
|
+
this.sourcemapLocations.add(char);
|
|
7182
|
+
};
|
|
7103
7183
|
|
|
7104
|
-
|
|
7105
|
-
}
|
|
7184
|
+
MagicString.prototype.append = function append (content) {
|
|
7185
|
+
if (typeof content !== 'string') { throw new TypeError('outro content must be a string'); }
|
|
7106
7186
|
|
|
7107
|
-
|
|
7108
|
-
|
|
7109
|
-
|
|
7187
|
+
this.outro += content;
|
|
7188
|
+
return this;
|
|
7189
|
+
};
|
|
7110
7190
|
|
|
7111
|
-
|
|
7191
|
+
MagicString.prototype.appendLeft = function appendLeft (index, content) {
|
|
7192
|
+
if (typeof content !== 'string') { throw new TypeError('inserted content must be a string'); }
|
|
7112
7193
|
|
|
7113
|
-
|
|
7114
|
-
returnValue += character;
|
|
7194
|
+
this._split(index);
|
|
7115
7195
|
|
|
7116
|
-
|
|
7117
|
-
const {groups} = new RegExp(`(?:\\${ANSI_CSI}(?<code>\\d+)m|\\${ANSI_ESCAPE_LINK}(?<uri>.*)${ANSI_ESCAPE_BELL})`).exec(pre.slice(index).join('')) || {groups: {}};
|
|
7118
|
-
if (groups.code !== undefined) {
|
|
7119
|
-
const code = Number.parseFloat(groups.code);
|
|
7120
|
-
escapeCode = code === END_CODE ? undefined : code;
|
|
7121
|
-
} else if (groups.uri !== undefined) {
|
|
7122
|
-
escapeUrl = groups.uri.length === 0 ? undefined : groups.uri;
|
|
7123
|
-
}
|
|
7124
|
-
}
|
|
7196
|
+
var chunk = this.byEnd[index];
|
|
7125
7197
|
|
|
7126
|
-
|
|
7198
|
+
if (chunk) {
|
|
7199
|
+
chunk.appendLeft(content);
|
|
7200
|
+
} else {
|
|
7201
|
+
this.intro += content;
|
|
7202
|
+
}
|
|
7203
|
+
return this;
|
|
7204
|
+
};
|
|
7127
7205
|
|
|
7128
|
-
|
|
7129
|
-
|
|
7130
|
-
returnValue += wrapAnsiHyperlink('');
|
|
7131
|
-
}
|
|
7206
|
+
MagicString.prototype.appendRight = function appendRight (index, content) {
|
|
7207
|
+
if (typeof content !== 'string') { throw new TypeError('inserted content must be a string'); }
|
|
7132
7208
|
|
|
7133
|
-
|
|
7134
|
-
returnValue += wrapAnsiCode(code);
|
|
7135
|
-
}
|
|
7136
|
-
} else if (character === '\n') {
|
|
7137
|
-
if (escapeCode && code) {
|
|
7138
|
-
returnValue += wrapAnsiCode(escapeCode);
|
|
7139
|
-
}
|
|
7209
|
+
this._split(index);
|
|
7140
7210
|
|
|
7141
|
-
|
|
7142
|
-
returnValue += wrapAnsiHyperlink(escapeUrl);
|
|
7143
|
-
}
|
|
7144
|
-
}
|
|
7145
|
-
}
|
|
7211
|
+
var chunk = this.byStart[index];
|
|
7146
7212
|
|
|
7147
|
-
|
|
7213
|
+
if (chunk) {
|
|
7214
|
+
chunk.appendRight(content);
|
|
7215
|
+
} else {
|
|
7216
|
+
this.outro += content;
|
|
7217
|
+
}
|
|
7218
|
+
return this;
|
|
7148
7219
|
};
|
|
7149
7220
|
|
|
7150
|
-
|
|
7151
|
-
|
|
7152
|
-
return String(string)
|
|
7153
|
-
.normalize()
|
|
7154
|
-
.replace(/\r\n/g, '\n')
|
|
7155
|
-
.split('\n')
|
|
7156
|
-
.map(line => exec(line, columns, options))
|
|
7157
|
-
.join('\n');
|
|
7158
|
-
}
|
|
7221
|
+
MagicString.prototype.clone = function clone () {
|
|
7222
|
+
var cloned = new MagicString(this.original, { filename: this.filename });
|
|
7159
7223
|
|
|
7160
|
-
|
|
7224
|
+
var originalChunk = this.firstChunk;
|
|
7225
|
+
var clonedChunk = (cloned.firstChunk = cloned.lastSearchedChunk = originalChunk.clone());
|
|
7161
7226
|
|
|
7162
|
-
|
|
7163
|
-
|
|
7227
|
+
while (originalChunk) {
|
|
7228
|
+
cloned.byStart[clonedChunk.start] = clonedChunk;
|
|
7229
|
+
cloned.byEnd[clonedChunk.end] = clonedChunk;
|
|
7164
7230
|
|
|
7165
|
-
|
|
7166
|
-
|
|
7167
|
-
}
|
|
7231
|
+
var nextOriginalChunk = originalChunk.next;
|
|
7232
|
+
var nextClonedChunk = nextOriginalChunk && nextOriginalChunk.clone();
|
|
7168
7233
|
|
|
7169
|
-
|
|
7170
|
-
|
|
7234
|
+
if (nextClonedChunk) {
|
|
7235
|
+
clonedChunk.next = nextClonedChunk;
|
|
7236
|
+
nextClonedChunk.previous = clonedChunk;
|
|
7171
7237
|
|
|
7172
|
-
|
|
7173
|
-
|
|
7174
|
-
const lines = text.split('\n');
|
|
7238
|
+
clonedChunk = nextClonedChunk;
|
|
7239
|
+
}
|
|
7175
7240
|
|
|
7176
|
-
|
|
7177
|
-
if (toRemove <= 0) {
|
|
7178
|
-
return text;
|
|
7241
|
+
originalChunk = nextOriginalChunk;
|
|
7179
7242
|
}
|
|
7180
7243
|
|
|
7181
|
-
|
|
7182
|
-
text,
|
|
7183
|
-
lines.slice(0, toRemove).join('\n').length + 1,
|
|
7184
|
-
text.length);
|
|
7185
|
-
};
|
|
7244
|
+
cloned.lastChunk = clonedChunk;
|
|
7186
7245
|
|
|
7187
|
-
|
|
7188
|
-
|
|
7189
|
-
|
|
7190
|
-
let previousOutput = '';
|
|
7246
|
+
if (this.indentExclusionRanges) {
|
|
7247
|
+
cloned.indentExclusionRanges = this.indentExclusionRanges.slice();
|
|
7248
|
+
}
|
|
7191
7249
|
|
|
7192
|
-
|
|
7193
|
-
if (!showCursor) {
|
|
7194
|
-
cliCursor.hide();
|
|
7195
|
-
}
|
|
7250
|
+
cloned.sourcemapLocations = new BitSet(this.sourcemapLocations);
|
|
7196
7251
|
|
|
7197
|
-
|
|
7198
|
-
|
|
7199
|
-
const width = getWidth(stream);
|
|
7200
|
-
if (output === previousOutput && previousWidth === width) {
|
|
7201
|
-
return;
|
|
7202
|
-
}
|
|
7252
|
+
cloned.intro = this.intro;
|
|
7253
|
+
cloned.outro = this.outro;
|
|
7203
7254
|
|
|
7204
|
-
|
|
7205
|
-
|
|
7206
|
-
output = wrapAnsi(output, width, {
|
|
7207
|
-
trim: false,
|
|
7208
|
-
hard: true,
|
|
7209
|
-
wordWrap: false,
|
|
7210
|
-
});
|
|
7211
|
-
stream.write(ansiEscapes.eraseLines(previousLineCount) + output);
|
|
7212
|
-
previousLineCount = output.split('\n').length;
|
|
7213
|
-
};
|
|
7255
|
+
return cloned;
|
|
7256
|
+
};
|
|
7214
7257
|
|
|
7215
|
-
|
|
7216
|
-
|
|
7217
|
-
previousOutput = '';
|
|
7218
|
-
previousWidth = getWidth(stream);
|
|
7219
|
-
previousLineCount = 0;
|
|
7220
|
-
};
|
|
7258
|
+
MagicString.prototype.generateDecodedMap = function generateDecodedMap (options) {
|
|
7259
|
+
var this$1$1 = this;
|
|
7221
7260
|
|
|
7222
|
-
|
|
7223
|
-
previousOutput = '';
|
|
7224
|
-
previousWidth = getWidth(stream);
|
|
7225
|
-
previousLineCount = 0;
|
|
7261
|
+
options = options || {};
|
|
7226
7262
|
|
|
7227
|
-
|
|
7228
|
-
|
|
7229
|
-
|
|
7230
|
-
};
|
|
7263
|
+
var sourceIndex = 0;
|
|
7264
|
+
var names = Object.keys(this.storedNames);
|
|
7265
|
+
var mappings = new Mappings(options.hires);
|
|
7231
7266
|
|
|
7232
|
-
|
|
7233
|
-
}
|
|
7267
|
+
var locate = getLocator(this.original);
|
|
7234
7268
|
|
|
7235
|
-
|
|
7269
|
+
if (this.intro) {
|
|
7270
|
+
mappings.advance(this.intro);
|
|
7271
|
+
}
|
|
7236
7272
|
|
|
7237
|
-
|
|
7273
|
+
this.firstChunk.eachNext(function (chunk) {
|
|
7274
|
+
var loc = locate(chunk.start);
|
|
7238
7275
|
|
|
7239
|
-
|
|
7240
|
-
const MAX_HEIGHT = 20;
|
|
7241
|
-
const spinnerMap = /* @__PURE__ */ new WeakMap();
|
|
7242
|
-
const outputMap = /* @__PURE__ */ new WeakMap();
|
|
7243
|
-
const pointer = c.yellow(F_POINTER);
|
|
7244
|
-
const skipped = c.yellow(F_DOWN);
|
|
7245
|
-
function divider(text, left, right) {
|
|
7246
|
-
let length = process.stdout.columns;
|
|
7247
|
-
if (!length || isNaN(length))
|
|
7248
|
-
length = 10;
|
|
7249
|
-
if (text) {
|
|
7250
|
-
const textLength = stripAnsi(text).length;
|
|
7251
|
-
if (left == null && right != null) {
|
|
7252
|
-
left = length - textLength - right;
|
|
7253
|
-
} else {
|
|
7254
|
-
left = left ?? Math.floor((length - textLength) / 2);
|
|
7255
|
-
right = length - textLength - left;
|
|
7256
|
-
}
|
|
7257
|
-
left = Math.max(0, left);
|
|
7258
|
-
right = Math.max(0, right);
|
|
7259
|
-
return `${F_LONG_DASH.repeat(left)}${text}${F_LONG_DASH.repeat(right)}`;
|
|
7260
|
-
}
|
|
7261
|
-
return F_LONG_DASH.repeat(length);
|
|
7262
|
-
}
|
|
7263
|
-
function formatTestPath(root, path) {
|
|
7264
|
-
var _a;
|
|
7265
|
-
if (isAbsolute(path))
|
|
7266
|
-
path = relative(root, path);
|
|
7267
|
-
const dir = dirname(path);
|
|
7268
|
-
const ext = ((_a = path.match(/(\.(spec|test)\.[cm]?[tj]sx?)$/)) == null ? void 0 : _a[0]) || "";
|
|
7269
|
-
const base = basename(path, ext);
|
|
7270
|
-
return slash$1(c.dim(`${dir}/`) + c.bold(base)) + c.dim(ext);
|
|
7271
|
-
}
|
|
7272
|
-
function renderSnapshotSummary(rootDir, snapshots) {
|
|
7273
|
-
const summary = [];
|
|
7274
|
-
if (snapshots.added)
|
|
7275
|
-
summary.push(c.bold(c.green(`${snapshots.added} written`)));
|
|
7276
|
-
if (snapshots.unmatched)
|
|
7277
|
-
summary.push(c.bold(c.red(`${snapshots.unmatched} failed`)));
|
|
7278
|
-
if (snapshots.updated)
|
|
7279
|
-
summary.push(c.bold(c.green(`${snapshots.updated} updated `)));
|
|
7280
|
-
if (snapshots.filesRemoved) {
|
|
7281
|
-
if (snapshots.didUpdate)
|
|
7282
|
-
summary.push(c.bold(c.green(`${snapshots.filesRemoved} files removed `)));
|
|
7283
|
-
else
|
|
7284
|
-
summary.push(c.bold(c.yellow(`${snapshots.filesRemoved} files obsolete `)));
|
|
7285
|
-
}
|
|
7286
|
-
if (snapshots.filesRemovedList && snapshots.filesRemovedList.length) {
|
|
7287
|
-
const [head, ...tail] = snapshots.filesRemovedList;
|
|
7288
|
-
summary.push(`${c.gray(F_DOWN_RIGHT)} ${formatTestPath(rootDir, head)}`);
|
|
7289
|
-
tail.forEach((key) => {
|
|
7290
|
-
summary.push(` ${c.gray(F_DOT)} ${formatTestPath(rootDir, key)}`);
|
|
7291
|
-
});
|
|
7292
|
-
}
|
|
7293
|
-
if (snapshots.unchecked) {
|
|
7294
|
-
if (snapshots.didUpdate)
|
|
7295
|
-
summary.push(c.bold(c.green(`${snapshots.unchecked} removed`)));
|
|
7296
|
-
else
|
|
7297
|
-
summary.push(c.bold(c.yellow(`${snapshots.unchecked} obsolete`)));
|
|
7298
|
-
snapshots.uncheckedKeysByFile.forEach((uncheckedFile) => {
|
|
7299
|
-
summary.push(`${c.gray(F_DOWN_RIGHT)} ${formatTestPath(rootDir, uncheckedFile.filePath)}`);
|
|
7300
|
-
uncheckedFile.keys.forEach((key) => summary.push(` ${c.gray(F_DOT)} ${key}`));
|
|
7301
|
-
});
|
|
7302
|
-
}
|
|
7303
|
-
return summary;
|
|
7304
|
-
}
|
|
7305
|
-
function getStateString(tasks, name = "tests") {
|
|
7306
|
-
if (tasks.length === 0)
|
|
7307
|
-
return c.dim(`no ${name}`);
|
|
7308
|
-
const passed = tasks.filter((i) => {
|
|
7309
|
-
var _a;
|
|
7310
|
-
return ((_a = i.result) == null ? void 0 : _a.state) === "pass";
|
|
7311
|
-
});
|
|
7312
|
-
const failed = tasks.filter((i) => {
|
|
7313
|
-
var _a;
|
|
7314
|
-
return ((_a = i.result) == null ? void 0 : _a.state) === "fail";
|
|
7315
|
-
});
|
|
7316
|
-
const skipped2 = tasks.filter((i) => i.mode === "skip");
|
|
7317
|
-
const todo = tasks.filter((i) => i.mode === "todo");
|
|
7318
|
-
return [
|
|
7319
|
-
failed.length ? c.bold(c.red(`${failed.length} failed`)) : null,
|
|
7320
|
-
passed.length ? c.bold(c.green(`${passed.length} passed`)) : null,
|
|
7321
|
-
skipped2.length ? c.yellow(`${skipped2.length} skipped`) : null,
|
|
7322
|
-
todo.length ? c.gray(`${todo.length} todo`) : null
|
|
7323
|
-
].filter(Boolean).join(c.dim(" | ")) + c.gray(` (${tasks.length})`);
|
|
7324
|
-
}
|
|
7325
|
-
function getStateSymbol(task) {
|
|
7326
|
-
if (task.mode === "skip" || task.mode === "todo")
|
|
7327
|
-
return skipped;
|
|
7328
|
-
if (!task.result)
|
|
7329
|
-
return c.gray("\xB7");
|
|
7330
|
-
if (task.result.state === "run") {
|
|
7331
|
-
if (task.type === "suite")
|
|
7332
|
-
return pointer;
|
|
7333
|
-
let spinner = spinnerMap.get(task);
|
|
7334
|
-
if (!spinner) {
|
|
7335
|
-
spinner = elegantSpinner();
|
|
7336
|
-
spinnerMap.set(task, spinner);
|
|
7337
|
-
}
|
|
7338
|
-
return c.yellow(spinner());
|
|
7339
|
-
}
|
|
7340
|
-
if (task.result.state === "pass")
|
|
7341
|
-
return c.green(F_CHECK);
|
|
7342
|
-
if (task.result.state === "fail") {
|
|
7343
|
-
return task.type === "suite" ? pointer : c.red(F_CROSS);
|
|
7344
|
-
}
|
|
7345
|
-
return " ";
|
|
7346
|
-
}
|
|
7347
|
-
function renderTree(tasks, level = 0) {
|
|
7348
|
-
var _a, _b, _c, _d;
|
|
7349
|
-
let output = [];
|
|
7350
|
-
for (const task of tasks) {
|
|
7351
|
-
let suffix = "";
|
|
7352
|
-
const prefix = ` ${getStateSymbol(task)} `;
|
|
7353
|
-
if (task.mode === "skip" || task.mode === "todo")
|
|
7354
|
-
suffix += ` ${c.dim("[skipped]")}`;
|
|
7355
|
-
if (task.type === "suite")
|
|
7356
|
-
suffix += c.dim(` (${getTests(task).length})`);
|
|
7357
|
-
if ((_a = task.result) == null ? void 0 : _a.end) {
|
|
7358
|
-
const duration = task.result.end - task.result.start;
|
|
7359
|
-
if (duration > DURATION_LONG)
|
|
7360
|
-
suffix += c.yellow(` ${Math.round(duration)}${c.dim("ms")}`);
|
|
7361
|
-
}
|
|
7362
|
-
output.push(" ".repeat(level) + prefix + task.name + suffix);
|
|
7363
|
-
if (((_b = task.result) == null ? void 0 : _b.state) !== "pass" && outputMap.get(task) != null) {
|
|
7364
|
-
let data = outputMap.get(task);
|
|
7365
|
-
if (typeof data === "string") {
|
|
7366
|
-
data = stripAnsi(data.trim().split("\n").filter(Boolean).pop());
|
|
7367
|
-
if (data === "")
|
|
7368
|
-
data = void 0;
|
|
7369
|
-
}
|
|
7370
|
-
if (data != null) {
|
|
7371
|
-
const out = `${" ".repeat(level)}${F_RIGHT} ${data}`;
|
|
7372
|
-
output.push(` ${c.gray(cliTruncate(out, process.stdout.columns - 3))}`);
|
|
7373
|
-
}
|
|
7374
|
-
}
|
|
7375
|
-
if ((((_c = task.result) == null ? void 0 : _c.state) === "fail" || ((_d = task.result) == null ? void 0 : _d.state) === "run") && task.type === "suite" && task.tasks.length > 0)
|
|
7376
|
-
output = output.concat(renderTree(task.tasks, level + 1));
|
|
7377
|
-
}
|
|
7378
|
-
return output.slice(0, MAX_HEIGHT).join("\n");
|
|
7379
|
-
}
|
|
7380
|
-
const createRenderer = (_tasks) => {
|
|
7381
|
-
let tasks = _tasks;
|
|
7382
|
-
let timer;
|
|
7383
|
-
const stdout = process.stdout;
|
|
7384
|
-
const log = createLogUpdate(stdout);
|
|
7385
|
-
function update() {
|
|
7386
|
-
log(renderTree(tasks));
|
|
7387
|
-
}
|
|
7388
|
-
return {
|
|
7389
|
-
start() {
|
|
7390
|
-
if (timer)
|
|
7391
|
-
return this;
|
|
7392
|
-
timer = setInterval(update, 200);
|
|
7393
|
-
return this;
|
|
7394
|
-
},
|
|
7395
|
-
update(_tasks2) {
|
|
7396
|
-
tasks = _tasks2;
|
|
7397
|
-
update();
|
|
7398
|
-
return this;
|
|
7399
|
-
},
|
|
7400
|
-
async stop() {
|
|
7401
|
-
if (timer) {
|
|
7402
|
-
clearInterval(timer);
|
|
7403
|
-
timer = void 0;
|
|
7404
|
-
}
|
|
7405
|
-
log.clear();
|
|
7406
|
-
stdout.write(`${renderTree(tasks)}
|
|
7407
|
-
`);
|
|
7408
|
-
return this;
|
|
7409
|
-
},
|
|
7410
|
-
clear() {
|
|
7411
|
-
log.clear();
|
|
7412
|
-
}
|
|
7413
|
-
};
|
|
7414
|
-
};
|
|
7415
|
-
function getFullName(task) {
|
|
7416
|
-
return getNames(task).join(c.dim(" > "));
|
|
7417
|
-
}
|
|
7418
|
-
const spinnerFrames = process.platform === "win32" ? ["-", "\\", "|", "/"] : ["\u280B", "\u2819", "\u2839", "\u2838", "\u283C", "\u2834", "\u2826", "\u2827", "\u2807", "\u280F"];
|
|
7419
|
-
function elegantSpinner() {
|
|
7420
|
-
let index = 0;
|
|
7421
|
-
return () => {
|
|
7422
|
-
index = ++index % spinnerFrames.length;
|
|
7423
|
-
return spinnerFrames[index];
|
|
7424
|
-
};
|
|
7425
|
-
}
|
|
7426
|
-
|
|
7427
|
-
const isTTY = process.stdout.isTTY && !process.env.CI;
|
|
7428
|
-
class ConsoleReporter {
|
|
7429
|
-
constructor(ctx) {
|
|
7430
|
-
this.ctx = ctx;
|
|
7431
|
-
this.start = 0;
|
|
7432
|
-
this.end = 0;
|
|
7433
|
-
this.isFirstWatchRun = true;
|
|
7434
|
-
const mode = ctx.config.watch ? c.yellow(" DEV ") : c.cyan(" RUN ");
|
|
7435
|
-
this.ctx.log(`
|
|
7436
|
-
${c.inverse(c.bold(mode))} ${c.gray(this.ctx.config.root)}
|
|
7437
|
-
`);
|
|
7438
|
-
this.start = performance.now();
|
|
7439
|
-
}
|
|
7440
|
-
relative(path) {
|
|
7441
|
-
return relative(this.ctx.config.root, path);
|
|
7442
|
-
}
|
|
7443
|
-
onStart() {
|
|
7444
|
-
if (isTTY) {
|
|
7445
|
-
const files = this.ctx.state.getFiles(this.watchFilters);
|
|
7446
|
-
if (!this.renderer)
|
|
7447
|
-
this.renderer = createRenderer(files).start();
|
|
7448
|
-
else
|
|
7449
|
-
this.renderer.update(files);
|
|
7450
|
-
}
|
|
7451
|
-
}
|
|
7452
|
-
onTaskUpdate(pack) {
|
|
7453
|
-
var _a, _b, _c;
|
|
7454
|
-
if (isTTY)
|
|
7455
|
-
return;
|
|
7456
|
-
const task = this.ctx.state.idMap[pack[0]];
|
|
7457
|
-
if (task.type === "test" && ((_a = task.result) == null ? void 0 : _a.state) && ((_b = task.result) == null ? void 0 : _b.state) !== "run") {
|
|
7458
|
-
this.ctx.log(` ${getStateSymbol(task)} ${getFullName(task)}`);
|
|
7459
|
-
if (task.result.state === "fail")
|
|
7460
|
-
this.ctx.log(c.red(` ${F_RIGHT} ${(_c = task.result.error) == null ? void 0 : _c.message}`));
|
|
7461
|
-
}
|
|
7462
|
-
}
|
|
7463
|
-
async onFinished(files = this.ctx.state.getFiles()) {
|
|
7464
|
-
var _a, _b;
|
|
7465
|
-
this.end = performance.now();
|
|
7466
|
-
await this.stopListRender();
|
|
7467
|
-
this.ctx.log();
|
|
7468
|
-
const suites = getSuites(files);
|
|
7469
|
-
const tests = getTests(files);
|
|
7470
|
-
const failedSuites = suites.filter((i) => {
|
|
7471
|
-
var _a2;
|
|
7472
|
-
return (_a2 = i.result) == null ? void 0 : _a2.error;
|
|
7473
|
-
});
|
|
7474
|
-
const failedTests = tests.filter((i) => {
|
|
7475
|
-
var _a2;
|
|
7476
|
-
return ((_a2 = i.result) == null ? void 0 : _a2.state) === "fail";
|
|
7477
|
-
});
|
|
7478
|
-
const failedTotal = failedSuites.length + failedTests.length;
|
|
7479
|
-
let current = 1;
|
|
7480
|
-
const errorDivider = () => this.ctx.error(`${c.red(c.dim(divider(`[${current++}/${failedTotal}]`, void 0, 1)))}
|
|
7481
|
-
`);
|
|
7482
|
-
if (failedSuites.length) {
|
|
7483
|
-
this.ctx.error(c.red(divider(c.bold(c.inverse(` Failed Suites ${failedSuites.length} `)))));
|
|
7484
|
-
this.ctx.error();
|
|
7485
|
-
for (const suite of failedSuites) {
|
|
7486
|
-
this.ctx.error(c.red(`
|
|
7487
|
-
- ${getFullName(suite)}`));
|
|
7488
|
-
await printError((_a = suite.result) == null ? void 0 : _a.error, this.ctx);
|
|
7489
|
-
errorDivider();
|
|
7490
|
-
}
|
|
7491
|
-
}
|
|
7492
|
-
if (failedTests.length) {
|
|
7493
|
-
this.ctx.error(c.red(divider(c.bold(c.inverse(` Failed Tests ${failedTests.length} `)))));
|
|
7494
|
-
this.ctx.error();
|
|
7495
|
-
for (const test of failedTests) {
|
|
7496
|
-
this.ctx.error(`${c.red(c.bold(c.inverse(" FAIL ")))} ${getFullName(test)}`);
|
|
7497
|
-
await printError((_b = test.result) == null ? void 0 : _b.error, this.ctx);
|
|
7498
|
-
errorDivider();
|
|
7499
|
-
}
|
|
7500
|
-
}
|
|
7501
|
-
const executionTime = this.end - this.start;
|
|
7502
|
-
const threadTime = tests.reduce((acc, test) => {
|
|
7503
|
-
var _a2;
|
|
7504
|
-
return acc + (((_a2 = test.result) == null ? void 0 : _a2.end) ? test.result.end - test.result.start : 0);
|
|
7505
|
-
}, 0);
|
|
7506
|
-
const padTitle = (str) => c.dim(`${str.padStart(10)} `);
|
|
7507
|
-
const time = (time2) => {
|
|
7508
|
-
if (time2 > 1e3)
|
|
7509
|
-
return `${(time2 / 1e3).toFixed(2)}s`;
|
|
7510
|
-
return `${Math.round(time2)}ms`;
|
|
7511
|
-
};
|
|
7512
|
-
const snapshotOutput = renderSnapshotSummary(this.ctx.config.root, this.ctx.snapshot.summary);
|
|
7513
|
-
if (snapshotOutput.length) {
|
|
7514
|
-
this.ctx.log(snapshotOutput.map((t, i) => i === 0 ? `${padTitle("Snapshots")} ${t}` : `${padTitle("")} ${t}`).join("\n"));
|
|
7515
|
-
if (snapshotOutput.length > 1)
|
|
7516
|
-
this.ctx.log();
|
|
7517
|
-
}
|
|
7518
|
-
this.ctx.log(padTitle("Test Files"), getStateString(files));
|
|
7519
|
-
this.ctx.log(padTitle("Tests"), getStateString(tests));
|
|
7520
|
-
if (this.watchFilters)
|
|
7521
|
-
this.ctx.log(padTitle("Time"), time(threadTime));
|
|
7522
|
-
else
|
|
7523
|
-
this.ctx.log(padTitle("Time"), time(executionTime) + c.gray(` (in thread ${time(threadTime)}, ${(executionTime / threadTime * 100).toFixed(2)}%)`));
|
|
7524
|
-
this.ctx.log();
|
|
7525
|
-
}
|
|
7526
|
-
async onWatcherStart() {
|
|
7527
|
-
await this.stopListRender();
|
|
7528
|
-
const failed = getTests(this.ctx.state.getFiles()).filter((i) => {
|
|
7529
|
-
var _a;
|
|
7530
|
-
return ((_a = i.result) == null ? void 0 : _a.state) === "fail";
|
|
7531
|
-
});
|
|
7532
|
-
if (failed.length)
|
|
7533
|
-
this.ctx.log(`
|
|
7534
|
-
${c.bold(c.inverse(c.red(" FAIL ")))}${c.red(` ${failed.length} tests failed. Watching for file changes...`)}`);
|
|
7535
|
-
else
|
|
7536
|
-
this.ctx.log(`
|
|
7537
|
-
${c.bold(c.inverse(c.green(" PASS ")))}${c.green(" Waiting for file changes...")}`);
|
|
7538
|
-
if (this.isFirstWatchRun) {
|
|
7539
|
-
this.isFirstWatchRun = false;
|
|
7540
|
-
this.ctx.log(c.gray("press any key to exit..."));
|
|
7541
|
-
}
|
|
7542
|
-
}
|
|
7543
|
-
async onWatcherRerun(files, trigger) {
|
|
7544
|
-
await this.stopListRender();
|
|
7545
|
-
this.watchFilters = files;
|
|
7546
|
-
if (!this.ctx.config.silent) {
|
|
7547
|
-
this.ctx.console.clear();
|
|
7548
|
-
this.ctx.log(c.blue("Re-running tests...") + c.dim(` [ ${this.relative(trigger)} ]
|
|
7549
|
-
`));
|
|
7550
|
-
}
|
|
7551
|
-
}
|
|
7552
|
-
async stopListRender() {
|
|
7553
|
-
var _a;
|
|
7554
|
-
(_a = this.renderer) == null ? void 0 : _a.stop();
|
|
7555
|
-
this.renderer = void 0;
|
|
7556
|
-
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
7557
|
-
}
|
|
7558
|
-
onUserConsoleLog(log) {
|
|
7559
|
-
var _a;
|
|
7560
|
-
(_a = this.renderer) == null ? void 0 : _a.clear();
|
|
7561
|
-
const task = log.taskId ? this.ctx.state.idMap[log.taskId] : void 0;
|
|
7562
|
-
this.ctx.log(c.gray(log.type + c.dim(` | ${task ? getFullName(task) : "unknown test"}`)));
|
|
7563
|
-
process[log.type].write(`${log.content}
|
|
7564
|
-
`);
|
|
7565
|
-
}
|
|
7566
|
-
onServerRestart() {
|
|
7567
|
-
this.ctx.log(c.cyan("Restarted due to config changes..."));
|
|
7568
|
-
}
|
|
7569
|
-
}
|
|
7570
|
-
|
|
7571
|
-
var charToInteger = {};
|
|
7572
|
-
var chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
|
|
7573
|
-
for (var i = 0; i < chars.length; i++) {
|
|
7574
|
-
charToInteger[chars.charCodeAt(i)] = i;
|
|
7575
|
-
}
|
|
7576
|
-
function encode(decoded) {
|
|
7577
|
-
var sourceFileIndex = 0; // second field
|
|
7578
|
-
var sourceCodeLine = 0; // third field
|
|
7579
|
-
var sourceCodeColumn = 0; // fourth field
|
|
7580
|
-
var nameIndex = 0; // fifth field
|
|
7581
|
-
var mappings = '';
|
|
7582
|
-
for (var i = 0; i < decoded.length; i++) {
|
|
7583
|
-
var line = decoded[i];
|
|
7584
|
-
if (i > 0)
|
|
7585
|
-
mappings += ';';
|
|
7586
|
-
if (line.length === 0)
|
|
7587
|
-
continue;
|
|
7588
|
-
var generatedCodeColumn = 0; // first field
|
|
7589
|
-
var lineMappings = [];
|
|
7590
|
-
for (var _i = 0, line_1 = line; _i < line_1.length; _i++) {
|
|
7591
|
-
var segment = line_1[_i];
|
|
7592
|
-
var segmentMappings = encodeInteger(segment[0] - generatedCodeColumn);
|
|
7593
|
-
generatedCodeColumn = segment[0];
|
|
7594
|
-
if (segment.length > 1) {
|
|
7595
|
-
segmentMappings +=
|
|
7596
|
-
encodeInteger(segment[1] - sourceFileIndex) +
|
|
7597
|
-
encodeInteger(segment[2] - sourceCodeLine) +
|
|
7598
|
-
encodeInteger(segment[3] - sourceCodeColumn);
|
|
7599
|
-
sourceFileIndex = segment[1];
|
|
7600
|
-
sourceCodeLine = segment[2];
|
|
7601
|
-
sourceCodeColumn = segment[3];
|
|
7602
|
-
}
|
|
7603
|
-
if (segment.length === 5) {
|
|
7604
|
-
segmentMappings += encodeInteger(segment[4] - nameIndex);
|
|
7605
|
-
nameIndex = segment[4];
|
|
7606
|
-
}
|
|
7607
|
-
lineMappings.push(segmentMappings);
|
|
7608
|
-
}
|
|
7609
|
-
mappings += lineMappings.join(',');
|
|
7610
|
-
}
|
|
7611
|
-
return mappings;
|
|
7612
|
-
}
|
|
7613
|
-
function encodeInteger(num) {
|
|
7614
|
-
var result = '';
|
|
7615
|
-
num = num < 0 ? (-num << 1) | 1 : num << 1;
|
|
7616
|
-
do {
|
|
7617
|
-
var clamped = num & 31;
|
|
7618
|
-
num >>>= 5;
|
|
7619
|
-
if (num > 0) {
|
|
7620
|
-
clamped |= 32;
|
|
7621
|
-
}
|
|
7622
|
-
result += chars[clamped];
|
|
7623
|
-
} while (num > 0);
|
|
7624
|
-
return result;
|
|
7625
|
-
}
|
|
7276
|
+
if (chunk.intro.length) { mappings.advance(chunk.intro); }
|
|
7626
7277
|
|
|
7627
|
-
|
|
7628
|
-
|
|
7278
|
+
if (chunk.edited) {
|
|
7279
|
+
mappings.addEdit(
|
|
7280
|
+
sourceIndex,
|
|
7281
|
+
chunk.content,
|
|
7282
|
+
loc,
|
|
7283
|
+
chunk.storeName ? names.indexOf(chunk.original) : -1
|
|
7284
|
+
);
|
|
7285
|
+
} else {
|
|
7286
|
+
mappings.addUneditedChunk(sourceIndex, chunk, this$1$1.original, loc, this$1$1.sourcemapLocations);
|
|
7287
|
+
}
|
|
7288
|
+
|
|
7289
|
+
if (chunk.outro.length) { mappings.advance(chunk.outro); }
|
|
7290
|
+
});
|
|
7291
|
+
|
|
7292
|
+
return {
|
|
7293
|
+
file: options.file ? options.file.split(/[/\\]/).pop() : null,
|
|
7294
|
+
sources: [options.source ? getRelativePath(options.file || '', options.source) : null],
|
|
7295
|
+
sourcesContent: options.includeContent ? [this.original] : [null],
|
|
7296
|
+
names: names,
|
|
7297
|
+
mappings: mappings.raw
|
|
7298
|
+
};
|
|
7629
7299
|
};
|
|
7630
7300
|
|
|
7631
|
-
|
|
7632
|
-
|
|
7301
|
+
MagicString.prototype.generateMap = function generateMap (options) {
|
|
7302
|
+
return new SourceMap(this.generateDecodedMap(options));
|
|
7633
7303
|
};
|
|
7634
7304
|
|
|
7635
|
-
|
|
7636
|
-
return
|
|
7305
|
+
MagicString.prototype.getIndentString = function getIndentString () {
|
|
7306
|
+
return this.indentStr === null ? '\t' : this.indentStr;
|
|
7637
7307
|
};
|
|
7638
7308
|
|
|
7639
|
-
|
|
7640
|
-
|
|
7641
|
-
this.end = end;
|
|
7642
|
-
this.original = content;
|
|
7309
|
+
MagicString.prototype.indent = function indent (indentStr, options) {
|
|
7310
|
+
var pattern = /^[^\r\n]/gm;
|
|
7643
7311
|
|
|
7644
|
-
|
|
7645
|
-
|
|
7312
|
+
if (isObject(indentStr)) {
|
|
7313
|
+
options = indentStr;
|
|
7314
|
+
indentStr = undefined;
|
|
7315
|
+
}
|
|
7646
7316
|
|
|
7647
|
-
this.
|
|
7648
|
-
this.storeName = false;
|
|
7649
|
-
this.edited = false;
|
|
7317
|
+
indentStr = indentStr !== undefined ? indentStr : this.indentStr || '\t';
|
|
7650
7318
|
|
|
7651
|
-
|
|
7652
|
-
Object.defineProperties(this, {
|
|
7653
|
-
previous: { writable: true, value: null },
|
|
7654
|
-
next: { writable: true, value: null }
|
|
7655
|
-
});
|
|
7656
|
-
};
|
|
7319
|
+
if (indentStr === '') { return this; } // noop
|
|
7657
7320
|
|
|
7658
|
-
|
|
7659
|
-
this.outro += content;
|
|
7660
|
-
};
|
|
7321
|
+
options = options || {};
|
|
7661
7322
|
|
|
7662
|
-
|
|
7663
|
-
|
|
7664
|
-
};
|
|
7323
|
+
// Process exclusion ranges
|
|
7324
|
+
var isExcluded = {};
|
|
7665
7325
|
|
|
7666
|
-
|
|
7667
|
-
|
|
7326
|
+
if (options.exclude) {
|
|
7327
|
+
var exclusions =
|
|
7328
|
+
typeof options.exclude[0] === 'number' ? [options.exclude] : options.exclude;
|
|
7329
|
+
exclusions.forEach(function (exclusion) {
|
|
7330
|
+
for (var i = exclusion[0]; i < exclusion[1]; i += 1) {
|
|
7331
|
+
isExcluded[i] = true;
|
|
7332
|
+
}
|
|
7333
|
+
});
|
|
7334
|
+
}
|
|
7668
7335
|
|
|
7669
|
-
|
|
7670
|
-
|
|
7671
|
-
|
|
7672
|
-
|
|
7673
|
-
|
|
7336
|
+
var shouldIndentNextCharacter = options.indentStart !== false;
|
|
7337
|
+
var replacer = function (match) {
|
|
7338
|
+
if (shouldIndentNextCharacter) { return ("" + indentStr + match); }
|
|
7339
|
+
shouldIndentNextCharacter = true;
|
|
7340
|
+
return match;
|
|
7341
|
+
};
|
|
7674
7342
|
|
|
7675
|
-
|
|
7676
|
-
};
|
|
7343
|
+
this.intro = this.intro.replace(pattern, replacer);
|
|
7677
7344
|
|
|
7678
|
-
|
|
7679
|
-
|
|
7680
|
-
};
|
|
7345
|
+
var charIndex = 0;
|
|
7346
|
+
var chunk = this.firstChunk;
|
|
7681
7347
|
|
|
7682
|
-
Chunk.prototype.eachNext = function eachNext (fn) {
|
|
7683
|
-
var chunk = this;
|
|
7684
7348
|
while (chunk) {
|
|
7685
|
-
|
|
7349
|
+
var end = chunk.end;
|
|
7350
|
+
|
|
7351
|
+
if (chunk.edited) {
|
|
7352
|
+
if (!isExcluded[charIndex]) {
|
|
7353
|
+
chunk.content = chunk.content.replace(pattern, replacer);
|
|
7354
|
+
|
|
7355
|
+
if (chunk.content.length) {
|
|
7356
|
+
shouldIndentNextCharacter = chunk.content[chunk.content.length - 1] === '\n';
|
|
7357
|
+
}
|
|
7358
|
+
}
|
|
7359
|
+
} else {
|
|
7360
|
+
charIndex = chunk.start;
|
|
7361
|
+
|
|
7362
|
+
while (charIndex < end) {
|
|
7363
|
+
if (!isExcluded[charIndex]) {
|
|
7364
|
+
var char = this.original[charIndex];
|
|
7365
|
+
|
|
7366
|
+
if (char === '\n') {
|
|
7367
|
+
shouldIndentNextCharacter = true;
|
|
7368
|
+
} else if (char !== '\r' && shouldIndentNextCharacter) {
|
|
7369
|
+
shouldIndentNextCharacter = false;
|
|
7370
|
+
|
|
7371
|
+
if (charIndex === chunk.start) {
|
|
7372
|
+
chunk.prependRight(indentStr);
|
|
7373
|
+
} else {
|
|
7374
|
+
this._splitChunk(chunk, charIndex);
|
|
7375
|
+
chunk = chunk.next;
|
|
7376
|
+
chunk.prependRight(indentStr);
|
|
7377
|
+
}
|
|
7378
|
+
}
|
|
7379
|
+
}
|
|
7380
|
+
|
|
7381
|
+
charIndex += 1;
|
|
7382
|
+
}
|
|
7383
|
+
}
|
|
7384
|
+
|
|
7385
|
+
charIndex = chunk.end;
|
|
7686
7386
|
chunk = chunk.next;
|
|
7687
7387
|
}
|
|
7388
|
+
|
|
7389
|
+
this.outro = this.outro.replace(pattern, replacer);
|
|
7390
|
+
|
|
7391
|
+
return this;
|
|
7688
7392
|
};
|
|
7689
7393
|
|
|
7690
|
-
|
|
7691
|
-
|
|
7692
|
-
|
|
7693
|
-
|
|
7694
|
-
|
|
7394
|
+
MagicString.prototype.insert = function insert () {
|
|
7395
|
+
throw new Error('magicString.insert(...) is deprecated. Use prependRight(...) or appendLeft(...)');
|
|
7396
|
+
};
|
|
7397
|
+
|
|
7398
|
+
MagicString.prototype.insertLeft = function insertLeft (index, content) {
|
|
7399
|
+
if (!warned.insertLeft) {
|
|
7400
|
+
console.warn('magicString.insertLeft(...) is deprecated. Use magicString.appendLeft(...) instead'); // eslint-disable-line no-console
|
|
7401
|
+
warned.insertLeft = true;
|
|
7402
|
+
}
|
|
7403
|
+
|
|
7404
|
+
return this.appendLeft(index, content);
|
|
7405
|
+
};
|
|
7406
|
+
|
|
7407
|
+
MagicString.prototype.insertRight = function insertRight (index, content) {
|
|
7408
|
+
if (!warned.insertRight) {
|
|
7409
|
+
console.warn('magicString.insertRight(...) is deprecated. Use magicString.prependRight(...) instead'); // eslint-disable-line no-console
|
|
7410
|
+
warned.insertRight = true;
|
|
7411
|
+
}
|
|
7412
|
+
|
|
7413
|
+
return this.prependRight(index, content);
|
|
7414
|
+
};
|
|
7415
|
+
|
|
7416
|
+
MagicString.prototype.move = function move (start, end, index) {
|
|
7417
|
+
if (index >= start && index <= end) { throw new Error('Cannot move a selection inside itself'); }
|
|
7418
|
+
|
|
7419
|
+
this._split(start);
|
|
7420
|
+
this._split(end);
|
|
7421
|
+
this._split(index);
|
|
7422
|
+
|
|
7423
|
+
var first = this.byStart[start];
|
|
7424
|
+
var last = this.byEnd[end];
|
|
7425
|
+
|
|
7426
|
+
var oldLeft = first.previous;
|
|
7427
|
+
var oldRight = last.next;
|
|
7428
|
+
|
|
7429
|
+
var newRight = this.byStart[index];
|
|
7430
|
+
if (!newRight && last === this.lastChunk) { return this; }
|
|
7431
|
+
var newLeft = newRight ? newRight.previous : this.lastChunk;
|
|
7432
|
+
|
|
7433
|
+
if (oldLeft) { oldLeft.next = oldRight; }
|
|
7434
|
+
if (oldRight) { oldRight.previous = oldLeft; }
|
|
7435
|
+
|
|
7436
|
+
if (newLeft) { newLeft.next = first; }
|
|
7437
|
+
if (newRight) { newRight.previous = last; }
|
|
7438
|
+
|
|
7439
|
+
if (!first.previous) { this.firstChunk = last.next; }
|
|
7440
|
+
if (!last.next) {
|
|
7441
|
+
this.lastChunk = first.previous;
|
|
7442
|
+
this.lastChunk.next = null;
|
|
7695
7443
|
}
|
|
7444
|
+
|
|
7445
|
+
first.previous = newLeft;
|
|
7446
|
+
last.next = newRight || null;
|
|
7447
|
+
|
|
7448
|
+
if (!newLeft) { this.firstChunk = first; }
|
|
7449
|
+
if (!newRight) { this.lastChunk = last; }
|
|
7450
|
+
return this;
|
|
7696
7451
|
};
|
|
7697
7452
|
|
|
7698
|
-
|
|
7699
|
-
|
|
7700
|
-
|
|
7701
|
-
|
|
7702
|
-
|
|
7453
|
+
MagicString.prototype.overwrite = function overwrite (start, end, content, options) {
|
|
7454
|
+
if (typeof content !== 'string') { throw new TypeError('replacement content must be a string'); }
|
|
7455
|
+
|
|
7456
|
+
while (start < 0) { start += this.original.length; }
|
|
7457
|
+
while (end < 0) { end += this.original.length; }
|
|
7458
|
+
|
|
7459
|
+
if (end > this.original.length) { throw new Error('end is out of bounds'); }
|
|
7460
|
+
if (start === end)
|
|
7461
|
+
{ throw new Error('Cannot overwrite a zero-length range – use appendLeft or prependRight instead'); }
|
|
7462
|
+
|
|
7463
|
+
this._split(start);
|
|
7464
|
+
this._split(end);
|
|
7465
|
+
|
|
7466
|
+
if (options === true) {
|
|
7467
|
+
if (!warned.storeName) {
|
|
7468
|
+
console.warn('The final argument to magicString.overwrite(...) should be an options object. See https://github.com/rich-harris/magic-string'); // eslint-disable-line no-console
|
|
7469
|
+
warned.storeName = true;
|
|
7470
|
+
}
|
|
7471
|
+
|
|
7472
|
+
options = { storeName: true };
|
|
7473
|
+
}
|
|
7474
|
+
var storeName = options !== undefined ? options.storeName : false;
|
|
7475
|
+
var contentOnly = options !== undefined ? options.contentOnly : false;
|
|
7476
|
+
|
|
7477
|
+
if (storeName) {
|
|
7478
|
+
var original = this.original.slice(start, end);
|
|
7479
|
+
this.storedNames[original] = true;
|
|
7703
7480
|
}
|
|
7704
|
-
this.storeName = storeName;
|
|
7705
7481
|
|
|
7706
|
-
|
|
7482
|
+
var first = this.byStart[start];
|
|
7483
|
+
var last = this.byEnd[end];
|
|
7484
|
+
|
|
7485
|
+
if (first) {
|
|
7486
|
+
if (end > first.end && first.next !== this.byStart[first.end]) {
|
|
7487
|
+
throw new Error('Cannot overwrite across a split point');
|
|
7488
|
+
}
|
|
7489
|
+
|
|
7490
|
+
first.edit(content, storeName, contentOnly);
|
|
7491
|
+
|
|
7492
|
+
if (first !== last) {
|
|
7493
|
+
var chunk = first.next;
|
|
7494
|
+
while (chunk !== last) {
|
|
7495
|
+
chunk.edit('', false);
|
|
7496
|
+
chunk = chunk.next;
|
|
7497
|
+
}
|
|
7498
|
+
|
|
7499
|
+
chunk.edit('', false);
|
|
7500
|
+
}
|
|
7501
|
+
} else {
|
|
7502
|
+
// must be inserting at the end
|
|
7503
|
+
var newChunk = new Chunk(start, end, '').edit(content, storeName);
|
|
7707
7504
|
|
|
7505
|
+
// TODO last chunk in the array may not be the last chunk, if it's moved...
|
|
7506
|
+
last.next = newChunk;
|
|
7507
|
+
newChunk.previous = last;
|
|
7508
|
+
}
|
|
7708
7509
|
return this;
|
|
7709
7510
|
};
|
|
7710
7511
|
|
|
7711
|
-
|
|
7712
|
-
|
|
7713
|
-
};
|
|
7512
|
+
MagicString.prototype.prepend = function prepend (content) {
|
|
7513
|
+
if (typeof content !== 'string') { throw new TypeError('outro content must be a string'); }
|
|
7714
7514
|
|
|
7715
|
-
Chunk.prototype.prependRight = function prependRight (content) {
|
|
7716
7515
|
this.intro = content + this.intro;
|
|
7516
|
+
return this;
|
|
7717
7517
|
};
|
|
7718
7518
|
|
|
7719
|
-
|
|
7720
|
-
|
|
7721
|
-
|
|
7722
|
-
var originalBefore = this.original.slice(0, sliceIndex);
|
|
7723
|
-
var originalAfter = this.original.slice(sliceIndex);
|
|
7724
|
-
|
|
7725
|
-
this.original = originalBefore;
|
|
7519
|
+
MagicString.prototype.prependLeft = function prependLeft (index, content) {
|
|
7520
|
+
if (typeof content !== 'string') { throw new TypeError('inserted content must be a string'); }
|
|
7726
7521
|
|
|
7727
|
-
|
|
7728
|
-
newChunk.outro = this.outro;
|
|
7729
|
-
this.outro = '';
|
|
7522
|
+
this._split(index);
|
|
7730
7523
|
|
|
7731
|
-
|
|
7524
|
+
var chunk = this.byEnd[index];
|
|
7732
7525
|
|
|
7733
|
-
if (
|
|
7734
|
-
|
|
7735
|
-
newChunk.edit('', false);
|
|
7736
|
-
this.content = '';
|
|
7526
|
+
if (chunk) {
|
|
7527
|
+
chunk.prependLeft(content);
|
|
7737
7528
|
} else {
|
|
7738
|
-
this.
|
|
7529
|
+
this.intro = content + this.intro;
|
|
7739
7530
|
}
|
|
7740
|
-
|
|
7741
|
-
newChunk.next = this.next;
|
|
7742
|
-
if (newChunk.next) { newChunk.next.previous = newChunk; }
|
|
7743
|
-
newChunk.previous = this;
|
|
7744
|
-
this.next = newChunk;
|
|
7745
|
-
|
|
7746
|
-
return newChunk;
|
|
7747
|
-
};
|
|
7748
|
-
|
|
7749
|
-
Chunk.prototype.toString = function toString () {
|
|
7750
|
-
return this.intro + this.content + this.outro;
|
|
7531
|
+
return this;
|
|
7751
7532
|
};
|
|
7752
7533
|
|
|
7753
|
-
|
|
7754
|
-
|
|
7755
|
-
if (this.outro.length) { return true; }
|
|
7534
|
+
MagicString.prototype.prependRight = function prependRight (index, content) {
|
|
7535
|
+
if (typeof content !== 'string') { throw new TypeError('inserted content must be a string'); }
|
|
7756
7536
|
|
|
7757
|
-
|
|
7537
|
+
this._split(index);
|
|
7758
7538
|
|
|
7759
|
-
|
|
7760
|
-
if (trimmed !== this.content) {
|
|
7761
|
-
this.split(this.start + trimmed.length).edit('', undefined, true);
|
|
7762
|
-
}
|
|
7763
|
-
return true;
|
|
7539
|
+
var chunk = this.byStart[index];
|
|
7764
7540
|
|
|
7541
|
+
if (chunk) {
|
|
7542
|
+
chunk.prependRight(content);
|
|
7765
7543
|
} else {
|
|
7766
|
-
this.
|
|
7767
|
-
|
|
7768
|
-
this.intro = this.intro.replace(rx, '');
|
|
7769
|
-
if (this.intro.length) { return true; }
|
|
7544
|
+
this.outro = content + this.outro;
|
|
7770
7545
|
}
|
|
7546
|
+
return this;
|
|
7771
7547
|
};
|
|
7772
7548
|
|
|
7773
|
-
|
|
7774
|
-
|
|
7775
|
-
|
|
7549
|
+
MagicString.prototype.remove = function remove (start, end) {
|
|
7550
|
+
while (start < 0) { start += this.original.length; }
|
|
7551
|
+
while (end < 0) { end += this.original.length; }
|
|
7776
7552
|
|
|
7777
|
-
|
|
7553
|
+
if (start === end) { return this; }
|
|
7778
7554
|
|
|
7779
|
-
if (
|
|
7780
|
-
|
|
7781
|
-
this.split(this.end - trimmed.length);
|
|
7782
|
-
this.edit('', undefined, true);
|
|
7783
|
-
}
|
|
7784
|
-
return true;
|
|
7555
|
+
if (start < 0 || end > this.original.length) { throw new Error('Character is out of bounds'); }
|
|
7556
|
+
if (start > end) { throw new Error('end must be greater than start'); }
|
|
7785
7557
|
|
|
7786
|
-
|
|
7787
|
-
|
|
7558
|
+
this._split(start);
|
|
7559
|
+
this._split(end);
|
|
7788
7560
|
|
|
7789
|
-
|
|
7790
|
-
|
|
7561
|
+
var chunk = this.byStart[start];
|
|
7562
|
+
|
|
7563
|
+
while (chunk) {
|
|
7564
|
+
chunk.intro = '';
|
|
7565
|
+
chunk.outro = '';
|
|
7566
|
+
chunk.edit('');
|
|
7567
|
+
|
|
7568
|
+
chunk = end > chunk.end ? this.byStart[chunk.end] : null;
|
|
7791
7569
|
}
|
|
7570
|
+
return this;
|
|
7792
7571
|
};
|
|
7793
7572
|
|
|
7794
|
-
|
|
7795
|
-
|
|
7573
|
+
MagicString.prototype.lastChar = function lastChar () {
|
|
7574
|
+
if (this.outro.length)
|
|
7575
|
+
{ return this.outro[this.outro.length - 1]; }
|
|
7576
|
+
var chunk = this.lastChunk;
|
|
7577
|
+
do {
|
|
7578
|
+
if (chunk.outro.length)
|
|
7579
|
+
{ return chunk.outro[chunk.outro.length - 1]; }
|
|
7580
|
+
if (chunk.content.length)
|
|
7581
|
+
{ return chunk.content[chunk.content.length - 1]; }
|
|
7582
|
+
if (chunk.intro.length)
|
|
7583
|
+
{ return chunk.intro[chunk.intro.length - 1]; }
|
|
7584
|
+
} while (chunk = chunk.previous);
|
|
7585
|
+
if (this.intro.length)
|
|
7586
|
+
{ return this.intro[this.intro.length - 1]; }
|
|
7587
|
+
return '';
|
|
7796
7588
|
};
|
|
7797
|
-
if (typeof window !== 'undefined' && typeof window.btoa === 'function') {
|
|
7798
|
-
btoa = function (str) { return window.btoa(unescape(encodeURIComponent(str))); };
|
|
7799
|
-
} else if (typeof Buffer === 'function') {
|
|
7800
|
-
btoa = function (str) { return Buffer.from(str, 'utf-8').toString('base64'); };
|
|
7801
|
-
}
|
|
7802
7589
|
|
|
7803
|
-
|
|
7804
|
-
|
|
7805
|
-
|
|
7806
|
-
|
|
7807
|
-
|
|
7808
|
-
|
|
7809
|
-
|
|
7810
|
-
|
|
7590
|
+
MagicString.prototype.lastLine = function lastLine () {
|
|
7591
|
+
var lineIndex = this.outro.lastIndexOf(n);
|
|
7592
|
+
if (lineIndex !== -1)
|
|
7593
|
+
{ return this.outro.substr(lineIndex + 1); }
|
|
7594
|
+
var lineStr = this.outro;
|
|
7595
|
+
var chunk = this.lastChunk;
|
|
7596
|
+
do {
|
|
7597
|
+
if (chunk.outro.length > 0) {
|
|
7598
|
+
lineIndex = chunk.outro.lastIndexOf(n);
|
|
7599
|
+
if (lineIndex !== -1)
|
|
7600
|
+
{ return chunk.outro.substr(lineIndex + 1) + lineStr; }
|
|
7601
|
+
lineStr = chunk.outro + lineStr;
|
|
7602
|
+
}
|
|
7811
7603
|
|
|
7812
|
-
|
|
7813
|
-
|
|
7814
|
-
|
|
7604
|
+
if (chunk.content.length > 0) {
|
|
7605
|
+
lineIndex = chunk.content.lastIndexOf(n);
|
|
7606
|
+
if (lineIndex !== -1)
|
|
7607
|
+
{ return chunk.content.substr(lineIndex + 1) + lineStr; }
|
|
7608
|
+
lineStr = chunk.content + lineStr;
|
|
7609
|
+
}
|
|
7815
7610
|
|
|
7816
|
-
|
|
7817
|
-
|
|
7611
|
+
if (chunk.intro.length > 0) {
|
|
7612
|
+
lineIndex = chunk.intro.lastIndexOf(n);
|
|
7613
|
+
if (lineIndex !== -1)
|
|
7614
|
+
{ return chunk.intro.substr(lineIndex + 1) + lineStr; }
|
|
7615
|
+
lineStr = chunk.intro + lineStr;
|
|
7616
|
+
}
|
|
7617
|
+
} while (chunk = chunk.previous);
|
|
7618
|
+
lineIndex = this.intro.lastIndexOf(n);
|
|
7619
|
+
if (lineIndex !== -1)
|
|
7620
|
+
{ return this.intro.substr(lineIndex + 1) + lineStr; }
|
|
7621
|
+
return this.intro + lineStr;
|
|
7818
7622
|
};
|
|
7819
7623
|
|
|
7820
|
-
function
|
|
7821
|
-
|
|
7624
|
+
MagicString.prototype.slice = function slice (start, end) {
|
|
7625
|
+
if ( start === void 0 ) start = 0;
|
|
7626
|
+
if ( end === void 0 ) end = this.original.length;
|
|
7822
7627
|
|
|
7823
|
-
|
|
7824
|
-
|
|
7628
|
+
while (start < 0) { start += this.original.length; }
|
|
7629
|
+
while (end < 0) { end += this.original.length; }
|
|
7825
7630
|
|
|
7826
|
-
|
|
7827
|
-
return null;
|
|
7828
|
-
}
|
|
7631
|
+
var result = '';
|
|
7829
7632
|
|
|
7830
|
-
//
|
|
7831
|
-
|
|
7832
|
-
|
|
7833
|
-
|
|
7834
|
-
|
|
7633
|
+
// find start chunk
|
|
7634
|
+
var chunk = this.firstChunk;
|
|
7635
|
+
while (chunk && (chunk.start > start || chunk.end <= start)) {
|
|
7636
|
+
// found end chunk before start
|
|
7637
|
+
if (chunk.start < end && chunk.end >= end) {
|
|
7638
|
+
return result;
|
|
7639
|
+
}
|
|
7640
|
+
|
|
7641
|
+
chunk = chunk.next;
|
|
7835
7642
|
}
|
|
7836
7643
|
|
|
7837
|
-
|
|
7838
|
-
|
|
7839
|
-
var numSpaces = /^ +/.exec(current)[0].length;
|
|
7840
|
-
return Math.min(numSpaces, previous);
|
|
7841
|
-
}, Infinity);
|
|
7644
|
+
if (chunk && chunk.edited && chunk.start !== start)
|
|
7645
|
+
{ throw new Error(("Cannot use replaced character " + start + " as slice start anchor.")); }
|
|
7842
7646
|
|
|
7843
|
-
|
|
7844
|
-
|
|
7647
|
+
var startChunk = chunk;
|
|
7648
|
+
while (chunk) {
|
|
7649
|
+
if (chunk.intro && (startChunk !== chunk || chunk.start === start)) {
|
|
7650
|
+
result += chunk.intro;
|
|
7651
|
+
}
|
|
7845
7652
|
|
|
7846
|
-
|
|
7847
|
-
|
|
7848
|
-
|
|
7653
|
+
var containsEnd = chunk.start < end && chunk.end >= end;
|
|
7654
|
+
if (containsEnd && chunk.edited && chunk.end !== end)
|
|
7655
|
+
{ throw new Error(("Cannot use replaced character " + end + " as slice end anchor.")); }
|
|
7849
7656
|
|
|
7850
|
-
|
|
7657
|
+
var sliceStart = startChunk === chunk ? start - chunk.start : 0;
|
|
7658
|
+
var sliceEnd = containsEnd ? chunk.content.length + end - chunk.end : chunk.content.length;
|
|
7851
7659
|
|
|
7852
|
-
|
|
7853
|
-
|
|
7854
|
-
|
|
7855
|
-
|
|
7660
|
+
result += chunk.content.slice(sliceStart, sliceEnd);
|
|
7661
|
+
|
|
7662
|
+
if (chunk.outro && (!containsEnd || chunk.end === end)) {
|
|
7663
|
+
result += chunk.outro;
|
|
7664
|
+
}
|
|
7856
7665
|
|
|
7857
|
-
|
|
7858
|
-
|
|
7859
|
-
|
|
7666
|
+
if (containsEnd) {
|
|
7667
|
+
break;
|
|
7668
|
+
}
|
|
7669
|
+
|
|
7670
|
+
chunk = chunk.next;
|
|
7860
7671
|
}
|
|
7861
7672
|
|
|
7862
|
-
return
|
|
7863
|
-
}
|
|
7673
|
+
return result;
|
|
7674
|
+
};
|
|
7864
7675
|
|
|
7865
|
-
|
|
7676
|
+
// TODO deprecate this? not really very useful
|
|
7677
|
+
MagicString.prototype.snip = function snip (start, end) {
|
|
7678
|
+
var clone = this.clone();
|
|
7679
|
+
clone.remove(0, start);
|
|
7680
|
+
clone.remove(end, clone.original.length);
|
|
7866
7681
|
|
|
7867
|
-
|
|
7868
|
-
|
|
7869
|
-
}
|
|
7682
|
+
return clone;
|
|
7683
|
+
};
|
|
7870
7684
|
|
|
7871
|
-
function
|
|
7872
|
-
|
|
7873
|
-
var lineOffsets = [];
|
|
7685
|
+
MagicString.prototype._split = function _split (index) {
|
|
7686
|
+
if (this.byStart[index] || this.byEnd[index]) { return; }
|
|
7874
7687
|
|
|
7875
|
-
|
|
7876
|
-
|
|
7877
|
-
pos += originalLines[i].length + 1;
|
|
7878
|
-
}
|
|
7688
|
+
var chunk = this.lastSearchedChunk;
|
|
7689
|
+
var searchForward = index > chunk.end;
|
|
7879
7690
|
|
|
7880
|
-
|
|
7881
|
-
|
|
7882
|
-
var j = lineOffsets.length;
|
|
7883
|
-
while (i < j) {
|
|
7884
|
-
var m = (i + j) >> 1;
|
|
7885
|
-
if (index < lineOffsets[m]) {
|
|
7886
|
-
j = m;
|
|
7887
|
-
} else {
|
|
7888
|
-
i = m + 1;
|
|
7889
|
-
}
|
|
7890
|
-
}
|
|
7891
|
-
var line = i - 1;
|
|
7892
|
-
var column = index - lineOffsets[line];
|
|
7893
|
-
return { line: line, column: column };
|
|
7894
|
-
};
|
|
7895
|
-
}
|
|
7691
|
+
while (chunk) {
|
|
7692
|
+
if (chunk.contains(index)) { return this._splitChunk(chunk, index); }
|
|
7896
7693
|
|
|
7897
|
-
|
|
7898
|
-
|
|
7899
|
-
this.generatedCodeLine = 0;
|
|
7900
|
-
this.generatedCodeColumn = 0;
|
|
7901
|
-
this.raw = [];
|
|
7902
|
-
this.rawSegments = this.raw[this.generatedCodeLine] = [];
|
|
7903
|
-
this.pending = null;
|
|
7694
|
+
chunk = searchForward ? this.byStart[chunk.end] : this.byEnd[chunk.start];
|
|
7695
|
+
}
|
|
7904
7696
|
};
|
|
7905
7697
|
|
|
7906
|
-
|
|
7907
|
-
if (content.length) {
|
|
7908
|
-
|
|
7909
|
-
|
|
7910
|
-
|
|
7911
|
-
|
|
7912
|
-
|
|
7913
|
-
} else if (this.pending) {
|
|
7914
|
-
this.rawSegments.push(this.pending);
|
|
7698
|
+
MagicString.prototype._splitChunk = function _splitChunk (chunk, index) {
|
|
7699
|
+
if (chunk.edited && chunk.content.length) {
|
|
7700
|
+
// zero-length edited chunks are a special case (overlapping replacements)
|
|
7701
|
+
var loc = getLocator(this.original)(index);
|
|
7702
|
+
throw new Error(
|
|
7703
|
+
("Cannot split a chunk that has already been edited (" + (loc.line) + ":" + (loc.column) + " – \"" + (chunk.original) + "\")")
|
|
7704
|
+
);
|
|
7915
7705
|
}
|
|
7916
7706
|
|
|
7917
|
-
|
|
7918
|
-
this.pending = null;
|
|
7919
|
-
};
|
|
7707
|
+
var newChunk = chunk.split(index);
|
|
7920
7708
|
|
|
7921
|
-
|
|
7922
|
-
|
|
7923
|
-
|
|
7709
|
+
this.byEnd[index] = chunk;
|
|
7710
|
+
this.byStart[index] = newChunk;
|
|
7711
|
+
this.byEnd[newChunk.end] = newChunk;
|
|
7924
7712
|
|
|
7925
|
-
|
|
7926
|
-
if (this.hires || first || sourcemapLocations.has(originalCharIndex)) {
|
|
7927
|
-
this.rawSegments.push([this.generatedCodeColumn, sourceIndex, loc.line, loc.column]);
|
|
7928
|
-
}
|
|
7713
|
+
if (chunk === this.lastChunk) { this.lastChunk = newChunk; }
|
|
7929
7714
|
|
|
7930
|
-
|
|
7931
|
-
|
|
7932
|
-
|
|
7933
|
-
this.generatedCodeLine += 1;
|
|
7934
|
-
this.raw[this.generatedCodeLine] = this.rawSegments = [];
|
|
7935
|
-
this.generatedCodeColumn = 0;
|
|
7936
|
-
first = true;
|
|
7937
|
-
} else {
|
|
7938
|
-
loc.column += 1;
|
|
7939
|
-
this.generatedCodeColumn += 1;
|
|
7940
|
-
first = false;
|
|
7941
|
-
}
|
|
7715
|
+
this.lastSearchedChunk = chunk;
|
|
7716
|
+
return true;
|
|
7717
|
+
};
|
|
7942
7718
|
|
|
7943
|
-
|
|
7719
|
+
MagicString.prototype.toString = function toString () {
|
|
7720
|
+
var str = this.intro;
|
|
7721
|
+
|
|
7722
|
+
var chunk = this.firstChunk;
|
|
7723
|
+
while (chunk) {
|
|
7724
|
+
str += chunk.toString();
|
|
7725
|
+
chunk = chunk.next;
|
|
7944
7726
|
}
|
|
7945
7727
|
|
|
7946
|
-
this.
|
|
7728
|
+
return str + this.outro;
|
|
7947
7729
|
};
|
|
7948
7730
|
|
|
7949
|
-
|
|
7950
|
-
|
|
7731
|
+
MagicString.prototype.isEmpty = function isEmpty () {
|
|
7732
|
+
var chunk = this.firstChunk;
|
|
7733
|
+
do {
|
|
7734
|
+
if (chunk.intro.length && chunk.intro.trim() ||
|
|
7735
|
+
chunk.content.length && chunk.content.trim() ||
|
|
7736
|
+
chunk.outro.length && chunk.outro.trim())
|
|
7737
|
+
{ return false; }
|
|
7738
|
+
} while (chunk = chunk.next);
|
|
7739
|
+
return true;
|
|
7740
|
+
};
|
|
7951
7741
|
|
|
7952
|
-
|
|
7742
|
+
MagicString.prototype.length = function length () {
|
|
7743
|
+
var chunk = this.firstChunk;
|
|
7744
|
+
var length = 0;
|
|
7745
|
+
do {
|
|
7746
|
+
length += chunk.intro.length + chunk.content.length + chunk.outro.length;
|
|
7747
|
+
} while (chunk = chunk.next);
|
|
7748
|
+
return length;
|
|
7749
|
+
};
|
|
7953
7750
|
|
|
7954
|
-
|
|
7955
|
-
|
|
7956
|
-
|
|
7957
|
-
this.raw[this.generatedCodeLine] = this.rawSegments = [];
|
|
7958
|
-
}
|
|
7959
|
-
this.generatedCodeColumn = 0;
|
|
7960
|
-
}
|
|
7751
|
+
MagicString.prototype.trimLines = function trimLines () {
|
|
7752
|
+
return this.trim('[\\r\\n]');
|
|
7753
|
+
};
|
|
7961
7754
|
|
|
7962
|
-
|
|
7755
|
+
MagicString.prototype.trim = function trim (charType) {
|
|
7756
|
+
return this.trimStart(charType).trimEnd(charType);
|
|
7963
7757
|
};
|
|
7964
7758
|
|
|
7965
|
-
|
|
7759
|
+
MagicString.prototype.trimEndAborted = function trimEndAborted (charType) {
|
|
7760
|
+
var rx = new RegExp((charType || '\\s') + '+$');
|
|
7966
7761
|
|
|
7967
|
-
|
|
7968
|
-
|
|
7969
|
-
insertRight: false,
|
|
7970
|
-
storeName: false
|
|
7971
|
-
};
|
|
7762
|
+
this.outro = this.outro.replace(rx, '');
|
|
7763
|
+
if (this.outro.length) { return true; }
|
|
7972
7764
|
|
|
7973
|
-
var
|
|
7974
|
-
if ( options === void 0 ) options = {};
|
|
7765
|
+
var chunk = this.lastChunk;
|
|
7975
7766
|
|
|
7976
|
-
|
|
7767
|
+
do {
|
|
7768
|
+
var end = chunk.end;
|
|
7769
|
+
var aborted = chunk.trimEnd(rx);
|
|
7977
7770
|
|
|
7978
|
-
|
|
7979
|
-
|
|
7980
|
-
|
|
7981
|
-
|
|
7982
|
-
|
|
7983
|
-
lastChunk: { writable: true, value: chunk },
|
|
7984
|
-
lastSearchedChunk: { writable: true, value: chunk },
|
|
7985
|
-
byStart: { writable: true, value: {} },
|
|
7986
|
-
byEnd: { writable: true, value: {} },
|
|
7987
|
-
filename: { writable: true, value: options.filename },
|
|
7988
|
-
indentExclusionRanges: { writable: true, value: options.indentExclusionRanges },
|
|
7989
|
-
sourcemapLocations: { writable: true, value: new BitSet() },
|
|
7990
|
-
storedNames: { writable: true, value: {} },
|
|
7991
|
-
indentStr: { writable: true, value: guessIndent(string) }
|
|
7992
|
-
});
|
|
7771
|
+
// if chunk was trimmed, we have a new lastChunk
|
|
7772
|
+
if (chunk.end !== end) {
|
|
7773
|
+
if (this.lastChunk === chunk) {
|
|
7774
|
+
this.lastChunk = chunk.next;
|
|
7775
|
+
}
|
|
7993
7776
|
|
|
7994
|
-
|
|
7995
|
-
|
|
7996
|
-
|
|
7777
|
+
this.byEnd[chunk.end] = chunk;
|
|
7778
|
+
this.byStart[chunk.next.start] = chunk.next;
|
|
7779
|
+
this.byEnd[chunk.next.end] = chunk.next;
|
|
7780
|
+
}
|
|
7997
7781
|
|
|
7998
|
-
|
|
7999
|
-
|
|
8000
|
-
};
|
|
7782
|
+
if (aborted) { return true; }
|
|
7783
|
+
chunk = chunk.previous;
|
|
7784
|
+
} while (chunk);
|
|
8001
7785
|
|
|
8002
|
-
|
|
8003
|
-
|
|
7786
|
+
return false;
|
|
7787
|
+
};
|
|
8004
7788
|
|
|
8005
|
-
|
|
7789
|
+
MagicString.prototype.trimEnd = function trimEnd (charType) {
|
|
7790
|
+
this.trimEndAborted(charType);
|
|
8006
7791
|
return this;
|
|
8007
7792
|
};
|
|
7793
|
+
MagicString.prototype.trimStartAborted = function trimStartAborted (charType) {
|
|
7794
|
+
var rx = new RegExp('^' + (charType || '\\s') + '+');
|
|
8008
7795
|
|
|
8009
|
-
|
|
8010
|
-
if (
|
|
7796
|
+
this.intro = this.intro.replace(rx, '');
|
|
7797
|
+
if (this.intro.length) { return true; }
|
|
8011
7798
|
|
|
8012
|
-
this.
|
|
7799
|
+
var chunk = this.firstChunk;
|
|
8013
7800
|
|
|
8014
|
-
|
|
7801
|
+
do {
|
|
7802
|
+
var end = chunk.end;
|
|
7803
|
+
var aborted = chunk.trimStart(rx);
|
|
8015
7804
|
|
|
8016
|
-
|
|
8017
|
-
|
|
8018
|
-
|
|
8019
|
-
this.intro += content;
|
|
8020
|
-
}
|
|
8021
|
-
return this;
|
|
8022
|
-
};
|
|
7805
|
+
if (chunk.end !== end) {
|
|
7806
|
+
// special case...
|
|
7807
|
+
if (chunk === this.lastChunk) { this.lastChunk = chunk.next; }
|
|
8023
7808
|
|
|
8024
|
-
|
|
8025
|
-
|
|
7809
|
+
this.byEnd[chunk.end] = chunk;
|
|
7810
|
+
this.byStart[chunk.next.start] = chunk.next;
|
|
7811
|
+
this.byEnd[chunk.next.end] = chunk.next;
|
|
7812
|
+
}
|
|
8026
7813
|
|
|
8027
|
-
|
|
7814
|
+
if (aborted) { return true; }
|
|
7815
|
+
chunk = chunk.next;
|
|
7816
|
+
} while (chunk);
|
|
8028
7817
|
|
|
8029
|
-
|
|
7818
|
+
return false;
|
|
7819
|
+
};
|
|
8030
7820
|
|
|
8031
|
-
|
|
8032
|
-
|
|
8033
|
-
} else {
|
|
8034
|
-
this.outro += content;
|
|
8035
|
-
}
|
|
7821
|
+
MagicString.prototype.trimStart = function trimStart (charType) {
|
|
7822
|
+
this.trimStartAborted(charType);
|
|
8036
7823
|
return this;
|
|
8037
7824
|
};
|
|
8038
7825
|
|
|
8039
|
-
|
|
8040
|
-
|
|
8041
|
-
|
|
8042
|
-
|
|
8043
|
-
|
|
8044
|
-
|
|
8045
|
-
|
|
8046
|
-
|
|
8047
|
-
|
|
7826
|
+
const mockRegexp = /\b((?:vitest|vi)\s*.\s*mock\(["`'\s](.*[@\w_-]+)["`'\s])[),]{1}/;
|
|
7827
|
+
const pathRegexp = /\b(?:vitest|vi)\s*.\s*(unmock|importActual|importMock)\(["`'\s](.*[@\w_-]+)["`'\s]\);?/mg;
|
|
7828
|
+
const isComment = (line) => {
|
|
7829
|
+
const commentStarts = ["//", "/*", "*"];
|
|
7830
|
+
line = line.trim();
|
|
7831
|
+
return commentStarts.some((cmt) => line.startsWith(cmt));
|
|
7832
|
+
};
|
|
7833
|
+
const parseMocks = (code) => {
|
|
7834
|
+
const splitted = code.split("\n");
|
|
7835
|
+
const mockCalls = {};
|
|
7836
|
+
let mockCall = 0;
|
|
7837
|
+
let lineIndex = -1;
|
|
7838
|
+
while (lineIndex < splitted.length) {
|
|
7839
|
+
lineIndex++;
|
|
7840
|
+
const line = splitted[lineIndex];
|
|
7841
|
+
if (!line)
|
|
7842
|
+
break;
|
|
7843
|
+
const mock = mockCalls[mockCall] || {
|
|
7844
|
+
code: "",
|
|
7845
|
+
declaraton: "",
|
|
7846
|
+
path: ""
|
|
7847
|
+
};
|
|
7848
|
+
if (!mock.code) {
|
|
7849
|
+
const started = mockRegexp.exec(line);
|
|
7850
|
+
if (!started || isComment(line))
|
|
7851
|
+
continue;
|
|
7852
|
+
mock.code += `${line}
|
|
7853
|
+
`;
|
|
7854
|
+
mock.declaraton = started[1];
|
|
7855
|
+
mock.path = started[2];
|
|
7856
|
+
mockCalls[mockCall] = mock;
|
|
7857
|
+
if (line.includes(");")) {
|
|
7858
|
+
mockCall++;
|
|
7859
|
+
continue;
|
|
7860
|
+
}
|
|
7861
|
+
continue;
|
|
7862
|
+
}
|
|
7863
|
+
mock.code += `${line}
|
|
7864
|
+
`;
|
|
7865
|
+
mockCalls[mockCall] = mock;
|
|
7866
|
+
const startNumber = (mock.code.match(/{/g) || []).length;
|
|
7867
|
+
const endNumber = (mock.code.match(/}/g) || []).length;
|
|
7868
|
+
if (line.includes(");")) {
|
|
7869
|
+
if (startNumber === endNumber || startNumber === 0 && endNumber === 0)
|
|
7870
|
+
mockCall++;
|
|
7871
|
+
}
|
|
7872
|
+
}
|
|
7873
|
+
return Object.values(mockCalls);
|
|
7874
|
+
};
|
|
7875
|
+
const getMethodCall = (method, actualPath, importPath) => {
|
|
7876
|
+
let nodeModule = "null";
|
|
7877
|
+
if (actualPath.includes("/node_modules/"))
|
|
7878
|
+
nodeModule = `"${importPath}"`;
|
|
7879
|
+
return `__vitest__${method}__("${actualPath}", ${nodeModule}`;
|
|
7880
|
+
};
|
|
7881
|
+
const MocksPlugin = () => {
|
|
7882
|
+
return {
|
|
7883
|
+
name: "vitest:mock-plugin",
|
|
7884
|
+
enforce: "post",
|
|
7885
|
+
async transform(code, id) {
|
|
7886
|
+
let m;
|
|
7887
|
+
const matchAll = code.matchAll(pathRegexp);
|
|
7888
|
+
for (const match of matchAll) {
|
|
7889
|
+
const [line, method, modulePath] = match;
|
|
7890
|
+
const filepath = await this.resolve(modulePath, id);
|
|
7891
|
+
if (filepath) {
|
|
7892
|
+
m ?? (m = new MagicString(code));
|
|
7893
|
+
const start = match.index || 0;
|
|
7894
|
+
const end = start + line.length;
|
|
7895
|
+
const overwrite = `${getMethodCall(method, filepath.id, modulePath)});`;
|
|
7896
|
+
m.overwrite(start, end, overwrite);
|
|
7897
|
+
}
|
|
7898
|
+
}
|
|
7899
|
+
if (mockRegexp.exec(code)) {
|
|
7900
|
+
const mocks = parseMocks((m == null ? void 0 : m.toString()) || code);
|
|
7901
|
+
for (const mock of mocks) {
|
|
7902
|
+
const filepath = await this.resolve(mock.path, id);
|
|
7903
|
+
if (!filepath)
|
|
7904
|
+
continue;
|
|
7905
|
+
m ?? (m = new MagicString(code));
|
|
7906
|
+
const overwrite = getMethodCall("mock", filepath.id, mock.path);
|
|
7907
|
+
m.prepend(mock.code.replace(mock.declaraton, overwrite));
|
|
7908
|
+
}
|
|
7909
|
+
}
|
|
7910
|
+
if (m) {
|
|
7911
|
+
return {
|
|
7912
|
+
code: m.toString(),
|
|
7913
|
+
map: m.generateMap()
|
|
7914
|
+
};
|
|
7915
|
+
}
|
|
7916
|
+
}
|
|
7917
|
+
};
|
|
7918
|
+
};
|
|
7919
|
+
|
|
7920
|
+
const spinnerMap = /* @__PURE__ */ new WeakMap();
|
|
7921
|
+
const pointer = c.yellow(F_POINTER);
|
|
7922
|
+
const skipped = c.yellow(F_DOWN);
|
|
7923
|
+
function getCols(delta = 0) {
|
|
7924
|
+
let length = process.stdout.columns;
|
|
7925
|
+
if (!length || isNaN(length))
|
|
7926
|
+
length = 30;
|
|
7927
|
+
return Math.max(length + delta, 0);
|
|
7928
|
+
}
|
|
7929
|
+
function divider(text, left, right) {
|
|
7930
|
+
const cols = getCols();
|
|
7931
|
+
if (text) {
|
|
7932
|
+
const textLength = stripAnsi(text).length;
|
|
7933
|
+
if (left == null && right != null) {
|
|
7934
|
+
left = cols - textLength - right;
|
|
7935
|
+
} else {
|
|
7936
|
+
left = left ?? Math.floor((cols - textLength) / 2);
|
|
7937
|
+
right = cols - textLength - left;
|
|
7938
|
+
}
|
|
7939
|
+
left = Math.max(0, left);
|
|
7940
|
+
right = Math.max(0, right);
|
|
7941
|
+
return `${F_LONG_DASH.repeat(left)}${text}${F_LONG_DASH.repeat(right)}`;
|
|
7942
|
+
}
|
|
7943
|
+
return F_LONG_DASH.repeat(cols);
|
|
7944
|
+
}
|
|
7945
|
+
function formatTestPath(root, path) {
|
|
7946
|
+
var _a;
|
|
7947
|
+
if (isAbsolute(path))
|
|
7948
|
+
path = relative(root, path);
|
|
7949
|
+
const dir = dirname(path);
|
|
7950
|
+
const ext = ((_a = path.match(/(\.(spec|test)\.[cm]?[tj]sx?)$/)) == null ? void 0 : _a[0]) || "";
|
|
7951
|
+
const base = basename(path, ext);
|
|
7952
|
+
return slash$1(c.dim(`${dir}/`) + c.bold(base)) + c.dim(ext);
|
|
7953
|
+
}
|
|
7954
|
+
function renderSnapshotSummary(rootDir, snapshots) {
|
|
7955
|
+
const summary = [];
|
|
7956
|
+
if (snapshots.added)
|
|
7957
|
+
summary.push(c.bold(c.green(`${snapshots.added} written`)));
|
|
7958
|
+
if (snapshots.unmatched)
|
|
7959
|
+
summary.push(c.bold(c.red(`${snapshots.unmatched} failed`)));
|
|
7960
|
+
if (snapshots.updated)
|
|
7961
|
+
summary.push(c.bold(c.green(`${snapshots.updated} updated `)));
|
|
7962
|
+
if (snapshots.filesRemoved) {
|
|
7963
|
+
if (snapshots.didUpdate)
|
|
7964
|
+
summary.push(c.bold(c.green(`${snapshots.filesRemoved} files removed `)));
|
|
7965
|
+
else
|
|
7966
|
+
summary.push(c.bold(c.yellow(`${snapshots.filesRemoved} files obsolete `)));
|
|
7967
|
+
}
|
|
7968
|
+
if (snapshots.filesRemovedList && snapshots.filesRemovedList.length) {
|
|
7969
|
+
const [head, ...tail] = snapshots.filesRemovedList;
|
|
7970
|
+
summary.push(`${c.gray(F_DOWN_RIGHT)} ${formatTestPath(rootDir, head)}`);
|
|
7971
|
+
tail.forEach((key) => {
|
|
7972
|
+
summary.push(` ${c.gray(F_DOT)} ${formatTestPath(rootDir, key)}`);
|
|
7973
|
+
});
|
|
7974
|
+
}
|
|
7975
|
+
if (snapshots.unchecked) {
|
|
7976
|
+
if (snapshots.didUpdate)
|
|
7977
|
+
summary.push(c.bold(c.green(`${snapshots.unchecked} removed`)));
|
|
7978
|
+
else
|
|
7979
|
+
summary.push(c.bold(c.yellow(`${snapshots.unchecked} obsolete`)));
|
|
7980
|
+
snapshots.uncheckedKeysByFile.forEach((uncheckedFile) => {
|
|
7981
|
+
summary.push(`${c.gray(F_DOWN_RIGHT)} ${formatTestPath(rootDir, uncheckedFile.filePath)}`);
|
|
7982
|
+
uncheckedFile.keys.forEach((key) => summary.push(` ${c.gray(F_DOT)} ${key}`));
|
|
7983
|
+
});
|
|
7984
|
+
}
|
|
7985
|
+
return summary;
|
|
7986
|
+
}
|
|
7987
|
+
function getStateString(tasks, name = "tests") {
|
|
7988
|
+
if (tasks.length === 0)
|
|
7989
|
+
return c.dim(`no ${name}`);
|
|
7990
|
+
const passed = tasks.filter((i) => {
|
|
7991
|
+
var _a;
|
|
7992
|
+
return ((_a = i.result) == null ? void 0 : _a.state) === "pass";
|
|
7993
|
+
});
|
|
7994
|
+
const failed = tasks.filter((i) => {
|
|
7995
|
+
var _a;
|
|
7996
|
+
return ((_a = i.result) == null ? void 0 : _a.state) === "fail";
|
|
7997
|
+
});
|
|
7998
|
+
const skipped2 = tasks.filter((i) => i.mode === "skip");
|
|
7999
|
+
const todo = tasks.filter((i) => i.mode === "todo");
|
|
8000
|
+
return [
|
|
8001
|
+
failed.length ? c.bold(c.red(`${failed.length} failed`)) : null,
|
|
8002
|
+
passed.length ? c.bold(c.green(`${passed.length} passed`)) : null,
|
|
8003
|
+
skipped2.length ? c.yellow(`${skipped2.length} skipped`) : null,
|
|
8004
|
+
todo.length ? c.gray(`${todo.length} todo`) : null
|
|
8005
|
+
].filter(Boolean).join(c.dim(" | ")) + c.gray(` (${tasks.length})`);
|
|
8006
|
+
}
|
|
8007
|
+
function getStateSymbol(task) {
|
|
8008
|
+
if (task.mode === "skip" || task.mode === "todo")
|
|
8009
|
+
return skipped;
|
|
8010
|
+
if (!task.result)
|
|
8011
|
+
return c.gray("\xB7");
|
|
8012
|
+
if (task.result.state === "run") {
|
|
8013
|
+
if (task.type === "suite")
|
|
8014
|
+
return pointer;
|
|
8015
|
+
let spinner = spinnerMap.get(task);
|
|
8016
|
+
if (!spinner) {
|
|
8017
|
+
spinner = elegantSpinner();
|
|
8018
|
+
spinnerMap.set(task, spinner);
|
|
8019
|
+
}
|
|
8020
|
+
return c.yellow(spinner());
|
|
8021
|
+
}
|
|
8022
|
+
if (task.result.state === "pass")
|
|
8023
|
+
return c.green(F_CHECK);
|
|
8024
|
+
if (task.result.state === "fail") {
|
|
8025
|
+
return task.type === "suite" ? pointer : c.red(F_CROSS);
|
|
8026
|
+
}
|
|
8027
|
+
return " ";
|
|
8028
|
+
}
|
|
8029
|
+
const spinnerFrames = process.platform === "win32" ? ["-", "\\", "|", "/"] : ["\u280B", "\u2819", "\u2839", "\u2838", "\u283C", "\u2834", "\u2826", "\u2827", "\u2807", "\u280F"];
|
|
8030
|
+
function elegantSpinner() {
|
|
8031
|
+
let index = 0;
|
|
8032
|
+
return () => {
|
|
8033
|
+
index = ++index % spinnerFrames.length;
|
|
8034
|
+
return spinnerFrames[index];
|
|
8035
|
+
};
|
|
8036
|
+
}
|
|
8048
8037
|
|
|
8049
|
-
|
|
8050
|
-
|
|
8038
|
+
class BaseReporter {
|
|
8039
|
+
constructor(ctx) {
|
|
8040
|
+
this.ctx = ctx;
|
|
8041
|
+
this.start = 0;
|
|
8042
|
+
this.end = 0;
|
|
8043
|
+
this.isTTY = process.stdout.isTTY && !process.env.CI;
|
|
8044
|
+
this.isFirstWatchRun = true;
|
|
8045
|
+
const mode = ctx.config.watch ? c.yellow(" DEV ") : c.cyan(" RUN ");
|
|
8046
|
+
this.ctx.log(`
|
|
8047
|
+
${c.inverse(c.bold(mode))} ${c.gray(this.ctx.config.root)}
|
|
8048
|
+
`);
|
|
8049
|
+
this.start = performance.now();
|
|
8050
|
+
}
|
|
8051
|
+
relative(path) {
|
|
8052
|
+
return relative(this.ctx.config.root, path);
|
|
8053
|
+
}
|
|
8054
|
+
async onFinished(files = this.ctx.state.getFiles()) {
|
|
8055
|
+
this.end = performance.now();
|
|
8056
|
+
await this.reportSummary(files);
|
|
8057
|
+
}
|
|
8058
|
+
onTaskUpdate(pack) {
|
|
8059
|
+
var _a, _b, _c;
|
|
8060
|
+
if (this.isTTY)
|
|
8061
|
+
return;
|
|
8062
|
+
const task = this.ctx.state.idMap[pack[0]];
|
|
8063
|
+
if (task.type === "test" && ((_a = task.result) == null ? void 0 : _a.state) && ((_b = task.result) == null ? void 0 : _b.state) !== "run") {
|
|
8064
|
+
this.ctx.log(` ${getStateSymbol(task)} ${getFullName(task)}`);
|
|
8065
|
+
if (task.result.state === "fail")
|
|
8066
|
+
this.ctx.log(c.red(` ${F_RIGHT} ${(_c = task.result.error) == null ? void 0 : _c.message}`));
|
|
8067
|
+
}
|
|
8068
|
+
}
|
|
8069
|
+
async onWatcherStart() {
|
|
8070
|
+
const failed = getTests(this.ctx.state.getFiles()).filter((i) => {
|
|
8071
|
+
var _a;
|
|
8072
|
+
return ((_a = i.result) == null ? void 0 : _a.state) === "fail";
|
|
8073
|
+
});
|
|
8074
|
+
if (failed.length)
|
|
8075
|
+
this.ctx.log(`
|
|
8076
|
+
${c.bold(c.inverse(c.red(" FAIL ")))}${c.red(` ${failed.length} tests failed. Watching for file changes...`)}`);
|
|
8077
|
+
else
|
|
8078
|
+
this.ctx.log(`
|
|
8079
|
+
${c.bold(c.inverse(c.green(" PASS ")))}${c.green(" Waiting for file changes...")}`);
|
|
8080
|
+
if (this.isFirstWatchRun) {
|
|
8081
|
+
this.isFirstWatchRun = false;
|
|
8082
|
+
this.ctx.log(c.gray("press any key to exit..."));
|
|
8083
|
+
}
|
|
8084
|
+
}
|
|
8085
|
+
async onWatcherRerun(files, trigger) {
|
|
8086
|
+
this.watchFilters = files;
|
|
8087
|
+
if (!this.ctx.config.silent) {
|
|
8088
|
+
this.ctx.console.clear();
|
|
8089
|
+
this.ctx.log(c.blue("Re-running tests...") + c.dim(` [ ${this.relative(trigger)} ]
|
|
8090
|
+
`));
|
|
8091
|
+
}
|
|
8092
|
+
}
|
|
8093
|
+
onUserConsoleLog(log) {
|
|
8094
|
+
const task = log.taskId ? this.ctx.state.idMap[log.taskId] : void 0;
|
|
8095
|
+
this.ctx.log(c.gray(log.type + c.dim(` | ${task ? getFullName(task) : "unknown test"}`)));
|
|
8096
|
+
process[log.type].write(`${log.content}
|
|
8097
|
+
`);
|
|
8098
|
+
}
|
|
8099
|
+
onServerRestart() {
|
|
8100
|
+
this.ctx.log(c.cyan("Restarted due to config changes..."));
|
|
8101
|
+
}
|
|
8102
|
+
async reportSummary(files) {
|
|
8103
|
+
var _a, _b;
|
|
8104
|
+
const suites = getSuites(files);
|
|
8105
|
+
const tests = getTests(files);
|
|
8106
|
+
const failedSuites = suites.filter((i) => {
|
|
8107
|
+
var _a2;
|
|
8108
|
+
return (_a2 = i.result) == null ? void 0 : _a2.error;
|
|
8109
|
+
});
|
|
8110
|
+
const failedTests = tests.filter((i) => {
|
|
8111
|
+
var _a2;
|
|
8112
|
+
return ((_a2 = i.result) == null ? void 0 : _a2.state) === "fail";
|
|
8113
|
+
});
|
|
8114
|
+
const failedTotal = failedSuites.length + failedTests.length;
|
|
8115
|
+
let current = 1;
|
|
8116
|
+
const errorDivider = () => this.ctx.error(`${c.red(c.dim(divider(`[${current++}/${failedTotal}]`, void 0, 1)))}
|
|
8117
|
+
`);
|
|
8118
|
+
if (failedSuites.length) {
|
|
8119
|
+
this.ctx.error(c.red(divider(c.bold(c.inverse(` Failed Suites ${failedSuites.length} `)))));
|
|
8120
|
+
this.ctx.error();
|
|
8121
|
+
for (const suite of failedSuites) {
|
|
8122
|
+
const filepath = (suite == null ? void 0 : suite.filepath) || "";
|
|
8123
|
+
this.ctx.error(c.red(`
|
|
8124
|
+
- ${getFullName(suite)} ${c.dim(`[ ${this.relative(filepath)} ]`)}`));
|
|
8125
|
+
await printError((_a = suite.result) == null ? void 0 : _a.error, this.ctx);
|
|
8126
|
+
errorDivider();
|
|
8127
|
+
}
|
|
8128
|
+
}
|
|
8129
|
+
if (failedTests.length) {
|
|
8130
|
+
this.ctx.error(c.red(divider(c.bold(c.inverse(` Failed Tests ${failedTests.length} `)))));
|
|
8131
|
+
this.ctx.error();
|
|
8132
|
+
for (const test of failedTests) {
|
|
8133
|
+
this.ctx.error(`${c.red(c.bold(c.inverse(" FAIL ")))} ${getFullName(test)}`);
|
|
8134
|
+
await printError((_b = test.result) == null ? void 0 : _b.error, this.ctx);
|
|
8135
|
+
errorDivider();
|
|
8136
|
+
}
|
|
8137
|
+
}
|
|
8138
|
+
const executionTime = this.end - this.start;
|
|
8139
|
+
const threadTime = tests.reduce((acc, test) => {
|
|
8140
|
+
var _a2;
|
|
8141
|
+
return acc + (((_a2 = test.result) == null ? void 0 : _a2.end) ? test.result.end - test.result.start : 0);
|
|
8142
|
+
}, 0);
|
|
8143
|
+
const padTitle = (str) => c.dim(`${str.padStart(10)} `);
|
|
8144
|
+
const time = (time2) => {
|
|
8145
|
+
if (time2 > 1e3)
|
|
8146
|
+
return `${(time2 / 1e3).toFixed(2)}s`;
|
|
8147
|
+
return `${Math.round(time2)}ms`;
|
|
8148
|
+
};
|
|
8149
|
+
const snapshotOutput = renderSnapshotSummary(this.ctx.config.root, this.ctx.snapshot.summary);
|
|
8150
|
+
if (snapshotOutput.length) {
|
|
8151
|
+
this.ctx.log(snapshotOutput.map((t, i) => i === 0 ? `${padTitle("Snapshots")} ${t}` : `${padTitle("")} ${t}`).join("\n"));
|
|
8152
|
+
if (snapshotOutput.length > 1)
|
|
8153
|
+
this.ctx.log();
|
|
8154
|
+
}
|
|
8155
|
+
this.ctx.log(padTitle("Test Files"), getStateString(files));
|
|
8156
|
+
this.ctx.log(padTitle("Tests"), getStateString(tests));
|
|
8157
|
+
if (this.watchFilters)
|
|
8158
|
+
this.ctx.log(padTitle("Time"), time(threadTime));
|
|
8159
|
+
else
|
|
8160
|
+
this.ctx.log(padTitle("Time"), time(executionTime) + c.gray(` (in thread ${time(threadTime)}, ${(executionTime / threadTime * 100).toFixed(2)}%)`));
|
|
8161
|
+
this.ctx.log();
|
|
8162
|
+
}
|
|
8163
|
+
}
|
|
8051
8164
|
|
|
8052
|
-
|
|
8053
|
-
|
|
8054
|
-
|
|
8165
|
+
const ESC = '\u001B[';
|
|
8166
|
+
const OSC = '\u001B]';
|
|
8167
|
+
const BEL = '\u0007';
|
|
8168
|
+
const SEP = ';';
|
|
8169
|
+
const isTerminalApp = process.env.TERM_PROGRAM === 'Apple_Terminal';
|
|
8055
8170
|
|
|
8056
|
-
|
|
8057
|
-
}
|
|
8171
|
+
const ansiEscapes = {};
|
|
8058
8172
|
|
|
8059
|
-
|
|
8173
|
+
ansiEscapes.cursorTo = (x, y) => {
|
|
8174
|
+
if (typeof x !== 'number') {
|
|
8175
|
+
throw new TypeError('The `x` argument is required');
|
|
8060
8176
|
}
|
|
8061
8177
|
|
|
8062
|
-
|
|
8063
|
-
|
|
8064
|
-
if (this.indentExclusionRanges) {
|
|
8065
|
-
cloned.indentExclusionRanges = this.indentExclusionRanges.slice();
|
|
8178
|
+
if (typeof y !== 'number') {
|
|
8179
|
+
return ESC + (x + 1) + 'G';
|
|
8066
8180
|
}
|
|
8067
8181
|
|
|
8068
|
-
|
|
8069
|
-
|
|
8070
|
-
cloned.intro = this.intro;
|
|
8071
|
-
cloned.outro = this.outro;
|
|
8072
|
-
|
|
8073
|
-
return cloned;
|
|
8182
|
+
return ESC + (y + 1) + ';' + (x + 1) + 'H';
|
|
8074
8183
|
};
|
|
8075
8184
|
|
|
8076
|
-
|
|
8077
|
-
|
|
8078
|
-
|
|
8079
|
-
options = options || {};
|
|
8080
|
-
|
|
8081
|
-
var sourceIndex = 0;
|
|
8082
|
-
var names = Object.keys(this.storedNames);
|
|
8083
|
-
var mappings = new Mappings(options.hires);
|
|
8084
|
-
|
|
8085
|
-
var locate = getLocator(this.original);
|
|
8086
|
-
|
|
8087
|
-
if (this.intro) {
|
|
8088
|
-
mappings.advance(this.intro);
|
|
8185
|
+
ansiEscapes.cursorMove = (x, y) => {
|
|
8186
|
+
if (typeof x !== 'number') {
|
|
8187
|
+
throw new TypeError('The `x` argument is required');
|
|
8089
8188
|
}
|
|
8090
8189
|
|
|
8091
|
-
|
|
8092
|
-
var loc = locate(chunk.start);
|
|
8093
|
-
|
|
8094
|
-
if (chunk.intro.length) { mappings.advance(chunk.intro); }
|
|
8095
|
-
|
|
8096
|
-
if (chunk.edited) {
|
|
8097
|
-
mappings.addEdit(
|
|
8098
|
-
sourceIndex,
|
|
8099
|
-
chunk.content,
|
|
8100
|
-
loc,
|
|
8101
|
-
chunk.storeName ? names.indexOf(chunk.original) : -1
|
|
8102
|
-
);
|
|
8103
|
-
} else {
|
|
8104
|
-
mappings.addUneditedChunk(sourceIndex, chunk, this$1$1.original, loc, this$1$1.sourcemapLocations);
|
|
8105
|
-
}
|
|
8106
|
-
|
|
8107
|
-
if (chunk.outro.length) { mappings.advance(chunk.outro); }
|
|
8108
|
-
});
|
|
8109
|
-
|
|
8110
|
-
return {
|
|
8111
|
-
file: options.file ? options.file.split(/[/\\]/).pop() : null,
|
|
8112
|
-
sources: [options.source ? getRelativePath(options.file || '', options.source) : null],
|
|
8113
|
-
sourcesContent: options.includeContent ? [this.original] : [null],
|
|
8114
|
-
names: names,
|
|
8115
|
-
mappings: mappings.raw
|
|
8116
|
-
};
|
|
8117
|
-
};
|
|
8118
|
-
|
|
8119
|
-
MagicString.prototype.generateMap = function generateMap (options) {
|
|
8120
|
-
return new SourceMap(this.generateDecodedMap(options));
|
|
8121
|
-
};
|
|
8122
|
-
|
|
8123
|
-
MagicString.prototype.getIndentString = function getIndentString () {
|
|
8124
|
-
return this.indentStr === null ? '\t' : this.indentStr;
|
|
8125
|
-
};
|
|
8126
|
-
|
|
8127
|
-
MagicString.prototype.indent = function indent (indentStr, options) {
|
|
8128
|
-
var pattern = /^[^\r\n]/gm;
|
|
8190
|
+
let returnValue = '';
|
|
8129
8191
|
|
|
8130
|
-
if (
|
|
8131
|
-
|
|
8132
|
-
|
|
8192
|
+
if (x < 0) {
|
|
8193
|
+
returnValue += ESC + (-x) + 'D';
|
|
8194
|
+
} else if (x > 0) {
|
|
8195
|
+
returnValue += ESC + x + 'C';
|
|
8133
8196
|
}
|
|
8134
8197
|
|
|
8135
|
-
|
|
8136
|
-
|
|
8137
|
-
if (
|
|
8138
|
-
|
|
8139
|
-
options = options || {};
|
|
8140
|
-
|
|
8141
|
-
// Process exclusion ranges
|
|
8142
|
-
var isExcluded = {};
|
|
8143
|
-
|
|
8144
|
-
if (options.exclude) {
|
|
8145
|
-
var exclusions =
|
|
8146
|
-
typeof options.exclude[0] === 'number' ? [options.exclude] : options.exclude;
|
|
8147
|
-
exclusions.forEach(function (exclusion) {
|
|
8148
|
-
for (var i = exclusion[0]; i < exclusion[1]; i += 1) {
|
|
8149
|
-
isExcluded[i] = true;
|
|
8150
|
-
}
|
|
8151
|
-
});
|
|
8198
|
+
if (y < 0) {
|
|
8199
|
+
returnValue += ESC + (-y) + 'A';
|
|
8200
|
+
} else if (y > 0) {
|
|
8201
|
+
returnValue += ESC + y + 'B';
|
|
8152
8202
|
}
|
|
8153
8203
|
|
|
8154
|
-
|
|
8155
|
-
|
|
8156
|
-
if (shouldIndentNextCharacter) { return ("" + indentStr + match); }
|
|
8157
|
-
shouldIndentNextCharacter = true;
|
|
8158
|
-
return match;
|
|
8159
|
-
};
|
|
8160
|
-
|
|
8161
|
-
this.intro = this.intro.replace(pattern, replacer);
|
|
8162
|
-
|
|
8163
|
-
var charIndex = 0;
|
|
8164
|
-
var chunk = this.firstChunk;
|
|
8165
|
-
|
|
8166
|
-
while (chunk) {
|
|
8167
|
-
var end = chunk.end;
|
|
8168
|
-
|
|
8169
|
-
if (chunk.edited) {
|
|
8170
|
-
if (!isExcluded[charIndex]) {
|
|
8171
|
-
chunk.content = chunk.content.replace(pattern, replacer);
|
|
8172
|
-
|
|
8173
|
-
if (chunk.content.length) {
|
|
8174
|
-
shouldIndentNextCharacter = chunk.content[chunk.content.length - 1] === '\n';
|
|
8175
|
-
}
|
|
8176
|
-
}
|
|
8177
|
-
} else {
|
|
8178
|
-
charIndex = chunk.start;
|
|
8179
|
-
|
|
8180
|
-
while (charIndex < end) {
|
|
8181
|
-
if (!isExcluded[charIndex]) {
|
|
8182
|
-
var char = this.original[charIndex];
|
|
8183
|
-
|
|
8184
|
-
if (char === '\n') {
|
|
8185
|
-
shouldIndentNextCharacter = true;
|
|
8186
|
-
} else if (char !== '\r' && shouldIndentNextCharacter) {
|
|
8187
|
-
shouldIndentNextCharacter = false;
|
|
8188
|
-
|
|
8189
|
-
if (charIndex === chunk.start) {
|
|
8190
|
-
chunk.prependRight(indentStr);
|
|
8191
|
-
} else {
|
|
8192
|
-
this._splitChunk(chunk, charIndex);
|
|
8193
|
-
chunk = chunk.next;
|
|
8194
|
-
chunk.prependRight(indentStr);
|
|
8195
|
-
}
|
|
8196
|
-
}
|
|
8197
|
-
}
|
|
8198
|
-
|
|
8199
|
-
charIndex += 1;
|
|
8200
|
-
}
|
|
8201
|
-
}
|
|
8202
|
-
|
|
8203
|
-
charIndex = chunk.end;
|
|
8204
|
-
chunk = chunk.next;
|
|
8205
|
-
}
|
|
8204
|
+
return returnValue;
|
|
8205
|
+
};
|
|
8206
8206
|
|
|
8207
|
-
|
|
8207
|
+
ansiEscapes.cursorUp = (count = 1) => ESC + count + 'A';
|
|
8208
|
+
ansiEscapes.cursorDown = (count = 1) => ESC + count + 'B';
|
|
8209
|
+
ansiEscapes.cursorForward = (count = 1) => ESC + count + 'C';
|
|
8210
|
+
ansiEscapes.cursorBackward = (count = 1) => ESC + count + 'D';
|
|
8208
8211
|
|
|
8209
|
-
|
|
8210
|
-
|
|
8212
|
+
ansiEscapes.cursorLeft = ESC + 'G';
|
|
8213
|
+
ansiEscapes.cursorSavePosition = isTerminalApp ? '\u001B7' : ESC + 's';
|
|
8214
|
+
ansiEscapes.cursorRestorePosition = isTerminalApp ? '\u001B8' : ESC + 'u';
|
|
8215
|
+
ansiEscapes.cursorGetPosition = ESC + '6n';
|
|
8216
|
+
ansiEscapes.cursorNextLine = ESC + 'E';
|
|
8217
|
+
ansiEscapes.cursorPrevLine = ESC + 'F';
|
|
8218
|
+
ansiEscapes.cursorHide = ESC + '?25l';
|
|
8219
|
+
ansiEscapes.cursorShow = ESC + '?25h';
|
|
8211
8220
|
|
|
8212
|
-
|
|
8213
|
-
|
|
8214
|
-
};
|
|
8221
|
+
ansiEscapes.eraseLines = count => {
|
|
8222
|
+
let clear = '';
|
|
8215
8223
|
|
|
8216
|
-
|
|
8217
|
-
|
|
8218
|
-
console.warn('magicString.insertLeft(...) is deprecated. Use magicString.appendLeft(...) instead'); // eslint-disable-line no-console
|
|
8219
|
-
warned.insertLeft = true;
|
|
8224
|
+
for (let i = 0; i < count; i++) {
|
|
8225
|
+
clear += ansiEscapes.eraseLine + (i < count - 1 ? ansiEscapes.cursorUp() : '');
|
|
8220
8226
|
}
|
|
8221
8227
|
|
|
8222
|
-
|
|
8223
|
-
|
|
8224
|
-
|
|
8225
|
-
MagicString.prototype.insertRight = function insertRight (index, content) {
|
|
8226
|
-
if (!warned.insertRight) {
|
|
8227
|
-
console.warn('magicString.insertRight(...) is deprecated. Use magicString.prependRight(...) instead'); // eslint-disable-line no-console
|
|
8228
|
-
warned.insertRight = true;
|
|
8228
|
+
if (count) {
|
|
8229
|
+
clear += ansiEscapes.cursorLeft;
|
|
8229
8230
|
}
|
|
8230
8231
|
|
|
8231
|
-
return
|
|
8232
|
+
return clear;
|
|
8232
8233
|
};
|
|
8233
8234
|
|
|
8234
|
-
|
|
8235
|
-
|
|
8236
|
-
|
|
8237
|
-
|
|
8238
|
-
|
|
8239
|
-
|
|
8240
|
-
|
|
8241
|
-
|
|
8242
|
-
var last = this.byEnd[end];
|
|
8243
|
-
|
|
8244
|
-
var oldLeft = first.previous;
|
|
8245
|
-
var oldRight = last.next;
|
|
8246
|
-
|
|
8247
|
-
var newRight = this.byStart[index];
|
|
8248
|
-
if (!newRight && last === this.lastChunk) { return this; }
|
|
8249
|
-
var newLeft = newRight ? newRight.previous : this.lastChunk;
|
|
8250
|
-
|
|
8251
|
-
if (oldLeft) { oldLeft.next = oldRight; }
|
|
8252
|
-
if (oldRight) { oldRight.previous = oldLeft; }
|
|
8253
|
-
|
|
8254
|
-
if (newLeft) { newLeft.next = first; }
|
|
8255
|
-
if (newRight) { newRight.previous = last; }
|
|
8256
|
-
|
|
8257
|
-
if (!first.previous) { this.firstChunk = last.next; }
|
|
8258
|
-
if (!last.next) {
|
|
8259
|
-
this.lastChunk = first.previous;
|
|
8260
|
-
this.lastChunk.next = null;
|
|
8261
|
-
}
|
|
8262
|
-
|
|
8263
|
-
first.previous = newLeft;
|
|
8264
|
-
last.next = newRight || null;
|
|
8235
|
+
ansiEscapes.eraseEndLine = ESC + 'K';
|
|
8236
|
+
ansiEscapes.eraseStartLine = ESC + '1K';
|
|
8237
|
+
ansiEscapes.eraseLine = ESC + '2K';
|
|
8238
|
+
ansiEscapes.eraseDown = ESC + 'J';
|
|
8239
|
+
ansiEscapes.eraseUp = ESC + '1J';
|
|
8240
|
+
ansiEscapes.eraseScreen = ESC + '2J';
|
|
8241
|
+
ansiEscapes.scrollUp = ESC + 'S';
|
|
8242
|
+
ansiEscapes.scrollDown = ESC + 'T';
|
|
8265
8243
|
|
|
8266
|
-
|
|
8267
|
-
if (!newRight) { this.lastChunk = last; }
|
|
8268
|
-
return this;
|
|
8269
|
-
};
|
|
8244
|
+
ansiEscapes.clearScreen = '\u001Bc';
|
|
8270
8245
|
|
|
8271
|
-
|
|
8272
|
-
|
|
8246
|
+
ansiEscapes.clearTerminal = process.platform === 'win32' ?
|
|
8247
|
+
`${ansiEscapes.eraseScreen}${ESC}0f` :
|
|
8248
|
+
// 1. Erases the screen (Only done in case `2` is not supported)
|
|
8249
|
+
// 2. Erases the whole screen including scrollback buffer
|
|
8250
|
+
// 3. Moves cursor to the top-left position
|
|
8251
|
+
// More info: https://www.real-world-systems.com/docs/ANSIcode.html
|
|
8252
|
+
`${ansiEscapes.eraseScreen}${ESC}3J${ESC}H`;
|
|
8273
8253
|
|
|
8274
|
-
|
|
8275
|
-
while (end < 0) { end += this.original.length; }
|
|
8254
|
+
ansiEscapes.beep = BEL;
|
|
8276
8255
|
|
|
8277
|
-
|
|
8278
|
-
|
|
8279
|
-
|
|
8256
|
+
ansiEscapes.link = (text, url) => {
|
|
8257
|
+
return [
|
|
8258
|
+
OSC,
|
|
8259
|
+
'8',
|
|
8260
|
+
SEP,
|
|
8261
|
+
SEP,
|
|
8262
|
+
url,
|
|
8263
|
+
BEL,
|
|
8264
|
+
text,
|
|
8265
|
+
OSC,
|
|
8266
|
+
'8',
|
|
8267
|
+
SEP,
|
|
8268
|
+
SEP,
|
|
8269
|
+
BEL
|
|
8270
|
+
].join('');
|
|
8271
|
+
};
|
|
8280
8272
|
|
|
8281
|
-
|
|
8282
|
-
|
|
8273
|
+
ansiEscapes.image = (buffer, options = {}) => {
|
|
8274
|
+
let returnValue = `${OSC}1337;File=inline=1`;
|
|
8283
8275
|
|
|
8284
|
-
if (options
|
|
8285
|
-
|
|
8286
|
-
|
|
8287
|
-
warned.storeName = true;
|
|
8288
|
-
}
|
|
8276
|
+
if (options.width) {
|
|
8277
|
+
returnValue += `;width=${options.width}`;
|
|
8278
|
+
}
|
|
8289
8279
|
|
|
8290
|
-
|
|
8280
|
+
if (options.height) {
|
|
8281
|
+
returnValue += `;height=${options.height}`;
|
|
8291
8282
|
}
|
|
8292
|
-
var storeName = options !== undefined ? options.storeName : false;
|
|
8293
|
-
var contentOnly = options !== undefined ? options.contentOnly : false;
|
|
8294
8283
|
|
|
8295
|
-
if (
|
|
8296
|
-
|
|
8297
|
-
this.storedNames[original] = true;
|
|
8284
|
+
if (options.preserveAspectRatio === false) {
|
|
8285
|
+
returnValue += ';preserveAspectRatio=0';
|
|
8298
8286
|
}
|
|
8299
8287
|
|
|
8300
|
-
|
|
8301
|
-
|
|
8288
|
+
return returnValue + ':' + buffer.toString('base64') + BEL;
|
|
8289
|
+
};
|
|
8302
8290
|
|
|
8303
|
-
|
|
8304
|
-
|
|
8305
|
-
|
|
8291
|
+
ansiEscapes.iTerm = {
|
|
8292
|
+
setCwd: (cwd = process.cwd()) => `${OSC}50;CurrentDir=${cwd}${BEL}`,
|
|
8293
|
+
|
|
8294
|
+
annotation: (message, options = {}) => {
|
|
8295
|
+
let returnValue = `${OSC}1337;`;
|
|
8296
|
+
|
|
8297
|
+
const hasX = typeof options.x !== 'undefined';
|
|
8298
|
+
const hasY = typeof options.y !== 'undefined';
|
|
8299
|
+
if ((hasX || hasY) && !(hasX && hasY && typeof options.length !== 'undefined')) {
|
|
8300
|
+
throw new Error('`x`, `y` and `length` must be defined when `x` or `y` is defined');
|
|
8306
8301
|
}
|
|
8307
8302
|
|
|
8308
|
-
|
|
8303
|
+
message = message.replace(/\|/g, '');
|
|
8309
8304
|
|
|
8310
|
-
|
|
8311
|
-
var chunk = first.next;
|
|
8312
|
-
while (chunk !== last) {
|
|
8313
|
-
chunk.edit('', false);
|
|
8314
|
-
chunk = chunk.next;
|
|
8315
|
-
}
|
|
8305
|
+
returnValue += options.isHidden ? 'AddHiddenAnnotation=' : 'AddAnnotation=';
|
|
8316
8306
|
|
|
8317
|
-
|
|
8307
|
+
if (options.length > 0) {
|
|
8308
|
+
returnValue +=
|
|
8309
|
+
(hasX ?
|
|
8310
|
+
[message, options.length, options.x, options.y] :
|
|
8311
|
+
[options.length, message]).join('|');
|
|
8312
|
+
} else {
|
|
8313
|
+
returnValue += message;
|
|
8318
8314
|
}
|
|
8319
|
-
} else {
|
|
8320
|
-
// must be inserting at the end
|
|
8321
|
-
var newChunk = new Chunk(start, end, '').edit(content, storeName);
|
|
8322
8315
|
|
|
8323
|
-
|
|
8324
|
-
last.next = newChunk;
|
|
8325
|
-
newChunk.previous = last;
|
|
8316
|
+
return returnValue + BEL;
|
|
8326
8317
|
}
|
|
8327
|
-
return this;
|
|
8328
|
-
};
|
|
8329
|
-
|
|
8330
|
-
MagicString.prototype.prepend = function prepend (content) {
|
|
8331
|
-
if (typeof content !== 'string') { throw new TypeError('outro content must be a string'); }
|
|
8332
|
-
|
|
8333
|
-
this.intro = content + this.intro;
|
|
8334
|
-
return this;
|
|
8335
8318
|
};
|
|
8336
8319
|
|
|
8337
|
-
|
|
8338
|
-
|
|
8320
|
+
const restoreCursor = onetime(() => {
|
|
8321
|
+
signalExit(() => {
|
|
8322
|
+
process$1.stderr.write('\u001B[?25h');
|
|
8323
|
+
}, {alwaysLast: true});
|
|
8324
|
+
});
|
|
8339
8325
|
|
|
8340
|
-
|
|
8326
|
+
let isHidden = false;
|
|
8341
8327
|
|
|
8342
|
-
|
|
8328
|
+
const cliCursor = {};
|
|
8343
8329
|
|
|
8344
|
-
|
|
8345
|
-
|
|
8346
|
-
|
|
8347
|
-
this.intro = content + this.intro;
|
|
8330
|
+
cliCursor.show = (writableStream = process$1.stderr) => {
|
|
8331
|
+
if (!writableStream.isTTY) {
|
|
8332
|
+
return;
|
|
8348
8333
|
}
|
|
8349
|
-
|
|
8334
|
+
|
|
8335
|
+
isHidden = false;
|
|
8336
|
+
writableStream.write('\u001B[?25h');
|
|
8350
8337
|
};
|
|
8351
8338
|
|
|
8352
|
-
|
|
8353
|
-
if (
|
|
8339
|
+
cliCursor.hide = (writableStream = process$1.stderr) => {
|
|
8340
|
+
if (!writableStream.isTTY) {
|
|
8341
|
+
return;
|
|
8342
|
+
}
|
|
8354
8343
|
|
|
8355
|
-
|
|
8344
|
+
restoreCursor();
|
|
8345
|
+
isHidden = true;
|
|
8346
|
+
writableStream.write('\u001B[?25l');
|
|
8347
|
+
};
|
|
8356
8348
|
|
|
8357
|
-
|
|
8349
|
+
cliCursor.toggle = (force, writableStream) => {
|
|
8350
|
+
if (force !== undefined) {
|
|
8351
|
+
isHidden = force;
|
|
8352
|
+
}
|
|
8358
8353
|
|
|
8359
|
-
if (
|
|
8360
|
-
|
|
8354
|
+
if (isHidden) {
|
|
8355
|
+
cliCursor.show(writableStream);
|
|
8361
8356
|
} else {
|
|
8362
|
-
|
|
8357
|
+
cliCursor.hide(writableStream);
|
|
8363
8358
|
}
|
|
8364
|
-
return this;
|
|
8365
8359
|
};
|
|
8366
8360
|
|
|
8367
|
-
|
|
8368
|
-
|
|
8369
|
-
|
|
8370
|
-
|
|
8371
|
-
if (start === end) { return this; }
|
|
8372
|
-
|
|
8373
|
-
if (start < 0 || end > this.original.length) { throw new Error('Character is out of bounds'); }
|
|
8374
|
-
if (start > end) { throw new Error('end must be greater than start'); }
|
|
8361
|
+
const ESCAPES = new Set([
|
|
8362
|
+
'\u001B',
|
|
8363
|
+
'\u009B',
|
|
8364
|
+
]);
|
|
8375
8365
|
|
|
8376
|
-
|
|
8377
|
-
|
|
8366
|
+
const END_CODE = 39;
|
|
8367
|
+
const ANSI_ESCAPE_BELL = '\u0007';
|
|
8368
|
+
const ANSI_CSI = '[';
|
|
8369
|
+
const ANSI_OSC = ']';
|
|
8370
|
+
const ANSI_SGR_TERMINATOR = 'm';
|
|
8371
|
+
const ANSI_ESCAPE_LINK = `${ANSI_OSC}8;;`;
|
|
8378
8372
|
|
|
8379
|
-
|
|
8373
|
+
const wrapAnsiCode = code => `${ESCAPES.values().next().value}${ANSI_CSI}${code}${ANSI_SGR_TERMINATOR}`;
|
|
8374
|
+
const wrapAnsiHyperlink = uri => `${ESCAPES.values().next().value}${ANSI_ESCAPE_LINK}${uri}${ANSI_ESCAPE_BELL}`;
|
|
8380
8375
|
|
|
8381
|
-
|
|
8382
|
-
|
|
8383
|
-
|
|
8384
|
-
chunk.edit('');
|
|
8376
|
+
// Calculate the length of words split on ' ', ignoring
|
|
8377
|
+
// the extra characters added by ansi escape codes
|
|
8378
|
+
const wordLengths = string => string.split(' ').map(character => stringWidth(character));
|
|
8385
8379
|
|
|
8386
|
-
|
|
8387
|
-
|
|
8388
|
-
|
|
8389
|
-
|
|
8380
|
+
// Wrap a long word across multiple rows
|
|
8381
|
+
// Ansi escape codes do not count towards length
|
|
8382
|
+
const wrapWord = (rows, word, columns) => {
|
|
8383
|
+
const characters = [...word];
|
|
8390
8384
|
|
|
8391
|
-
|
|
8392
|
-
|
|
8393
|
-
|
|
8394
|
-
var chunk = this.lastChunk;
|
|
8395
|
-
do {
|
|
8396
|
-
if (chunk.outro.length)
|
|
8397
|
-
{ return chunk.outro[chunk.outro.length - 1]; }
|
|
8398
|
-
if (chunk.content.length)
|
|
8399
|
-
{ return chunk.content[chunk.content.length - 1]; }
|
|
8400
|
-
if (chunk.intro.length)
|
|
8401
|
-
{ return chunk.intro[chunk.intro.length - 1]; }
|
|
8402
|
-
} while (chunk = chunk.previous);
|
|
8403
|
-
if (this.intro.length)
|
|
8404
|
-
{ return this.intro[this.intro.length - 1]; }
|
|
8405
|
-
return '';
|
|
8406
|
-
};
|
|
8385
|
+
let isInsideEscape = false;
|
|
8386
|
+
let isInsideLinkEscape = false;
|
|
8387
|
+
let visible = stringWidth(stripAnsi(rows[rows.length - 1]));
|
|
8407
8388
|
|
|
8408
|
-
|
|
8409
|
-
|
|
8410
|
-
if (lineIndex !== -1)
|
|
8411
|
-
{ return this.outro.substr(lineIndex + 1); }
|
|
8412
|
-
var lineStr = this.outro;
|
|
8413
|
-
var chunk = this.lastChunk;
|
|
8414
|
-
do {
|
|
8415
|
-
if (chunk.outro.length > 0) {
|
|
8416
|
-
lineIndex = chunk.outro.lastIndexOf(n);
|
|
8417
|
-
if (lineIndex !== -1)
|
|
8418
|
-
{ return chunk.outro.substr(lineIndex + 1) + lineStr; }
|
|
8419
|
-
lineStr = chunk.outro + lineStr;
|
|
8420
|
-
}
|
|
8389
|
+
for (const [index, character] of characters.entries()) {
|
|
8390
|
+
const characterLength = stringWidth(character);
|
|
8421
8391
|
|
|
8422
|
-
if (
|
|
8423
|
-
|
|
8424
|
-
|
|
8425
|
-
|
|
8426
|
-
|
|
8392
|
+
if (visible + characterLength <= columns) {
|
|
8393
|
+
rows[rows.length - 1] += character;
|
|
8394
|
+
} else {
|
|
8395
|
+
rows.push(character);
|
|
8396
|
+
visible = 0;
|
|
8427
8397
|
}
|
|
8428
8398
|
|
|
8429
|
-
if (
|
|
8430
|
-
|
|
8431
|
-
|
|
8432
|
-
{ return chunk.intro.substr(lineIndex + 1) + lineStr; }
|
|
8433
|
-
lineStr = chunk.intro + lineStr;
|
|
8399
|
+
if (ESCAPES.has(character)) {
|
|
8400
|
+
isInsideEscape = true;
|
|
8401
|
+
isInsideLinkEscape = characters.slice(index + 1).join('').startsWith(ANSI_ESCAPE_LINK);
|
|
8434
8402
|
}
|
|
8435
|
-
} while (chunk = chunk.previous);
|
|
8436
|
-
lineIndex = this.intro.lastIndexOf(n);
|
|
8437
|
-
if (lineIndex !== -1)
|
|
8438
|
-
{ return this.intro.substr(lineIndex + 1) + lineStr; }
|
|
8439
|
-
return this.intro + lineStr;
|
|
8440
|
-
};
|
|
8441
8403
|
|
|
8442
|
-
|
|
8443
|
-
|
|
8444
|
-
|
|
8404
|
+
if (isInsideEscape) {
|
|
8405
|
+
if (isInsideLinkEscape) {
|
|
8406
|
+
if (character === ANSI_ESCAPE_BELL) {
|
|
8407
|
+
isInsideEscape = false;
|
|
8408
|
+
isInsideLinkEscape = false;
|
|
8409
|
+
}
|
|
8410
|
+
} else if (character === ANSI_SGR_TERMINATOR) {
|
|
8411
|
+
isInsideEscape = false;
|
|
8412
|
+
}
|
|
8445
8413
|
|
|
8446
|
-
|
|
8447
|
-
|
|
8414
|
+
continue;
|
|
8415
|
+
}
|
|
8448
8416
|
|
|
8449
|
-
|
|
8417
|
+
visible += characterLength;
|
|
8450
8418
|
|
|
8451
|
-
|
|
8452
|
-
|
|
8453
|
-
|
|
8454
|
-
// found end chunk before start
|
|
8455
|
-
if (chunk.start < end && chunk.end >= end) {
|
|
8456
|
-
return result;
|
|
8419
|
+
if (visible === columns && index < characters.length - 1) {
|
|
8420
|
+
rows.push('');
|
|
8421
|
+
visible = 0;
|
|
8457
8422
|
}
|
|
8423
|
+
}
|
|
8458
8424
|
|
|
8459
|
-
|
|
8425
|
+
// It's possible that the last row we copy over is only
|
|
8426
|
+
// ansi escape characters, handle this edge-case
|
|
8427
|
+
if (!visible && rows[rows.length - 1].length > 0 && rows.length > 1) {
|
|
8428
|
+
rows[rows.length - 2] += rows.pop();
|
|
8460
8429
|
}
|
|
8430
|
+
};
|
|
8461
8431
|
|
|
8462
|
-
|
|
8463
|
-
|
|
8432
|
+
// Trims spaces from a string ignoring invisible sequences
|
|
8433
|
+
const stringVisibleTrimSpacesRight = string => {
|
|
8434
|
+
const words = string.split(' ');
|
|
8435
|
+
let last = words.length;
|
|
8464
8436
|
|
|
8465
|
-
|
|
8466
|
-
|
|
8467
|
-
|
|
8468
|
-
result += chunk.intro;
|
|
8437
|
+
while (last > 0) {
|
|
8438
|
+
if (stringWidth(words[last - 1]) > 0) {
|
|
8439
|
+
break;
|
|
8469
8440
|
}
|
|
8470
8441
|
|
|
8471
|
-
|
|
8472
|
-
|
|
8473
|
-
{ throw new Error(("Cannot use replaced character " + end + " as slice end anchor.")); }
|
|
8442
|
+
last--;
|
|
8443
|
+
}
|
|
8474
8444
|
|
|
8475
|
-
|
|
8476
|
-
|
|
8445
|
+
if (last === words.length) {
|
|
8446
|
+
return string;
|
|
8447
|
+
}
|
|
8477
8448
|
|
|
8478
|
-
|
|
8449
|
+
return words.slice(0, last).join(' ') + words.slice(last).join('');
|
|
8450
|
+
};
|
|
8479
8451
|
|
|
8480
|
-
|
|
8481
|
-
|
|
8482
|
-
|
|
8452
|
+
// The wrap-ansi module can be invoked in either 'hard' or 'soft' wrap mode
|
|
8453
|
+
//
|
|
8454
|
+
// 'hard' will never allow a string to take up more than columns characters
|
|
8455
|
+
//
|
|
8456
|
+
// 'soft' allows long words to expand past the column length
|
|
8457
|
+
const exec = (string, columns, options = {}) => {
|
|
8458
|
+
if (options.trim !== false && string.trim() === '') {
|
|
8459
|
+
return '';
|
|
8460
|
+
}
|
|
8483
8461
|
|
|
8484
|
-
|
|
8485
|
-
|
|
8462
|
+
let returnValue = '';
|
|
8463
|
+
let escapeCode;
|
|
8464
|
+
let escapeUrl;
|
|
8465
|
+
|
|
8466
|
+
const lengths = wordLengths(string);
|
|
8467
|
+
let rows = [''];
|
|
8468
|
+
|
|
8469
|
+
for (const [index, word] of string.split(' ').entries()) {
|
|
8470
|
+
if (options.trim !== false) {
|
|
8471
|
+
rows[rows.length - 1] = rows[rows.length - 1].trimStart();
|
|
8486
8472
|
}
|
|
8487
8473
|
|
|
8488
|
-
|
|
8489
|
-
}
|
|
8474
|
+
let rowLength = stringWidth(rows[rows.length - 1]);
|
|
8490
8475
|
|
|
8491
|
-
|
|
8492
|
-
|
|
8476
|
+
if (index !== 0) {
|
|
8477
|
+
if (rowLength >= columns && (options.wordWrap === false || options.trim === false)) {
|
|
8478
|
+
// If we start with a new word but the current row length equals the length of the columns, add a new row
|
|
8479
|
+
rows.push('');
|
|
8480
|
+
rowLength = 0;
|
|
8481
|
+
}
|
|
8493
8482
|
|
|
8494
|
-
|
|
8495
|
-
|
|
8496
|
-
|
|
8497
|
-
|
|
8498
|
-
|
|
8483
|
+
if (rowLength > 0 || options.trim === false) {
|
|
8484
|
+
rows[rows.length - 1] += ' ';
|
|
8485
|
+
rowLength++;
|
|
8486
|
+
}
|
|
8487
|
+
}
|
|
8499
8488
|
|
|
8500
|
-
|
|
8501
|
-
|
|
8489
|
+
// In 'hard' wrap mode, the length of a line is never allowed to extend past 'columns'
|
|
8490
|
+
if (options.hard && lengths[index] > columns) {
|
|
8491
|
+
const remainingColumns = (columns - rowLength);
|
|
8492
|
+
const breaksStartingThisLine = 1 + Math.floor((lengths[index] - remainingColumns - 1) / columns);
|
|
8493
|
+
const breaksStartingNextLine = Math.floor((lengths[index] - 1) / columns);
|
|
8494
|
+
if (breaksStartingNextLine < breaksStartingThisLine) {
|
|
8495
|
+
rows.push('');
|
|
8496
|
+
}
|
|
8502
8497
|
|
|
8503
|
-
|
|
8504
|
-
|
|
8498
|
+
wrapWord(rows, word, columns);
|
|
8499
|
+
continue;
|
|
8500
|
+
}
|
|
8505
8501
|
|
|
8506
|
-
|
|
8507
|
-
|
|
8502
|
+
if (rowLength + lengths[index] > columns && rowLength > 0 && lengths[index] > 0) {
|
|
8503
|
+
if (options.wordWrap === false && rowLength < columns) {
|
|
8504
|
+
wrapWord(rows, word, columns);
|
|
8505
|
+
continue;
|
|
8506
|
+
}
|
|
8508
8507
|
|
|
8509
|
-
|
|
8510
|
-
|
|
8508
|
+
rows.push('');
|
|
8509
|
+
}
|
|
8511
8510
|
|
|
8512
|
-
|
|
8511
|
+
if (rowLength + lengths[index] > columns && options.wordWrap === false) {
|
|
8512
|
+
wrapWord(rows, word, columns);
|
|
8513
|
+
continue;
|
|
8514
|
+
}
|
|
8515
|
+
|
|
8516
|
+
rows[rows.length - 1] += word;
|
|
8513
8517
|
}
|
|
8514
|
-
};
|
|
8515
8518
|
|
|
8516
|
-
|
|
8517
|
-
|
|
8518
|
-
// zero-length edited chunks are a special case (overlapping replacements)
|
|
8519
|
-
var loc = getLocator(this.original)(index);
|
|
8520
|
-
throw new Error(
|
|
8521
|
-
("Cannot split a chunk that has already been edited (" + (loc.line) + ":" + (loc.column) + " – \"" + (chunk.original) + "\")")
|
|
8522
|
-
);
|
|
8519
|
+
if (options.trim !== false) {
|
|
8520
|
+
rows = rows.map(row => stringVisibleTrimSpacesRight(row));
|
|
8523
8521
|
}
|
|
8524
8522
|
|
|
8525
|
-
|
|
8523
|
+
const pre = [...rows.join('\n')];
|
|
8526
8524
|
|
|
8527
|
-
|
|
8528
|
-
|
|
8529
|
-
this.byEnd[newChunk.end] = newChunk;
|
|
8525
|
+
for (const [index, character] of pre.entries()) {
|
|
8526
|
+
returnValue += character;
|
|
8530
8527
|
|
|
8531
|
-
|
|
8528
|
+
if (ESCAPES.has(character)) {
|
|
8529
|
+
const {groups} = new RegExp(`(?:\\${ANSI_CSI}(?<code>\\d+)m|\\${ANSI_ESCAPE_LINK}(?<uri>.*)${ANSI_ESCAPE_BELL})`).exec(pre.slice(index).join('')) || {groups: {}};
|
|
8530
|
+
if (groups.code !== undefined) {
|
|
8531
|
+
const code = Number.parseFloat(groups.code);
|
|
8532
|
+
escapeCode = code === END_CODE ? undefined : code;
|
|
8533
|
+
} else if (groups.uri !== undefined) {
|
|
8534
|
+
escapeUrl = groups.uri.length === 0 ? undefined : groups.uri;
|
|
8535
|
+
}
|
|
8536
|
+
}
|
|
8532
8537
|
|
|
8533
|
-
|
|
8534
|
-
return true;
|
|
8535
|
-
};
|
|
8538
|
+
const code = ansiStyles.codes.get(Number(escapeCode));
|
|
8536
8539
|
|
|
8537
|
-
|
|
8538
|
-
|
|
8540
|
+
if (pre[index + 1] === '\n') {
|
|
8541
|
+
if (escapeUrl) {
|
|
8542
|
+
returnValue += wrapAnsiHyperlink('');
|
|
8543
|
+
}
|
|
8539
8544
|
|
|
8540
|
-
|
|
8541
|
-
|
|
8542
|
-
|
|
8543
|
-
|
|
8545
|
+
if (escapeCode && code) {
|
|
8546
|
+
returnValue += wrapAnsiCode(code);
|
|
8547
|
+
}
|
|
8548
|
+
} else if (character === '\n') {
|
|
8549
|
+
if (escapeCode && code) {
|
|
8550
|
+
returnValue += wrapAnsiCode(escapeCode);
|
|
8551
|
+
}
|
|
8552
|
+
|
|
8553
|
+
if (escapeUrl) {
|
|
8554
|
+
returnValue += wrapAnsiHyperlink(escapeUrl);
|
|
8555
|
+
}
|
|
8556
|
+
}
|
|
8544
8557
|
}
|
|
8545
8558
|
|
|
8546
|
-
return
|
|
8559
|
+
return returnValue;
|
|
8547
8560
|
};
|
|
8548
8561
|
|
|
8549
|
-
|
|
8550
|
-
|
|
8551
|
-
|
|
8552
|
-
|
|
8553
|
-
|
|
8554
|
-
|
|
8555
|
-
|
|
8556
|
-
|
|
8557
|
-
|
|
8558
|
-
};
|
|
8562
|
+
// For each newline, invoke the method separately
|
|
8563
|
+
function wrapAnsi(string, columns, options) {
|
|
8564
|
+
return String(string)
|
|
8565
|
+
.normalize()
|
|
8566
|
+
.replace(/\r\n/g, '\n')
|
|
8567
|
+
.split('\n')
|
|
8568
|
+
.map(line => exec(line, columns, options))
|
|
8569
|
+
.join('\n');
|
|
8570
|
+
}
|
|
8559
8571
|
|
|
8560
|
-
|
|
8561
|
-
var chunk = this.firstChunk;
|
|
8562
|
-
var length = 0;
|
|
8563
|
-
do {
|
|
8564
|
-
length += chunk.intro.length + chunk.content.length + chunk.outro.length;
|
|
8565
|
-
} while (chunk = chunk.next);
|
|
8566
|
-
return length;
|
|
8567
|
-
};
|
|
8572
|
+
const defaultTerminalHeight = 24;
|
|
8568
8573
|
|
|
8569
|
-
|
|
8570
|
-
|
|
8571
|
-
};
|
|
8574
|
+
const getWidth = stream => {
|
|
8575
|
+
const {columns} = stream;
|
|
8572
8576
|
|
|
8573
|
-
|
|
8574
|
-
|
|
8575
|
-
}
|
|
8577
|
+
if (!columns) {
|
|
8578
|
+
return 80;
|
|
8579
|
+
}
|
|
8576
8580
|
|
|
8577
|
-
|
|
8578
|
-
|
|
8581
|
+
return columns;
|
|
8582
|
+
};
|
|
8579
8583
|
|
|
8580
|
-
|
|
8581
|
-
|
|
8584
|
+
const fitToTerminalHeight = (stream, text) => {
|
|
8585
|
+
const terminalHeight = stream.rows || defaultTerminalHeight;
|
|
8586
|
+
const lines = text.split('\n');
|
|
8582
8587
|
|
|
8583
|
-
|
|
8588
|
+
const toRemove = lines.length - terminalHeight;
|
|
8589
|
+
if (toRemove <= 0) {
|
|
8590
|
+
return text;
|
|
8591
|
+
}
|
|
8584
8592
|
|
|
8585
|
-
|
|
8586
|
-
|
|
8587
|
-
|
|
8593
|
+
return sliceAnsi(
|
|
8594
|
+
text,
|
|
8595
|
+
lines.slice(0, toRemove).join('\n').length + 1,
|
|
8596
|
+
text.length);
|
|
8597
|
+
};
|
|
8588
8598
|
|
|
8589
|
-
|
|
8590
|
-
|
|
8591
|
-
|
|
8592
|
-
|
|
8593
|
-
}
|
|
8599
|
+
function createLogUpdate(stream, {showCursor = false} = {}) {
|
|
8600
|
+
let previousLineCount = 0;
|
|
8601
|
+
let previousWidth = getWidth(stream);
|
|
8602
|
+
let previousOutput = '';
|
|
8594
8603
|
|
|
8595
|
-
|
|
8596
|
-
|
|
8597
|
-
|
|
8604
|
+
const render = (...arguments_) => {
|
|
8605
|
+
if (!showCursor) {
|
|
8606
|
+
cliCursor.hide();
|
|
8598
8607
|
}
|
|
8599
8608
|
|
|
8600
|
-
|
|
8601
|
-
|
|
8602
|
-
|
|
8603
|
-
|
|
8604
|
-
|
|
8605
|
-
}
|
|
8609
|
+
let output = arguments_.join(' ') + '\n';
|
|
8610
|
+
output = fitToTerminalHeight(stream, output);
|
|
8611
|
+
const width = getWidth(stream);
|
|
8612
|
+
if (output === previousOutput && previousWidth === width) {
|
|
8613
|
+
return;
|
|
8614
|
+
}
|
|
8606
8615
|
|
|
8607
|
-
|
|
8608
|
-
|
|
8609
|
-
|
|
8610
|
-
|
|
8611
|
-
|
|
8612
|
-
|
|
8616
|
+
previousOutput = output;
|
|
8617
|
+
previousWidth = width;
|
|
8618
|
+
output = wrapAnsi(output, width, {
|
|
8619
|
+
trim: false,
|
|
8620
|
+
hard: true,
|
|
8621
|
+
wordWrap: false,
|
|
8622
|
+
});
|
|
8623
|
+
stream.write(ansiEscapes.eraseLines(previousLineCount) + output);
|
|
8624
|
+
previousLineCount = output.split('\n').length;
|
|
8625
|
+
};
|
|
8613
8626
|
|
|
8614
|
-
|
|
8615
|
-
|
|
8627
|
+
render.clear = () => {
|
|
8628
|
+
stream.write(ansiEscapes.eraseLines(previousLineCount));
|
|
8629
|
+
previousOutput = '';
|
|
8630
|
+
previousWidth = getWidth(stream);
|
|
8631
|
+
previousLineCount = 0;
|
|
8632
|
+
};
|
|
8616
8633
|
|
|
8617
|
-
|
|
8634
|
+
render.done = () => {
|
|
8635
|
+
previousOutput = '';
|
|
8636
|
+
previousWidth = getWidth(stream);
|
|
8637
|
+
previousLineCount = 0;
|
|
8618
8638
|
|
|
8619
|
-
|
|
8620
|
-
|
|
8621
|
-
|
|
8639
|
+
if (!showCursor) {
|
|
8640
|
+
cliCursor.show();
|
|
8641
|
+
}
|
|
8642
|
+
};
|
|
8622
8643
|
|
|
8623
|
-
|
|
8624
|
-
|
|
8625
|
-
if (chunk === this.lastChunk) { this.lastChunk = chunk.next; }
|
|
8644
|
+
return render;
|
|
8645
|
+
}
|
|
8626
8646
|
|
|
8627
|
-
|
|
8628
|
-
this.byStart[chunk.next.start] = chunk.next;
|
|
8629
|
-
this.byEnd[chunk.next.end] = chunk.next;
|
|
8630
|
-
}
|
|
8647
|
+
createLogUpdate(process$1.stdout);
|
|
8631
8648
|
|
|
8632
|
-
|
|
8633
|
-
chunk = chunk.next;
|
|
8634
|
-
} while (chunk);
|
|
8649
|
+
createLogUpdate(process$1.stderr);
|
|
8635
8650
|
|
|
8636
|
-
|
|
8651
|
+
const DURATION_LONG = 300;
|
|
8652
|
+
const MAX_HEIGHT = 20;
|
|
8653
|
+
const outputMap = /* @__PURE__ */ new WeakMap();
|
|
8654
|
+
function formatFilepath(path) {
|
|
8655
|
+
const lastSlash = Math.max(path.lastIndexOf("/") + 1, 0);
|
|
8656
|
+
const basename = path.slice(lastSlash);
|
|
8657
|
+
let firstDot = basename.indexOf(".");
|
|
8658
|
+
if (firstDot < 0)
|
|
8659
|
+
firstDot = basename.length;
|
|
8660
|
+
firstDot += lastSlash;
|
|
8661
|
+
return c.dim(path.slice(0, lastSlash)) + path.slice(lastSlash, firstDot) + c.dim(path.slice(firstDot));
|
|
8662
|
+
}
|
|
8663
|
+
function renderTree(tasks, options, level = 0) {
|
|
8664
|
+
var _a, _b, _c, _d;
|
|
8665
|
+
let output = [];
|
|
8666
|
+
for (const task of tasks) {
|
|
8667
|
+
let suffix = "";
|
|
8668
|
+
const prefix = ` ${getStateSymbol(task)} `;
|
|
8669
|
+
if (task.mode === "skip" || task.mode === "todo")
|
|
8670
|
+
suffix += ` ${c.dim("[skipped]")}`;
|
|
8671
|
+
if (task.type === "suite")
|
|
8672
|
+
suffix += c.dim(` (${getTests(task).length})`);
|
|
8673
|
+
if ((_a = task.result) == null ? void 0 : _a.end) {
|
|
8674
|
+
const duration = task.result.end - task.result.start;
|
|
8675
|
+
if (duration > DURATION_LONG)
|
|
8676
|
+
suffix += c.yellow(` ${Math.round(duration)}${c.dim("ms")}`);
|
|
8677
|
+
}
|
|
8678
|
+
let name = task.name;
|
|
8679
|
+
if (level === 0)
|
|
8680
|
+
name = formatFilepath(name);
|
|
8681
|
+
output.push(" ".repeat(level) + prefix + name + suffix);
|
|
8682
|
+
if (((_b = task.result) == null ? void 0 : _b.state) !== "pass" && outputMap.get(task) != null) {
|
|
8683
|
+
let data = outputMap.get(task);
|
|
8684
|
+
if (typeof data === "string") {
|
|
8685
|
+
data = stripAnsi(data.trim().split("\n").filter(Boolean).pop());
|
|
8686
|
+
if (data === "")
|
|
8687
|
+
data = void 0;
|
|
8688
|
+
}
|
|
8689
|
+
if (data != null) {
|
|
8690
|
+
const out = `${" ".repeat(level)}${F_RIGHT} ${data}`;
|
|
8691
|
+
output.push(` ${c.gray(cliTruncate(out, getCols(-3)))}`);
|
|
8692
|
+
}
|
|
8693
|
+
}
|
|
8694
|
+
if (task.type === "suite" && task.tasks.length > 0) {
|
|
8695
|
+
if (((_c = task.result) == null ? void 0 : _c.state) === "fail" || ((_d = task.result) == null ? void 0 : _d.state) === "run" || options.renderSucceed)
|
|
8696
|
+
output = output.concat(renderTree(task.tasks, options, level + 1));
|
|
8697
|
+
}
|
|
8698
|
+
}
|
|
8699
|
+
return output.slice(0, MAX_HEIGHT).join("\n");
|
|
8700
|
+
}
|
|
8701
|
+
const createListRenderer = (_tasks, options = {}) => {
|
|
8702
|
+
let tasks = _tasks;
|
|
8703
|
+
let timer;
|
|
8704
|
+
const stdout = process.stdout;
|
|
8705
|
+
const log = createLogUpdate(stdout);
|
|
8706
|
+
function update() {
|
|
8707
|
+
log(renderTree(tasks, options));
|
|
8708
|
+
}
|
|
8709
|
+
return {
|
|
8710
|
+
start() {
|
|
8711
|
+
if (timer)
|
|
8712
|
+
return this;
|
|
8713
|
+
timer = setInterval(update, 200);
|
|
8714
|
+
return this;
|
|
8715
|
+
},
|
|
8716
|
+
update(_tasks2) {
|
|
8717
|
+
tasks = _tasks2;
|
|
8718
|
+
update();
|
|
8719
|
+
return this;
|
|
8720
|
+
},
|
|
8721
|
+
async stop() {
|
|
8722
|
+
if (timer) {
|
|
8723
|
+
clearInterval(timer);
|
|
8724
|
+
timer = void 0;
|
|
8725
|
+
}
|
|
8726
|
+
log.clear();
|
|
8727
|
+
stdout.write(`${renderTree(tasks, options)}
|
|
8728
|
+
`);
|
|
8729
|
+
return this;
|
|
8730
|
+
},
|
|
8731
|
+
clear() {
|
|
8732
|
+
log.clear();
|
|
8733
|
+
}
|
|
8734
|
+
};
|
|
8637
8735
|
};
|
|
8638
8736
|
|
|
8639
|
-
|
|
8640
|
-
|
|
8641
|
-
|
|
8642
|
-
};
|
|
8737
|
+
class DefaultReporter extends BaseReporter {
|
|
8738
|
+
constructor() {
|
|
8739
|
+
super(...arguments);
|
|
8740
|
+
this.rendererOptions = {};
|
|
8741
|
+
}
|
|
8742
|
+
onStart() {
|
|
8743
|
+
if (this.isTTY) {
|
|
8744
|
+
const files = this.ctx.state.getFiles(this.watchFilters);
|
|
8745
|
+
if (!this.renderer)
|
|
8746
|
+
this.renderer = createListRenderer(files, this.rendererOptions).start();
|
|
8747
|
+
else
|
|
8748
|
+
this.renderer.update(files);
|
|
8749
|
+
}
|
|
8750
|
+
}
|
|
8751
|
+
async onFinished(files = this.ctx.state.getFiles()) {
|
|
8752
|
+
await this.stopListRender();
|
|
8753
|
+
this.ctx.log();
|
|
8754
|
+
await super.onFinished(files);
|
|
8755
|
+
}
|
|
8756
|
+
async onWatcherStart() {
|
|
8757
|
+
await this.stopListRender();
|
|
8758
|
+
super.onWatcherStart();
|
|
8759
|
+
}
|
|
8760
|
+
async stopListRender() {
|
|
8761
|
+
var _a;
|
|
8762
|
+
(_a = this.renderer) == null ? void 0 : _a.stop();
|
|
8763
|
+
this.renderer = void 0;
|
|
8764
|
+
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
8765
|
+
}
|
|
8766
|
+
async onWatcherRerun(files, trigger) {
|
|
8767
|
+
await this.stopListRender();
|
|
8768
|
+
await super.onWatcherRerun(files, trigger);
|
|
8769
|
+
}
|
|
8770
|
+
onUserConsoleLog(log) {
|
|
8771
|
+
var _a;
|
|
8772
|
+
(_a = this.renderer) == null ? void 0 : _a.clear();
|
|
8773
|
+
super.onUserConsoleLog(log);
|
|
8774
|
+
}
|
|
8775
|
+
}
|
|
8643
8776
|
|
|
8644
|
-
const
|
|
8645
|
-
const
|
|
8777
|
+
const check = c.green("\xB7");
|
|
8778
|
+
const cross = c.red("x");
|
|
8779
|
+
const pending = c.yellow("*");
|
|
8780
|
+
const skip = c.dim(c.gray("-"));
|
|
8781
|
+
function render(tasks) {
|
|
8782
|
+
const all = getTests(tasks);
|
|
8783
|
+
return all.map((i) => {
|
|
8784
|
+
var _a;
|
|
8785
|
+
if (i.mode === "skip" || i.mode === "todo")
|
|
8786
|
+
return skip;
|
|
8787
|
+
switch ((_a = i.result) == null ? void 0 : _a.state) {
|
|
8788
|
+
case "pass":
|
|
8789
|
+
return check;
|
|
8790
|
+
case "fail":
|
|
8791
|
+
return cross;
|
|
8792
|
+
default:
|
|
8793
|
+
return pending;
|
|
8794
|
+
}
|
|
8795
|
+
}).join("");
|
|
8796
|
+
}
|
|
8797
|
+
const createDotRenderer = (_tasks) => {
|
|
8798
|
+
let tasks = _tasks;
|
|
8799
|
+
let timer;
|
|
8800
|
+
const stdout = process.stdout;
|
|
8801
|
+
const log = createLogUpdate(stdout);
|
|
8802
|
+
function update() {
|
|
8803
|
+
log(render(tasks));
|
|
8804
|
+
}
|
|
8646
8805
|
return {
|
|
8647
|
-
|
|
8648
|
-
|
|
8649
|
-
|
|
8650
|
-
|
|
8651
|
-
|
|
8652
|
-
|
|
8653
|
-
|
|
8654
|
-
|
|
8655
|
-
|
|
8656
|
-
|
|
8657
|
-
|
|
8658
|
-
|
|
8659
|
-
|
|
8660
|
-
|
|
8661
|
-
|
|
8662
|
-
if (filepath.id.includes("/node_modules/"))
|
|
8663
|
-
nodeModule = `"${modulePath}"`;
|
|
8664
|
-
const overwrite = `__vitest__${method}__("${filepath.id}", ${nodeModule});`;
|
|
8665
|
-
if (method === "mock") {
|
|
8666
|
-
m.prepend(`${overwrite}
|
|
8667
|
-
|
|
8668
|
-
`);
|
|
8669
|
-
m.remove(start, end);
|
|
8670
|
-
} else {
|
|
8671
|
-
m.overwrite(start, end, overwrite);
|
|
8672
|
-
}
|
|
8673
|
-
}
|
|
8674
|
-
}
|
|
8675
|
-
if (m) {
|
|
8676
|
-
return {
|
|
8677
|
-
code: m.toString(),
|
|
8678
|
-
map: m.generateMap()
|
|
8679
|
-
};
|
|
8806
|
+
start() {
|
|
8807
|
+
if (timer)
|
|
8808
|
+
return this;
|
|
8809
|
+
timer = setInterval(update, 200);
|
|
8810
|
+
return this;
|
|
8811
|
+
},
|
|
8812
|
+
update(_tasks2) {
|
|
8813
|
+
tasks = _tasks2;
|
|
8814
|
+
update();
|
|
8815
|
+
return this;
|
|
8816
|
+
},
|
|
8817
|
+
async stop() {
|
|
8818
|
+
if (timer) {
|
|
8819
|
+
clearInterval(timer);
|
|
8820
|
+
timer = void 0;
|
|
8680
8821
|
}
|
|
8822
|
+
log.clear();
|
|
8823
|
+
stdout.write(`${render(tasks)}
|
|
8824
|
+
`);
|
|
8825
|
+
return this;
|
|
8826
|
+
},
|
|
8827
|
+
clear() {
|
|
8828
|
+
log.clear();
|
|
8681
8829
|
}
|
|
8682
8830
|
};
|
|
8683
8831
|
};
|
|
8684
8832
|
|
|
8833
|
+
class DotReporter extends BaseReporter {
|
|
8834
|
+
onStart() {
|
|
8835
|
+
if (this.isTTY) {
|
|
8836
|
+
const files = this.ctx.state.getFiles(this.watchFilters);
|
|
8837
|
+
if (!this.renderer)
|
|
8838
|
+
this.renderer = createDotRenderer(files).start();
|
|
8839
|
+
else
|
|
8840
|
+
this.renderer.update(files);
|
|
8841
|
+
}
|
|
8842
|
+
}
|
|
8843
|
+
async onFinished(files = this.ctx.state.getFiles()) {
|
|
8844
|
+
await this.stopListRender();
|
|
8845
|
+
this.ctx.log();
|
|
8846
|
+
await super.onFinished(files);
|
|
8847
|
+
}
|
|
8848
|
+
async onWatcherStart() {
|
|
8849
|
+
await this.stopListRender();
|
|
8850
|
+
super.onWatcherStart();
|
|
8851
|
+
}
|
|
8852
|
+
async stopListRender() {
|
|
8853
|
+
var _a;
|
|
8854
|
+
(_a = this.renderer) == null ? void 0 : _a.stop();
|
|
8855
|
+
this.renderer = void 0;
|
|
8856
|
+
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
8857
|
+
}
|
|
8858
|
+
async onWatcherRerun(files, trigger) {
|
|
8859
|
+
await this.stopListRender();
|
|
8860
|
+
await super.onWatcherRerun(files, trigger);
|
|
8861
|
+
}
|
|
8862
|
+
onUserConsoleLog(log) {
|
|
8863
|
+
var _a;
|
|
8864
|
+
(_a = this.renderer) == null ? void 0 : _a.clear();
|
|
8865
|
+
super.onUserConsoleLog(log);
|
|
8866
|
+
}
|
|
8867
|
+
}
|
|
8868
|
+
|
|
8869
|
+
class VerboseReporter extends DefaultReporter {
|
|
8870
|
+
constructor(ctx) {
|
|
8871
|
+
super(ctx);
|
|
8872
|
+
this.rendererOptions.renderSucceed = true;
|
|
8873
|
+
}
|
|
8874
|
+
}
|
|
8875
|
+
|
|
8876
|
+
const ReportersMap = {
|
|
8877
|
+
default: DefaultReporter,
|
|
8878
|
+
verbose: VerboseReporter,
|
|
8879
|
+
dot: DotReporter
|
|
8880
|
+
};
|
|
8881
|
+
|
|
8685
8882
|
class StateManager {
|
|
8686
8883
|
constructor() {
|
|
8687
8884
|
this.filesMap = {};
|
|
@@ -8945,9 +9142,17 @@ class Vitest {
|
|
|
8945
9142
|
this.config = resolved;
|
|
8946
9143
|
this.state = new StateManager();
|
|
8947
9144
|
this.snapshot = new SnapshotManager(resolved);
|
|
8948
|
-
this.reporters = toArray(resolved.reporters)
|
|
9145
|
+
this.reporters = toArray(resolved.reporters || resolved.reporter).map((i) => {
|
|
9146
|
+
if (typeof i === "string") {
|
|
9147
|
+
const Reporter = ReportersMap[i];
|
|
9148
|
+
if (!Reporter)
|
|
9149
|
+
throw new Error(`Unknown reporter: ${i}`);
|
|
9150
|
+
return new Reporter(this);
|
|
9151
|
+
}
|
|
9152
|
+
return i;
|
|
9153
|
+
});
|
|
8949
9154
|
if (!this.reporters.length && !this.config.silent)
|
|
8950
|
-
this.reporters.push(new
|
|
9155
|
+
this.reporters.push(new DefaultReporter(this));
|
|
8951
9156
|
if (this.config.watch)
|
|
8952
9157
|
this.registerWatcher();
|
|
8953
9158
|
this.runningPromise = void 0;
|
|
@@ -9113,7 +9318,7 @@ async function createVitest(options, viteOverrides = {}) {
|
|
|
9113
9318
|
ctx.setServer(options, server2);
|
|
9114
9319
|
haveStarted = true;
|
|
9115
9320
|
if (options.api)
|
|
9116
|
-
server2.middlewares.use((await import('./middleware-
|
|
9321
|
+
server2.middlewares.use((await import('./middleware-2028dfa0.js')).default(ctx));
|
|
9117
9322
|
}
|
|
9118
9323
|
},
|
|
9119
9324
|
MocksPlugin()
|