Skip to content
Closed
2 changes: 1 addition & 1 deletion packages/next/build/generate-build-id.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export async function generateBuildId(
generate: () => string | null,
generate: () => string | null | Promise<string>,
fallback: () => string
): Promise<string> {
let buildId = await generate()
Expand Down
72 changes: 67 additions & 5 deletions packages/next/next-server/server/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,73 @@ import { basename, extname } from 'path'
import { CONFIG_FILE } from '../lib/constants'
import { execOnce } from '../lib/utils'
import * as Log from '../../build/output/log'
import webpack from 'webpack'

const targets = ['server', 'serverless', 'experimental-serverless-trace']
const reactModes = ['legacy', 'blocking', 'concurrent']

const defaultConfig: { [key: string]: any } = {
type ExportPathMap = {
[page: string]: { page: string; query?: { [key: string]: string } }
}

type Webpack = (
config: webpack.Configuration,
{
dir,
dev,
isServer,
buildId,
}: { dir: string; dev: boolean; isServer: boolean; buildId: boolean }
) => webpack.Configuration | Promise<webpack.Configuration>
type WebpackDevMiddleware = (
config: webpack.Configuration
) => webpack.Configuration

export interface IIndexable {
[key: string]: any
}

interface Config extends IIndexable {
env: { [key: string]: any }
webpack: Webpack | null
webpackDevMiddleware: WebpackDevMiddleware | null
distDir: string
assetPrefix: string
configOrigin: string
useFileSystemPublicRoutes: boolean
generateBuildId: () => string | null | Promise<string>
generateEtags: boolean
pageExtensions: string[]
target: 'server' | 'serverless'
poweredByHeader: boolean
compress: boolean
devIndicators: {
buildActivity: boolean
autoPrerender: boolean
}
onDemandEntries: {
maxInactiveAge: number
pagesBufferLength: number
}
amp: {
canonicalBase: string
}
exportTrailingSlash: boolean
sassOptions: object
experimental: { [key: string]: any }
future: {
excludeDefaultMomentLocales: boolean
}
serverRuntimeConfig: object
publicRuntimeConfig: object
reactStrictMode: boolean
exportPathMap?: (defaultMap: ExportPathMap) => ExportPathMap
typescript?: {
ignoreBuildErrors: boolean
}
}

const defaultConfig: Config = {
env: [],
webpack: null,
webpackDevMiddleware: null,
Expand Down Expand Up @@ -194,7 +256,7 @@ function assignDefaults(userConfig: { [key: string]: any }) {
return result
}

export function normalizeConfig(phase: string, config: any) {
export function normalizeConfig(phase: string, config: Config | any): Config {
if (typeof config === 'function') {
config = config(phase, { defaultConfig })

Expand All @@ -210,8 +272,8 @@ export function normalizeConfig(phase: string, config: any) {
export default function loadConfig(
phase: string,
dir: string,
customConfig?: object | null
) {
customConfig?: Config | null
): Config {
if (customConfig) {
return assignDefaults({ configOrigin: 'server', ...customConfig })
}
Expand Down Expand Up @@ -286,7 +348,7 @@ export default function loadConfig(
return defaultConfig
}

export function isTargetLikeServerless(target: string) {
export function isTargetLikeServerless(target: string): boolean {
const isServerless = target === 'serverless'
const isServerlessTrace = target === 'experimental-serverless-trace'
return isServerless || isServerlessTrace
Expand Down