Skip to content

fix: fix incorrect dev config types and netlify dev regression #7135

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/commands/dev/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ export const dev = async (options: OptionValues, command: BaseCommand) => {
const { api, cachedConfig, config, repositoryRoot, site, siteInfo, state } = command.netlify
config.dev = { ...config.dev }
config.build = { ...config.build }
const devConfig = {
const devConfig: DevConfig = {
framework: '#auto',
autoLaunch: Boolean(options.open),
...(cachedConfig.siteInfo?.dev_server_settings && {
Expand All @@ -104,7 +104,7 @@ export const dev = async (options: OptionValues, command: BaseCommand) => {
...(config.build.base && { base: config.build.base }),
...config.dev,
...options,
} as DevConfig
}

let { env } = cachedConfig

Expand Down
27 changes: 9 additions & 18 deletions src/commands/dev/types.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { PollingStrategy, NetlifyTOML } from '@netlify/build-info'
import type { NetlifyTOML } from '@netlify/build-info'

import type { FrameworkNames } from '../../utils/types'

Expand All @@ -8,23 +8,14 @@ export type BuildConfig = NonNullable<NetlifyTOML['build']>
export type DevConfig = NonNullable<NetlifyTOML['dev']> & {
framework: FrameworkNames
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can see here we're extending this type, but we were duplicating most of it here. Most of this diff is cleaning up this unnecessary duplication + adding undefined to optional properties.

/** Directory of the functions */
functions?: string
publish?: string
/** Port to serve the functions */
port: number
live: boolean
functions?: string | undefined
live?: boolean | undefined
/** The base directory from the [build] section of the configuration file */
base?: string
staticServerPort?: number
functionsPort?: number
autoLaunch?: boolean
https?: {
keyFile: string
certFile: string
}
envFiles?: string[]
base?: string | undefined
staticServerPort?: number | undefined
envFiles?: string[] | undefined

jwtSecret: string
jwtRolePath: string
pollingStrategies?: PollingStrategy[]
jwtSecret?: string | undefined
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

jwtRolePath?: string | undefined
pollingStrategies?: string[] | undefined
}
4 changes: 2 additions & 2 deletions src/commands/serve/serve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export const serve = async (options: OptionValues, command: BaseCommand) => {
const { api, cachedConfig, config, frameworksAPIPaths, repositoryRoot, site, siteInfo, state } = command.netlify
config.dev = { ...config.dev }
config.build = { ...config.build }
const devConfig = {
const devConfig: DevConfig = {
...(config.functionsDirectory && { functions: config.functionsDirectory }),
...(config.build.publish && { publish: config.build.publish }),

Expand All @@ -46,7 +46,7 @@ export const serve = async (options: OptionValues, command: BaseCommand) => {
// Override the `framework` value so that we start a static server and not
// the framework's development server.
framework: '#static',
} as DevConfig
}

let { env } = cachedConfig

Expand Down
2 changes: 1 addition & 1 deletion src/utils/detect-server-settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ const handleCustomFramework = ({
frameworkPort: devConfig.targetPort,
dist: devConfig.publish || getDefaultDist(workingDir),
framework: '#custom',
pollingStrategies: devConfig.pollingStrategies?.map((s) => s.name) ?? [],
pollingStrategies: devConfig.pollingStrategies ?? [],
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the regression/fix

}
}

Expand Down
9 changes: 5 additions & 4 deletions src/utils/types.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { Buffer } from 'buffer'
import { IncomingMessage } from 'http'
import type { Buffer } from 'buffer'
import type { IncomingMessage } from 'http'

import { Match } from 'netlify-redirector'
import type { PollingStrategy, Settings } from '@netlify/build-info'
import type { Match } from 'netlify-redirector'

export type FrameworkNames = '#static' | '#auto' | '#custom' | string

Expand All @@ -12,7 +13,7 @@ export type FrameworkInfo = {
dev: {
commands: string[]
port: number
pollingStrategies: { name: string }[]
pollingStrategies: PollingStrategy[]
}
Comment on lines -15 to +16
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one was correct. I made it reference the canonical type while I was here.

name: FrameworkNames
staticAssetsDirectory: string
Expand Down
Loading