vite-node 0.28.5 → 0.29.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.cjs +5 -5
- package/dist/cli.d.ts +3 -1
- package/dist/cli.mjs +5 -5
- package/dist/client.cjs +4 -8
- package/dist/client.d.ts +2 -1
- package/dist/client.mjs +4 -8
- package/dist/hmr.d.ts +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/server.cjs +42 -13
- package/dist/server.d.ts +7 -4
- package/dist/server.mjs +43 -14
- package/dist/source-map.cjs +857 -4
- package/dist/source-map.d.ts +3 -3
- package/dist/source-map.mjs +851 -3
- package/dist/{types-63205a44.d.ts → types-e288fc62.d.ts} +7 -4
- package/dist/types.d-1e7e3fdf.d.ts +23 -0
- package/dist/types.d.ts +2 -1
- package/dist/utils.d.ts +2 -1
- package/package.json +2 -5
package/dist/source-map.mjs
CHANGED
|
@@ -1,4 +1,854 @@
|
|
|
1
|
-
import
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
|
|
4
|
+
const comma = ','.charCodeAt(0);
|
|
5
|
+
const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
|
|
6
|
+
const intToChar = new Uint8Array(64); // 64 possible chars.
|
|
7
|
+
const charToInt = new Uint8Array(128); // z is 122 in ASCII
|
|
8
|
+
for (let i = 0; i < chars.length; i++) {
|
|
9
|
+
const c = chars.charCodeAt(i);
|
|
10
|
+
intToChar[i] = c;
|
|
11
|
+
charToInt[c] = i;
|
|
12
|
+
}
|
|
13
|
+
function decode(mappings) {
|
|
14
|
+
const state = new Int32Array(5);
|
|
15
|
+
const decoded = [];
|
|
16
|
+
let index = 0;
|
|
17
|
+
do {
|
|
18
|
+
const semi = indexOf(mappings, index);
|
|
19
|
+
const line = [];
|
|
20
|
+
let sorted = true;
|
|
21
|
+
let lastCol = 0;
|
|
22
|
+
state[0] = 0;
|
|
23
|
+
for (let i = index; i < semi; i++) {
|
|
24
|
+
let seg;
|
|
25
|
+
i = decodeInteger(mappings, i, state, 0); // genColumn
|
|
26
|
+
const col = state[0];
|
|
27
|
+
if (col < lastCol)
|
|
28
|
+
sorted = false;
|
|
29
|
+
lastCol = col;
|
|
30
|
+
if (hasMoreVlq(mappings, i, semi)) {
|
|
31
|
+
i = decodeInteger(mappings, i, state, 1); // sourcesIndex
|
|
32
|
+
i = decodeInteger(mappings, i, state, 2); // sourceLine
|
|
33
|
+
i = decodeInteger(mappings, i, state, 3); // sourceColumn
|
|
34
|
+
if (hasMoreVlq(mappings, i, semi)) {
|
|
35
|
+
i = decodeInteger(mappings, i, state, 4); // namesIndex
|
|
36
|
+
seg = [col, state[1], state[2], state[3], state[4]];
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
seg = [col, state[1], state[2], state[3]];
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
seg = [col];
|
|
44
|
+
}
|
|
45
|
+
line.push(seg);
|
|
46
|
+
}
|
|
47
|
+
if (!sorted)
|
|
48
|
+
sort(line);
|
|
49
|
+
decoded.push(line);
|
|
50
|
+
index = semi + 1;
|
|
51
|
+
} while (index <= mappings.length);
|
|
52
|
+
return decoded;
|
|
53
|
+
}
|
|
54
|
+
function indexOf(mappings, index) {
|
|
55
|
+
const idx = mappings.indexOf(';', index);
|
|
56
|
+
return idx === -1 ? mappings.length : idx;
|
|
57
|
+
}
|
|
58
|
+
function decodeInteger(mappings, pos, state, j) {
|
|
59
|
+
let value = 0;
|
|
60
|
+
let shift = 0;
|
|
61
|
+
let integer = 0;
|
|
62
|
+
do {
|
|
63
|
+
const c = mappings.charCodeAt(pos++);
|
|
64
|
+
integer = charToInt[c];
|
|
65
|
+
value |= (integer & 31) << shift;
|
|
66
|
+
shift += 5;
|
|
67
|
+
} while (integer & 32);
|
|
68
|
+
const shouldNegate = value & 1;
|
|
69
|
+
value >>>= 1;
|
|
70
|
+
if (shouldNegate) {
|
|
71
|
+
value = -0x80000000 | -value;
|
|
72
|
+
}
|
|
73
|
+
state[j] += value;
|
|
74
|
+
return pos;
|
|
75
|
+
}
|
|
76
|
+
function hasMoreVlq(mappings, i, length) {
|
|
77
|
+
if (i >= length)
|
|
78
|
+
return false;
|
|
79
|
+
return mappings.charCodeAt(i) !== comma;
|
|
80
|
+
}
|
|
81
|
+
function sort(line) {
|
|
82
|
+
line.sort(sortComparator$1);
|
|
83
|
+
}
|
|
84
|
+
function sortComparator$1(a, b) {
|
|
85
|
+
return a[0] - b[0];
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// Matches the scheme of a URL, eg "http://"
|
|
89
|
+
const schemeRegex = /^[\w+.-]+:\/\//;
|
|
90
|
+
/**
|
|
91
|
+
* Matches the parts of a URL:
|
|
92
|
+
* 1. Scheme, including ":", guaranteed.
|
|
93
|
+
* 2. User/password, including "@", optional.
|
|
94
|
+
* 3. Host, guaranteed.
|
|
95
|
+
* 4. Port, including ":", optional.
|
|
96
|
+
* 5. Path, including "/", optional.
|
|
97
|
+
* 6. Query, including "?", optional.
|
|
98
|
+
* 7. Hash, including "#", optional.
|
|
99
|
+
*/
|
|
100
|
+
const urlRegex = /^([\w+.-]+:)\/\/([^@/#?]*@)?([^:/#?]*)(:\d+)?(\/[^#?]*)?(\?[^#]*)?(#.*)?/;
|
|
101
|
+
/**
|
|
102
|
+
* File URLs are weird. They dont' need the regular `//` in the scheme, they may or may not start
|
|
103
|
+
* with a leading `/`, they can have a domain (but only if they don't start with a Windows drive).
|
|
104
|
+
*
|
|
105
|
+
* 1. Host, optional.
|
|
106
|
+
* 2. Path, which may include "/", guaranteed.
|
|
107
|
+
* 3. Query, including "?", optional.
|
|
108
|
+
* 4. Hash, including "#", optional.
|
|
109
|
+
*/
|
|
110
|
+
const fileRegex = /^file:(?:\/\/((?![a-z]:)[^/#?]*)?)?(\/?[^#?]*)(\?[^#]*)?(#.*)?/i;
|
|
111
|
+
var UrlType;
|
|
112
|
+
(function (UrlType) {
|
|
113
|
+
UrlType[UrlType["Empty"] = 1] = "Empty";
|
|
114
|
+
UrlType[UrlType["Hash"] = 2] = "Hash";
|
|
115
|
+
UrlType[UrlType["Query"] = 3] = "Query";
|
|
116
|
+
UrlType[UrlType["RelativePath"] = 4] = "RelativePath";
|
|
117
|
+
UrlType[UrlType["AbsolutePath"] = 5] = "AbsolutePath";
|
|
118
|
+
UrlType[UrlType["SchemeRelative"] = 6] = "SchemeRelative";
|
|
119
|
+
UrlType[UrlType["Absolute"] = 7] = "Absolute";
|
|
120
|
+
})(UrlType || (UrlType = {}));
|
|
121
|
+
function isAbsoluteUrl(input) {
|
|
122
|
+
return schemeRegex.test(input);
|
|
123
|
+
}
|
|
124
|
+
function isSchemeRelativeUrl(input) {
|
|
125
|
+
return input.startsWith('//');
|
|
126
|
+
}
|
|
127
|
+
function isAbsolutePath(input) {
|
|
128
|
+
return input.startsWith('/');
|
|
129
|
+
}
|
|
130
|
+
function isFileUrl(input) {
|
|
131
|
+
return input.startsWith('file:');
|
|
132
|
+
}
|
|
133
|
+
function isRelative(input) {
|
|
134
|
+
return /^[.?#]/.test(input);
|
|
135
|
+
}
|
|
136
|
+
function parseAbsoluteUrl(input) {
|
|
137
|
+
const match = urlRegex.exec(input);
|
|
138
|
+
return makeUrl(match[1], match[2] || '', match[3], match[4] || '', match[5] || '/', match[6] || '', match[7] || '');
|
|
139
|
+
}
|
|
140
|
+
function parseFileUrl(input) {
|
|
141
|
+
const match = fileRegex.exec(input);
|
|
142
|
+
const path = match[2];
|
|
143
|
+
return makeUrl('file:', '', match[1] || '', '', isAbsolutePath(path) ? path : '/' + path, match[3] || '', match[4] || '');
|
|
144
|
+
}
|
|
145
|
+
function makeUrl(scheme, user, host, port, path, query, hash) {
|
|
146
|
+
return {
|
|
147
|
+
scheme,
|
|
148
|
+
user,
|
|
149
|
+
host,
|
|
150
|
+
port,
|
|
151
|
+
path,
|
|
152
|
+
query,
|
|
153
|
+
hash,
|
|
154
|
+
type: UrlType.Absolute,
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
function parseUrl(input) {
|
|
158
|
+
if (isSchemeRelativeUrl(input)) {
|
|
159
|
+
const url = parseAbsoluteUrl('http:' + input);
|
|
160
|
+
url.scheme = '';
|
|
161
|
+
url.type = UrlType.SchemeRelative;
|
|
162
|
+
return url;
|
|
163
|
+
}
|
|
164
|
+
if (isAbsolutePath(input)) {
|
|
165
|
+
const url = parseAbsoluteUrl('http://foo.com' + input);
|
|
166
|
+
url.scheme = '';
|
|
167
|
+
url.host = '';
|
|
168
|
+
url.type = UrlType.AbsolutePath;
|
|
169
|
+
return url;
|
|
170
|
+
}
|
|
171
|
+
if (isFileUrl(input))
|
|
172
|
+
return parseFileUrl(input);
|
|
173
|
+
if (isAbsoluteUrl(input))
|
|
174
|
+
return parseAbsoluteUrl(input);
|
|
175
|
+
const url = parseAbsoluteUrl('http://foo.com/' + input);
|
|
176
|
+
url.scheme = '';
|
|
177
|
+
url.host = '';
|
|
178
|
+
url.type = input
|
|
179
|
+
? input.startsWith('?')
|
|
180
|
+
? UrlType.Query
|
|
181
|
+
: input.startsWith('#')
|
|
182
|
+
? UrlType.Hash
|
|
183
|
+
: UrlType.RelativePath
|
|
184
|
+
: UrlType.Empty;
|
|
185
|
+
return url;
|
|
186
|
+
}
|
|
187
|
+
function stripPathFilename(path) {
|
|
188
|
+
// If a path ends with a parent directory "..", then it's a relative path with excess parent
|
|
189
|
+
// paths. It's not a file, so we can't strip it.
|
|
190
|
+
if (path.endsWith('/..'))
|
|
191
|
+
return path;
|
|
192
|
+
const index = path.lastIndexOf('/');
|
|
193
|
+
return path.slice(0, index + 1);
|
|
194
|
+
}
|
|
195
|
+
function mergePaths(url, base) {
|
|
196
|
+
normalizePath(base, base.type);
|
|
197
|
+
// If the path is just a "/", then it was an empty path to begin with (remember, we're a relative
|
|
198
|
+
// path).
|
|
199
|
+
if (url.path === '/') {
|
|
200
|
+
url.path = base.path;
|
|
201
|
+
}
|
|
202
|
+
else {
|
|
203
|
+
// Resolution happens relative to the base path's directory, not the file.
|
|
204
|
+
url.path = stripPathFilename(base.path) + url.path;
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* The path can have empty directories "//", unneeded parents "foo/..", or current directory
|
|
209
|
+
* "foo/.". We need to normalize to a standard representation.
|
|
210
|
+
*/
|
|
211
|
+
function normalizePath(url, type) {
|
|
212
|
+
const rel = type <= UrlType.RelativePath;
|
|
213
|
+
const pieces = url.path.split('/');
|
|
214
|
+
// We need to preserve the first piece always, so that we output a leading slash. The item at
|
|
215
|
+
// pieces[0] is an empty string.
|
|
216
|
+
let pointer = 1;
|
|
217
|
+
// Positive is the number of real directories we've output, used for popping a parent directory.
|
|
218
|
+
// Eg, "foo/bar/.." will have a positive 2, and we can decrement to be left with just "foo".
|
|
219
|
+
let positive = 0;
|
|
220
|
+
// We need to keep a trailing slash if we encounter an empty directory (eg, splitting "foo/" will
|
|
221
|
+
// generate `["foo", ""]` pieces). And, if we pop a parent directory. But once we encounter a
|
|
222
|
+
// real directory, we won't need to append, unless the other conditions happen again.
|
|
223
|
+
let addTrailingSlash = false;
|
|
224
|
+
for (let i = 1; i < pieces.length; i++) {
|
|
225
|
+
const piece = pieces[i];
|
|
226
|
+
// An empty directory, could be a trailing slash, or just a double "//" in the path.
|
|
227
|
+
if (!piece) {
|
|
228
|
+
addTrailingSlash = true;
|
|
229
|
+
continue;
|
|
230
|
+
}
|
|
231
|
+
// If we encounter a real directory, then we don't need to append anymore.
|
|
232
|
+
addTrailingSlash = false;
|
|
233
|
+
// A current directory, which we can always drop.
|
|
234
|
+
if (piece === '.')
|
|
235
|
+
continue;
|
|
236
|
+
// A parent directory, we need to see if there are any real directories we can pop. Else, we
|
|
237
|
+
// have an excess of parents, and we'll need to keep the "..".
|
|
238
|
+
if (piece === '..') {
|
|
239
|
+
if (positive) {
|
|
240
|
+
addTrailingSlash = true;
|
|
241
|
+
positive--;
|
|
242
|
+
pointer--;
|
|
243
|
+
}
|
|
244
|
+
else if (rel) {
|
|
245
|
+
// If we're in a relativePath, then we need to keep the excess parents. Else, in an absolute
|
|
246
|
+
// URL, protocol relative URL, or an absolute path, we don't need to keep excess.
|
|
247
|
+
pieces[pointer++] = piece;
|
|
248
|
+
}
|
|
249
|
+
continue;
|
|
250
|
+
}
|
|
251
|
+
// We've encountered a real directory. Move it to the next insertion pointer, which accounts for
|
|
252
|
+
// any popped or dropped directories.
|
|
253
|
+
pieces[pointer++] = piece;
|
|
254
|
+
positive++;
|
|
255
|
+
}
|
|
256
|
+
let path = '';
|
|
257
|
+
for (let i = 1; i < pointer; i++) {
|
|
258
|
+
path += '/' + pieces[i];
|
|
259
|
+
}
|
|
260
|
+
if (!path || (addTrailingSlash && !path.endsWith('/..'))) {
|
|
261
|
+
path += '/';
|
|
262
|
+
}
|
|
263
|
+
url.path = path;
|
|
264
|
+
}
|
|
265
|
+
/**
|
|
266
|
+
* Attempts to resolve `input` URL/path relative to `base`.
|
|
267
|
+
*/
|
|
268
|
+
function resolve$1(input, base) {
|
|
269
|
+
if (!input && !base)
|
|
270
|
+
return '';
|
|
271
|
+
const url = parseUrl(input);
|
|
272
|
+
let inputType = url.type;
|
|
273
|
+
if (base && inputType !== UrlType.Absolute) {
|
|
274
|
+
const baseUrl = parseUrl(base);
|
|
275
|
+
const baseType = baseUrl.type;
|
|
276
|
+
switch (inputType) {
|
|
277
|
+
case UrlType.Empty:
|
|
278
|
+
url.hash = baseUrl.hash;
|
|
279
|
+
// fall through
|
|
280
|
+
case UrlType.Hash:
|
|
281
|
+
url.query = baseUrl.query;
|
|
282
|
+
// fall through
|
|
283
|
+
case UrlType.Query:
|
|
284
|
+
case UrlType.RelativePath:
|
|
285
|
+
mergePaths(url, baseUrl);
|
|
286
|
+
// fall through
|
|
287
|
+
case UrlType.AbsolutePath:
|
|
288
|
+
// The host, user, and port are joined, you can't copy one without the others.
|
|
289
|
+
url.user = baseUrl.user;
|
|
290
|
+
url.host = baseUrl.host;
|
|
291
|
+
url.port = baseUrl.port;
|
|
292
|
+
// fall through
|
|
293
|
+
case UrlType.SchemeRelative:
|
|
294
|
+
// The input doesn't have a schema at least, so we need to copy at least that over.
|
|
295
|
+
url.scheme = baseUrl.scheme;
|
|
296
|
+
}
|
|
297
|
+
if (baseType > inputType)
|
|
298
|
+
inputType = baseType;
|
|
299
|
+
}
|
|
300
|
+
normalizePath(url, inputType);
|
|
301
|
+
const queryHash = url.query + url.hash;
|
|
302
|
+
switch (inputType) {
|
|
303
|
+
// This is impossible, because of the empty checks at the start of the function.
|
|
304
|
+
// case UrlType.Empty:
|
|
305
|
+
case UrlType.Hash:
|
|
306
|
+
case UrlType.Query:
|
|
307
|
+
return queryHash;
|
|
308
|
+
case UrlType.RelativePath: {
|
|
309
|
+
// The first char is always a "/", and we need it to be relative.
|
|
310
|
+
const path = url.path.slice(1);
|
|
311
|
+
if (!path)
|
|
312
|
+
return queryHash || '.';
|
|
313
|
+
if (isRelative(base || input) && !isRelative(path)) {
|
|
314
|
+
// If base started with a leading ".", or there is no base and input started with a ".",
|
|
315
|
+
// then we need to ensure that the relative path starts with a ".". We don't know if
|
|
316
|
+
// relative starts with a "..", though, so check before prepending.
|
|
317
|
+
return './' + path + queryHash;
|
|
318
|
+
}
|
|
319
|
+
return path + queryHash;
|
|
320
|
+
}
|
|
321
|
+
case UrlType.AbsolutePath:
|
|
322
|
+
return url.path + queryHash;
|
|
323
|
+
default:
|
|
324
|
+
return url.scheme + '//' + url.user + url.host + url.port + url.path + queryHash;
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
function resolve(input, base) {
|
|
329
|
+
// The base is always treated as a directory, if it's not empty.
|
|
330
|
+
// https://github.com/mozilla/source-map/blob/8cb3ee57/lib/util.js#L327
|
|
331
|
+
// https://github.com/chromium/chromium/blob/da4adbb3/third_party/blink/renderer/devtools/front_end/sdk/SourceMap.js#L400-L401
|
|
332
|
+
if (base && !base.endsWith('/'))
|
|
333
|
+
base += '/';
|
|
334
|
+
return resolve$1(input, base);
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
/**
|
|
338
|
+
* Removes everything after the last "/", but leaves the slash.
|
|
339
|
+
*/
|
|
340
|
+
function stripFilename(path) {
|
|
341
|
+
if (!path)
|
|
342
|
+
return '';
|
|
343
|
+
const index = path.lastIndexOf('/');
|
|
344
|
+
return path.slice(0, index + 1);
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
const COLUMN = 0;
|
|
348
|
+
const SOURCES_INDEX = 1;
|
|
349
|
+
const SOURCE_LINE = 2;
|
|
350
|
+
const SOURCE_COLUMN = 3;
|
|
351
|
+
const NAMES_INDEX = 4;
|
|
352
|
+
|
|
353
|
+
function maybeSort(mappings, owned) {
|
|
354
|
+
const unsortedIndex = nextUnsortedSegmentLine(mappings, 0);
|
|
355
|
+
if (unsortedIndex === mappings.length)
|
|
356
|
+
return mappings;
|
|
357
|
+
// If we own the array (meaning we parsed it from JSON), then we're free to directly mutate it. If
|
|
358
|
+
// not, we do not want to modify the consumer's input array.
|
|
359
|
+
if (!owned)
|
|
360
|
+
mappings = mappings.slice();
|
|
361
|
+
for (let i = unsortedIndex; i < mappings.length; i = nextUnsortedSegmentLine(mappings, i + 1)) {
|
|
362
|
+
mappings[i] = sortSegments(mappings[i], owned);
|
|
363
|
+
}
|
|
364
|
+
return mappings;
|
|
365
|
+
}
|
|
366
|
+
function nextUnsortedSegmentLine(mappings, start) {
|
|
367
|
+
for (let i = start; i < mappings.length; i++) {
|
|
368
|
+
if (!isSorted(mappings[i]))
|
|
369
|
+
return i;
|
|
370
|
+
}
|
|
371
|
+
return mappings.length;
|
|
372
|
+
}
|
|
373
|
+
function isSorted(line) {
|
|
374
|
+
for (let j = 1; j < line.length; j++) {
|
|
375
|
+
if (line[j][COLUMN] < line[j - 1][COLUMN]) {
|
|
376
|
+
return false;
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
return true;
|
|
380
|
+
}
|
|
381
|
+
function sortSegments(line, owned) {
|
|
382
|
+
if (!owned)
|
|
383
|
+
line = line.slice();
|
|
384
|
+
return line.sort(sortComparator);
|
|
385
|
+
}
|
|
386
|
+
function sortComparator(a, b) {
|
|
387
|
+
return a[COLUMN] - b[COLUMN];
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
let found = false;
|
|
391
|
+
/**
|
|
392
|
+
* A binary search implementation that returns the index if a match is found.
|
|
393
|
+
* If no match is found, then the left-index (the index associated with the item that comes just
|
|
394
|
+
* before the desired index) is returned. To maintain proper sort order, a splice would happen at
|
|
395
|
+
* the next index:
|
|
396
|
+
*
|
|
397
|
+
* ```js
|
|
398
|
+
* const array = [1, 3];
|
|
399
|
+
* const needle = 2;
|
|
400
|
+
* const index = binarySearch(array, needle, (item, needle) => item - needle);
|
|
401
|
+
*
|
|
402
|
+
* assert.equal(index, 0);
|
|
403
|
+
* array.splice(index + 1, 0, needle);
|
|
404
|
+
* assert.deepEqual(array, [1, 2, 3]);
|
|
405
|
+
* ```
|
|
406
|
+
*/
|
|
407
|
+
function binarySearch(haystack, needle, low, high) {
|
|
408
|
+
while (low <= high) {
|
|
409
|
+
const mid = low + ((high - low) >> 1);
|
|
410
|
+
const cmp = haystack[mid][COLUMN] - needle;
|
|
411
|
+
if (cmp === 0) {
|
|
412
|
+
found = true;
|
|
413
|
+
return mid;
|
|
414
|
+
}
|
|
415
|
+
if (cmp < 0) {
|
|
416
|
+
low = mid + 1;
|
|
417
|
+
}
|
|
418
|
+
else {
|
|
419
|
+
high = mid - 1;
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
found = false;
|
|
423
|
+
return low - 1;
|
|
424
|
+
}
|
|
425
|
+
function upperBound(haystack, needle, index) {
|
|
426
|
+
for (let i = index + 1; i < haystack.length; index = i++) {
|
|
427
|
+
if (haystack[i][COLUMN] !== needle)
|
|
428
|
+
break;
|
|
429
|
+
}
|
|
430
|
+
return index;
|
|
431
|
+
}
|
|
432
|
+
function lowerBound(haystack, needle, index) {
|
|
433
|
+
for (let i = index - 1; i >= 0; index = i--) {
|
|
434
|
+
if (haystack[i][COLUMN] !== needle)
|
|
435
|
+
break;
|
|
436
|
+
}
|
|
437
|
+
return index;
|
|
438
|
+
}
|
|
439
|
+
function memoizedState() {
|
|
440
|
+
return {
|
|
441
|
+
lastKey: -1,
|
|
442
|
+
lastNeedle: -1,
|
|
443
|
+
lastIndex: -1,
|
|
444
|
+
};
|
|
445
|
+
}
|
|
446
|
+
/**
|
|
447
|
+
* This overly complicated beast is just to record the last tested line/column and the resulting
|
|
448
|
+
* index, allowing us to skip a few tests if mappings are monotonically increasing.
|
|
449
|
+
*/
|
|
450
|
+
function memoizedBinarySearch(haystack, needle, state, key) {
|
|
451
|
+
const { lastKey, lastNeedle, lastIndex } = state;
|
|
452
|
+
let low = 0;
|
|
453
|
+
let high = haystack.length - 1;
|
|
454
|
+
if (key === lastKey) {
|
|
455
|
+
if (needle === lastNeedle) {
|
|
456
|
+
found = lastIndex !== -1 && haystack[lastIndex][COLUMN] === needle;
|
|
457
|
+
return lastIndex;
|
|
458
|
+
}
|
|
459
|
+
if (needle >= lastNeedle) {
|
|
460
|
+
// lastIndex may be -1 if the previous needle was not found.
|
|
461
|
+
low = lastIndex === -1 ? 0 : lastIndex;
|
|
462
|
+
}
|
|
463
|
+
else {
|
|
464
|
+
high = lastIndex;
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
state.lastKey = key;
|
|
468
|
+
state.lastNeedle = needle;
|
|
469
|
+
return (state.lastIndex = binarySearch(haystack, needle, low, high));
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
const LINE_GTR_ZERO = '`line` must be greater than 0 (lines start at line 1)';
|
|
473
|
+
const COL_GTR_EQ_ZERO = '`column` must be greater than or equal to 0 (columns start at column 0)';
|
|
474
|
+
const LEAST_UPPER_BOUND = -1;
|
|
475
|
+
const GREATEST_LOWER_BOUND = 1;
|
|
476
|
+
/**
|
|
477
|
+
* Returns the decoded (array of lines of segments) form of the SourceMap's mappings field.
|
|
478
|
+
*/
|
|
479
|
+
let decodedMappings;
|
|
480
|
+
/**
|
|
481
|
+
* A higher-level API to find the source/line/column associated with a generated line/column
|
|
482
|
+
* (think, from a stack trace). Line is 1-based, but column is 0-based, due to legacy behavior in
|
|
483
|
+
* `source-map` library.
|
|
484
|
+
*/
|
|
485
|
+
let originalPositionFor;
|
|
486
|
+
class TraceMap {
|
|
487
|
+
constructor(map, mapUrl) {
|
|
488
|
+
const isString = typeof map === 'string';
|
|
489
|
+
if (!isString && map._decodedMemo)
|
|
490
|
+
return map;
|
|
491
|
+
const parsed = (isString ? JSON.parse(map) : map);
|
|
492
|
+
const { version, file, names, sourceRoot, sources, sourcesContent } = parsed;
|
|
493
|
+
this.version = version;
|
|
494
|
+
this.file = file;
|
|
495
|
+
this.names = names;
|
|
496
|
+
this.sourceRoot = sourceRoot;
|
|
497
|
+
this.sources = sources;
|
|
498
|
+
this.sourcesContent = sourcesContent;
|
|
499
|
+
const from = resolve(sourceRoot || '', stripFilename(mapUrl));
|
|
500
|
+
this.resolvedSources = sources.map((s) => resolve(s || '', from));
|
|
501
|
+
const { mappings } = parsed;
|
|
502
|
+
if (typeof mappings === 'string') {
|
|
503
|
+
this._encoded = mappings;
|
|
504
|
+
this._decoded = undefined;
|
|
505
|
+
}
|
|
506
|
+
else {
|
|
507
|
+
this._encoded = undefined;
|
|
508
|
+
this._decoded = maybeSort(mappings, isString);
|
|
509
|
+
}
|
|
510
|
+
this._decodedMemo = memoizedState();
|
|
511
|
+
this._bySources = undefined;
|
|
512
|
+
this._bySourceMemos = undefined;
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
(() => {
|
|
516
|
+
decodedMappings = (map) => {
|
|
517
|
+
return (map._decoded || (map._decoded = decode(map._encoded)));
|
|
518
|
+
};
|
|
519
|
+
originalPositionFor = (map, { line, column, bias }) => {
|
|
520
|
+
line--;
|
|
521
|
+
if (line < 0)
|
|
522
|
+
throw new Error(LINE_GTR_ZERO);
|
|
523
|
+
if (column < 0)
|
|
524
|
+
throw new Error(COL_GTR_EQ_ZERO);
|
|
525
|
+
const decoded = decodedMappings(map);
|
|
526
|
+
// It's common for parent source maps to have pointers to lines that have no
|
|
527
|
+
// mapping (like a "//# sourceMappingURL=") at the end of the child file.
|
|
528
|
+
if (line >= decoded.length)
|
|
529
|
+
return OMapping(null, null, null, null);
|
|
530
|
+
const segments = decoded[line];
|
|
531
|
+
const index = traceSegmentInternal(segments, map._decodedMemo, line, column, bias || GREATEST_LOWER_BOUND);
|
|
532
|
+
if (index === -1)
|
|
533
|
+
return OMapping(null, null, null, null);
|
|
534
|
+
const segment = segments[index];
|
|
535
|
+
if (segment.length === 1)
|
|
536
|
+
return OMapping(null, null, null, null);
|
|
537
|
+
const { names, resolvedSources } = map;
|
|
538
|
+
return OMapping(resolvedSources[segment[SOURCES_INDEX]], segment[SOURCE_LINE] + 1, segment[SOURCE_COLUMN], segment.length === 5 ? names[segment[NAMES_INDEX]] : null);
|
|
539
|
+
};
|
|
540
|
+
})();
|
|
541
|
+
function OMapping(source, line, column, name) {
|
|
542
|
+
return { source, line, column, name };
|
|
543
|
+
}
|
|
544
|
+
function traceSegmentInternal(segments, memo, line, column, bias) {
|
|
545
|
+
let index = memoizedBinarySearch(segments, column, memo, line);
|
|
546
|
+
if (found) {
|
|
547
|
+
index = (bias === LEAST_UPPER_BOUND ? upperBound : lowerBound)(segments, column, index);
|
|
548
|
+
}
|
|
549
|
+
else if (bias === LEAST_UPPER_BOUND)
|
|
550
|
+
index++;
|
|
551
|
+
if (index === -1 || index === segments.length)
|
|
552
|
+
return -1;
|
|
553
|
+
return index;
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
let errorFormatterInstalled = false;
|
|
557
|
+
let fileContentsCache = {};
|
|
558
|
+
let sourceMapCache = {};
|
|
559
|
+
const reSourceMap = /^data:application\/json[^,]+base64,/;
|
|
560
|
+
let retrieveFileHandlers = [];
|
|
561
|
+
let retrieveMapHandlers = [];
|
|
562
|
+
function globalProcessVersion() {
|
|
563
|
+
if (typeof process === "object" && process !== null)
|
|
564
|
+
return process.version;
|
|
565
|
+
else
|
|
566
|
+
return "";
|
|
567
|
+
}
|
|
568
|
+
function handlerExec(list) {
|
|
569
|
+
return function(arg) {
|
|
570
|
+
for (let i = 0; i < list.length; i++) {
|
|
571
|
+
const ret = list[i](arg);
|
|
572
|
+
if (ret)
|
|
573
|
+
return ret;
|
|
574
|
+
}
|
|
575
|
+
return null;
|
|
576
|
+
};
|
|
577
|
+
}
|
|
578
|
+
let retrieveFile = handlerExec(retrieveFileHandlers);
|
|
579
|
+
retrieveFileHandlers.push((path2) => {
|
|
580
|
+
path2 = path2.trim();
|
|
581
|
+
if (path2.startsWith("file:")) {
|
|
582
|
+
path2 = path2.replace(/file:\/\/\/(\w:)?/, (protocol, drive) => {
|
|
583
|
+
return drive ? "" : "/";
|
|
584
|
+
});
|
|
585
|
+
}
|
|
586
|
+
if (path2 in fileContentsCache)
|
|
587
|
+
return fileContentsCache[path2];
|
|
588
|
+
let contents = "";
|
|
589
|
+
try {
|
|
590
|
+
if (fs.existsSync(path2))
|
|
591
|
+
contents = fs.readFileSync(path2, "utf8");
|
|
592
|
+
} catch (er) {
|
|
593
|
+
}
|
|
594
|
+
return fileContentsCache[path2] = contents;
|
|
595
|
+
});
|
|
596
|
+
function supportRelativeURL(file, url) {
|
|
597
|
+
if (!file)
|
|
598
|
+
return url;
|
|
599
|
+
const dir = path.dirname(file);
|
|
600
|
+
const match = /^\w+:\/\/[^\/]*/.exec(dir);
|
|
601
|
+
let protocol = match ? match[0] : "";
|
|
602
|
+
const startPath = dir.slice(protocol.length);
|
|
603
|
+
if (protocol && /^\/\w\:/.test(startPath)) {
|
|
604
|
+
protocol += "/";
|
|
605
|
+
return protocol + path.resolve(dir.slice(protocol.length), url).replace(/\\/g, "/");
|
|
606
|
+
}
|
|
607
|
+
return protocol + path.resolve(dir.slice(protocol.length), url);
|
|
608
|
+
}
|
|
609
|
+
function retrieveSourceMapURL(source) {
|
|
610
|
+
const fileData = retrieveFile(source);
|
|
611
|
+
if (!fileData)
|
|
612
|
+
return null;
|
|
613
|
+
const re = /(?:\/\/[@#][\s]*sourceMappingURL=([^\s'"]+)[\s]*$)|(?:\/\*[@#][\s]*sourceMappingURL=([^\s*'"]+)[\s]*(?:\*\/)[\s]*$)/mg;
|
|
614
|
+
let lastMatch, match;
|
|
615
|
+
while (match = re.exec(fileData))
|
|
616
|
+
lastMatch = match;
|
|
617
|
+
if (!lastMatch)
|
|
618
|
+
return null;
|
|
619
|
+
return lastMatch[1];
|
|
620
|
+
}
|
|
621
|
+
let retrieveSourceMap = handlerExec(retrieveMapHandlers);
|
|
622
|
+
retrieveMapHandlers.push((source) => {
|
|
623
|
+
let sourceMappingURL = retrieveSourceMapURL(source);
|
|
624
|
+
if (!sourceMappingURL)
|
|
625
|
+
return null;
|
|
626
|
+
let sourceMapData;
|
|
627
|
+
if (reSourceMap.test(sourceMappingURL)) {
|
|
628
|
+
const rawData = sourceMappingURL.slice(sourceMappingURL.indexOf(",") + 1);
|
|
629
|
+
sourceMapData = Buffer.from(rawData, "base64").toString();
|
|
630
|
+
sourceMappingURL = source;
|
|
631
|
+
} else {
|
|
632
|
+
sourceMappingURL = supportRelativeURL(source, sourceMappingURL);
|
|
633
|
+
sourceMapData = retrieveFile(sourceMappingURL);
|
|
634
|
+
}
|
|
635
|
+
if (!sourceMapData)
|
|
636
|
+
return null;
|
|
637
|
+
return {
|
|
638
|
+
url: sourceMappingURL,
|
|
639
|
+
map: sourceMapData
|
|
640
|
+
};
|
|
641
|
+
});
|
|
642
|
+
function mapSourcePosition(position) {
|
|
643
|
+
var _a;
|
|
644
|
+
if (!position.source)
|
|
645
|
+
return position;
|
|
646
|
+
let sourceMap = sourceMapCache[position.source];
|
|
647
|
+
if (!sourceMap) {
|
|
648
|
+
const urlAndMap = retrieveSourceMap(position.source);
|
|
649
|
+
if (urlAndMap && urlAndMap.map) {
|
|
650
|
+
sourceMap = sourceMapCache[position.source] = {
|
|
651
|
+
url: urlAndMap.url,
|
|
652
|
+
map: new TraceMap(urlAndMap.map)
|
|
653
|
+
};
|
|
654
|
+
if ((_a = sourceMap.map) == null ? void 0 : _a.sourcesContent) {
|
|
655
|
+
sourceMap.map.sources.forEach((source, i) => {
|
|
656
|
+
var _a2, _b;
|
|
657
|
+
const contents = (_b = (_a2 = sourceMap.map) == null ? void 0 : _a2.sourcesContent) == null ? void 0 : _b[i];
|
|
658
|
+
if (contents && source && sourceMap.url) {
|
|
659
|
+
const url = supportRelativeURL(sourceMap.url, source);
|
|
660
|
+
fileContentsCache[url] = contents;
|
|
661
|
+
}
|
|
662
|
+
});
|
|
663
|
+
}
|
|
664
|
+
} else {
|
|
665
|
+
sourceMap = sourceMapCache[position.source] = {
|
|
666
|
+
url: null,
|
|
667
|
+
map: null
|
|
668
|
+
};
|
|
669
|
+
}
|
|
670
|
+
}
|
|
671
|
+
if (sourceMap && sourceMap.map && sourceMap.url) {
|
|
672
|
+
const originalPosition = originalPositionFor(sourceMap.map, position);
|
|
673
|
+
if (originalPosition.source !== null) {
|
|
674
|
+
originalPosition.source = supportRelativeURL(
|
|
675
|
+
sourceMap.url,
|
|
676
|
+
originalPosition.source
|
|
677
|
+
);
|
|
678
|
+
return originalPosition;
|
|
679
|
+
}
|
|
680
|
+
}
|
|
681
|
+
return position;
|
|
682
|
+
}
|
|
683
|
+
function mapEvalOrigin(origin) {
|
|
684
|
+
let match = /^eval at ([^(]+) \((.+):(\d+):(\d+)\)$/.exec(origin);
|
|
685
|
+
if (match) {
|
|
686
|
+
const position = mapSourcePosition({
|
|
687
|
+
name: null,
|
|
688
|
+
source: match[2],
|
|
689
|
+
line: +match[3],
|
|
690
|
+
column: +match[4] - 1
|
|
691
|
+
});
|
|
692
|
+
return `eval at ${match[1]} (${position.source}:${position.line}:${position.column + 1})`;
|
|
693
|
+
}
|
|
694
|
+
match = /^eval at ([^(]+) \((.+)\)$/.exec(origin);
|
|
695
|
+
if (match)
|
|
696
|
+
return `eval at ${match[1]} (${mapEvalOrigin(match[2])})`;
|
|
697
|
+
return origin;
|
|
698
|
+
}
|
|
699
|
+
function CallSiteToString() {
|
|
700
|
+
let fileName;
|
|
701
|
+
let fileLocation = "";
|
|
702
|
+
if (this.isNative()) {
|
|
703
|
+
fileLocation = "native";
|
|
704
|
+
} else {
|
|
705
|
+
fileName = this.getScriptNameOrSourceURL();
|
|
706
|
+
if (!fileName && this.isEval()) {
|
|
707
|
+
fileLocation = this.getEvalOrigin();
|
|
708
|
+
fileLocation += ", ";
|
|
709
|
+
}
|
|
710
|
+
if (fileName) {
|
|
711
|
+
fileLocation += fileName;
|
|
712
|
+
} else {
|
|
713
|
+
fileLocation += "<anonymous>";
|
|
714
|
+
}
|
|
715
|
+
const lineNumber = this.getLineNumber();
|
|
716
|
+
if (lineNumber != null) {
|
|
717
|
+
fileLocation += `:${lineNumber}`;
|
|
718
|
+
const columnNumber = this.getColumnNumber();
|
|
719
|
+
if (columnNumber)
|
|
720
|
+
fileLocation += `:${columnNumber}`;
|
|
721
|
+
}
|
|
722
|
+
}
|
|
723
|
+
let line = "";
|
|
724
|
+
const functionName = this.getFunctionName();
|
|
725
|
+
let addSuffix = true;
|
|
726
|
+
const isConstructor = this.isConstructor();
|
|
727
|
+
const isMethodCall = !(this.isToplevel() || isConstructor);
|
|
728
|
+
if (isMethodCall) {
|
|
729
|
+
let typeName = this.getTypeName();
|
|
730
|
+
if (typeName === "[object Object]")
|
|
731
|
+
typeName = "null";
|
|
732
|
+
const methodName = this.getMethodName();
|
|
733
|
+
if (functionName) {
|
|
734
|
+
if (typeName && functionName.indexOf(typeName) !== 0)
|
|
735
|
+
line += `${typeName}.`;
|
|
736
|
+
line += functionName;
|
|
737
|
+
if (methodName && functionName.indexOf(`.${methodName}`) !== functionName.length - methodName.length - 1)
|
|
738
|
+
line += ` [as ${methodName}]`;
|
|
739
|
+
} else {
|
|
740
|
+
line += `${typeName}.${methodName || "<anonymous>"}`;
|
|
741
|
+
}
|
|
742
|
+
} else if (isConstructor) {
|
|
743
|
+
line += `new ${functionName || "<anonymous>"}`;
|
|
744
|
+
} else if (functionName) {
|
|
745
|
+
line += functionName;
|
|
746
|
+
} else {
|
|
747
|
+
line += fileLocation;
|
|
748
|
+
addSuffix = false;
|
|
749
|
+
}
|
|
750
|
+
if (addSuffix)
|
|
751
|
+
line += ` (${fileLocation})`;
|
|
752
|
+
return line;
|
|
753
|
+
}
|
|
754
|
+
function cloneCallSite(frame) {
|
|
755
|
+
const object = {};
|
|
756
|
+
Object.getOwnPropertyNames(Object.getPrototypeOf(frame)).forEach((name) => {
|
|
757
|
+
const key = name;
|
|
758
|
+
object[key] = /^(?:is|get)/.test(name) ? function() {
|
|
759
|
+
return frame[key].call(frame);
|
|
760
|
+
} : frame[key];
|
|
761
|
+
});
|
|
762
|
+
object.toString = CallSiteToString;
|
|
763
|
+
return object;
|
|
764
|
+
}
|
|
765
|
+
function wrapCallSite(frame, state) {
|
|
766
|
+
if (state === void 0)
|
|
767
|
+
state = { nextPosition: null, curPosition: null };
|
|
768
|
+
if (frame.isNative()) {
|
|
769
|
+
state.curPosition = null;
|
|
770
|
+
return frame;
|
|
771
|
+
}
|
|
772
|
+
const source = frame.getFileName() || frame.getScriptNameOrSourceURL();
|
|
773
|
+
if (source) {
|
|
774
|
+
const line = frame.getLineNumber();
|
|
775
|
+
let column = frame.getColumnNumber() - 1;
|
|
776
|
+
const noHeader = /^v(10\.1[6-9]|10\.[2-9][0-9]|10\.[0-9]{3,}|1[2-9]\d*|[2-9]\d|\d{3,}|11\.11)/;
|
|
777
|
+
const headerLength = noHeader.test(globalProcessVersion()) ? 0 : 62;
|
|
778
|
+
if (line === 1 && column > headerLength && !frame.isEval())
|
|
779
|
+
column -= headerLength;
|
|
780
|
+
const position = mapSourcePosition({
|
|
781
|
+
name: null,
|
|
782
|
+
source,
|
|
783
|
+
line,
|
|
784
|
+
column
|
|
785
|
+
});
|
|
786
|
+
state.curPosition = position;
|
|
787
|
+
frame = cloneCallSite(frame);
|
|
788
|
+
const originalFunctionName = frame.getFunctionName;
|
|
789
|
+
frame.getFunctionName = function() {
|
|
790
|
+
if (state.nextPosition == null)
|
|
791
|
+
return originalFunctionName();
|
|
792
|
+
return state.nextPosition.name || originalFunctionName();
|
|
793
|
+
};
|
|
794
|
+
frame.getFileName = function() {
|
|
795
|
+
return position.source;
|
|
796
|
+
};
|
|
797
|
+
frame.getLineNumber = function() {
|
|
798
|
+
return position.line;
|
|
799
|
+
};
|
|
800
|
+
frame.getColumnNumber = function() {
|
|
801
|
+
return position.column + 1;
|
|
802
|
+
};
|
|
803
|
+
frame.getScriptNameOrSourceURL = function() {
|
|
804
|
+
return position.source;
|
|
805
|
+
};
|
|
806
|
+
return frame;
|
|
807
|
+
}
|
|
808
|
+
let origin = frame.isEval() && frame.getEvalOrigin();
|
|
809
|
+
if (origin) {
|
|
810
|
+
origin = mapEvalOrigin(origin);
|
|
811
|
+
frame = cloneCallSite(frame);
|
|
812
|
+
frame.getEvalOrigin = function() {
|
|
813
|
+
return origin || void 0;
|
|
814
|
+
};
|
|
815
|
+
return frame;
|
|
816
|
+
}
|
|
817
|
+
return frame;
|
|
818
|
+
}
|
|
819
|
+
function prepareStackTrace(error, stack) {
|
|
820
|
+
const name = error.name || "Error";
|
|
821
|
+
const message = error.message || "";
|
|
822
|
+
const errorString = `${name}: ${message}`;
|
|
823
|
+
const state = { nextPosition: null, curPosition: null };
|
|
824
|
+
const processedStack = [];
|
|
825
|
+
for (let i = stack.length - 1; i >= 0; i--) {
|
|
826
|
+
processedStack.push(`
|
|
827
|
+
at ${wrapCallSite(stack[i], state)}`);
|
|
828
|
+
state.nextPosition = state.curPosition;
|
|
829
|
+
}
|
|
830
|
+
state.curPosition = state.nextPosition = null;
|
|
831
|
+
return errorString + processedStack.reverse().join("");
|
|
832
|
+
}
|
|
833
|
+
retrieveFileHandlers.slice(0);
|
|
834
|
+
retrieveMapHandlers.slice(0);
|
|
835
|
+
const install = function(options) {
|
|
836
|
+
options = options || {};
|
|
837
|
+
if (options.retrieveFile) {
|
|
838
|
+
if (options.overrideRetrieveFile)
|
|
839
|
+
retrieveFileHandlers.length = 0;
|
|
840
|
+
retrieveFileHandlers.unshift(options.retrieveFile);
|
|
841
|
+
}
|
|
842
|
+
if (options.retrieveSourceMap) {
|
|
843
|
+
if (options.overrideRetrieveSourceMap)
|
|
844
|
+
retrieveMapHandlers.length = 0;
|
|
845
|
+
retrieveMapHandlers.unshift(options.retrieveSourceMap);
|
|
846
|
+
}
|
|
847
|
+
if (!errorFormatterInstalled) {
|
|
848
|
+
errorFormatterInstalled = true;
|
|
849
|
+
Error.prepareStackTrace = prepareStackTrace;
|
|
850
|
+
}
|
|
851
|
+
};
|
|
2
852
|
|
|
3
853
|
let SOURCEMAPPING_URL = "sourceMa";
|
|
4
854
|
SOURCEMAPPING_URL += "ppingURL";
|
|
@@ -30,8 +880,6 @@ function extractSourceMap(code) {
|
|
|
30
880
|
}
|
|
31
881
|
function installSourcemapsSupport(options) {
|
|
32
882
|
install({
|
|
33
|
-
environment: "node",
|
|
34
|
-
handleUncaughtExceptions: false,
|
|
35
883
|
retrieveSourceMap(source) {
|
|
36
884
|
const map = options.getSourceMap(source);
|
|
37
885
|
if (map) {
|