build: the repo writes TypeScript, and node runs it without a build step #2477
No reviewers
Labels
No labels
blocked-on-build
bug
device
device-request
enhancement
from-github
needs-datasheet
needs-info
needs-triage
ready-for-agent
ready-for-human
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
jaylouisw/packetforge!2477
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "build/typescript"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Jay's rule from today: all new code is TypeScript; existing JS converts as it is touched;
anyappears 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
.tsfile is the program:node scripts/x.tsis the build.tsc --noEmitis a checker, never an emitter.typescriptand@types/nodeare dev-only;dependenciesstays empty and the Docker image still ships nonode_modules.What changes
package.jsontypescript+@types/nodeas the only devDependencies;engines.node: >=22.18.0;typecheck=tsc --noEmit && node scripts/check-no-any.ts;testandcheck:bytesrepointed at the converted scripttsconfig.jsonnoEmit,allowJs: false,erasableSyntaxOnly(the runtime refusesenum/namespace, so the compiler refuses them first — proven by probes that fail with TS1294/TS2322)scripts/check-control-bytes.js → .ts.jsit replaces: same stdout, same failure text and exit code on an injected 0x08; the only behavioural difference is that it now scans.tstooscripts/run-tests.js.test.jsor.test.ts;.jsorder and count unchanged. Rebased on #2468, so the dirty-tree guard and failure attribution are intact.forgejo/workflows/ci.ymlnpm 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-codedmatrix.node == '18'keys re-pointed so the width switch and syntax sweep keep runningDockerfilenode:20-alpine→node:22-alpine, matching the floor.gitattributes*.ts,*.d.tsas LFdocs/TYPESCRIPT.md(new).jsis toucheddocs/CI.md,CONTRIBUTING.mddocs/TYPESCRIPT.mdOne design reversal, recorded because it matters. This branch first shipped a hand-written
types/node.d.tsdeclaring the Node surface the converted files used, sotypescriptcould be the only devDependency. It went stale within the same batch: the no-anyguard from #2474 importsnode:osandnode:child_process, and the hand-declared surface rejected both. It is deleted;@types/nodeis 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.tsand its 305-line test (this branch's own 144-line copy was dropped in favour of it), and #2466'sdocs/CI.mdrewrite (the classifier-job sentence is main's; the Node/typecheck sentences are this branch's).Gates
Not done:
allowJsstays off (the 544 legacy files enter the typecheck one conversion at a time — that is the "migrate as touched" half of the rule),AGENTS.mduntouched (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.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.ymlchange). Needs Jay's decision / the author.What I verified (this run, scratch worktree at
fbe32281,npm ci --ignore-scripts):./node_modules/.bin/tsc --noEmitat head./node_modules/.bin/tsc --noEmitaftergit merge origin/main(throughd7767ee0)node scripts/check-no-any.ts(Node 26)0 occurrences in 0 files (3 scanned)So the tree is clean and the merge is clean;
mergeable=trueis 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 300ontscto have fired (a 124/137 would have cost 300 s plus the 10 s kill-after), which leaves the third step. Thetypecheckjob (line 1549) has nosetup-nodeand 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 theTest (Node *)legs each fetch their own pinned 22/24 tarball. On Node 20,node scripts/check-no-any.tscannot load a.tsfile at all (ERR_UNKNOWN_FILE_EXTENSION), so it exits non-zero and takes the job with it.tscis 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 tonode:22-alpine— and then the one job that executes a.tsfile is left on 20.Two ways out, both an author decision:
typecheckjob the same pinned Node 22 tarball the test legs use (costs ~20 s per run on a job that is currently ~60 s), ornode scripts/check-no-any.tsfrom that job and run it undertsc, keeping the job on 20.npm run typecheckinpackage.jsonchains both, so (2) also means changing that script. I have not touched the workflow, the Dockerfile,package.jsonortsconfig.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.
fbe32281d3a004642b24