Skip to content

Commit

Permalink
fix: adding additional logging when importing/requiring a module in c…
Browse files Browse the repository at this point in the history
…ase the hook script is invalid or unable to be executed (#8356)
  • Loading branch information
mmaietta committed Jul 19, 2024
1 parent fb16669 commit 2541eb6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/polite-impalas-shout.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"app-builder-lib": patch
---

fix: adding additional logging when importing/requiring a module in case the hook script is invalid or unable to be executed
11 changes: 8 additions & 3 deletions packages/app-builder-lib/src/platformPackager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -778,10 +778,15 @@ async function resolveModule<T>(type: string | undefined, name: string): Promise
const fileUrl = pathToFileURL(name).href
return await eval("import('" + fileUrl + "')")
}
} catch (error) {
log.debug({ moduleName: name }, "Unable to dynamically import hook, falling back to `require`")
} catch (error: any) {
log.debug({ moduleName: name, message: error.message ?? error.stack }, "Unable to dynamically import hook, falling back to `require`")
}
try {
return require(name)
} catch (error: any) {
log.error({ moduleName: name, message: error.message ?? error.stack }, "Unable to `require` hook")
throw new Error(error.message ?? error.stack)
}
return require(name)
}

export async function resolveFunction<T>(type: string | undefined, executor: T | string, name: string): Promise<T> {
Expand Down

0 comments on commit 2541eb6

Please sign in to comment.