From ebd214e7fe233a49d7c08ed27fcd198bc72e2b76 Mon Sep 17 00:00:00 2001 From: David Berlin Date: Tue, 26 Mar 2024 12:03:32 +0200 Subject: [PATCH 1/4] feat: allow skipping the target port wait --- src/commands/dev/dev.ts | 1 + src/utils/framework-server.ts | 27 +++++++++++++++------------ src/utils/run-build.ts | 1 + src/utils/types.ts | 1 + 4 files changed, 18 insertions(+), 12 deletions(-) diff --git a/src/commands/dev/dev.ts b/src/commands/dev/dev.ts index 165cdc8f819..6731c551b1d 100644 --- a/src/commands/dev/dev.ts +++ b/src/commands/dev/dev.ts @@ -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 of target app server', (value) => Number.parseInt(value)) .option('--framework ', 'framework to use. Defaults to #auto which automatically detects a framework') diff --git a/src/utils/framework-server.ts b/src/utils/framework-server.ts index 8d7ed452f74..706a3907950 100644 --- a/src/utils/framework-server.ts +++ b/src/utils/framework-server.ts @@ -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_) { diff --git a/src/utils/run-build.ts b/src/utils/run-build.ts index aefe93d88cf..8a118f94c7c 100644 --- a/src/utils/run-build.ts +++ b/src/utils/run-build.ts @@ -98,6 +98,7 @@ export const runNetlifyBuild = async ({ settings: { ...settings, ...settingsOverrides, + ...(options.skipWaitPort ? { skipWaitPort: true } : {}), }, cwd, }) diff --git a/src/utils/types.ts b/src/utils/types.ts index 22ff19ab3af..95f1b5266ba 100644 --- a/src/utils/types.ts +++ b/src/utils/types.ts @@ -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 { From 56cb18e3d395747e63a6de7bb4e9e3571c479f3c Mon Sep 17 00:00:00 2001 From: David Berlin Date: Tue, 26 Mar 2024 12:30:50 +0200 Subject: [PATCH 2/4] fix: sync docs --- docs/commands/dev.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/commands/dev.md b/docs/commands/dev.md index 2db13187129..fc57cebb273 100644 --- a/docs/commands/dev.md +++ b/docs/commands/dev.md @@ -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 From 8a8c57c1f4e4af0143a47e97033bddf7edb0b21e Mon Sep 17 00:00:00 2001 From: David Berlin Date: Wed, 27 Mar 2024 09:57:05 +0200 Subject: [PATCH 3/4] fix: remove skipWaitPort from help and docs --- docs/commands/dev.md | 1 - src/commands/dev/dev.ts | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/docs/commands/dev.md b/docs/commands/dev.md index fc57cebb273..2db13187129 100644 --- a/docs/commands/dev.md +++ b/docs/commands/dev.md @@ -32,7 +32,6 @@ 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 diff --git a/src/commands/dev/dev.ts b/src/commands/dev/dev.ts index 6731c551b1d..5dc38e256d0 100644 --- a/src/commands/dev/dev.ts +++ b/src/commands/dev/dev.ts @@ -264,7 +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('--skip-wait-port', 'disables waiting for target port to become available').hideHelp(true)) .addOption(new Option('--no-open', 'disables the automatic opening of a browser window')) .option('--target-port ', 'port of target app server', (value) => Number.parseInt(value)) .option('--framework ', 'framework to use. Defaults to #auto which automatically detects a framework') From 9961f3718cc2a24148994a026e8732ce4f149d2c Mon Sep 17 00:00:00 2001 From: David Berlin Date: Wed, 27 Mar 2024 10:02:08 +0200 Subject: [PATCH 4/4] fix: sync docs --- docs/commands/dev.md | 1 - 1 file changed, 1 deletion(-) diff --git a/docs/commands/dev.md b/docs/commands/dev.md index fc57cebb273..2db13187129 100644 --- a/docs/commands/dev.md +++ b/docs/commands/dev.md @@ -32,7 +32,6 @@ 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