Home / File/ serve.ts — vite Source File

serve.ts — vite Source File

Architecture documentation for serve.ts, a typescript file in the vite codebase. 4 imports, 1 dependents.

File typescript ViteCore ConfigEngine 4 imports 1 dependents 3 functions

Entity Profile

Dependency Diagram

graph LR
  f7b3d158_cef2_c5d6_e1e9_618c0b12e5a8["serve.ts"]
  10809968_066c_58db_f8b4_cb0464da805e["node:util"]
  f7b3d158_cef2_c5d6_e1e9_618c0b12e5a8 --> 10809968_066c_58db_f8b4_cb0464da805e
  e4bc57e8_546b_c84b_ee54_df323bec2a01["execa"]
  f7b3d158_cef2_c5d6_e1e9_618c0b12e5a8 --> e4bc57e8_546b_c84b_ee54_df323bec2a01
  c61c7da5_ab1b_2881_075e_127cc87cab93["kill-port"]
  f7b3d158_cef2_c5d6_e1e9_618c0b12e5a8 --> c61c7da5_ab1b_2881_075e_127cc87cab93
  d3fd5575_295b_d6be_24dd_62d277645dc9["~utils"]
  f7b3d158_cef2_c5d6_e1e9_618c0b12e5a8 --> d3fd5575_295b_d6be_24dd_62d277645dc9
  969881f2_5b11_837d_716a_e199f79f88d1["cli-module.spec.ts"]
  969881f2_5b11_837d_716a_e199f79f88d1 --> f7b3d158_cef2_c5d6_e1e9_618c0b12e5a8
  style f7b3d158_cef2_c5d6_e1e9_618c0b12e5a8 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

// this is automatically detected by playground/vitestSetup.ts and will replace
// the default e2e test serve behavior

import { stripVTControlCharacters } from 'node:util'
import { execaCommand } from 'execa'
import kill from 'kill-port'
import {
  isBuild,
  isWindows,
  killProcess,
  ports,
  rootDir,
  viteBinPath,
} from '~utils'

export const port = ports['cli-module']

export async function serve() {
  // collect stdout and stderr streams from child processes here to avoid interfering with regular vitest output
  const streams = {
    build: { out: [], err: [] },
    server: { out: [], err: [] },
  }
  // helpers to collect streams
  const collectStreams = (name, process) => {
    process.stdout.on('data', (d) => streams[name].out.push(d.toString()))
    process.stderr.on('data', (d) => streams[name].err.push(d.toString()))
  }
  const collectErrorStreams = (name, e) => {
    e.stdout && streams[name].out.push(e.stdout)
    e.stderr && streams[name].err.push(e.stderr)
  }

  // helper to output stream content on error
  const printStreamsToConsole = async (name) => {
    const std = streams[name]
    if (std.out && std.out.length > 0) {
      console.log(`stdout of ${name}\n${std.out.join('\n')}\n`)
    }
    if (std.err && std.err.length > 0) {
      console.log(`stderr of ${name}\n${std.err.join('\n')}\n`)
    }
  }

  // only run `vite build` when needed
  if (isBuild) {
    const buildCommand = `${viteBinPath} build`
    try {
      const buildProcess = execaCommand(buildCommand, {
        cwd: rootDir,
        stdio: 'pipe',
      })
      collectStreams('build', buildProcess)
      await buildProcess
    } catch (e) {
      console.error(`error while executing cli command "${buildCommand}":`, e)
      collectErrorStreams('build', e)
      await printStreamsToConsole('build')
      throw e
    }
// ... (97 more lines)

Domain

Subdomains

Dependencies

  • execa
  • kill-port
  • node:util
  • ~utils

Frequently Asked Questions

What does serve.ts do?
serve.ts is a source file in the vite codebase, written in typescript. It belongs to the ViteCore domain, ConfigEngine subdomain.
What functions are defined in serve.ts?
serve.ts defines 3 function(s): resolvedOrTimeout, serve, startedOnPort.
What does serve.ts depend on?
serve.ts imports 4 module(s): execa, kill-port, node:util, ~utils.
What files import serve.ts?
serve.ts is imported by 1 file(s): cli-module.spec.ts.
Where is serve.ts in the architecture?
serve.ts is located at playground/cli-module/__tests__/serve.ts (domain: ViteCore, subdomain: ConfigEngine, directory: playground/cli-module/__tests__).

Analyze Your Own Codebase

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

Try Supermodel Free