mirror of
https://github.com/kuhyx/utils.git
synced 2026-11-19 04:54:39 +01:00
Finishes the last two of the eleven manifests in this repo. Exact-pins every devDependency and takes three majors -- @testing-library/jest-dom 6 -> 7, jsdom 29 -> 30, pnpm 10.13.1 -> 11.24.0 -- with lint and coverage green in both (ts_core 42/42, web_ui 102/102, 100% branches). **TypeScript stays at 6.0.3, and this is the campaign's first real unsatisfiable conflict.** TS 7.0.2 is latest, but typescript-eslint 8.68.0 -- itself the latest release -- declares `typescript: ">=4.8.4 <6.1.0"` and throws "does not support TS 7.0" as eslint loads its config. There is no 9.x. Taking TS 7 would mean dropping every type-aware lint rule from both packages, so the compiler waits for the linter. Recorded as a `transitive:` allowlist entry, which is a predicate rather than a date: the gate re-checks the blocker each run and the entry clears itself when upstream ships support. First use of the allowlist, and the loud banner now prints on every run here. **pnpm 11 also made the gate wrong, and the gate was fixed rather than pnpm.** pnpm 11 quarantines packages published inside a 24h window -- a supply-chain measure against the period when a compromised publish is live -- and refused @testing-library/react 16.3.3, published 18h earlier. Reporting a repo as behind a version its package manager will not install is a finding nobody can act on: the hook fails, and so does the fix it asks for. `quarantine.py` now narrows npm's "latest" to the newest release old enough to install, bounded above by `dist-tags.latest` so a maintenance-line release never outranks the tag. It fetches the FULL packument (7MB for react, 16MB for typescript) and so runs only after a finding already exists -- a clean run pays nothing, which a test asserts by making the fetch raise. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01CRykabMwPgDzFHcARoqpaK
77 lines
2.9 KiB
Python
77 lines
2.9 KiB
Python
"""What is the newest npm version the package manager will actually install?
|
|
|
|
pnpm 11 refuses any package published inside its `minimumReleaseAge` window --
|
|
a supply-chain measure that blunts the period during which a compromised
|
|
publish is live. Reporting a repo as "behind" a version pnpm would reject is a
|
|
finding nobody can act on, so the gate's notion of latest is narrowed to match.
|
|
|
|
Cost is the reason this is a separate pass rather than part of `npmjs.latest`.
|
|
Publish timestamps live only in the FULL registry document, which is 7MB for
|
|
react and 16MB for typescript, against 3MB and 9MB abbreviated. So the full
|
|
document is fetched only when a finding already exists -- in the steady state,
|
|
where everything is current, that is zero extra requests.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from datetime import datetime, timedelta, timezone
|
|
|
|
from dep_freshness._tables import NPM_API, NPM_QUARANTINE_HOURS
|
|
from dep_freshness.registries.http import Offline, get_json
|
|
from dep_freshness.versions import newest_stable, parse
|
|
|
|
|
|
def cutoff(now: datetime | None = None) -> datetime:
|
|
"""Publishes at or after this instant are still quarantined."""
|
|
moment = now or datetime.now(timezone.utc)
|
|
return moment - timedelta(hours=NPM_QUARANTINE_HOURS)
|
|
|
|
|
|
def _parse(stamp: str) -> datetime | None:
|
|
try:
|
|
return datetime.fromisoformat(str(stamp).replace("Z", "+00:00"))
|
|
except (TypeError, ValueError):
|
|
return None
|
|
|
|
|
|
def installable_latest(
|
|
name: str, ceiling: str, now: datetime | None = None
|
|
) -> str | None:
|
|
"""Newest stable release published before the quarantine cutoff.
|
|
|
|
`ceiling` is the registry's `dist-tags.latest`, and candidates above it are
|
|
ignored. npm lets a maintainer publish a version without tagging it
|
|
`latest` -- a maintenance-line release on an older major, say -- so the
|
|
highest version NUMBER is not always the current release. Falling back to
|
|
the numeric maximum here would recommend a version npm does not consider
|
|
current, and would disagree with `npmjs.latest`, which honours the tag.
|
|
|
|
Returns None when the answer cannot be determined (offline, or the
|
|
registry has no `time` map), which callers must treat as "no change" --
|
|
narrowing on a guess would hide a genuinely stale dependency.
|
|
"""
|
|
url = NPM_API.format(name=name.replace("/", "%2f"))
|
|
try:
|
|
payload = get_json(url)
|
|
except Offline:
|
|
return None
|
|
if not payload:
|
|
return None
|
|
times = payload.get("time")
|
|
if not isinstance(times, dict):
|
|
return None
|
|
limit = cutoff(now)
|
|
top = parse(ceiling)
|
|
old_enough = []
|
|
for version, stamp in times.items():
|
|
if version in ("created", "modified"):
|
|
continue
|
|
when = _parse(stamp)
|
|
if when is None or when >= limit:
|
|
continue
|
|
here = parse(version)
|
|
if top is not None and (here is None or here > top):
|
|
continue
|
|
old_enough.append(version)
|
|
return newest_stable(old_enough)
|