Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions src/marketing/app/_lib/developersPaths.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { afterEach, describe, expect, it, vi } from 'vitest'

describe('developersPath', () => {
afterEach(() => {
vi.unstubAllEnvs()
vi.resetModules()
})

it('uses root-relative paths outside production deployments', async () => {
vi.stubEnv('VERCEL_ENV', 'preview')
const { developersPath } = await import('./developersPaths')

expect(developersPath('/')).toBe('/')
expect(developersPath('/docs')).toBe('/docs')
expect(developersPath('/build/tempo-transactions')).toBe('/build/tempo-transactions')
})

it('uses the developers mount in production deployments', async () => {
vi.stubEnv('VERCEL_ENV', 'production')
const { developersPath } = await import('./developersPaths')

expect(developersPath('/')).toBe('/developers')
expect(developersPath('/docs')).toBe('/developers/docs')
expect(developersPath('/build/tempo-transactions')).toBe(
'/developers/build/tempo-transactions',
)
})
})
12 changes: 10 additions & 2 deletions src/marketing/app/_lib/developersPaths.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
export const DEVELOPERS_BASE_PATH = '/developers'

function normalizedPath(path: string): string {
if (path === '/') return '/'
return path.startsWith('/') ? path : `/${path}`
}

export function developersPath(path: string): string {
if (path === '/') return DEVELOPERS_BASE_PATH
return `${DEVELOPERS_BASE_PATH}${path.startsWith('/') ? path : `/${path}`}`
const normalized = normalizedPath(path)

if (import.meta.env.VERCEL_ENV !== 'production') return normalized
if (normalized === '/') return DEVELOPERS_BASE_PATH
return `${DEVELOPERS_BASE_PATH}${normalized}`
}
3 changes: 3 additions & 0 deletions vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ export default defineConfig(({ mode }) => {
}

return {
define: {
'import.meta.env.VERCEL_ENV': JSON.stringify(process.env.VERCEL_ENV ?? ''),
},
plugins: [
blogPostsPlugin(),
marketingPages(),
Expand Down
Loading