fix(spec): properly translate v0 into v1

This commit is contained in:
sh0rez 2020-02-28 23:01:26 +01:00
parent f8be6a936f
commit e28e7ff55b
No known key found for this signature in database
GPG key ID: 87C71DF9F8181FF1
4 changed files with 99 additions and 79 deletions

View file

@ -19,6 +19,8 @@ import (
"sort"
)
const Version = 0
// JsonnetFile is the structure of a `.json` file describing a set of jsonnet
// dependencies. It is used for both, the jsonnetFile and the lockFile.
type JsonnetFile struct {

36
spec/v1/v0.go Normal file
View file

@ -0,0 +1,36 @@
package spec
import (
"path/filepath"
v0 "github.com/jsonnet-bundler/jsonnet-bundler/spec/v0"
"github.com/jsonnet-bundler/jsonnet-bundler/spec/v1/deps"
)
func FromV0(mv0 v0.JsonnetFile) (JsonnetFile, error) {
m := New()
m.LegacyImports = true
for name, old := range mv0.Dependencies {
var d deps.Dependency
switch {
case old.Source.GitSource != nil:
d = *deps.Parse("", old.Source.GitSource.Remote)
subdir := filepath.Clean("/" + old.Source.GitSource.Subdir)
d.Source.GitSource.Subdir = subdir
case old.Source.LocalSource != nil:
d = *deps.Parse("", old.Source.LocalSource.Directory)
}
d.Sum = old.Sum
d.Version = old.Version
d.LegacyNameCompat = name
m.Dependencies[d.Name()] = d
}
return m, nil
}