From 40dfa3df77c889aa0d83bd27d5bdc570faacee05 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Chopin?= Date: Mon, 3 Jun 2024 14:58:13 +0200 Subject: [PATCH] fix: ensure env is set before calling `projectUrl()` --- src/module.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/module.ts b/src/module.ts index d06958ca..07c55c40 100644 --- a/src/module.ts +++ b/src/module.ts @@ -288,13 +288,15 @@ export default defineNuxtModule({ if (String(env) === 'true') { try { branch = execSync('git branch --show-current', { stdio: ['ignore', 'pipe', 'ignore'] }).toString().trim() + env = (branch === 'main' ? 'production' : 'preview') } catch { // ignore log.warn('Could not guess the environment from the branch name, using `production` as default') env = 'production' } } - if (typeof hub.projectUrl === 'function') { + // If projectUrl is a function and we cannot know the productionBranch + if (typeof hub.projectUrl === 'function' && !hub.projectKey) { // @ts-expect-error issue with defu transform hub.projectUrl = hub.projectUrl({ env, branch }) } @@ -320,6 +322,10 @@ export default defineNuxtModule({ }) // Adapt env based on project defined production branch env = (branch === project.productionBranch ? 'production' : 'preview') + if (typeof hub.projectUrl === 'function') { + // @ts-expect-error issue with defu transform + hub.projectUrl = hub.projectUrl({ env, branch }) + } const adminUrl = joinURL(hub.url, project.teamSlug, project.slug) log.info(`Linked to \`${adminUrl}\``)