Internals: Build and Cache
This page is for debugging source plugin builds.
Cold Build Path
When ttsc sees a plugin source descriptor:
- Resolve
source. - Hash the plugin source and host versions.
- Reuse the cached binary on hit.
- Copy source into a scratch directory on miss.
- Generate a
go.workoverlay pointing atttscand its shims. - Run
go build -o plugin <entry>. - Move the binary into the cache.
- Invoke the binary with
check,transform, orbuild.
Cache Key Inputs
The cache key includes:
ttscpackage version.- resolved
@typescript/native-previewversion. - platform and architecture.
- resolved source entry.
- files under the plugin source directory, except skipped generated/cache directories and editor backup files ending in
~. - the same hashable files under the local
ttscand shim overlay directories used for the generatedgo.work.
The cache key does not include:
- consumer TypeScript source files;
- plugin options such as lint
rules/extends,banner, orcalls; - CLI flags such as
--emitor--outDir;
README, JSON, schema, and other data files inside the plugin source directory do affect the cache key. This keeps //go:embed and other file-backed plugin data aligned with the built binary. Local workspace changes to ttscβs Go host or shim overlay also invalidate the source plugin cache automatically.
Cache Locations
Default:
<project>/node_modules/.ttsc/plugins/<key>/plugin
<project>/.ttsc/plugins/<key>/pluginOverride:
TTSC_CACHE_DIR=/tmp/ttsc-cache npx ttsc --emitClean:
npx ttsc cleanGo Toolchain Resolution
ttsc resolves Go in this order:
TTSC_GO_BINARY, when set.- the installed
@ttsc/{platform}-{arch}packageβs bundled Go SDK. - local workspace fallback under
ttsc/native/go. goonPATH.
Published consumer installs should use the bundled Go SDK. go on PATH is mainly a development fallback.
Debugging Build Failures
If go build fails, ttsc prints the Go stderr:
ttsc: building plugin "my-plugin" via "go build" failed:
go-plugin/main.go:42:8: undefined: shimast.SomethingCheck:
- missing shim
requireingo.mod; - missing source files in the npm tarball;
- wrong source directory or package entry;
- stale cache, fixed with
npx ttsc clean; - pnpm local dev layout, fixed in Local Development.
Concurrency
Concurrent ttsc processes may build the same missing key at the same time. Scratch directories are unique, and the final move is atomic. This is wasteful but safe.
See also
- Reference plugins β first-party plugins as worked examples.
- Pitfalls β failure modes specific to plugin authoring.
- Plugin Protocol β the wire contract.