Files
supabase/apps/studio/vercel.test.ts
Alaister YoungandAlaister Young 200cc3f65d [FE-3106] (part 1) – ci(studio): build and test tanstack start only (#53199)
First part of the FE-3106 cleanup (final pass of the TanStack Start
migration): Studio now builds, runs and tests TanStack Start only.
Retiring the Next build first is what lets the follow-up PRs in this
stack delete `pages/**` files without breaking a still-built Next
runtime, the Next E2E shard or Next previews. Part 1 of the stack, based
on `master`.

**Changed:**
- `apps/studio/package.json` – `dev`/`build`/`start` run the Vite/Nitro
build directly (the former `*:tanstack` scripts)
- `apps/studio/vercel.ts` – always emits the TanStack Start config
(`framework: null`, redirects, headers); no `STUDIO_FRAMEWORK` gate, so
every Vercel project building Studio deploys the Nitro output
- `apps/studio/Dockerfile` – single TanStack `build` stage; the image no
longer defaults to Next
- `.github/workflows/studio-e2e-test.yml` – one E2E run (2 shards)
instead of a `next`/`tanstack` matrix; drops the `.next` cache step
- `.github/workflows/studio-docker-build.yml` – one image build
- `apps/studio/turbo.jsonc` – drops `STUDIO_FRAMEWORK` and the `.next`
outputs
- `apps/studio/AGENTS.md`, `apps/studio/TANSTACK_MIGRATION.md` –
describe the TanStack-only runtime

**Removed:**
- `dev:next`/`build:next`/`start:next` scripts, `scripts/dispatch.js`,
`scripts/lib/env.js`, the Turbopack cache `predev` script, and the root
`build:studio:docker:tanstack` script

Addresses
[FE-3106](https://linear.app/supabase/issue/FE-3106/move-page-bodies-into-route-files-and-delete-pages).

Before merging: branch protection lists `E2E tests (next, 1, 2)`/`(next,
2, 2)` and `E2E tests (tanstack, 1, 2)`/`(tanstack, 2, 2)` as required
checks. The jobs are now `E2E tests (1, 2)`/`(2, 2)`, so the required
checks need updating. Any Vercel project or self-hosted image still on
Next switches to TanStack Start with this PR.

## To test

- `pnpm dev:studio` without `STUDIO_FRAMEWORK` set – Vite dev server
starts on :8082
- `pnpm build --filter=studio` – Vite/Nitro build succeeds, no `.next`
output
- Vercel previews (`studio`, `studio-self-hosted`, `studio-staging`) –
build and serve the TanStack app
- `Studio Docker Build` and E2E checks – pass with the single TanStack
run

Ran `vercel.test.ts`, studio typecheck, knip, ESLint on changed files,
Prettier and the TanStack build locally. Docker and E2E are verified by
CI only.

---------

Co-authored-by: Alaister Young <10985857+alaister@users.noreply.github.com>
2026-11-11 06:04:46 +00:00

170 lines
5.9 KiB
TypeScript

import { createRequire } from 'node:module'
import type { VercelConfig } from '@vercel/config/v1'
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
// Compile with the routing utilities consumed by the installed Vercel config SDK.
const require = createRequire(import.meta.url)
const vercelRequire = createRequire(require.resolve('@vercel/config/v1'))
const getTransformedRoutes: (
config: Pick<VercelConfig, 'headers'> | Pick<VercelConfig, 'redirects'>
) => {
error: unknown
routes: { src?: string; headers?: Record<string, string>; status?: number }[] | null
} = vercelRequire('@vercel/routing-utils').getTransformedRoutes
afterEach(() => {
vi.unstubAllEnvs()
vi.resetModules()
})
describe.each(['', '/dashboard'])('Vercel headers with base path "%s"', (basePath) => {
it('leaves only exact deployment metadata paths to the handler cache policy', async () => {
vi.stubEnv('NEXT_PUBLIC_BASE_PATH', basePath)
const { config } = await import('./vercel')
const compiled = getTransformedRoutes({ headers: config.headers })
expect(compiled.error).toBeNull()
expect(compiled.routes).not.toBeNull()
function cacheHeaders(pathname: string) {
return compiled.routes!.flatMap(({ src, headers }) =>
src && new RegExp(src).test(pathname) && headers?.['Cache-Control']
? [headers['Cache-Control']]
: []
)
}
for (const prefix of basePath ? ['', basePath] : ['']) {
expect(cacheHeaders(`${prefix}/api/get-deployment-commit`)).toEqual([])
expect(cacheHeaders(`${prefix}/api/get-deployment-commit/`)).toEqual([])
for (const path of [
'/api/get-deployment-commit/extra',
'/api/get-deployment-commit-other',
'/api/get-deployment-commit.json',
'/api/Get-deployment-commit',
'/api/platform/profile',
'/api/v1/projects/example/api-keys',
'/api/status-page',
'/_serverFn/function-id',
]) {
expect(cacheHeaders(`${prefix}${path}`), `${prefix}${path}`).toEqual(['private, no-store'])
}
const securityRule = compiled.routes!.find(
({ src, headers }) =>
src &&
new RegExp(src).test(`${prefix}/api/get-deployment-commit`) &&
headers?.['X-Frame-Options']
)
expect(securityRule).toBeDefined()
}
})
})
describe.each(['', '/dashboard'])('TanStack content types with base path "%s"', (basePath) => {
let compiledRoutes: ReturnType<typeof getTransformedRoutes>['routes']
beforeEach(async () => {
vi.resetModules()
vi.stubEnv('NEXT_PUBLIC_BASE_PATH', basePath)
const { config } = await import('./vercel')
const result = getTransformedRoutes({ headers: config.headers })
expect(result.error).toBeNull()
compiledRoutes = result.routes
})
function headersForPath(pathname: string) {
const headers: Record<string, string> = {}
for (const route of compiledRoutes ?? []) {
if (route.src && new RegExp(route.src).test(pathname)) Object.assign(headers, route.headers)
}
return headers
}
it.each(['edge-runtime.d.ts', 'lib.deno.d.ts'])(
'serves %s as TypeScript at root and base path',
(file) => {
for (const prefix of new Set(['', basePath])) {
const headers = headersForPath(`${prefix}/deno/${file}`)
expect(headers['content-type']).toBe('text/typescript')
expect(headers['X-Content-Type-Options']).toBe('nosniff')
expect(headers['Cache-Control']).toBeUndefined()
}
}
)
it.each([
'/deno/edge-runtime.d.ts.map',
'/deno/edge-runtime.d.tsx',
'/deno/edge-runtime.dXts',
'/deno/edge-runtime.d.ts/extra',
'/deno/edge-runtime.d.tsextra',
'/deno-other/edge-runtime.d.ts',
'/edge-runtime.d.ts',
'/img/example.ts',
])('does not override content type for %s', (pathname) => {
for (const prefix of new Set(['', basePath])) {
expect(headersForPath(`${prefix}${pathname}`)['content-type']).toBeUndefined()
}
})
it.each(['/api/example.ts', '/api/deno/example.ts', '/_serverFn/example.ts'])(
'preserves dynamic content type and private caching for %s',
(pathname) => {
for (const prefix of new Set(['', basePath])) {
const headers = headersForPath(`${prefix}${pathname}`)
expect(headers['content-type']).toBeUndefined()
expect(headers['Cache-Control']).toBe('private, no-store')
}
}
)
it('preserves JSON content type for the flags endpoint', () => {
expect(headersForPath('/.well-known/vercel/flags')['content-type']).toBe('application/json')
})
})
describe.each(['', '/dashboard'])(
'TanStack maintenance redirects with base path "%s"',
(basePath) => {
let compiledRoutes: ReturnType<typeof getTransformedRoutes>['routes']
beforeEach(async () => {
vi.resetModules()
vi.stubEnv('NEXT_PUBLIC_BASE_PATH', basePath)
vi.stubEnv('NEXT_PUBLIC_IS_PLATFORM', 'true')
vi.stubEnv('MAINTENANCE_MODE', 'true')
const { config } = await import('./vercel')
const result = getTransformedRoutes({ redirects: config.redirects })
expect(result.error).toBeNull()
compiledRoutes = result.routes
})
function redirectFor(pathname: string) {
const route = compiledRoutes?.find(({ src }) => src && new RegExp(src).test(pathname))
return route?.headers?.Location
}
it.each([
'/maintenance',
'/img/supabase-dark.svg',
'/favicon/favicon.ico',
'/favicon/manifest.json',
'/assets/main-abc123.js',
'/_vercel/immutable/salt/nitro/main-abc123.js',
'/_vercel/immutable/salt/nitro/styles-abc123.css',
])('does not redirect %s', (pathname) => {
expect(redirectFor(`${basePath}${pathname}`)).toBeUndefined()
})
it.each([
'/project/abc/editor',
'/org/acme/billing',
'/maintenance-other',
'/api/platform/profile',
])('redirects %s to the maintenance page', (pathname) => {
expect(redirectFor(`${basePath}${pathname}`)).toBe(`${basePath}/maintenance`)
})
}
)