fix: wrap loadConfig in try/catch

This commit is contained in:
Nate Moore 2021-12-14 15:30:49 -06:00
parent 9388fd0cdf
commit 4c21b35ea6

View file

@ -126,18 +126,21 @@ export async function loadConfig(options: LoadConfigOptions): Promise<AstroConfi
let userConfig: AstroUserConfig = {}; let userConfig: AstroUserConfig = {};
let userConfigPath: string | undefined; let userConfigPath: string | undefined;
if (options.filename) { if (options.filename) {
userConfigPath = /^\.*\//.test(options.filename) ? options.filename : `./${options.filename}`; userConfigPath = /^\.*\//.test(options.filename) ? options.filename : `./${options.filename}`;
userConfigPath = fileURLToPath(new URL(userConfigPath, `file://${root}/`)); userConfigPath = fileURLToPath(new URL(userConfigPath, `file://${root}/`));
} }
// Automatically load config file using Proload // Automatically load config file using Proload
// If `userConfigPath` is `undefined`, Proload will search for `astro.config.[cm]?[jt]s` // If `userConfigPath` is `undefined`, Proload will search for `astro.config.[cm]?[jt]s`
const config = await load('astro', { mustExist: false, cwd: root, filePath: userConfigPath }); let config;
if (config) { try {
userConfig = config.value; config = await load('astro', { mustExist: false, cwd: root, filePath: userConfigPath });
} } catch (e) {}
// normalize, validate, and return if (config) {
return validateConfig(userConfig, root); userConfig = config.value;
}
// normalize, validate, and return
return validateConfig(userConfig, root);
} }
export function formatConfigError(err: z.ZodError) { export function formatConfigError(err: z.ZodError) {