Skip to content

Commit ad197f7

Browse files
authored
fix: fix incorrect dev config types, dev regression (#7135)
The regression was introduced here: https://github.com/netlify/cli/pull/7112/files#r2005549184. This was introduced because the `DevConfig` type was incorrect and the weak type assertion (and general type weakness in this codebase) allowed it. This also fixes a few nearby type isues.
1 parent 0e6291d commit ad197f7

File tree

5 files changed

+19
-27
lines changed

5 files changed

+19
-27
lines changed

src/commands/dev/dev.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ export const dev = async (options: OptionValues, command: BaseCommand) => {
9292
const { api, cachedConfig, config, repositoryRoot, site, siteInfo, state } = command.netlify
9393
config.dev = { ...config.dev }
9494
config.build = { ...config.build }
95-
const devConfig = {
95+
const devConfig: DevConfig = {
9696
framework: '#auto',
9797
autoLaunch: Boolean(options.open),
9898
...(cachedConfig.siteInfo?.dev_server_settings && {
@@ -104,7 +104,7 @@ export const dev = async (options: OptionValues, command: BaseCommand) => {
104104
...(config.build.base && { base: config.build.base }),
105105
...config.dev,
106106
...options,
107-
} as DevConfig
107+
}
108108

109109
let { env } = cachedConfig
110110

src/commands/dev/types.d.ts

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { PollingStrategy, NetlifyTOML } from '@netlify/build-info'
1+
import type { NetlifyTOML } from '@netlify/build-info'
22

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

@@ -8,23 +8,14 @@ export type BuildConfig = NonNullable<NetlifyTOML['build']>
88
export type DevConfig = NonNullable<NetlifyTOML['dev']> & {
99
framework: FrameworkNames
1010
/** Directory of the functions */
11-
functions?: string
12-
publish?: string
13-
/** Port to serve the functions */
14-
port: number
15-
live: boolean
11+
functions?: string | undefined
12+
live?: boolean | undefined
1613
/** The base directory from the [build] section of the configuration file */
17-
base?: string
18-
staticServerPort?: number
19-
functionsPort?: number
20-
autoLaunch?: boolean
21-
https?: {
22-
keyFile: string
23-
certFile: string
24-
}
25-
envFiles?: string[]
14+
base?: string | undefined
15+
staticServerPort?: number | undefined
16+
envFiles?: string[] | undefined
2617

27-
jwtSecret: string
28-
jwtRolePath: string
29-
pollingStrategies?: PollingStrategy[]
18+
jwtSecret?: string | undefined
19+
jwtRolePath?: string | undefined
20+
pollingStrategies?: string[] | undefined
3021
}

src/commands/serve/serve.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export const serve = async (options: OptionValues, command: BaseCommand) => {
3737
const { api, cachedConfig, config, frameworksAPIPaths, repositoryRoot, site, siteInfo, state } = command.netlify
3838
config.dev = { ...config.dev }
3939
config.build = { ...config.build }
40-
const devConfig = {
40+
const devConfig: DevConfig = {
4141
...(config.functionsDirectory && { functions: config.functionsDirectory }),
4242
...(config.build.publish && { publish: config.build.publish }),
4343

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

5151
let { env } = cachedConfig
5252

src/utils/detect-server-settings.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ const handleCustomFramework = ({
193193
frameworkPort: devConfig.targetPort,
194194
dist: devConfig.publish || getDefaultDist(workingDir),
195195
framework: '#custom',
196-
pollingStrategies: devConfig.pollingStrategies?.map((s) => s.name) ?? [],
196+
pollingStrategies: devConfig.pollingStrategies ?? [],
197197
}
198198
}
199199

src/utils/types.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
import { Buffer } from 'buffer'
2-
import { IncomingMessage } from 'http'
1+
import type { Buffer } from 'buffer'
2+
import type { IncomingMessage } from 'http'
33

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

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

@@ -12,7 +13,7 @@ export type FrameworkInfo = {
1213
dev: {
1314
commands: string[]
1415
port: number
15-
pollingStrategies: { name: string }[]
16+
pollingStrategies: PollingStrategy[]
1617
}
1718
name: FrameworkNames
1819
staticAssetsDirectory: string

0 commit comments

Comments
 (0)