Skip to content

Commit

Permalink
feat: allow skipping the target port wait (#6472)
Browse files Browse the repository at this point in the history
allow skipping the target port wait
  • Loading branch information
davbree committed Mar 26, 2024
1 parent cd19d2b commit cfa8e2b
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 12 deletions.
1 change: 1 addition & 0 deletions docs/commands/dev.md
Expand Up @@ -32,6 +32,7 @@ netlify dev
- `no-open` (*boolean*) - disables the automatic opening of a browser window
- `offline` (*boolean*) - disables any features that require network access
- `port` (*string*) - port of netlify dev
- `skip-wait-port` (*boolean*) - disables waiting for target port to become available
- `target-port` (*string*) - port of target app server
- `debug` (*boolean*) - Print debugging information

Expand Down
1 change: 1 addition & 0 deletions src/commands/dev/dev.ts
Expand Up @@ -264,6 +264,7 @@ export const createDevCommand = (program: BaseCommand) => {
.argParser((value) => Number.parseInt(value))
.hideHelp(true),
)
.option('--skip-wait-port', 'disables waiting for target port to become available')
.addOption(new Option('--no-open', 'disables the automatic opening of a browser window'))
.option('--target-port <port>', 'port of target app server', (value) => Number.parseInt(value))
.option('--framework <name>', 'framework to use. Defaults to #auto which automatically detects a framework')
Expand Down
27 changes: 15 additions & 12 deletions src/utils/framework-server.ts
Expand Up @@ -47,21 +47,24 @@ export const startFrameworkServer = async function ({

runCommand(settings.command, { env: settings.env, spinner, cwd })

let port
let port: { open: boolean; ipVersion?: 4 | 6 } | undefined
try {
port = await waitPort({
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
port: settings.frameworkPort!,
host: 'localhost',
output: 'silent',
timeout: FRAMEWORK_PORT_TIMEOUT,
...(settings.pollingStrategies?.includes('HTTP') && { protocol: 'http' }),
})
if (settings.skipWaitPort) {
port = { open: true, ipVersion: 6 }
} else {
port = await waitPort({
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
port: settings.frameworkPort!,
host: 'localhost',
output: 'silent',
timeout: FRAMEWORK_PORT_TIMEOUT,
...(settings.pollingStrategies?.includes('HTTP') && { protocol: 'http' }),
})

if (!port.open) {
throw new Error(`Timed out waiting for port '${settings.frameworkPort}' to be open`)
if (!port.open) {
throw new Error(`Timed out waiting for port '${settings.frameworkPort}' to be open`)
}
}

// @ts-expect-error TS(2345) FIXME: Argument of type '{ error: boolean; spinner: Ora; ... Remove this comment to see the full error message
stopSpinner({ error: false, spinner })
} catch (error_) {
Expand Down
1 change: 1 addition & 0 deletions src/utils/run-build.ts
Expand Up @@ -98,6 +98,7 @@ export const runNetlifyBuild = async ({
settings: {
...settings,
...settingsOverrides,
...(options.skipWaitPort ? { skipWaitPort: true } : {}),
},
cwd,
})
Expand Down
1 change: 1 addition & 0 deletions src/utils/types.ts
Expand Up @@ -52,6 +52,7 @@ export type ServerSettings = BaseServerSettings & {
functionsPort: number
https?: { key: string; cert: string; keyFilePath: string; certFilePath: string }
clearPublishDirectory?: boolean
skipWaitPort?: boolean
}

export interface Request extends IncomingMessage {
Expand Down

2 comments on commit cfa8e2b

@github-actions
Copy link

Choose a reason for hiding this comment

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

📊 Benchmark results

  • Dependency count: 1,328
  • Package size: 298 MB
  • Number of ts-expect-error directives: 1,029

@github-actions
Copy link

Choose a reason for hiding this comment

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

📊 Benchmark results

  • Dependency count: 1,328
  • Package size: 298 MB
  • Number of ts-expect-error directives: 1,029

Please sign in to comment.