Turborepo allows to cache results for scripts from package.json
files.
Minimal example:
- The
build
script compiles files fromsrc
folder and puts the result intodist
folder - We can setup a Turborepo pipeline
"build": { "inputs": ["src/**"], "outputs": ["dist/**"] }
- On the first
turbo build
run Turborepo will- calculate hashes for files from
src
folder, and save them into cache, - save
dist
folder into cache.
- calculate hashes for files from
- On the second
turbo build
run Turborepo will comparesrc
hashes with cache. If hashes do match, it will restoredist
folder from the cache without running thebuild
script.
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-cache
withTURBO_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