Skip to content

fix: declare build outputs so the turbo cache restores artifacts - #636

Merged
stian-overasen merged 1 commit into
mainfrom
fix/turbo-build-outputs
Sep 10, 2026
Merged

stian-overasen merged 1 commit into
mainfrom
fix/turbo-build-outputs

Conversation

@peroks

@peroks peroks commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

Short Introduction

Adds "outputs": ["build/**"] to the build task so turbo actually caches and restores build artifacts, instead of recording a cache hit that restores nothing.

Description

Fixes #635.

Turbo only stores the files a task declares in outputs. The build task declared none, so its cache stored nothing — yet turbo still reported the task as cached on a matching input hash and exited 0. A cache hit therefore produced a successful, sub-second build with an empty build/ directory.

That makes the current state a correctness problem rather than a missed optimisation: any run where build/ is absent but the cache is warm (CI restoring a cache into a fresh checkout, a container reusing a cache volume, a rebuild after git clean) silently yields no build output, and a subsequent deploy ships it.

build/** is sufficient for this repo: the only buildable package is packages/themes/block-theme, and its wp-scripts build --webpack-copy-php writes only into build/.

Note for downstream projects inheriting this config: a package that emits anything outside build/ must declare it as well, otherwise that file goes missing on a cache hit. A theme with a theme.json generation step needs "outputs": ["build/**", "theme.json"].

Steps to Test/Replicate

# 1. Warm the cache and confirm artifacts exist.
rm -rf .turbo/cache
npm run build
find packages -path '*/build/*' -type f | wc -l   # non-zero

# 2. Delete the build output, keeping the cache, and rebuild.
rm -rf packages/themes/block-theme/build
npm run build                                      # >>> FULL TURBO
find packages -path '*/build/*' -type f | wc -l    # same non-zero count

On main step 2 reports FULL TURBO and leaves the count at 0. With this change the artifacts are restored from the cache.

The before/after transcript from a downstream project with an identical build task is in #635.

Screenshots

n/a — build configuration only.

Checklist

  • I have written unit tests where applicable
  • My code follows the Dekode coding standards
  • I've tested my changes with keyboard and screen readers
  • My code follows the accessibility standards
  • My code is properly documented
  • I've declared any PII (Personally Identifiable Information) for anonymization

The build task declared no `outputs`, so turbo cached no artifacts for it
while still recording a cache hit on a matching input hash. A cache hit
therefore reported success in milliseconds and produced zero files.

That is a correctness problem rather than a missed optimisation: wherever
build/ is absent but the cache is warm - CI restoring a cache into a fresh
checkout, a container reusing a cache volume, a rebuild after git clean -
the build silently yields no output and a deploy ships it.

build/** covers every buildable package here; block-theme's
`wp-scripts build --webpack-copy-php` writes only into build/.

Fixes #635
@stian-overasen
stian-overasen merged commit 076bf22 into main Sep 10, 2026
4 checks passed
@stian-overasen
stian-overasen deleted the fix/turbo-build-outputs branch September 10, 2026 05:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

turbo.json: the build task declares no outputs, so its cache restores nothing

2 participants