vite 8.3.1 → 8.3.3

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.
@@ -253,6 +253,64 @@ const createWebSocketModuleRunnerTransport = (options) => {
253
253
  };
254
254
  };
255
255
  //#endregion
256
+ //#region src/shared/pretty-format.ts
257
+ const DEFAULT_OPTIONS = {
258
+ maxDepth: 3,
259
+ maxWidth: 100
260
+ };
261
+ const objectToString = Object.prototype.toString;
262
+ const errorToString = Error.prototype.toString;
263
+ const identifierRE = /^[a-z_$][\w$]*$/i;
264
+ function prettyFormat(value, options = {}) {
265
+ return printer(value, {
266
+ ...DEFAULT_OPTIONS,
267
+ ...options
268
+ }, 0, []);
269
+ }
270
+ function printer(value, config, depth, refs) {
271
+ return printBasicValue(value) ?? printComplexValue(value, config, depth, refs);
272
+ }
273
+ function printBasicValue(value) {
274
+ if (value == null) return String(value);
275
+ if (typeof value === "string") return JSON.stringify(value);
276
+ if (typeof value === "number") return Object.is(value, -0) ? "-0" : String(value);
277
+ if (typeof value === "bigint") return `${value}n`;
278
+ if (typeof value === "boolean" || typeof value === "symbol") return String(value);
279
+ if (typeof value === "function") return value.name ? `[Function: ${value.name}]` : "[Function]";
280
+ const type = objectToString.call(value);
281
+ if (type === "[object Date]") return Number.isNaN(+value) ? "Date { NaN }" : value.toISOString();
282
+ if (type === "[object Error]" || value instanceof Error) return `[${errorToString.call(value)}]`;
283
+ }
284
+ function printComplexValue(value, config, depth, refs) {
285
+ if (refs.includes(value)) return "[Circular]";
286
+ refs = [...refs, value];
287
+ const hitMaxDepth = ++depth > config.maxDepth;
288
+ if (Array.isArray(value)) return hitMaxDepth ? "[Array]" : `[${printListItems(value, config, depth, refs)}]`;
289
+ return hitMaxDepth ? "[Object]" : `{${printObjectProperties(value, config, depth, refs)}}`;
290
+ }
291
+ function printListItems(value, config, depth, refs) {
292
+ const width = Math.min(value.length, config.maxWidth);
293
+ const result = [];
294
+ for (let i = 0; i < width; i++) result.push(i in value ? printer(value[i], config, depth, refs) : "");
295
+ if (width < value.length) result.push(`…(${value.length - width})`);
296
+ return withSpacing(result);
297
+ }
298
+ function printObjectProperties(value, config, depth, refs) {
299
+ const keys = Object.keys(value);
300
+ const width = Math.min(keys.length, config.maxWidth);
301
+ const result = [];
302
+ for (let i = 0; i < width; i++) {
303
+ const key = keys[i];
304
+ const name = key !== "__proto__" && identifierRE.test(key) ? key : JSON.stringify(key);
305
+ result.push(`${name}: ${printer(value[key], config, depth, refs)}`);
306
+ }
307
+ if (width < keys.length) result.push(`…(${keys.length - width})`);
308
+ return withSpacing(result);
309
+ }
310
+ function withSpacing(values) {
311
+ return values.length === 0 ? "" : ` ${values.join(", ")} `;
312
+ }
313
+ //#endregion
256
314
  //#region src/shared/forwardConsole.ts
257
315
  function setupForwardConsoleHandler(transport, options, console = globalThis.console) {
258
316
  if (!options.enabled) return;
@@ -279,7 +337,7 @@ function setupForwardConsoleHandler(transport, options, console = globalThis.con
279
337
  type: "log",
280
338
  data: {
281
339
  level,
282
- message: formatConsoleArgs(args)
340
+ message: truncateConsoleMessage(formatConsoleArgs(args))
283
341
  }
284
342
  }
285
343
  });
@@ -356,32 +414,25 @@ function formatConsoleArgs(args) {
356
414
  }
357
415
  function stringifyConsoleArg(value) {
358
416
  if (typeof value === "string") return value;
359
- if (typeof value === "number" || typeof value === "boolean" || typeof value === "undefined") return String(value);
360
- if (typeof value === "symbol") return value.toString();
361
- if (typeof value === "function") return value.name ? `[Function: ${value.name}]` : "[Function]";
362
417
  if (value instanceof Error) return value.stack || `${value.name}: ${value.message}`;
363
- if (typeof value === "bigint") return `${value}n`;
364
- const seen = /* @__PURE__ */ new WeakSet();
365
418
  try {
366
- return JSON.stringify(value, (_, nested) => {
367
- if (typeof nested === "bigint") return `${nested}n`;
368
- if (nested instanceof Error) return {
369
- name: nested.name,
370
- message: nested.message,
371
- stack: nested.stack
372
- };
373
- if (nested && typeof nested === "object") {
374
- if (seen.has(nested)) return "[Circular]";
375
- seen.add(nested);
376
- }
377
- return nested;
378
- }) ?? String(value);
419
+ return prettyFormat(value);
379
420
  } catch {
380
421
  return String(value);
381
422
  }
382
423
  }
424
+ const MAX_CONSOLE_MESSAGE_LENGTH = 1e4;
425
+ function truncateConsoleMessage(message) {
426
+ if (message.length <= MAX_CONSOLE_MESSAGE_LENGTH) return message;
427
+ let end = 9999;
428
+ if (isHighSurrogate(message[end - 1])) end--;
429
+ return `${message.slice(0, end)}…`;
430
+ }
431
+ function isHighSurrogate(value) {
432
+ return value >= "\ud800" && value <= "\udbff";
433
+ }
383
434
  //#endregion
384
- //#region \0@oxc-project+runtime@0.150.0/helpers/esm/typeof.js
435
+ //#region \0@oxc-project+runtime@0.151.0/helpers/esm/typeof.js
385
436
  function _typeof(o) {
386
437
  "@babel/helpers - typeof";
387
438
  return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
@@ -391,7 +442,7 @@ function _typeof(o) {
391
442
  }, _typeof(o);
392
443
  }
393
444
  //#endregion
394
- //#region \0@oxc-project+runtime@0.150.0/helpers/esm/toPrimitive.js
445
+ //#region \0@oxc-project+runtime@0.151.0/helpers/esm/toPrimitive.js
395
446
  function toPrimitive(t, r) {
396
447
  if ("object" != _typeof(t) || !t) return t;
397
448
  var e = t[Symbol.toPrimitive];
@@ -403,13 +454,13 @@ function toPrimitive(t, r) {
403
454
  return ("string" === r ? String : Number)(t);
404
455
  }
405
456
  //#endregion
406
- //#region \0@oxc-project+runtime@0.150.0/helpers/esm/toPropertyKey.js
457
+ //#region \0@oxc-project+runtime@0.151.0/helpers/esm/toPropertyKey.js
407
458
  function toPropertyKey(t) {
408
459
  var i = toPrimitive(t, "string");
409
460
  return "symbol" == _typeof(i) ? i : i + "";
410
461
  }
411
462
  //#endregion
412
- //#region \0@oxc-project+runtime@0.150.0/helpers/esm/defineProperty.js
463
+ //#region \0@oxc-project+runtime@0.151.0/helpers/esm/defineProperty.js
413
464
  function _defineProperty(e, r, t) {
414
465
  return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
415
466
  value: t,