diff --git a/packages/next/build/generate-build-id.ts b/packages/next/build/generate-build-id.ts index 0f9de31c1ddb4..884ed5e062219 100644 --- a/packages/next/build/generate-build-id.ts +++ b/packages/next/build/generate-build-id.ts @@ -1,5 +1,5 @@ export async function generateBuildId( - generate: () => string | null, + generate: () => string | null | Promise, fallback: () => string ): Promise { let buildId = await generate() diff --git a/packages/next/next-server/server/config.ts b/packages/next/next-server/server/config.ts index 9e0487e29c5ab..8980711d9d7a8 100644 --- a/packages/next/next-server/server/config.ts +++ b/packages/next/next-server/server/config.ts @@ -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 +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 + 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, @@ -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 }) @@ -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 }) } @@ -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