@@ -4,7 +4,7 @@ import type { SourceLoader, StackFrame } from 'youch-core/types'
44import { readFile } from 'node:fs/promises'
55import process from 'node:process'
66
7- import { dirname , resolve } from 'pathe'
7+ import { dirname , normalize , resolve } from 'pathe'
88import { SourceMapConsumer } from 'source-map'
99import { Youch } from 'youch'
1010import { ErrorParser } from 'youch-core'
@@ -59,7 +59,17 @@ export async function renderError(req: IncomingMessage, res: ServerResponse, err
5959export async function renderErrorAnsi ( error : unknown ) : Promise < string > {
6060 await loadStackTrace ( error ) . catch ( err => debug ( 'Failed to load stack trace:' , err ) )
6161 const ansi = await new Youch ( ) . toANSI ( error )
62- return ansi . replaceAll ( process . cwd ( ) , '.' )
62+ return stripCwd ( ansi )
63+ }
64+
65+ /**
66+ * Replace the working directory in rendered output with `.`.
67+ *
68+ * Frame filenames are normalised to forward slashes, so on Windows the native
69+ * `process.cwd()` spelling never matches and both forms have to be stripped.
70+ */
71+ export function stripCwd ( text : string , cwd = process . cwd ( ) ) : string {
72+ return text . replaceAll ( cwd , '.' ) . replaceAll ( normalize ( cwd ) , '.' )
6373}
6474
6575const sourceLoader : SourceLoader = async ( frame ) => {
0 commit comments