fix: restore generate-sections/loaders, drop broken ESM bundles - #167
Merged
Conversation
Patches three 5.1.0 regressions in the build-time scripts surface: - generate-sections and generate-loaders are rebuilt and re-exported. Sources were still in scripts/ but had been dropped from the tsup entries (PR #164 oversight); files: ["dist"] then hid them. - Scripts bundle switches to format: ["cjs"] + platform: "node". The prior platform: "neutral" ESM emit wrapped externalized require() in a __require shim that threw "Dynamic require of fs" as soon as ts-morph's bundled typescript loaded. CLI scripts are CJS-only now. - generate-invoke resolveAppsDir() walks up node_modules from CWD and distinguishes "package missing" from "vtex/invoke.ts not shipped" (the common case — the published @decocms/apps tarball omits the source file the script parses). CHANGELOG documents this as 5.1.1. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
🎉 This PR is included in version 5.1.1 🎉 The release is available on:
Your semantic-release bot 📦🚀 |
7 tasks
vibe-dex
added a commit
that referenced
this pull request
May 19, 2026
Reverts the full chain of commits introduced in PRs #164, #165, #166, #167, #170, #174, #175, #176, #177 plus the two semantic-release auto commits (5.1.0, 5.1.1). Root cause: PR #164 (Framework-agnostic entrypoints: /core, /tanstack, /next, /node) repointed package.json exports from src/ to dist/ and split the framework into multiple bundle chunks via tsup. This is correct in principle, but the tsup output produces a separate copy of every module per entry tier. Files with module-level mutable state (let foo = ..., new Map(), new Set() at top level) end up with one copy per dist entry, so writes through one export resolve a different copy than reads through another export. Symptoms observed on @decocms/start@5.1.0+ and 5.3.0-rc.0/rc.1: - GET/POST /deco/invoke/site/loaders/<any-site-loader> → 404 "Unknown handler: site/loaders/<name>" despite the loader being correctly emitted into site/server/cms/loaders.gen.ts and registered via setInvokeLoaders() in setup.ts. The site's setup.ts mutates the getRegisteredLoaders closure inside dist/core/admin/index.js, while handleInvoke (mounted on the catch-all route) reads getRegisteredLoaders from a different copy of invoke.ts bundled into dist/tanstack/routes/index.js — which still holds the default () => ({}). - OTel direct-POST channels silently dropped (metrics + error logs) — same pattern in src/core/sdk/observability.ts and src/core/sdk/logger.ts. Partially fixed on the fix/o11y-shared-state-singleton branch (the rc.1 work) but the fix never covered invoke.ts handler registry. PR #167 patched two other #164 regressions (CLI scripts dropped from the tsup entries, ESM bundle wrapping require() in a broken __require shim) and PR #166 finalized the publish surface — both strictly downstream of #164. #174 (router preload options) and #170/#175/ #176/#177 (CI / release machinery) build on the same foundation. Path forward: A future re-attempt at framework-agnostic entrypoints must (a) emit a single shared bundle for the admin/invoke handler registry, the observability state, and any other module-level mutable state, or (b) hoist that state onto a globalThis-keyed singleton from the start, with a CI guard that fails any new module-level mutable state inside src/core/. This revert intentionally takes us back to the single-bundle src/-exports world where the bug is latent but inert. Verification: - npm run build → succeeds against the pre-#164 source layout - On a casaevideo build pinned to a snapshot from this revert, POST /deco/invoke/site/loaders/adressByCep returns 500 ("Cannot read properties of undefined (reading 'replace')" from the loader body, not a 404) — i.e. the registry contains the handler again, matching v5.0.0 behaviour. This is the working-baseline state. Re-landing #174's preload options on top of the restored src/ layout is a follow-up. Co-authored-by: Cursor <cursoragent@cursor.com>
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
Patches three regressions in
5.1.0's build-time scripts surface:generate-sections/generate-loadersare back. Sources still existed inscripts/but had been dropped from thetsupentries in PR Framework-agnostic entrypoints: /core, /tanstack, /next, /node #164;files: ["dist"]then hid them from consumers.Dynamic require of "fs" is not supportedbecausetsupusedplatform: "neutral"— switching the scripts bundle toformat: ["cjs"]+platform: "node"fixes it and stops shipping a broken.jsalongside each.cjs.generate-invokeresolution + error. Now walks upnode_modulesfrom CWD and distinguishes "@decocms/apps not installed" from "installed butvtex/invoke.tsnot shipped" (the published tarball omits the source file the script parses) with an actionable error pointing at--apps-dir.CHANGELOG entry added as
5.1.1since 5.1.0 was published as a minor but acted as a breaking change for any site running the generators in CI.Test plan
bun run buildclean (all 10 scripts emit, no.jsfiles)bun run typecheckpassesbun run test— 45 files, 541 tests passingnode dist/scripts/generate-schema.cjsno longer throws the dynamic-require errornode dist/scripts/generate-invoke.cjsagainst a site with@decocms/apps@1.13.0installed gives the new actionable errornode dist/scripts/generate-sections.cjsandgenerate-loaders.cjsrun end-to-end in a scratch dir🤖 Generated with Claude Code
Summary by cubic
Restores
generate-sectionsandgenerate-loaders, makes all CLI scripts CJS-only to stop ESM crashes, and improvesgenerate-invokeresolution and error messaging. This fixes 5.1.0 regressions that broke build-time generators.Bug Fixes
scripts/generate-sectionsandscripts/generate-loadersto thetsupbuild andpackage.jsonexports; both now ship as.cjs.format: ["cjs"],platform: "node"); drops broken ESM.jsand fixes “Dynamic require of 'fs' is not supported”.generate-invokenow walks upnode_modulesto find@decocms/appsand shows a clear error whenvtex/invoke.tsis missing, with a hint to use--apps-dir.Migration
.cjsscripts, e.g.node node_modules/@decocms/start/dist/scripts/generate-schema.cjs.generate-invoke, point--apps-dirto a local checkout that includes the source (e.g.../apps-start), or skip regeneration ifinvoke.gen.tsis already committed.Written for commit 266a48f. Summary will update on new commits.