mirror of
https://github.com/TECHNOFAB11/jsonnet-bundler.git
synced 2025-12-11 23:50:05 +01:00
feat: update single dependencies
The `update` command now takes dependency URI's like the `install` command. In contrast to `install`, `update` always pulls the latest version.
This commit is contained in:
parent
cd5e2945d2
commit
eeea4677d2
2 changed files with 29 additions and 13 deletions
|
|
@ -52,10 +52,11 @@ func Main() int {
|
||||||
|
|
||||||
initCmd := a.Command(initActionName, "Initialize a new empty jsonnetfile")
|
initCmd := a.Command(initActionName, "Initialize a new empty jsonnetfile")
|
||||||
|
|
||||||
installCmd := a.Command(installActionName, "Install all dependencies or install specific ones")
|
installCmd := a.Command(installActionName, "Install new dependencies. Existing ones are silently skipped")
|
||||||
installCmdURIs := installCmd.Arg("uris", "URIs to packages to install, URLs or file paths").Strings()
|
installCmdURIs := installCmd.Arg("uris", "URIs to packages to install, URLs or file paths").Strings()
|
||||||
|
|
||||||
updateCmd := a.Command(updateActionName, "Update all dependencies.")
|
updateCmd := a.Command(updateActionName, "Update all or specific dependencies.")
|
||||||
|
updateCmdURIs := updateCmd.Arg("uris", "URIs to packages to update, URLs or file paths").Strings()
|
||||||
|
|
||||||
rewriteCmd := a.Command(rewriteActionName, "Automatically rewrite legacy imports to absolute ones")
|
rewriteCmd := a.Command(rewriteActionName, "Automatically rewrite legacy imports to absolute ones")
|
||||||
|
|
||||||
|
|
@ -79,7 +80,7 @@ func Main() int {
|
||||||
case installCmd.FullCommand():
|
case installCmd.FullCommand():
|
||||||
return installCommand(workdir, cfg.JsonnetHome, *installCmdURIs)
|
return installCommand(workdir, cfg.JsonnetHome, *installCmdURIs)
|
||||||
case updateCmd.FullCommand():
|
case updateCmd.FullCommand():
|
||||||
return updateCommand(workdir, cfg.JsonnetHome)
|
return updateCommand(workdir, cfg.JsonnetHome, *updateCmdURIs)
|
||||||
case rewriteCmd.FullCommand():
|
case rewriteCmd.FullCommand():
|
||||||
return rewriteCommand(workdir, cfg.JsonnetHome)
|
return rewriteCommand(workdir, cfg.JsonnetHome)
|
||||||
default:
|
default:
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,6 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"net/url"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
|
|
@ -27,28 +26,44 @@ import (
|
||||||
"github.com/jsonnet-bundler/jsonnet-bundler/spec/v1/deps"
|
"github.com/jsonnet-bundler/jsonnet-bundler/spec/v1/deps"
|
||||||
)
|
)
|
||||||
|
|
||||||
func updateCommand(dir, jsonnetHome string, urls ...*url.URL) int {
|
func updateCommand(dir, jsonnetHome string, uris []string) int {
|
||||||
if dir == "" {
|
if dir == "" {
|
||||||
dir = "."
|
dir = "."
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// load jsonnetfiles
|
||||||
jsonnetFile, err := jsonnetfile.Load(filepath.Join(dir, jsonnetfile.File))
|
jsonnetFile, err := jsonnetfile.Load(filepath.Join(dir, jsonnetfile.File))
|
||||||
kingpin.FatalIfError(err, "failed to load jsonnetfile")
|
kingpin.FatalIfError(err, "failed to load jsonnetfile")
|
||||||
|
|
||||||
|
lockFile, err := jsonnetfile.Load(filepath.Join(dir, jsonnetfile.LockFile))
|
||||||
|
kingpin.FatalIfError(err, "failed to load lockfile")
|
||||||
|
|
||||||
kingpin.FatalIfError(
|
kingpin.FatalIfError(
|
||||||
os.MkdirAll(filepath.Join(dir, jsonnetHome, ".tmp"), os.ModePerm),
|
os.MkdirAll(filepath.Join(dir, jsonnetHome, ".tmp"), os.ModePerm),
|
||||||
"creating vendor folder")
|
"creating vendor folder")
|
||||||
|
|
||||||
// When updating, locks are ignored.
|
locks := lockFile.Dependencies
|
||||||
locks := map[string]deps.Dependency{}
|
|
||||||
locked, err := pkg.Ensure(jsonnetFile, jsonnetHome, locks)
|
for _, u := range uris {
|
||||||
kingpin.FatalIfError(err, "failed to install packages")
|
d := deps.Parse(dir, u)
|
||||||
|
if d == nil {
|
||||||
|
kingpin.Fatalf("Unable to parse package URI `%s`", u)
|
||||||
|
}
|
||||||
|
|
||||||
|
delete(locks, d.Name())
|
||||||
|
}
|
||||||
|
|
||||||
|
// no uris: update all
|
||||||
|
if len(uris) == 0 {
|
||||||
|
locks = make(map[string]deps.Dependency)
|
||||||
|
}
|
||||||
|
|
||||||
|
newLocks, err := pkg.Ensure(jsonnetFile, jsonnetHome, locks)
|
||||||
|
kingpin.FatalIfError(err, "updating")
|
||||||
|
|
||||||
kingpin.FatalIfError(
|
kingpin.FatalIfError(
|
||||||
writeJSONFile(filepath.Join(dir, jsonnetfile.File), jsonnetFile),
|
writeJSONFile(filepath.Join(dir, jsonnetfile.LockFile), v1.JsonnetFile{Dependencies: newLocks}),
|
||||||
"updating jsonnetfile.json")
|
|
||||||
kingpin.FatalIfError(
|
|
||||||
writeJSONFile(filepath.Join(dir, jsonnetfile.LockFile), v1.JsonnetFile{Dependencies: locked}),
|
|
||||||
"updating jsonnetfile.lock.json")
|
"updating jsonnetfile.lock.json")
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue