vite-node 4.0.0-beta.10 → 4.0.0-beta.12

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.
@@ -7,106 +7,103 @@ var utils = require('./utils.cjs');
7
7
  require('node:module');
8
8
  require('node:url');
9
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
10
+ // src/vlq.ts
11
+ var comma = ",".charCodeAt(0);
12
+ var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
13
+ var intToChar = new Uint8Array(64);
14
+ var charToInt = new Uint8Array(128);
14
15
  for (let i = 0; i < chars.length; i++) {
15
- const c = chars.charCodeAt(i);
16
- intToChar[i] = c;
17
- charToInt[c] = i;
16
+ const c = chars.charCodeAt(i);
17
+ intToChar[i] = c;
18
+ charToInt[c] = i;
18
19
  }
19
20
  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;
21
+ let value = 0;
22
+ let shift = 0;
23
+ let integer = 0;
24
+ do {
25
+ const c = reader.next();
26
+ integer = charToInt[c];
27
+ value |= (integer & 31) << shift;
28
+ shift += 5;
29
+ } while (integer & 32);
30
+ const shouldNegate = value & 1;
31
+ value >>>= 1;
32
+ if (shouldNegate) {
33
+ value = -2147483648 | -value;
34
+ }
35
+ return relative + value;
35
36
  }
36
37
  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
- }
38
+ if (reader.pos >= max) return false;
39
+ return reader.peek() !== comma;
57
40
  }
41
+ var StringReader = class {
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
58
 
59
+ // src/sourcemap-codec.ts
59
60
  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++;
61
+ const { length } = mappings;
62
+ const reader = new StringReader(mappings);
63
+ const decoded = [];
64
+ let genColumn = 0;
65
+ let sourcesIndex = 0;
66
+ let sourceLine = 0;
67
+ let sourceColumn = 0;
68
+ let namesIndex = 0;
69
+ do {
70
+ const semi = reader.indexOf(";");
71
+ const line = [];
72
+ let sorted = true;
73
+ let lastCol = 0;
74
+ genColumn = 0;
75
+ while (reader.pos < semi) {
76
+ let seg;
77
+ genColumn = decodeInteger(reader, genColumn);
78
+ if (genColumn < lastCol) 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
+ } else {
88
+ seg = [genColumn, sourcesIndex, sourceLine, sourceColumn];
97
89
  }
98
- if (!sorted)
99
- sort(line);
100
- decoded.push(line);
101
- reader.pos = semi + 1;
102
- } while (reader.pos <= length);
103
- return decoded;
90
+ } else {
91
+ seg = [genColumn];
92
+ }
93
+ line.push(seg);
94
+ reader.pos++;
95
+ }
96
+ if (!sorted) sort(line);
97
+ decoded.push(line);
98
+ reader.pos = semi + 1;
99
+ } while (reader.pos <= length);
100
+ return decoded;
104
101
  }
105
102
  function sort(line) {
106
- line.sort(sortComparator$1);
103
+ line.sort(sortComparator$1);
107
104
  }
108
105
  function sortComparator$1(a, b) {
109
- return a[0] - b[0];
106
+ return a[0] - b[0];
110
107
  }
111
108
 
112
109
  // Matches the scheme of a URL, eg "http://"
@@ -132,16 +129,6 @@ const urlRegex = /^([\w+.-]+:)\/\/([^@/#?]*@)?([^:/#?]*)(:\d+)?(\/[^#?]*)?(\?[^#
132
129
  * 4. Hash, including "#", optional.
133
130
  */
134
131
  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
132
  function isAbsoluteUrl(input) {
146
133
  return schemeRegex.test(input);
147
134
  }
@@ -175,21 +162,21 @@ function makeUrl(scheme, user, host, port, path, query, hash) {
175
162
  path,
176
163
  query,
177
164
  hash,
178
- type: UrlType.Absolute,
165
+ type: 7 /* Absolute */,
179
166
  };
180
167
  }
181
168
  function parseUrl(input) {
182
169
  if (isSchemeRelativeUrl(input)) {
183
170
  const url = parseAbsoluteUrl('http:' + input);
184
171
  url.scheme = '';
185
- url.type = UrlType.SchemeRelative;
172
+ url.type = 6 /* SchemeRelative */;
186
173
  return url;
187
174
  }
188
175
  if (isAbsolutePath(input)) {
189
176
  const url = parseAbsoluteUrl('http://foo.com' + input);
190
177
  url.scheme = '';
191
178
  url.host = '';
192
- url.type = UrlType.AbsolutePath;
179
+ url.type = 5 /* AbsolutePath */;
193
180
  return url;
194
181
  }
195
182
  if (isFileUrl(input))
@@ -201,11 +188,11 @@ function parseUrl(input) {
201
188
  url.host = '';
202
189
  url.type = input
203
190
  ? input.startsWith('?')
204
- ? UrlType.Query
191
+ ? 3 /* Query */
205
192
  : input.startsWith('#')
206
- ? UrlType.Hash
207
- : UrlType.RelativePath
208
- : UrlType.Empty;
193
+ ? 2 /* Hash */
194
+ : 4 /* RelativePath */
195
+ : 1 /* Empty */;
209
196
  return url;
210
197
  }
211
198
  function stripPathFilename(path) {
@@ -233,7 +220,7 @@ function mergePaths(url, base) {
233
220
  * "foo/.". We need to normalize to a standard representation.
234
221
  */
235
222
  function normalizePath(url, type) {
236
- const rel = type <= UrlType.RelativePath;
223
+ const rel = type <= 4 /* RelativePath */;
237
224
  const pieces = url.path.split('/');
238
225
  // We need to preserve the first piece always, so that we output a leading slash. The item at
239
226
  // pieces[0] is an empty string.
@@ -294,27 +281,27 @@ function resolve(input, base) {
294
281
  return '';
295
282
  const url = parseUrl(input);
296
283
  let inputType = url.type;
297
- if (base && inputType !== UrlType.Absolute) {
284
+ if (base && inputType !== 7 /* Absolute */) {
298
285
  const baseUrl = parseUrl(base);
299
286
  const baseType = baseUrl.type;
300
287
  switch (inputType) {
301
- case UrlType.Empty:
288
+ case 1 /* Empty */:
302
289
  url.hash = baseUrl.hash;
303
290
  // fall through
304
- case UrlType.Hash:
291
+ case 2 /* Hash */:
305
292
  url.query = baseUrl.query;
306
293
  // fall through
307
- case UrlType.Query:
308
- case UrlType.RelativePath:
294
+ case 3 /* Query */:
295
+ case 4 /* RelativePath */:
309
296
  mergePaths(url, baseUrl);
310
297
  // fall through
311
- case UrlType.AbsolutePath:
298
+ case 5 /* AbsolutePath */:
312
299
  // The host, user, and port are joined, you can't copy one without the others.
313
300
  url.user = baseUrl.user;
314
301
  url.host = baseUrl.host;
315
302
  url.port = baseUrl.port;
316
303
  // fall through
317
- case UrlType.SchemeRelative:
304
+ case 6 /* SchemeRelative */:
318
305
  // The input doesn't have a schema at least, so we need to copy at least that over.
319
306
  url.scheme = baseUrl.scheme;
320
307
  }
@@ -326,10 +313,10 @@ function resolve(input, base) {
326
313
  switch (inputType) {
327
314
  // This is impossible, because of the empty checks at the start of the function.
328
315
  // case UrlType.Empty:
329
- case UrlType.Hash:
330
- case UrlType.Query:
316
+ case 2 /* Hash */:
317
+ case 3 /* Query */:
331
318
  return queryHash;
332
- case UrlType.RelativePath: {
319
+ case 4 /* RelativePath */: {
333
320
  // The first char is always a "/", and we need it to be relative.
334
321
  const path = url.path.slice(1);
335
322
  if (!path)
@@ -342,7 +329,7 @@ function resolve(input, base) {
342
329
  }
343
330
  return path + queryHash;
344
331
  }
345
- case UrlType.AbsolutePath:
332
+ case 5 /* AbsolutePath */:
346
333
  return url.path + queryHash;
347
334
  default:
348
335
  return url.scheme + '//' + url.user + url.host + url.port + url.path + queryHash;
@@ -709,8 +696,8 @@ function CallSiteToString() {
709
696
  let line = "";
710
697
  const functionName = this.getFunctionName();
711
698
  let addSuffix = true;
712
- const isConstructor = this.isConstructor(), isMethodCall = !(this.isToplevel() || isConstructor);
713
- if (isMethodCall) {
699
+ const isConstructor = this.isConstructor();
700
+ if (!(this.isToplevel() || isConstructor)) {
714
701
  let typeName = this.getTypeName();
715
702
  // Fixes shim to be backward compatible with Node v0 to v4
716
703
  if (typeName === "[object Object]") typeName = "null";
@@ -750,12 +737,7 @@ function wrapCallSite(frame, state) {
750
737
  if (source) {
751
738
  const line = frame.getLineNumber();
752
739
  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;
740
+ 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;
759
741
  if (line === 1 && column > headerLength && !frame.isEval()) column -= headerLength;
760
742
  const position = mapSourcePosition({
761
743
  name: null,
@@ -828,7 +810,7 @@ function withInlineSourcemap(result, options) {
828
810
  // this is a bug in Vite
829
811
  // all files should be either absolute to the file system or relative to the source map file
830
812
  if (pathe.isAbsolute(source)) {
831
- const actualPath = !source.startsWith(utils.withTrailingSlash(options.root)) && source.startsWith("/") ? pathe.resolve(options.root, source.slice(1)) : source;
813
+ const actualPath = !source.startsWith(utils.withTrailingSlash(options.root)) && source[0] === "/" ? pathe.resolve(options.root, source.slice(1)) : source;
832
814
  return pathe.relative(pathe.dirname(options.filepath), actualPath);
833
815
  }
834
816
  return source;
@@ -841,7 +823,7 @@ function withInlineSourcemap(result, options) {
841
823
  // so that debuggers can be set to break on first line
842
824
  // Since Vite 6, import statements at the top of the file are preserved correctly,
843
825
  // so we don't need to add this mapping anymore.
844
- if (!options.noFirstLineMapping && map.mappings.startsWith(";")) map.mappings = `AAAA,CAAA${map.mappings}`;
826
+ if (!options.noFirstLineMapping && map.mappings[0] === ";") map.mappings = `AAAA,CAAA${map.mappings}`;
845
827
  const sourceMap = Buffer.from(JSON.stringify(map), "utf-8").toString("base64");
846
828
  return result.code = `${code.trimEnd()}\n\n${VITE_NODE_SOURCEMAPPING_SOURCE}\n//# ${VITE_NODE_SOURCEMAPPING_URL};base64,${sourceMap}\n`, result;
847
829
  }