* Assigns defaults to the user config and validates the config. * * @param dir - The directory of the project. * @param userConfig - The user config. * @param silent - Whether to suppress warnings. * @returns The complete config.
(
dir: string,
userConfig: NextConfig & { configFileName: string },
silent: boolean,
phase: PHASE_TYPE
)
| 273 | * @returns The complete config. |
| 274 | */ |
| 275 | function assignDefaultsAndValidate( |
| 276 | dir: string, |
| 277 | userConfig: NextConfig & { configFileName: string }, |
| 278 | silent: boolean, |
| 279 | phase: PHASE_TYPE |
| 280 | ): NextConfigComplete { |
| 281 | const configFileName = userConfig.configFileName |
| 282 | if (typeof (userConfig as any).exportTrailingSlash !== 'undefined') { |
| 283 | if (!silent) { |
| 284 | Log.warn( |
| 285 | `The "exportTrailingSlash" option has been renamed to "trailingSlash". Please update your ${configFileName}.` |
| 286 | ) |
| 287 | } |
| 288 | if (typeof userConfig.trailingSlash === 'undefined') { |
| 289 | userConfig.trailingSlash = (userConfig as any).exportTrailingSlash |
| 290 | } |
| 291 | delete (userConfig as any).exportTrailingSlash |
| 292 | } |
| 293 | |
| 294 | const config = Object.keys(userConfig).reduce<{ [key: string]: any }>( |
| 295 | (currentConfig, key) => { |
| 296 | const value = (userConfig as any)[key] |
| 297 | |
| 298 | if (value === undefined || value === null) { |
| 299 | return currentConfig |
| 300 | } |
| 301 | |
| 302 | if (key === 'distDir') { |
| 303 | if (typeof value !== 'string') { |
| 304 | throw new Error( |
| 305 | `Specified distDir is not a string, found type "${typeof value}"` |
| 306 | ) |
| 307 | } |
| 308 | const userDistDir = value.trim() |
| 309 | |
| 310 | // don't allow public as the distDir as this is a reserved folder for |
| 311 | // public files |
| 312 | if (userDistDir === 'public') { |
| 313 | throw new Error( |
| 314 | `The 'public' directory is reserved in Next.js and can not be set as the 'distDir'. https://nextjs.org/docs/messages/can-not-output-to-public` |
| 315 | ) |
| 316 | } |
| 317 | // make sure distDir isn't an empty string as it can result in the provided |
| 318 | // directory being deleted in development mode |
| 319 | if (userDistDir.length === 0) { |
| 320 | throw new Error( |
| 321 | `Invalid distDir provided, distDir can not be an empty string. Please remove this config or set it to undefined` |
| 322 | ) |
| 323 | } |
| 324 | } |
| 325 | |
| 326 | if (key === 'pageExtensions') { |
| 327 | if (!Array.isArray(value)) { |
| 328 | throw new Error( |
| 329 | `Specified pageExtensions is not an array of strings, found "${value}". Please update this config or remove it.` |
| 330 | ) |
| 331 | } |
| 332 |
no test coverage detected