Skip to content

fix(github): require() in composites breaks under ESM (#1068) - #1095

Merged
lex00 merged 1 commit into
mainfrom
fix/1068-github-esm-require
Jul 27, 2026
Merged

lex00 merged 1 commit into
mainfrom
fix/1068-github-esm-require

Conversation

@lex00

@lex00 lex00 commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

Summary

  • All 13 github composites that build a Step/Job/Workflow used a lazy require("@intentius/chant/runtime") to dodge a circular import "at module load time." That cycle doesn't exist today: generated/index.ts only imports from ./runtime (a thin re-export of core), never from composites/. require() is plain CJS and fails outright under ESM, which is how these modules actually run — every github example failed to build with require is not defined in ES module scope.
  • Replaced the lazy require + createProperty/createResource re-derivation with static imports of the already-generated Step/Job/Workflow classes from ../generated/index (the exact same classes those calls were reconstructing).
  • That change surfaced a real, separate type gap in core: createProperty's declared return type never said its instances satisfy Declarable, even though the constructor sets DECLARABLE_MARKER/lexicon/entityType at runtime exactly like createResource does. It only worked before because every caller went through the untyped require(). Fixed packages/core/src/runtime.ts to declare what was already true at runtime.
  • Fixing the require() issue also exposed a pre-existing duplicate top-level export const build between docs-snippets/src/composites-usage.ts and docs-snippets/src/quickstart.ts — invisible until docs-snippets actually got a chant build src run (the example test suite had skipBuild: true on it). Renamed to combinedJob / buildJob respectively, updated the matching docs snippets, and removed the skipBuild override.
  • Removed the github → "Every shipped example builds" entry from KNOWN_FAILURES in scripts/check-lexicons.ts now that it passes. The other two github entries in that map (#1069, intrinsics export mismatch) are a separate, unrelated issue and are left untouched.

Test plan

  • npm run build -w @intentius/chant-lexicon-github
  • just build
  • npx eslint packages/
  • npx vitest run (756 passed, 1 skipped)
  • npx tsx scripts/check-lexicons.ts — no untracked failures
  • chant dev check-lexicon lexicons/github — "Every shipped example builds" passes (8/8)

… imports (#1068)

Composites lazily required @intentius/chant/runtime to dodge a circular
import that no longer exists — generated/index.ts never depends on
composites/. That require() is plain CJS and breaks every example under
ESM. Import Step/Job/Workflow directly from ../generated/index instead,
the same classes createProperty/createResource already produced.

createProperty's return type never declared that its instances satisfy
Declarable, even though the constructor sets DECLARABLE_MARKER/lexicon/
entityType at runtime exactly like createResource does. That gap only
surfaced once removing require()'s implicit any exposed the real type;
fixed to match actual runtime behavior.

Also fixes a duplicate "build" export collision in the docs-snippets
example (composites-usage.ts and quickstart.ts both exported top-level
build), which the example test suite had been skipping around instead
of fixing, and updates the docs snippets to match.

Removes the github "Every shipped example builds" entry from
KNOWN_FAILURES in scripts/check-lexicons.ts now that it passes.
@lex00
lex00 merged commit e515bb8 into main Jul 27, 2026
6 checks passed
@lex00
lex00 deleted the fix/1068-github-esm-require branch August 3, 2026 19:21
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