Skip to content
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

feat: allow skipping the target port wait #6472

Merged
merged 2 commits into from
Mar 26, 2024
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
1 change: 1 addition & 0 deletions docs/commands/dev.md
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Loading