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
This commit is contained in:
Matthew Phillips 2021-12-30 09:03:03 -05:00 committed by GitHub
parent ae5255dd25
commit c77cf52e16
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 4 deletions

View file

@ -0,0 +1,5 @@
---
'astro': patch
---
Preserve wasm stack trace when verbose logging is enabled

View file

@ -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 }),

View file

@ -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,9 +120,12 @@ export default function astro({ config }: AstroPluginOptions): vite.Plugin {
Please open
a GitHub issue using the link below:
${err.url}`;
if(logging.level !== 'debug') {
// TODO: remove stack replacement when compiler throws better errors
err.stack = ` at ${id}`;
}
}
throw err;
}