serve.ts — vite Source File
Architecture documentation for serve.ts, a typescript file in the vite codebase. 4 imports, 1 dependents.
Entity Profile
Dependency Diagram
graph LR ef6fee49_c1b8_1e5b_85c2_51741ccb23ee["serve.ts"] 10809968_066c_58db_f8b4_cb0464da805e["node:util"] ef6fee49_c1b8_1e5b_85c2_51741ccb23ee --> 10809968_066c_58db_f8b4_cb0464da805e e4bc57e8_546b_c84b_ee54_df323bec2a01["execa"] ef6fee49_c1b8_1e5b_85c2_51741ccb23ee --> e4bc57e8_546b_c84b_ee54_df323bec2a01 c61c7da5_ab1b_2881_075e_127cc87cab93["kill-port"] ef6fee49_c1b8_1e5b_85c2_51741ccb23ee --> c61c7da5_ab1b_2881_075e_127cc87cab93 d3fd5575_295b_d6be_24dd_62d277645dc9["~utils"] ef6fee49_c1b8_1e5b_85c2_51741ccb23ee --> d3fd5575_295b_d6be_24dd_62d277645dc9 d70b45e3_211a_67d3_88ac_20efaa3f9b6f["cli.spec.ts"] d70b45e3_211a_67d3_88ac_20efaa3f9b6f --> ef6fee49_c1b8_1e5b_85c2_51741ccb23ee style ef6fee49_c1b8_1e5b_85c2_51741ccb23ee 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
export const streams = {} as {
build: { out: string[]; err: string[] }
server: { out: string[]; err: string[] }
}
export async function serve() {
// collect stdout and stderr streams from child processes here to avoid interfering with regular vitest output
Object.assign(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)
// ... (100 more lines)
Domain
Subdomains
Dependencies
- execa
- kill-port
- node:util
- ~utils
Imported By
Source
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.spec.ts.
Where is serve.ts in the architecture?
serve.ts is located at playground/cli/__tests__/serve.ts (domain: ViteCore, subdomain: ConfigEngine, directory: playground/cli/__tests__).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free