Unverified Commit c6279129 authored by JJ Kasper's avatar JJ Kasper Committed by GitHub

Ensure default config passes schema checks (#46656)

This ensures our config schema correctly validates with the default
config we provide.

Fixes: https://github.com/vercel/next.js/issues/46626

## Bug

- [x] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Errors have a helpful link attached, see
[`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)
parent 5e112c06
...@@ -11,7 +11,7 @@ const configSchema = { ...@@ -11,7 +11,7 @@ const configSchema = {
additionalProperties: false, additionalProperties: false,
properties: { properties: {
canonicalBase: { canonicalBase: {
minLength: 1, nullable: true,
type: 'string', type: 'string',
}, },
}, },
...@@ -21,7 +21,7 @@ const configSchema = { ...@@ -21,7 +21,7 @@ const configSchema = {
type: 'string', type: 'string',
}, },
assetPrefix: { assetPrefix: {
minLength: 1, nullable: true,
type: 'string', type: 'string',
}, },
basePath: { basePath: {
...@@ -170,6 +170,9 @@ const configSchema = { ...@@ -170,6 +170,9 @@ const configSchema = {
compress: { compress: {
type: 'boolean', type: 'boolean',
}, },
configOrigin: {
type: 'string',
},
crossOrigin: { crossOrigin: {
oneOf: [ oneOf: [
false, false,
...@@ -342,7 +345,7 @@ const configSchema = { ...@@ -342,7 +345,7 @@ const configSchema = {
type: 'boolean', type: 'boolean',
}, },
outputFileTracingRoot: { outputFileTracingRoot: {
minLength: 1, nullable: true,
type: 'string', type: 'string',
}, },
outputFileTracingExcludes: { outputFileTracingExcludes: {
...@@ -521,6 +524,7 @@ const configSchema = { ...@@ -521,6 +524,7 @@ const configSchema = {
}, },
i18n: { i18n: {
additionalProperties: false, additionalProperties: false,
nullable: true,
properties: { properties: {
defaultLocale: { defaultLocale: {
minLength: 1, minLength: 1,
...@@ -568,17 +572,17 @@ const configSchema = { ...@@ -568,17 +572,17 @@ const configSchema = {
}, },
images: { images: {
additionalProperties: false, additionalProperties: false,
nullable: true,
properties: { properties: {
remotePatterns: { remotePatterns: {
nullable: true,
items: { items: {
additionalProperties: false, additionalProperties: false,
properties: { properties: {
hostname: { hostname: {
minLength: 1,
type: 'string', type: 'string',
}, },
pathname: { pathname: {
minLength: 1,
type: 'string', type: 'string',
}, },
port: { port: {
...@@ -601,15 +605,17 @@ const configSchema = { ...@@ -601,15 +605,17 @@ const configSchema = {
type: 'boolean', type: 'boolean',
}, },
contentSecurityPolicy: { contentSecurityPolicy: {
minLength: 1,
type: 'string', type: 'string',
nullable: true,
}, },
contentDispositionType: { contentDispositionType: {
enum: ['inline', 'attachment'] as any, // automatic typing does not like enum enum: ['inline', 'attachment'] as any, // automatic typing does not like enum
type: 'string', type: 'string',
nullable: true,
}, },
dangerouslyAllowSVG: { dangerouslyAllowSVG: {
type: 'boolean', type: 'boolean',
nullable: true,
}, },
deviceSizes: { deviceSizes: {
items: { items: {
...@@ -617,12 +623,13 @@ const configSchema = { ...@@ -617,12 +623,13 @@ const configSchema = {
minimum: 1, minimum: 1,
maximum: 10000, maximum: 10000,
}, },
minItems: 1,
maxItems: 25, maxItems: 25,
type: 'array', type: 'array',
nullable: true,
}, },
disableStaticImages: { disableStaticImages: {
type: 'boolean', type: 'boolean',
nullable: true,
}, },
domains: { domains: {
items: { items: {
...@@ -630,6 +637,7 @@ const configSchema = { ...@@ -630,6 +637,7 @@ const configSchema = {
}, },
maxItems: 50, maxItems: 50,
type: 'array', type: 'array',
nullable: true,
}, },
formats: { formats: {
items: { items: {
...@@ -638,6 +646,7 @@ const configSchema = { ...@@ -638,6 +646,7 @@ const configSchema = {
} as any, } as any,
maxItems: 4, maxItems: 4,
type: 'array', type: 'array',
nullable: true,
}, },
imageSizes: { imageSizes: {
items: { items: {
...@@ -648,23 +657,26 @@ const configSchema = { ...@@ -648,23 +657,26 @@ const configSchema = {
minItems: 0, minItems: 0,
maxItems: 25, maxItems: 25,
type: 'array', type: 'array',
nullable: true,
}, },
loader: { loader: {
// automatic typing does not like enum // automatic typing does not like enum
enum: VALID_LOADERS as any, enum: VALID_LOADERS as any,
type: 'string', type: 'string',
nullable: true,
}, },
loaderFile: { loaderFile: {
minLength: 1,
type: 'string', type: 'string',
nullable: true,
}, },
minimumCacheTTL: { minimumCacheTTL: {
type: 'integer', type: 'integer',
minimum: 0, minimum: 0,
nullable: true,
}, },
path: { path: {
minLength: 1,
type: 'string', type: 'string',
nullable: true,
}, },
}, },
type: 'object', type: 'object',
...@@ -737,6 +749,9 @@ const configSchema = { ...@@ -737,6 +749,9 @@ const configSchema = {
swcMinify: { swcMinify: {
type: 'boolean', type: 'boolean',
}, },
target: {
type: 'string',
},
trailingSlash: { trailingSlash: {
type: 'boolean', type: 'boolean',
}, },
...@@ -768,7 +783,7 @@ const configSchema = { ...@@ -768,7 +783,7 @@ const configSchema = {
'must be a function that returns a webpack configuration object', 'must be a function that returns a webpack configuration object',
} as any, } as any,
}, },
} as JSONSchemaType<NextConfig> } as JSONSchemaType<NextConfig & { configOrigin?: any; target?: any }>
// module.exports is used to get around an export bug with TypeScript // module.exports is used to get around an export bug with TypeScript
// and the Ajv automatic typing // and the Ajv automatic typing
......
...@@ -16,6 +16,7 @@ export type NextConfigComplete = Required<NextConfig> & { ...@@ -16,6 +16,7 @@ export type NextConfigComplete = Required<NextConfig> & {
configOrigin?: string configOrigin?: string
configFile?: string configFile?: string
configFileName: string configFileName: string
target?: string
} }
export interface I18NConfig { export interface I18NConfig {
...@@ -569,7 +570,6 @@ export interface NextConfig extends Record<string, any> { ...@@ -569,7 +570,6 @@ export interface NextConfig extends Record<string, any> {
export const defaultConfig: NextConfig = { export const defaultConfig: NextConfig = {
env: {}, env: {},
webpack: null, webpack: null,
webpackDevMiddleware: null,
eslint: { eslint: {
ignoreDuringBuilds: false, ignoreDuringBuilds: false,
}, },
...@@ -610,7 +610,7 @@ export const defaultConfig: NextConfig = { ...@@ -610,7 +610,7 @@ export const defaultConfig: NextConfig = {
excludeDefaultMomentLocales: true, excludeDefaultMomentLocales: true,
serverRuntimeConfig: {}, serverRuntimeConfig: {},
publicRuntimeConfig: {}, publicRuntimeConfig: {},
reactStrictMode: null, reactStrictMode: false,
httpAgentOptions: { httpAgentOptions: {
keepAlive: true, keepAlive: true,
}, },
......
...@@ -304,11 +304,11 @@ export async function compile_config_schema(task, opts) { ...@@ -304,11 +304,11 @@ export async function compile_config_schema(task, opts) {
keyword: 'isFunction', keyword: 'isFunction',
schemaType: 'boolean', schemaType: 'boolean',
compile() { compile() {
return (data) => data instanceof Function return (data) => data == null || data instanceof Function
}, },
code(ctx) { code(ctx) {
const { data } = ctx const { data } = ctx
ctx.fail(Ajv._`!(${data} instanceof Function)`) ctx.fail(Ajv._`!(${data} == null || ${data} instanceof Function)`)
}, },
metaSchema: { metaSchema: {
anyOf: [{ type: 'boolean' }], anyOf: [{ type: 'boolean' }],
......
module.exports = (phase, { defaultConfig }) => {
return defaultConfig
}
export default function Page() {
return <p>hello world</p>
}
/* eslint-env jest */
import { join } from 'path'
import { nextBuild } from 'next-test-utils'
import stripAnsi from 'strip-ansi'
const appDir = join(__dirname, '../')
describe('next.config.js schema validating', () => {
it('should validate against defaultConfig', async () => {
const result = await nextBuild(appDir, undefined, {
stderr: true,
stdout: true,
})
const output = stripAnsi(result.stderr + result.stdout)
expect(output).not.toContain('Invalid next.config.js options detected')
expect(result.code).toBe(0)
})
})
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment