Skip to content

Commit

Permalink
fix: ensure env is set before calling projectUrl()
Browse files Browse the repository at this point in the history
  • Loading branch information
atinux committed Jun 3, 2024
1 parent 85b1cae commit 40dfa3d
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -288,13 +288,15 @@ export default defineNuxtModule<ModuleOptions>({
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 })
}
Expand All @@ -320,6 +322,10 @@ export default defineNuxtModule<ModuleOptions>({
})
// 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}\``)
Expand Down

0 comments on commit 40dfa3d

Please sign in to comment.