<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Jacob Ley</title>
    <description>The latest articles on DEV Community by Jacob Ley (@jacobley).</description>
    <link>https://dev.to/jacobley</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4231468%2Feaaff9be-d7b6-475a-91a6-ae3e575bf908.png</url>
      <title>DEV Community: Jacob Ley</title>
      <link>https://dev.to/jacobley</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/jacobley"/>
    <language>en</language>
    <item>
      <title>Rewriting a server in another language found bugs the original had missed</title>
      <dc:creator>Jacob Ley</dc:creator>
      <pubDate>Sat, 28 Nov 2026 00:00:00 +0000</pubDate>
      <link>https://dev.to/jacobley/rewriting-a-server-in-another-language-found-bugs-the-original-had-missed-2p40</link>
      <guid>https://dev.to/jacobley/rewriting-a-server-in-another-language-found-bugs-the-original-had-missed-2p40</guid>
      <description>&lt;p&gt;leyman has an &lt;a href="https://jacobley.github.io/leyman/demos/openapi/" rel="noopener noreferrer"&gt;OpenAPI demo&lt;/a&gt;: a notes API (add a note, read one, list the newest) with a spec, a TypeScript client, a Hono server and a Postgres schema, at 100% coverage, with integration tests against a real database. On November 17 I added a second client and server, in Go, built from the same &lt;code&gt;openapi.json&lt;/code&gt;, and changed the TypeScript server's integration tests to run every request against both servers. Agents wrote most of that code, under my direction. Building the Go side found three bugs in the TypeScript server, which was passing its own tests, and each was found a different way:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://www.npmjs.com/package/ajv-formats" rel="noopener noreferrer"&gt;ajv-formats&lt;/a&gt; accepts &lt;code&gt;urn:uuid:…&lt;/code&gt; as a &lt;code&gt;uuid&lt;/code&gt;, so a note id with that prefix went to Postgres, which refused it, and the client got a &lt;code&gt;500&lt;/code&gt;. The Go validator asserts the strict form, which showed the difference.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.npmjs.com/package/hono" rel="noopener noreferrer"&gt;Hono&lt;/a&gt; keeps a query escape that isn't UTF-8 (&lt;code&gt;%ff&lt;/code&gt;) as the literal text &lt;code&gt;%ff&lt;/code&gt;, where the URL standard reads it as U+FFFD. The shared suite caught this one.&lt;/li&gt;
&lt;li&gt;Neither server required &lt;code&gt;exp&lt;/code&gt; in an access token, so a token without one was good forever. No test caught it; it came up while fixing the Go server's token checks.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The versions throughout are Hono 4.13.17, ajv-formats 3.0.1 and &lt;a href="https://www.npmjs.com/package/jose" rel="noopener noreferrer"&gt;jose&lt;/a&gt; 6.2.14 on the TypeScript side, and Go 1.26, &lt;a href="https://github.com/lestrrat-go/jwx" rel="noopener noreferrer"&gt;jwx&lt;/a&gt; v3.4.0 and &lt;a href="https://github.com/santhosh-tekuri/jsonschema" rel="noopener noreferrer"&gt;santhosh-tekuri/jsonschema&lt;/a&gt; v6.0.3 on the Go side.&lt;/p&gt;

&lt;p&gt;The Go server could share the TypeScript server's tests because those tests check behaviour (what goes over HTTP, judged against what the document and the standards say) and nothing about how either server produces it.&lt;/p&gt;

&lt;p&gt;I wanted the Go side for two reasons. I'd been porting leyman's libraries to Go (&lt;a href="https://jacobley.github.io/leyman/packages/genever/" rel="noopener noreferrer"&gt;genever&lt;/a&gt; and &lt;a href="https://jacobley.github.io/leyman/packages/idempotency-keys/" rel="noopener noreferrer"&gt;idempotency-keys&lt;/a&gt; among them) and wanted to prove they work in practice, in a real application. And the repo had no demo of running a whole Go application, only small libraries.&lt;/p&gt;

&lt;h2&gt;
  
  
  Test the behaviour, not the implementation
&lt;/h2&gt;

&lt;p&gt;The TypeScript server's suite checked statuses, headers and bodies through HTTP, retries with an &lt;code&gt;Idempotency-Key&lt;/code&gt;, and JWTs from a real issuer, and its property test draws notes from the document's own &lt;code&gt;NewNote&lt;/code&gt; schema with &lt;a href="https://jacobley.github.io/leyman/packages/juniper-arbitrary/" rel="noopener noreferrer"&gt;juniper-arbitrary&lt;/a&gt;. So the tests were behavioural in form, but they were written alongside the server, and their cases were picked from what the server already handled, which left out all three above.&lt;/p&gt;

&lt;p&gt;The way out is to test behaviour instead of implementation, so the tests don't reinforce whatever the implementation already does wrong. Had the suite asserted whatever the TypeScript server answered to a search for &lt;code&gt;%ff wool&lt;/code&gt;, it would have passed while asserting Hono's mistake. A test of behaviour states what the caller should get, and takes the answer from the contract (the OpenAPI document, the URL standard, an RFC).&lt;/p&gt;

&lt;p&gt;A second implementation of the same contract comes at that from the other side: it's written separately, on other libraries, and a place where the two answer differently is a bug in one of them, a gap in the contract, or a difference both are allowed (listed under "Where the servers still differ").&lt;/p&gt;

&lt;h2&gt;
  
  
  Both servers read the same openapi.json
&lt;/h2&gt;

&lt;p&gt;Neither server lists the API by hand. The spec package writes one &lt;code&gt;openapi.json&lt;/code&gt;, and both servers read it: the TypeScript server compiles Ajv validators from it, and the Go module embeds the same bytes (&lt;code&gt;//go:embed out/openapi.json&lt;/code&gt;) and validates with santhosh-tekuri/jsonschema. Routes, scopes, parameters, schemas and the statuses each operation documents all come from the document, and the Go types are generated from it by genever-go. So the servers can only disagree where their validators read a schema differently, where the parts no document describes (authentication, idempotency, a &lt;code&gt;404&lt;/code&gt; for an unknown path) differ, or where a handler does something the document doesn't say.&lt;/p&gt;

&lt;p&gt;The integration suites for notes, idempotency keys and JWTs became one loop over both implementations. The TypeScript server runs in-process, and the Go server is its &lt;code&gt;notes-server&lt;/code&gt; binary, built once per run and started per test on port 0, with its URL read from stdout. Simplified, from &lt;a href="https://github.com/JacobLey/leyman/blob/main/demos/openapi/server/test/integration/notes.spec.ts" rel="noopener noreferrer"&gt;&lt;code&gt;notes.spec.ts&lt;/code&gt;&lt;/a&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Black-box tests, through HTTP alone, so each server is held to the same expectations&lt;/span&gt;
&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;implementation&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt; &lt;span class="n"&gt;implementations&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;suite&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sb"&gt;`Notes API on ${implementation.name}`&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;withServer&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;withDatabase&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;beforeEach&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;database&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;served&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;implementation&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;start&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;databaseUrl&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;database&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;url&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;authentication&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;tokens&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;served&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;client&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;NotesClient&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;baseUrl&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;served&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;url&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;token&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="c1"&gt;// ...every test from before, unchanged&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Each test gets its own database cloned from a template (&lt;a href="https://jacobley.github.io/leyman/packages/pg-dolly/" rel="noopener noreferrer"&gt;pg-dolly&lt;/a&gt;), so both servers start from the same empty state. Tests that reach into the TypeScript server's internals (handlers swapped for broken ones, a store that fails on purpose) can't run against a binary, so they stay in suites marked TypeScript alone. There are 6 of those, against 68 that run on both. Those 6 are useful (they check that a handler breaking the contract gets caught), but they're about this implementation.&lt;/p&gt;

&lt;p&gt;The interop tests cross between servers: a &lt;code&gt;createNote&lt;/code&gt; retried with the same &lt;code&gt;Idempotency-Key&lt;/code&gt; against the other server on the same database replays the first note, which works because both follow one &lt;a href="https://github.com/JacobLey/leyman/blob/main/tools/idempotency-keys/SPEC.md" rel="noopener noreferrer"&gt;specification&lt;/a&gt; for the key's fingerprint and row, and the Go client runs its own tests against each server.&lt;/p&gt;

&lt;h2&gt;
  
  
  What it found, in order
&lt;/h2&gt;

&lt;p&gt;The UUID came first, before the suites were even shared. JSON Schema's &lt;code&gt;uuid&lt;/code&gt; format is &lt;a href="https://json-schema.org/draft/2020-12/json-schema-validation#section-7.3.5" rel="noopener noreferrer"&gt;RFC 4122's string form&lt;/a&gt;, with no prefix, and that's what the Go validator asserts. ajv-formats also accepts &lt;code&gt;urn:uuid:00000000-0000-4000-8000-000000000000&lt;/code&gt;, so the TypeScript server's &lt;code&gt;getNote&lt;/code&gt; passed that to Postgres's &lt;code&gt;uuid&lt;/code&gt; column, Postgres refused it, and the client got a &lt;code&gt;500&lt;/code&gt; for what should have been a &lt;code&gt;400&lt;/code&gt;. The fix overrides the format in both of the server's Ajv instances with the strict pattern (&lt;a href="https://github.com/JacobLey/leyman/commit/3b6786b1" rel="noopener noreferrer"&gt;commit&lt;/a&gt;), and both servers now answer &lt;code&gt;400&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The query string turned up differences in both directions, and the first was a bug in the Go server: Go's &lt;a href="https://pkg.go.dev/net/url#ParseQuery" rel="noopener noreferrer"&gt;&lt;code&gt;url.ParseQuery&lt;/code&gt;&lt;/a&gt; drops a pair containing a &lt;code&gt;;&lt;/code&gt; or a broken escape, so &lt;code&gt;/notes?limit=1;x=1&lt;/code&gt; listed 20 notes and &lt;code&gt;/notes?q=%zz&lt;/code&gt; listed every note, where the TypeScript server answered &lt;code&gt;400&lt;/code&gt; to the first and searched for the literal &lt;code&gt;%zz&lt;/code&gt; in the second. The &lt;a href="https://url.spec.whatwg.org/#urlencoded-parsing" rel="noopener noreferrer"&gt;URL standard's parser&lt;/a&gt; sides with Hono there (pairs split on &lt;code&gt;&amp;amp;&lt;/code&gt; alone, and a &lt;code&gt;%&lt;/code&gt; without two hex digits is kept as it is), so the Go server now parses the raw query that way (&lt;a href="https://github.com/JacobLey/leyman/commit/8d4603d3" rel="noopener noreferrer"&gt;commit&lt;/a&gt;). But the same comparison caught &lt;code&gt;%ff&lt;/code&gt;, where Hono keeps the escape as text and the standard decodes it as U+FFFD, which is what Go did. So a search for &lt;code&gt;%ff wool&lt;/code&gt; matched a note titled &lt;code&gt;%ff wool&lt;/code&gt; on the TypeScript server and &lt;code&gt;� wool&lt;/code&gt; on the Go server, and only Go's was right. That test was left out of the shared suite until the TypeScript server read the query with &lt;code&gt;URLSearchParams&lt;/code&gt;, keeping Hono's other choices (the first of a repeated parameter wins, a pair without a name is ignored) (&lt;a href="https://github.com/JacobLey/leyman/commit/59a434a4" rel="noopener noreferrer"&gt;commit&lt;/a&gt;).&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.rfc-editor.org/rfc/rfc9068#section-2.2" rel="noopener noreferrer"&gt;RFC 9068&lt;/a&gt; requires &lt;code&gt;exp&lt;/code&gt; in a JWT access token, but jose and jwx only check it when it's there, and both servers relied on the library, so they agreed and the shared suite had nothing to flag. It came up during a run of fixes to the Go server's token checks, and now the JWT suite signs its own token without &lt;code&gt;exp&lt;/code&gt; and expects a &lt;code&gt;401&lt;/code&gt; from both servers (&lt;a href="https://github.com/JacobLey/leyman/commit/71ae98c0" rel="noopener noreferrer"&gt;commit&lt;/a&gt;).&lt;/p&gt;

&lt;p&gt;The Go server picked up its own fixes along the way, mostly from places where Go's defaults differ from what the TypeScript server already did: jwx requires a &lt;code&gt;kid&lt;/code&gt; when verifying against a key set where jose tries every key that fits, net/http recovers a panicking handler by dropping the connection instead of answering &lt;code&gt;500&lt;/code&gt;, and Go's &lt;code&gt;ServeMux&lt;/code&gt; answers a missing method with a plain-text &lt;code&gt;405&lt;/code&gt; of its own. Those are listed in the &lt;a href="https://github.com/JacobLey/leyman/blob/main/demos/openapi/go/README.md#what-was-learned" rel="noopener noreferrer"&gt;Go README&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Neither server decided which answer was right
&lt;/h2&gt;

&lt;p&gt;The UUID fix links JSON Schema's definition of &lt;code&gt;uuid&lt;/code&gt; in a comment. The query tests carry comments linking the URL standard's &lt;a href="https://url.spec.whatwg.org/#percent-decode" rel="noopener noreferrer"&gt;percent-decoding&lt;/a&gt; and urlencoded parsing sections, and they went against the TypeScript server once (&lt;code&gt;%ff&lt;/code&gt;) and against the Go server twice (&lt;code&gt;;&lt;/code&gt; and &lt;code&gt;%zz&lt;/code&gt;). The &lt;code&gt;exp&lt;/code&gt; test follows RFC 9068, against both servers at once (its commit cites the section). If "whatever the TypeScript server does" had been the reference, the Go server would have copied Hono's &lt;code&gt;%ff&lt;/code&gt; bug to pass, and if it had been the Go server, the TypeScript server would have copied Go's &lt;code&gt;;&lt;/code&gt; bug.&lt;/p&gt;

&lt;h2&gt;
  
  
  Where the servers still differ
&lt;/h2&gt;

&lt;p&gt;Each server's message for a request that doesn't match the document comes from its own validator and is allowed to differ, so the shared tests check the status and the error code, and not the text. Go's &lt;code&gt;ServeMux&lt;/code&gt; answers a path that isn't clean (&lt;code&gt;/notes/../notes&lt;/code&gt;) with a &lt;code&gt;307&lt;/code&gt; to the cleaned path before authentication, while the TypeScript server resolves dot segments as the URL standard does, and that's listed under the Go README's &lt;a href="https://github.com/JacobLey/leyman/blob/main/demos/openapi/go/README.md#not-covered" rel="noopener noreferrer"&gt;Not covered&lt;/a&gt;. jwx also refuses a token whose &lt;code&gt;iat&lt;/code&gt; is in the future, which jose doesn't check.&lt;/p&gt;

&lt;p&gt;The cost is a second server to maintain. The Go server, its binary and its reading of the document come to about 2,300 lines without tests or generated types, against about 1,100 in the TypeScript server's source. Neither hand-codes an operation, so a spec change still reaches both at once.&lt;/p&gt;

&lt;h2&gt;
  
  
  When I'd write the second one
&lt;/h2&gt;

&lt;p&gt;Not always, but in general I try to solve a problem in a language-agnostic way, because that keeps the focus on the problem rather than on one solution to it. The exception is a solution that only makes sense in one language: the TypeScript client here takes its types from the YAML document through a TypeScript content mapper at compile time, which has no Go equivalent, so Go gets committed, generated types instead, and there's nothing to compare.&lt;/p&gt;

&lt;p&gt;To run both servers through the suite, in a &lt;a href="https://github.com/JacobLey/leyman" rel="noopener noreferrer"&gt;leyman&lt;/a&gt; checkout (the devcontainer has Go and the Postgres sidecar):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;nx run @leyman/demo-openapi-server:test

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The Go side has its own tests too, with &lt;code&gt;nx run @leyman/demo-openapi-go:verify&lt;/code&gt;.&lt;/p&gt;

</description>
      <category>backend</category>
      <category>go</category>
      <category>softwaredevelopment</category>
      <category>testing</category>
    </item>
    <item>
      <title>An agent's sandbox: every worktree is a standalone devcontainer</title>
      <dc:creator>Jacob Ley</dc:creator>
      <pubDate>Thu, 19 Nov 2026 00:00:00 +0000</pubDate>
      <link>https://dev.to/jacobley/an-agents-sandbox-every-worktree-is-a-standalone-devcontainer-5f13</link>
      <guid>https://dev.to/jacobley/an-agents-sandbox-every-worktree-is-a-standalone-devcontainer-5f13</guid>
      <description>&lt;p&gt;Once I leaned into agentic development, I often had more than one task I wanted to work on at once, and I wanted each &lt;a href="https://www.npmjs.com/package/@anthropic-ai/claude-code" rel="noopener noreferrer"&gt;Claude Code&lt;/a&gt; session to just work. A single checkout doesn't give you that. It has one set of installed dependencies, one database and one dev server, so two sessions working in it on different tasks tread on each other. That was only a bit of a problem in practice, but for each session to just work it needed an isolated environment.&lt;/p&gt;

&lt;p&gt;On &lt;a href="https://github.com/JacobLey/leyman" rel="noopener noreferrer"&gt;leyman&lt;/a&gt;, my monorepo, every session now gets a &lt;a href="https://git-scm.com/docs/git-worktree" rel="noopener noreferrer"&gt;git worktree&lt;/a&gt; opened in its own &lt;a href="https://containers.dev/" rel="noopener noreferrer"&gt;devcontainer&lt;/a&gt;, with its own Postgres, Valkey and HTTPS origin, and the only things sessions share are caches. The part that carries to any repo is that a worktree should map to an isolated(-ish) container, and that once every environment has real services in it, it is better to test against those than against mocks.&lt;/p&gt;

&lt;h2&gt;
  
  
  Every task gets a full environment, as every tab did on Meta's DevServers
&lt;/h2&gt;

&lt;p&gt;The original inspiration was Meta's &lt;a href="https://developers.facebook.com/blog/post/2022/11/15/meta-developers-workflow-exploring-tools-used-to-code/" rel="noopener noreferrer"&gt;DevServer setup&lt;/a&gt;: on-demand servers that just work, with a full environment, where each VS Code tab was a completely separate machine. I don't need VMs in the cloud to follow the same pattern, because a worktree plus a devcontainer gives each session its own full environment on one machine. A single session &lt;em&gt;should&lt;/em&gt; be able to be as chaotic as it needs to be when testing, without risking the other sessions, and if it really goes off the rails, it is one container rebuild away from recovery.&lt;/p&gt;

&lt;p&gt;I run about three sessions at once on leyman, and use the same pattern in other repos, so this is less about incredible horizontal scale than about following a pattern of "one click setup". A new session's environment is built from nothing, so any manual step would have to be repeated in every worktree, which makes it a forcing function: setting up the entire repo &lt;em&gt;has&lt;/em&gt; to be codified. Once it is, going from downloading the repo to running it locally is a single "build container" away, for a person as much as for an agent.&lt;/p&gt;

&lt;h2&gt;
  
  
  Isolate what holds state, and share what's expensive to rebuild
&lt;/h2&gt;

&lt;p&gt;Each session keeps to itself whatever holds state: the checkout and the dependencies installed into it, its databases, and the origin its dev server answers on. What the sessions share is what's expensive to rebuild and safe to share, like a package manager's content-addressed store and build caches keyed by their inputs, and most tools take their cache directory from an environment variable. Inside its environment every session sees the same names (the database is at the same hostname, so &lt;code&gt;DATABASE_URL&lt;/code&gt; is the same string everywhere), which means no configuration is derived per session.&lt;/p&gt;

&lt;p&gt;The "-ish" is that none of this is a security sandbox between sessions. Each leyman container mounts every worktree read-write and talks to the host's Docker, so a session can still delete another worktree or stop its containers. At the end of the day an agent could be highly destructive to the other worktrees, but I haven't found that to be a realistic concern: as long as work is pushed to GitHub periodically, there isn't much damage it can do.&lt;/p&gt;

&lt;h2&gt;
  
  
  A mock is always catching up with the service you could run locally
&lt;/h2&gt;

&lt;p&gt;Giving every session its own database is also what lets the tests stop mocking it. Mocks are always playing catch-up with the service they stand in for, and there's little point mocking "insert into the database and read it back" when you can just &lt;em&gt;do&lt;/em&gt; the write and the read in a local Postgres, or mocking that an email can be sent when you can run an actual SMTP server locally. Many of the best services come with a local version, even AWS ones (&lt;a href="https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/DynamoDBLocal.html" rel="noopener noreferrer"&gt;DynamoDB local&lt;/a&gt;, for example). Mocks aren't 100% avoidable (an integration with Slack probably needs to be mocked out), but that also means being &lt;em&gt;very&lt;/em&gt; careful about isolating what you depend on and take in from Slack behind a well-shaped interface.&lt;/p&gt;

&lt;p&gt;I'm sure there are edge cases to "can run locally", but it is the general preference. Many times the pushback is something like "it's harder to do" or "I can't properly isolate tests", and that is a setup issue. Lean into local services as the preferred solution, and once the setup is there, future tests are easier. You need a way to test "if the setup is X and I do Y, Z happens" against a realistic local service anyway, because if you can't do that, you probably don't have a strong understanding of your system, and the same "I can't know if it works correctly" is going to rear its ugly head in prod. I would much rather deal with those headaches on my local machine &lt;em&gt;before&lt;/em&gt; they get to prod.&lt;/p&gt;

&lt;p&gt;It does take very intentional consideration in your code. No session has a database that somebody set up by hand, so every table, seed row and extension has to come from a script, and codifying all of that is easier said than done.&lt;/p&gt;

&lt;h2&gt;
  
  
  The same images run locally and in CI, at the versions meant for prod
&lt;/h2&gt;

&lt;p&gt;The other half of the benefit is parity. The services a test talks to on my machine are the same images CI runs, and those versions should generally match what you intend to run in prod, so testing locally, then in Docker, then in prod happens with fairly consistent logic. If anything CI could cover a wider range than local does (iterating the tests on both Postgres 17 and 18, say), though leyman's doesn't today.&lt;/p&gt;

&lt;p&gt;In leyman, &lt;a href="https://www.postgresql.org/" rel="noopener noreferrer"&gt;Postgres&lt;/a&gt; and &lt;a href="https://valkey.io/" rel="noopener noreferrer"&gt;Valkey&lt;/a&gt; are sidecars in each worktree's compose project. Every worktree reaches them at &lt;code&gt;postgres:5432&lt;/code&gt; and &lt;code&gt;valkey:6379&lt;/code&gt;, because each compose project has its own default network and those names resolve on it to that worktree's containers. Neither keeps anything, and the compose file says why:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;postgres&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
  &lt;span class="c1"&gt;# Nothing is persisted (in memory, not even an anonymous volume), so a restart starts from empty.
&lt;/span&gt;  &lt;span class="c1"&gt;# Dev data comes from scripts, never from what a database happens to hold.
&lt;/span&gt;  &lt;span class="na"&gt;tmpfs&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="s"&gt;/var/lib/postgresql&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For the "I can't properly isolate tests" part, &lt;a href="https://jacobley.github.io/leyman/packages/pg-dolly/" rel="noopener noreferrer"&gt;pg-dolly&lt;/a&gt; builds a template database from the schema's SQL once and gives each test its own copy, so parallel tests on one worktree's server don't see each other. CI runs the tests in &lt;a href="https://dagger.io/" rel="noopener noreferrer"&gt;Dagger&lt;/a&gt; with the same Postgres and Valkey images, pinned by the same digests and under the same hostnames, and a &lt;code&gt;check-parity&lt;/code&gt; target fails when the pins drift (&lt;a href="https://github.com/JacobLey/leyman/blob/main/.agents/skills/devcontainer/SKILL.md#version-parity-devcontainer--dagger" rel="noopener noreferrer"&gt;devcontainer skill&lt;/a&gt;).&lt;/p&gt;

&lt;h2&gt;
  
  
  What you'd hit copying leyman's setup
&lt;/h2&gt;

&lt;p&gt;The whole thing is the &lt;a href="https://github.com/JacobLey/leyman/blob/main/.devcontainer/docker-compose.yml" rel="noopener noreferrer"&gt;compose file&lt;/a&gt;, &lt;a href="https://github.com/JacobLey/leyman/blob/main/.devcontainer/initialize.sh" rel="noopener noreferrer"&gt;&lt;code&gt;initialize.sh&lt;/code&gt;&lt;/a&gt; (which runs on the host before the container starts) and &lt;a href="https://github.com/JacobLey/leyman/blob/main/scripts/worktree" rel="noopener noreferrer"&gt;&lt;code&gt;scripts/worktree&lt;/code&gt;&lt;/a&gt; (the one click: &lt;code&gt;scripts/worktree new feat/x&lt;/code&gt;), along with the &lt;a href="https://github.com/JacobLey/leyman/blob/main/.agents/skills/worktrees/SKILL.md" rel="noopener noreferrer"&gt;worktrees&lt;/a&gt; and &lt;a href="https://github.com/JacobLey/leyman/blob/main/.agents/skills/devcontainer/SKILL.md" rel="noopener noreferrer"&gt;devcontainer&lt;/a&gt; skills, which are what the agents read. The high-level architecture is entirely mine, but actually getting the implementation working, iterated on and debugged was an agent-heavy process. An agent is just so much faster at writing Dockerfiles than a human could hope to be.&lt;/p&gt;

&lt;p&gt;Worktrees go in a folder beside the main checkout, with the shared caches next to them:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;~/code/
  leyman/ &amp;lt;- main checkout, owns .git
  leyman-worktrees/
    feat-x/ &amp;lt;- worktree for branch feat/x
    .shared/
      pnpm-store/, pnpm-cache/
      go-build/, go-mod/
      nx-cache/ &amp;lt;- served by the nx-cache sidecar

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Every container mounts the main checkout and the worktrees folder at the absolute paths they have on the host. Git records absolute paths in a worktree's links to the main checkout's &lt;code&gt;.git&lt;/code&gt;, and they have to resolve from both sides. Docker inside the container is also the host's Docker (&lt;a href="https://github.com/devcontainers/features/tree/main/src/docker-outside-of-docker" rel="noopener noreferrer"&gt;docker-outside-of-docker&lt;/a&gt;, which Dagger needs), so a bind mount started from inside names a path that the host's daemon resolves on the host.&lt;/p&gt;

&lt;p&gt;The &lt;a href="https://pnpm.io/" rel="noopener noreferrer"&gt;pnpm&lt;/a&gt; store is shared by setting &lt;code&gt;pnpm_config_store_dir&lt;/code&gt; in the container's environment, and it has one trap: &lt;a href="https://pnpm.io/settings#storedir" rel="noopener noreferrer"&gt;&lt;code&gt;storeDir&lt;/code&gt;&lt;/a&gt; in &lt;code&gt;pnpm-workspace.yaml&lt;/code&gt; takes precedence over the environment variable, so setting it would quietly give each worktree its own store again.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.npmjs.com/package/nx" rel="noopener noreferrer"&gt;Nx&lt;/a&gt; couldn't share its cache through a folder. It only restores a result that has a row in its cache database (&lt;a href="https://github.com/nrwl/nx/blob/19a9e5f4e525b517faa4b1ab086781c9d158957d/packages/nx/src/native/cache/cache.rs#L275-L303" rel="noopener noreferrer"&gt;&lt;code&gt;cache.rs&lt;/code&gt;&lt;/a&gt;), and pointing &lt;code&gt;NX_CACHE_DIRECTORY&lt;/code&gt; at a shared folder leaves that database in each checkout's own &lt;code&gt;.nx/&lt;/code&gt; (&lt;a href="https://github.com/nrwl/nx/blob/19a9e5f4e525b517faa4b1ab086781c9d158957d/packages/nx/src/utils/cache-directory.ts#L310-L326" rel="noopener noreferrer"&gt;&lt;code&gt;cache-directory.ts&lt;/code&gt;&lt;/a&gt;), so anything another worktree built is a miss. Nx's self-hosted remote cache does work across worktrees, so each compose project runs a small cache server as a sidecar (&lt;a href="https://github.com/JacobLey/leyman/blob/main/.devcontainer/nx-cache-server.mjs" rel="noopener noreferrer"&gt;&lt;code&gt;nx-cache-server.mjs&lt;/code&gt;&lt;/a&gt;), all of them reading and writing the same &lt;code&gt;.shared/nx-cache&lt;/code&gt;. Nx 24 can do the cross-worktree part itself (&lt;a href="https://github.com/nrwl/nx/pull/36514" rel="noopener noreferrer"&gt;nrwl/nx#36514&lt;/a&gt;), but the sidecar stays for now because it also reads results it doesn't have from the hosted cache that CI on &lt;code&gt;main&lt;/code&gt; writes to (&lt;a href="https://github.com/JacobLey/leyman/commit/cb89b60a" rel="noopener noreferrer"&gt;commit&lt;/a&gt;), so a new worktree doesn't start cold.&lt;/p&gt;

&lt;p&gt;Rebuild Container once failed for me with &lt;code&gt;container is marked for removal and cannot be started&lt;/code&gt;, while two other repos' devcontainers were rebuilding at the same time. Docker was still deleting the old container when the Dev Containers extension ran &lt;code&gt;docker compose up --no-recreate&lt;/code&gt;, so compose found the old one (&lt;a href="https://github.com/microsoft/vscode-remote-release/issues/11967" rel="noopener noreferrer"&gt;microsoft/vscode-remote-release#11967&lt;/a&gt;; I've seen it once, and retrying worked). The race is the extension's, but how long a delete takes is partly up to me, because Docker deletes everything the container wrote to its own filesystem along with it. So what grows moved out of the container (&lt;a href="https://github.com/JacobLey/leyman/commit/12c4ae75" rel="noopener noreferrer"&gt;commit&lt;/a&gt;): pnpm's metadata cache and Go's caches to &lt;code&gt;.shared/&lt;/code&gt;, and &lt;code&gt;/tmp&lt;/code&gt; to a &lt;a href="https://docs.docker.com/engine/storage/tmpfs/" rel="noopener noreferrer"&gt;tmpfs&lt;/a&gt;, which took the container's layer from 2.44 GB to 1.08 GB by &lt;code&gt;docker ps --size&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;That tmpfs then broke every &lt;code&gt;nx&lt;/code&gt; command. Docker mounts a tmpfs &lt;code&gt;noexec&lt;/code&gt; by default, and Nx copies its native binding to &lt;code&gt;/tmp/.nx&lt;/code&gt; and loads it from there (always the literal &lt;code&gt;/tmp&lt;/code&gt;, never &lt;code&gt;$TMPDIR&lt;/code&gt;), so it falls back to WASM, which fails with &lt;code&gt;WorkspaceContext is not a constructor&lt;/code&gt;. The mount has to be &lt;code&gt;/tmp:exec&lt;/code&gt; (&lt;a href="https://github.com/JacobLey/leyman/commit/b42b45e7" rel="noopener noreferrer"&gt;commit&lt;/a&gt;).&lt;/p&gt;

&lt;p&gt;For the dev server, one &lt;a href="https://caddyserver.com/" rel="noopener noreferrer"&gt;Caddy&lt;/a&gt; per machine routes &lt;code&gt;https://&amp;lt;worktree&amp;gt;.&amp;lt;repo&amp;gt;.localhost&lt;/code&gt; to that worktree's container (&lt;a href="https://github.com/JacobLey/leyman/blob/main/tools/local-ingress/README.md" rel="noopener noreferrer"&gt;&lt;code&gt;tools/local-ingress&lt;/code&gt;&lt;/a&gt;). Browsers resolve &lt;code&gt;*.localhost&lt;/code&gt; to loopback themselves (&lt;a href="https://www.rfc-editor.org/rfc/rfc6761#section-6.3" rel="noopener noreferrer"&gt;RFC 6761, section 6.3&lt;/a&gt;), and because every worktree is its own origin, cookies and OAuth redirect URIs don't collide.&lt;/p&gt;

&lt;h2&gt;
  
  
  A worktree costs about 2 GiB of memory
&lt;/h2&gt;

&lt;p&gt;The machine is a Mac with 36 GB of RAM, 24 GB of it granted to &lt;a href="https://orbstack.dev/" rel="noopener noreferrer"&gt;OrbStack&lt;/a&gt;, which I did have to raise from 10 GB at one point. One leyman worktree's compose project came to between 1.9 and 2.5 GiB over three &lt;code&gt;docker stats --no-stream&lt;/code&gt; readings, nearly all of it the workspace container.&lt;/p&gt;

&lt;h2&gt;
  
  
  Where to start
&lt;/h2&gt;

&lt;p&gt;Simply adopt devcontainers to start. That alone means nobody has to manage &lt;code&gt;nvm&lt;/code&gt;, or coordinate across teams to get everyone on the right version of Python. From there, sharing data across devcontainers (the pnpm store, say) is fairly straightforward. The long-term goal is the database setup, since that is the part that asks something of your code.&lt;/p&gt;

&lt;p&gt;This blog's repo is a much smaller copy to start from: its &lt;a href="https://github.com/JacobLey/jacobley.github.io/tree/main/.devcontainer" rel="noopener noreferrer"&gt;&lt;code&gt;.devcontainer&lt;/code&gt;&lt;/a&gt; has Node.js and pnpm as its toolchain, no Nx and no databases.&lt;/p&gt;

</description>
      <category>agents</category>
      <category>containers</category>
      <category>devops</category>
      <category>git</category>
    </item>
    <item>
      <title>A cached Nx run took almost 3 minutes. Now it takes 40 seconds</title>
      <dc:creator>Jacob Ley</dc:creator>
      <pubDate>Sun, 15 Nov 2026 13:53:22 +0000</pubDate>
      <link>https://dev.to/jacobley/a-cached-nx-run-took-almost-3-minutes-now-it-takes-40-seconds-2oh4</link>
      <guid>https://dev.to/jacobley/a-cached-nx-run-took-almost-3-minutes-now-it-takes-40-seconds-2oh4</guid>
      <description>&lt;p&gt;In &lt;a href="https://github.com/JacobLey/leyman" rel="noopener noreferrer"&gt;leyman&lt;/a&gt;, &lt;code&gt;verify&lt;/code&gt; is the stage that runs every check and every test. Nothing had changed, so all 1,796 tasks were cache hits, and &lt;code&gt;nx run-many -t verify&lt;/code&gt; still took between 2m 22s and 2m 54s. On November 1 I got that down to about 40 seconds.&lt;/p&gt;

&lt;p&gt;Most of the time went to one bug in &lt;a href="https://www.npmjs.com/package/nx" rel="noopener noreferrer"&gt;Nx&lt;/a&gt;: without the Nx daemon, each pass of task hashing copied the result of every task hashed so far into native code, and threw the copy away. I patched it locally the same day and sent the fix upstream as &lt;a href="https://github.com/nrwl/nx/pull/37714" rel="noopener noreferrer"&gt;nrwl/nx#37714&lt;/a&gt;. It's in Nx 24.0.4, so you just need to upgrade.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Setup (62 projects, 1,796 tasks, 14 cores)&lt;/th&gt;
&lt;th&gt;Warm &lt;code&gt;verify&lt;/code&gt;
&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Nx 23.3.1, no daemon, as Nx defaults to in Docker&lt;/td&gt;
&lt;td&gt;2m 22s–2m 54s&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Nx 23.3.1 with the patch, no daemon&lt;/td&gt;
&lt;td&gt;37.5s&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Nx 23.3.1 with the patch, daemon on, &lt;code&gt;NX_PARALLEL=5&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;about 40s&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Nx 24.0.5, no patch, no daemon&lt;/td&gt;
&lt;td&gt;36s&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The Nx 23.3.1 rows were measured on November 1, the Nx 24.0.5 row on November 15, when leyman upgraded (&lt;a href="https://github.com/JacobLey/leyman/commit/3cb81500" rel="noopener noreferrer"&gt;commit&lt;/a&gt;). The first two rows come from &lt;a href="https://github.com/nrwl/nx/pull/37714" rel="noopener noreferrer"&gt;the pull request&lt;/a&gt;. Per call, the native hash planner went from about 400ms to about 11ms.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why a cached run is slow at all
&lt;/h2&gt;

&lt;p&gt;The &lt;a href="https://jacobley.github.io/blog/nx-lifecycle" rel="noopener noreferrer"&gt;previous post&lt;/a&gt; covered how &lt;a href="https://jacobley.github.io/leyman/packages/nx-lifecycle/" rel="noopener noreferrer"&gt;nx-lifecycle&lt;/a&gt; orders leyman's targets into stages. &lt;code&gt;verify&lt;/code&gt; sits at the end and depends on &lt;code&gt;check&lt;/code&gt; and &lt;code&gt;test&lt;/code&gt; (&lt;a href="https://github.com/JacobLey/leyman/blob/main/leyman/main/lifecycle.json" rel="noopener noreferrer"&gt;&lt;code&gt;lifecycle.json&lt;/code&gt;&lt;/a&gt;), so running it for every project pulls in builds, lint, type checks, packaging checks and tests across all 62 projects.&lt;/p&gt;

&lt;p&gt;Nx still hashes every task's inputs on a cache hit. In leyman a lot of those inputs are &lt;code&gt;dependentTasksOutputFiles&lt;/code&gt; (files the dependencies' tasks produced), which can't be hashed until the dependency is done, so it hashes in waves. A full warm &lt;code&gt;verify&lt;/code&gt; called the native planner about 270 times.&lt;/p&gt;

&lt;h2&gt;
  
  
  Profiling it
&lt;/h2&gt;

&lt;p&gt;leyman's &lt;a href="https://github.com/JacobLey/leyman/tree/main/.devcontainer" rel="noopener noreferrer"&gt;devcontainer&lt;/a&gt; runs in Docker, and Nx turns its &lt;a href="https://nx.dev/concepts/nx-daemon" rel="noopener noreferrer"&gt;daemon&lt;/a&gt; off in Docker by default (&lt;a href="https://github.com/nrwl/nx/issues/14126" rel="noopener noreferrer"&gt;nrwl/nx#14126&lt;/a&gt;). CI runs without one too. So I was never running with a daemon.&lt;/p&gt;

&lt;p&gt;I ran Nx under Node.js's CPU profiler, &lt;a href="https://nodejs.org/api/cli.html#--cpu-prof" rel="noopener noreferrer"&gt;&lt;code&gt;node --cpu-prof&lt;/code&gt;&lt;/a&gt;, pointed at Nx's own entry point. From leyman's root:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;node --cpu-prof leyman/main/node_modules/nx/dist/bin/nx.js run-many -t verify

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I didn't open the profile myself. This whole investigation was heavily AI-assisted, and I had Claude read it. It put most of the main thread's time in the hasher's &lt;code&gt;plan&lt;/code&gt; method, which calls the planner, so our first conclusion was that Nx re-planned the graph for every task. That turned out to be wrong. The profiler counts the time spent converting arguments for native code against the caller, so the planner looked slow but wasn't. What was slow was converting the stuff &lt;code&gt;plan&lt;/code&gt; handed it.&lt;/p&gt;

&lt;h2&gt;
  
  
  The planner's input
&lt;/h2&gt;

&lt;p&gt;The planner is written in Rust and called through &lt;a href="https://nodejs.org/api/n-api.html" rel="noopener noreferrer"&gt;N-API&lt;/a&gt;, which converts JavaScript objects into native structures on every call. It does that on the main thread, blocking. And the hasher was passing it the whole live task graph.&lt;/p&gt;

&lt;p&gt;As each task is hashed, Nx writes its &lt;code&gt;hash&lt;/code&gt; and &lt;code&gt;hashDetails&lt;/code&gt; onto the task object in the graph, and &lt;code&gt;hashDetails&lt;/code&gt; holds the hash of every input: in leyman about a million entries by the end of a run. The planner reads neither field, but N-API converted them anyway, so every wave copied the details of every task hashed before it. So each call got slower as the run went on, up to about 400ms. Times ~270 calls, that's roughly 112 seconds of a warm &lt;code&gt;verify&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Nx had actually fixed this twice already. &lt;a href="https://github.com/nrwl/nx/pull/36716" rel="noopener noreferrer"&gt;nrwl/nx#36716&lt;/a&gt; stopped resending results to the daemon and &lt;a href="https://github.com/nrwl/nx/pull/37015" rel="noopener noreferrer"&gt;nrwl/nx#37015&lt;/a&gt; stopped sending them to task workers, both through a helper called &lt;code&gt;pruneTaskGraph&lt;/code&gt; that strips run results off the graph. Nobody had added it to the daemonless planner call.&lt;/p&gt;

&lt;h2&gt;
  
  
  The patch
&lt;/h2&gt;

&lt;p&gt;The fix just prunes the graph before it goes to the planner. leyman carried it as a &lt;a href="https://pnpm.io/settings#patcheddependencies" rel="noopener noreferrer"&gt;pnpm patch&lt;/a&gt; of Nx 23.3.1's compiled code (&lt;a href="https://github.com/JacobLey/leyman/blob/49959e5128b9959326b5f36c9069d2be7979ed17/patches/nx@23.3.1.patch" rel="noopener noreferrer"&gt;the patch&lt;/a&gt;, &lt;a href="https://github.com/JacobLey/leyman/commit/49959e51" rel="noopener noreferrer"&gt;commit&lt;/a&gt;):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;     &lt;span class="nf"&gt;plan&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;taskIds&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;taskGraph&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;ultracacheConfigurations&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;prunedGraph&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;prune_task_graph_1&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;pruneTaskGraph&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;taskGraph&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
         &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="n"&gt;ultracacheConfigurations&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;planner&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getPlansReference&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;taskIds&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;taskGraph&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;planner&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getPlansReference&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;taskIds&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;prunedGraph&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
         &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;planner&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getPlansReference&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;taskIds&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;taskGraph&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;ultracacheConfigurations&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;overrides_1&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ultracacheEligibilityOptions&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;projectGraph&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;taskGraph&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;planner&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getPlansReference&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;taskIds&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;prunedGraph&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;ultracacheConfigurations&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;overrides_1&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ultracacheEligibilityOptions&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;projectGraph&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;taskGraph&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
     &lt;span class="p"&gt;}&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Only the planner gets the pruned copy. Everything else still reads the original graph. To check that the change was safe, I compared the hashes of all 1,796 tasks with and without it. They were identical, apart from one flip I come back to below.&lt;/p&gt;

&lt;h2&gt;
  
  
  Upstream
&lt;/h2&gt;

&lt;p&gt;I sent the same change upstream as &lt;a href="https://github.com/nrwl/nx/pull/37714" rel="noopener noreferrer"&gt;nrwl/nx#37714&lt;/a&gt;. It was merged on November 2 and released in &lt;a href="https://github.com/nrwl/nx/releases/tag/24.0.4" rel="noopener noreferrer"&gt;Nx 24.0.4&lt;/a&gt; on November 3. No 23.x release has it.&lt;/p&gt;

&lt;p&gt;leyman ran the patch until November 15, when it moved to Nx 24.0.5 and dropped it (&lt;a href="https://github.com/JacobLey/leyman/commit/3cb81500" rel="noopener noreferrer"&gt;commit&lt;/a&gt;). That's 24.0.5 rather than the newer 24.0.6 because leyman only installs releases at least 7 days old. On stock 24.0.5, a warm &lt;code&gt;verify&lt;/code&gt; without the daemon takes 36s, about the same as 23.3.1 with the patch.&lt;/p&gt;

&lt;h2&gt;
  
  
  The other changes
&lt;/h2&gt;

&lt;p&gt;Two settings in the devcontainer changed the same day.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;NX_DAEMON=true&lt;/code&gt; turns the daemon back on (&lt;a href="https://github.com/JacobLey/leyman/commit/e05797d5" rel="noopener noreferrer"&gt;commit&lt;/a&gt;). Nx turns it off in Docker so that a container exiting can't cut off Nx Cloud's background calls, and leyman doesn't use Nx Cloud. With the daemon on, a single-project command starts about a second sooner, and outputs already on disk aren't restored again. The daemon path was already fixed by #36716. CI doesn't use the daemon though, so CI still needed the patch.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;NX_PARALLEL=5&lt;/code&gt; moved from &lt;code&gt;.bashrc&lt;/code&gt; into the devcontainer's environment (&lt;a href="https://github.com/JacobLey/leyman/commit/e3d87f41" rel="noopener noreferrer"&gt;commit&lt;/a&gt;). It had only reached bash, while the terminals and editor tasks ran zsh and so used Nx's default of 3 parallel tasks. It's still 5 (CPU count, capped at 5), same as the old &lt;code&gt;.bashrc&lt;/code&gt; line.&lt;/p&gt;

&lt;p&gt;I also measured the tasks that never cache, in case they were the problem. Nope. &lt;code&gt;sync-injected&lt;/code&gt; is 48ms, &lt;code&gt;biome&lt;/code&gt; 49ms, and all the no-op tasks together about a second.&lt;/p&gt;

&lt;h2&gt;
  
  
  A hash that wouldn't stay put
&lt;/h2&gt;

&lt;p&gt;While comparing hashes, one target's kept changing between identical runs. &lt;code&gt;check-package&lt;/code&gt; lists the &lt;code&gt;ignore&lt;/code&gt; package in its &lt;a href="https://github.com/JacobLey/leyman/blob/main/nx.json" rel="noopener noreferrer"&gt;&lt;code&gt;externalDependencies&lt;/code&gt;&lt;/a&gt;, and leyman's lockfile has three versions of it: 5.3.2, 7.0.6 and 7.0.14. With no single &lt;code&gt;ignore&lt;/code&gt; to match, Nx 23.3.1 took the first matching version from a Rust &lt;code&gt;HashMap&lt;/code&gt;, whose iteration order changes per process. When a run picked a version whose hash wasn't cached yet, all 29 &lt;code&gt;check-package&lt;/code&gt; tasks reran, about 74 seconds.&lt;/p&gt;

&lt;p&gt;That one was already fixed upstream by &lt;a href="https://github.com/nrwl/nx/pull/37327" rel="noopener noreferrer"&gt;nrwl/nx#37327&lt;/a&gt;, which hashes every installed version in sorted order. It shipped in Nx 24.0.0 and wasn't backported to 23.x, so leyman got it with the same upgrade.&lt;/p&gt;

&lt;h2&gt;
  
  
  What's left
&lt;/h2&gt;

&lt;p&gt;About 24 of the remaining 40 seconds are Nx hashing dependencies' outputs on the main thread, in &lt;code&gt;hashPlansFor&lt;/code&gt;. Those hashes are needed for the &lt;code&gt;dependentTasksOutputFiles&lt;/code&gt; inputs. Moving it off the main thread is the next thing I'd look at.&lt;/p&gt;

&lt;h2&gt;
  
  
  Timing it yourself
&lt;/h2&gt;

&lt;p&gt;This needs Nx and the whole workspace, so it can't run in the browser. In leyman's devcontainer (&lt;code&gt;nx&lt;/code&gt; is on the &lt;code&gt;PATH&lt;/code&gt; there; elsewhere use &lt;code&gt;leyman/main/node_modules/.bin/nx&lt;/code&gt; after &lt;code&gt;pnpm install&lt;/code&gt;), run &lt;code&gt;verify&lt;/code&gt; once to fill the cache, then time a second run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;nx run-many -t verify
&lt;span class="k"&gt;time&lt;/span&gt; &lt;span class="nv"&gt;NX_DAEMON&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;false&lt;/span&gt; nx run-many -t verify

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;NX_DAEMON=false&lt;/code&gt; matters: with the daemon on, Nx 23.3.1 takes the already-fixed path and the difference disappears. To see the old behaviour, check out the commit just before the patch, which is Nx 23.3.1 unpatched, and repeat:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git checkout 49959e51~1 &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; pnpm install
nx run-many -t verify
&lt;span class="k"&gt;time&lt;/span&gt; &lt;span class="nv"&gt;NX_DAEMON&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;false&lt;/span&gt; nx run-many -t verify

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then do the same on the upgrade to Nx 24.0.5:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git checkout 3cb81500 &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; pnpm install
nx run-many -t verify
&lt;span class="k"&gt;time&lt;/span&gt; &lt;span class="nv"&gt;NX_DAEMON&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;false&lt;/span&gt; nx run-many -t verify

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Run each a few times: on 23.3.1 the &lt;code&gt;check-package&lt;/code&gt; flip can add over a minute to any one run.&lt;/p&gt;

&lt;p&gt;In your own workspace, the test is the same: time a fully cached &lt;code&gt;nx run-many&lt;/code&gt; with &lt;code&gt;NX_DAEMON=false&lt;/code&gt; before and after upgrading to Nx 24.0.4 or later.&lt;/p&gt;

</description>
      <category>performance</category>
      <category>softwaredevelopment</category>
      <category>tooling</category>
    </item>
    <item>
      <title>nx-lifecycle: dependency injection for Nx task pipelines</title>
      <dc:creator>Jacob Ley</dc:creator>
      <pubDate>Sun, 15 Nov 2026 06:12:54 +0000</pubDate>
      <link>https://dev.to/jacobley/nx-lifecycle-dependency-injection-for-nx-task-pipelines-3k26</link>
      <guid>https://dev.to/jacobley/nx-lifecycle-dependency-injection-for-nx-task-pipelines-3k26</guid>
      <description>&lt;p&gt;On November 1, Rust became a supported language in &lt;a href="https://github.com/JacobLey/leyman" rel="noopener noreferrer"&gt;leyman&lt;/a&gt;, my monorepo (&lt;a href="https://github.com/JacobLey/leyman/commit/97a41c04" rel="noopener noreferrer"&gt;commit&lt;/a&gt;). That meant five new &lt;a href="https://nx.dev/" rel="noopener noreferrer"&gt;Nx&lt;/a&gt; targets: &lt;code&gt;rustfmt&lt;/code&gt;, &lt;code&gt;rust-clippy&lt;/code&gt;, &lt;code&gt;rust-wasm&lt;/code&gt;, &lt;code&gt;rust-test&lt;/code&gt; and &lt;code&gt;rust-coverage-report&lt;/code&gt;. They all have to run in the right order. Format first, build the wasm before anything imports it, coverage after tests.&lt;/p&gt;

&lt;p&gt;The ordering itself only took five lines in &lt;a href="https://github.com/JacobLey/leyman/blob/main/leyman/main/lifecycle.json" rel="noopener noreferrer"&gt;&lt;code&gt;lifecycle.json&lt;/code&gt;&lt;/a&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;"bindings"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nl"&gt;"rustfmt"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"prepare:format"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="nl"&gt;"rust-clippy"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"check:lint"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="nl"&gt;"rust-wasm"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"build:run"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="nl"&gt;"rust-test"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"test:run"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="nl"&gt;"rust-coverage-report"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"test:report"&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Wiring the same order by hand would have meant adding 86 &lt;a href="https://nx.dev/reference/project-configuration#dependson" rel="noopener noreferrer"&gt;&lt;code&gt;dependsOn&lt;/code&gt;&lt;/a&gt; entries, spread over all 25 existing targets, plus dependency lists for the five new ones. &lt;a href="https://jacobley.github.io/leyman/packages/nx-lifecycle/" rel="noopener noreferrer"&gt;nx-lifecycle&lt;/a&gt; generated all of it for me.&lt;/p&gt;

&lt;p&gt;Nx thrives on micro-packages (efficient caching/testing) but that means all the boilerplate for every package gets multiplied every time you need to tweak task dependencies. I wanted to give teams a way to get packages up to speed, while only caring about the "important parts" (e.g. &lt;em&gt;how&lt;/em&gt; you test, not &lt;em&gt;when&lt;/em&gt; you test). Basically, I needed dependency injection for my task runners.&lt;/p&gt;

&lt;h2&gt;
  
  
  Interface and implementation
&lt;/h2&gt;

&lt;p&gt;In leyman, tests always run after the build, but "build" is different per project: &lt;code&gt;tsc&lt;/code&gt; for a TypeScript package, &lt;code&gt;rust-wasm&lt;/code&gt; for a crate compiled to WebAssembly, &lt;code&gt;vitepress-build&lt;/code&gt; for the docs site, and nothing at all for a Go module. Nx's &lt;code&gt;dependsOn&lt;/code&gt; only takes concrete target names, so every target that waits on the build has to name &lt;code&gt;tsc&lt;/code&gt;, &lt;code&gt;rust-wasm&lt;/code&gt;, and so on itself.&lt;/p&gt;

&lt;p&gt;nx-lifecycle splits that into two parts, the way dependency injection does. Stages and their hooks are the interface: the intended order, with no tool named. These are leyman's:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;"stages"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nl"&gt;"install"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;"dependsOn"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"^build"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="nl"&gt;"prepare"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;"hooks"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"generate"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"format"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nl"&gt;"dependsOn"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"install"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="nl"&gt;"check"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;"hooks"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"lint"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nl"&gt;"dependsOn"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"^build"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"prepare"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"build"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="nl"&gt;"build"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;"hooks"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"run"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"post"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"sync"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nl"&gt;"dependsOn"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"^build"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"prepare"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="nl"&gt;"test"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;"hooks"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"compile"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"run"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"report"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nl"&gt;"dependsOn"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"build"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="nl"&gt;"verify"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;"dependsOn"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"check"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"test"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Bindings are the implementations: each tool is bound to one hook, once. Each stage becomes a chain of no-op targets (&lt;code&gt;build:_ → build:run → build:post → build:sync → build&lt;/code&gt;), a bound target depends on the hook before its own, and the hook depends on every target bound to it. All the &lt;code&gt;dependsOn&lt;/code&gt; get generated from those two maps.&lt;/p&gt;

&lt;h2&gt;
  
  
  Counting the hand-written version
&lt;/h2&gt;

&lt;p&gt;To compare, I needed a version of leyman without nx-lifecycle. Leyman configures its targets in &lt;code&gt;nx.json&lt;/code&gt;'s &lt;a href="https://nx.dev/reference/nx-json#target-defaults" rel="noopener noreferrer"&gt;&lt;code&gt;targetDefaults&lt;/code&gt;&lt;/a&gt;, one entry per target shared by every project, so the hand-written version is one &lt;code&gt;dependsOn&lt;/code&gt; per target there.&lt;/p&gt;

&lt;p&gt;The count assumes a hand-written entry lists every target it waits for, not only the one just before it. Chaining through the step in between only works in projects that have it, because Nx &lt;a href="https://github.com/nrwl/nx/blob/0239b3ee05b9051a7558c5a444a14b2d448f8d4d/packages/nx/src/tasks-runner/create-task-graph.ts#L243" rel="noopener noreferrer"&gt;skips a same-project dependency the project doesn't declare&lt;/a&gt;, along with everything that dependency would have waited on. If &lt;code&gt;mocha-unit-test&lt;/code&gt; depended on &lt;code&gt;populate-files&lt;/code&gt; alone, then in the 49 projects that run &lt;code&gt;tsc&lt;/code&gt; without &lt;code&gt;populate-files&lt;/code&gt;, nothing would order mocha after &lt;code&gt;tsc&lt;/code&gt;. (On leyman's &lt;code&gt;main&lt;/code&gt; as of November 14, 55 of 86 projects declare &lt;code&gt;tsc&lt;/code&gt;, and 7 declare &lt;code&gt;populate-files&lt;/code&gt;, 6 of them alongside &lt;code&gt;tsc&lt;/code&gt;.)&lt;/p&gt;

&lt;p&gt;So each entry comes down to two rules. A new target &lt;code&gt;t&lt;/code&gt; bound to stage S must be added to an existing target's entry:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;as &lt;code&gt;t&lt;/code&gt;, if the existing target is in a later hook of S, or in a stage that runs after S in the same project;&lt;/li&gt;
&lt;li&gt;as &lt;code&gt;^t&lt;/code&gt;, if its stage, or a stage that one runs after, has a &lt;code&gt;^&lt;/code&gt; dependency on S or on a stage that runs after S. These are the dependent projects.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This script applies those two rules to the bindings that already existed:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Which bound targets must wait for the given ones, in their own project or a dependent one.&lt;/span&gt;
&lt;span class="c1"&gt;// git show &amp;lt;commit&amp;gt;:leyman/main/lifecycle.json | node waiters.mjs &amp;lt;target&amp;gt;...&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;readFileSync&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s1"&gt;'node:fs'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;stages&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;bindings&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;JSON&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;parse&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;readFileSync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'utf8'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;deps&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;stage&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;stages&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;stage&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;dependsOn&lt;/span&gt; &lt;span class="o"&gt;??&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="c1"&gt;// The stages a stage runs after in the same project, transitively, and the stage itself.&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;upTo&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;stage&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;seen&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nb"&gt;Set&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;stage&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;dep&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt; &lt;span class="nf"&gt;deps&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;stage&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="n"&gt;dep&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;startsWith&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'^'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="n"&gt;seen&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;has&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;dep&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="n"&gt;seen&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;dep&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
            &lt;span class="nf"&gt;upTo&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;dep&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;seen&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;seen&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;at&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;target&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;stage&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;hook&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;bindings&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;target&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;split&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;':'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;stage&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;hook&lt;/span&gt; &lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="n"&gt;stages&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;stage&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;hooks&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;indexOf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;hook&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;added&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;argv&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;slice&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="n"&gt;targets&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="n"&gt;entries&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;target&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt; &lt;span class="nb"&gt;Object&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;keys&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;bindings&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;filter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="n"&gt;added&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;includes&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;stage&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;hook&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;at&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;target&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;needs&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;added&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;flatMap&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;newTarget&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;newStage&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;newHook&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;at&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;newTarget&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;sameProject&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;stage&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="n"&gt;newStage&lt;/span&gt; &lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="n"&gt;hook&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;newHook&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;upTo&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;stage&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;has&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;newStage&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;dependent&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;upTo&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;stage&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;some&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;
            &lt;span class="nf"&gt;deps&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;some&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;dep&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;dep&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;startsWith&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'^'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nf"&gt;upTo&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;dep&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;slice&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;has&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;newStage&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;sameProject&lt;/span&gt; &lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;newTarget&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;dependent&lt;/span&gt; &lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sb"&gt;`^${newTarget}`&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;needs&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;length&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;targets&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="n"&gt;entries&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="n"&gt;needs&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;length&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="nb"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sb"&gt;`${target}: ${needs.join(', ')}`&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nb"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sb"&gt;`${targets} targets, ${entries} dependsOn entries`&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Run it from a leyman checkout against the Rust commit:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git show 97a41c04:leyman/main/lifecycle.json \
  &lt;span class="o"&gt;|&lt;/span&gt; node waiters.mjs rustfmt rust-clippy rust-wasm rust-test rust-coverage-report

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It lists 25 targets, which is every binding in the parent commit, and 86 entries. Two of the five tools are almost all of it:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;rustfmt&lt;/code&gt; and &lt;code&gt;rust-wasm&lt;/code&gt; account for almost all of it. Formatting and the build run early, and since &lt;code&gt;install&lt;/code&gt; waits on &lt;code&gt;^build&lt;/code&gt;, every stage of a dependent project waits on them. Most targets need both &lt;code&gt;rustfmt&lt;/code&gt; and &lt;code&gt;^rustfmt&lt;/code&gt;, and the same for &lt;code&gt;rust-wasm&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;rust-test&lt;/code&gt; adds 2 entries, to &lt;code&gt;coverage-report&lt;/code&gt; and &lt;code&gt;go-coverage-report&lt;/code&gt;, the only targets that run after &lt;code&gt;test:run&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;rust-clippy&lt;/code&gt; and &lt;code&gt;rust-coverage-report&lt;/code&gt; add none. Nothing waits on lint or on coverage.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  What was generated instead
&lt;/h2&gt;

&lt;p&gt;Leyman runs nx-lifecycle's executor, so the generated &lt;code&gt;dependsOn&lt;/code&gt; are committed and the commit shows them. In &lt;code&gt;nx.json&lt;/code&gt;, each new target depends on the one hook before its own (&lt;code&gt;rust-wasm&lt;/code&gt; on &lt;code&gt;build:_&lt;/code&gt;, &lt;code&gt;rust-test&lt;/code&gt; on &lt;code&gt;test:compile&lt;/code&gt;), and each of the five hook targets gained one name: &lt;code&gt;build:run&lt;/code&gt; now waits on &lt;code&gt;rust-wasm&lt;/code&gt; beside &lt;code&gt;tsc&lt;/code&gt; and &lt;code&gt;vitepress-build&lt;/code&gt;. No existing target's entry changed. One existing project, constant-consistent-hash's test vectors, opted into &lt;code&gt;rustfmt&lt;/code&gt; with a one-line &lt;code&gt;"rustfmt": {}&lt;/code&gt; in its &lt;code&gt;project.json&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The Rust targets themselves come from a &lt;a href="https://github.com/JacobLey/leyman/blob/main/leyman/main/scripts/nx-rust-plugin.mjs" rel="noopener noreferrer"&gt;small Nx plugin in the repo&lt;/a&gt; that reads each crate's &lt;code&gt;Cargo.toml&lt;/code&gt;. It only defines the commands. The &lt;code&gt;dependsOn&lt;/code&gt; all come from nx-lifecycle.&lt;/p&gt;

&lt;h2&gt;
  
  
  Plugin or executor
&lt;/h2&gt;

&lt;p&gt;You can run nx-lifecycle as a plugin or as an executor.&lt;/p&gt;

&lt;p&gt;The plugin infers every lifecycle target when Nx builds the project graph. It doesn't write anything to your files, so there's no generated config to drift. If a project's own &lt;code&gt;dependsOn&lt;/code&gt; replaces an inferred one and drops its lifecycle dependency, the plugin fails and names the entry to add.&lt;/p&gt;

&lt;p&gt;The executor writes the targets into &lt;code&gt;nx.json&lt;/code&gt; and each &lt;code&gt;project.json&lt;/code&gt;, to be committed. In CI it only checks that the files match what it would write, and fails if they don't. Leyman uses it because Nx loads plugins before building anything, so a workspace can't run the plugin from its own unbuilt source. Anywhere else, use the plugin.&lt;/p&gt;

&lt;h2&gt;
  
  
  Mixed toolchains, partial projects
&lt;/h2&gt;

&lt;p&gt;Several tools can bind to one hook. In leyman, &lt;code&gt;test:run&lt;/code&gt; alone has two mocha suites, vitest, &lt;code&gt;go-test&lt;/code&gt; and &lt;code&gt;rust-test&lt;/code&gt;. Targets bound to the same hook run in parallel.&lt;/p&gt;

&lt;p&gt;A project only gets the bound targets it declares, so not every project implements every hook. A Go module has nothing in &lt;code&gt;build:run&lt;/code&gt;, and its tests still wait on its &lt;code&gt;prepare&lt;/code&gt; stage and on its dependencies' builds, since that's set on the stage, not the tool. &lt;code&gt;nx run &amp;lt;project&amp;gt;:build&lt;/code&gt; runs &lt;code&gt;tsc&lt;/code&gt; in a TypeScript package and nothing in a Go module.&lt;/p&gt;

&lt;p&gt;The stage at the end is &lt;code&gt;verify&lt;/code&gt;, which is &lt;code&gt;check&lt;/code&gt; and &lt;code&gt;test&lt;/code&gt;. &lt;code&gt;nx run-many -t verify&lt;/code&gt; lints, builds and tests everything. How long it takes is a whole other post (the next one).&lt;/p&gt;

&lt;h2&gt;
  
  
  Testing the planner
&lt;/h2&gt;

&lt;p&gt;nx-lifecycle validates its options with a JSON Schema built in &lt;a href="https://jacobley.github.io/leyman/packages/juniper/" rel="noopener noreferrer"&gt;Juniper&lt;/a&gt;. One unit test feeds the planner stage configurations generated from that same schema by &lt;a href="https://jacobley.github.io/leyman/packages/juniper-arbitrary/" rel="noopener noreferrer"&gt;juniper-arbitrary&lt;/a&gt; and &lt;a href="https://www.npmjs.com/package/fast-check" rel="noopener noreferrer"&gt;fast-check&lt;/a&gt;, with a fixed seed, and fails if planning throws on any of them (&lt;a href="https://github.com/JacobLey/leyman/blob/main/apps/nx-lifecycle/test/unit/lifecycle/generated-stages.spec.ts" rel="noopener noreferrer"&gt;test&lt;/a&gt;):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="n"&gt;fc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;assert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;fc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;property&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;makeArbitrary&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;stagesSchema&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;stages&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nf"&gt;planLifecycle&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;stages&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;bindings&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;seed&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;42&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So whenever I make the planner reject something new, I have to make the schema reject it too, or the test will generate one and fail. The schema now requires hook names to be non-empty, unique, and not &lt;code&gt;_&lt;/code&gt; (the name of a stage's anchor target), matching what the planner rejects as of nx-lifecycle 1.4.2 (&lt;a href="https://github.com/JacobLey/leyman/commit/d3be6ecf" rel="noopener noreferrer"&gt;commit&lt;/a&gt;).&lt;/p&gt;

&lt;h2&gt;
  
  
  Try it
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;pnpm add -D nx-lifecycle

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Install it in the workspace root, where Nx resolves plugins, and add the plugin to &lt;code&gt;nx.json&lt;/code&gt; with your stages and bindings:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;"plugins"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="nl"&gt;"plugin"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"nx-lifecycle/plugin"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="nl"&gt;"options"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="nl"&gt;"stages"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                    &lt;span class="nl"&gt;"build"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;"hooks"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"pre"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"run"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"post"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nl"&gt;"dependsOn"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"^build"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                    &lt;span class="nl"&gt;"test"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;"hooks"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"run"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"report"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nl"&gt;"dependsOn"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"build"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
                &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                &lt;span class="nl"&gt;"bindings"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                    &lt;span class="nl"&gt;"tsc"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"build:run"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                    &lt;span class="nl"&gt;"mocha"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"test:run"&lt;/span&gt;
                &lt;span class="p"&gt;}&lt;/span&gt;
            &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Each project opts into a binding by declaring the target (&lt;code&gt;"tsc": {}&lt;/code&gt;) in its &lt;code&gt;project.json&lt;/code&gt;. &lt;code&gt;nx show project &amp;lt;name&amp;gt;&lt;/code&gt; lists the inferred targets, and &lt;code&gt;pnpx nx-lifecycle explain &amp;lt;name&amp;gt;&lt;/code&gt; prints what runs in which order. nx-lifecycle 1.5.0 needs Node.js 24 and Nx 24; for Nx 23, use 1.4.2.&lt;/p&gt;

&lt;p&gt;Setup is in the &lt;a href="https://jacobley.github.io/leyman/packages/nx-lifecycle/getting-started" rel="noopener noreferrer"&gt;getting started guide&lt;/a&gt;. &lt;a href="https://jacobley.github.io/leyman/packages/nx-lifecycle/guides/stages-and-hooks" rel="noopener noreferrer"&gt;Stages and hooks&lt;/a&gt; explains the generated targets. The &lt;a href="https://jacobley.github.io/leyman/packages/nx-lifecycle/why" rel="noopener noreferrer"&gt;why&lt;/a&gt; page does the hand-written version of a smaller example. Leyman's own &lt;a href="https://github.com/JacobLey/leyman/blob/main/leyman/main/lifecycle.json" rel="noopener noreferrer"&gt;&lt;code&gt;lifecycle.json&lt;/code&gt;&lt;/a&gt; is a full real config.&lt;/p&gt;

</description>
      <category>architecture</category>
      <category>automation</category>
      <category>rust</category>
      <category>tooling</category>
    </item>
    <item>
      <title>One library, several languages, held to one set of test vectors</title>
      <dc:creator>Jacob Ley</dc:creator>
      <pubDate>Thu, 12 Nov 2026 21:48:00 +0000</pubDate>
      <link>https://dev.to/jacobley/one-library-several-languages-held-to-one-set-of-test-vectors-ba7</link>
      <guid>https://dev.to/jacobley/one-library-several-languages-held-to-one-set-of-test-vectors-ba7</guid>
      <description>&lt;p&gt;&lt;a href="https://jacobley.github.io/leyman/packages/genever/" rel="noopener noreferrer"&gt;genever&lt;/a&gt; generates TypeScript types from JSON Schema and OpenAPI documents. Since November 8 it also has a Go version, released as v0.1.0:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;go get -tool github.com/JacobLey/leyman/apps/genever/go/cmd/genever@v0.1.0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It reads the same schemas, has the same strict mode, and rejects the same bad schemas with the same kind of error at the same JSON Pointer. It writes Go structs instead of TypeScript types. Two of genever's dependencies came along, because the Go command has to sign its output and keep a manifest the way the TypeScript one does: &lt;a href="https://jacobley.github.io/leyman/packages/populate-files/" rel="noopener noreferrer"&gt;populate-files&lt;/a&gt; and &lt;a href="https://jacobley.github.io/leyman/packages/generated-signature/" rel="noopener noreferrer"&gt;generated-signature&lt;/a&gt; are Go modules now too, released at the same version.&lt;/p&gt;

&lt;p&gt;This continues a pattern in my adoption of Go, which forces language-agnostic support for common functionality (in this case, type-ifying JSON Schema + OpenAPI).&lt;/p&gt;

&lt;p&gt;None of the Go code is tested against the TypeScript code. Both are tested against a set of test vectors: inputs and expected outputs, as JSON, that the TypeScript implementation computed once and that are committed to the repository.&lt;/p&gt;

&lt;h2&gt;
  
  
  One directory per package, one per language
&lt;/h2&gt;

&lt;p&gt;Each of these packages is a directory named after the package, with one project per language beside the vectors they share:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;apps/genever/
├── README.md        what every implementation promises
├── ts/              published to npm as genever
├── go/              the Go module github.com/JacobLey/leyman/apps/genever/go
└── test-vectors/    schemas, sample values and error cases, as JSON
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://github.com/JacobLey/leyman/tree/main/apps/populate-files" rel="noopener noreferrer"&gt;populate-files&lt;/a&gt; and &lt;a href="https://github.com/JacobLey/leyman/tree/main/tools/generated-signature" rel="noopener noreferrer"&gt;generated-signature&lt;/a&gt; have the same shape. &lt;a href="https://github.com/JacobLey/leyman/tree/main/tools/constant-consistent-hash" rel="noopener noreferrer"&gt;constant-consistent-hash&lt;/a&gt;, the oldest of the four, has &lt;code&gt;ts/&lt;/code&gt;, &lt;code&gt;go/&lt;/code&gt;, &lt;code&gt;rust/&lt;/code&gt;, and a &lt;code&gt;wasm/&lt;/code&gt; package that calls the Rust implementation from TypeScript.&lt;/p&gt;

&lt;p&gt;Until the release, the TypeScript package was the root and the Go code lived in a &lt;code&gt;go-impl/&lt;/code&gt; folder next to it. Moving each language into its own directory means neither is the package. The group README describes what holds in every language (the format a file is signed in, which schemas are rejected and where), and a third language has an obvious place to go.&lt;/p&gt;

&lt;h2&gt;
  
  
  Where the expected values come from
&lt;/h2&gt;

&lt;p&gt;genever's vectors are a &lt;a href="https://github.com/JacobLey/leyman/tree/main/apps/genever/test-vectors" rel="noopener noreferrer"&gt;TypeScript package&lt;/a&gt; that writes JSON files under &lt;code&gt;out/&lt;/code&gt; on every build:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;45 schema fixtures, each with sample values it accepts. The schemas are &lt;a href="https://jacobley.github.io/leyman/packages/juniper/" rel="noopener noreferrer"&gt;Juniper&lt;/a&gt; definitions and the samples come from juniper-arbitrary with a fixed seed, so a file only changes when a fixture does.&lt;/li&gt;
&lt;li&gt;Two OpenAPI documents, 3.0.3 and 3.1.0, with samples of each component.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;errors.json&lt;/code&gt;: 74 schemas genever rejects, each with the kind of error and the JSON Pointer it must name.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The files are committed, and CI fails if one is stale. The TypeScript genever runs the vectors from the package; the Go one reads the JSON by relative path:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="nf"&gt;testVectors&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;fs&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;FS&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;DirFS&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;filepath&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Join&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;".."&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"test-vectors"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Reading by path was a late change. The vectors started as a Go module that embedded the JSON, which works until you release: a published Go module can't require one that isn't published, and the vectors are only for tests. So the Go tests read the working copy, and the Go project lists the vectors in its Nx &lt;code&gt;implicitDependencies&lt;/code&gt; so its tests rerun when they change (&lt;a href="https://github.com/JacobLey/leyman/commit/6a6fe44e" rel="noopener noreferrer"&gt;commit&lt;/a&gt;).&lt;/p&gt;

&lt;p&gt;generated-signature has 187 cases in &lt;a href="https://github.com/JacobLey/leyman/blob/main/tools/generated-signature/test-vectors/data/test-vectors.json" rel="noopener noreferrer"&gt;one file&lt;/a&gt; (signing, verifying, manual sections, manifests), and populate-files has 71 scenarios: files written, hand edits made, then one call with the results, error and files it must leave behind.&lt;/p&gt;

&lt;p&gt;No implementation regenerates the values it is tested against: if the Go port could rewrite them, a change in Go would update the vectors and pass.&lt;/p&gt;

&lt;h2&gt;
  
  
  The same error, at the same pointer
&lt;/h2&gt;

&lt;p&gt;genever's error cases are vectors too. One per kind, from &lt;a href="https://github.com/JacobLey/leyman/blob/main/apps/genever/test-vectors/out/errors.json" rel="noopener noreferrer"&gt;&lt;code&gt;errors.json&lt;/code&gt;&lt;/a&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;"invalid"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nl"&gt;"type is unknown"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;"schema"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;"type"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"date"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nl"&gt;"pointer"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"#/type"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nl"&gt;"strict"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nl"&gt;"unknown keyword"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;"schema"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;"type"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"string"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nl"&gt;"foo"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nl"&gt;"pointer"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"#/foo"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nl"&gt;"unsupported"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nl"&gt;"$dynamicRef"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;"options"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;"strict"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nl"&gt;"schema"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;"$dynamicRef"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"#node"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nl"&gt;"pointer"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"#/$dynamicRef"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;a href="https://github.com/JacobLey/leyman/blob/main/apps/genever/go/errors_test.go" rel="noopener noreferrer"&gt;Go test&lt;/a&gt; checks the error's kind with &lt;code&gt;errors.Is&lt;/code&gt; and its pointer, and that each strict mode case is accepted once strict mode is off:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;geneverErr&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;genever&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Error&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="n"&gt;errors&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Is&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;err&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;kind&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="n"&gt;errors&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;As&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;err&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;geneverErr&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="n"&gt;geneverErr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Pointer&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="n"&gt;item&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Pointer&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Fatalf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"got %v, expected %s at %s"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;kind&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;item&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Pointer&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Moving the cases out of the TypeScript tests made those tests stricter too. They had checked the error's class but not the pointer. And the whole suite had run as OpenAPI 3.0, which hid that one check (&lt;code&gt;exclusiveMaximum&lt;/code&gt;) behaved differently outside it; now only the two cases that need OpenAPI 3.0 run as it (&lt;a href="https://github.com/JacobLey/leyman/commit/b6fd7cf3" rel="noopener noreferrer"&gt;commit&lt;/a&gt;).&lt;/p&gt;

&lt;h2&gt;
  
  
  What the vectors caught
&lt;/h2&gt;

&lt;p&gt;generated-signature's vectors cover the places where Go and JavaScript disagree by default: what JavaScript's &lt;code&gt;\s&lt;/code&gt; and &lt;code&gt;trim()&lt;/code&gt; count as whitespace, Node.js's &lt;code&gt;extname&lt;/code&gt;, lowercase &lt;code&gt;İ&lt;/code&gt;, the byte order mark &lt;code&gt;TextDecoder&lt;/code&gt; drops, and &lt;code&gt;JSON.stringify&lt;/code&gt;'s escaping. One case lists five manifest keys, &lt;code&gt;Z&lt;/code&gt;, &lt;code&gt;a&lt;/code&gt;, &lt;code&gt;é&lt;/code&gt;, &lt;code&gt;😀&lt;/code&gt; and &lt;code&gt;&lt;/code&gt;, in that order. JavaScript compares strings by UTF-16 code unit, so the emoji (a surrogate pair starting at &lt;code&gt;0xD83D&lt;/code&gt;) sorts before &lt;code&gt;&lt;/code&gt;. Go compares UTF-8 bytes, where &lt;code&gt;&lt;/code&gt; comes first. A manifest written by one would look edited to the other, so the Go code sorts by &lt;code&gt;utf16.Encode&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;In populate-files, the TypeScript package was the one that changed. The Go port decided every file before writing any, so a refused write left everything as it was. The TypeScript package wrote files in parallel as it decided them, so a refusal could come after other files were written. The scenarios couldn't pin the files a failed call leaves while the two disagreed, so the TypeScript package changed to match the port in populate-files 1.2.3 (&lt;a href="https://github.com/JacobLey/leyman/commit/fe4dff12" rel="noopener noreferrer"&gt;commit&lt;/a&gt;), and the scenarios now pin those files.&lt;/p&gt;

&lt;p&gt;A third turned up the day before release. The released modules declare &lt;code&gt;go 1.24&lt;/code&gt;, the oldest Go they support, and CI now runs each released module's tests on Go 1.24 as well as the current Go. That run failed: Go 1.24's JSON decoder reports an unclosed &lt;code&gt;{&lt;/code&gt; or &lt;code&gt;[&lt;/code&gt; only when asked for the closing delimiter, which genever-go's order-keeping JSON parser had been discarding, so truncated JSON was accepted. It now fails with &lt;code&gt;ErrSyntax&lt;/code&gt; (&lt;a href="https://github.com/JacobLey/leyman/commit/2783a6b7" rel="noopener noreferrer"&gt;commit&lt;/a&gt;).&lt;/p&gt;

&lt;h2&gt;
  
  
  Where vectors stop
&lt;/h2&gt;

&lt;p&gt;The vectors say which schemas are accepted and which values every generated type must hold. They can't say how narrow a Go type is, since Go has no union or literal types and a &lt;code&gt;json.RawMessage&lt;/code&gt; field would hold every sample. So the Go tests also read each fixture's generated declarations back with &lt;code&gt;go/types&lt;/code&gt; and compare them with what's expected: struct fields and their types, union variants, enum constants. A fixture without expectations fails, so a new one can't go unchecked. Neither implementation's tests compare generated text, so formatting can change freely.&lt;/p&gt;

&lt;p&gt;For how genever-go compares with other Go generators, the &lt;a href="https://jacobley.github.io/leyman/packages/genever/go-comparison" rel="noopener noreferrer"&gt;Go comparison&lt;/a&gt; runs it, &lt;a href="https://pkg.go.dev/github.com/atombender/go-jsonschema" rel="noopener noreferrer"&gt;go-jsonschema&lt;/a&gt; and &lt;a href="https://pkg.go.dev/github.com/oapi-codegen/oapi-codegen/v2" rel="noopener noreferrer"&gt;oapi-codegen&lt;/a&gt; through the same probes every night: 18 values decoded into the type generated from a JSON Schema, and 7 into the type for an OpenAPI request body. I wrote genever-go, and only its results are tested.&lt;/p&gt;

&lt;p&gt;In the run of November 11, 2026:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Tool&lt;/th&gt;
&lt;th&gt;Version&lt;/th&gt;
&lt;th&gt;JSON Schema probes&lt;/th&gt;
&lt;th&gt;OpenAPI probes&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;genever-go&lt;/td&gt;
&lt;td&gt;0.1.0&lt;/td&gt;
&lt;td&gt;18 / 18&lt;/td&gt;
&lt;td&gt;7 / 7&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;go-jsonschema&lt;/td&gt;
&lt;td&gt;0.24.1&lt;/td&gt;
&lt;td&gt;13 / 18&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;oapi-codegen&lt;/td&gt;
&lt;td&gt;2.8.2 (kin-openapi 0.152.0)&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;5 / 7&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;go-jsonschema's type doesn't keep &lt;code&gt;null&lt;/code&gt; apart from an absent property, can't hold &lt;code&gt;null&lt;/code&gt; as a member of a mixed enum, and decodes three values it should reject: a tuple with a string member, a &lt;code&gt;oneOf&lt;/code&gt; branch with a property of the wrong type, and a &lt;code&gt;patternProperties&lt;/code&gt; value of the wrong type. oapi-codegen's type decodes the tuple with a string member and doesn't keep &lt;code&gt;null&lt;/code&gt; apart from absent in a mixed enum. Before kin-openapi 0.152.0, oapi-codegen's loader rejected the 3.1 document, so it scored 0 / 7.&lt;/p&gt;

&lt;h2&gt;
  
  
  Try it
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;go get -tool github.com/JacobLey/leyman/apps/genever/go/cmd/genever@v0.1.0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="c1"&gt;//go:generate go tool genever openapi.yaml --package api --signed&lt;/span&gt;
&lt;span class="k"&gt;package&lt;/span&gt; &lt;span class="n"&gt;api&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It needs Go 1.24 or later, as does the code it writes. The released modules keep &lt;code&gt;replace&lt;/code&gt; directives pointing at each other's workspace copies, so a change to populate-files is tested against genever before either is tagged. &lt;code&gt;go install&lt;/code&gt; refuses a module with &lt;code&gt;replace&lt;/code&gt; directives, which is why the install line uses &lt;code&gt;go get -tool&lt;/code&gt;: it ignores a dependency's replaces and pins the version in your &lt;code&gt;go.mod&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The &lt;a href="https://jacobley.github.io/leyman/packages/genever/guides/go" rel="noopener noreferrer"&gt;Go guide&lt;/a&gt; covers the options and how Go types differ from the TypeScript ones. If a schema is accepted by one implementation and rejected by the other, that's a bug in one of them, and the &lt;a href="https://github.com/JacobLey/leyman/tree/main/apps/genever/test-vectors" rel="noopener noreferrer"&gt;test vectors&lt;/a&gt; are where the fix starts.&lt;/p&gt;

</description>
      <category>go</category>
      <category>softwaredevelopment</category>
      <category>testing</category>
      <category>typescript</category>
    </item>
    <item>
      <title>How narrow are generated TypeScript types? Six JSON Schema generators compared</title>
      <dc:creator>Jacob Ley</dc:creator>
      <pubDate>Sat, 07 Nov 2026 00:00:00 +0000</pubDate>
      <link>https://dev.to/jacobley/how-narrow-are-generated-typescript-types-six-json-schema-generators-compared-4m45</link>
      <guid>https://dev.to/jacobley/how-narrow-are-generated-typescript-types-six-json-schema-generators-compared-4m45</guid>
      <description>&lt;p&gt;A JSON Schema can say more than most generated TypeScript types do. A tuple of two numbers becomes &lt;code&gt;number[]&lt;/code&gt;, an ID that must start with &lt;code&gt;ord_&lt;/code&gt; becomes &lt;code&gt;string&lt;/code&gt;, and an object that only allows &lt;code&gt;x-&lt;/code&gt; headers takes any key. The type compiles, and bad data goes straight through it.&lt;/p&gt;

&lt;p&gt;My existing package, &lt;a href="https://jacobley.github.io/leyman/packages/juniper/" rel="noopener noreferrer"&gt;Juniper&lt;/a&gt;, avoids this by building the schema in TypeScript at runtime, so its types come straight from the code. That leaves a gap: a schema from somewhere else, like another service's OpenAPI spec or a shared JSON file, can't be &lt;em&gt;safely&lt;/em&gt; pulled into TypeScript that way.&lt;/p&gt;

&lt;p&gt;I wrote &lt;a href="https://jacobley.github.io/leyman/packages/genever/" rel="noopener noreferrer"&gt;genever&lt;/a&gt; for those schemas. It reads the file and writes types narrow enough that the bad data above is a compile error. To check that it really is narrower than the alternatives, and stays that way, a nightly job gives it and five other generators the same schema and type-checks what each one produces.&lt;/p&gt;

&lt;h2&gt;
  
  
  The same schema, two outputs
&lt;/h2&gt;

&lt;p&gt;A schema for an order, with one property per feature that TypeScript can express but most generators don't:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;"$schema"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"https://json-schema.org/draft/2020-12/schema"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"type"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"object"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"properties"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;"id"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;"type"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"string"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nl"&gt;"pattern"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"^ord_"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nl"&gt;"location"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nl"&gt;"type"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"array"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="nl"&gt;"prefixItems"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;"type"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"number"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;"type"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"number"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="nl"&gt;"items"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="nl"&gt;"minItems"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nl"&gt;"shipping"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nl"&gt;"oneOf"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt;
          &lt;span class="nl"&gt;"type"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"object"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
          &lt;span class="nl"&gt;"properties"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;"kind"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;"const"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"pickup"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nl"&gt;"store"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;"type"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"string"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
          &lt;span class="nl"&gt;"required"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"kind"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"store"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
          &lt;span class="nl"&gt;"additionalProperties"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt;
          &lt;span class="nl"&gt;"type"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"object"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
          &lt;span class="nl"&gt;"properties"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;"kind"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;"const"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"delivery"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nl"&gt;"address"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;"type"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"string"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
          &lt;span class="nl"&gt;"required"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"kind"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"address"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
          &lt;span class="nl"&gt;"additionalProperties"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
      &lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nl"&gt;"headers"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nl"&gt;"type"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"object"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="nl"&gt;"patternProperties"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;"^x-"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;"type"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"string"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="nl"&gt;"additionalProperties"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nl"&gt;"payment"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nl"&gt;"type"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"object"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="nl"&gt;"properties"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;"card"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;"type"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"string"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nl"&gt;"billingAddress"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;"type"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"string"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="nl"&gt;"dependentRequired"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;"card"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"billingAddress"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="nl"&gt;"additionalProperties"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"required"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"id"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"additionalProperties"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://www.npmjs.com/package/json-schema-to-typescript" rel="noopener noreferrer"&gt;json-schema-to-typescript&lt;/a&gt; 16.0.0, the most-downloaded tool that writes a &lt;code&gt;.ts&lt;/code&gt; file from JSON Schema, generates this (banner comment removed):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;interface&lt;/span&gt; &lt;span class="nc"&gt;Order&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="cm"&gt;/**
   * @minItems 2
   */&lt;/span&gt;
  &lt;span class="n"&gt;location&lt;/span&gt;&lt;span class="o"&gt;?:&lt;/span&gt; &lt;span class="kt"&gt;never&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;shipping&lt;/span&gt;&lt;span class="o"&gt;?:&lt;/span&gt;
    &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;kind&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"pickup"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="n"&gt;store&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;kind&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"delivery"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="n"&gt;address&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;headers&lt;/span&gt;&lt;span class="o"&gt;?:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="cm"&gt;/**
     * This interface was referenced by `undefined`'s JSON-Schema definition
     * via the `patternProperty` "^x-".
     */&lt;/span&gt;
    &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;k&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;payment&lt;/span&gt;&lt;span class="o"&gt;?:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;card&lt;/span&gt;&lt;span class="o"&gt;?:&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;billingAddress&lt;/span&gt;&lt;span class="o"&gt;?:&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;oneOf&lt;/code&gt; union is right. &lt;code&gt;location&lt;/code&gt; is &lt;code&gt;never[]&lt;/code&gt;, so even a valid &lt;code&gt;[1, 2]&lt;/code&gt; fails to compile (2020-12's &lt;code&gt;prefixItems&lt;/code&gt; isn't read). &lt;code&gt;id&lt;/code&gt; and &lt;code&gt;headers&lt;/code&gt; take any string, and &lt;code&gt;payment&lt;/code&gt; allows a card without a billing address.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;npx genever order.json --name Order&lt;/code&gt; writes:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;type&lt;/span&gt; &lt;span class="nc"&gt;Order&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="cm"&gt;/**
     * @pattern "^ord_"
     */&lt;/span&gt;
    &lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sb"&gt;`ord_${string}`&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="cm"&gt;/**
     * @minItems 2
     */&lt;/span&gt;
    &lt;span class="n"&gt;location&lt;/span&gt;&lt;span class="o"&gt;?:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="kt"&gt;number&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;number&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;shipping&lt;/span&gt;&lt;span class="o"&gt;?:&lt;/span&gt;
        &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
              &lt;span class="n"&gt;kind&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'pickup'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
              &lt;span class="n"&gt;store&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
          &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
              &lt;span class="n"&gt;kind&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'delivery'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
              &lt;span class="n"&gt;address&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
          &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;headers&lt;/span&gt;&lt;span class="o"&gt;?:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sb"&gt;`x-${string}`&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;payment&lt;/span&gt;&lt;span class="o"&gt;?:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;card&lt;/span&gt;&lt;span class="o"&gt;?:&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="n"&gt;billingAddress&lt;/span&gt;&lt;span class="o"&gt;?:&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
              &lt;span class="n"&gt;card&lt;/span&gt;&lt;span class="o"&gt;?:&lt;/span&gt; &lt;span class="kt"&gt;never&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
          &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
              &lt;span class="n"&gt;billingAddress&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
          &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Each of those mistakes is now a compile error:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;type&lt;/span&gt; &lt;span class="nc"&gt;Order&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sb"&gt;`ord_${string}`&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;location&lt;/span&gt;&lt;span class="o"&gt;?:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="kt"&gt;number&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;number&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;headers&lt;/span&gt;&lt;span class="o"&gt;?:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sb"&gt;`x-${string}`&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;payment&lt;/span&gt;&lt;span class="o"&gt;?:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;card&lt;/span&gt;&lt;span class="o"&gt;?:&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;billingAddress&lt;/span&gt;&lt;span class="o"&gt;?:&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;card&lt;/span&gt;&lt;span class="o"&gt;?:&lt;/span&gt; &lt;span class="kt"&gt;never&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;billingAddress&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="c1"&gt;// ---cut---&lt;/span&gt;
&lt;span class="c1"&gt;// @errors: 2322 2353&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;wrongId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Order&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'usr_1'&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;wrongLocation&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Order&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'ord_1'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;location&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;wrongHeader&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Order&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'ord_1'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;headers&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;accept&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'json'&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;noBillingAddress&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Order&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'ord_1'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;payment&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;card&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'4242'&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  How the comparison works
&lt;/h2&gt;

&lt;p&gt;One schema proves nothing, so the comparison runs every night in CI. Every tool gets &lt;a href="https://github.com/JacobLey/leyman/blob/main/e2e/genever-comparison/src/documents.ts" rel="noopener noreferrer"&gt;the same documents&lt;/a&gt;: one JSON Schema with a property per feature (nullable values, mixed enums, tuples, &lt;code&gt;oneOf&lt;/code&gt; objects, recursion, closed &lt;code&gt;patternProperties&lt;/code&gt;, literal patterns and &lt;code&gt;dependentRequired&lt;/code&gt;), and an OpenAPI 3.1 document for the tools that read OpenAPI.&lt;/p&gt;

&lt;p&gt;Each &lt;a href="https://github.com/JacobLey/leyman/blob/main/e2e/genever-comparison/src/probes.ts" rel="noopener noreferrer"&gt;probe&lt;/a&gt; is one line of TypeScript, compiled against the generated type:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;accepts&lt;/strong&gt;: a value the schema allows must type-check.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;rejects&lt;/strong&gt;: a value the schema forbids must not type-check.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;reads&lt;/strong&gt;: reading a value must give exactly the right type, compared with an identity check, so &lt;code&gt;any&lt;/code&gt; doesn't pass.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Most comparisons only check that valid values are accepted, which any wide enough type does; &lt;code&gt;any&lt;/code&gt; passes all of them. The rejecting probes are the ones that separate the tools.&lt;/p&gt;

&lt;p&gt;I wrote the probes too, so of course genever passes them. Each one follows what the spec says a validator must accept or reject, and the documents and probes are public; if one is unfair to a tool, or a feature is missing, &lt;a href="https://github.com/JacobLey/leyman/issues" rel="noopener noreferrer"&gt;open an issue&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.npmjs.com/package/json-schema-to-ts" rel="noopener noreferrer"&gt;json-schema-to-ts&lt;/a&gt; and &lt;a href="https://www.npmjs.com/package/typebox" rel="noopener noreferrer"&gt;TypeBox&lt;/a&gt; infer types inside TypeScript instead of writing a file, so they get the schema pasted in &lt;code&gt;as const&lt;/code&gt;. That is their best case. Import the same schema from a &lt;code&gt;.json&lt;/code&gt; file and TypeScript widens it; json-schema-to-ts then gives &lt;code&gt;unknown&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  What the latest run found
&lt;/h2&gt;

&lt;p&gt;Results from the 2026-11-06 run, 23 JSON Schema probes each:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Tool&lt;/th&gt;
&lt;th&gt;Version&lt;/th&gt;
&lt;th&gt;Passed&lt;/th&gt;
&lt;th&gt;Missed&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;genever&lt;/td&gt;
&lt;td&gt;0.10.1&lt;/td&gt;
&lt;td&gt;23&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;json-schema-to-typescript&lt;/td&gt;
&lt;td&gt;16.0.0&lt;/td&gt;
&lt;td&gt;18&lt;/td&gt;
&lt;td&gt;tuples, closed &lt;code&gt;patternProperties&lt;/code&gt;, literal patterns, &lt;code&gt;dependentRequired&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;quicktype&lt;/td&gt;
&lt;td&gt;26.0.0&lt;/td&gt;
&lt;td&gt;17&lt;/td&gt;
&lt;td&gt;tuple length, narrowing &lt;code&gt;oneOf&lt;/code&gt; objects, closed &lt;code&gt;patternProperties&lt;/code&gt;, literal patterns, &lt;code&gt;dependentRequired&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;json-schema-to-ts&lt;/td&gt;
&lt;td&gt;3.1.1&lt;/td&gt;
&lt;td&gt;17&lt;/td&gt;
&lt;td&gt;tuples, recursion (a type error), closed &lt;code&gt;patternProperties&lt;/code&gt;, literal patterns, &lt;code&gt;dependentRequired&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;TypeBox&lt;/td&gt;
&lt;td&gt;1.4.3&lt;/td&gt;
&lt;td&gt;17&lt;/td&gt;
&lt;td&gt;tuples, recursion, closed &lt;code&gt;patternProperties&lt;/code&gt;, literal patterns, &lt;code&gt;dependentRequired&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;json-schema-to-zod&lt;/td&gt;
&lt;td&gt;2.8.1&lt;/td&gt;
&lt;td&gt;13&lt;/td&gt;
&lt;td&gt;tuples, &lt;code&gt;oneOf&lt;/code&gt; objects, recursion (&lt;code&gt;$ref&lt;/code&gt; becomes &lt;code&gt;z.any()&lt;/code&gt;), closed &lt;code&gt;patternProperties&lt;/code&gt;, literal patterns, &lt;code&gt;dependentRequired&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;On the OpenAPI document, genever passed 10 of 10 probes and &lt;a href="https://www.npmjs.com/package/openapi-typescript" rel="noopener noreferrer"&gt;openapi-typescript&lt;/a&gt; 7.13.0 passed 9, missing only the literal pattern.&lt;/p&gt;

&lt;p&gt;The other rows are a snapshot: what each tool did that night, at the version shown. When one of them ships a fix, the next run picks it up. Only genever's results are asserted by the comparison's tests.&lt;/p&gt;

&lt;p&gt;Generating from a schema of 500 definitions took genever 54 ms, json-schema-to-typescript 141 ms and quicktype 295 ms (median of 5 runs, on a shared CI runner, so only compare within one run). The tools that infer types aren't timed, since their cost is paid while type-checking.&lt;/p&gt;

&lt;p&gt;The &lt;a href="https://jacobley.github.io/leyman/packages/genever/comparison" rel="noopener noreferrer"&gt;live report&lt;/a&gt; on genever's docs is rebuilt from each night's run, with the failed probes on hover.&lt;/p&gt;

&lt;h2&gt;
  
  
  Where I'd use the others
&lt;/h2&gt;

&lt;p&gt;If the same schema feeds Go, Swift or Kotlin code, use quicktype: it generates for many languages and can infer a schema from sample JSON, and genever only writes TypeScript. If you want runtime checks and the schema has no &lt;code&gt;$ref&lt;/code&gt;s, json-schema-to-zod gives you a Zod validator with the type attached, one generated file instead of a type plus a separate validator. json-schema-to-ts and TypeBox have no build step, which matters when the schema is already written in TypeScript; if it is, &lt;a href="https://jacobley.github.io/leyman/packages/juniper/" rel="noopener noreferrer"&gt;Juniper&lt;/a&gt; is my version of that, with the same types genever generates. And openapi-typescript has more built around it, openapi-fetch for one; genever's &lt;code&gt;Paths&lt;/code&gt; and &lt;code&gt;Operations&lt;/code&gt; types are shaped like its output.&lt;/p&gt;

&lt;h2&gt;
  
  
  Run it yourself
&lt;/h2&gt;

&lt;p&gt;The comparison is &lt;a href="https://github.com/JacobLey/leyman/tree/main/e2e/genever-comparison" rel="noopener noreferrer"&gt;a package in the repository&lt;/a&gt;, and the nightly job runs it with &lt;a href="https://dagger.io/" rel="noopener noreferrer"&gt;Dagger&lt;/a&gt;, so a clone, Docker and the Dagger CLI are enough to run the same thing:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git clone https://github.com/JacobLey/leyman.git &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nb"&gt;cd&lt;/span&gt; leyman
dagger call comparison-report --commit=&lt;span class="s2"&gt;"$(git rev-parse HEAD)"&lt;/span&gt; &lt;span class="kd"&gt;export&lt;/span&gt; --path ./reports
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The report is &lt;code&gt;reports/genever.json&lt;/code&gt;, beside the Go comparison's.&lt;/p&gt;

&lt;p&gt;Versions are pinned in the lockfile, so running the same commit gives the same versions as the table.&lt;/p&gt;

&lt;h2&gt;
  
  
  Try it
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npx genever schema.json --name MyType
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Commit the output, and run &lt;code&gt;genever --ci&lt;/code&gt; in CI to fail when it's out of date. &lt;a href="https://jacobley.github.io/leyman/packages/genever/getting-started" rel="noopener noreferrer"&gt;Getting started&lt;/a&gt; covers the rest, including &lt;a href="https://jacobley.github.io/leyman/packages/genever/guides/openapi" rel="noopener noreferrer"&gt;OpenAPI documents&lt;/a&gt; and &lt;a href="https://jacobley.github.io/leyman/packages/genever/guides/references" rel="noopener noreferrer"&gt;references to other files&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;A type doesn't check anything at runtime. &lt;code&gt;minLength&lt;/code&gt;, &lt;code&gt;format&lt;/code&gt; and most patterns have no TypeScript equivalent, so data still needs a validator: &lt;a href="https://ajv.js.org/" rel="noopener noreferrer"&gt;Ajv&lt;/a&gt; or &lt;a href="https://jacobley.github.io/leyman/packages/juniper-validator/" rel="noopener noreferrer"&gt;juniper-validator&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>programming</category>
      <category>softwaredevelopment</category>
      <category>typescript</category>
    </item>
  </channel>
</rss>
