@visulima/vite-overlay 1.3.5 → 1.3.7

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.
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Patches Vite's client code to replace the default error overlay with our custom overlay.
3
+ */
4
+ export declare const patchOverlay: (code: string, showBalloonButton: boolean) => string;
5
+ export default patchOverlay;
@@ -0,0 +1,94 @@
1
+ import type { ErrorLocation } from "@visulima/error/error";
2
+ import type { Solution } from "@visulima/error/solution";
3
+ export type ErrorLike = Error | {
4
+ message?: string;
5
+ name?: string;
6
+ stack?: string;
7
+ };
8
+ export interface PluginPattern {
9
+ readonly name: string;
10
+ readonly pattern: RegExp;
11
+ }
12
+ export type SupportedExtension = ".js" | ".ts" | ".mjs" | ".cjs" | ".jsx" | ".tsx" | ".vue" | ".svelte";
13
+ export interface StackLocation {
14
+ readonly column?: number;
15
+ readonly file?: string;
16
+ readonly line?: number;
17
+ }
18
+ export interface VisulimaViteOverlayErrorPayload {
19
+ readonly errors: ReadonlyArray<ExtendedError>;
20
+ readonly errorType: "client" | "server";
21
+ readonly rootPath: string;
22
+ readonly solution?: Solution;
23
+ }
24
+ export interface ExtendedError extends ErrorProcessingResult {
25
+ readonly hint?: string;
26
+ readonly message: string;
27
+ readonly name: string;
28
+ readonly stack: string;
29
+ }
30
+ export interface DevelopmentLogger {
31
+ readonly error: (message: unknown) => void;
32
+ readonly log: (message: unknown) => void;
33
+ }
34
+ export interface RecentErrorTracker {
35
+ readonly recentErrors: Map<string, number>;
36
+ readonly shouldSkip: (signature: string) => boolean;
37
+ }
38
+ export interface RawErrorData {
39
+ readonly cause?: {
40
+ readonly cause?: {
41
+ readonly cause?: any;
42
+ readonly message?: string | null;
43
+ readonly name?: string | null;
44
+ readonly stack?: string | null;
45
+ } | null;
46
+ readonly message?: string | null;
47
+ readonly name?: string | null;
48
+ readonly stack?: string | null;
49
+ } | null;
50
+ readonly column?: number | null;
51
+ readonly file?: string | null;
52
+ readonly line?: number | null;
53
+ readonly message: string;
54
+ readonly name?: string;
55
+ readonly ownerStack?: string | null;
56
+ readonly plugin?: string;
57
+ readonly stack: string;
58
+ }
59
+ export interface VueErrorInfo {
60
+ readonly column: number;
61
+ readonly line: number;
62
+ readonly message?: string;
63
+ readonly originalFilePath: string;
64
+ }
65
+ export type ViteErrorData = ErrorLocation & {
66
+ plugin?: string;
67
+ };
68
+ export interface ResolvedLocation {
69
+ readonly originalFileColumn: number;
70
+ readonly originalFileLine: number;
71
+ readonly originalFilePath: string;
72
+ }
73
+ export interface SourceTexts {
74
+ readonly compiledSourceText?: string;
75
+ readonly originalSourceText?: string;
76
+ }
77
+ export interface ErrorProcessingResult {
78
+ readonly compiledCodeFrameContent?: string;
79
+ readonly compiledColumn?: number;
80
+ readonly compiledFilePath?: string;
81
+ readonly compiledLine?: number;
82
+ readonly compiledStack?: string;
83
+ readonly errorCount?: number;
84
+ readonly fixPrompt: string;
85
+ readonly message?: string;
86
+ readonly originalCodeFrameContent?: string;
87
+ readonly originalFileColumn: number;
88
+ readonly originalFileLine: number;
89
+ readonly originalFilePath: string;
90
+ readonly originalSnippet: string;
91
+ readonly originalStack?: string;
92
+ readonly plugin?: string;
93
+ }
94
+ export type StackFrameValidator = (line: string) => boolean;
@@ -0,0 +1,13 @@
1
+ import type { SolutionFinder } from "@visulima/error/solution";
2
+ /**
3
+ * Creates a solution finder specifically designed for Vite-related errors.
4
+ * Provides intelligent suggestions for common Vite import resolution and configuration issues.
5
+ * @param rootPath The root path of the project
6
+ * @returns A solution finder object for Vite-specific error handling
7
+ */
8
+ declare const createViteSolutionFinder: (rootPath: string) => SolutionFinder;
9
+ /**
10
+ * Default export for creating Vite solution finders.
11
+ * @see createViteSolutionFinder
12
+ */
13
+ export default createViteSolutionFinder;
@@ -0,0 +1,21 @@
1
+ import type { ViteDevServer } from "vite";
2
+ import type { ErrorProcessingResult, ViteErrorData } from "../../types.d.ts";
3
+ /**
4
+ * Builds comprehensive error data including source maps, code frames, and AI prompts.
5
+ * This function processes runtime errors and extracts all information needed for
6
+ * the error overlay UI, including original source locations and syntax-highlighted code.
7
+ * Handles both single errors and AggregateError (multiple errors).
8
+ * @param error The error object to process (can be AggregateError with multiple errors)
9
+ * @param server The Vite dev server instance for module resolution
10
+ * @returns Promise resolving to extended error data object
11
+ */
12
+ declare const buildExtendedErrorData: (error: Error, server: ViteDevServer, errorIndex?: number, framework?: string, viteErrorData?: ViteErrorData, allErrors?: (Error | {
13
+ message: string;
14
+ name?: string;
15
+ stack?: string;
16
+ })[]) => Promise<ErrorProcessingResult>;
17
+ /**
18
+ * Default export for building extended error data with source maps and code frames.
19
+ * @see buildExtendedErrorData
20
+ */
21
+ export default buildExtendedErrorData;
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Parses Vue SFC compilation error messages to extract file, line, and column information.
3
+ * @param errorMessage The Vue compilation error message to parse
4
+ * @returns Object containing parsed error information or null if not a Vue error
5
+ */
6
+ declare const parseVueCompilationError: (errorMessage: string) => {
7
+ column: number;
8
+ line: number;
9
+ message: string;
10
+ originalFilePath: string;
11
+ } | undefined;
12
+ export default parseVueCompilationError;
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Processes React hydration diff content to extract and format relevant differences.
3
+ * @param error The raw error object containing hydration diff
4
+ * @returns Formatted diff content with markers and limited context
5
+ */
6
+ declare const processHydrationDiff: (error: Error) => string | undefined;
7
+ export default processHydrationDiff;
@@ -0,0 +1,18 @@
1
+ import type { ViteDevServer } from "vite";
2
+ /**
3
+ * Remaps a stack trace from compiled locations to original source locations using source maps.
4
+ * Handles React-specific stack frames and module resolution for better debugging experience.
5
+ * @param server The Vite dev server instance
6
+ * @param stack The stack trace string to remap
7
+ * @param header Optional header information for the formatted stack trace
8
+ * @returns Promise resolving to the remapped stack trace
9
+ */
10
+ declare const remapStackToOriginal: (server: ViteDevServer, stack: string, header?: {
11
+ message?: string;
12
+ name?: string;
13
+ }) => Promise<string>;
14
+ /**
15
+ * Default export for remapping stack traces to original source locations.
16
+ * @see remapStackToOriginal
17
+ */
18
+ export default remapStackToOriginal;
@@ -0,0 +1,8 @@
1
+ import type { ViteDevServer } from "vite";
2
+ import type { SourceTexts } from "../../types.d.ts";
3
+ /**
4
+ * Retrieves original and compiled source texts from various sources.
5
+ * Attempts multiple strategies to find source code for error context.
6
+ */
7
+ declare const retrieveSourceTexts: (server: ViteDevServer, module_: unknown, filePath: string, idCandidates: ReadonlyArray<string>) => Promise<SourceTexts>;
8
+ export default retrieveSourceTexts;
@@ -0,0 +1,8 @@
1
+ import type { ShikiTransformer } from "shiki/types";
2
+ type Options = {
3
+ classActivePre?: string;
4
+ classLineAdd?: string;
5
+ classLineRemove?: string;
6
+ };
7
+ declare const shikiDiffTransformer: (options?: Options) => ShikiTransformer;
8
+ export default shikiDiffTransformer;
@@ -0,0 +1,2 @@
1
+ declare const addQueryToUrl: (baseUrl: string, query: string) => string;
2
+ export default addQueryToUrl;
@@ -0,0 +1,2 @@
1
+ declare const extractQueryFromHttpUrl: (url: string) => string;
2
+ export default extractQueryFromHttpUrl;
@@ -0,0 +1,29 @@
1
+ export interface ESBuildMessage extends Error {
2
+ location?: {
3
+ column?: number;
4
+ file?: string;
5
+ line?: number;
6
+ };
7
+ pluginName?: string;
8
+ text: string;
9
+ }
10
+ /**
11
+ * Checks if an array contains ESBuild error objects.
12
+ * @param errors Array of potential ESBuild errors
13
+ * @returns True if the array contains ESBuild errors
14
+ */
15
+ export declare const isESBuildErrorArray: (errors: any[]) => boolean;
16
+ /**
17
+ * Processes ESBuild error messages into a standardized format.
18
+ * @param esbuildErrors Array of ESBuild error messages
19
+ * @returns Array of processed error objects with standardized structure
20
+ */
21
+ export declare const processESBuildErrors: (esbuildErrors: ESBuildMessage[]) => {
22
+ column?: number;
23
+ file?: string;
24
+ line?: number;
25
+ message: string;
26
+ name: string;
27
+ plugin?: string;
28
+ stack: string;
29
+ }[];
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Finds the location of an error message within source code by analyzing error patterns.
3
+ * @param sourceCode The source code to search in
4
+ * @param errorMessage The error message to locate
5
+ * @param occurrenceIndex The index of occurrence to find (default: 0)
6
+ * @returns The line and column location of the error, or null if not found
7
+ */
8
+ declare const findErrorInSourceCode: (sourceCode: string, errorMessage: string, occurrenceIndex?: number) => {
9
+ column: number;
10
+ line: number;
11
+ } | null;
12
+ export default findErrorInSourceCode;
@@ -0,0 +1,9 @@
1
+ import type { ModuleNode, ViteDevServer } from "vite";
2
+ /**
3
+ * Finds a module in Vite's module graph using various strategies and candidate paths.
4
+ * @param server The Vite dev server instance
5
+ * @param candidates Array of candidate file paths to search for
6
+ * @returns The matching module node or undefined if not found
7
+ */
8
+ declare const findModuleForPath: (server: ViteDevServer, candidates: string[]) => ModuleNode | undefined;
9
+ export default findModuleForPath;
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Generates the client-side script for error interception and reporting.
3
+ * @param mode The current Vite mode (development/production)
4
+ * @param forwardedConsoleMethods Array of console method names to forward
5
+ * @returns The client-side JavaScript code as a string
6
+ */
7
+ declare const generateClientScript: (mode: string, forwardedConsoleMethods: string[]) => string;
8
+ export default generateClientScript;
@@ -0,0 +1,6 @@
1
+ interface SourceMap {
2
+ sources?: string[];
3
+ sourcesContent?: (string | null)[];
4
+ }
5
+ declare const getSourceFromMap: (map: SourceMap, wantedSource: string | undefined) => string | undefined;
6
+ export default getSourceFromMap;
@@ -0,0 +1,2 @@
1
+ export declare const isHttpUrl: (value: string) => boolean;
2
+ export declare const normalizeIdCandidates: (filePath: string) => string[];
@@ -0,0 +1,6 @@
1
+ interface Position {
2
+ column: number;
3
+ line: number;
4
+ }
5
+ declare const realignOriginalPosition: (compiledSource: string, compiledLine: number, compiledColumn: number, originalSource: string) => Position | null;
6
+ export default realignOriginalPosition;
@@ -0,0 +1,29 @@
1
+ import type { ViteDevServer } from "vite";
2
+ interface ResolvedLocation {
3
+ originalFileColumn: number;
4
+ originalFileLine: number;
5
+ originalFilePath: string;
6
+ }
7
+ interface ViteModule {
8
+ id?: string | null;
9
+ transformResult?: {
10
+ code?: string;
11
+ map?: any;
12
+ } | null;
13
+ url?: string;
14
+ }
15
+ /**
16
+ * Resolves the original source location from a compiled location using source maps.
17
+ * Uses Vite's built-in source map resolution for consistency with browser behavior.
18
+ * Falls back to source code search for error messages when source maps are unreliable.
19
+ * @param server The Vite dev server instance
20
+ * @param module_ The Vite module containing transform result
21
+ * @param filePath The original file path
22
+ * @param fileLine The line number in the compiled source
23
+ * @param fileColumn The column number in the compiled source
24
+ * @param errorMessage Optional error message to search for in source code
25
+ * @param errorIndex Index of this error in a cause chain (0-based)
26
+ * @returns Object with resolved filePath, fileLine, and fileColumn
27
+ */
28
+ declare const resolveOriginalLocation: (server: ViteDevServer, module_: ViteModule, filePath: string, fileLine: number, fileColumn: number, errorMessage?: string, errorIndex?: number) => Promise<ResolvedLocation>;
29
+ export default resolveOriginalLocation;
@@ -0,0 +1,8 @@
1
+ import type { ViteDevServer } from "vite";
2
+ /**
3
+ * Enhances SSR errors with better stack traces and contextual hints.
4
+ * - Fixes stack traces via Vite's SSR helper
5
+ * - Detects common SSR failure patterns and enriches message/loc
6
+ */
7
+ declare const enhanceViteSsrError: (rawError: unknown, server: ViteDevServer) => Promise<Error>;
8
+ export default enhanceViteSsrError;
@@ -0,0 +1,38 @@
1
+ import type { StackFrameValidator } from "../types.d.ts";
2
+ /**
3
+ * Validates if a stack trace line represents a valid stack frame.
4
+ * @param line The stack trace line to validate
5
+ * @returns True if the line is a valid stack frame
6
+ */
7
+ export declare const isValidStackFrame: StackFrameValidator;
8
+ /**
9
+ * Cleans an error stack trace by normalizing line endings and filtering invalid stack frames.
10
+ * @param stack The raw stack trace string
11
+ * @returns The cleaned stack trace
12
+ */
13
+ export declare const cleanErrorStack: (stack: string) => string;
14
+ /**
15
+ * Cleans an error message by removing VT control characters.
16
+ * @param error The error object or error message string
17
+ * @returns The cleaned error message
18
+ */
19
+ export declare const cleanErrorMessage: (error: Error | string) => string;
20
+ /**
21
+ * Checks if an error is an AggregateError (contains multiple errors).
22
+ * @param error The error to check
23
+ * @returns True if the error is an AggregateError
24
+ */
25
+ export declare const isAggregateError: (error: any) => error is AggregateError;
26
+ /**
27
+ * Extracts individual errors from an AggregateError or returns the error as-is.
28
+ * @param error The error to process
29
+ * @returns Array of individual errors
30
+ */
31
+ export declare const extractErrors: (error: any) => Error[];
32
+ /**
33
+ * Converts HTTP URLs in stack traces to absolute filesystem paths
34
+ * @param stack Raw stack trace with HTTP URLs
35
+ * @param rootPath Root directory for path resolution
36
+ * @returns Stack trace with absolute paths
37
+ */
38
+ export declare const absolutizeStackUrls: (stack: string, rootPath: string) => string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@visulima/vite-overlay",
3
- "version": "1.3.5",
3
+ "version": "1.3.7",
4
4
  "description": "Improved vite overlay",
5
5
  "keywords": [
6
6
  "vite",
@@ -57,12 +57,12 @@
57
57
  ],
58
58
  "dependencies": {
59
59
  "@jridgewell/trace-mapping": "^0.3.31",
60
- "@shikijs/cli": "3.14.0",
61
- "@shikijs/langs": "3.14.0",
62
- "@shikijs/themes": "3.14.0",
63
- "@visulima/error": "5.0.4",
60
+ "@shikijs/cli": "3.15.0",
61
+ "@shikijs/langs": "3.15.0",
62
+ "@shikijs/themes": "3.15.0",
63
+ "@visulima/error": "5.0.6",
64
64
  "fastest-levenshtein": "^1.0.16",
65
- "shiki": "3.14.0"
65
+ "shiki": "3.15.0"
66
66
  },
67
67
  "peerDependencies": {
68
68
  "vite": "^6 || ^7 || ^8"