From 470ce3d3f3272639288cb888dc89d37f041df104 Mon Sep 17 00:00:00 2001 From: Evan You Date: Mon, 13 Mar 2023 14:32:22 +0800 Subject: [PATCH] fix: gracefully handle config update with syntax error close #2041 --- src/node/config.ts | 2 +- src/node/plugin.ts | 13 +++++++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/node/config.ts b/src/node/config.ts index 22183404..613c3697 100644 --- a/src/node/config.ts +++ b/src/node/config.ts @@ -296,7 +296,7 @@ export async function resolveConfig( const supportedConfigExtensions = ['js', 'ts', 'cjs', 'mjs', 'cts', 'mts'] -async function resolveUserConfig( +export async function resolveUserConfig( root: string, command: 'serve' | 'build', mode: string diff --git a/src/node/plugin.ts b/src/node/plugin.ts index 50f7f218..0d05c021 100644 --- a/src/node/plugin.ts +++ b/src/node/plugin.ts @@ -15,7 +15,7 @@ import { SITE_DATA_REQUEST_PATH, resolveAliases } from './alias' -import { resolvePages, type SiteConfig } from './config' +import { resolveUserConfig, resolvePages, type SiteConfig } from './config' import { clearCache, createMarkdownToVueRenderFn } from './markdownToVue' import type { PageDataPayload } from './shared' import { staticDataPlugin } from './plugins/staticDataPlugin' @@ -316,14 +316,15 @@ export async function createVitePressPlugin( ), { clear: true, timestamp: true } ) + try { - clearCache() - await recreateServer?.() + await resolveUserConfig(siteConfig.root, 'serve', 'development') } catch (err: any) { - siteConfig.logger.error( - `\n${c.red(`failed to restart server. error:`)}\n${err.stack}` - ) + return } + + clearCache() + await recreateServer?.() return }