Skip to content

Commit

Permalink
fix: prevent bundling of ZodError type
Browse files Browse the repository at this point in the history
  • Loading branch information
SukkaW committed Oct 5, 2023
1 parent f70caa2 commit c7a1b0e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 20 deletions.
16 changes: 0 additions & 16 deletions packages/next/src/server/config-shared.ts
Expand Up @@ -10,7 +10,6 @@ import { SubresourceIntegrityAlgorithm } from '../build/webpack/plugins/subresou
import { WEB_VITALS } from '../shared/lib/utils'
import type { NextParsedUrlQuery } from './request-meta'
import { SizeLimit } from '../../types'
import type { ZodError } from 'zod'

export type NextConfigComplete = Required<NextConfig> & {
images: Required<ImageConfigComplete>
Expand Down Expand Up @@ -781,18 +780,3 @@ export async function normalizeConfig(phase: string, config: any) {
// Support `new Promise` and `async () =>` as return values of the config export
return await config
}

export function validateConfig(userConfig: NextConfig): ZodError | null {
if (process.env.NEXT_MINIMAL) {
return null
}

const { configSchema } =
require('./config-schema') as typeof import('./config-schema')
const state = configSchema.safeParse(userConfig)
if (state.success) {
return null
}

return state.error
}
9 changes: 5 additions & 4 deletions packages/next/src/server/config.ts
Expand Up @@ -9,7 +9,6 @@ import {
normalizeConfig,
ExperimentalConfig,
NextConfigComplete,
validateConfig,
NextConfig,
TurboLoaderItem,
} from './config-shared'
Expand Down Expand Up @@ -955,13 +954,15 @@ export default async function loadConfig(
userConfigModule.default || userConfigModule
)

const validateError = validateConfig(userConfig)
const { configSchema } =
require('./config-schema') as typeof import('./config-schema')
const state = configSchema.safeParse(userConfig)

if (validateError) {
if (!state.success) {
// error message header
const messages = [`Invalid ${configFileName} options detected: `]

const [errorMessages, shouldExit] = normalizeZodErrors(validateError)
const [errorMessages, shouldExit] = normalizeZodErrors(state.error)
// ident list item
for (const error of errorMessages) {
messages.push(` ${error}`)
Expand Down

0 comments on commit c7a1b0e

Please sign in to comment.