From e7a96e18bce3973cfa625506bbb822d2e7f2e84b Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Thu, 29 Jan 2026 16:36:10 +0000 Subject: [PATCH] fix(types): improve type safety in server settings detection Replaced an 'any' type with BaseServerSettings in src/utils/detect-server-settings.ts. The stricter typing required refactoring the control flow, which also fixed a latent bug where an undefined framework would not be handled correctly, defaulting now to '#auto'. Co-authored-by: serhalp <1377702+serhalp@users.noreply.github.com> --- src/utils/detect-server-settings.ts | 38 ++++++++++++++--------------- 1 file changed, 18 insertions(+), 20 deletions(-) diff --git a/src/utils/detect-server-settings.ts b/src/utils/detect-server-settings.ts index 0355c4a3097..6dbe164d286 100644 --- a/src/utils/detect-server-settings.ts +++ b/src/utils/detect-server-settings.ts @@ -259,34 +259,16 @@ const detectServerSettings = async ( ): Promise => { validateProperty(devConfig, 'framework', 'string') - // eslint-disable-next-line @typescript-eslint/no-explicit-any -- TODO(serhalp): Set to `BaseServerSettings`. Good luck! - let settings: any = {} + let settings: BaseServerSettings if (flags.dir || devConfig.framework === '#static') { // serving files statically without a framework server settings = await handleStaticServer({ flags, devConfig, workingDir: command.workingDir }) - } else if (devConfig.framework === '#auto') { - // this is the default CLI behavior - - const runDetection = !hasCommandAndTargetPort(devConfig) - const frameworkSettings = runDetection - ? getSettingsFromDetectedSettings(command, await detectFrameworkSettings(command, 'dev')) - : undefined - if (frameworkSettings === undefined && runDetection) { - log(`${NETLIFYDEVWARN} No app server detected. Using simple static server`) - settings = await handleStaticServer({ flags, devConfig, workingDir: command.workingDir }) - } else { - validateFrameworkConfig({ devConfig }) - - settings = await mergeSettings({ devConfig, frameworkSettings, workingDir: command.workingDir }) - } - - settings.plugins = frameworkSettings?.plugins } else if (devConfig.framework === '#custom') { validateFrameworkConfig({ devConfig }) // when the users wants to configure `command` and `targetPort` settings = handleCustomFramework({ devConfig, workingDir: command.workingDir }) - } else if (devConfig.framework) { + } else if (devConfig.framework && devConfig.framework !== '#auto') { validateFrameworkConfig({ devConfig }) // this is when the user explicitly configures a framework, e.g. `framework = "gatsby"` settings = await handleForcedFramework({ @@ -296,6 +278,22 @@ const detectServerSettings = async ( workingDir: command.workingDir, workspacePackage: command.workspacePackage, }) + } else { + // this is the default CLI behavior (#auto or undefined) + const runDetection = !hasCommandAndTargetPort(devConfig) + const frameworkSettings = runDetection + ? getSettingsFromDetectedSettings(command, await detectFrameworkSettings(command, 'dev')) + : undefined + + if (frameworkSettings === undefined && runDetection) { + log(`${NETLIFYDEVWARN} No app server detected. Using simple static server`) + settings = await handleStaticServer({ flags, devConfig, workingDir: command.workingDir }) + } else { + validateFrameworkConfig({ devConfig }) + + const mergedSettings = await mergeSettings({ devConfig, frameworkSettings, workingDir: command.workingDir }) + settings = { ...mergedSettings, plugins: frameworkSettings?.plugins } + } } validateConfiguredPort({ devConfig, detectedPort: settings.frameworkPort })