mirror of
https://github.com/TECHNOFAB11/jsonnet-bundler.git
synced 2025-12-11 23:50:05 +01:00
only write jsonnnet files if we made changes (#56)
Adding a dep, or updating a dependency version makes writes to the jsonnet files. We evaluate the changes on each of the files. An empty jsonnetfile.json does not create a corresponding lockfile, as a missing lockfile is not different from its previous (non existent).
This commit is contained in:
parent
7fc7c31856
commit
f4417ac665
3 changed files with 124 additions and 12 deletions
|
|
@ -33,13 +33,21 @@ var ErrNoFile = errors.New("no jsonnetfile")
|
|||
|
||||
// Load reads a jsonnetfile.(lock).json from disk
|
||||
func Load(filepath string) (spec.JsonnetFile, error) {
|
||||
m := spec.New()
|
||||
|
||||
bytes, err := ioutil.ReadFile(filepath)
|
||||
if err != nil {
|
||||
return m, err
|
||||
return spec.New(), err
|
||||
}
|
||||
|
||||
return Unmarshal(bytes)
|
||||
}
|
||||
|
||||
// Unmarshal creates a spec.JsonnetFile from bytes. Empty bytes
|
||||
// will create an empty spec.
|
||||
func Unmarshal(bytes []byte) (spec.JsonnetFile, error) {
|
||||
m := spec.New()
|
||||
if len(bytes) == 0 {
|
||||
return m, nil
|
||||
}
|
||||
if err := json.Unmarshal(bytes, &m); err != nil {
|
||||
return m, errors.Wrap(err, "failed to unmarshal file")
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue