Invalidate stale latest resolution when a newer explicit version is requested - #1398
Conversation
|
Alternative considered: bump the While implementing this I also considered a cheaper alternative: when an explicit-version request resolves to a version newer than the currently cached I did not follow that path, for a semantic reason:
A prerelease-suffix check ( This also pairs well with a larger Second alternative considered: ask npm for its dist-tags instead of comparing versions The invalidation above compares the requested version against the cached We still did not go with it. The re-resolution already is the tag lookup: the bare-name URL goes straight through the registry's dist-tag route, so it cannot disagree with npm — which is the entire point. Querying the tags separately would cost the same single small request (it only happens once per freshly built version, on demand) yet add an endpoint, a matching branch and a failure path, to save at most a redundant re-resolution that is harmless and rare. One honest caveat: because the invalidation fires only when the requested version is newer than the cached |
Problem
After publishing a new version, the default (bare-name) URL such as
https://esm.sh/<pkg>/...keeps resolving to the previously cachedlatestversion until the npm query cache TTL (npmQueryCacheTTL, default 600s) expires. Requesting the new version explicitly (<pkg>@newver/...) builds and caches it, but does not make the default URL follow — the two resolutions live in separate cache entries (npm:<pkg>@latestvsnpm:<pkg>@<version>).Change
When an explicit-version request has been built successfully, and that version is newer than the currently cached
latestresolution, invalidate thenpm:<pkg>@latestand404:<pkg>@latestcache entries. The invalidation is triggered from the build-success path in the router (invalidateDistTagCacheIfNewer), and the next bare-name request re-resolves the dist-tag through the registry version route (a single smallpackage.json, not the full metadata), so it still follows npm's officiallatestdist-tag — no guessing involved.Two design choices worth noting:
latestitself), never touch the cache. Av/=-prefixed version is normalized first.Benefits
npmQueryCacheTTL: since authors can refresh on demand, deployments can raisenpmQueryCacheTTL(e.g. to 1h) to reduce registry query pressure without delaying how soon new releases become the default.Tests
Added
TestInvalidateDistTagCacheIfNewercovering equal, older, newer, non-exact andv-prefixed version requests.