Support [build].watch for theme app extensions#7392
Open
erikmay wants to merge 1 commit intoShopify:mainfrom
Open
Support [build].watch for theme app extensions#7392erikmay wants to merge 1 commit intoShopify:mainfrom
erikmay wants to merge 1 commit intoShopify:mainfrom
Conversation
Theme extensions currently use the base `dd` schema which has no `build`
field, and don't implement `devSessionWatchConfig`. Any `[build]` block
in `shopify.extension.toml` is silently stripped by zod, and the CLI's
dev watcher falls back to globbing `**/*` under the extension directory.
That cascade is painful when an external build tool (Vite, esbuild,
tsc --watch) writes multiple output files per build — each write fires
"Extension changed", triggering redundant theme-check and bundle cycles.
This mirrors the function extension pattern:
- Extend `BaseSchema` into `ThemeExtensionSchema` with
`build: { watch: string | string[] }`.
- Add `devSessionWatchConfig` to the theme spec that restricts watched
paths to `build.watch` + `locales/**.json` + `**.toml` (dropping the
`**/!(.)*.graphql` entry from the function version since theme
extensions don't use GraphQL).
With this change, authors can point the CLI at a sentinel file written
by their build tool after all outputs are on disk — one CLI trigger per
full build instead of N.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Theme app extensions currently use the base
BaseSchema(which has nobuildfield) and don't implementdevSessionWatchConfig. As a result, any[build]block inshopify.extension.tomlis silently stripped by zod, and the CLI's dev watcher falls back to globbing**/*under the extension directory.This is painful when an external build tool (Vite, esbuild,
tsc --watch) writes multiple output files per build — each write fires an "Extension changed" event, triggering redundant theme-check and bundle cycles. A single manualbun run theme-extension:buildduringshopify app devcan produce 8+ "Extension changed" events and 2 full bundle cycles.This PR makes the theme spec support
[build].watchthe same way function extensions already do:BaseSchemaintoThemeExtensionSchemawithbuild: { watch: string | string[] }.devSessionWatchConfigto the theme spec that restricts watched paths tobuild.watch+locales/**.json+**.toml.Motivation
Authors who use a separate source directory + build tool (common when writing Tailwind, TypeScript, or templated Liquid that compiles into
blocks/) have no way to tell the CLI "only rebundle when the build is fully done." With this change, they can point the CLI at a sentinel file written last by their build tool:and get exactly one bundle cycle per build.
Changes
packages/app/src/cli/models/extensions/specifications/theme.ts: extend schema withbuild.watch, adddevSessionWatchConfig.@shopify/apppatch).Test plan
[build]in its toml — dev watcher behaves exactly as before (watches whole extension dir).[build] watch = [".build-stamp"]and an external build tool that touches.build-stamplast —shopify app devonly triggers one bundle cycle per build, instead of one per file write.[build] watch = ["src/**"]— only changes undersrc/trigger the watcher.locales/**.jsonand**.tomlstill trigger bundle cycles whenbuild.watchis set (parity with function extensions).