From 435d5256789f1bf02b6d69ad4290c7e206cb0c42 Mon Sep 17 00:00:00 2001 From: Joshua Date: Sun, 25 Jun 2023 02:25:50 -0700 Subject: [PATCH] fix: Fix `ts-import` strategy. --- src/lib/configuration/loader.ts | 8 ++++---- src/lib/configuration/strategies/esbuild.ts | 5 +++++ src/lib/configuration/strategies/ts-import.ts | 7 +++++-- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/lib/configuration/loader.ts b/src/lib/configuration/loader.ts index 2900591..ebd1483 100644 --- a/src/lib/configuration/loader.ts +++ b/src/lib/configuration/loader.ts @@ -104,8 +104,8 @@ export default async function configurationLoader(filePath: string, content: str errors.push(err); } - - if (errors.length > 0) { - throw new AggregateError(errors, 'All parsing strategies failed.'); - } + if (errors.length > 0) throw new AggregateError( + errors, + 'All parsing strategies failed.' + ); } diff --git a/src/lib/configuration/strategies/esbuild.ts b/src/lib/configuration/strategies/esbuild.ts index 4523803..83e4a5f 100644 --- a/src/lib/configuration/strategies/esbuild.ts +++ b/src/lib/configuration/strategies/esbuild.ts @@ -64,6 +64,11 @@ export async function esbuildStrategy(filePath: string, pkgInfo: PackageInfo) { const result = await import(tempFilePath); return result?.default ?? result; + } catch (cause: any) { + throw new Error( + `${log.prefix('esbuildStrategy')} Failed to load configuration file: ${cause}`, + { cause } + ); } finally { if (await fs.exists(tempFilePath)) { await fs.remove(tempFilePath); diff --git a/src/lib/configuration/strategies/ts-import.ts b/src/lib/configuration/strategies/ts-import.ts index eb5caea..82c9ac1 100644 --- a/src/lib/configuration/strategies/ts-import.ts +++ b/src/lib/configuration/strategies/ts-import.ts @@ -24,8 +24,11 @@ export async function tsImportStrategy(filePath: string) { }); return result?.default || result; - } catch (err: any) { - log.error(log.prefix('ts-import'), 'Error removing cache directory:', err); + } catch (cause: any) { + throw new Error( + `${log.prefix('tsImportStrategy')} Failed to load configuration file: ${cause}`, + { cause } + ); } finally { if (await fs.exists(cacheDir)) await fs.remove(cacheDir); }