Skip to content

Generate src/version.js from codemeta.json instead of tracking it - #48

Merged
t4k merged 2 commits into
caltechlibrary:mainfrom
t4k:build/generate-version-js
Sep 2, 2026
Merged

Generate src/version.js from codemeta.json instead of tracking it#48
t4k merged 2 commits into
caltechlibrary:mainfrom
t4k:build/generate-version-js

Conversation

@t4k

@t4k t4k commented Sep 2, 2026

Copy link
Copy Markdown
Member

The version reported by the shipped bundles has been wrong for over a year.
src/version.js said 0.0.12 while codemeta.json said 0.0.16, and since
the CDN serves unversioned paths, that export is the only way a consumer can
tell what they are running.

Why it went stale

Nothing wrote it. cmt is the generator and the Makefile invokes it:

version.js: .FORCE
	cmt codemeta.json version.js

That writes the repository root. The bundler reads src/version.js. They have
been different files since the src/ reorganization in dac929b (2025-07-17),
and the target cannot be pointed at the new location, because cmt uses the
output filename as the format key (cmt.ts:211, const format = outputName).
So cmt codemeta.json src/version.js exits with unsupported format.

src/version.js still carries that commit’\s own date and hash. It was correct
the day it was written and never again.

What this does

  • tools/generate-version.js reads codemeta.json and writes src/version.js.
    Byte-identical to what cmt 0.0.46 produces; verified by diff.
  • deno task build now depends on deno task generate-version, so the version
    cannot drift from codemeta.json again.
  • src/version.js is untracked, per ADR-0003 — it is build output.
  • deno task release had also drifted and would have built from a missing file
    on a clean checkout. It is now an alias for deno task build.

Verified on a clean checkout: produces 0.0.16, matching codemeta.json.

What this does not change

cmt codemeta.json version.js still works and still refreshes the root
version.js, which is published. The Makefile is untouched.

A copy, deliberately

The script is vendored rather than shared, because every option that would
share it is blocked or out of scope right now. ADR-0004 records the four
rejected alternatives so the next person does not have to rediscover them.
The script is project-agnostic, so replacing it later costs one line in
deno.json.

t4k and others added 2 commits September 2, 2026 07:36
The CDN bundle reports version 0.0.12, released 2025-07-17, while
codemeta.json says 0.0.16, released 2026-01-28. That string is in production
JavaScript today, four releases and seven months out of date.

The cause is a gap in the tooling rather than anyone forgetting. cmt can only
write to the repository root, so the Makefile generates version.js there and
moves it into src/. Nothing runs that except a person typing `make`, and
`deno task build` used to write its own bundle over the top of it.

tools/version.js writes the file from inputs already in the repository:

  version      codemeta.json "version"
  releaseDate  codemeta.json "datePublished"
  releaseHash  git rev-parse --short HEAD
  licenseText  LICENSE.txt, or LICENSE

Output is byte-identical to cmt's, verified against the committed file. This
is not a replacement for cmt -- it covers the one file cmt cannot write to the
right place, and cmt keeps README.md and CITATION.cff.

`deno task build` runs it first, so a fresh clone needs Deno and nothing else,
and the file cannot drift because it no longer exists between builds. It is
gitignored for the same reason: it is build output, and it was tracked before,
so without the ignore the next `git add -A` would restore the stale copy.

`deno task release` becomes an alias for `deno task build` rather than a second
copy of the same commands. The two had already drifted -- release omitted the
version step, so on a clean checkout it would bundle against a file that does
not exist. Two definitions of one build is what allowed that, and it is the
same drift that let release zips and local builds disagree. The task CI
exercises is the one that stays correct; nothing ever ran release.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
ADR-0004. The generator has to live somewhere, and the options that would
share it across projects are all blocked or out of scope: cmt cannot write
to src/, metadatatools is the wrong domain and its only version is yanked,
raw GitHub URLs are served as text/plain and Deno refuses them, and
publishing a package to JSR is not something we are taking on now.

Vendoring is a placeholder. The script is deliberately project-agnostic so
that replacing it costs one line in deno.json.
@t4k
t4k merged commit 4aea270 into caltechlibrary:main Sep 2, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant