mirror of
https://github.com/floci-io/floci.git
synced 2026-11-22 21:50:46 -05:00
npm's native registry route can now retain a missing package from a repository's own public:npmjs external connection and serve it, instead of always 404ing, mirroring the AWS-documented external-connection behavior already shipped for Maven (#6889) and NuGet (#7104). Unlike Maven's GAV layout and NuGet's {id}/{version}/{filename} content route, npm's own real wire protocol has no request shape that names one version: npm install <pkg>@<version> always fetches the bare package's full packument first (confirmed against pacote's own source, RegistryFetcher#packumentUrl, always the bare package path) and only picks the version out of its own versions map afterward. So this does two things together, not just one: - A bare packument read (the one every real npm install actually sends) merges the real registry's own versions and dist-tags into whatever Verdaccio already knows locally, computed fresh per request and never written to Verdaccio itself (its own publish protocol has no way to record a version's metadata without that version's real tarball bytes in the very same call, confirmed against a live container). Every newly-merged version's dist.tarball is rewritten to this repository's own proxy URL under a deterministic <bareName>-<version>.tgz shape; dist.shasum/dist.integrity are kept exactly as the real registry declared them, since there is no real content yet to hash locally. - A tarball download for a version not yet genuinely retained triggers the real fetch, the same claim/fence/origin-tracking machinery Maven and NuGet already use (closing the same race against a concurrent DeletePackageVersions/direct push), reusing CodeArtifactService's already-generalized claimRetainedVersionOrigin/retainAssetUnderVersionFence methods directly. New: NpmExternalConnectionClient (the outbound client for public:npmjs) and CodeArtifactNpmExternalConnectionImporter (the merge and retention logic), wired into CodeArtifactNpmDataPlane's existing raw proxy. Deliberately scoped the same way Maven/NuGet's own base PRs were: no caching/TTL on the merge fetch (a live check against the real registry on every packument read for a connected repository, matching the same no-caching fidelity level Maven's own maven-metadata.xml merge already ships with), and the documented but rarely-used single-version registry endpoint (GET /<pkg>/<version>) is not specially handled, since real npm install never sends it either. Update: fixed three issues Greptile's review caught, all specific to npm's own two-step retention (a plain cache-miss asset fetch, as NuGet/Maven's retention already was, is not enough here): - retainAssetUnderVersionFence's own write was always the fixed RepositorySidecarManager# storePackageVersionAsset call, which builds a minimal version document with no dependencies/ engines/scripts. Generalized it to take the actual write as a plain Runnable instead, so npm's own call can reuse the real registry's full-form version document verbatim (the same reuse-the-source-document treatment VerdaccioSidecarClient#copyPackageVersionAsset already gives a version copied from another repository), fetched once, only when a version is actually retained, via a new NpmExternalConnectionClient#fetchFullPackument. NuGet's own call site wraps the exact same plain storePackageVersionAsset call it always made. - Verdaccio always points a fresh package's dist-tags.latest at whichever version was retained most recently (confirmed live, nothing a retention write sends can suppress it), so a plain retention could silently move what an unpinned npm install or ListPackageVersions' defaultDisplayVersion resolves to. Fixed on both sides of that same bug: the merge now only lets an external dist-tag replace a local one that itself points at an externally-retained version, and CodeArtifactService#listPackageVersions ignores preferredDisplayVersion the same way when it names one. - A retained version's readme was never captured, so GetPackageVersionReadme 404ed on it even though the tarball existed; the full packument fetch above also captures the package's own readme (confirmed live: it only ever lives at the top of the full packument, never per version) the same way a native publish's own readme capture already works. Verified two ways beyond the automated suite: - A Docker-gated integration test retains a real package (is-even 1.0.0) from the real, live npmjs.com, through a real Verdaccio sidecar: a bare packument read merges the real version in without yet counting any bytes, a subsequent tarball fetch retains it and counts its bytes, a refetch does not double-count, mixed-case-irrelevant upstream-block enforcement blocks both the merge and the retention, a genuinely-missing package stays 404, the retained version's EXTERNAL origin reporting is confirmed against the real sidecar, and its real dependencies/ engines and readme are confirmed readable back from the real sidecar afterward. - Direct curl checks against the real registry.npmjs.org confirmed the exact packument/tarball URL shapes this client builds, including the %2F-escaped scope separator the packument endpoint specifically needs (unlike the tarball path, which uses a literal slash), and that the abbreviated packument form carries dependencies/engines but not scripts or any readme. Update: fixed a fourth issue from the same re-review, found once the three fixes above landed: mergedPackument always fetched the real registry's abbreviated form, even when the real npm client's own Accept header asked for the full one (the shape npm view <pkg> readme-style commands use), so a package the merge had not yet retained anything for showed no readme at all. The merge now honors that header, fetching the real full packument only when the request actually asked for it, and copies its package-level descriptive fields (readme among them) in the same never-override-local way everything else here already merges, with no change to the hot npm install path's own abbreviated fetch. Update 3: fixed a fifth issue from the same re-review: mergedPackument's own real registry fetch is a genuine network round trip, and nothing held any lock across it, so a DeleteRepository finishing its own cleanup while that fetch was still in flight let the later ensureReady call start a fresh container under an id the delete had already released, one nothing would ever release again. Added a re-check that the repository still exists right after that fetch, before this method ever touches the sidecar. This narrows the window back down to an ordinary check-then-act gap rather than one stretched out by a real network round trip, not a full fix: VerdaccioSidecarManager's own beginUse/endUse are no-ops today (unlike PypiserverSidecarManager's), so nothing here can fully close this yet. Filed #7204 to track giving it real in-flight-use tracking as its own, cross-cutting fix. Update 4: fixed a sixth issue from the same re-review: DisposePackageVersions deletes a version's real Verdaccio content outright, so versions.has(version) alone could not tell a disposed version apart from one never retained at all, and the merge could add a disposed version straight back in from the real registry's own still-unaware listing, even pointing dist-tags.latest at it. An unpinned npm install could then select it, only to have the download correctly, but confusingly, fail. The merge now excludes any externally-named version this repository has marked Archived or Disposed, reusing the same requireContainerBackedVersionDownloadable check the native download route itself already enforces.