mirror of
https://github.com/TECHNOFAB11/jsonnet-bundler.git
synced 2025-12-12 08:00:05 +01:00
feat: minor improvements
- allow to install pkg that is already locked - clean unknown files from vendor - correctly handle checksums and locked versions (was accidentally ignoring - these before)
This commit is contained in:
parent
cc1d7ea3b8
commit
0588b89c07
3 changed files with 95 additions and 18 deletions
|
|
@ -19,6 +19,7 @@ import (
|
|||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
kingpin "gopkg.in/alecthomas/kingpin.v2"
|
||||
|
|
@ -33,23 +34,30 @@ func installCommand(dir, jsonnetHome string, uris []string) int {
|
|||
dir = "."
|
||||
}
|
||||
|
||||
kingpin.FatalIfError(
|
||||
os.MkdirAll(filepath.Join(dir, jsonnetHome, ".tmp"), os.ModePerm),
|
||||
"creating vendor folder")
|
||||
|
||||
jsonnetFile, err := jsonnetfile.Load(filepath.Join(dir, jsonnetfile.File))
|
||||
kingpin.FatalIfError(err, "failed to load jsonnetfile")
|
||||
|
||||
for _, u := range uris {
|
||||
d := parseDependency(dir, u)
|
||||
jsonnetFile.Dependencies[d.Name] = *d
|
||||
}
|
||||
|
||||
lockFile, err := jsonnetfile.Load(filepath.Join(dir, jsonnetfile.LockFile))
|
||||
if !os.IsNotExist(err) {
|
||||
kingpin.FatalIfError(err, "failed to load lockfile")
|
||||
}
|
||||
|
||||
kingpin.FatalIfError(
|
||||
os.MkdirAll(filepath.Join(dir, jsonnetHome, ".tmp"), os.ModePerm),
|
||||
"creating vendor folder")
|
||||
|
||||
for _, u := range uris {
|
||||
d := parseDependency(dir, u)
|
||||
|
||||
if !depEqual(jsonnetFile.Dependencies[d.Name], *d) {
|
||||
// the dep passed on the cli is different from the jsonnetFile
|
||||
jsonnetFile.Dependencies[d.Name] = *d
|
||||
|
||||
// we want to install the passed version (ignore the lock)
|
||||
delete(lockFile.Dependencies, d.Name)
|
||||
}
|
||||
}
|
||||
|
||||
locked, err := pkg.Ensure(jsonnetFile, jsonnetHome, lockFile.Dependencies)
|
||||
kingpin.FatalIfError(err, "failed to install packages")
|
||||
|
||||
|
|
@ -63,6 +71,14 @@ func installCommand(dir, jsonnetHome string, uris []string) int {
|
|||
return 0
|
||||
}
|
||||
|
||||
func depEqual(d1, d2 spec.Dependency) bool {
|
||||
name := d1.Name == d2.Name
|
||||
version := d1.Version == d2.Version
|
||||
source := reflect.DeepEqual(d1.Source, d2.Source)
|
||||
|
||||
return name && version && source
|
||||
}
|
||||
|
||||
func writeJSONFile(name string, d interface{}) error {
|
||||
b, err := json.MarshalIndent(d, "", " ")
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ import (
|
|||
"path/filepath"
|
||||
"regexp"
|
||||
|
||||
"github.com/fatih/color"
|
||||
"github.com/pkg/errors"
|
||||
kingpin "gopkg.in/alecthomas/kingpin.v2"
|
||||
|
||||
|
|
@ -54,6 +55,8 @@ func Main() int {
|
|||
JsonnetHome string
|
||||
}{}
|
||||
|
||||
color.Output = color.Error
|
||||
|
||||
a := kingpin.New(filepath.Base(os.Args[0]), "A jsonnet package manager")
|
||||
a.HelpFlag.Short('h')
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue