CodeVetter · Repo Unpack · System map
sindresorhus/got
The runtime is a callable library instance built around a shared request engine. Factory code selects the outward Promise or stream interface, while Options centralizes configuration and Request owns transport lifecycle state. HTTP caching, DNS caching, and HTTP/2 pooling occupy separate state boundaries. Distribution and CI are defined by package.json, tsconfig.json, and one inspected GitHub Actions workflow.
- source/index.ts creates the default Got instance from new Options(), an empty handler list, and mutableDefaults:false, then exports the instance plus configuration, response, error, diagnostics, and factory APIs.
- create() constructs Request before dispatching handlers; its lastHandler calls flush() and returns either the Request stream or an asPromise() wrapper according to isStream.
- Options owns cloned internals, raw merge history, and explicit-header state; merge() runs init hooks before assigning validated option setters and rejects unknown option keys.
- Request extends Node Duplex and owns response metadata, redirect history, retry count, upload/download counters, active request, queued writes, timeout cancellation, and abort disposal.
- Default HTTPS transport uses https.request unless http2 is enabled; HTTP/2 auto() negotiates ALPN, chooses requestHttp2 for h2, and falls back to HTTP/1.1.
- HTTP cache wrappers are retained per storage adapter by cacheableStore; DNS state is owned by DnsCache, and HTTP/2 connections are pooled in Http2Agent.sessions with pending-session and queue state.
- The npm package is ESM, requires Node >=22, and publishes dist/source; build deletes dist and runs tsc, prepare invokes build, and tsconfig compiles source, test, and benchmark using an ES2024 target.
- npm test chains XO, tsc --noEmit, and AVA with the tsx ESM import hook; CI specifies npm install and npm run test on Ubuntu for Node 22, 24, and 26.