Skip to content

Commit 28c23c0

Browse files
cliffhallclaude
andcommitted
fix: latest never moves backward on a re-run; pack:verify builds from a clean dist
- publish-npm chooses the dist-tag at publish time: latest for the move from the date-stamped line to 1.x and for a version higher than the registry's latest, backfill otherwise. An older release's failed leg re-run after a newer version published no longer drags latest back. - pack:verify removes dist before packing. tsc never deletes the output of a removed or renamed source file, so a previously built checkout could pack files a fresh checkout would not. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Signed-off-by: cliffhall <[email protected]>
1 parent 7e95cf9 commit 28c23c0

3 files changed

Lines changed: 66 additions & 12 deletions

File tree

‎.github/workflows/release.yml‎

Lines changed: 59 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -274,15 +274,65 @@ jobs:
274274
echo "Refusing to publish: the tarball's package.json $VERDICT"
275275
exit 1
276276
fi
277-
# `--tag latest` is explicit on purpose. npm 11 refuses to apply
278-
# `latest` implicitly when the registry already holds a HIGHER
279-
# version, and it does: the date-stamped releases (2026.8.31) sort
280-
# above every semver version these packages will carry. Without the
281-
# flag the first 1.0.0 publish fails with "Cannot implicitly apply
282-
# the latest tag". The cost is that a prerelease would take `latest`
283-
# too; none is published from here, and one that is needs its own
284-
# tag chosen before this line runs.
285-
npm publish "$1" --access public --tag latest --registry https://registry.npmjs.org/
277+
# The dist-tag is chosen here, at publish time, and always passed
278+
# explicitly.
279+
#
280+
# Explicitly, because npm 11 refuses to apply `latest` on its own
281+
# when the registry already holds a HIGHER version, and it does: the
282+
# date-stamped releases (2026.8.31) sort above every semver version
283+
# these packages will carry. Without a tag the first 1.0.0 publish
284+
# fails with "Cannot implicitly apply the latest tag".
285+
#
286+
# Chosen, because `latest` must never move BACKWARD. A failed leg of
287+
# an older release can be re-run after a newer version has
288+
# published; the registry-diff guard rightly lets the missing older
289+
# version through, and tagging it `latest` would make every `npx`
290+
# serve the older release. So:
291+
# - the registry's `latest` is date-stamped (major >= 2000), or
292+
# the package was never published: `latest`. This is the
293+
# one-time move from 2026.x to 1.x.
294+
# - this version is higher than the registry's `latest`: `latest`.
295+
# - otherwise: `backfill`. The version is published and
296+
# installable by number, and `latest` stays where it is.
297+
# It is asked of the registry now, not when the run started: a
298+
# re-run reuses the original run's job outputs. A registry answer
299+
# that cannot be read, or a version that is not plain x.y.z (a
300+
# prerelease needs its tag chosen by a person), stops the job.
301+
ENCODED="$(printf '%s' "$EXPECTED_NAME" | sed 's|/|%2F|')"
302+
CODE="$(curl -sS -o registry.json -w '%{http_code}' \
303+
-H 'Accept: application/vnd.npm.install-v1+json' \
304+
"https://registry.npmjs.org/$ENCODED")" || {
305+
echo "Refusing to publish: could not reach the registry to read the current latest"
306+
exit 1
307+
}
308+
case "$CODE" in
309+
200) ;;
310+
404) echo '{}' > registry.json ;;
311+
*)
312+
echo "Refusing to publish: the registry answered $CODE when asked for the current latest"
313+
exit 1
314+
;;
315+
esac
316+
TAG="$(node -e "
317+
const num = (s, what) => {
318+
const m = /^(\d+)\.(\d+)\.(\d+)$/.exec(s);
319+
if (!m) throw new Error(what + ' ' + JSON.stringify(s) + ' is not a plain x.y.z version');
320+
return m.slice(1).map(Number);
321+
};
322+
const candidate = num(process.env.EXPECTED_VERSION, 'the version to publish');
323+
const doc = JSON.parse(require('fs').readFileSync('registry.json', 'utf8'));
324+
const latest = (doc['dist-tags'] || {}).latest;
325+
if (typeof latest !== 'string') { console.log('latest'); process.exit(0); }
326+
const current = num(latest, 'the registry latest');
327+
let order = 0;
328+
for (let i = 0; i < 3 && order === 0; i += 1) order = Math.sign(candidate[i] - current[i]);
329+
console.log(current[0] >= 2000 || order > 0 ? 'latest' : 'backfill');
330+
")" || {
331+
echo "Refusing to publish: could not choose a dist-tag (see the error above)"
332+
exit 1
333+
}
334+
echo "Publishing $EXPECTED_NAME@$EXPECTED_VERSION with dist-tag $TAG"
335+
npm publish "$1" --access public --tag "$TAG" --registry https://registry.npmjs.org/
286336
287337
build-pypi:
288338
timeout-minutes: 15

‎RELEASING.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Semver policy:
2222
| **minor** | A new tool, prompt, resource or option |
2323
| **major** | A breaking change: a tool removed or renamed, a schema change that breaks clients, a protocol or Node floor bump |
2424

25-
The semver line starts at **`1.0.0`** for all four packages. Their earlier releases were date-stamped (`2025.x`, `2026.x`), which sorts above any semver number, but `npm install` and `npx` resolve the `latest` dist-tag rather than the highest number, so publishing `1.x` is what users get. npm will not move `latest` to a lower version implicitly, so `release.yml` publishes with an explicit `--tag latest`. Once `1.0.0` is live, a scope maintainer deprecates the date-stamped range (`>=2025.0.0 <2027.0.0`) by hand, once; the `release` skill has the command and the check to run first.
25+
The semver line starts at **`1.0.0`** for all four packages. Their earlier releases were date-stamped (`2025.x`, `2026.x`), which sorts above any semver number, but `npm install` and `npx` resolve the `latest` dist-tag rather than the highest number, so publishing `1.x` is what users get. npm will not move `latest` to a lower version implicitly, so `release.yml` always passes the dist-tag explicitly, and chooses it at publish time: `latest` for the move from the date-stamped line to `1.x` and for any version higher than the registry's current `latest`, and `backfill` otherwise. The second case is an older release's failed leg re-run after a newer version has published: the version becomes installable by number, and `latest` does not move backward. Once `1.0.0` is live, a scope maintainer deprecates the date-stamped range (`>=2025.0.0 <2027.0.0`) by hand, once; the `release` skill has the command and the check to run first.
2626

2727
### Python servers: CalVer
2828

‎scripts/pack-and-verify.mjs‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -268,8 +268,12 @@ function packTs(server, artifactDir, consumer) {
268268
const manifest = JSON.parse(
269269
readFileSync(path.join(pkgDir, "package.json"), "utf8"),
270270
);
271-
// `npm pack` runs the package's `prepare` script, which builds it: the
272-
// tarball holds a fresh build, never whatever `dist/` was lying around.
271+
// `npm pack` runs the package's `prepare` script, which builds it. But
272+
// `tsc` only writes: it never removes the output of a source file that was
273+
// deleted or renamed, so a checkout that was built before can pack files a
274+
// fresh release checkout would not have. The build output is removed first,
275+
// so the tarball is built from the current source and nothing else.
276+
rmSync(path.join(pkgDir, "dist"), { recursive: true, force: true });
273277
const [packed] = JSON.parse(
274278
run("npm", ["pack", "--json", "--pack-destination", artifactDir], pkgDir),
275279
);

0 commit comments

Comments
 (0)