Turborepo allows to cache results for scripts from package.json files.
Minimal example:
- The
buildscript compiles files fromsrcfolder and puts the result intodistfolder - We can setup a Turborepo pipeline
"build": { "inputs": ["src/**"], "outputs": ["dist/**"] }
- On the first
turbo buildrun Turborepo will- calculate hashes for files from
srcfolder, and save them into cache, - save
distfolder into cache.
- calculate hashes for files from
- On the second
turbo buildrun Turborepo will comparesrchashes with cache. If hashes do match, it will restoredistfolder from the cache without running thebuildscript.
More in docs: https://turbo.build/repo/docs/core-concepts/caching
Locally, Turborepo stores caches in .turbo folder.
In CI, the caches are saved in Github artifacts.
It can happen that some script fails in CI because of a misconfigured Turborepo pipeline. The following can be used in order to debug this locally:
-
Setup https://github.com/ducktors/turborepo-remote-cache locally
-
Run
turborepo-remote-cachewithTURBO_TOKEN=local pnpm dev -
Run tests in the target repo with
# Clean the repo devbox run clean # Install dependencies pnpm i # Run tests with # - local Turborepo server # - Turborepo debug info # - simulated CI TURBO_API=http://0.0.0.0:3000 TURBO_TOKEN=local TURBO_TEAM=local TURBO_RUN_SUMMARY=true CI=true pnpm turbo:test