diff --git a/packages/astro/e2e/error-cyclic.test.js b/packages/astro/e2e/error-cyclic.test.js index ef17a32d3..98c3f19d5 100644 --- a/packages/astro/e2e/error-cyclic.test.js +++ b/packages/astro/e2e/error-cyclic.test.js @@ -3,7 +3,7 @@ import { testFactory, getErrorOverlayContent } from './test-utils.js'; const test = testFactory({ experimentalErrorOverlay: true, - root: './fixtures/error-cyclic/' + root: './fixtures/error-cyclic/', }); let devServer; diff --git a/packages/astro/e2e/error-react-spectrum.test.js b/packages/astro/e2e/error-react-spectrum.test.js index 618859ac1..eacaaadc2 100644 --- a/packages/astro/e2e/error-react-spectrum.test.js +++ b/packages/astro/e2e/error-react-spectrum.test.js @@ -3,7 +3,7 @@ import { testFactory, getErrorOverlayContent } from './test-utils.js'; const test = testFactory({ experimentalErrorOverlay: true, - root: './fixtures/error-react-spectrum/' + root: './fixtures/error-react-spectrum/', }); let devServer; diff --git a/packages/astro/e2e/error-sass.test.js b/packages/astro/e2e/error-sass.test.js index 2eeab13df..5fbd10976 100644 --- a/packages/astro/e2e/error-sass.test.js +++ b/packages/astro/e2e/error-sass.test.js @@ -3,7 +3,7 @@ import { testFactory, getErrorOverlayContent } from './test-utils.js'; const test = testFactory({ experimentalErrorOverlay: true, - root: './fixtures/error-sass/' + root: './fixtures/error-sass/', }); let devServer; diff --git a/packages/astro/e2e/errors.test.js b/packages/astro/e2e/errors.test.js index 34f3c59ad..ba43851b0 100644 --- a/packages/astro/e2e/errors.test.js +++ b/packages/astro/e2e/errors.test.js @@ -3,7 +3,7 @@ import { getErrorOverlayContent, testFactory } from './test-utils.js'; const test = testFactory({ experimentalErrorOverlay: true, - root: './fixtures/errors/' + root: './fixtures/errors/', }); let devServer; diff --git a/packages/astro/src/core/config/config.ts b/packages/astro/src/core/config/config.ts index 864a13eaf..797b3f1ff 100644 --- a/packages/astro/src/core/config/config.ts +++ b/packages/astro/src/core/config/config.ts @@ -100,7 +100,10 @@ export function resolveFlags(flags: Partial): CLIFlags { host: typeof flags.host === 'string' || typeof flags.host === 'boolean' ? flags.host : undefined, drafts: typeof flags.drafts === 'boolean' ? flags.drafts : undefined, - experimentalErrorOverlay: typeof flags.experimentalErrorOverlay === 'boolean' ? flags.experimentalErrorOverlay : undefined, + experimentalErrorOverlay: + typeof flags.experimentalErrorOverlay === 'boolean' + ? flags.experimentalErrorOverlay + : undefined, }; } diff --git a/packages/astro/src/core/config/schema.ts b/packages/astro/src/core/config/schema.ts index 78a0ed60c..33ef28aa4 100644 --- a/packages/astro/src/core/config/schema.ts +++ b/packages/astro/src/core/config/schema.ts @@ -3,13 +3,13 @@ import type * as Postcss from 'postcss'; import type { ILanguageRegistration, IThemeRegistration, Theme } from 'shiki'; import type { AstroUserConfig, ViteUserConfig } from '../../@types/astro'; +import { OutgoingHttpHeaders } from 'http'; import postcssrc from 'postcss-load-config'; import { BUNDLED_THEMES } from 'shiki'; import { fileURLToPath } from 'url'; import { z } from 'zod'; import { appendForwardSlash, prependForwardSlash, trimSlashes } from '../path.js'; import { isObject } from '../util.js'; -import { OutgoingHttpHeaders } from 'http'; const ASTRO_CONFIG_DEFAULTS: AstroUserConfig & any = { root: '.', diff --git a/packages/astro/src/core/errors/dev/utils.ts b/packages/astro/src/core/errors/dev/utils.ts index 9843f3b0f..3d11e58bb 100644 --- a/packages/astro/src/core/errors/dev/utils.ts +++ b/packages/astro/src/core/errors/dev/utils.ts @@ -1,15 +1,14 @@ +import { escape } from 'html-escaper'; +import { bold, underline } from 'kleur/colors'; import * as fs from 'node:fs'; import { isAbsolute, join } from 'node:path'; import { fileURLToPath } from 'node:url'; import stripAnsi from 'strip-ansi'; -import { escape } from 'html-escaper'; -import type { BuildResult } from 'esbuild'; import type { ESBuildTransformResult } from 'vite'; import type { SSRError } from '../../../@types/astro.js'; import { AggregateError, ErrorWithMetadata } from '../errors.js'; import { codeFrame } from '../printer.js'; import { normalizeLF } from '../utils.js'; -import { bold, underline } from 'kleur/colors'; type EsbuildMessage = ESBuildTransformResult['warnings'][number]; diff --git a/packages/astro/src/core/errors/overlay.ts b/packages/astro/src/core/errors/overlay.ts index 159a095f4..431657292 100644 --- a/packages/astro/src/core/errors/overlay.ts +++ b/packages/astro/src/core/errors/overlay.ts @@ -561,25 +561,25 @@ function getOverlayCode() { } export function patchOverlay(code: string, config: AstroConfig) { - if(config.experimentalErrorOverlay) { + if (config.experimentalErrorOverlay) { return code.replace('class ErrorOverlay', getOverlayCode() + '\nclass ViteErrorOverlay'); } else { // Legacy overlay return ( code - // Transform links in the message to clickable links - .replace( - "this.text('.message-body', message.trim());", - `const urlPattern = /(\\b(https?|ftp):\\/\\/[-A-Z0-9+&@#\\/%?=~_|!:,.;]*[-A-Z0-9+&@#\\/%=~_|])/gim; + // Transform links in the message to clickable links + .replace( + "this.text('.message-body', message.trim());", + `const urlPattern = /(\\b(https?|ftp):\\/\\/[-A-Z0-9+&@#\\/%?=~_|!:,.;]*[-A-Z0-9+&@#\\/%=~_|])/gim; function escapeHtml(unsafe){return unsafe.replace(//g, ">");} const escapedMessage = escapeHtml(message); this.root.querySelector(".message-body").innerHTML = escapedMessage.trim().replace(urlPattern, '$1');` - ) - .replace('', '.message-body a {\n color: #ededed;\n}\n') - // Hide `.tip` in Vite's ErrorOverlay - .replace(/\.tip \{[^}]*\}/gm, '.tip {\n display: none;\n}') - // Replace [vite] messages with [astro] - .replace(/\[vite\]/g, '[astro]') - ) + ) + .replace('', '.message-body a {\n color: #ededed;\n}\n') + // Hide `.tip` in Vite's ErrorOverlay + .replace(/\.tip \{[^}]*\}/gm, '.tip {\n display: none;\n}') + // Replace [vite] messages with [astro] + .replace(/\[vite\]/g, '[astro]') + ); } } diff --git a/packages/astro/src/vite-plugin-astro-server/plugin.ts b/packages/astro/src/vite-plugin-astro-server/plugin.ts index a880bf36f..9fd2a1645 100644 --- a/packages/astro/src/vite-plugin-astro-server/plugin.ts +++ b/packages/astro/src/vite-plugin-astro-server/plugin.ts @@ -2,6 +2,7 @@ import type * as vite from 'vite'; import type { AstroSettings, ManifestData } from '../@types/astro'; import type fs from 'fs'; +import { patchOverlay } from '../core/errors/overlay.js'; import { LogOptions } from '../core/logger/core.js'; import { createViteLoader } from '../core/module-loader/index.js'; import { createDevelopmentEnvironment } from '../core/render/dev/index.js'; @@ -9,7 +10,6 @@ import { createRouteManifest } from '../core/routing/index.js'; import { baseMiddleware } from './base.js'; import { createController } from './controller.js'; import { handleRequest } from './request.js'; -import { patchOverlay } from '../core/errors/overlay.js'; export interface AstroPluginOptions { settings: AstroSettings;