Status: blocked
Waits for: VB-378, VB-379
Priority: 3
Size: M
Arch: yardstick
Phase: implement
Design ref: none (code structure). docs/typescript-plan.md (P8); the survey in backlog/VB-055.md.
Goal: One sweep, so that every file is rewritten once: (1) rename the 63 modules *.js to *.ts with git mv in a commit of its own (rename only, so history follows); (2) src/ (the modules and src/page/*.js, which stay .js: the page is a script spliced into one closure, 623 top-level names on 12 November) is formatted and Prettier installed at an exact version, print width 120, single quotes (13 Nov, tests/format.js); what is left is the rename to .ts, tests/ and tools/ formatted in a commit of their own, listed in .git-blame-ignore-revs, and tools/wrap.js gone. This also re-indents the module bodies that VB-376 to VB-378 left as they were. Imports name the extension (from './x.ts'; Node’s type stripping needs it, tried in a scratch directory on 12 November), only erasable syntax is allowed (no enum, namespace or parameter properties; Node refused all three there), nothing but the page’s bundle is built: Node runs the .ts modules as they are. tools/wrap.js, its test, the lint’s 160 columns and its 400 lines go in this task (the formatted sim/relations is 691 lines, sim/heirs 651, so the cap cannot stay); tsconfig.json is added with noEmit, allowImportingTsExtensions, erasableSyntaxOnly (TypeScript 5.8 or later: to verify), not strict, and the files are // no checking yet in effect, since nothing is annotated (tsc --noEmit joins npm test in VB-382). Measured on 12 November (Prettier 3.3.3, width 120, single quotes, the defaults otherwise, over a copy of src/sim, src/gen, src/gen.js, src/culture.js, src/sim.js, src/vb.js): 11,917 lines become 19,722; sim/relations 691, sim/heirs 651, sim/records 725, gen.js 1,044. Functions over 60 lines go from 11 to 26 (largest: gen.js:generate 257 to 486).
Acceptance criteria:
.git-blame-ignore-revs lists the formatting commits and the README line git config blame.ignoreRevsFile .git-blame-ignore-revs is in AGENTS.md.npm test runs the modules with Node’s type stripping as they are, and node build.js strips types in the bundle; the Node floor (to verify: type stripping without a flag since 22.18; the Checks workflow’s node-version: 22 takes the latest 22, 22.23.4 here) is written into package.json engines and AGENTS.md.tests/lint.js has no line or column cap, tools/wrap.js and tests/wrap*.js are gone, AGENTS.md’s and BACKLOG.md’s mentions (the refactor rules: “stays under 400 lines”, “lines over 160 characters”) go.src/ is formatted, with npm run format and tests/format.js in npm test (13 Nov); what is left: tests/ and tools/ formatted and under the same check, so an unformatted file fails..ts files; tests/dependencies.js, tests/ownership.js pass; behaviour (node tools/same.js --base REF prints same) and counters unchanged. The first npm run verify makes new fixtures.docs/typescript-plan.md, where this task is P8): waits for Kim’s answers to QUESTIONS.md, “VB-055: the move to TypeScript” (the formatter, the bundler, the hook, the width measures, when, the page and the tests, strict), which may change its criteria; the three rules common to these tasks are at the top of the plan.src/, tests/ or tools/: it is the second window.tests/lint-baseline.json holds long lines only). This task’s own criteria are unchanged; where they name the 400 lines, only the report and its mentions are left to remove.src/ only, asked for in a session with the user after VB-413 (the packing was the habit the cap left; a pilot by hand on sim/stores came first). Prettier 3.10.1 at an exact version, .prettierrc.json (print width 120, single quotes), npm run format, and tests/format.js in the fast tier (prettier --check over src/**/*.js, 2.6 s). The formatting is commit 21ecd40, alone and listed in .git-blame-ignore-revs; AGENTS.md has the git config line. src/ went from 19,795 lines to 34,003 (108 files); sim/relations 692, sim/heirs 651, sim/records 733, gen.js 1,040.node tools/same.js prints same (founders and heirs, seeds 7 and 42, tiny, 2 years); verify, tests/smoke.js and the six tests/browser*.js pass.let st = null, speed = 1, selPawn = -1;, now three lines); one // lint-allow: owner that covered two writes on a line (sim/plans, an old save’s migration), now on each.gen 1,040, page/rigs 977, page/farmart 901, sim/rules 804, sim/kinds 781, sim/records 733, sim/stores 718) are in tests/lint-baseline.json at their lengths. The 160 columns stay, since Prettier breaks no comment: one line is in the baseline (page/treelayout, a template literal)..ts and what comes with it, tests/ and tools/ formatted in a commit of their own (the next batch; tools/wrap.js and its tests go then), and the criteria’s wording where they name the 400 lines and the column cap.