Status: done (2026-11-21)
Priority: 3
Size: M
Arch: yardstick
Phase: implement
Design ref: none (code structure). docs/typescript-plan.md (P3); the survey in backlog/VB-055.md.
Goal: An ES module’s exports cannot be reassigned, and ten files do that today to count or time a function: tools/perf.js (about 25 functions of 12 modules), tools/moving-profile.js, tools/route-bench.js, tools/wood.js, tests/spread.js, tests/plans.js (R.value), tests/lib/owner-caches.js (heirs.refreshRoles) and tests/lib/record.js, tests/lib/line.js and tests/bench.js (which patch data tables or a fixture loader, and may need nothing). Seven of them also read src/manifest.json and require each module in turn to wrap one right after it registers, so that the modules loaded later destructure the wrapper. Choose, build and use one hook for all of them, and put the loading itself in one place (src/load.js today, read by 120 files) so that the later tasks change one file. Three ways were weighed in the survey: (a) a registry in the source, probe(key, name, fn), an identity unless a hook is installed before load; (b) the build’s own instrumenting, an esbuild plugin that wraps the named exports in a bundle made for the tool; (c) a Node module-customisation hook. Proposed: (b), because tools/perf.js states that “nothing is added to src/”, production has no cost, and it needs no change to the sources when the modules become ES modules; (a) is the fallback if the plugin proves fragile. The first step of the task is to prototype (b) on tools/perf.js and tests/spread.js and say what it cost.
Acceptance criteria:
tests/lib/load.js exports loadModules({ wrap }), wrap being { 'sim/lifecycle': { roundPhase: (fn) => wrapped } }; with no argument it is src/load.js as now. Today it works as the seven tools do (require in manifest order, wrap after each registers); it is the one place the later tasks change.src/manifest.json to load (the fixtures hash and the lint still read it as a list).tools/perf.js’s report and tests/bench.js are unchanged.docs/architecture/modules.md, “Adding things”: one line on how to time or count a function.docs/typescript-plan.md, where this task is P3): 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.May run beside: any task that does not edit those ten files.