From c77cf52e1648a2581479bd3187b5a5fa1f918832 Mon Sep 17 00:00:00 2001 From: Matthew Phillips Date: Thu, 30 Dec 2021 09:03:03 -0500 Subject: [PATCH] Don't overwrite the stack when using verbose logging (#2290) * Don't overwrite the stack when using verbose logging This makes it so that if the compiler panics and `--verbose` logging is on (debug level), we don't replace the stack trace. * Adds a changeset --- .changeset/soft-frogs-tap.md | 5 +++++ packages/astro/src/core/create-vite.ts | 2 +- packages/astro/src/vite-plugin-astro/index.ts | 11 ++++++++--- 3 files changed, 14 insertions(+), 4 deletions(-) create mode 100644 .changeset/soft-frogs-tap.md diff --git a/.changeset/soft-frogs-tap.md b/.changeset/soft-frogs-tap.md new file mode 100644 index 0000000000..7f9b58ac9a --- /dev/null +++ b/.changeset/soft-frogs-tap.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +Preserve wasm stack trace when verbose logging is enabled diff --git a/packages/astro/src/core/create-vite.ts b/packages/astro/src/core/create-vite.ts index 9e6dc419ca..80fd870c0a 100644 --- a/packages/astro/src/core/create-vite.ts +++ b/packages/astro/src/core/create-vite.ts @@ -50,7 +50,7 @@ export async function createVite(inlineConfig: ViteConfigWithSSR, { astroConfig, }, plugins: [ configAliasVitePlugin({ config: astroConfig }), - astroVitePlugin({ config: astroConfig, devServer }), + astroVitePlugin({ config: astroConfig, devServer, logging }), markdownVitePlugin({ config: astroConfig, devServer }), jsxVitePlugin({ config: astroConfig, logging }), astroPostprocessVitePlugin({ config: astroConfig, devServer }), diff --git a/packages/astro/src/vite-plugin-astro/index.ts b/packages/astro/src/vite-plugin-astro/index.ts index 8fae5dc3b2..484949823e 100644 --- a/packages/astro/src/vite-plugin-astro/index.ts +++ b/packages/astro/src/vite-plugin-astro/index.ts @@ -1,5 +1,6 @@ import type vite from '../core/vite'; import type { AstroConfig } from '../@types/astro'; +import type { LogOptions } from '../core/logger'; import esbuild from 'esbuild'; import { fileURLToPath } from 'url'; @@ -11,11 +12,12 @@ import { cachedCompilation, invalidateCompilation } from './compile.js'; const FRONTMATTER_PARSE_REGEXP = /^\-\-\-(.*)^\-\-\-/ms; interface AstroPluginOptions { config: AstroConfig; + logging: LogOptions; devServer?: AstroDevServer; } /** Transform .astro files for Vite */ -export default function astro({ config }: AstroPluginOptions): vite.Plugin { +export default function astro({ config, logging }: AstroPluginOptions): vite.Plugin { let viteTransform: TransformHook; return { name: '@astrojs/vite-plugin-astro', @@ -118,8 +120,11 @@ export default function astro({ config }: AstroPluginOptions): vite.Plugin { Please open a GitHub issue using the link below: ${err.url}`; - // TODO: remove stack replacement when compiler throws better errors - err.stack = ` at ${id}`; + + if(logging.level !== 'debug') { + // TODO: remove stack replacement when compiler throws better errors + err.stack = ` at ${id}`; + } } throw err;