Skip to content

fix(blocks-cli): resolve hoisted workspace dependencies during codegen - #566

Merged
tlgimenes merged 1 commit into
mainfrom
fix/blocks-cli-hoisted-workspaces
Sep 24, 2026
Merged

tlgimenes merged 1 commit into
mainfrom
fix/blocks-cli-hoisted-workspaces

Conversation

@tlgimenes

@tlgimenes tlgimenes commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

Code generation from a nested workspace such as apps/website silently omits commerce loaders when Yarn hoists @decocms packages into the repository root. The CLI also misses framework detection and dependency changes in its generation cache.

Resolve packages from the consuming site's Node module search paths, preserving the nearest installed copy. Use the same lookup for framework detection, package-version and app-source fingerprints, schema loaders, and the invoke generator. Prefer the site's declared framework when sibling workspaces hoist both Next.js and TanStack bindings. Explicit --apps-dir accepts either a package root or its source directory.

Adds 12 regression cases covering hoisted schema/Props output, real invoke generation, cache invalidation, local-package precedence, restricted exports, and mixed-framework workspaces. This upstreams the fix currently carried by FILA as a patch-package patch; the consuming site can remove it after upgrading to the released fix.

Validation:

  • bun install --frozen-lockfile passed.
  • npm_config_offline=true bun run --filter @decocms/blocks-cli test: 820 tests passed across 62 files.
  • The 12 workspace cases passed again after final review; the hoisting cases reproduced failures before the implementation.
  • Biome checks passed on all four new files; git diff --check passed.

Existing baseline issues were verified against main at c099045: CLI typecheck reports the same six migration-fixture errors; existing generator lint findings are unchanged. Knip has the same existing findings and also lists the two new test files as unused, as it does the other generator tests.


Summary by cubic

Fixes blocks-cli codegen in nested workspaces where Yarn hoists @decocms packages into the repo root, so sites no longer silently drop commerce loaders, miss framework detection, or run against stale cache fingerprints.

All package lookups — schema loaders, invoke generation, framework detection, and the generation cache — now resolve through the site's Node module search paths, preserving the nearest installed copy. --apps-dir accepts either a package root or its source directory.

Bug Fixes

  • Framework detection prefers the site's declared binding when sibling workspaces hoist both Next.js and TanStack.
  • Hoisted app sources and versions are fingerprinted, so cache invalidation catches in-place changes without a version bump.

Migration

  • Sites carrying the FILA patch-package patch for this fix can remove it after upgrading.

Written for commit 12ed669. Summary will update on new commits.

Review in cubic

@tlgimenes
tlgimenes requested a review from a team September 24, 2026 21:59
@tlgimenes
tlgimenes merged commit ced7404 into main Sep 24, 2026
1 check passed
vitoUwu pushed a commit to vitoUwu/deco-start that referenced this pull request Nov 26, 2026
…ocms#493)

## Problem

The vite plugin's `meta.gen.json` auto-regeneration runs
`generate-schema.ts` **without `--compose`** at both invocation sites:

- `plugin.js` — watch-driven regen (fires on any `src/**/*.ts(x)`
add/change)
- `plugin.js` — cold-start bootstrap (when the file is absent)

`generate-schema.ts` defaults `COMPOSE = false`, and its own header
notes that without `--compose` the output "omits Page, matchers,
`__SECTION_REF__`, Resolvable that `composeMeta` otherwise [injects]".
So every regen writes an **uncomposed** manifest missing every framework
`website/*` block.

`meta.gen.json` is committed, and Studio reads it **as-is** (no
`composeMeta` at read time). In a sandbox session the plugin rewrites it
uncomposed, and the daemon's shutdown "sync all local changes" commits
it — clobbering the composed manifest on the branch. The admin editors
then break silently. Most visibly, `website/matchers/date.ts`
disappears, so the variant-rule editor ("Regra de variante") loses its
start/end **date fields**.

Reported on casaevideo-tanstack (["o campo com as datas sumiu de
novo"](deco-sites/casaevideo-tanstack#633)); a
`lebiscuit-tanstack` whose committed manifest was still composed was
unaffected. This recurred repeatedly (casaevideo decocms#494, decocms#566, decocms#633) —
each time a hotfix restored the composed file, but the plugin
re-clobbered it on the next session.

## Fix

Route both invocations through a new exported
`generateSchemaArgs(siteName)` helper that pins `--compose`, so the flag
can't drift off one site. This mirrors `npm run generate`'s schema step
(`blocks-cli generate --compose`) and the production build, which
already compose.

No other flags are needed: `generate-schema` defaults `--sections
src/sections`, `--loaders src/loaders`, `--apps src/apps`, out
`.deco/meta.gen.json` — exactly what sites pass. `composeMeta` is
dynamically imported from `@decocms/blocks`, which is installed in the
sandbox.

## Test

`generateSchemaArgs` unit test asserts `--compose` is always present and
the site is targeted. The invocations themselves live in the
`configureServer` closure (needs a live vite server to exercise), so the
helper is the unit boundary both sites derive their args from — the flag
can't silently drop off one again.

`npm run typecheck` and `vitest` (12 passed) green; no new Biome
diagnostics.

## Note

This is the generation-side root fix. The daemon committing a generated
`meta.gen.json` is by design (it's committed for cold-start, and a
vibecode agent may legitimately change an interface and regenerate it) —
the defect was purely that the sandbox regen produced a *degraded*
manifest.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

<!-- This is an auto-generated description by cubic. -->
---
## Summary by cubic
Composes meta.gen.json during dev/sandbox schema regeneration to stop
committing an uncomposed manifest that removes framework website/*
blocks and breaks admin editors. Previously the Vite plugin ran
`generate-schema.ts` without `--compose`; now both watch and cold-start
invocations always include `--compose` via a shared helper.

- Centralizes args in `generateSchemaArgs(site)` and routes both
invocations through it, pinning `--compose`.
- Matches `npm run generate` and production behavior
(`@decocms/blocks-cli` with `--compose`).
- Adds unit tests that assert `--compose` is present and the target site
is set.
- No migration required; committed meta.gen.json remains composed and
features like the date matcher in the variant rule editor persist.

<sup>Written for commit b33d2bb.
Summary will update on new commits.</sup>

<a href="https://cubic.dev/pr/decocms/blocks/pull/493?utm_source=github"
target="_blank" rel="noopener noreferrer"
data-no-image-dialog="true"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"><source
media="(prefers-color-scheme: light)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-light.svg"><img
alt="Review in cubic"
src="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"></picture></a>

<!-- End of auto-generated description by cubic. -->

Co-authored-by: Claude Opus 4.8 <[email protected]>
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.

1 participant