Home / Function/ startedOnPort() — vite Function Reference

startedOnPort() — vite Function Reference

Architecture documentation for the startedOnPort() function in serve.ts from the vite codebase.

Entity Profile

Dependency Diagram

graph TD
  fe3d154a_8fd8_adee_8784_8a0d58dd4c70["startedOnPort()"]
  f7b3d158_cef2_c5d6_e1e9_618c0b12e5a8["serve.ts"]
  fe3d154a_8fd8_adee_8784_8a0d58dd4c70 -->|defined in| f7b3d158_cef2_c5d6_e1e9_618c0b12e5a8
  f797f934_0de5_e01d_8e86_ee712b506fda["serve()"]
  f797f934_0de5_e01d_8e86_ee712b506fda -->|calls| fe3d154a_8fd8_adee_8784_8a0d58dd4c70
  32dae94d_4e52_4562_6377_73438c721fcb["resolvedOrTimeout()"]
  fe3d154a_8fd8_adee_8784_8a0d58dd4c70 -->|calls| 32dae94d_4e52_4562_6377_73438c721fcb
  style fe3d154a_8fd8_adee_8784_8a0d58dd4c70 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

playground/cli-module/__tests__/serve.ts lines 117–142

async function startedOnPort(serverProcess, port, timeout) {
  let checkPort
  const startedPromise = new Promise<void>((resolve, reject) => {
    checkPort = (data) => {
      const str = stripVTControlCharacters(data.toString())
      const match = str.match(
        /http:\/\/(?:localhost|127\.0\.0\.1|\[::1\]):(\d{4})/,
      )
      if (match) {
        const startedPort = parseInt(match[1], 10)
        if (startedPort === port) {
          resolve()
        } else {
          const msg = `server listens on port ${startedPort} instead of ${port}`
          reject(msg)
        }
      }
    }
    serverProcess.stdout.on('data', checkPort)
  })
  return resolvedOrTimeout(
    startedPromise,
    timeout,
    `failed to start within ${timeout}ms`,
  ).finally(() => serverProcess.stdout.off('data', checkPort))
}

Domain

Subdomains

Called By

Frequently Asked Questions

What does startedOnPort() do?
startedOnPort() is a function in the vite codebase, defined in playground/cli-module/__tests__/serve.ts.
Where is startedOnPort() defined?
startedOnPort() is defined in playground/cli-module/__tests__/serve.ts at line 117.
What does startedOnPort() call?
startedOnPort() calls 1 function(s): resolvedOrTimeout.
What calls startedOnPort()?
startedOnPort() is called by 1 function(s): serve.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free