Repository navigation
fix(codegen-ts): drop dprint-node from the CLI install - #579
Merged
Merged
Conversation
ts-poet requires dprint-node (about 25 MB of platform binaries) at module load. Vendor ts-poet's printer as codegen-ts/src/poet.ts (Apache-2.0, licence kept) and format with the same dprint TypeScript plugin, 0.87.1, through its WebAssembly build (@dprint/typescript + @dprint/formatter). Output is byte-identical: every codegen golden and conformance fixture is unchanged. poet.ts is an engine module, so owned and ejected templates take Code from @metaobjectsdev/codegen-ts/engine and class identity holds. The config loader still maps a legacy bare ts-poet import to that entry. check-peer-ranges now refuses dprint-node, ts-poet and @types/* in a published package's dependencies or required peers unless allowlisted. No published package declared @types/*; @types/node arrives only through the libSQL driver, which is out of scope. Fresh CLI install: 151 MB (134,525,165 bytes) -> 133 MB (115,177,311 bytes).
- A formatter that fails to load now throws instead of silently emitting unformatted code; only a format error falls back. - The CLI pins @metaobjectsdev/codegen-ts/engine to the same build (dist vs src) as the package root, so both reach one poet.ts. - The engine entry re-exports only code/imp/joinCode/Import/Code from the printer, as it did from ts-poet. - Restore ts-poet's toString() call for non-plain placeholders. - Refresh the index.ts comment and narrow the CHANGELOG claims about legacy ts-poet imports and the standalone binary.
…e peer guard Remove asOneline/oneline, Import.fromMaybeString and arrayOf from the vendored printer (no callers). check-peer-ranges enumerates packages through publish-set.mjs's enumerateWorkspacePackages instead of its own readdir walk.
…nstall numbers after #567
…ndencies; add real-check tests
dmealing
added a commit
that referenced
this pull request
Nov 15, 2026
…0063) (#587) * feat(codegen-ts): code writer, writer contract and corpus, layout ratchet (ADR-0063) Generators own their layout; formatters become test oracles only (ADR-0063). This change lands the foundation and converts no generator, so generated output is unchanged. - spec/code-writer.md: the shared writer contract (lines and blocks, blank-line requests, snippets, fit-or-break lists, output form, and the TypeScript dialect's import collection). - fixtures/writer-conformance/: 40 cases (30 core, 10 TypeScript), the 35th shared corpus. - CodeWriter and TsWriter (codegen-ts/src/writer/), at 120 columns, exported from the package root and the engine entry and listed in eject.engineSurface. TsWriter accepts ts-poet Code fragments and collects their imports, so generators can convert one function at a time. - Layout ratchet: an AST walk (ts.createSourceFile) over generator source that flags newline and indentation literals, newline joins and repeat-built indentation, resolving same-file constants. It has its own catch/pass cases. The allowlist names all 74 unconverted files with reasons, fails on stale entries and may only shrink against the merge base. * feat(codegen-ts): writer and reference generators are extended by subclassing (ADR-0063) CodeWriter and TsWriter keep no private members: their steps are protected methods (piece, breakAt, fits, writeHeader, writeImports, writeImport, orderModules), so a subclass overrides one and keeps the rest. ADR-0063 item 7 and spec/code-writer.md state that reference generators take the same shape, one overridable method per piece of output, and that these methods are not a stability contract. A test shows a subclass overriding orderModules. * no-mistakes(review): refuse trailing newline in writer line() * fix(codegen-ts): adapt the writer foundation to main (vendored poet, ratchet allowlist, counts) TsWriter reads Code from src/poet.ts (the ts-poet copy main vendored in #579), so a generator's imp() imports are collected again. The layout ratchet's allowlist gains the six main files that type layout (one unconverted helper, four JSON document writers and the vendored printer, exempt). Corpus count 41. * no-mistakes(document): docs: name CodeWriter/TsWriter in engine surface
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.
What Changed
codegen-tsvendors the part of ts-poet the generators use assrc/poet.ts(Apache-2.0, licence inLICENSE.ts-poet). It formats with the same dprint TypeScript plugin, run as WebAssembly via@dprint/typescript(pinned to 0.87.1) and@dprint/formatter, with ts-poet's configuration. Generated output is byte-identical.codegen-ts-react,codegen-ts-tanstackandcodegen-ts-angulardrop theirts-poetdependency.ts-poetstays a devDependency of the CLI only, andmeta genaliases a barets-poetimport in older scaffolds to thecodegen-ts/engineentry.scripts/check-peer-ranges.tsalso refusesdprint-node,ts-poetand any@types/*package independencies,optionalDependenciesor a required peer of a published package. Exceptions go inALLOWED_TYPES_DEPSwith a reason. The newscripts/check-peer-ranges.test.tsruns from thegate_peer_rangesstep inscripts/ci-local.sh.@metaobjectsdev/cli(packed CLI plus@metaobjectsdevclosure, installed into an empty project, measured asnode_modulessize): 151 MB (134,641,989 bytes) before, 133 MB (115,302,944 bytes) after.dprint-nodeis no longer in the tree. The standalone binary no longer crashes on engine-loading commands such asmeta migrateandmeta verify --db.Validation
Risk Assessment
✅ Low: Both fix-round claims verified in source (optionalDependencies now guarded by a real-check test wired into the gate lane); the rest of the change is mechanical import swaps onto a faithful vendored printer whose byte-identity claim is gated by the unchanged goldens in the pipeline's test step.
Testing
Fresh-install measurement, installed-CLI generation, the legacy
ts-poetimport, the standalone binary and the guard were all driven live and pass. Baseline numbers came from a base-commit build packed the same way: 149M (132,339,536 B) before and 130M (112,949,965 B) after, a drop of about 19.4 MB. dprint-node is 24 MB in the base tree; after the change @dprint is 5.7 MB and the @metaobjectsdev packages grew from about 26.7 MB to about 26.8 MB. The only quick-CI failure was the 'site payload is true' lane; its run was red on a 5s test timeout inscripts/site/reference.test.tsand onmeta verifyfailing on examples/showcase (exit 1). Both passed when I re-ran the same commands alone. The mutation gate was running alongside them, and an earlier gate run on this machine also reported contention, so I judged it load-induced. The flagless full run (C#, Java, Python, Kotlin lanes, Testcontainers) was not run.--quickskips those lanes, which this TS-only change does not touch. Thescripts/ci-local.sh --only ts-fast --only ts-unitbaseline also ran green before this step.meta init+meta genformats output with no ts-poet present, byte-identical to the base installdiff -rof src/ against the base install is empty); Product.ts is formattedts-poetstill resolves and emits when ts-poet is not installedbun build --compilebinary runs migrate and verify --db with no dprint-node crash (the base binary crashes)ci-local --quick) passes on this HEADEvidence: Fresh install after (HEAD)
Evidence: Fresh install before (base f8a1dc5)
Evidence: meta gen on installed CLI
Evidence: Byte-identical output vs base
Evidence: Base binary crash (dprint-node .node)
Evidence: HEAD binary migrate
Evidence: HEAD binary verify --db
Evidence: Guard run on real workspace
Evidence: Guard test
Evidence: ci-local --quick full log
Evidence: Site payload gate re-run (green)
Pipeline
Updates from git push no-mistakes
✅ **Intent** - passed
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
🔧 **Review** - 1 issue found → auto-fixed (2) ✅
scripts/check-peer-ranges.ts:88- The extended install-time guard readsdependenciesand non-optionalpeerDependenciesonly. npm installsoptionalDependenciesby default (it skips them only on install failure), so a published package that adds"optionalDependencies": {"dprint-node": "^1.0.8"}(or a@types/*orts-poetentry) puts the package into every CLI install while this gate stays green — defeating requirement 3's stated purpose ("a published package cannot reintroduce dprint-node or a run-time @types/* dependency"). The same field gap existed for the pre-change@biomejs/biomerule, but this change is what broadens the guard's claim, so it owns the completeness of the new rule. Note the distinction from required peers:peerDependenciesMeta.optionalexemption is deliberate (documented escape hatch); theoptionalDependenciesfield is simply unexamined. Fix: add...Object.keys(pkg.optionalDependencies ?? {}).map((dep) => ({ dep, field: "optionalDependencies" }))to therequiredarray (naming it "installed" would be clearer), sibling site: none — one construction covers all three categories.🔧 Fix applied.
2 issues (1 warning, 1 info) still open:
scripts/check-peer-ranges.test.ts:1- The fix round's new test drives the realpeerRangeReportagainst synthetic workspaces, but no CI lane or workflow executes it:gate_peer_ranges(scripts/ci-local.sh:372) runs onlybun scripts/check-peer-ranges.ts, and no gate runsbun test scripts/check-peer-ranges.test.ts. This deviates from the repo's own convention for sibling script tests —gate_publish_setrunstest-publish-set.mjsbeside the check it protects. As merged, the optionalDependencies regression protection the fix round claims never runs anywhere automated and will silently rot on the next refactor of the guard.CHANGELOG.md:86- Applied inline: the [Unreleased] entry described the extended guard as refusing install-only deps 'throughdependenciesor a non-optional peer', which predates the fix round's extension tooptionalDependencies(scripts/check-peer-ranges.ts:30-33). Reworded to name all three fields so the changelog matches what the guard now enforces.🔧 Fix applied.
2 infos still open:
CHANGELOG.md:86- Applied inline: the [Unreleased] entry described the extended guard as refusing install-only deps 'throughdependenciesor a non-optional peer', which predates the fix round's extension tooptionalDependencies(scripts/check-peer-ranges.ts:30-33). Reworded to name all three fields so the changelog matches what the guard now enforces.scripts/check-peer-ranges.ts:109- The ALLOWED_TYPES_DEPS exemption is keyed only on<pkg> <dep>and is checked before the category is known, so an entry namingdprint-node,ts-poetor@biomejs/biomewould also silence the guard, even though the header (lines 41-43) and the constant's doc present the allowlist as an@types/*-only escape hatch. No current entry does this and adding one requires deliberate action, so this is informational: the allowlist's effective scope is wider than its documented scope.scripts/site/reference.test.ts- The 'site payload is true' lane ofci-local.sh --quickfailed once with a 5s timeout inscripts/site/reference.test.tsandmeta verifyexit 1 on examples/showcase. It was red under load while the mutation gate ran. Re-runningbun test scripts/siteand the payload--checkalone passed (168 pass, payload fresh), so I treated it as a load-induced flake rather than a defect in this change.metaobjects.config.tsfails to load ("could not resolve @metaobjectsdev/codegen-ts from the CLI"). Schema commands still work:migrategoes on without the config's providers andverify --dbpasses when the config is absent. This matches the intent's statement thatmeta genin the binary is unsupported.meta init+meta genformats output with no ts-poet present, byte-identical to the base installdiff -rof src/ against the base install is empty); Product.ts is formattedts-poetstill resolves and emits when ts-poet is not installedbun build --compilebinary runs migrate and verify --db with no dprint-node crash (the base binary crashes)ci-local --quick) passes on this HEADscripts/ci-local.sh --only ts-fast --only ts-unit --strict-toolchainsbun run --filter '*' build(exit 0)Packed the 10-package CLI closure withbun pm pack, rannpm installinto an empty project with overrides to the tarballs, thendu -sb, top packages andfindfor dprint-node and ts-poet, on the HEAD build and on the base commit f8a1dc59bInstalled CLI:meta init, wired a shop model and a legacy owned generator importing barets-poet, ranmeta gen, then diffedsrc/against the same run on the base installbun build --compilestandalone binaries from the HEAD and base sources, thenmigrate --from-db ... --apply,verify --dbandmigrate --dry-runbun scripts/check-peer-ranges.tsandbun test scripts/check-peer-ranges.test.ts(4 pass)scripts/ci-local.sh --quick --strict-toolchains: every lane green except 'site payload is true', which was red oncebun test scripts/siteandbun scripts/build-site-payload.ts --checkre-run alone (168 pass, payload fresh)✅ **Document** - passed
✅ No issues found.
✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.