Files
mesh-catalog/modules/mesh-build-node/cmd/mesh-build-node/builds.go
T

71 lines
2.3 KiB
Go

package main
// **A group run's package members, laid from their builds** (design 47 G §465, §373): a fetch naming `builds` reads each
// member's build (the npm package's packed tarball, package.go's packed) from the artifact store by its digest, checks
// it and places it as the local package it names in each TypeScript module's node_modules: nothing is fetched by a
// version, and none is reserved. A member that does not match its digest, or a store that does not answer, fails the
// step naming the member.
import (
"context"
"fmt"
"os"
"path/filepath"
sdkstep "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/buildstep"
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/steprun"
)
// storedBuild is one member's build, read and checked.
type storedBuild struct {
member sdkstep.FetchBuild
tgz []byte
}
// readBuilds reads every member of builds from the artifact store.
func (m *Module) readBuilds(ctx context.Context, builds []sdkstep.FetchBuild) ([]storedBuild, error) {
if len(builds) == 0 {
return nil, nil
}
base, err := steprun.StoreURL(m.ArtifactStoreFile)
if err != nil {
return nil, fmt.Errorf("a group run's members are read from the artifact store: %w", err)
}
var out []storedBuild
for _, b := range builds {
data, err := steprun.ReadStoredBuild(ctx, m.httpClient(), base, b)
if err != nil {
return nil, err
}
out = append(out, storedBuild{b, data})
}
return out, nil
}
// names says whether a member of the builds is the package pkg.
func namesPackage(builds []storedBuild, pkg string) bool {
for _, b := range builds {
if b.member.Package == pkg {
return true
}
}
return false
}
// layBuilds places each member in dir's node_modules as the package it names, in place of any other.
func (m *Module) layBuilds(dir string, builds []storedBuild) error {
for _, b := range builds {
into := filepath.Join(dir, "node_modules", filepath.FromSlash(b.member.Package))
if err := os.RemoveAll(into); err != nil {
return err
}
if err := unpackPackage(b.tgz, into); err != nil {
return fmt.Errorf("the build of %s (%s %s at %s): %w", b.member.Package, b.member.Module, b.member.Artifact, b.member.Digest, err)
}
if m.Say != nil {
m.Say("laid %s from its build %s (%s %s)", b.member.Package, b.member.Digest, b.member.Module, b.member.Artifact)
}
}
return nil
}