Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

fix(studio): serve Deno declarations as TypeScript (#51057)

Alaister Young46b7382d504d
diff --git a/apps/studio/vercel-content-types.test.ts b/apps/studio/vercel-content-types.test.ts
new file mode 100644
index 00000000000..dc2045d26d0
--- /dev/null
+++ b/apps/studio/vercel-content-types.test.ts
@@ -0,0 +1,94 @@
+import { createRequire } from 'node:module'
+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
+import { z } from 'zod'
+
+const require = createRequire(import.meta.url)
+const sdkRequire = createRequire(require.resolve('@vercel/config/v1'))
+const { getTransformedRoutes } = sdkRequire('@vercel/routing-utils')
+const compiledConfigSchema = z.object({
+ error: z.unknown(),
+ routes: z
+ .array(z.object({ src: z.string().optional(), headers: z.record(z.string()).optional() }))
+ .nullable(),
+})
+
+afterEach(() => {
+ vi.unstubAllEnvs()
+ vi.resetModules()
+})
+
+describe.each(['', '/dashboard'])('TanStack content types with base path "%s"', (basePath) => {
+ let compiledRoutes: z.infer<typeof compiledConfigSchema>['routes']
+
+ beforeEach(async () => {
+ vi.resetModules()
+ vi.stubEnv('STUDIO_FRAMEWORK', 'tanstack')
+ vi.stubEnv('NEXT_PUBLIC_BASE_PATH', basePath)
+ const { config } = await import('./vercel')
+ const compiled: unknown = getTransformedRoutes({ headers: config.headers })
+ const result = compiledConfigSchema.parse(compiled)
+ 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')
+ })
+})
+
+it.each([undefined, 'next'])(
+ 'leaves the Next Vercel configuration untouched (%s)',
+ async (framework) => {
+ vi.resetModules()
+ vi.stubEnv('STUDIO_FRAMEWORK', framework)
+ vi.stubEnv('NEXT_PUBLIC_BASE_PATH', '/dashboard')
+ const { config } = await import('./vercel')
+ expect(config).toEqual({})
+ }
+)
diff --git a/apps/studio/vercel.ts b/apps/studio/vercel.ts
index c61b80d7dca..9fcd4a9d39b 100644
--- a/apps/studio/vercel.ts
+++ b/apps/studio/vercel.ts
@@ -47,6 +47,9 @@ function headersFor(prefix: string) {
// favicon: max-age=86400 = 1 day).
routes.cacheControl(`${prefix}/img/(.*)`, { public: true, maxAge: '30days' }),
routes.cacheControl(`${prefix}/favicon/(.*)`, { public: true, maxAge: '1day' }),
+ // Deno declarations are public TypeScript assets. Keep this override
+ // scoped to /deno so dynamic response types remain handler-owned.
+ routes.header(`${prefix}/deno/(.*)\\.ts`, [{ key: 'content-type', value: 'text/typescript' }]),
]
}