Skip to content

Commit 3cdc971

Browse files
authored
Convert Next config to TypeScript (#360)
1 parent c1cb3e6 commit 3cdc971

10 files changed

Lines changed: 20 additions & 17 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ This application is optimized for deployment on Vercel:
163163
2. Import your repository in Vercel
164164
3. Deploy!
165165

166-
> **Note**: The application uses Partial Prerendering (PPR) which is currently only supported on Vercel's infrastructure. This can be turned off inside [`next.config.mjs`](./next.config.mjs).
166+
> **Note**: The application uses Partial Prerendering (PPR) which is currently only supported on Vercel's infrastructure. This can be turned off inside [`next.config.ts`](./next.config.ts).
167167
168168
## Contributing
169169
We welcome contributions! Please see our [Contributing Guide](CONTRIBUTING.md) for details.

next.config.mjs renamed to next.config.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
// NOTE: related to src/configs/rewrites.ts
22
import path from 'node:path'
3+
import type { NextConfig } from 'next'
4+
import { DOCUMENTATION_DOMAIN } from './src/configs/documentation'
35

4-
export const DOCUMENTATION_DOMAIN = 'e2b.mintlify.app'
5-
6-
const browserStub = (file) => path.resolve(process.cwd(), 'stubs', file)
6+
const browserStub = (file: string) => path.resolve(process.cwd(), 'stubs', file)
77

88
const browserNodeModuleStubs = {
99
crypto: browserStub('crypto.ts'),
@@ -16,8 +16,7 @@ const browserNodeModuleStubs = {
1616
'node:path': browserStub('path.ts'),
1717
}
1818

19-
/** @type {import('next').NextConfig} */
20-
const config = {
19+
const config: NextConfig = {
2120
reactStrictMode: true,
2221
reactCompiler: true,
2322
experimental: {
@@ -48,9 +47,12 @@ const config = {
4847
}
4948

5049
webpackConfig.plugins.push(
51-
new webpack.NormalModuleReplacementPlugin(/^node:/, (resource) => {
52-
resource.request = resource.request.replace(/^node:/, '')
53-
})
50+
new webpack.NormalModuleReplacementPlugin(
51+
/^node:/,
52+
(resource: { request: string }) => {
53+
resource.request = resource.request.replace(/^node:/, '')
54+
}
55+
)
5456
)
5557
}
5658

src/app/sitemap.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@
99

1010
import { XMLParser } from 'fast-xml-parser'
1111
import type { MetadataRoute } from 'next'
12+
import { DOCUMENTATION_DOMAIN } from '@/configs/documentation'
1213
import { ALLOW_SEO_INDEXING } from '@/configs/flags'
1314
import { LANDING_PAGE_DOMAIN, ROUTE_REWRITE_CONFIG } from '@/configs/rewrites'
1415
import { SITEMAP_EXCLUDE_CONFIG } from '@/configs/sitemap'
1516
import type { DomainConfig } from '@/types/rewrites.types'
16-
import { DOCUMENTATION_DOMAIN } from '../../next.config.mjs'
1717

1818
// Cache the sitemap for 15 minutes (in seconds)
1919
const SITEMAP_CACHE_TIME = 15 * 60

src/configs/documentation.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const DOCUMENTATION_DOMAIN = 'e2b.mintlify.app'

src/configs/rewrites.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import type { DomainConfig } from '@/types/rewrites.types'
2+
import { DOCUMENTATION_DOMAIN } from './documentation'
23

34
export const LANDING_PAGE_DOMAIN = 'www.e2b-landing-page.com'
45

5-
import { DOCUMENTATION_DOMAIN } from '../../next.config.mjs'
6-
76
// Currently we have two locations for rewrites to happen.
87

98
// 1. Route handler catch-all rewrite config (cached on build time with revalidation)
@@ -41,7 +40,7 @@ export const ROUTE_REWRITE_CONFIG: DomainConfig[] = [
4140
* Middleware native rewrite config
4241
*
4342
* We implement rewrites directly in middleware rather than using Next.js's built-in
44-
* `rewrites` configuration in next.config.js because we need to set custom request
43+
* `rewrites` configuration in next.config.ts because we need to set custom request
4544
* and response headers for these rewritten requests.
4645
*
4746
* Specifically, we need to:

src/configs/sitemap.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { DOCUMENTATION_DOMAIN } from '../../next.config.mjs'
1+
import { DOCUMENTATION_DOMAIN } from './documentation'
22

33
export const SITEMAP_EXCLUDE_CONFIG: Array<{
44
domain: string

tests/integration/e2b-browser-stubs.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { describe, expect, it } from 'vitest'
2-
import nextConfig from '../../next.config.mjs'
2+
import nextConfig from '../../next.config'
33

44
class MockNormalModuleReplacementPlugin {
55
readonly pattern: RegExp

tests/integration/proxy.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { createServerClient } from '@supabase/ssr'
22
import { NextRequest, NextResponse } from 'next/server'
33
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
4+
import { DOCUMENTATION_DOMAIN } from '@/configs/documentation'
45
import { AUTH_URLS, PROTECTED_URLS } from '@/configs/urls'
56
import { proxy } from '@/proxy'
6-
import { DOCUMENTATION_DOMAIN } from '../../next.config.mjs'
77

88
// mock supabase auth
99
vi.mock('@supabase/ssr', () => ({

tests/unit/sitemap.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
2+
import { DOCUMENTATION_DOMAIN } from '@/configs/documentation'
23
import { LANDING_PAGE_DOMAIN } from '@/configs/rewrites'
3-
import { DOCUMENTATION_DOMAIN } from '../../next.config.mjs'
44

55
vi.mock('@/configs/flags', () => ({
66
ALLOW_SEO_INDEXING: true,

tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
},
3636
"include": [
3737
"next-env.d.ts",
38+
"next.config.ts",
3839
"src",
3940
".next/types/**/*.ts",
4041
".next/dev/types/**/*.ts",

0 commit comments

Comments
 (0)