# Behavior traces — evanw/esbuild

> Canonical page: https://codevetter.com/unpack/esbuild/behavior-traces

# Behavior traces — evanw/esbuild

Scanned commit f6058f8364fe7ab91ca57a83e02577ed74c9cae4 (2026-08-09). Generated by codevetter codevetter 1.12.0 on 2026-09-22.

Three flows matter: process startup (CLI versus service), a full bundle (scan, link, write), and the JS client attaching to that service. Watch and serve sit on the same Context and reuse rebuild. Transform is the bundle path with a mock filesystem and no entry-point files.
- Startup with no args and a TTY stdin prints helpText and exits 0. --version prints esbuildVersion and exits 0. --service=VERSION checks the host version, then runService(sendPings) and returns without calling cli.Run. — [cmd/esbuild/main.go#L176-L184](https://github.com/evanw/esbuild/blob/f6058f8364fe7ab91ca57a83e02577ed74c9cae4/cmd/esbuild/main.go#L176-L184) [cmd/esbuild/main.go#L200-L253](https://github.com/evanw/esbuild/blob/f6058f8364fe7ab91ca57a83e02577ed74c9cae4/cmd/esbuild/main.go#L200-L253)
- runService sets logger.API to JSAPI, writes the version as the first length-prefixed stdout packet, and if --ping was passed sends command ping every second. Packets are written on one goroutine so they cannot interleave. EOF on stdin ends the loop. — [cmd/esbuild/service.go#L84-L159](https://github.com/evanw/esbuild/blob/f6058f8364fe7ab91ca57a83e02577ed74c9cae4/cmd/esbuild/service.go#L84-L159)
- A normal CLI invocation strips the special flags, optionally disables GC when there is at most one entry point and the process is not watch/serve, then sets exitCode from cli.Run. Non-TTY stdin starts a goroutine that os.Exit when stdin closes, which is how watch and serve stop. — [cmd/esbuild/main.go#L309-L382](https://github.com/evanw/esbuild/blob/f6058f8364fe7ab91ca57a83e02577ed74c9cae4/cmd/esbuild/main.go#L309-L382)
- cli.runImpl intercepts any --serve, --servedir, or --serve-fallback argument and calls serveImpl, which parseServeOptionsImpl, api.Context, ctx.Serve, optional ctx.Watch, then blocks forever on a nil channel. Returning from serveImpl yields exit code 1. — [pkg/cli/cli_impl.go#L1198-L1207](https://github.com/evanw/esbuild/blob/f6058f8364fe7ab91ca57a83e02577ed74c9cae4/pkg/cli/cli_impl.go#L1198-L1207) [pkg/cli/cli_impl.go#L1497-L1555](https://github.com/evanw/esbuild/blob/f6058f8364fe7ab91ca57a83e02577ed74c9cae4/pkg/cli/cli_impl.go#L1497-L1555)
- One-shot Build calls contextImpl, then ctx.Rebuild, optionally printSummary, then ctx.Dispose. Rebuild coalesces concurrent callers onto the active buildInProgress and otherwise calls rebuildImpl. — [pkg/api/api.go#L398-L416](https://github.com/evanw/esbuild/blob/f6058f8364fe7ab91ca57a83e02577ed74c9cae4/pkg/api/api.go#L398-L416) [pkg/api/api_impl.go#L1001-L1032](https://github.com/evanw/esbuild/blob/f6058f8364fe7ab91ca57a83e02577ed74c9cae4/pkg/api/api_impl.go#L1001-L1032)
- Scan order inside ScanBundle is: parallel onStart callbacks, generateUniqueKeyPrefix, resolver.NewResolver, parse runtime, wait for onStart, honor CancelFlag, preprocessInjectedFiles, addEntryPoints, scanAllDependencies, processScannedFiles. Cancel after onStart still returns a Bundle so onEnd can run. — [internal/bundler/bundler.go#L1385-L1518](https://github.com/evanw/esbuild/blob/f6058f8364fe7ab91ca57a83e02577ed74c9cae4/internal/bundler/bundler.go#L1385-L1518)
- linker.Link order is: wrappedLog, graph.CloneLinkerGraph, bind __commonJS or __commonJSMin from the runtime AST, scanImportsAndExports, treeShakingAndCodeSplitting, computeChunks, computeCrossChunkDependencies, mangleProps and mangleLocalCSS, ast.FollowAllSymbols, generateChunksInParallel. — [internal/linker/linker.go#L227-L349](https://github.com/evanw/esbuild/blob/f6058f8364fe7ab91ca57a83e02577ed74c9cae4/internal/linker/linker.go#L227-L349)
- JS build() and transform() call ensureServiceIsRunning(). The child argv is the native binPath, or node plus the wasm bin shim when WASM or the platform fallback is WASM. esbuildCommandAndArgs throws if the API file is not lib/main.js, because bundling the package breaks the relative binary path. — [lib/npm/node.ts#L51-L79](https://github.com/evanw/esbuild/blob/f6058f8364fe7ab91ca57a83e02577ed74c9cae4/lib/npm/node.ts#L51-L79) [lib/npm/node.ts#L135-L142](https://github.com/evanw/esbuild/blob/f6058f8364fe7ab91ca57a83e02577ed74c9cae4/lib/npm/node.ts#L135-L142)
- handleBuildRequest parses flags with cli.ParseBuildOptions. For a context build it keeps an activeBuild keyed by an integer and wires plugin onEnd back across the protocol. A non-context build calls api.Build and encodes errors, warnings, output files, metafile, and mangle cache. — [cmd/esbuild/service.go#L597-L604](https://github.com/evanw/esbuild/blob/f6058f8364fe7ab91ca57a83e02577ed74c9cae4/cmd/esbuild/service.go#L597-L604) [cmd/esbuild/service.go#L721](https://github.com/evanw/esbuild/blob/f6058f8364fe7ab91ca57a83e02577ed74c9cae4/cmd/esbuild/service.go#L721) [cmd/esbuild/service.go#L789](https://github.com/evanw/esbuild/blob/f6058f8364fe7ab91ca57a83e02577ed74c9cae4/cmd/esbuild/service.go#L789)
- ServeHTTP checks Host against localhost or the server's host list (DNS rebinding), rejects backslash paths, rebuilds via h.rebuild(), returns 503 text if the build has errors, then matches the cleaned URL to in-memory output or servedir. — [pkg/api/serve_other.go#L105-L183](https://github.com/evanw/esbuild/blob/f6058f8364fe7ab91ca57a83e02577ed74c9cae4/pkg/api/serve_other.go#L105-L183)
- A service rebuild command looks up activeBuild by key, increments withinRebuildCount, calls ctx.Rebuild(), and returns only errors and warnings, not output files. dispose waits on disposeWaitGroup so in-flight rebuild, watch, serve, and resolve calls finish. — [cmd/esbuild/service.go#L30-L39](https://github.com/evanw/esbuild/blob/f6058f8364fe7ab91ca57a83e02577ed74c9cae4/cmd/esbuild/service.go#L30-L39) [cmd/esbuild/service.go#L274-L311](https://github.com/evanw/esbuild/blob/f6058f8364fe7ab91ca57a83e02577ed74c9cae4/cmd/esbuild/service.go#L274-L311)
- Plugin onResolve filters are compiled with config.CompileFilterForPlugin before the callback is stored. During the build, Go plugins call bundler.RunOnResolvePlugins; JS plugins are proxied as service resolve requests. — [pkg/api/api_impl.go#L1952-L1964](https://github.com/evanw/esbuild/blob/f6058f8364fe7ab91ca57a83e02577ed74c9cae4/pkg/api/api_impl.go#L1952-L1964) [pkg/api/api_impl.go#L2141](https://github.com/evanw/esbuild/blob/f6058f8364fe7ab91ca57a83e02577ed74c9cae4/pkg/api/api_impl.go#L2141) [internal/config/config.go#L756](https://github.com/evanw/esbuild/blob/f6058f8364fe7ab91ca57a83e02577ed74c9cae4/internal/config/config.go#L756)

Every claim links to its cited files at the pinned commit. Citations identify source evidence; they do not establish runtime correctness. Independent CodeVetter scan — not reviewed by upstream maintainers.

## Public product links

- [CodeVetter](https://codevetter.com/)
- [Download](https://codevetter.com/download)
- [Documentation](https://codevetter.com/docs/)
- [Source](https://github.com/Codevetter/codevetter)
