2c671a1be7
ci/woodpecker/tag/docker Pipeline was successful
npm clients need one registry for internal and public packages, but npm virtuals have no merger, so a local npm repo and npmjs cannot be served together. - merge packuments across members: union versions (member order wins), first-defined dist-tags minus ones naming missing versions - serve full and abbreviated (`install-v1`) packuments, scoped names included, via the shared virtual merge cache - point tarballs at `<virtual>/<member>/<path>` and 302 them to the owning member - reject an invalid Host with 400; serve virtual and local packuments `no-store` with `Vary: Host, X-Forwarded-Proto, Accept` - return 502 when a member errors; skip members without the package - add `docs/npm/virtual.md` and a stock `node:22` e2e-docker case Reviewed-on: #152 Co-authored-by: unkin-agent <unkin-agent@unkin.net> Co-committed-by: unkin-agent <unkin-agent@unkin.net>
27 lines
678 B
Go
27 lines
678 B
Go
package v1
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
|
|
"git.unkin.net/unkin/artifactapi/internal/virtual"
|
|
)
|
|
|
|
// LocalNPMPackument serves a local npm repo's packument to npm virtuals, with
|
|
// tarball paths relative to the repo.
|
|
func (h *ProxyHandler) LocalNPMPackument(ctx context.Context, repo, pkg string) ([]byte, error) {
|
|
files, err := h.db.ListLocalFilesByPrefix(ctx, repo, pkg+"/-/")
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
read := func(hash string) ([]byte, error) { return h.readLocalBlob(ctx, hash) }
|
|
doc, err := buildNPMPackument(pkg, files, read, "")
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if doc == nil {
|
|
return nil, virtual.ErrNotFound
|
|
}
|
|
return json.Marshal(doc)
|
|
}
|