vite-node 4.0.0-beta.8 → 5.0.0-beta.2
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/LICENSE +1 -1
- package/README.md +8 -4
- package/dist/{chunk-hmr.mjs → chunk-hmr.js} +63 -34
- package/dist/{chunk-browser.mjs → chunk-index.js} +26 -25
- package/dist/cli.d.ts +1 -1
- package/dist/{cli.mjs → cli.js} +67 -23
- package/dist/client.d.ts +1 -1
- package/dist/{client.mjs → client.js} +110 -46
- package/dist/hmr.d.ts +1 -4
- package/dist/{hmr.mjs → hmr.js} +4 -3
- package/dist/{index.d-CvIJUDRh.d.ts → index.d-D6Pqey3g.d.ts} +5 -1
- package/dist/index.d.ts +1 -1
- package/dist/server.d.ts +2 -2
- package/dist/{server.mjs → server.js} +110 -56
- package/dist/{source-map.mjs → source-map.js} +229 -173
- package/dist/types.d.ts +1 -1
- package/dist/utils.d.ts +1 -1
- package/dist/{utils.mjs → utils.js} +33 -13
- package/package.json +41 -60
- package/vite-node.js +2 -0
- package/dist/chunk-browser.cjs +0 -83
- package/dist/chunk-hmr.cjs +0 -221
- package/dist/cli.cjs +0 -114
- package/dist/client.cjs +0 -447
- package/dist/constants.cjs +0 -36
- package/dist/hmr.cjs +0 -21
- package/dist/index.cjs +0 -2
- package/dist/server.cjs +0 -382
- package/dist/source-map.cjs +0 -867
- package/dist/types.cjs +0 -2
- package/dist/utils.cjs +0 -196
- package/vite-node.mjs +0 -2
- /package/dist/{constants.mjs → constants.js} +0 -0
- /package/dist/{index.mjs → index.js} +0 -0
- /package/dist/{types.mjs → types.js} +0 -0
package/dist/source-map.cjs
DELETED
|
@@ -1,867 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var pathe = require('pathe');
|
|
4
|
-
var fs = require('node:fs');
|
|
5
|
-
var path = require('node:path');
|
|
6
|
-
var utils = require('./utils.cjs');
|
|
7
|
-
require('node:module');
|
|
8
|
-
require('node:url');
|
|
9
|
-
|
|
10
|
-
const comma = ','.charCodeAt(0);
|
|
11
|
-
const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
|
|
12
|
-
const intToChar = new Uint8Array(64); // 64 possible chars.
|
|
13
|
-
const charToInt = new Uint8Array(128); // z is 122 in ASCII
|
|
14
|
-
for (let i = 0; i < chars.length; i++) {
|
|
15
|
-
const c = chars.charCodeAt(i);
|
|
16
|
-
intToChar[i] = c;
|
|
17
|
-
charToInt[c] = i;
|
|
18
|
-
}
|
|
19
|
-
function decodeInteger(reader, relative) {
|
|
20
|
-
let value = 0;
|
|
21
|
-
let shift = 0;
|
|
22
|
-
let integer = 0;
|
|
23
|
-
do {
|
|
24
|
-
const c = reader.next();
|
|
25
|
-
integer = charToInt[c];
|
|
26
|
-
value |= (integer & 31) << shift;
|
|
27
|
-
shift += 5;
|
|
28
|
-
} while (integer & 32);
|
|
29
|
-
const shouldNegate = value & 1;
|
|
30
|
-
value >>>= 1;
|
|
31
|
-
if (shouldNegate) {
|
|
32
|
-
value = -2147483648 | -value;
|
|
33
|
-
}
|
|
34
|
-
return relative + value;
|
|
35
|
-
}
|
|
36
|
-
function hasMoreVlq(reader, max) {
|
|
37
|
-
if (reader.pos >= max)
|
|
38
|
-
return false;
|
|
39
|
-
return reader.peek() !== comma;
|
|
40
|
-
}
|
|
41
|
-
class StringReader {
|
|
42
|
-
constructor(buffer) {
|
|
43
|
-
this.pos = 0;
|
|
44
|
-
this.buffer = buffer;
|
|
45
|
-
}
|
|
46
|
-
next() {
|
|
47
|
-
return this.buffer.charCodeAt(this.pos++);
|
|
48
|
-
}
|
|
49
|
-
peek() {
|
|
50
|
-
return this.buffer.charCodeAt(this.pos);
|
|
51
|
-
}
|
|
52
|
-
indexOf(char) {
|
|
53
|
-
const { buffer, pos } = this;
|
|
54
|
-
const idx = buffer.indexOf(char, pos);
|
|
55
|
-
return idx === -1 ? buffer.length : idx;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
function decode(mappings) {
|
|
60
|
-
const { length } = mappings;
|
|
61
|
-
const reader = new StringReader(mappings);
|
|
62
|
-
const decoded = [];
|
|
63
|
-
let genColumn = 0;
|
|
64
|
-
let sourcesIndex = 0;
|
|
65
|
-
let sourceLine = 0;
|
|
66
|
-
let sourceColumn = 0;
|
|
67
|
-
let namesIndex = 0;
|
|
68
|
-
do {
|
|
69
|
-
const semi = reader.indexOf(';');
|
|
70
|
-
const line = [];
|
|
71
|
-
let sorted = true;
|
|
72
|
-
let lastCol = 0;
|
|
73
|
-
genColumn = 0;
|
|
74
|
-
while (reader.pos < semi) {
|
|
75
|
-
let seg;
|
|
76
|
-
genColumn = decodeInteger(reader, genColumn);
|
|
77
|
-
if (genColumn < lastCol)
|
|
78
|
-
sorted = false;
|
|
79
|
-
lastCol = genColumn;
|
|
80
|
-
if (hasMoreVlq(reader, semi)) {
|
|
81
|
-
sourcesIndex = decodeInteger(reader, sourcesIndex);
|
|
82
|
-
sourceLine = decodeInteger(reader, sourceLine);
|
|
83
|
-
sourceColumn = decodeInteger(reader, sourceColumn);
|
|
84
|
-
if (hasMoreVlq(reader, semi)) {
|
|
85
|
-
namesIndex = decodeInteger(reader, namesIndex);
|
|
86
|
-
seg = [genColumn, sourcesIndex, sourceLine, sourceColumn, namesIndex];
|
|
87
|
-
}
|
|
88
|
-
else {
|
|
89
|
-
seg = [genColumn, sourcesIndex, sourceLine, sourceColumn];
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
else {
|
|
93
|
-
seg = [genColumn];
|
|
94
|
-
}
|
|
95
|
-
line.push(seg);
|
|
96
|
-
reader.pos++;
|
|
97
|
-
}
|
|
98
|
-
if (!sorted)
|
|
99
|
-
sort(line);
|
|
100
|
-
decoded.push(line);
|
|
101
|
-
reader.pos = semi + 1;
|
|
102
|
-
} while (reader.pos <= length);
|
|
103
|
-
return decoded;
|
|
104
|
-
}
|
|
105
|
-
function sort(line) {
|
|
106
|
-
line.sort(sortComparator$1);
|
|
107
|
-
}
|
|
108
|
-
function sortComparator$1(a, b) {
|
|
109
|
-
return a[0] - b[0];
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
// Matches the scheme of a URL, eg "http://"
|
|
113
|
-
const schemeRegex = /^[\w+.-]+:\/\//;
|
|
114
|
-
/**
|
|
115
|
-
* Matches the parts of a URL:
|
|
116
|
-
* 1. Scheme, including ":", guaranteed.
|
|
117
|
-
* 2. User/password, including "@", optional.
|
|
118
|
-
* 3. Host, guaranteed.
|
|
119
|
-
* 4. Port, including ":", optional.
|
|
120
|
-
* 5. Path, including "/", optional.
|
|
121
|
-
* 6. Query, including "?", optional.
|
|
122
|
-
* 7. Hash, including "#", optional.
|
|
123
|
-
*/
|
|
124
|
-
const urlRegex = /^([\w+.-]+:)\/\/([^@/#?]*@)?([^:/#?]*)(:\d+)?(\/[^#?]*)?(\?[^#]*)?(#.*)?/;
|
|
125
|
-
/**
|
|
126
|
-
* File URLs are weird. They dont' need the regular `//` in the scheme, they may or may not start
|
|
127
|
-
* with a leading `/`, they can have a domain (but only if they don't start with a Windows drive).
|
|
128
|
-
*
|
|
129
|
-
* 1. Host, optional.
|
|
130
|
-
* 2. Path, which may include "/", guaranteed.
|
|
131
|
-
* 3. Query, including "?", optional.
|
|
132
|
-
* 4. Hash, including "#", optional.
|
|
133
|
-
*/
|
|
134
|
-
const fileRegex = /^file:(?:\/\/((?![a-z]:)[^/#?]*)?)?(\/?[^#?]*)(\?[^#]*)?(#.*)?/i;
|
|
135
|
-
var UrlType;
|
|
136
|
-
(function (UrlType) {
|
|
137
|
-
UrlType[UrlType["Empty"] = 1] = "Empty";
|
|
138
|
-
UrlType[UrlType["Hash"] = 2] = "Hash";
|
|
139
|
-
UrlType[UrlType["Query"] = 3] = "Query";
|
|
140
|
-
UrlType[UrlType["RelativePath"] = 4] = "RelativePath";
|
|
141
|
-
UrlType[UrlType["AbsolutePath"] = 5] = "AbsolutePath";
|
|
142
|
-
UrlType[UrlType["SchemeRelative"] = 6] = "SchemeRelative";
|
|
143
|
-
UrlType[UrlType["Absolute"] = 7] = "Absolute";
|
|
144
|
-
})(UrlType || (UrlType = {}));
|
|
145
|
-
function isAbsoluteUrl(input) {
|
|
146
|
-
return schemeRegex.test(input);
|
|
147
|
-
}
|
|
148
|
-
function isSchemeRelativeUrl(input) {
|
|
149
|
-
return input.startsWith('//');
|
|
150
|
-
}
|
|
151
|
-
function isAbsolutePath(input) {
|
|
152
|
-
return input.startsWith('/');
|
|
153
|
-
}
|
|
154
|
-
function isFileUrl(input) {
|
|
155
|
-
return input.startsWith('file:');
|
|
156
|
-
}
|
|
157
|
-
function isRelative(input) {
|
|
158
|
-
return /^[.?#]/.test(input);
|
|
159
|
-
}
|
|
160
|
-
function parseAbsoluteUrl(input) {
|
|
161
|
-
const match = urlRegex.exec(input);
|
|
162
|
-
return makeUrl(match[1], match[2] || '', match[3], match[4] || '', match[5] || '/', match[6] || '', match[7] || '');
|
|
163
|
-
}
|
|
164
|
-
function parseFileUrl(input) {
|
|
165
|
-
const match = fileRegex.exec(input);
|
|
166
|
-
const path = match[2];
|
|
167
|
-
return makeUrl('file:', '', match[1] || '', '', isAbsolutePath(path) ? path : '/' + path, match[3] || '', match[4] || '');
|
|
168
|
-
}
|
|
169
|
-
function makeUrl(scheme, user, host, port, path, query, hash) {
|
|
170
|
-
return {
|
|
171
|
-
scheme,
|
|
172
|
-
user,
|
|
173
|
-
host,
|
|
174
|
-
port,
|
|
175
|
-
path,
|
|
176
|
-
query,
|
|
177
|
-
hash,
|
|
178
|
-
type: UrlType.Absolute,
|
|
179
|
-
};
|
|
180
|
-
}
|
|
181
|
-
function parseUrl(input) {
|
|
182
|
-
if (isSchemeRelativeUrl(input)) {
|
|
183
|
-
const url = parseAbsoluteUrl('http:' + input);
|
|
184
|
-
url.scheme = '';
|
|
185
|
-
url.type = UrlType.SchemeRelative;
|
|
186
|
-
return url;
|
|
187
|
-
}
|
|
188
|
-
if (isAbsolutePath(input)) {
|
|
189
|
-
const url = parseAbsoluteUrl('http://foo.com' + input);
|
|
190
|
-
url.scheme = '';
|
|
191
|
-
url.host = '';
|
|
192
|
-
url.type = UrlType.AbsolutePath;
|
|
193
|
-
return url;
|
|
194
|
-
}
|
|
195
|
-
if (isFileUrl(input))
|
|
196
|
-
return parseFileUrl(input);
|
|
197
|
-
if (isAbsoluteUrl(input))
|
|
198
|
-
return parseAbsoluteUrl(input);
|
|
199
|
-
const url = parseAbsoluteUrl('http://foo.com/' + input);
|
|
200
|
-
url.scheme = '';
|
|
201
|
-
url.host = '';
|
|
202
|
-
url.type = input
|
|
203
|
-
? input.startsWith('?')
|
|
204
|
-
? UrlType.Query
|
|
205
|
-
: input.startsWith('#')
|
|
206
|
-
? UrlType.Hash
|
|
207
|
-
: UrlType.RelativePath
|
|
208
|
-
: UrlType.Empty;
|
|
209
|
-
return url;
|
|
210
|
-
}
|
|
211
|
-
function stripPathFilename(path) {
|
|
212
|
-
// If a path ends with a parent directory "..", then it's a relative path with excess parent
|
|
213
|
-
// paths. It's not a file, so we can't strip it.
|
|
214
|
-
if (path.endsWith('/..'))
|
|
215
|
-
return path;
|
|
216
|
-
const index = path.lastIndexOf('/');
|
|
217
|
-
return path.slice(0, index + 1);
|
|
218
|
-
}
|
|
219
|
-
function mergePaths(url, base) {
|
|
220
|
-
normalizePath(base, base.type);
|
|
221
|
-
// If the path is just a "/", then it was an empty path to begin with (remember, we're a relative
|
|
222
|
-
// path).
|
|
223
|
-
if (url.path === '/') {
|
|
224
|
-
url.path = base.path;
|
|
225
|
-
}
|
|
226
|
-
else {
|
|
227
|
-
// Resolution happens relative to the base path's directory, not the file.
|
|
228
|
-
url.path = stripPathFilename(base.path) + url.path;
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
/**
|
|
232
|
-
* The path can have empty directories "//", unneeded parents "foo/..", or current directory
|
|
233
|
-
* "foo/.". We need to normalize to a standard representation.
|
|
234
|
-
*/
|
|
235
|
-
function normalizePath(url, type) {
|
|
236
|
-
const rel = type <= UrlType.RelativePath;
|
|
237
|
-
const pieces = url.path.split('/');
|
|
238
|
-
// We need to preserve the first piece always, so that we output a leading slash. The item at
|
|
239
|
-
// pieces[0] is an empty string.
|
|
240
|
-
let pointer = 1;
|
|
241
|
-
// Positive is the number of real directories we've output, used for popping a parent directory.
|
|
242
|
-
// Eg, "foo/bar/.." will have a positive 2, and we can decrement to be left with just "foo".
|
|
243
|
-
let positive = 0;
|
|
244
|
-
// We need to keep a trailing slash if we encounter an empty directory (eg, splitting "foo/" will
|
|
245
|
-
// generate `["foo", ""]` pieces). And, if we pop a parent directory. But once we encounter a
|
|
246
|
-
// real directory, we won't need to append, unless the other conditions happen again.
|
|
247
|
-
let addTrailingSlash = false;
|
|
248
|
-
for (let i = 1; i < pieces.length; i++) {
|
|
249
|
-
const piece = pieces[i];
|
|
250
|
-
// An empty directory, could be a trailing slash, or just a double "//" in the path.
|
|
251
|
-
if (!piece) {
|
|
252
|
-
addTrailingSlash = true;
|
|
253
|
-
continue;
|
|
254
|
-
}
|
|
255
|
-
// If we encounter a real directory, then we don't need to append anymore.
|
|
256
|
-
addTrailingSlash = false;
|
|
257
|
-
// A current directory, which we can always drop.
|
|
258
|
-
if (piece === '.')
|
|
259
|
-
continue;
|
|
260
|
-
// A parent directory, we need to see if there are any real directories we can pop. Else, we
|
|
261
|
-
// have an excess of parents, and we'll need to keep the "..".
|
|
262
|
-
if (piece === '..') {
|
|
263
|
-
if (positive) {
|
|
264
|
-
addTrailingSlash = true;
|
|
265
|
-
positive--;
|
|
266
|
-
pointer--;
|
|
267
|
-
}
|
|
268
|
-
else if (rel) {
|
|
269
|
-
// If we're in a relativePath, then we need to keep the excess parents. Else, in an absolute
|
|
270
|
-
// URL, protocol relative URL, or an absolute path, we don't need to keep excess.
|
|
271
|
-
pieces[pointer++] = piece;
|
|
272
|
-
}
|
|
273
|
-
continue;
|
|
274
|
-
}
|
|
275
|
-
// We've encountered a real directory. Move it to the next insertion pointer, which accounts for
|
|
276
|
-
// any popped or dropped directories.
|
|
277
|
-
pieces[pointer++] = piece;
|
|
278
|
-
positive++;
|
|
279
|
-
}
|
|
280
|
-
let path = '';
|
|
281
|
-
for (let i = 1; i < pointer; i++) {
|
|
282
|
-
path += '/' + pieces[i];
|
|
283
|
-
}
|
|
284
|
-
if (!path || (addTrailingSlash && !path.endsWith('/..'))) {
|
|
285
|
-
path += '/';
|
|
286
|
-
}
|
|
287
|
-
url.path = path;
|
|
288
|
-
}
|
|
289
|
-
/**
|
|
290
|
-
* Attempts to resolve `input` URL/path relative to `base`.
|
|
291
|
-
*/
|
|
292
|
-
function resolve(input, base) {
|
|
293
|
-
if (!input && !base)
|
|
294
|
-
return '';
|
|
295
|
-
const url = parseUrl(input);
|
|
296
|
-
let inputType = url.type;
|
|
297
|
-
if (base && inputType !== UrlType.Absolute) {
|
|
298
|
-
const baseUrl = parseUrl(base);
|
|
299
|
-
const baseType = baseUrl.type;
|
|
300
|
-
switch (inputType) {
|
|
301
|
-
case UrlType.Empty:
|
|
302
|
-
url.hash = baseUrl.hash;
|
|
303
|
-
// fall through
|
|
304
|
-
case UrlType.Hash:
|
|
305
|
-
url.query = baseUrl.query;
|
|
306
|
-
// fall through
|
|
307
|
-
case UrlType.Query:
|
|
308
|
-
case UrlType.RelativePath:
|
|
309
|
-
mergePaths(url, baseUrl);
|
|
310
|
-
// fall through
|
|
311
|
-
case UrlType.AbsolutePath:
|
|
312
|
-
// The host, user, and port are joined, you can't copy one without the others.
|
|
313
|
-
url.user = baseUrl.user;
|
|
314
|
-
url.host = baseUrl.host;
|
|
315
|
-
url.port = baseUrl.port;
|
|
316
|
-
// fall through
|
|
317
|
-
case UrlType.SchemeRelative:
|
|
318
|
-
// The input doesn't have a schema at least, so we need to copy at least that over.
|
|
319
|
-
url.scheme = baseUrl.scheme;
|
|
320
|
-
}
|
|
321
|
-
if (baseType > inputType)
|
|
322
|
-
inputType = baseType;
|
|
323
|
-
}
|
|
324
|
-
normalizePath(url, inputType);
|
|
325
|
-
const queryHash = url.query + url.hash;
|
|
326
|
-
switch (inputType) {
|
|
327
|
-
// This is impossible, because of the empty checks at the start of the function.
|
|
328
|
-
// case UrlType.Empty:
|
|
329
|
-
case UrlType.Hash:
|
|
330
|
-
case UrlType.Query:
|
|
331
|
-
return queryHash;
|
|
332
|
-
case UrlType.RelativePath: {
|
|
333
|
-
// The first char is always a "/", and we need it to be relative.
|
|
334
|
-
const path = url.path.slice(1);
|
|
335
|
-
if (!path)
|
|
336
|
-
return queryHash || '.';
|
|
337
|
-
if (isRelative(base || input) && !isRelative(path)) {
|
|
338
|
-
// If base started with a leading ".", or there is no base and input started with a ".",
|
|
339
|
-
// then we need to ensure that the relative path starts with a ".". We don't know if
|
|
340
|
-
// relative starts with a "..", though, so check before prepending.
|
|
341
|
-
return './' + path + queryHash;
|
|
342
|
-
}
|
|
343
|
-
return path + queryHash;
|
|
344
|
-
}
|
|
345
|
-
case UrlType.AbsolutePath:
|
|
346
|
-
return url.path + queryHash;
|
|
347
|
-
default:
|
|
348
|
-
return url.scheme + '//' + url.user + url.host + url.port + url.path + queryHash;
|
|
349
|
-
}
|
|
350
|
-
}
|
|
351
|
-
|
|
352
|
-
// src/trace-mapping.ts
|
|
353
|
-
|
|
354
|
-
// src/strip-filename.ts
|
|
355
|
-
function stripFilename(path) {
|
|
356
|
-
if (!path) return "";
|
|
357
|
-
const index = path.lastIndexOf("/");
|
|
358
|
-
return path.slice(0, index + 1);
|
|
359
|
-
}
|
|
360
|
-
|
|
361
|
-
// src/resolve.ts
|
|
362
|
-
function resolver(mapUrl, sourceRoot) {
|
|
363
|
-
const from = stripFilename(mapUrl);
|
|
364
|
-
const prefix = sourceRoot ? sourceRoot + "/" : "";
|
|
365
|
-
return (source) => resolve(prefix + (source || ""), from);
|
|
366
|
-
}
|
|
367
|
-
|
|
368
|
-
// src/sourcemap-segment.ts
|
|
369
|
-
var COLUMN = 0;
|
|
370
|
-
var SOURCES_INDEX = 1;
|
|
371
|
-
var SOURCE_LINE = 2;
|
|
372
|
-
var SOURCE_COLUMN = 3;
|
|
373
|
-
var NAMES_INDEX = 4;
|
|
374
|
-
|
|
375
|
-
// src/sort.ts
|
|
376
|
-
function maybeSort(mappings, owned) {
|
|
377
|
-
const unsortedIndex = nextUnsortedSegmentLine(mappings, 0);
|
|
378
|
-
if (unsortedIndex === mappings.length) return mappings;
|
|
379
|
-
if (!owned) mappings = mappings.slice();
|
|
380
|
-
for (let i = unsortedIndex; i < mappings.length; i = nextUnsortedSegmentLine(mappings, i + 1)) {
|
|
381
|
-
mappings[i] = sortSegments(mappings[i], owned);
|
|
382
|
-
}
|
|
383
|
-
return mappings;
|
|
384
|
-
}
|
|
385
|
-
function nextUnsortedSegmentLine(mappings, start) {
|
|
386
|
-
for (let i = start; i < mappings.length; i++) {
|
|
387
|
-
if (!isSorted(mappings[i])) return i;
|
|
388
|
-
}
|
|
389
|
-
return mappings.length;
|
|
390
|
-
}
|
|
391
|
-
function isSorted(line) {
|
|
392
|
-
for (let j = 1; j < line.length; j++) {
|
|
393
|
-
if (line[j][COLUMN] < line[j - 1][COLUMN]) {
|
|
394
|
-
return false;
|
|
395
|
-
}
|
|
396
|
-
}
|
|
397
|
-
return true;
|
|
398
|
-
}
|
|
399
|
-
function sortSegments(line, owned) {
|
|
400
|
-
if (!owned) line = line.slice();
|
|
401
|
-
return line.sort(sortComparator);
|
|
402
|
-
}
|
|
403
|
-
function sortComparator(a, b) {
|
|
404
|
-
return a[COLUMN] - b[COLUMN];
|
|
405
|
-
}
|
|
406
|
-
|
|
407
|
-
// src/binary-search.ts
|
|
408
|
-
var found = false;
|
|
409
|
-
function binarySearch(haystack, needle, low, high) {
|
|
410
|
-
while (low <= high) {
|
|
411
|
-
const mid = low + (high - low >> 1);
|
|
412
|
-
const cmp = haystack[mid][COLUMN] - needle;
|
|
413
|
-
if (cmp === 0) {
|
|
414
|
-
found = true;
|
|
415
|
-
return mid;
|
|
416
|
-
}
|
|
417
|
-
if (cmp < 0) {
|
|
418
|
-
low = mid + 1;
|
|
419
|
-
} else {
|
|
420
|
-
high = mid - 1;
|
|
421
|
-
}
|
|
422
|
-
}
|
|
423
|
-
found = false;
|
|
424
|
-
return low - 1;
|
|
425
|
-
}
|
|
426
|
-
function upperBound(haystack, needle, index) {
|
|
427
|
-
for (let i = index + 1; i < haystack.length; index = i++) {
|
|
428
|
-
if (haystack[i][COLUMN] !== needle) 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) break;
|
|
435
|
-
}
|
|
436
|
-
return index;
|
|
437
|
-
}
|
|
438
|
-
function memoizedState() {
|
|
439
|
-
return {
|
|
440
|
-
lastKey: -1,
|
|
441
|
-
lastNeedle: -1,
|
|
442
|
-
lastIndex: -1
|
|
443
|
-
};
|
|
444
|
-
}
|
|
445
|
-
function memoizedBinarySearch(haystack, needle, state, key) {
|
|
446
|
-
const { lastKey, lastNeedle, lastIndex } = state;
|
|
447
|
-
let low = 0;
|
|
448
|
-
let high = haystack.length - 1;
|
|
449
|
-
if (key === lastKey) {
|
|
450
|
-
if (needle === lastNeedle) {
|
|
451
|
-
found = lastIndex !== -1 && haystack[lastIndex][COLUMN] === needle;
|
|
452
|
-
return lastIndex;
|
|
453
|
-
}
|
|
454
|
-
if (needle >= lastNeedle) {
|
|
455
|
-
low = lastIndex === -1 ? 0 : lastIndex;
|
|
456
|
-
} else {
|
|
457
|
-
high = lastIndex;
|
|
458
|
-
}
|
|
459
|
-
}
|
|
460
|
-
state.lastKey = key;
|
|
461
|
-
state.lastNeedle = needle;
|
|
462
|
-
return state.lastIndex = binarySearch(haystack, needle, low, high);
|
|
463
|
-
}
|
|
464
|
-
|
|
465
|
-
// src/types.ts
|
|
466
|
-
function parse(map) {
|
|
467
|
-
return typeof map === "string" ? JSON.parse(map) : map;
|
|
468
|
-
}
|
|
469
|
-
|
|
470
|
-
// src/trace-mapping.ts
|
|
471
|
-
var LINE_GTR_ZERO = "`line` must be greater than 0 (lines start at line 1)";
|
|
472
|
-
var COL_GTR_EQ_ZERO = "`column` must be greater than or equal to 0 (columns start at column 0)";
|
|
473
|
-
var LEAST_UPPER_BOUND = -1;
|
|
474
|
-
var GREATEST_LOWER_BOUND = 1;
|
|
475
|
-
var TraceMap = class {
|
|
476
|
-
constructor(map, mapUrl) {
|
|
477
|
-
const isString = typeof map === "string";
|
|
478
|
-
if (!isString && map._decodedMemo) return map;
|
|
479
|
-
const parsed = parse(map);
|
|
480
|
-
const { version, file, names, sourceRoot, sources, sourcesContent } = parsed;
|
|
481
|
-
this.version = version;
|
|
482
|
-
this.file = file;
|
|
483
|
-
this.names = names || [];
|
|
484
|
-
this.sourceRoot = sourceRoot;
|
|
485
|
-
this.sources = sources;
|
|
486
|
-
this.sourcesContent = sourcesContent;
|
|
487
|
-
this.ignoreList = parsed.ignoreList || parsed.x_google_ignoreList || void 0;
|
|
488
|
-
const resolve = resolver(mapUrl, sourceRoot);
|
|
489
|
-
this.resolvedSources = sources.map(resolve);
|
|
490
|
-
const { mappings } = parsed;
|
|
491
|
-
if (typeof mappings === "string") {
|
|
492
|
-
this._encoded = mappings;
|
|
493
|
-
this._decoded = void 0;
|
|
494
|
-
} else if (Array.isArray(mappings)) {
|
|
495
|
-
this._encoded = void 0;
|
|
496
|
-
this._decoded = maybeSort(mappings, isString);
|
|
497
|
-
} else if (parsed.sections) {
|
|
498
|
-
throw new Error(`TraceMap passed sectioned source map, please use FlattenMap export instead`);
|
|
499
|
-
} else {
|
|
500
|
-
throw new Error(`invalid source map: ${JSON.stringify(parsed)}`);
|
|
501
|
-
}
|
|
502
|
-
this._decodedMemo = memoizedState();
|
|
503
|
-
this._bySources = void 0;
|
|
504
|
-
this._bySourceMemos = void 0;
|
|
505
|
-
}
|
|
506
|
-
};
|
|
507
|
-
function cast(map) {
|
|
508
|
-
return map;
|
|
509
|
-
}
|
|
510
|
-
function decodedMappings(map) {
|
|
511
|
-
var _a;
|
|
512
|
-
return (_a = cast(map))._decoded || (_a._decoded = decode(cast(map)._encoded));
|
|
513
|
-
}
|
|
514
|
-
function originalPositionFor(map, needle) {
|
|
515
|
-
let { line, column, bias } = needle;
|
|
516
|
-
line--;
|
|
517
|
-
if (line < 0) throw new Error(LINE_GTR_ZERO);
|
|
518
|
-
if (column < 0) throw new Error(COL_GTR_EQ_ZERO);
|
|
519
|
-
const decoded = decodedMappings(map);
|
|
520
|
-
if (line >= decoded.length) return OMapping(null, null, null, null);
|
|
521
|
-
const segments = decoded[line];
|
|
522
|
-
const index = traceSegmentInternal(
|
|
523
|
-
segments,
|
|
524
|
-
cast(map)._decodedMemo,
|
|
525
|
-
line,
|
|
526
|
-
column,
|
|
527
|
-
bias || GREATEST_LOWER_BOUND
|
|
528
|
-
);
|
|
529
|
-
if (index === -1) return OMapping(null, null, null, null);
|
|
530
|
-
const segment = segments[index];
|
|
531
|
-
if (segment.length === 1) return OMapping(null, null, null, null);
|
|
532
|
-
const { names, resolvedSources } = map;
|
|
533
|
-
return OMapping(
|
|
534
|
-
resolvedSources[segment[SOURCES_INDEX]],
|
|
535
|
-
segment[SOURCE_LINE] + 1,
|
|
536
|
-
segment[SOURCE_COLUMN],
|
|
537
|
-
segment.length === 5 ? names[segment[NAMES_INDEX]] : null
|
|
538
|
-
);
|
|
539
|
-
}
|
|
540
|
-
function OMapping(source, line, column, name) {
|
|
541
|
-
return { source, line, column, name };
|
|
542
|
-
}
|
|
543
|
-
function traceSegmentInternal(segments, memo, line, column, bias) {
|
|
544
|
-
let index = memoizedBinarySearch(segments, column, memo, line);
|
|
545
|
-
if (found) {
|
|
546
|
-
index = (bias === LEAST_UPPER_BOUND ? upperBound : lowerBound)(segments, column, index);
|
|
547
|
-
} else if (bias === LEAST_UPPER_BOUND) index++;
|
|
548
|
-
if (index === -1 || index === segments.length) return -1;
|
|
549
|
-
return index;
|
|
550
|
-
}
|
|
551
|
-
|
|
552
|
-
// Only install once if called multiple times
|
|
553
|
-
let errorFormatterInstalled = false;
|
|
554
|
-
// Maps a file path to a string containing the file contents
|
|
555
|
-
const fileContentsCache = {}, sourceMapCache = {}, reSourceMap = /^data:application\/json[^,]+base64,/;
|
|
556
|
-
// Priority list of retrieve handlers
|
|
557
|
-
let retrieveFileHandlers = [], retrieveMapHandlers = [];
|
|
558
|
-
function globalProcessVersion() {
|
|
559
|
-
return typeof process === "object" && process !== null ? process.version : "";
|
|
560
|
-
}
|
|
561
|
-
function handlerExec(list) {
|
|
562
|
-
return function(arg) {
|
|
563
|
-
for (let i = 0; i < list.length; i++) {
|
|
564
|
-
const ret = list[i](arg);
|
|
565
|
-
if (ret) return ret;
|
|
566
|
-
}
|
|
567
|
-
return null;
|
|
568
|
-
};
|
|
569
|
-
}
|
|
570
|
-
let retrieveFile = handlerExec(retrieveFileHandlers);
|
|
571
|
-
retrieveFileHandlers.push((path) => {
|
|
572
|
-
if (path = path.trim(), path.startsWith("file:"))
|
|
573
|
-
// existsSync/readFileSync can't handle file protocol, but once stripped, it works
|
|
574
|
-
path = path.replace(/file:\/\/\/(\w:)?/, (protocol, drive) => {
|
|
575
|
-
return drive ? "" : "/";
|
|
576
|
-
});
|
|
577
|
-
if (path in fileContentsCache) return fileContentsCache[path];
|
|
578
|
-
let contents = "";
|
|
579
|
-
try {
|
|
580
|
-
if (fs.existsSync(path)) contents = fs.readFileSync(path, "utf8");
|
|
581
|
-
} catch {}
|
|
582
|
-
return fileContentsCache[path] = contents;
|
|
583
|
-
});
|
|
584
|
-
// Support URLs relative to a directory, but be careful about a protocol prefix
|
|
585
|
-
function supportRelativeURL(file, url) {
|
|
586
|
-
if (!file) return url;
|
|
587
|
-
const dir = path.dirname(file), match = /^\w+:\/\/[^/]*/.exec(dir);
|
|
588
|
-
let protocol = match ? match[0] : "";
|
|
589
|
-
const startPath = dir.slice(protocol.length);
|
|
590
|
-
return protocol && /^\/\w:/.test(startPath) ? (protocol += "/", protocol + path.resolve(dir.slice(protocol.length), url).replace(/\\/g, "/")) : protocol + path.resolve(dir.slice(protocol.length), url);
|
|
591
|
-
}
|
|
592
|
-
function retrieveSourceMapURL(source) {
|
|
593
|
-
// Get the URL of the source map
|
|
594
|
-
const fileData = retrieveFile(source);
|
|
595
|
-
if (!fileData) return null;
|
|
596
|
-
const re = /\/\/[@#]\s*sourceMappingURL=([^\s'"]+)\s*$|\/\*[@#]\s*sourceMappingURL=[^\s*'"]+\s*\*\/\s*$/gm;
|
|
597
|
-
// Keep executing the search to find the *last* sourceMappingURL to avoid
|
|
598
|
-
// picking up sourceMappingURLs from comments, strings, etc.
|
|
599
|
-
let lastMatch, match;
|
|
600
|
-
// eslint-disable-next-line no-cond-assign
|
|
601
|
-
while (match = re.exec(fileData)) lastMatch = match;
|
|
602
|
-
return lastMatch ? lastMatch[1] : null;
|
|
603
|
-
}
|
|
604
|
-
// Can be overridden by the retrieveSourceMap option to install. Takes a
|
|
605
|
-
// generated source filename; returns a {map, optional url} object, or null if
|
|
606
|
-
// there is no source map. The map field may be either a string or the parsed
|
|
607
|
-
// JSON object (ie, it must be a valid argument to the SourceMapConsumer
|
|
608
|
-
// constructor).
|
|
609
|
-
let retrieveSourceMap = handlerExec(retrieveMapHandlers);
|
|
610
|
-
retrieveMapHandlers.push((source) => {
|
|
611
|
-
let sourceMappingURL = retrieveSourceMapURL(source);
|
|
612
|
-
if (!sourceMappingURL) return null;
|
|
613
|
-
// Read the contents of the source map
|
|
614
|
-
let sourceMapData;
|
|
615
|
-
if (reSourceMap.test(sourceMappingURL)) {
|
|
616
|
-
// Support source map URL as a data url
|
|
617
|
-
const rawData = sourceMappingURL.slice(sourceMappingURL.indexOf(",") + 1);
|
|
618
|
-
sourceMapData = Buffer.from(rawData, "base64").toString(), sourceMappingURL = source;
|
|
619
|
-
} else sourceMappingURL = supportRelativeURL(source, sourceMappingURL), sourceMapData = retrieveFile(sourceMappingURL);
|
|
620
|
-
return sourceMapData ? {
|
|
621
|
-
url: sourceMappingURL,
|
|
622
|
-
map: sourceMapData
|
|
623
|
-
} : null;
|
|
624
|
-
});
|
|
625
|
-
// interface Position {
|
|
626
|
-
// source: string
|
|
627
|
-
// line: number
|
|
628
|
-
// column: number
|
|
629
|
-
// }
|
|
630
|
-
function mapSourcePosition(position) {
|
|
631
|
-
if (!position.source) return position;
|
|
632
|
-
let sourceMap = sourceMapCache[position.source];
|
|
633
|
-
if (!sourceMap) {
|
|
634
|
-
// Call the (overridable) retrieveSourceMap function to get the source map.
|
|
635
|
-
const urlAndMap = retrieveSourceMap(position.source), map = urlAndMap && urlAndMap.map;
|
|
636
|
-
if (map && !(typeof map === "object" && "mappings" in map && map.mappings === "")) {
|
|
637
|
-
var _sourceMap$map;
|
|
638
|
-
// Load all sources stored inline with the source map into the file cache
|
|
639
|
-
// to pretend like they are already loaded. They may not exist on disk.
|
|
640
|
-
if (sourceMap = sourceMapCache[position.source] = {
|
|
641
|
-
url: urlAndMap.url,
|
|
642
|
-
map: new TraceMap(map)
|
|
643
|
-
}, (_sourceMap$map = sourceMap.map) === null || _sourceMap$map === void 0 ? void 0 : _sourceMap$map.sourcesContent) sourceMap.map.sources.forEach((source, i) => {
|
|
644
|
-
var _sourceMap$map2;
|
|
645
|
-
const contents = (_sourceMap$map2 = sourceMap.map) === null || _sourceMap$map2 === void 0 || (_sourceMap$map2 = _sourceMap$map2.sourcesContent) === null || _sourceMap$map2 === void 0 ? void 0 : _sourceMap$map2[i];
|
|
646
|
-
if (contents && source && sourceMap.url) {
|
|
647
|
-
const url = supportRelativeURL(sourceMap.url, source);
|
|
648
|
-
fileContentsCache[url] = contents;
|
|
649
|
-
}
|
|
650
|
-
});
|
|
651
|
-
} else sourceMap = sourceMapCache[position.source] = {
|
|
652
|
-
url: null,
|
|
653
|
-
map: null
|
|
654
|
-
};
|
|
655
|
-
}
|
|
656
|
-
// Resolve the source URL relative to the URL of the source map
|
|
657
|
-
if (sourceMap && sourceMap.map && sourceMap.url) {
|
|
658
|
-
const originalPosition = originalPositionFor(sourceMap.map, position);
|
|
659
|
-
// Only return the original position if a matching line was found. If no
|
|
660
|
-
// matching line is found then we return position instead, which will cause
|
|
661
|
-
// the stack trace to print the path and line for the compiled file. It is
|
|
662
|
-
// better to give a precise location in the compiled file than a vague
|
|
663
|
-
// location in the original file.
|
|
664
|
-
if (originalPosition.source !== null) return originalPosition.source = supportRelativeURL(sourceMap.url, originalPosition.source), originalPosition;
|
|
665
|
-
}
|
|
666
|
-
return position;
|
|
667
|
-
}
|
|
668
|
-
// Parses code generated by FormatEvalOrigin(), a function inside V8:
|
|
669
|
-
// https://code.google.com/p/v8/source/browse/trunk/src/messages.js
|
|
670
|
-
function mapEvalOrigin(origin) {
|
|
671
|
-
// Most eval() calls are in this format
|
|
672
|
-
let match = /^eval at ([^(]+) \((.+):(\d+):(\d+)\)$/.exec(origin);
|
|
673
|
-
if (match) {
|
|
674
|
-
const position = mapSourcePosition({
|
|
675
|
-
name: null,
|
|
676
|
-
source: match[2],
|
|
677
|
-
line: +match[3],
|
|
678
|
-
column: +match[4] - 1
|
|
679
|
-
});
|
|
680
|
-
return `eval at ${match[1]} (${position.source}:${position.line}:${position.column + 1})`;
|
|
681
|
-
}
|
|
682
|
-
// Make sure we still return useful information if we didn't find anything
|
|
683
|
-
return match = /^eval at ([^(]+) \((.+)\)$/.exec(origin), match ? `eval at ${match[1]} (${mapEvalOrigin(match[2])})` : origin;
|
|
684
|
-
}
|
|
685
|
-
// This is copied almost verbatim from the V8 source code at
|
|
686
|
-
// https://code.google.com/p/v8/source/browse/trunk/src/messages.js. The
|
|
687
|
-
// implementation of wrapCallSite() used to just forward to the actual source
|
|
688
|
-
// code of CallSite.prototype.toString but unfortunately a new release of V8
|
|
689
|
-
// did something to the prototype chain and broke the shim. The only fix I
|
|
690
|
-
// could find was copy/paste.
|
|
691
|
-
function CallSiteToString() {
|
|
692
|
-
let fileName, fileLocation = "";
|
|
693
|
-
if (this.isNative()) fileLocation = "native";
|
|
694
|
-
else {
|
|
695
|
-
if (fileName = this.getScriptNameOrSourceURL(), !fileName && this.isEval()) fileLocation = this.getEvalOrigin(), fileLocation += ", ";
|
|
696
|
-
if (fileName) fileLocation += fileName;
|
|
697
|
-
else
|
|
698
|
-
// Source code does not originate from a file and is not native, but we
|
|
699
|
-
// can still get the source position inside the source string, e.g. in
|
|
700
|
-
// an eval string.
|
|
701
|
-
fileLocation += "<anonymous>";
|
|
702
|
-
const lineNumber = this.getLineNumber();
|
|
703
|
-
if (lineNumber != null) {
|
|
704
|
-
fileLocation += `:${lineNumber}`;
|
|
705
|
-
const columnNumber = this.getColumnNumber();
|
|
706
|
-
if (columnNumber) fileLocation += `:${columnNumber}`;
|
|
707
|
-
}
|
|
708
|
-
}
|
|
709
|
-
let line = "";
|
|
710
|
-
const functionName = this.getFunctionName();
|
|
711
|
-
let addSuffix = true;
|
|
712
|
-
const isConstructor = this.isConstructor(), isMethodCall = !(this.isToplevel() || isConstructor);
|
|
713
|
-
if (isMethodCall) {
|
|
714
|
-
let typeName = this.getTypeName();
|
|
715
|
-
// Fixes shim to be backward compatible with Node v0 to v4
|
|
716
|
-
if (typeName === "[object Object]") typeName = "null";
|
|
717
|
-
const methodName = this.getMethodName();
|
|
718
|
-
if (functionName) {
|
|
719
|
-
if (typeName && functionName.indexOf(typeName) !== 0) line += `${typeName}.`;
|
|
720
|
-
if (line += functionName, methodName && functionName.indexOf(`.${methodName}`) !== functionName.length - methodName.length - 1) line += ` [as ${methodName}]`;
|
|
721
|
-
} else line += `${typeName}.${methodName || "<anonymous>"}`;
|
|
722
|
-
} else if (isConstructor) line += `new ${functionName || "<anonymous>"}`;
|
|
723
|
-
else if (functionName) line += functionName;
|
|
724
|
-
else line += fileLocation, addSuffix = false;
|
|
725
|
-
if (addSuffix) line += ` (${fileLocation})`;
|
|
726
|
-
return line;
|
|
727
|
-
}
|
|
728
|
-
function cloneCallSite(frame) {
|
|
729
|
-
const object = {};
|
|
730
|
-
return Object.getOwnPropertyNames(Object.getPrototypeOf(frame)).forEach((name) => {
|
|
731
|
-
const key = name;
|
|
732
|
-
// @ts-expect-error difficult to type
|
|
733
|
-
object[key] = /^(?:is|get)/.test(name) ? function() {
|
|
734
|
-
// eslint-disable-next-line no-useless-call
|
|
735
|
-
return frame[key].call(frame);
|
|
736
|
-
} : frame[key];
|
|
737
|
-
}), object.toString = CallSiteToString, object;
|
|
738
|
-
}
|
|
739
|
-
function wrapCallSite(frame, state) {
|
|
740
|
-
// provides interface backward compatibility
|
|
741
|
-
if (state === void 0) state = {
|
|
742
|
-
nextPosition: null,
|
|
743
|
-
curPosition: null
|
|
744
|
-
};
|
|
745
|
-
if (frame.isNative()) return state.curPosition = null, frame;
|
|
746
|
-
// Most call sites will return the source file from getFileName(), but code
|
|
747
|
-
// passed to eval() ending in "//# sourceURL=..." will return the source file
|
|
748
|
-
// from getScriptNameOrSourceURL() instead
|
|
749
|
-
const source = frame.getFileName() || frame.getScriptNameOrSourceURL();
|
|
750
|
-
if (source) {
|
|
751
|
-
const line = frame.getLineNumber();
|
|
752
|
-
let column = frame.getColumnNumber() - 1;
|
|
753
|
-
// Fix position in Node where some (internal) code is prepended.
|
|
754
|
-
// See https://github.com/evanw/node-source-map-support/issues/36
|
|
755
|
-
// Header removed in node at ^10.16 || >=11.11.0
|
|
756
|
-
// v11 is not an LTS candidate, we can just test the one version with it.
|
|
757
|
-
// Test node versions for: 10.16-19, 10.20+, 12-19, 20-99, 100+, or 11.11
|
|
758
|
-
const noHeader = /^v(?:10\.1[6-9]|10\.[2-9]\d|10\.\d{3,}|1[2-9]\d*|[2-9]\d|\d{3,}|11\.11)/, headerLength = noHeader.test(globalProcessVersion()) ? 0 : 62;
|
|
759
|
-
if (line === 1 && column > headerLength && !frame.isEval()) column -= headerLength;
|
|
760
|
-
const position = mapSourcePosition({
|
|
761
|
-
name: null,
|
|
762
|
-
source,
|
|
763
|
-
line,
|
|
764
|
-
column
|
|
765
|
-
});
|
|
766
|
-
state.curPosition = position, frame = cloneCallSite(frame);
|
|
767
|
-
const originalFunctionName = frame.getFunctionName;
|
|
768
|
-
return frame.getFunctionName = function() {
|
|
769
|
-
return state.nextPosition == null ? originalFunctionName() : state.nextPosition.name || originalFunctionName();
|
|
770
|
-
}, frame.getFileName = function() {
|
|
771
|
-
return position.source ?? null;
|
|
772
|
-
}, frame.getLineNumber = function() {
|
|
773
|
-
return position.line;
|
|
774
|
-
}, frame.getColumnNumber = function() {
|
|
775
|
-
return position.column + 1;
|
|
776
|
-
}, frame.getScriptNameOrSourceURL = function() {
|
|
777
|
-
return position.source;
|
|
778
|
-
}, frame;
|
|
779
|
-
}
|
|
780
|
-
// Code called using eval() needs special handling
|
|
781
|
-
let origin = frame.isEval() && frame.getEvalOrigin();
|
|
782
|
-
// If we get here then we were unable to change the source position
|
|
783
|
-
return origin ? (origin = mapEvalOrigin(origin), frame = cloneCallSite(frame), frame.getEvalOrigin = function() {
|
|
784
|
-
return origin || void 0;
|
|
785
|
-
}, frame) : frame;
|
|
786
|
-
}
|
|
787
|
-
// This function is part of the V8 stack trace API, for more info see:
|
|
788
|
-
// https://v8.dev/docs/stack-trace-api
|
|
789
|
-
function prepareStackTrace(error, stack) {
|
|
790
|
-
const name = error.name || "Error", message = error.message || "", errorString = `${name}: ${message}`, state = {
|
|
791
|
-
nextPosition: null,
|
|
792
|
-
curPosition: null
|
|
793
|
-
}, processedStack = [];
|
|
794
|
-
for (let i = stack.length - 1; i >= 0; i--) processedStack.push(`\n at ${wrapCallSite(stack[i], state)}`), state.nextPosition = state.curPosition;
|
|
795
|
-
return state.curPosition = state.nextPosition = null, errorString + processedStack.reverse().join("");
|
|
796
|
-
}
|
|
797
|
-
retrieveFileHandlers.slice(0); retrieveMapHandlers.slice(0);
|
|
798
|
-
function install(options) {
|
|
799
|
-
// Allow sources to be found by methods other than reading the files
|
|
800
|
-
// directly from disk.
|
|
801
|
-
if (options = options || {}, options.retrieveFile) {
|
|
802
|
-
if (options.overrideRetrieveFile) retrieveFileHandlers.length = 0;
|
|
803
|
-
retrieveFileHandlers.unshift(options.retrieveFile);
|
|
804
|
-
}
|
|
805
|
-
// Allow source maps to be found by methods other than reading the files
|
|
806
|
-
// directly from disk.
|
|
807
|
-
if (options.retrieveSourceMap) {
|
|
808
|
-
if (options.overrideRetrieveSourceMap) retrieveMapHandlers.length = 0;
|
|
809
|
-
retrieveMapHandlers.unshift(options.retrieveSourceMap);
|
|
810
|
-
}
|
|
811
|
-
// Install the error reformatter
|
|
812
|
-
if (!errorFormatterInstalled) errorFormatterInstalled = true, Error.prepareStackTrace = prepareStackTrace;
|
|
813
|
-
}
|
|
814
|
-
|
|
815
|
-
let SOURCEMAPPING_URL = "sourceMa";
|
|
816
|
-
SOURCEMAPPING_URL += "ppingURL";
|
|
817
|
-
const VITE_NODE_SOURCEMAPPING_SOURCE = "//# sourceMappingSource=vite-node", VITE_NODE_SOURCEMAPPING_URL = `${SOURCEMAPPING_URL}=data:application/json;charset=utf-8`;
|
|
818
|
-
function withInlineSourcemap(result, options) {
|
|
819
|
-
const map = result.map;
|
|
820
|
-
let code = result.code;
|
|
821
|
-
if (!map || code.includes(VITE_NODE_SOURCEMAPPING_SOURCE)) return result;
|
|
822
|
-
if ("sources" in map) {
|
|
823
|
-
var _map$sources;
|
|
824
|
-
map.sources = (_map$sources = map.sources) === null || _map$sources === void 0 ? void 0 : _map$sources.map((source) => {
|
|
825
|
-
if (!source) return source;
|
|
826
|
-
// sometimes files here are absolute,
|
|
827
|
-
// but they are considered absolute to the server url, not the file system
|
|
828
|
-
// this is a bug in Vite
|
|
829
|
-
// all files should be either absolute to the file system or relative to the source map file
|
|
830
|
-
if (pathe.isAbsolute(source)) {
|
|
831
|
-
const actualPath = !source.startsWith(utils.withTrailingSlash(options.root)) && source.startsWith("/") ? pathe.resolve(options.root, source.slice(1)) : source;
|
|
832
|
-
return pathe.relative(pathe.dirname(options.filepath), actualPath);
|
|
833
|
-
}
|
|
834
|
-
return source;
|
|
835
|
-
});
|
|
836
|
-
}
|
|
837
|
-
// to reduce the payload size, we only inline vite node source map, because it's also the only one we use
|
|
838
|
-
const OTHER_SOURCE_MAP_REGEXP = new RegExp(`//# ${SOURCEMAPPING_URL}=data:application/json[^,]+base64,([A-Za-z0-9+/=]+)$`, "gm");
|
|
839
|
-
while (OTHER_SOURCE_MAP_REGEXP.test(code)) code = code.replace(OTHER_SOURCE_MAP_REGEXP, "");
|
|
840
|
-
// If the first line is not present on source maps, add simple 1:1 mapping ([0,0,0,0], [1,0,0,0])
|
|
841
|
-
// so that debuggers can be set to break on first line
|
|
842
|
-
// Since Vite 6, import statements at the top of the file are preserved correctly,
|
|
843
|
-
// so we don't need to add this mapping anymore.
|
|
844
|
-
if (!options.noFirstLineMapping && map.mappings.startsWith(";")) map.mappings = `AAAA,CAAA${map.mappings}`;
|
|
845
|
-
const sourceMap = Buffer.from(JSON.stringify(map), "utf-8").toString("base64");
|
|
846
|
-
return result.code = `${code.trimEnd()}\n\n${VITE_NODE_SOURCEMAPPING_SOURCE}\n//# ${VITE_NODE_SOURCEMAPPING_URL};base64,${sourceMap}\n`, result;
|
|
847
|
-
}
|
|
848
|
-
function extractSourceMap(code) {
|
|
849
|
-
const regexp = new RegExp(`//# ${VITE_NODE_SOURCEMAPPING_URL};base64,(.+)`, "gm");
|
|
850
|
-
let lastMatch, match;
|
|
851
|
-
// eslint-disable-next-line no-cond-assign
|
|
852
|
-
while (match = regexp.exec(code)) lastMatch = match;
|
|
853
|
-
return lastMatch ? JSON.parse(Buffer.from(lastMatch[1], "base64").toString("utf-8")) : null;
|
|
854
|
-
}
|
|
855
|
-
function installSourcemapsSupport(options) {
|
|
856
|
-
install({ retrieveSourceMap(source) {
|
|
857
|
-
const map = options.getSourceMap(source);
|
|
858
|
-
return map ? {
|
|
859
|
-
url: source,
|
|
860
|
-
map
|
|
861
|
-
} : null;
|
|
862
|
-
} });
|
|
863
|
-
}
|
|
864
|
-
|
|
865
|
-
exports.extractSourceMap = extractSourceMap;
|
|
866
|
-
exports.installSourcemapsSupport = installSourcemapsSupport;
|
|
867
|
-
exports.withInlineSourcemap = withInlineSourcemap;
|