VERSION says 26.8.0-beta.0 inside the 26.9.0-beta.1 package — "replaced at publish time" replaces nothing #92

Closed
opened 2026-09-05 19:52:28 +00:00 by chrnx · 1 comment
Owner

src/index.ts exports a version constant that nothing updates:

/** Package version, replaced at publish time. */
export const VERSION = '26.8.0-beta.0';

package.json and deno.json both say 26.9.0-beta.1. The comment describes a
publish step that does not exist: tsup.config.ts lists src/index.ts as an
entry with no define or replacement, and release.yml only ever reads
require('./package.json').version — to pick the dist-tag and to check whether
npm and JSR already hold the version. Nothing writes the constant back, so it
holds whatever the last hand-edit left there.

This is not only a repo-state drift; it shipped. From the published tarball:

$ npm view @green-tea/core@26.9.0-beta.1 dist.tarball -s | xargs curl -s \
    | tar -xzO package/dist/index.js | grep 'var VERSION'
var VERSION = "26.8.0-beta.0";

So an application that installs 26.9.0-beta.1 and reads VERSION is told it
is on 26.8.0-beta.0. Both are betas of a framework whose surface changed
between them — the request budget, sse(data, { id }), the reserved token
names — so the one value a consumer would reach for to branch on, or to put in a
bug report, is the one that is wrong. It also breaks the CLI direction: a
matcha doctor that reports which core a project is running cannot use this
export and has to read the installed package.json instead.

Why the test suite is green

test/smoke.test.ts is the only thing that looks at it:

expect(VERSION).toMatch(/^\d{2}\.\d{1,2}\.\d+(-beta\.\d+)?$/);

That asserts the shape, not the value. 26.8.0-beta.0 satisfies the CalVer
regex exactly as well as the correct string does, and would keep satisfying it
for as many releases as the constant sits still. The check that exists is the
reason nobody noticed the check that was missing.

Two ways out

  1. Assert the value. Have the smoke test — or test/package-metadata.test.ts,
    which is already the home for this kind of claim — compare VERSION against
    package.json's version. Then a bump that forgets the constant fails in CI,
    before the tag, rather than in a published artifact.
  2. Make the comment true. Have the release rewrite the constant from
    package.json before npm run build.

(1) is smaller, needs no new release machinery, and fails at the moment the
mistake is made rather than one step later. It also keeps the constant a plain
literal that JSR can serve as source, which (2) would have to be careful about —
JSR publishes src/, so a substitution applied only to the tsup build would fix
npm and leave JSR reporting the stale value.

Found while auditing what the matcha
CLI had fallen behind on; unrelated to that fix, and filed here because the
constant is core's to correct.

`src/index.ts` exports a version constant that nothing updates: ```ts /** Package version, replaced at publish time. */ export const VERSION = '26.8.0-beta.0'; ``` `package.json` and `deno.json` both say `26.9.0-beta.1`. The comment describes a publish step that does not exist: `tsup.config.ts` lists `src/index.ts` as an entry with no `define` or replacement, and `release.yml` only ever *reads* `require('./package.json').version` — to pick the dist-tag and to check whether npm and JSR already hold the version. Nothing writes the constant back, so it holds whatever the last hand-edit left there. This is not only a repo-state drift; it shipped. From the published tarball: ``` $ npm view @green-tea/core@26.9.0-beta.1 dist.tarball -s | xargs curl -s \ | tar -xzO package/dist/index.js | grep 'var VERSION' var VERSION = "26.8.0-beta.0"; ``` So an application that installs `26.9.0-beta.1` and reads `VERSION` is told it is on `26.8.0-beta.0`. Both are betas of a framework whose surface changed between them — the request budget, `sse(data, { id })`, the reserved token names — so the one value a consumer would reach for to branch on, or to put in a bug report, is the one that is wrong. It also breaks the CLI direction: a `matcha doctor` that reports which core a project is running cannot use this export and has to read the installed `package.json` instead. ## Why the test suite is green `test/smoke.test.ts` is the only thing that looks at it: ```ts expect(VERSION).toMatch(/^\d{2}\.\d{1,2}\.\d+(-beta\.\d+)?$/); ``` That asserts the *shape*, not the *value*. `26.8.0-beta.0` satisfies the CalVer regex exactly as well as the correct string does, and would keep satisfying it for as many releases as the constant sits still. The check that exists is the reason nobody noticed the check that was missing. ## Two ways out 1. **Assert the value.** Have the smoke test — or `test/package-metadata.test.ts`, which is already the home for this kind of claim — compare `VERSION` against `package.json`'s `version`. Then a bump that forgets the constant fails in CI, before the tag, rather than in a published artifact. 2. **Make the comment true.** Have the release rewrite the constant from `package.json` before `npm run build`. (1) is smaller, needs no new release machinery, and fails at the moment the mistake is made rather than one step later. It also keeps the constant a plain literal that JSR can serve as source, which (2) would have to be careful about — JSR publishes `src/`, so a substitution applied only to the tsup build would fix npm and leave JSR reporting the stale value. Found while auditing what the [matcha](https://github.com/Expressive-Tea/matcha) CLI had fallen behind on; unrelated to that fix, and filed here because the constant is core's to correct.
Author
Owner

Fixed in 26.9.0-beta.2 (a30c2ce). Nothing replaces the constant at publish time, so the code no longer pretends it does: the comment on VERSION in src/index.ts now says it is kept in step with package.json and deno.json by hand, and test/package-metadata.test.ts asserts that VERSION equals package.json's version. A release that bumps one and not the other now fails CI instead of shipping a stale constant. 26.11.0-rc.1 ships VERSION = '26.11.0-rc.1'.

Fixed in **26.9.0-beta.2** (`a30c2ce`). Nothing replaces the constant at publish time, so the code no longer pretends it does: the comment on `VERSION` in `src/index.ts` now says it is kept in step with `package.json` and `deno.json` by hand, and `test/package-metadata.test.ts` asserts that `VERSION` equals `package.json`'s version. A release that bumps one and not the other now fails CI instead of shipping a stale constant. 26.11.0-rc.1 ships `VERSION = '26.11.0-rc.1'`.
chrnx closed this issue 2026-11-18 01:03:56 +00:00
Sign in to join this conversation.