chore: hand mjs
highlighting in error overlay
This commit is contained in:
parent
ad56cd95c8
commit
8c348503fc
1 changed files with 7 additions and 1 deletions
|
@ -150,9 +150,15 @@ export async function getViteErrorPayload(err: ErrorWithMetadata): Promise<Astro
|
||||||
: undefined;
|
: undefined;
|
||||||
|
|
||||||
const highlighter = await getHighlighter({ theme: 'css-variables' });
|
const highlighter = await getHighlighter({ theme: 'css-variables' });
|
||||||
|
let highlighterLang = err.loc?.file?.split('.').pop();
|
||||||
|
if (['cjs', 'mjs'].includes(highlighterLang ?? '')) {
|
||||||
|
// Shiki does not support `mjs` or `cjs` aliases by default.
|
||||||
|
// Map these to `js` instead.
|
||||||
|
highlighterLang = 'js';
|
||||||
|
}
|
||||||
const highlightedCode = err.fullCode
|
const highlightedCode = err.fullCode
|
||||||
? highlighter.codeToHtml(err.fullCode, {
|
? highlighter.codeToHtml(err.fullCode, {
|
||||||
lang: err.loc?.file?.split('.').pop(),
|
lang: highlighterLang,
|
||||||
lineOptions: err.loc?.line ? [{ line: err.loc.line, classes: ['error-line'] }] : undefined,
|
lineOptions: err.loc?.line ? [{ line: err.loc.line, classes: ['error-line'] }] : undefined,
|
||||||
})
|
})
|
||||||
: undefined;
|
: undefined;
|
||||||
|
|
Loading…
Reference in a new issue