mirror of
https://github.com/TECHNOFAB11/jsonnet-bundler.git
synced 2025-12-11 23:50:05 +01:00
Merge pull request #99 from jsonnet-bundler/single
feat(install): skip dependencies
This commit is contained in:
commit
ccd60c13eb
6 changed files with 25 additions and 5 deletions
|
|
@ -100,7 +100,7 @@ Commands:
|
|||
init
|
||||
Initialize a new empty jsonnetfile
|
||||
|
||||
install [<uris>...]
|
||||
install [<flags>] [<uris>...]
|
||||
Install new dependencies. Existing ones are silently skipped
|
||||
|
||||
update [<uris>...]
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ import (
|
|||
"github.com/jsonnet-bundler/jsonnet-bundler/spec/v1/deps"
|
||||
)
|
||||
|
||||
func installCommand(dir, jsonnetHome string, uris []string) int {
|
||||
func installCommand(dir, jsonnetHome string, uris []string, single bool) int {
|
||||
if dir == "" {
|
||||
dir = "."
|
||||
}
|
||||
|
|
@ -59,6 +59,10 @@ func installCommand(dir, jsonnetHome string, uris []string) int {
|
|||
kingpin.Fatalf("Unable to parse package URI `%s`", u)
|
||||
}
|
||||
|
||||
if single {
|
||||
d.Single = true
|
||||
}
|
||||
|
||||
if !depEqual(jsonnetFile.Dependencies[d.Name()], *d) {
|
||||
// the dep passed on the cli is different from the jsonnetFile
|
||||
jsonnetFile.Dependencies[d.Name()] = *d
|
||||
|
|
|
|||
|
|
@ -49,6 +49,7 @@ func testInstallCommandWithJsonnetHome(t *testing.T, jsonnetHome string) {
|
|||
ExpectedCode int
|
||||
ExpectedJsonnetFile []byte
|
||||
ExpectedJsonnetLockFile []byte
|
||||
single bool
|
||||
}{
|
||||
{
|
||||
Name: "NoURLs",
|
||||
|
|
@ -69,6 +70,14 @@ func testInstallCommandWithJsonnetHome(t *testing.T, jsonnetHome string) {
|
|||
ExpectedJsonnetFile: []byte(`{"version": 1, "dependencies": [{"source": {"local": {"directory": "jsonnet/foobar"}}, "version": ""}], "legacyImports": true}`),
|
||||
ExpectedJsonnetLockFile: []byte(`{"version": 1, "dependencies": [{"source": {"local": {"directory": "jsonnet/foobar"}}, "version": ""}], "legacyImports": false}`),
|
||||
},
|
||||
{
|
||||
Name: "single",
|
||||
URIs: []string{"github.com/grafana/loki/production/ksonnet/loki@bd4d516262c107a0bde7a962fa2b1e567a2c21e5"},
|
||||
ExpectedCode: 0,
|
||||
ExpectedJsonnetFile: []byte(`{"version":1,"dependencies":[{"source":{"git":{"remote":"https://github.com/grafana/loki","subdir":"production/ksonnet/loki"}},"version":"bd4d516262c107a0bde7a962fa2b1e567a2c21e5","single":true}],"legacyImports":true}`),
|
||||
ExpectedJsonnetLockFile: []byte(`{"version":1,"dependencies":[{"source":{"git":{"remote":"https://github.com/grafana/loki","subdir":"production/ksonnet/loki"}},"version":"bd4d516262c107a0bde7a962fa2b1e567a2c21e5","sum":"ExovUKXmZ4KwJAv/q8ZwNW9BdIZlrxmoGrne7aR64wo=","single":true}],"legacyImports":false}`),
|
||||
single: true,
|
||||
},
|
||||
}
|
||||
|
||||
localDependency := "jsonnet/foobar"
|
||||
|
|
@ -92,7 +101,7 @@ func testInstallCommandWithJsonnetHome(t *testing.T, jsonnetHome string) {
|
|||
jsonnetFileContent(t, jsonnetfile.File, []byte(initContents))
|
||||
|
||||
// install something, check it writes only if required, etc.
|
||||
installCommand("", jsonnetHome, tc.URIs)
|
||||
installCommand("", jsonnetHome, tc.URIs, tc.single)
|
||||
jsonnetFileContent(t, jsonnetfile.File, tc.ExpectedJsonnetFile)
|
||||
if tc.ExpectedJsonnetLockFile != nil {
|
||||
jsonnetFileContent(t, jsonnetfile.LockFile, tc.ExpectedJsonnetLockFile)
|
||||
|
|
|
|||
|
|
@ -54,6 +54,7 @@ func Main() int {
|
|||
|
||||
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()
|
||||
installCmdSingle := installCmd.Flag("single", "install package without dependencies").Short('1').Bool()
|
||||
|
||||
updateCmd := a.Command(updateActionName, "Update all or specific dependencies.")
|
||||
updateCmdURIs := updateCmd.Arg("uris", "URIs to packages to update, URLs or file paths").Strings()
|
||||
|
|
@ -78,13 +79,13 @@ func Main() int {
|
|||
case initCmd.FullCommand():
|
||||
return initCommand(workdir)
|
||||
case installCmd.FullCommand():
|
||||
return installCommand(workdir, cfg.JsonnetHome, *installCmdURIs)
|
||||
return installCommand(workdir, cfg.JsonnetHome, *installCmdURIs, *installCmdSingle)
|
||||
case updateCmd.FullCommand():
|
||||
return updateCommand(workdir, cfg.JsonnetHome, *updateCmdURIs)
|
||||
case rewriteCmd.FullCommand():
|
||||
return rewriteCommand(workdir, cfg.JsonnetHome)
|
||||
default:
|
||||
installCommand(workdir, cfg.JsonnetHome, []string{})
|
||||
installCommand(workdir, cfg.JsonnetHome, []string{}, false)
|
||||
}
|
||||
|
||||
return 0
|
||||
|
|
|
|||
|
|
@ -243,6 +243,11 @@ func ensure(direct map[string]deps.Dependency, vendorDir string, locks map[strin
|
|||
}
|
||||
|
||||
for _, d := range deps {
|
||||
if d.Single {
|
||||
// skip dependencies that explicitely don't want nested ones installed
|
||||
continue
|
||||
}
|
||||
|
||||
f, err := jsonnetfile.Load(filepath.Join(vendorDir, d.Name(), jsonnetfile.File))
|
||||
if err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ type Dependency struct {
|
|||
Source Source `json:"source"`
|
||||
Version string `json:"version"`
|
||||
Sum string `json:"sum,omitempty"`
|
||||
Single bool `json:"single,omitempty"`
|
||||
|
||||
// older schema used to have `name`. We still need that data for
|
||||
// `LegacyName`
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue