diff --git a/scripts/tasks/dev.ts b/scripts/tasks/dev.ts index 71c0bc8f6a0c..268e8d1862ec 100644 --- a/scripts/tasks/dev.ts +++ b/scripts/tasks/dev.ts @@ -1,4 +1,3 @@ -import detectFreePort from 'detect-port'; import waitOn from 'wait-on'; import type { AllTemplatesKey } from '../../code/lib/cli-storybook/src/sandbox-templates'; @@ -21,7 +20,12 @@ export const dev: Task = { dependsOn: ['sandbox'], async ready({ key }) { const port = getDevPort(key); - return (await detectFreePort(port)) !== port; + try { + await fetch(`http://localhost:${port}/iframe.html`, { signal: AbortSignal.timeout(1000) }); + return true; + } catch { + return false; + } }, async run({ sandboxDir, key, selectedTask }, { dryRun, debug }) { const controller = new AbortController(); diff --git a/scripts/tasks/serve.ts b/scripts/tasks/serve.ts index 05e80006d620..6a5ee9513ceb 100644 --- a/scripts/tasks/serve.ts +++ b/scripts/tasks/serve.ts @@ -1,4 +1,3 @@ -import detectFreePort from 'detect-port'; import waitOn from 'wait-on'; import type { AllTemplatesKey } from '../../code/lib/cli-storybook/src/sandbox-templates'; @@ -21,7 +20,12 @@ export const serve: Task = { dependsOn: ['build'], async ready({ key }) { const port = getServePort(key); - return (await detectFreePort(port)) !== port; + try { + await fetch(`http://localhost:${port}/iframe.html`, { signal: AbortSignal.timeout(1000) }); + return true; + } catch { + return false; + } }, async run({ builtSandboxDir, key }, { debug, dryRun }) { const port = getServePort(key);