From a3e5f928c437481321d4adc34e6925a4e7241413 Mon Sep 17 00:00:00 2001 From: gbuomprisco Date: Sun, 23 Jun 2024 21:09:00 +0800 Subject: [PATCH] Add guard clauses in getHashFromProcess Additional logic has been introduced to the getHashFromProcess function. It will now exit early if the runtime is not Node.js or if the environment is not a development environment to prevent calling a Node.js command. This is done to avoid potential issues in the edge runtime and non-development environments. --- apps/web/app/version/route.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/apps/web/app/version/route.ts b/apps/web/app/version/route.ts index 2237ea8b0..b4874ba27 100644 --- a/apps/web/app/version/route.ts +++ b/apps/web/app/version/route.ts @@ -32,6 +32,19 @@ function getGitHash() { } async function getHashFromProcess() { + // avoid calling a Node.js command in the edge runtime + if (process.env.NEXT_RUNTIME !== 'nodejs') { + console.log(`[INFO] Could not find git hash in environment variables. Falling back to git command. Supply a known git hash environment variable to avoid this warning.`) + + return; + } + + if (process.env.NODE_ENV !== 'development') { + console.warn( + `[WARN] Could not find git hash in environment variables. Falling back to git command. Supply a known git hash environment variable to avoid this warning.`, + ); + } + const { execSync } = await import('child_process'); return execSync('git log --pretty=format:"%h" -n1').toString().trim();