8000 fix: ensure env is set before calling `projectUrl()` · nuxt-hub/core@40dfa3d · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Commit 40dfa3d

Browse files
committed
fix: ensure env is set before calling projectUrl()
1 parent 85b1cae commit 40dfa3d

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/module.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,13 +288,15 @@ export default defineNuxtModule<ModuleOptions>({
288288
if (String(env) === 'true') {
289289
try {
290290
branch = execSync('git branch --show-current', { stdio: ['ignore', 'pipe', 'ignore'] }).toString().trim()
291+
env = (branch === 'main' ? 'production' : 'preview')
291292
} catch {
292293
// ignore
293294
log.warn('Could not guess the environment from the branch name, using `production` as default')
294295
env = 'production'
295296
}
296297
}
297-
if (typeof hub.projectUrl === 'function') {
298+
// If projectUrl is a function and we cannot know the productionBranch
299+
if (typeof hub.projectUrl === 'function' && !hub.projectKey) {
298300
// @ts-expect-error issue with defu transform
299301
hub.projectUrl = hub.projectUrl({ env, branch })
300302
}
@@ -320,6 +322,10 @@ export default defineNuxtModule<ModuleOptions>({
320322
})
321323
// Adapt env based on project defined production branch
322324
env = (branch === project.productionBranch ? 'production' : 'preview')
325+
if (typeof hub.projectUrl === 'function') {
326+
// @ts-expect-error issue with defu transform
327+
hub.projectUrl = hub.projectUrl({ env, branch })
328+
}
323329

324330
const adminUrl = joinURL(hub.url, project.teamSlug, project.slug)
325331
log.info(`Linked to \`${adminUrl}\``)

0 commit comments

Comments
 (0)
0