From 2541eb62a6a8338c87f3d032ff48ed154c2d3cca Mon Sep 17 00:00:00 2001 From: Mike Maietta Date: Fri, 19 Jul 2024 09:17:21 -0700 Subject: [PATCH] fix: adding additional logging when importing/requiring a module in case the hook script is invalid or unable to be executed (#8356) --- .changeset/polite-impalas-shout.md | 5 +++++ packages/app-builder-lib/src/platformPackager.ts | 11 ++++++++--- 2 files changed, 13 insertions(+), 3 deletions(-) create mode 100644 .changeset/polite-impalas-shout.md diff --git a/.changeset/polite-impalas-shout.md b/.changeset/polite-impalas-shout.md new file mode 100644 index 00000000000..56047e67c27 --- /dev/null +++ b/.changeset/polite-impalas-shout.md @@ -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 diff --git a/packages/app-builder-lib/src/platformPackager.ts b/packages/app-builder-lib/src/platformPackager.ts index dd9c59bddc4..732ccf5c0f0 100644 --- a/packages/app-builder-lib/src/platformPackager.ts +++ b/packages/app-builder-lib/src/platformPackager.ts @@ -778,10 +778,15 @@ async function resolveModule(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(type: string | undefined, executor: T | string, name: string): Promise {