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