-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: show more error messages while evaluation (#47)
* chore: fix example config * feat: show more error messages while evaluation
- Loading branch information
Showing
12 changed files
with
181 additions
and
106 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
packages/core/src/vite/hooks/transform/stages/3.evaluate-module/loadModule.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import type { LoadModuleReturn } from "./types"; | ||
|
||
export async function loadModule<T extends { specifier: string }>( | ||
loaders: ((a: T) => Promise<LoadModuleReturn>)[], | ||
args: T, | ||
): Promise<LoadModuleReturn> { | ||
const tailLoader = loaders.pop(); | ||
if (!tailLoader) { | ||
throw new Error("Loaders are empty."); | ||
} | ||
const errors: Error[] = []; | ||
for (const loader of loaders) { | ||
const result = await loader(args); | ||
if (result.module) { | ||
return result; | ||
} | ||
errors.push(result.error); | ||
} | ||
const result = await tailLoader(args); | ||
if (result.module) { | ||
return result; | ||
} | ||
errors.push(result.error); | ||
const errorMsg = `\ | ||
Failed to load "${args.specifier}". | ||
Captured errors while loading: | ||
------ | ||
${errors.map((e) => `${e}`).join("\n------\n")} | ||
------ | ||
`; | ||
return { | ||
error: new Error(errorMsg), | ||
module: null, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.