Skip to content

perf: replace json-schema-to-typescript with a built-in emitter (-12 MB install) - #1325

Draft
l2ysho wants to merge 1 commit into
masterfrom
claude/apify-cli-1310-07b762
Draft

perf: replace json-schema-to-typescript with a built-in emitter (-12 MB install)#1325
l2ysho wants to merge 1 commit into
masterfrom
claude/apify-cli-1310-07b762

Conversation

@l2ysho

@l2ysho l2ysho commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

Closes #1310. Part of #1305.

TLDR;

  • removed json-schema-to-typescript completely as majority of package was not used
  • src/lib/schema-to-typescript.ts generates ts "by hand" now
  • test 🟢 but we should AB test this on some complex input schema
  • more info below

json-schema-to-typescript was the largest single install-size lever in the CLI. It served one command — actor generate-schema-types — and dragged in prettier, lodash and js-yaml. Replaced by src/lib/schema-to-typescript.ts (~270 lines).

Why a rewrite and not just dropping the formatting

json-schema-to-typescript@15 imports prettier at module top level, so format: false still ships all 9.5 MB. It's one dependency or zero.

Zero was viable because every option at the old call site turned a feature off: maxItems: -1 disabled tuple expansion, $refOptions disabled all remote resolution, and stripTitles (75 lines) existed purely to stop the library hoisting named interfaces. The command used a fraction of a general-purpose compiler at full price.

Install size

Metric master this branch Change
Full install (with dependencies) 55.61 MB 43.55 MB −12.06 MB (−21.7%)
Unpacked package 1.20 MB 1.21 MB +0.01 MB
Tarball download 0.30 MB 0.31 MB +0.01 MB

prettier, lodash, js-yaml and @apidevtools/json-schema-ref-parser leave the production graph entirely.

Behaviour

Output is byte-identical to the old library on every repo schema fixture, strict and non-strict.

  • stripTitles deleted — the new emitter ignores title, so it was a no-op.
  • Fixes two cases that previously emitted code that does not compile: a narrower index signature alongside optional members (TS2411), and */ inside a description terminating the generated JSDoc.
  • properties alongside allOf/anyOf/oneOf is now intersected in rather than silently dropped.
  • KVS collection names that collide as identifiers (my-store / my_store) get suffixed instead of emitting duplicate interfaces.

Accepted costs

  • Generated files are no longer prettier-formatted, so the first regeneration after upgrading shows whitespace churn. Content is unchanged on all fixtures.
  • Recursive $refs render as unknown; minItems/additionalItems tuple expansion is dropped. No Apify schema uses either, and the single-declaration design — previously enforced by stripTitles — cannot express recursion.

Follow-up

BANNER_COMMENT still emits /* prettier-ignore-start */ with no matching -end. Stale before this change, now doubly so; left alone as out of scope.

🤖 Generated with Claude Code

`json-schema-to-typescript` served one command, `actor generate-schema-types`,
and dragged prettier, lodash and js-yaml into the install. Dropping just the
formatting is not possible — v15 imports prettier at module top level — so it
is replaced by a built-in emitter in src/lib/schema-to-typescript.ts.

Output is byte-identical to the old library on every repo schema fixture.
Full install drops from 55.61 MB to 43.55 MB (-21.7%).

`stripTitles` is deleted: it existed only to stop the library hoisting named
interfaces, and the new emitter ignores `title` entirely.

Closes #1310

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@github-actions github-actions Bot added this to the 147th sprint - Tooling team milestone Aug 10, 2026
@github-actions github-actions Bot added t-tooling Issues with this label are in the ownership of the tooling team. tested Temporary label used only programatically for some analytics. labels Aug 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

t-tooling Issues with this label are in the ownership of the tooling team. tested Temporary label used only programatically for some analytics.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Replace json-schema-to-typescript with a lighter type codegen (−12.5 MB)

2 participants