vite-node 5.1.0 → 5.2.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.d.mts +21 -0
- package/dist/cli.mjs +145 -0
- package/dist/{client.js → client-CyS7w_FB.mjs} +54 -87
- package/dist/client.d.mts +2 -0
- package/dist/client.mjs +5 -0
- package/dist/{constants.js → constants-DRkacFwN.mjs} +3 -1
- package/dist/{constants.d.ts → constants.d.mts} +3 -2
- package/dist/constants.mjs +3 -0
- package/dist/dist-B2ebky9O.mjs +85 -0
- package/dist/{chunk-hmr.js → hmr-qEG3qSgW.mjs} +17 -29
- package/dist/hmr.d.mts +57 -0
- package/dist/hmr.mjs +5 -0
- package/dist/index.d.mts +2 -0
- package/dist/index.mjs +3 -0
- package/dist/{server.js → server-BWywEVuB.mjs} +52 -87
- package/dist/server.d.mts +60 -0
- package/dist/server.mjs +7 -0
- package/dist/source-map-DQLD3K8K.mjs +737 -0
- package/dist/{source-map.d.ts → source-map.d.mts} +9 -8
- package/dist/source-map.mjs +4 -0
- package/dist/types-55T_-8KG.mjs +1 -0
- package/dist/types-Dtew7m7O.d.mts +212 -0
- package/dist/types.d.mts +2 -0
- package/dist/types.mjs +3 -0
- package/dist/{utils.js → utils-ExLpYVUV.mjs} +10 -18
- package/dist/{utils.d.ts → utils.d.mts} +7 -7
- package/dist/utils.mjs +3 -0
- package/package.json +25 -32
- package/dist/chunk-index.js +0 -82
- package/dist/cli.d.ts +0 -21
- package/dist/cli.js +0 -162
- package/dist/client.d.ts +0 -2
- package/dist/hmr.d.ts +0 -55
- package/dist/hmr.js +0 -10
- package/dist/index.d-D6Pqey3g.d.ts +0 -367
- package/dist/index.d.ts +0 -2
- package/dist/index.js +0 -1
- package/dist/server.d.ts +0 -58
- package/dist/source-map.js +0 -919
- package/dist/trace-mapping.d-BWFx6tPc.d.ts +0 -62
- package/dist/types.d.ts +0 -2
- package/dist/types.js +0 -1
- package/vite-node.js +0 -2
|
@@ -0,0 +1,737 @@
|
|
|
1
|
+
import { _ as withTrailingSlash } from "./utils-ExLpYVUV.mjs";
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
import process from "node:process";
|
|
4
|
+
import { dirname, isAbsolute, relative, resolve } from "pathe";
|
|
5
|
+
import { Buffer as Buffer$1 } from "node:buffer";
|
|
6
|
+
import path from "node:path";
|
|
7
|
+
|
|
8
|
+
//#region node_modules/.pnpm/@jridgewell+sourcemap-codec@1.5.5/node_modules/@jridgewell/sourcemap-codec/dist/sourcemap-codec.mjs
|
|
9
|
+
var comma = ",".charCodeAt(0);
|
|
10
|
+
var semicolon = ";".charCodeAt(0);
|
|
11
|
+
var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
12
|
+
var intToChar = new Uint8Array(64);
|
|
13
|
+
var charToInt = new Uint8Array(128);
|
|
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$1) {
|
|
20
|
+
let value = 0;
|
|
21
|
+
let shift = 0;
|
|
22
|
+
let integer = 0;
|
|
23
|
+
do {
|
|
24
|
+
integer = charToInt[reader.next()];
|
|
25
|
+
value |= (integer & 31) << shift;
|
|
26
|
+
shift += 5;
|
|
27
|
+
} while (integer & 32);
|
|
28
|
+
const shouldNegate = value & 1;
|
|
29
|
+
value >>>= 1;
|
|
30
|
+
if (shouldNegate) value = -2147483648 | -value;
|
|
31
|
+
return relative$1 + value;
|
|
32
|
+
}
|
|
33
|
+
function hasMoreVlq(reader, max) {
|
|
34
|
+
if (reader.pos >= max) return false;
|
|
35
|
+
return reader.peek() !== comma;
|
|
36
|
+
}
|
|
37
|
+
var bufLength = 1024 * 16;
|
|
38
|
+
var StringReader = class {
|
|
39
|
+
constructor(buffer) {
|
|
40
|
+
this.pos = 0;
|
|
41
|
+
this.buffer = buffer;
|
|
42
|
+
}
|
|
43
|
+
next() {
|
|
44
|
+
return this.buffer.charCodeAt(this.pos++);
|
|
45
|
+
}
|
|
46
|
+
peek() {
|
|
47
|
+
return this.buffer.charCodeAt(this.pos);
|
|
48
|
+
}
|
|
49
|
+
indexOf(char) {
|
|
50
|
+
const { buffer, pos } = this;
|
|
51
|
+
const idx = buffer.indexOf(char, pos);
|
|
52
|
+
return idx === -1 ? buffer.length : idx;
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
function decode(mappings) {
|
|
56
|
+
const { length } = mappings;
|
|
57
|
+
const reader = new StringReader(mappings);
|
|
58
|
+
const decoded = [];
|
|
59
|
+
let genColumn = 0;
|
|
60
|
+
let sourcesIndex = 0;
|
|
61
|
+
let sourceLine = 0;
|
|
62
|
+
let sourceColumn = 0;
|
|
63
|
+
let namesIndex = 0;
|
|
64
|
+
do {
|
|
65
|
+
const semi = reader.indexOf(";");
|
|
66
|
+
const line = [];
|
|
67
|
+
let sorted = true;
|
|
68
|
+
let lastCol = 0;
|
|
69
|
+
genColumn = 0;
|
|
70
|
+
while (reader.pos < semi) {
|
|
71
|
+
let seg;
|
|
72
|
+
genColumn = decodeInteger(reader, genColumn);
|
|
73
|
+
if (genColumn < lastCol) sorted = false;
|
|
74
|
+
lastCol = genColumn;
|
|
75
|
+
if (hasMoreVlq(reader, semi)) {
|
|
76
|
+
sourcesIndex = decodeInteger(reader, sourcesIndex);
|
|
77
|
+
sourceLine = decodeInteger(reader, sourceLine);
|
|
78
|
+
sourceColumn = decodeInteger(reader, sourceColumn);
|
|
79
|
+
if (hasMoreVlq(reader, semi)) {
|
|
80
|
+
namesIndex = decodeInteger(reader, namesIndex);
|
|
81
|
+
seg = [
|
|
82
|
+
genColumn,
|
|
83
|
+
sourcesIndex,
|
|
84
|
+
sourceLine,
|
|
85
|
+
sourceColumn,
|
|
86
|
+
namesIndex
|
|
87
|
+
];
|
|
88
|
+
} else seg = [
|
|
89
|
+
genColumn,
|
|
90
|
+
sourcesIndex,
|
|
91
|
+
sourceLine,
|
|
92
|
+
sourceColumn
|
|
93
|
+
];
|
|
94
|
+
} else seg = [genColumn];
|
|
95
|
+
line.push(seg);
|
|
96
|
+
reader.pos++;
|
|
97
|
+
}
|
|
98
|
+
if (!sorted) sort(line);
|
|
99
|
+
decoded.push(line);
|
|
100
|
+
reader.pos = semi + 1;
|
|
101
|
+
} while (reader.pos <= length);
|
|
102
|
+
return decoded;
|
|
103
|
+
}
|
|
104
|
+
function sort(line) {
|
|
105
|
+
line.sort(sortComparator$1);
|
|
106
|
+
}
|
|
107
|
+
function sortComparator$1(a, b) {
|
|
108
|
+
return a[0] - b[0];
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
//#endregion
|
|
112
|
+
//#region node_modules/.pnpm/@jridgewell+resolve-uri@3.1.2/node_modules/@jridgewell/resolve-uri/dist/resolve-uri.mjs
|
|
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
|
+
function isAbsoluteUrl(input) {
|
|
136
|
+
return schemeRegex.test(input);
|
|
137
|
+
}
|
|
138
|
+
function isSchemeRelativeUrl(input) {
|
|
139
|
+
return input.startsWith("//");
|
|
140
|
+
}
|
|
141
|
+
function isAbsolutePath(input) {
|
|
142
|
+
return input.startsWith("/");
|
|
143
|
+
}
|
|
144
|
+
function isFileUrl(input) {
|
|
145
|
+
return input.startsWith("file:");
|
|
146
|
+
}
|
|
147
|
+
function isRelative(input) {
|
|
148
|
+
return /^[.?#]/.test(input);
|
|
149
|
+
}
|
|
150
|
+
function parseAbsoluteUrl(input) {
|
|
151
|
+
const match = urlRegex.exec(input);
|
|
152
|
+
return makeUrl(match[1], match[2] || "", match[3], match[4] || "", match[5] || "/", match[6] || "", match[7] || "");
|
|
153
|
+
}
|
|
154
|
+
function parseFileUrl(input) {
|
|
155
|
+
const match = fileRegex.exec(input);
|
|
156
|
+
const path$1 = match[2];
|
|
157
|
+
return makeUrl("file:", "", match[1] || "", "", isAbsolutePath(path$1) ? path$1 : "/" + path$1, match[3] || "", match[4] || "");
|
|
158
|
+
}
|
|
159
|
+
function makeUrl(scheme, user, host, port, path$1, query, hash) {
|
|
160
|
+
return {
|
|
161
|
+
scheme,
|
|
162
|
+
user,
|
|
163
|
+
host,
|
|
164
|
+
port,
|
|
165
|
+
path: path$1,
|
|
166
|
+
query,
|
|
167
|
+
hash,
|
|
168
|
+
type: 7
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
function parseUrl(input) {
|
|
172
|
+
if (isSchemeRelativeUrl(input)) {
|
|
173
|
+
const url$1 = parseAbsoluteUrl("http:" + input);
|
|
174
|
+
url$1.scheme = "";
|
|
175
|
+
url$1.type = 6;
|
|
176
|
+
return url$1;
|
|
177
|
+
}
|
|
178
|
+
if (isAbsolutePath(input)) {
|
|
179
|
+
const url$1 = parseAbsoluteUrl("http://foo.com" + input);
|
|
180
|
+
url$1.scheme = "";
|
|
181
|
+
url$1.host = "";
|
|
182
|
+
url$1.type = 5;
|
|
183
|
+
return url$1;
|
|
184
|
+
}
|
|
185
|
+
if (isFileUrl(input)) return parseFileUrl(input);
|
|
186
|
+
if (isAbsoluteUrl(input)) return parseAbsoluteUrl(input);
|
|
187
|
+
const url = parseAbsoluteUrl("http://foo.com/" + input);
|
|
188
|
+
url.scheme = "";
|
|
189
|
+
url.host = "";
|
|
190
|
+
url.type = input ? input.startsWith("?") ? 3 : input.startsWith("#") ? 2 : 4 : 1;
|
|
191
|
+
return url;
|
|
192
|
+
}
|
|
193
|
+
function stripPathFilename(path$1) {
|
|
194
|
+
if (path$1.endsWith("/..")) return path$1;
|
|
195
|
+
const index = path$1.lastIndexOf("/");
|
|
196
|
+
return path$1.slice(0, index + 1);
|
|
197
|
+
}
|
|
198
|
+
function mergePaths(url, base) {
|
|
199
|
+
normalizePath(base, base.type);
|
|
200
|
+
if (url.path === "/") url.path = base.path;
|
|
201
|
+
else url.path = stripPathFilename(base.path) + url.path;
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* The path can have empty directories "//", unneeded parents "foo/..", or current directory
|
|
205
|
+
* "foo/.". We need to normalize to a standard representation.
|
|
206
|
+
*/
|
|
207
|
+
function normalizePath(url, type) {
|
|
208
|
+
const rel = type <= 4;
|
|
209
|
+
const pieces = url.path.split("/");
|
|
210
|
+
let pointer = 1;
|
|
211
|
+
let positive = 0;
|
|
212
|
+
let addTrailingSlash = false;
|
|
213
|
+
for (let i = 1; i < pieces.length; i++) {
|
|
214
|
+
const piece = pieces[i];
|
|
215
|
+
if (!piece) {
|
|
216
|
+
addTrailingSlash = true;
|
|
217
|
+
continue;
|
|
218
|
+
}
|
|
219
|
+
addTrailingSlash = false;
|
|
220
|
+
if (piece === ".") continue;
|
|
221
|
+
if (piece === "..") {
|
|
222
|
+
if (positive) {
|
|
223
|
+
addTrailingSlash = true;
|
|
224
|
+
positive--;
|
|
225
|
+
pointer--;
|
|
226
|
+
} else if (rel) pieces[pointer++] = piece;
|
|
227
|
+
continue;
|
|
228
|
+
}
|
|
229
|
+
pieces[pointer++] = piece;
|
|
230
|
+
positive++;
|
|
231
|
+
}
|
|
232
|
+
let path$1 = "";
|
|
233
|
+
for (let i = 1; i < pointer; i++) path$1 += "/" + pieces[i];
|
|
234
|
+
if (!path$1 || addTrailingSlash && !path$1.endsWith("/..")) path$1 += "/";
|
|
235
|
+
url.path = path$1;
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* Attempts to resolve `input` URL/path relative to `base`.
|
|
239
|
+
*/
|
|
240
|
+
function resolve$2(input, base) {
|
|
241
|
+
if (!input && !base) return "";
|
|
242
|
+
const url = parseUrl(input);
|
|
243
|
+
let inputType = url.type;
|
|
244
|
+
if (base && inputType !== 7) {
|
|
245
|
+
const baseUrl = parseUrl(base);
|
|
246
|
+
const baseType = baseUrl.type;
|
|
247
|
+
switch (inputType) {
|
|
248
|
+
case 1: url.hash = baseUrl.hash;
|
|
249
|
+
case 2: url.query = baseUrl.query;
|
|
250
|
+
case 3:
|
|
251
|
+
case 4: mergePaths(url, baseUrl);
|
|
252
|
+
case 5:
|
|
253
|
+
url.user = baseUrl.user;
|
|
254
|
+
url.host = baseUrl.host;
|
|
255
|
+
url.port = baseUrl.port;
|
|
256
|
+
case 6: url.scheme = baseUrl.scheme;
|
|
257
|
+
}
|
|
258
|
+
if (baseType > inputType) inputType = baseType;
|
|
259
|
+
}
|
|
260
|
+
normalizePath(url, inputType);
|
|
261
|
+
const queryHash = url.query + url.hash;
|
|
262
|
+
switch (inputType) {
|
|
263
|
+
case 2:
|
|
264
|
+
case 3: return queryHash;
|
|
265
|
+
case 4: {
|
|
266
|
+
const path$1 = url.path.slice(1);
|
|
267
|
+
if (!path$1) return queryHash || ".";
|
|
268
|
+
if (isRelative(base || input) && !isRelative(path$1)) return "./" + path$1 + queryHash;
|
|
269
|
+
return path$1 + queryHash;
|
|
270
|
+
}
|
|
271
|
+
case 5: return url.path + queryHash;
|
|
272
|
+
default: return url.scheme + "//" + url.user + url.host + url.port + url.path + queryHash;
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
//#endregion
|
|
277
|
+
//#region node_modules/.pnpm/@jridgewell+trace-mapping@0.3.31/node_modules/@jridgewell/trace-mapping/dist/trace-mapping.mjs
|
|
278
|
+
function stripFilename(path$1) {
|
|
279
|
+
if (!path$1) return "";
|
|
280
|
+
const index = path$1.lastIndexOf("/");
|
|
281
|
+
return path$1.slice(0, index + 1);
|
|
282
|
+
}
|
|
283
|
+
function resolver(mapUrl, sourceRoot) {
|
|
284
|
+
const from = stripFilename(mapUrl);
|
|
285
|
+
const prefix = sourceRoot ? sourceRoot + "/" : "";
|
|
286
|
+
return (source) => resolve$2(prefix + (source || ""), from);
|
|
287
|
+
}
|
|
288
|
+
var COLUMN = 0;
|
|
289
|
+
var SOURCES_INDEX = 1;
|
|
290
|
+
var SOURCE_LINE = 2;
|
|
291
|
+
var SOURCE_COLUMN = 3;
|
|
292
|
+
var NAMES_INDEX = 4;
|
|
293
|
+
function maybeSort(mappings, owned) {
|
|
294
|
+
const unsortedIndex = nextUnsortedSegmentLine(mappings, 0);
|
|
295
|
+
if (unsortedIndex === mappings.length) return mappings;
|
|
296
|
+
if (!owned) mappings = mappings.slice();
|
|
297
|
+
for (let i = unsortedIndex; i < mappings.length; i = nextUnsortedSegmentLine(mappings, i + 1)) mappings[i] = sortSegments(mappings[i], owned);
|
|
298
|
+
return mappings;
|
|
299
|
+
}
|
|
300
|
+
function nextUnsortedSegmentLine(mappings, start) {
|
|
301
|
+
for (let i = start; i < mappings.length; i++) if (!isSorted(mappings[i])) return i;
|
|
302
|
+
return mappings.length;
|
|
303
|
+
}
|
|
304
|
+
function isSorted(line) {
|
|
305
|
+
for (let j = 1; j < line.length; j++) if (line[j][COLUMN] < line[j - 1][COLUMN]) return false;
|
|
306
|
+
return true;
|
|
307
|
+
}
|
|
308
|
+
function sortSegments(line, owned) {
|
|
309
|
+
if (!owned) line = line.slice();
|
|
310
|
+
return line.sort(sortComparator);
|
|
311
|
+
}
|
|
312
|
+
function sortComparator(a, b) {
|
|
313
|
+
return a[COLUMN] - b[COLUMN];
|
|
314
|
+
}
|
|
315
|
+
var found = false;
|
|
316
|
+
function binarySearch(haystack, needle, low, high) {
|
|
317
|
+
while (low <= high) {
|
|
318
|
+
const mid = low + (high - low >> 1);
|
|
319
|
+
const cmp = haystack[mid][COLUMN] - needle;
|
|
320
|
+
if (cmp === 0) {
|
|
321
|
+
found = true;
|
|
322
|
+
return mid;
|
|
323
|
+
}
|
|
324
|
+
if (cmp < 0) low = mid + 1;
|
|
325
|
+
else high = mid - 1;
|
|
326
|
+
}
|
|
327
|
+
found = false;
|
|
328
|
+
return low - 1;
|
|
329
|
+
}
|
|
330
|
+
function upperBound(haystack, needle, index) {
|
|
331
|
+
for (let i = index + 1; i < haystack.length; index = i++) if (haystack[i][COLUMN] !== needle) break;
|
|
332
|
+
return index;
|
|
333
|
+
}
|
|
334
|
+
function lowerBound(haystack, needle, index) {
|
|
335
|
+
for (let i = index - 1; i >= 0; index = i--) if (haystack[i][COLUMN] !== needle) break;
|
|
336
|
+
return index;
|
|
337
|
+
}
|
|
338
|
+
function memoizedState() {
|
|
339
|
+
return {
|
|
340
|
+
lastKey: -1,
|
|
341
|
+
lastNeedle: -1,
|
|
342
|
+
lastIndex: -1
|
|
343
|
+
};
|
|
344
|
+
}
|
|
345
|
+
function memoizedBinarySearch(haystack, needle, state, key) {
|
|
346
|
+
const { lastKey, lastNeedle, lastIndex } = state;
|
|
347
|
+
let low = 0;
|
|
348
|
+
let high = haystack.length - 1;
|
|
349
|
+
if (key === lastKey) {
|
|
350
|
+
if (needle === lastNeedle) {
|
|
351
|
+
found = lastIndex !== -1 && haystack[lastIndex][COLUMN] === needle;
|
|
352
|
+
return lastIndex;
|
|
353
|
+
}
|
|
354
|
+
if (needle >= lastNeedle) low = lastIndex === -1 ? 0 : lastIndex;
|
|
355
|
+
else high = lastIndex;
|
|
356
|
+
}
|
|
357
|
+
state.lastKey = key;
|
|
358
|
+
state.lastNeedle = needle;
|
|
359
|
+
return state.lastIndex = binarySearch(haystack, needle, low, high);
|
|
360
|
+
}
|
|
361
|
+
function parse(map) {
|
|
362
|
+
return typeof map === "string" ? JSON.parse(map) : map;
|
|
363
|
+
}
|
|
364
|
+
var LINE_GTR_ZERO = "`line` must be greater than 0 (lines start at line 1)";
|
|
365
|
+
var COL_GTR_EQ_ZERO = "`column` must be greater than or equal to 0 (columns start at column 0)";
|
|
366
|
+
var LEAST_UPPER_BOUND = -1;
|
|
367
|
+
var GREATEST_LOWER_BOUND = 1;
|
|
368
|
+
var TraceMap = class {
|
|
369
|
+
constructor(map, mapUrl) {
|
|
370
|
+
const isString = typeof map === "string";
|
|
371
|
+
if (!isString && map._decodedMemo) return map;
|
|
372
|
+
const parsed = parse(map);
|
|
373
|
+
const { version, file, names, sourceRoot, sources, sourcesContent } = parsed;
|
|
374
|
+
this.version = version;
|
|
375
|
+
this.file = file;
|
|
376
|
+
this.names = names || [];
|
|
377
|
+
this.sourceRoot = sourceRoot;
|
|
378
|
+
this.sources = sources;
|
|
379
|
+
this.sourcesContent = sourcesContent;
|
|
380
|
+
this.ignoreList = parsed.ignoreList || parsed.x_google_ignoreList || void 0;
|
|
381
|
+
const resolve$3 = resolver(mapUrl, sourceRoot);
|
|
382
|
+
this.resolvedSources = sources.map(resolve$3);
|
|
383
|
+
const { mappings } = parsed;
|
|
384
|
+
if (typeof mappings === "string") {
|
|
385
|
+
this._encoded = mappings;
|
|
386
|
+
this._decoded = void 0;
|
|
387
|
+
} else if (Array.isArray(mappings)) {
|
|
388
|
+
this._encoded = void 0;
|
|
389
|
+
this._decoded = maybeSort(mappings, isString);
|
|
390
|
+
} else if (parsed.sections) throw new Error(`TraceMap passed sectioned source map, please use FlattenMap export instead`);
|
|
391
|
+
else throw new Error(`invalid source map: ${JSON.stringify(parsed)}`);
|
|
392
|
+
this._decodedMemo = memoizedState();
|
|
393
|
+
this._bySources = void 0;
|
|
394
|
+
this._bySourceMemos = void 0;
|
|
395
|
+
}
|
|
396
|
+
};
|
|
397
|
+
function cast(map) {
|
|
398
|
+
return map;
|
|
399
|
+
}
|
|
400
|
+
function decodedMappings(map) {
|
|
401
|
+
var _a;
|
|
402
|
+
return (_a = cast(map))._decoded || (_a._decoded = decode(cast(map)._encoded));
|
|
403
|
+
}
|
|
404
|
+
function originalPositionFor(map, needle) {
|
|
405
|
+
let { line, column, bias } = needle;
|
|
406
|
+
line--;
|
|
407
|
+
if (line < 0) throw new Error(LINE_GTR_ZERO);
|
|
408
|
+
if (column < 0) throw new Error(COL_GTR_EQ_ZERO);
|
|
409
|
+
const decoded = decodedMappings(map);
|
|
410
|
+
if (line >= decoded.length) return OMapping(null, null, null, null);
|
|
411
|
+
const segments = decoded[line];
|
|
412
|
+
const index = traceSegmentInternal(segments, cast(map)._decodedMemo, line, column, bias || GREATEST_LOWER_BOUND);
|
|
413
|
+
if (index === -1) return OMapping(null, null, null, null);
|
|
414
|
+
const segment = segments[index];
|
|
415
|
+
if (segment.length === 1) return OMapping(null, null, null, null);
|
|
416
|
+
const { names, resolvedSources } = map;
|
|
417
|
+
return OMapping(resolvedSources[segment[SOURCES_INDEX]], segment[SOURCE_LINE] + 1, segment[SOURCE_COLUMN], segment.length === 5 ? names[segment[NAMES_INDEX]] : null);
|
|
418
|
+
}
|
|
419
|
+
function OMapping(source, line, column, name) {
|
|
420
|
+
return {
|
|
421
|
+
source,
|
|
422
|
+
line,
|
|
423
|
+
column,
|
|
424
|
+
name
|
|
425
|
+
};
|
|
426
|
+
}
|
|
427
|
+
function traceSegmentInternal(segments, memo, line, column, bias) {
|
|
428
|
+
let index = memoizedBinarySearch(segments, column, memo, line);
|
|
429
|
+
if (found) index = (bias === LEAST_UPPER_BOUND ? upperBound : lowerBound)(segments, column, index);
|
|
430
|
+
else if (bias === LEAST_UPPER_BOUND) index++;
|
|
431
|
+
if (index === -1 || index === segments.length) return -1;
|
|
432
|
+
return index;
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
//#endregion
|
|
436
|
+
//#region src/source-map-handler.ts
|
|
437
|
+
let errorFormatterInstalled = false;
|
|
438
|
+
const fileContentsCache = {};
|
|
439
|
+
const sourceMapCache = {};
|
|
440
|
+
const reSourceMap = /^data:application\/json[^,]+base64,/;
|
|
441
|
+
let retrieveFileHandlers = [];
|
|
442
|
+
let retrieveMapHandlers = [];
|
|
443
|
+
function globalProcessVersion() {
|
|
444
|
+
if (typeof process === "object" && process !== null) return process.version;
|
|
445
|
+
else return "";
|
|
446
|
+
}
|
|
447
|
+
function handlerExec(list) {
|
|
448
|
+
return function(arg) {
|
|
449
|
+
for (let i = 0; i < list.length; i++) {
|
|
450
|
+
const ret = list[i](arg);
|
|
451
|
+
if (ret) return ret;
|
|
452
|
+
}
|
|
453
|
+
return null;
|
|
454
|
+
};
|
|
455
|
+
}
|
|
456
|
+
let retrieveFile = handlerExec(retrieveFileHandlers);
|
|
457
|
+
retrieveFileHandlers.push((path$1) => {
|
|
458
|
+
path$1 = path$1.trim();
|
|
459
|
+
if (path$1.startsWith("file:")) path$1 = path$1.replace(/file:\/\/\/(\w:)?/, (protocol, drive) => {
|
|
460
|
+
return drive ? "" : "/";
|
|
461
|
+
});
|
|
462
|
+
if (path$1 in fileContentsCache) return fileContentsCache[path$1];
|
|
463
|
+
let contents = "";
|
|
464
|
+
try {
|
|
465
|
+
if (fs.existsSync(path$1)) contents = fs.readFileSync(path$1, "utf8");
|
|
466
|
+
} catch {}
|
|
467
|
+
return fileContentsCache[path$1] = contents;
|
|
468
|
+
});
|
|
469
|
+
function supportRelativeURL(file, url) {
|
|
470
|
+
if (!file) return url;
|
|
471
|
+
const dir = path.dirname(file);
|
|
472
|
+
const match = /^\w+:\/\/[^/]*/.exec(dir);
|
|
473
|
+
let protocol = match ? match[0] : "";
|
|
474
|
+
const startPath = dir.slice(protocol.length);
|
|
475
|
+
if (protocol && /^\/\w:/.test(startPath)) {
|
|
476
|
+
protocol += "/";
|
|
477
|
+
return protocol + path.resolve(dir.slice(protocol.length), url).replace(/\\/g, "/");
|
|
478
|
+
}
|
|
479
|
+
return protocol + path.resolve(dir.slice(protocol.length), url);
|
|
480
|
+
}
|
|
481
|
+
function retrieveSourceMapURL(source) {
|
|
482
|
+
const fileData = retrieveFile(source);
|
|
483
|
+
if (!fileData) return null;
|
|
484
|
+
const re = /\/\/[@#]\s*sourceMappingURL=([^\s'"]+)\s*$|\/\*[@#]\s*sourceMappingURL=[^\s*'"]+\s*\*\/\s*$/gm;
|
|
485
|
+
let lastMatch, match;
|
|
486
|
+
while (match = re.exec(fileData)) lastMatch = match;
|
|
487
|
+
if (!lastMatch) return null;
|
|
488
|
+
return lastMatch[1];
|
|
489
|
+
}
|
|
490
|
+
let retrieveSourceMap = handlerExec(retrieveMapHandlers);
|
|
491
|
+
retrieveMapHandlers.push((source) => {
|
|
492
|
+
let sourceMappingURL = retrieveSourceMapURL(source);
|
|
493
|
+
if (!sourceMappingURL) return null;
|
|
494
|
+
let sourceMapData;
|
|
495
|
+
if (reSourceMap.test(sourceMappingURL)) {
|
|
496
|
+
const rawData = sourceMappingURL.slice(sourceMappingURL.indexOf(",") + 1);
|
|
497
|
+
sourceMapData = Buffer$1.from(rawData, "base64").toString();
|
|
498
|
+
sourceMappingURL = source;
|
|
499
|
+
} else {
|
|
500
|
+
sourceMappingURL = supportRelativeURL(source, sourceMappingURL);
|
|
501
|
+
sourceMapData = retrieveFile(sourceMappingURL);
|
|
502
|
+
}
|
|
503
|
+
if (!sourceMapData) return null;
|
|
504
|
+
return {
|
|
505
|
+
url: sourceMappingURL,
|
|
506
|
+
map: sourceMapData
|
|
507
|
+
};
|
|
508
|
+
});
|
|
509
|
+
function mapSourcePosition(position) {
|
|
510
|
+
if (!position.source) return position;
|
|
511
|
+
let sourceMap = sourceMapCache[position.source];
|
|
512
|
+
if (!sourceMap) {
|
|
513
|
+
const urlAndMap = retrieveSourceMap(position.source);
|
|
514
|
+
const map = urlAndMap && urlAndMap.map;
|
|
515
|
+
if (map && !(typeof map === "object" && "mappings" in map && map.mappings === "")) {
|
|
516
|
+
sourceMap = sourceMapCache[position.source] = {
|
|
517
|
+
url: urlAndMap.url,
|
|
518
|
+
map: new TraceMap(map)
|
|
519
|
+
};
|
|
520
|
+
if (sourceMap.map?.sourcesContent) sourceMap.map.sources.forEach((source, i) => {
|
|
521
|
+
const contents = sourceMap.map?.sourcesContent?.[i];
|
|
522
|
+
if (contents && source && sourceMap.url) {
|
|
523
|
+
const url = supportRelativeURL(sourceMap.url, source);
|
|
524
|
+
fileContentsCache[url] = contents;
|
|
525
|
+
}
|
|
526
|
+
});
|
|
527
|
+
} else sourceMap = sourceMapCache[position.source] = {
|
|
528
|
+
url: null,
|
|
529
|
+
map: null
|
|
530
|
+
};
|
|
531
|
+
}
|
|
532
|
+
if (sourceMap && sourceMap.map && sourceMap.url) {
|
|
533
|
+
const originalPosition = originalPositionFor(sourceMap.map, position);
|
|
534
|
+
if (originalPosition.source !== null) {
|
|
535
|
+
originalPosition.source = supportRelativeURL(sourceMap.url, originalPosition.source);
|
|
536
|
+
return originalPosition;
|
|
537
|
+
}
|
|
538
|
+
}
|
|
539
|
+
return position;
|
|
540
|
+
}
|
|
541
|
+
function mapEvalOrigin(origin) {
|
|
542
|
+
let match = /^eval at ([^(]+) \((.+):(\d+):(\d+)\)$/.exec(origin);
|
|
543
|
+
if (match) {
|
|
544
|
+
const position = mapSourcePosition({
|
|
545
|
+
name: null,
|
|
546
|
+
source: match[2],
|
|
547
|
+
line: +match[3],
|
|
548
|
+
column: +match[4] - 1
|
|
549
|
+
});
|
|
550
|
+
return `eval at ${match[1]} (${position.source}:${position.line}:${position.column + 1})`;
|
|
551
|
+
}
|
|
552
|
+
match = /^eval at ([^(]+) \((.+)\)$/.exec(origin);
|
|
553
|
+
if (match) return `eval at ${match[1]} (${mapEvalOrigin(match[2])})`;
|
|
554
|
+
return origin;
|
|
555
|
+
}
|
|
556
|
+
function CallSiteToString() {
|
|
557
|
+
let fileName;
|
|
558
|
+
let fileLocation = "";
|
|
559
|
+
if (this.isNative()) fileLocation = "native";
|
|
560
|
+
else {
|
|
561
|
+
fileName = this.getScriptNameOrSourceURL();
|
|
562
|
+
if (!fileName && this.isEval()) {
|
|
563
|
+
fileLocation = this.getEvalOrigin();
|
|
564
|
+
fileLocation += ", ";
|
|
565
|
+
}
|
|
566
|
+
if (fileName) fileLocation += fileName;
|
|
567
|
+
else fileLocation += "<anonymous>";
|
|
568
|
+
const lineNumber = this.getLineNumber();
|
|
569
|
+
if (lineNumber != null) {
|
|
570
|
+
fileLocation += `:${lineNumber}`;
|
|
571
|
+
const columnNumber = this.getColumnNumber();
|
|
572
|
+
if (columnNumber) fileLocation += `:${columnNumber}`;
|
|
573
|
+
}
|
|
574
|
+
}
|
|
575
|
+
let line = "";
|
|
576
|
+
const functionName = this.getFunctionName();
|
|
577
|
+
let addSuffix = true;
|
|
578
|
+
const isConstructor = this.isConstructor();
|
|
579
|
+
if (!(this.isToplevel() || isConstructor)) {
|
|
580
|
+
let typeName = this.getTypeName();
|
|
581
|
+
if (typeName === "[object Object]") typeName = "null";
|
|
582
|
+
const methodName = this.getMethodName();
|
|
583
|
+
if (functionName) {
|
|
584
|
+
if (typeName && functionName.indexOf(typeName) !== 0) line += `${typeName}.`;
|
|
585
|
+
line += functionName;
|
|
586
|
+
if (methodName && functionName.indexOf(`.${methodName}`) !== functionName.length - methodName.length - 1) line += ` [as ${methodName}]`;
|
|
587
|
+
} else line += `${typeName}.${methodName || "<anonymous>"}`;
|
|
588
|
+
} else if (isConstructor) line += `new ${functionName || "<anonymous>"}`;
|
|
589
|
+
else if (functionName) line += functionName;
|
|
590
|
+
else {
|
|
591
|
+
line += fileLocation;
|
|
592
|
+
addSuffix = false;
|
|
593
|
+
}
|
|
594
|
+
if (addSuffix) line += ` (${fileLocation})`;
|
|
595
|
+
return line;
|
|
596
|
+
}
|
|
597
|
+
function cloneCallSite(frame) {
|
|
598
|
+
const object = {};
|
|
599
|
+
Object.getOwnPropertyNames(Object.getPrototypeOf(frame)).forEach((name) => {
|
|
600
|
+
const key = name;
|
|
601
|
+
object[key] = /^(?:is|get)/.test(name) ? function() {
|
|
602
|
+
return frame[key].call(frame);
|
|
603
|
+
} : frame[key];
|
|
604
|
+
});
|
|
605
|
+
object.toString = CallSiteToString;
|
|
606
|
+
return object;
|
|
607
|
+
}
|
|
608
|
+
function wrapCallSite(frame, state) {
|
|
609
|
+
if (state === void 0) state = {
|
|
610
|
+
nextPosition: null,
|
|
611
|
+
curPosition: null
|
|
612
|
+
};
|
|
613
|
+
if (frame.isNative()) {
|
|
614
|
+
state.curPosition = null;
|
|
615
|
+
return frame;
|
|
616
|
+
}
|
|
617
|
+
const source = frame.getFileName() || frame.getScriptNameOrSourceURL();
|
|
618
|
+
if (source) {
|
|
619
|
+
const line = frame.getLineNumber();
|
|
620
|
+
let column = frame.getColumnNumber() - 1;
|
|
621
|
+
const headerLength = /^v(?:10\.1[6-9]|10\.[2-9]\d|10\.\d{3,}|1[2-9]\d*|[2-9]\d|\d{3,}|11\.11)/.test(globalProcessVersion()) ? 0 : 62;
|
|
622
|
+
if (line === 1 && column > headerLength && !frame.isEval()) column -= headerLength;
|
|
623
|
+
const position = mapSourcePosition({
|
|
624
|
+
name: null,
|
|
625
|
+
source,
|
|
626
|
+
line,
|
|
627
|
+
column
|
|
628
|
+
});
|
|
629
|
+
state.curPosition = position;
|
|
630
|
+
frame = cloneCallSite(frame);
|
|
631
|
+
const originalFunctionName = frame.getFunctionName;
|
|
632
|
+
frame.getFunctionName = function() {
|
|
633
|
+
if (state.nextPosition == null) return originalFunctionName();
|
|
634
|
+
return state.nextPosition.name || originalFunctionName();
|
|
635
|
+
};
|
|
636
|
+
frame.getFileName = function() {
|
|
637
|
+
return position.source ?? null;
|
|
638
|
+
};
|
|
639
|
+
frame.getLineNumber = function() {
|
|
640
|
+
return position.line;
|
|
641
|
+
};
|
|
642
|
+
frame.getColumnNumber = function() {
|
|
643
|
+
return position.column + 1;
|
|
644
|
+
};
|
|
645
|
+
frame.getScriptNameOrSourceURL = function() {
|
|
646
|
+
return position.source;
|
|
647
|
+
};
|
|
648
|
+
return frame;
|
|
649
|
+
}
|
|
650
|
+
let origin = frame.isEval() && frame.getEvalOrigin();
|
|
651
|
+
if (origin) {
|
|
652
|
+
origin = mapEvalOrigin(origin);
|
|
653
|
+
frame = cloneCallSite(frame);
|
|
654
|
+
frame.getEvalOrigin = function() {
|
|
655
|
+
return origin || void 0;
|
|
656
|
+
};
|
|
657
|
+
return frame;
|
|
658
|
+
}
|
|
659
|
+
return frame;
|
|
660
|
+
}
|
|
661
|
+
function prepareStackTrace(error, stack) {
|
|
662
|
+
const errorString = `${error.name || "Error"}: ${error.message || ""}`;
|
|
663
|
+
const state = {
|
|
664
|
+
nextPosition: null,
|
|
665
|
+
curPosition: null
|
|
666
|
+
};
|
|
667
|
+
const processedStack = [];
|
|
668
|
+
for (let i = stack.length - 1; i >= 0; i--) {
|
|
669
|
+
processedStack.push(`\n at ${wrapCallSite(stack[i], state)}`);
|
|
670
|
+
state.nextPosition = state.curPosition;
|
|
671
|
+
}
|
|
672
|
+
state.curPosition = state.nextPosition = null;
|
|
673
|
+
return errorString + processedStack.reverse().join("");
|
|
674
|
+
}
|
|
675
|
+
const originalRetrieveFileHandlers = retrieveFileHandlers.slice(0);
|
|
676
|
+
const originalRetrieveMapHandlers = retrieveMapHandlers.slice(0);
|
|
677
|
+
function install(options) {
|
|
678
|
+
options = options || {};
|
|
679
|
+
if (options.retrieveFile) {
|
|
680
|
+
if (options.overrideRetrieveFile) retrieveFileHandlers.length = 0;
|
|
681
|
+
retrieveFileHandlers.unshift(options.retrieveFile);
|
|
682
|
+
}
|
|
683
|
+
if (options.retrieveSourceMap) {
|
|
684
|
+
if (options.overrideRetrieveSourceMap) retrieveMapHandlers.length = 0;
|
|
685
|
+
retrieveMapHandlers.unshift(options.retrieveSourceMap);
|
|
686
|
+
}
|
|
687
|
+
if (!errorFormatterInstalled) {
|
|
688
|
+
errorFormatterInstalled = true;
|
|
689
|
+
Error.prepareStackTrace = prepareStackTrace;
|
|
690
|
+
}
|
|
691
|
+
}
|
|
692
|
+
|
|
693
|
+
//#endregion
|
|
694
|
+
//#region src/source-map.ts
|
|
695
|
+
let SOURCEMAPPING_URL = "sourceMa";
|
|
696
|
+
SOURCEMAPPING_URL += "ppingURL";
|
|
697
|
+
const VITE_NODE_SOURCEMAPPING_SOURCE = "//# sourceMappingSource=vite-node";
|
|
698
|
+
const VITE_NODE_SOURCEMAPPING_URL = `${SOURCEMAPPING_URL}=data:application/json;charset=utf-8`;
|
|
699
|
+
function withInlineSourcemap(result, options) {
|
|
700
|
+
const map = result.map;
|
|
701
|
+
let code = result.code;
|
|
702
|
+
if (!map || code.includes(VITE_NODE_SOURCEMAPPING_SOURCE)) return result;
|
|
703
|
+
if ("sources" in map) map.sources = map.sources?.map((source) => {
|
|
704
|
+
if (!source) return source;
|
|
705
|
+
if (isAbsolute(source)) {
|
|
706
|
+
const actualPath = !source.startsWith(withTrailingSlash(options.root)) && source.startsWith("/") ? resolve(options.root, source.slice(1)) : source;
|
|
707
|
+
return relative(dirname(options.filepath), actualPath);
|
|
708
|
+
}
|
|
709
|
+
return source;
|
|
710
|
+
});
|
|
711
|
+
const OTHER_SOURCE_MAP_REGEXP = new RegExp(`//# ${SOURCEMAPPING_URL}=data:application/json[^,]+base64,([A-Za-z0-9+/=]+)$`, "gm");
|
|
712
|
+
while (OTHER_SOURCE_MAP_REGEXP.test(code)) code = code.replace(OTHER_SOURCE_MAP_REGEXP, "");
|
|
713
|
+
if (!options.noFirstLineMapping && map.mappings.startsWith(";")) map.mappings = `AAAA,CAAA${map.mappings}`;
|
|
714
|
+
const sourceMap = Buffer$1.from(JSON.stringify(map), "utf-8").toString("base64");
|
|
715
|
+
result.code = `${code.trimEnd()}\n\n${VITE_NODE_SOURCEMAPPING_SOURCE}\n//# ${VITE_NODE_SOURCEMAPPING_URL};base64,${sourceMap}\n`;
|
|
716
|
+
return result;
|
|
717
|
+
}
|
|
718
|
+
function extractSourceMap(code) {
|
|
719
|
+
const regexp = new RegExp(`//# ${VITE_NODE_SOURCEMAPPING_URL};base64,(.+)`, "gm");
|
|
720
|
+
let lastMatch, match;
|
|
721
|
+
while (match = regexp.exec(code)) lastMatch = match;
|
|
722
|
+
if (lastMatch) return JSON.parse(Buffer$1.from(lastMatch[1], "base64").toString("utf-8"));
|
|
723
|
+
return null;
|
|
724
|
+
}
|
|
725
|
+
function installSourcemapsSupport(options) {
|
|
726
|
+
install({ retrieveSourceMap(source) {
|
|
727
|
+
const map = options.getSourceMap(source);
|
|
728
|
+
if (map) return {
|
|
729
|
+
url: source,
|
|
730
|
+
map
|
|
731
|
+
};
|
|
732
|
+
return null;
|
|
733
|
+
} });
|
|
734
|
+
}
|
|
735
|
+
|
|
736
|
+
//#endregion
|
|
737
|
+
export { installSourcemapsSupport as n, withInlineSourcemap as r, extractSourceMap as t };
|