build: the repo writes TypeScript, and node runs it without a build step #2477

Merged
jaylouisw merged 1 commit from build/typescript into main 2026-11-23 22:56:25 +00:00
Owner

Jay's rule from today: all new code is TypeScript; existing JS converts as it is touched; any appears nowhere. This is the toolchain that makes that enforceable, with no build step and no runtime dependency.

The model. Node 22.18 strips types at load, so the .ts file is the program: node scripts/x.ts is the build. tsc --noEmit is a checker, never an emitter. typescript and @types/node are dev-only; dependencies stays empty and the Docker image still ships no node_modules.

What changes

File Change
package.json typescript + @types/node as the only devDependencies; engines.node: >=22.18.0; typecheck = tsc --noEmit && node scripts/check-no-any.ts; test and check:bytes repointed at the converted script
tsconfig.json strict, noEmit, allowJs: false, erasableSyntaxOnly (the runtime refuses enum/namespace, so the compiler refuses them first — proven by probes that fail with TS1294/TS2322)
scripts/check-control-bytes.js → .ts The seed conversion. Byte-identical to the .js it replaces: same stdout, same failure text and exit code on an injected 0x08; the only behavioural difference is that it now scans .ts too
scripts/run-tests.js One glob matches .test.js or .test.ts; .js order and count unchanged. Rebased on #2468, so the dirty-tree guard and failure attribution are intact
.forgejo/workflows/ci.yml New Typecheck job (npm ci --ignore-scripts, tsc, no-any); test matrix moves to Node 22 and 24 — 18 and 20 cannot run the language the repo now writes; the two hard-coded matrix.node == '18' keys re-pointed so the width switch and syntax sweep keep running
Dockerfile node:20-alpine → node:22-alpine, matching the floor
.gitattributes *.ts, *.d.ts as LF
docs/TYPESCRIPT.md (new) The rule, the toolchain, why there is no build step, what a converted module looks like, what to do when a legacy .js is touched
docs/CI.md, CONTRIBUTING.md The checks table and the Node floor, re-pointed at docs/TYPESCRIPT.md

One design reversal, recorded because it matters. This branch first shipped a hand-written types/node.d.ts declaring the Node surface the converted files used, so typescript could be the only devDependency. It went stale within the same batch: the no-any guard from #2474 imports node:os and node:child_process, and the hand-declared surface rejected both. It is deleted; @types/node is a dev-only type package that node never loads, so the zero-dependency claim is about the running program and stays true.

Merged concurrently and resolved here: #2468's runner work (kept intact under the glob change), #2474's 507-line check-no-any.ts and its 305-line test (this branch's own 144-line copy was dropped in favour of it), and #2466's docs/CI.md rewrite (the classifier-job sentence is main's; the Node/typecheck sentences are this branch's).

Gates

npx tsc --noEmit                 exit 0
scripts/check-no-any.ts          0 occurrences in 3 files
test/no-any.test.ts              28 passed, 0 failed
scripts/check-control-bytes.ts   clean (identical output to the .js it replaces)
scripts/syntax-check.js          547 files all OK
test/node-surface.test.js        8 passed   (floor assertion now parses the number, asserts >=18)
test/canonical-urls.test.js      58 passed
test/doc-citations.test.js       11 passed
check-ci-disk-hygiene, check-canonical-urls, check-node-surface   exit 0
npm ci in a clean dir            installs the lock, yields tsc

Not done: allowJs stays off (the 544 legacy files enter the typecheck one conversion at a time — that is the "migrate as touched" half of the rule), AGENTS.md untouched (protected file, awaiting Jay's consent on a separate draft), and no engine module is converted yet: this PR establishes the pattern, the next one applies it.

Jay's rule from today: **all new code is TypeScript; existing JS converts as it is touched; `any` appears nowhere.** This is the toolchain that makes that enforceable, with **no build step and no runtime dependency**. **The model.** Node 22.18 strips types at load, so the `.ts` file *is* the program: `node scripts/x.ts` is the build. `tsc --noEmit` is a checker, never an emitter. `typescript` and `@types/node` are dev-only; `dependencies` stays empty and the Docker image still ships no `node_modules`. **What changes** | File | Change | |---|---| | `package.json` | `typescript` + `@types/node` as the only devDependencies; `engines.node: >=22.18.0`; `typecheck` = `tsc --noEmit && node scripts/check-no-any.ts`; `test` and `check:bytes` repointed at the converted script | | `tsconfig.json` | strict, `noEmit`, `allowJs: false`, `erasableSyntaxOnly` (the runtime refuses `enum`/`namespace`, so the compiler refuses them first — proven by probes that fail with TS1294/TS2322) | | `scripts/check-control-bytes.js → .ts` | The seed conversion. **Byte-identical to the `.js` it replaces**: same stdout, same failure text and exit code on an injected 0x08; the only behavioural difference is that it now scans `.ts` too | | `scripts/run-tests.js` | One glob matches `.test.js` **or** `.test.ts`; `.js` order and count unchanged. Rebased on #2468, so the dirty-tree guard and failure attribution are intact | | `.forgejo/workflows/ci.yml` | New **Typecheck** job (`npm ci --ignore-scripts`, tsc, no-any); test matrix moves to **Node 22 and 24** — 18 and 20 cannot run the language the repo now writes; the two hard-coded `matrix.node == '18'` keys re-pointed so the width switch and syntax sweep keep running | | `Dockerfile` | `node:20-alpine` → `node:22-alpine`, matching the floor | | `.gitattributes` | `*.ts`, `*.d.ts` as LF | | `docs/TYPESCRIPT.md` (new) | The rule, the toolchain, why there is no build step, what a converted module looks like, what to do when a legacy `.js` is touched | | `docs/CI.md`, `CONTRIBUTING.md` | The checks table and the Node floor, re-pointed at `docs/TYPESCRIPT.md` | **One design reversal, recorded because it matters.** This branch first shipped a hand-written `types/node.d.ts` declaring the Node surface the converted files used, so `typescript` could be the *only* devDependency. It went stale within the same batch: the no-`any` guard from #2474 imports `node:os` and `node:child_process`, and the hand-declared surface rejected both. It is deleted; `@types/node` is a dev-only type package that node never loads, so the zero-dependency claim is about the running program and stays true. **Merged concurrently and resolved here:** #2468's runner work (kept intact under the glob change), #2474's 507-line `check-no-any.ts` and its 305-line test (this branch's own 144-line copy was dropped in favour of it), and #2466's `docs/CI.md` rewrite (the classifier-job sentence is main's; the Node/typecheck sentences are this branch's). **Gates** ``` npx tsc --noEmit exit 0 scripts/check-no-any.ts 0 occurrences in 3 files test/no-any.test.ts 28 passed, 0 failed scripts/check-control-bytes.ts clean (identical output to the .js it replaces) scripts/syntax-check.js 547 files all OK test/node-surface.test.js 8 passed (floor assertion now parses the number, asserts >=18) test/canonical-urls.test.js 58 passed test/doc-citations.test.js 11 passed check-ci-disk-hygiene, check-canonical-urls, check-node-surface exit 0 npm ci in a clean dir installs the lock, yields tsc ``` **Not done:** `allowJs` stays off (the 544 legacy files enter the typecheck one conversion at a time — that is the "migrate as touched" half of the rule), `AGENTS.md` untouched (protected file, awaiting Jay's consent on a separate draft), and no engine module is converted yet: this PR establishes the pattern, the next one applies it.
build: the repo writes TypeScript, and node runs it without a build step
Some checks failed
CI / Test (Node 22) (pull_request) Successful in 47s
CI / Test (Node 24) (pull_request) Successful in 52s
CI / Server smoke and Docker build (pull_request) Successful in 59s
CI / Typecheck (pull_request) Failing after 11s
PR rebase / Rebase onto main and arm auto-merge (pull_request) Successful in 6s
CI / Arm auto-merge (pull_request) Successful in 6s
fbe32281d3
typescript and @types/node are dev-only: node runs the .ts files themselves (type
stripping), so there is no compile step and the running program still has no
dependencies. engines.node moves to 22.18, the floor where stripping is on by
default, and tsc --noEmit is the gate rather than a build.

- tsconfig.json: strict, noEmit, allowJs false (the 544 CommonJS files stay out of
  the typecheck until each is touched), erasableSyntaxOnly - the strip-types runtime
  refuses enums and namespaces, so the compiler refuses them first.
- scripts/check-control-bytes.ts: the seed conversion, proven byte-identical to the
  .js it replaces - same stdout, same failure text and exit code on an injected 0x08.
- scripts/run-tests.js: one glob now matches .test.js and .test.ts; .js order and
  count unchanged. Keeps the dirty-tree guard and failure attribution landed in #2468.
- ci.yml: a Typecheck job, and the matrix moves to the versions that can run the
  language (18 and 20 cannot).
- Dockerfile, .gitattributes, CONTRIBUTING.md, docs/CI.md, docs/TYPESCRIPT.md.

The hand-declared types/node.d.ts this branch first shipped is deleted: @types/node
replaces it, because a Node surface maintained by hand went stale on the first branch
that imported node:child_process.
Author
Owner

Red on CI / Typecheck — the job has no Node ≥ 22, so the second gate cannot run at all. Not a code defect; not mine to fix (it is a .forgejo/workflows/ci.yml change). Needs Jay's decision / the author.

What I verified (this run, scratch worktree at fbe32281, npm ci --ignore-scripts):

Step Local result
./node_modules/.bin/tsc --noEmit at head exit 0, no output, 0.39 s
./node_modules/.bin/tsc --noEmit after git merge origin/main (through d7767ee0) exit 0, no output
node scripts/check-no-any.ts (Node 26) exit 0 — 0 occurrences in 0 files (3 scanned)

So the tree is clean and the merge is clean; mergeable=true is honest. The other four gates of run 10624 (Test 22, Test 24, smoke+Docker) went green on the same commit.

Why the job is red anyway. Run 10624: job start 22:15:14, failure 22:16:17 — 63 s. That is too fast for the timeout 300 on tsc to have fired (a 124/137 would have cost 300 s plus the 10 s kill-after), which leaves the third step. The typecheck job (line 1549) has no setup-node and no tarball download, so it runs on the runner's default Node 20 — the file says so itself at line 230: "No setup-node here: this job already runs on Node 20", and the Test (Node *) legs each fetch their own pinned 22/24 tarball. On Node 20, node scripts/check-no-any.ts cannot load a .ts file at all (ERR_UNKNOWN_FILE_EXTENSION), so it exits non-zero and takes the job with it. tsc is pure JS and passes on 20, which is why exactly one gate is red.

The same contradiction is in the PR's own premise: engines.node >=22.18.0, the matrix moved to 22/24 because 18 and 20 cannot run the language the repo now writes, the Dockerfile moves to node:22-alpine — and then the one job that executes a .ts file is left on 20.

Two ways out, both an author decision:

  1. give the typecheck job the same pinned Node 22 tarball the test legs use (costs ~20 s per run on a job that is currently ~60 s), or
  2. drop node scripts/check-no-any.ts from that job and run it under tsc, keeping the job on 20.

npm run typecheck in package.json chains both, so (2) also means changing that script. I have not touched the workflow, the Dockerfile, package.json or tsconfig.json — that is content, not a mechanical rebase.

Rebase not needed: head is mergeable, no conflict, no add/add, and a rebase cannot supply a runtime.

**Red on `CI / Typecheck` — the job has no Node ≥ 22, so the second gate cannot run at all. Not a code defect; not mine to fix (it is a `.forgejo/workflows/ci.yml` change). Needs Jay's decision / the author.** **What I verified (this run, scratch worktree at `fbe32281`, `npm ci --ignore-scripts`):** | Step | Local result | |---|---| | `./node_modules/.bin/tsc --noEmit` at head | exit 0, no output, 0.39 s | | `./node_modules/.bin/tsc --noEmit` after `git merge origin/main` (through `d7767ee0`) | exit 0, no output | | `node scripts/check-no-any.ts` (Node 26) | exit 0 — `0 occurrences in 0 files (3 scanned)` | So the tree is clean and the merge is clean; `mergeable=true` is honest. The other four gates of run 10624 (Test 22, Test 24, smoke+Docker) went green on the same commit. **Why the job is red anyway.** Run 10624: job start 22:15:14, failure 22:16:17 — **63 s**. That is too fast for the `timeout 300` on `tsc` to have fired (a 124/137 would have cost 300 s plus the 10 s kill-after), which leaves the third step. The `typecheck` job (line 1549) has **no `setup-node` and no tarball download**, so it runs on the **runner's default Node 20** — the file says so itself at line 230: *"No setup-node here: this job already runs on Node 20"*, and the `Test (Node *)` legs each fetch their own pinned 22/24 tarball. On Node 20, `node scripts/check-no-any.ts` cannot load a `.ts` file at all (`ERR_UNKNOWN_FILE_EXTENSION`), so it exits non-zero and takes the job with it. `tsc` is pure JS and passes on 20, which is why exactly one gate is red. **The same contradiction is in the PR's own premise:** `engines.node >=22.18.0`, the matrix moved to 22/24 *because 18 and 20 cannot run the language the repo now writes*, the Dockerfile moves to `node:22-alpine` — and then the one job that executes a `.ts` file is left on 20. **Two ways out, both an author decision:** 1. give the `typecheck` job the same pinned Node 22 tarball the test legs use (costs ~20 s per run on a job that is currently ~60 s), or 2. drop `node scripts/check-no-any.ts` from that job and run it under `tsc`, keeping the job on 20. `npm run typecheck` in `package.json` chains both, so (2) also means changing that script. I have not touched the workflow, the Dockerfile, `package.json` or `tsconfig.json` — that is content, not a mechanical rebase. **Rebase not needed:** head is mergeable, no conflict, no add/add, and a rebase cannot supply a runtime.
jaylouisw force-pushed build/typescript from fbe32281d3
Some checks failed
CI / Test (Node 22) (pull_request) Successful in 47s
CI / Test (Node 24) (pull_request) Successful in 52s
CI / Server smoke and Docker build (pull_request) Successful in 59s
CI / Typecheck (pull_request) Failing after 11s
PR rebase / Rebase onto main and arm auto-merge (pull_request) Successful in 6s
CI / Arm auto-merge (pull_request) Successful in 6s
to a004642b24
All checks were successful
CI / Test (Node 22) (pull_request) Successful in 47s
CI / Test (Node 24) (pull_request) Successful in 51s
CI / Server smoke and Docker build (pull_request) Successful in 57s
CI / Typecheck (pull_request) Successful in 14s
PR rebase / Rebase onto main and arm auto-merge (pull_request) Successful in 15s
CI / Arm auto-merge (pull_request) Successful in 9s
2026-11-23 22:53:23 +00:00
Compare
forgejo-actions scheduled this pull request to auto merge when all checks succeed 2026-11-23 22:55:40 +00:00
Sign in to join this conversation.
No description provided.