Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(next): next.config.ts #63051

Open
wants to merge 166 commits into
base: canary
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
166 commits
Select commit Hold shift + click to select a range
7c24a69
allow next.config.ts on load
devjiwonchoi Oct 27, 2023
21b18e0
test: add test for next.config.ts
devjiwonchoi Oct 27, 2023
407658d
add compile config
devjiwonchoi Oct 28, 2023
3075e2a
chore: compile as mjs
devjiwonchoi Oct 28, 2023
bd61aec
test: add test case for production
devjiwonchoi Oct 28, 2023
4ba992b
chore: add cache original config and skip compile if identical
devjiwonchoi Oct 28, 2023
5fcfd50
Merge branch 'canary' into next-config-ts-esm
devjiwonchoi Oct 28, 2023
834bdba
add next.config.ts to error message
devjiwonchoi Oct 28, 2023
7c25030
remove caching snapshot of config
devjiwonchoi Oct 28, 2023
7a0518c
fix: modify target version to esnext
devjiwonchoi Oct 29, 2023
5a394a9
refac: convert to async job, error handle
devjiwonchoi Oct 29, 2023
cd2c8d8
test: modify test to look for rendered element
devjiwonchoi Oct 29, 2023
22b1497
chore: use curLog for errors when failed compiling
devjiwonchoi Oct 29, 2023
57ea7ff
chore: add read off tsconfig for module type
devjiwonchoi Oct 30, 2023
7006fd3
chore: remove production test
devjiwonchoi Oct 30, 2023
bec6170
refac: output file ext always mjs
devjiwonchoi Oct 30, 2023
8de3c81
test: add esm test
devjiwonchoi Oct 30, 2023
5df0813
test: add cjs test
devjiwonchoi Oct 30, 2023
540f6ae
fix: file ext mjs if not cjs
devjiwonchoi Oct 30, 2023
de02ca8
chore: add type for Log
devjiwonchoi Oct 30, 2023
ab6e908
refac: explicit type for error log
devjiwonchoi Oct 30, 2023
c9d2eb6
test: import type at esm
devjiwonchoi Oct 30, 2023
4b2ed5a
chore: no module type check, just compile them as cjs
devjiwonchoi Oct 30, 2023
ff17aef
add more tests
devjiwonchoi Oct 30, 2023
75758cc
Merge branch 'canary' into next-config-ts-esm
devjiwonchoi Oct 30, 2023
f6aea6e
add failing tests
devjiwonchoi Oct 30, 2023
ab52aff
chore: naming as transpileConfig
devjiwonchoi Oct 30, 2023
3c87454
test: remove unnecessary tsconfig
devjiwonchoi Oct 31, 2023
1aeb69c
test: add necessary tsconfig.json
devjiwonchoi Oct 31, 2023
6375316
Merge branch 'canary' into next-config-ts-esm
devjiwonchoi Nov 6, 2023
d368dc4
Add strict mode and pure ESM import
devjiwonchoi Nov 7, 2023
b008c20
Refactor transpileConfig and loadConfig functions
devjiwonchoi Nov 7, 2023
2b6c10b
Fix transpile-config and loadConfig functions
devjiwonchoi Nov 7, 2023
5205dba
Update transpile-config and add new files for next-config-ts tests
devjiwonchoi Nov 7, 2023
7dfc842
Add next.compiled.config.* to gitignore
devjiwonchoi Nov 7, 2023
26c3e22
Merge branch 'canary' into next-config-ts-esm
devjiwonchoi Nov 7, 2023
e4c7acf
refac: use temporary config
devjiwonchoi Nov 21, 2023
fcc0d55
Remove next.compiled.config from gitignore
devjiwonchoi Nov 21, 2023
7e0855a
ensure import url
devjiwonchoi Nov 21, 2023
d8108e1
refac: transpile-config focus on returning code
devjiwonchoi Nov 21, 2023
ea5b249
Merge branch 'canary' into next-config-ts-esm
devjiwonchoi Nov 22, 2023
db7836e
Delete tsconfig.json and .gitignore files
devjiwonchoi Nov 22, 2023
f972c6f
remove log type declaration
devjiwonchoi Nov 22, 2023
02a47b2
Remove unused 'cwd' parameter in transpileConfig
devjiwonchoi Nov 22, 2023
2b84702
modify test names
devjiwonchoi Nov 22, 2023
1b9c204
test: add import from other ts
devjiwonchoi Dec 7, 2023
fa7a424
Merge branch 'canary' into next-config-ts-esm
devjiwonchoi Dec 7, 2023
379aabc
Merge branch 'canary' into next-config-ts-esm
devjiwonchoi Dec 30, 2023
1d3adfe
Merge branch 'canary' into next-config-ts-esm
devjiwonchoi Feb 7, 2024
5e57291
Merge branch 'canary' into next-config-ts-esm
devjiwonchoi Feb 18, 2024
39736a3
Merge branch 'canary' into next-config-ts-esm
devjiwonchoi Feb 20, 2024
db25521
chore: save current work
devjiwonchoi Feb 20, 2024
43a39d1
fix: taskfile and bundle5 terser-plugin path
devjiwonchoi Feb 20, 2024
20f8c42
save for now - webpack does complete bundle but output is 0 byte
devjiwonchoi Feb 20, 2024
8c63c93
refactor: re-compile if needed
devjiwonchoi Feb 21, 2024
4c70e92
test: import-alias
devjiwonchoi Feb 21, 2024
0aa3154
refactor: support path alias
devjiwonchoi Feb 21, 2024
c8d072b
chore: remove import-from-other-ts since path-alias can handle it
devjiwonchoi Feb 21, 2024
03ce640
refactor: error handling transpile config
devjiwonchoi Feb 21, 2024
0783399
refactor: remove resolve.extensions for webpack option
devjiwonchoi Feb 21, 2024
fb55de4
test: remove ALL current tests
devjiwonchoi Feb 21, 2024
cfb0851
Merge branch 'canary' into next-config-ts-esm
devjiwonchoi Feb 22, 2024
bfa25b5
test: add import alias
devjiwonchoi Feb 22, 2024
86d0201
test: export as default
devjiwonchoi Feb 22, 2024
55dd8ad
test: add import from node modules
devjiwonchoi Feb 22, 2024
dfb8816
fix: add webpack.resolve.extensions
devjiwonchoi Feb 22, 2024
9cc2ac9
refactor: next config options may be nullish
devjiwonchoi Feb 22, 2024
23edb4d
test: config as async function
devjiwonchoi Feb 22, 2024
b6c7888
refactor: add alias for swc helpers
devjiwonchoi Feb 22, 2024
0565dd7
test: config has no export default
devjiwonchoi Feb 22, 2024
a82e7ea
test: nest tests inside next-config-ts dir
devjiwonchoi Feb 22, 2024
1d386b1
test: ensure config recompiled when needed
devjiwonchoi Feb 22, 2024
555806a
refactor: pass nextconfig to bundleconfig as default empty obj
devjiwonchoi Feb 22, 2024
5e7f21d
refactor: re-use inputFileSystem
devjiwonchoi Feb 22, 2024
757108d
test: add dev server
devjiwonchoi Feb 22, 2024
15995b5
refactor: remove unintended changes
devjiwonchoi Feb 22, 2024
25293c9
test: ensure importing relative from root
devjiwonchoi Feb 22, 2024
1f85d1b
fix: remove reusing inputFileSystem
devjiwonchoi Feb 22, 2024
406b4ff
test: remove no default export since not throwing
devjiwonchoi Feb 22, 2024
9e8f5b5
refactor: replace webpack bundle with require hook and swc transform
devjiwonchoi Feb 24, 2024
3b49ca3
test: remove recompile
devjiwonchoi Feb 24, 2024
bf46de4
Merge branch 'canary' into next-config-ts-esm
devjiwonchoi Feb 24, 2024
7f16812
Revert "fix: taskfile and bundle5 terser-plugin path"
devjiwonchoi Feb 24, 2024
2e358df
refactor: modify variable names and add TODO
devjiwonchoi Feb 24, 2024
419d1a9
test: add pkg type module esm project
devjiwonchoi Feb 24, 2024
7c97ef5
test: add mts
devjiwonchoi Feb 24, 2024
3b81c7d
test: ensure esm imports correctly
devjiwonchoi Feb 24, 2024
932dd22
refactor: support ESM
devjiwonchoi Feb 24, 2024
4caea8b
refactor: remove unintended fixes
devjiwonchoi Feb 24, 2024
0d02318
refactor: return default
devjiwonchoi Feb 24, 2024
259c08b
test: import .mts and .cts
devjiwonchoi Feb 25, 2024
06c734c
refactor: support importing other ts extensions
devjiwonchoi Feb 25, 2024
91c4f92
test: add esm mjs imports
devjiwonchoi Feb 25, 2024
e4d4870
refactor: handle import ESM
devjiwonchoi Feb 25, 2024
1a3b83a
fix: do not modify require.extensions['.js']
devjiwonchoi Feb 25, 2024
4840acf
test: add import esm from node_modules
devjiwonchoi Feb 26, 2024
a52e610
test: add nested imports
devjiwonchoi Feb 26, 2024
230e44e
refactor: drop .cts, remove experimental log
devjiwonchoi Feb 27, 2024
92065d4
refactor: register by detecting transpile-config not extensions
devjiwonchoi Feb 27, 2024
598bdbc
chore: remove unrelated change
devjiwonchoi Feb 27, 2024
16a2412
refactor: revert handling register via extensions
devjiwonchoi Feb 27, 2024
519df26
chore: save progress before revert
devjiwonchoi Feb 29, 2024
d410013
refactor: transpile only or bundle if necessary
devjiwonchoi Feb 29, 2024
00d2988
refactor: separate bundle method
devjiwonchoi Feb 29, 2024
4f668ab
refactor: remove recompile, no unlinking config file
devjiwonchoi Mar 1, 2024
54d0d3f
test: add cjs, esm, node-api
devjiwonchoi Mar 1, 2024
cd1922b
refactor: handle importing js extensions
devjiwonchoi Mar 1, 2024
abd46e8
fix: update taskfile's terser-webpack-plugin path
devjiwonchoi Mar 1, 2024
e430955
test: add next-config-mts
devjiwonchoi Mar 1, 2024
0b698b2
refactor: webpack mode to production, fix on terser-plugin was needed
devjiwonchoi Mar 1, 2024
c3182c3
fix: allow .mts extension for swc-loader
devjiwonchoi Mar 1, 2024
d4f2abf
chore: remove tsconfig for next-config-mts test
devjiwonchoi Mar 1, 2024
694c3a9
refactor: use nodejs api, add unlink since it breaks when using __dir…
devjiwonchoi Mar 2, 2024
b1ee1db
Merge branch 'canary' into next-config-ts-esm
devjiwonchoi Mar 2, 2024
661b2fa
refactor: revert using .next dir, ensure __dirname to point cwd
devjiwonchoi Mar 2, 2024
35c78f5
docs: add next.config.ts, but as an option not default
devjiwonchoi Mar 3, 2024
80e6740
refactor: use next.config.ts for create next app-ts
devjiwonchoi Mar 3, 2024
8800145
Merge branch 'canary' into next-config-ts-esm
devjiwonchoi Mar 3, 2024
32fd66e
test: add dev
devjiwonchoi Mar 3, 2024
34af164
refactor: use build cache on production server if exists
devjiwonchoi Mar 3, 2024
9890443
refactor: remove unintended change
devjiwonchoi Mar 3, 2024
baaad07
refactor: try transpile-only first before any other operation
devjiwonchoi Mar 3, 2024
b7f50ab
test: add export default
devjiwonchoi Mar 3, 2024
c7765c8
refactor: join cwd with distDir to dedupe join operation
devjiwonchoi Mar 3, 2024
c1e796f
refactor: let loadConfig handle added default export of SWC transform
devjiwonchoi Mar 3, 2024
8bd8863
test: add cjs syntax for direct migration from .js
devjiwonchoi Mar 3, 2024
79b643d
docs: add we recommend next.config.ts if you are migrating to TS
devjiwonchoi Mar 3, 2024
8e4c38e
fix: do not pass an absolute path to distDir
devjiwonchoi Mar 4, 2024
1a61b97
Revert "fix: do not pass an absolute path to distDir"
devjiwonchoi Mar 4, 2024
874aab6
Merge branch 'canary' of https://github.com/devjiwonchoi/next.js into…
devjiwonchoi Mar 8, 2024
a431c9c
Merge branch 'canary' into next-config-ts-esm
samcx Mar 11, 2024
47742b4
Merge branch 'canary' into next-config-ts-esm
devjiwonchoi Mar 15, 2024
ed34515
Merge branch 'canary' of github.com:devjiwonchoi/next.js into next-co…
devjiwonchoi Apr 4, 2024
ec96813
sync bundle5
devjiwonchoi Apr 4, 2024
e0a4da9
Merge branch 'canary' into next-config-ts-esm
devjiwonchoi Apr 4, 2024
57006ce
REVERT to require hook
devjiwonchoi Apr 11, 2024
96b0000
wip: get ready for esm loader
devjiwonchoi Apr 15, 2024
a11d2c0
Merge branch 'canary' into next-config-ts-esm
devjiwonchoi Apr 23, 2024
2ea9b6e
docs: revert changes
devjiwonchoi Apr 24, 2024
ef984bb
Revert "refactor: use next.config.ts for create next app-ts"
devjiwonchoi Apr 24, 2024
03bb99e
Revert "fix: allow .mts extension for swc-loader"
devjiwonchoi Apr 24, 2024
463d2a2
test: remove webpack related dev test
devjiwonchoi Apr 24, 2024
58ec040
REVERT taskfile, bundle5
devjiwonchoi Apr 24, 2024
30b23d6
Merge branch 'canary' into next-config-ts-esm
devjiwonchoi Apr 24, 2024
8ff8b6c
test: commonjs
devjiwonchoi Apr 24, 2024
bb3dacf
test: pkg-commonjs, module
devjiwonchoi Apr 24, 2024
bac1be2
test: node-api import as node:
devjiwonchoi Apr 24, 2024
f8b4295
test: import alias
devjiwonchoi Apr 24, 2024
dee73f8
test: nested-import
devjiwonchoi Apr 24, 2024
bd1dd4d
test: remove cjs syntax
devjiwonchoi Apr 24, 2024
dfde1a8
test: import json
devjiwonchoi Apr 24, 2024
97a4d05
wip: transpile config
devjiwonchoi Apr 24, 2024
c616e05
test: pkg module esm
devjiwonchoi Apr 24, 2024
f14187b
test: fix names
devjiwonchoi Apr 24, 2024
5a078eb
refactor: test pass for esm on js
devjiwonchoi Apr 24, 2024
ef5d1f5
refactor: error handling
devjiwonchoi Apr 25, 2024
724b5ea
Update test/e2e/app-dir/next-config-ts/nested-imports/index.test.ts
devjiwonchoi Apr 25, 2024
5922d0e
Update packages/next/src/server/config.ts
devjiwonchoi Apr 25, 2024
694490e
Merge branch 'canary' into next-config-ts-esm
devjiwonchoi Apr 25, 2024
78cefa0
refactor: no writing to disk
devjiwonchoi Apr 25, 2024
9da25d2
test: delete next-config-mts
devjiwonchoi Apr 25, 2024
1a0f402
refactor: split code as hook and transpile-config
devjiwonchoi Apr 25, 2024
ad40f8d
refactor: strip comments on tsconfig
devjiwonchoi Apr 25, 2024
a20d80f
Merge branch 'canary' into next-config-ts-esm
ijjk Apr 25, 2024
0c0d003
refactor: re-use parseJsonFile
devjiwonchoi Apr 27, 2024
1fc6512
Merge branch 'canary' into next-config-ts-esm
devjiwonchoi Apr 27, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/next/src/build/load-jsconfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { hasNecessaryDependencies } from '../lib/has-necessary-dependencies'

let TSCONFIG_WARNED = false

function parseJsonFile(filePath: string) {
export function parseJsonFile(filePath: string) {
const JSON5 = require('next/dist/compiled/json5')
const contents = readFileSync(filePath, 'utf8')

Expand Down
53 changes: 53 additions & 0 deletions packages/next/src/build/next-config-ts/require-hook.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import type { Options as SWCOptions } from '@swc/core'
import Module from 'node:module'
import { readFileSync } from 'node:fs'
import { dirname } from 'node:path'
import { transformSync } from '../swc'

const oldJSHook = require.extensions['.js']
const extensions = ['.ts', '.cts', '.mts', '.cjs', '.mjs']

export function registerHook(swcOptions: SWCOptions) {
require.extensions['.js'] = function (mod: any, oldFilename) {
try {
return oldJSHook(mod, oldFilename)
} catch (error) {
if ((error as NodeJS.ErrnoException).code !== 'ERR_REQUIRE_ESM') {
throw error
}

// calling oldJSHook throws ERR_REQUIRE_ESM, so run _compile manually
// TODO: investigate if we can remove readFileSync
const content = readFileSync(oldFilename, 'utf8')
const { code } = transformSync(content, swcOptions)
mod._compile(code, oldFilename)
}
}

for (const ext of extensions) {
const oldHook = require.extensions[ext] ?? oldJSHook
require.extensions[ext] = function (mod: any, oldFilename) {
const _compile = mod._compile

mod._compile = function (code: string, filename: string) {
const swc = transformSync(code, swcOptions)
return _compile.call(this, swc.code, filename)
}

return oldHook(mod, oldFilename)
}
}
}

export function deregisterHook() {
require.extensions['.js'] = oldJSHook
extensions.forEach((ext) => delete require.extensions[ext])
}

export function requireFromString(code: string, filename: string) {
const paths = (Module as any)._nodeModulePaths(dirname(filename))
const m = new Module(filename, module.parent!) as any
m.paths = paths
m._compile(code, filename)
return m.exports
}
75 changes: 75 additions & 0 deletions packages/next/src/build/next-config-ts/transpile-config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import type { CompilerOptions } from 'typescript'
import type { Options as SWCOptions } from '@swc/core'
import { readFile } from 'node:fs/promises'
import { join } from 'node:path'
import { deregisterHook, registerHook, requireFromString } from './require-hook'
import { parseJsonFile } from '../load-jsconfig'
import { transform } from '../swc'

function resolveSWCOptions(
cwd: string,
compilerOptions: CompilerOptions
): SWCOptions {
const resolvedBaseUrl = join(cwd, compilerOptions.baseUrl ?? '.')
return {
jsc: {
target: 'es5',
parser: {
syntax: 'typescript',
},
paths: compilerOptions.paths,
baseUrl: resolvedBaseUrl,
},
module: {
type: 'commonjs',
},
isModule: 'unknown',
} satisfies SWCOptions
}

async function lazilyGetTSConfig(cwd: string) {
let tsConfig: { compilerOptions: CompilerOptions }
try {
tsConfig = parseJsonFile(join(cwd, 'tsconfig.json'))
} catch (error) {
// ignore if tsconfig.json does not exist
if ((error as NodeJS.ErrnoException).code !== 'ENOENT') {
throw error
}
tsConfig = { compilerOptions: {} }
}

return tsConfig
}

export async function transpileConfig({
nextConfigPath,
cwd,
}: {
nextConfigPath: string
cwd: string
}) {
let hasRequire = false
try {
const { compilerOptions } = await lazilyGetTSConfig(cwd)
const swcOptions = resolveSWCOptions(cwd, compilerOptions)

const nextConfigString = await readFile(nextConfigPath, 'utf8')
const { code } = await transform(nextConfigString, swcOptions)

// register require hook only if require exists
if (code.includes('require(')) {
registerHook(swcOptions)
hasRequire = true
}

// filename & extension don't matter here
return requireFromString(code, join(cwd, 'next.config.compiled.js'))
} catch (error) {
throw error
} finally {
if (hasRequire) {
deregisterHook()
}
}
}
23 changes: 17 additions & 6 deletions packages/next/src/server/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { matchRemotePattern } from '../shared/lib/match-remote-pattern'
import { ZodParsedType, util as ZodUtil } from 'next/dist/compiled/zod'
import type { ZodError, ZodIssue } from 'next/dist/compiled/zod'
import { hasNextSupport } from '../telemetry/ci-info'
import { transpileConfig } from '../build/next-config-ts/transpile-config'

export { normalizeConfig } from './config-shared'
export type { DomainLocale, NextConfig } from './config-shared'
Expand Down Expand Up @@ -969,8 +970,9 @@ export default async function loadConfig(
// If config file was found
if (path?.length) {
configFileName = basename(path)
let userConfigModule: any
const isTypeScript = configFileName.endsWith('.ts')

let userConfigModule: any
try {
const envBefore = Object.assign({}, process.env)

Expand All @@ -982,6 +984,14 @@ export default async function loadConfig(
// jest relies on so we fall back to require for this case
// https://github.com/nodejs/node/issues/35889
userConfigModule = require(path)
} else if (isTypeScript) {
userConfigModule = await transpileConfig({
nextConfigPath: path,
cwd: dir,
})
curLog.warn(
`Configuration with ${configFileName} is currently an experimental feature, use with caution.`
)
} else {
userConfigModule = await import(pathToFileURL(path).href)
}
Expand All @@ -998,11 +1008,13 @@ export default async function loadConfig(
return userConfigModule
}
} catch (err) {
// TODO: Modify docs to add cases of failing next.config.ts transformation
curLog.error(
`Failed to load ${configFileName}, see more info here https://nextjs.org/docs/messages/next-config-error`
)
throw err
}

const userConfig = await normalizeConfig(
phase,
userConfigModule.default || userConfigModule
Expand Down Expand Up @@ -1105,20 +1117,19 @@ export default async function loadConfig(
return completeConfig
} else {
const configBaseName = basename(CONFIG_FILES[0], extname(CONFIG_FILES[0]))
const nonJsPath = findUp.sync(
const unsupportedConfig = findUp.sync(
[
`${configBaseName}.jsx`,
`${configBaseName}.ts`,
`${configBaseName}.tsx`,
`${configBaseName}.json`,
],
{ cwd: dir }
)
if (nonJsPath?.length) {
if (unsupportedConfig?.length) {
throw new Error(
`Configuring Next.js via '${basename(
nonJsPath
)}' is not supported. Please replace the file with 'next.config.js' or 'next.config.mjs'.`
unsupportedConfig
)}' is not supported. Please replace the file with 'next.config.js', 'next.config.mjs', or 'next.config.ts'.`
devjiwonchoi marked this conversation as resolved.
Show resolved Hide resolved
)
}
}
Expand Down
6 changes: 5 additions & 1 deletion packages/next/src/shared/lib/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,11 @@ export const DEV_MIDDLEWARE_MANIFEST = '_devMiddlewareManifest.json'
export const REACT_LOADABLE_MANIFEST = 'react-loadable-manifest.json'
export const AUTOMATIC_FONT_OPTIMIZATION_MANIFEST = 'font-manifest.json'
export const SERVER_DIRECTORY = 'server'
export const CONFIG_FILES = ['next.config.js', 'next.config.mjs']
export const CONFIG_FILES = [
'next.config.js',
'next.config.mjs',
'next.config.ts',
]
export const BUILD_ID_FILE = 'BUILD_ID'
export const BLOCKED_PAGES = ['/_document', '/_app', '/_error']
export const CLIENT_PUBLIC_FILES_PATH = 'public'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export default function Root({ children }: { children: React.ReactNode }) {
return (
<html>
<body>{children}</body>
</html>
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default function Page() {
return <p>{process.env.foo}</p>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { nextTestSetup } from 'e2e-utils'

describe('next-config-ts-config-as-async-function', () => {
const { next } = nextTestSetup({
files: __dirname,
})

it('should support config as async function', async () => {
const $ = await next.render$('/')
expect($('p').text()).toBe('foo')
})
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import type { NextConfig } from 'next'

const nextConfigAsyncFunction = async (phase, { defaultConfig }) => {
const nextConfig: NextConfig = {
...defaultConfig,
env: {
foo: phase ? 'foo' : 'bar',
},
}
return nextConfig
}

export default nextConfigAsyncFunction
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export default function Root({ children }: { children: React.ReactNode }) {
return (
<html>
<body>{children}</body>
</html>
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default function Page() {
return <p>{process.env.foo}</p>
}
12 changes: 12 additions & 0 deletions test/e2e/app-dir/next-config-ts/export-as-default/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { nextTestSetup } from 'e2e-utils'

describe('next-config-ts-export-as-default', () => {
const { next } = nextTestSetup({
files: __dirname,
})

it('should support export { x as default }', async () => {
const $ = await next.render$('/')
expect($('p').text()).toBe('foo')
})
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import type { NextConfig } from 'next'

const nextConfig: NextConfig = {
env: {
foo: 'foo',
},
}

export { nextConfig as default }
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export default function Root({ children }: { children: React.ReactNode }) {
return (
<html>
<body>{children}</body>
</html>
)
}
3 changes: 3 additions & 0 deletions test/e2e/app-dir/next-config-ts/export-default/app/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default function Page() {
return <p>{process.env.foo}</p>
}
12 changes: 12 additions & 0 deletions test/e2e/app-dir/next-config-ts/export-default/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { nextTestSetup } from 'e2e-utils'

describe('next-config-ts-export-default', () => {
const { next } = nextTestSetup({
files: __dirname,
})

it('should support export default { ... }', async () => {
const $ = await next.render$('/')
expect($('p').text()).toBe('foo')
})
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import type { NextConfig } from 'next'

export default {
env: {
foo: 'foo',
},
} satisfies NextConfig
1 change: 1 addition & 0 deletions test/e2e/app-dir/next-config-ts/import-alias/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
!tsconfig.json
1 change: 1 addition & 0 deletions test/e2e/app-dir/next-config-ts/import-alias/bar.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const bar = 'bar'
12 changes: 12 additions & 0 deletions test/e2e/app-dir/next-config-ts/import-alias/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { nextTestSetup } from 'e2e-utils'

describe('next-config-ts-import-alias', () => {
const { next } = nextTestSetup({
files: __dirname,
})

it('should support import alias', async () => {
const $ = await next.render$('/')
expect($('p').text()).toBe('foobar')
})
})
12 changes: 12 additions & 0 deletions test/e2e/app-dir/next-config-ts/import-alias/next.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import type { NextConfig } from 'next'
import { foo } from '@/foo'
import { bar } from 'bar'

const nextConfig: NextConfig = {
env: {
foo,
bar,
},
}

export default nextConfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export default function Root({ children }: { children: React.ReactNode }) {
return (
<html>
<body>{children}</body>
</html>
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default function Page() {
return <p>{`${process.env.foo + process.env.bar}`}</p>
}
1 change: 1 addition & 0 deletions test/e2e/app-dir/next-config-ts/import-alias/src/foo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const foo = 'foo'
13 changes: 13 additions & 0 deletions test/e2e/app-dir/next-config-ts/import-alias/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/**
* comment
*/
{
"compilerOptions": {
"jsx": "preserve",
/* comment */
"baseUrl": ".",
"paths": {
"@/*": ["./src/*"] // comment
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export default function Root({ children }: { children: React.ReactNode }) {
return (
<html>
<body>{children}</body>
</html>
)
}