From 30a3cde870578d192a61e53bd37da0a30b4c724e Mon Sep 17 00:00:00 2001 From: Matthias Loibl Date: Mon, 22 Jul 2019 17:32:53 +0200 Subject: [PATCH 01/15] Make use of File and LockFile constants of jsonnetfile package --- cmd/jb/main.go | 9 ++++----- pkg/packages.go | 13 ++++++------- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/cmd/jb/main.go b/cmd/jb/main.go index 4fc0646..e49103a 100644 --- a/cmd/jb/main.go +++ b/cmd/jb/main.go @@ -26,6 +26,7 @@ import ( "regexp" "github.com/jsonnet-bundler/jsonnet-bundler/pkg" + "github.com/jsonnet-bundler/jsonnet-bundler/pkg/jsonnetfile" "github.com/jsonnet-bundler/jsonnet-bundler/spec" "github.com/pkg/errors" "gopkg.in/alecthomas/kingpin.v2" @@ -218,9 +219,7 @@ func parseGithubDependency(urlString string) *spec.Dependency { } func updateCommand(jsonnetHome string, urls ...*url.URL) int { - jsonnetfile := pkg.JsonnetFile - - m, err := pkg.LoadJsonnetfile(jsonnetfile) + m, err := pkg.LoadJsonnetfile(jsonnetfile.File) if err != nil { kingpin.Fatalf("failed to load jsonnetfile: %v", err) return 1 @@ -234,7 +233,7 @@ func updateCommand(jsonnetHome string, urls ...*url.URL) int { // When updating, the lockfile is explicitly ignored. isLock := false - lock, err := pkg.Install(context.TODO(), isLock, jsonnetfile, m, jsonnetHome) + lock, err := pkg.Install(context.TODO(), isLock, jsonnetfile.File, m, jsonnetHome) if err != nil { kingpin.Fatalf("failed to install: %v", err) return 3 @@ -247,7 +246,7 @@ func updateCommand(jsonnetHome string, urls ...*url.URL) int { } b = append(b, []byte("\n")...) - err = ioutil.WriteFile(pkg.JsonnetLockFile, b, 0644) + err = ioutil.WriteFile(jsonnetfile.LockFile, b, 0644) if err != nil { kingpin.Fatalf("failed to write lock file: %v", err) return 3 diff --git a/pkg/packages.go b/pkg/packages.go index a847298..d5afaa7 100644 --- a/pkg/packages.go +++ b/pkg/packages.go @@ -24,13 +24,12 @@ import ( "path/filepath" "github.com/fatih/color" + "github.com/jsonnet-bundler/jsonnet-bundler/pkg/jsonnetfile" "github.com/jsonnet-bundler/jsonnet-bundler/spec" "github.com/pkg/errors" ) var ( - JsonnetFile = "jsonnetfile.json" - JsonnetLockFile = "jsonnetfile.lock.json" VersionMismatch = errors.New("multiple colliding versions specified") ) @@ -161,18 +160,18 @@ func FileExists(path string) (bool, error) { } func ChooseJsonnetFile(dir string) (string, bool, error) { - lockfile := path.Join(dir, JsonnetLockFile) - jsonnetfile := path.Join(dir, JsonnetFile) - filename := lockfile + lockfilePath := path.Join(dir, jsonnetfile.LockFile) + jsonnetfilePath := path.Join(dir, jsonnetfile.File) + filename := lockfilePath isLock := true - lockExists, err := FileExists(filepath.Join(dir, JsonnetLockFile)) + lockExists, err := FileExists(filepath.Join(dir, jsonnetfile.LockFile)) if err != nil { return "", false, err } if !lockExists { - filename = jsonnetfile + filename = jsonnetfilePath isLock = false } From 53ca56c221be58a657a4173296f33be9eaa1f9e8 Mon Sep 17 00:00:00 2001 From: Matthias Loibl Date: Mon, 22 Jul 2019 17:34:58 +0200 Subject: [PATCH 02/15] Separate update command into own file cmd/jb/update.go --- cmd/jb/main.go | 43 -------------------------------- cmd/jb/update.go | 64 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+), 43 deletions(-) create mode 100644 cmd/jb/update.go diff --git a/cmd/jb/main.go b/cmd/jb/main.go index e49103a..76e0016 100644 --- a/cmd/jb/main.go +++ b/cmd/jb/main.go @@ -15,18 +15,12 @@ package main import ( - "context" - "encoding/json" "fmt" - "io/ioutil" - "net/url" "os" "path" "path/filepath" "regexp" - "github.com/jsonnet-bundler/jsonnet-bundler/pkg" - "github.com/jsonnet-bundler/jsonnet-bundler/pkg/jsonnetfile" "github.com/jsonnet-bundler/jsonnet-bundler/spec" "github.com/pkg/errors" "gopkg.in/alecthomas/kingpin.v2" @@ -217,40 +211,3 @@ func parseGithubDependency(urlString string) *spec.Dependency { Version: version, } } - -func updateCommand(jsonnetHome string, urls ...*url.URL) int { - m, err := pkg.LoadJsonnetfile(jsonnetfile.File) - if err != nil { - kingpin.Fatalf("failed to load jsonnetfile: %v", err) - return 1 - } - - err = os.MkdirAll(jsonnetHome, os.ModePerm) - if err != nil { - kingpin.Fatalf("failed to create jsonnet home path: %v", err) - return 3 - } - - // When updating, the lockfile is explicitly ignored. - isLock := false - lock, err := pkg.Install(context.TODO(), isLock, jsonnetfile.File, m, jsonnetHome) - if err != nil { - kingpin.Fatalf("failed to install: %v", err) - return 3 - } - - b, err := json.MarshalIndent(lock, "", " ") - if err != nil { - kingpin.Fatalf("failed to encode jsonnet file: %v", err) - return 3 - } - b = append(b, []byte("\n")...) - - err = ioutil.WriteFile(jsonnetfile.LockFile, b, 0644) - if err != nil { - kingpin.Fatalf("failed to write lock file: %v", err) - return 3 - } - - return 0 -} diff --git a/cmd/jb/update.go b/cmd/jb/update.go new file mode 100644 index 0000000..9496d31 --- /dev/null +++ b/cmd/jb/update.go @@ -0,0 +1,64 @@ +// Copyright 2018 jsonnet-bundler authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package main + +import ( + "context" + "encoding/json" + "io/ioutil" + "net/url" + "os" + + "github.com/jsonnet-bundler/jsonnet-bundler/pkg" + "github.com/jsonnet-bundler/jsonnet-bundler/pkg/jsonnetfile" + "gopkg.in/alecthomas/kingpin.v2" +) + +func updateCommand(jsonnetHome string, urls ...*url.URL) int { + m, err := pkg.LoadJsonnetfile(jsonnetfile.File) + if err != nil { + kingpin.Fatalf("failed to load jsonnetfile: %v", err) + return 1 + } + + err = os.MkdirAll(jsonnetHome, os.ModePerm) + if err != nil { + kingpin.Fatalf("failed to create jsonnet home path: %v", err) + return 3 + } + + // When updating, the lockfile is explicitly ignored. + isLock := false + lock, err := pkg.Install(context.TODO(), isLock, jsonnetfile.File, m, jsonnetHome) + if err != nil { + kingpin.Fatalf("failed to install: %v", err) + return 3 + } + + b, err := json.MarshalIndent(lock, "", " ") + if err != nil { + kingpin.Fatalf("failed to encode jsonnet file: %v", err) + return 3 + } + b = append(b, []byte("\n")...) + + err = ioutil.WriteFile(jsonnetfile.LockFile, b, 0644) + if err != nil { + kingpin.Fatalf("failed to write lock file: %v", err) + return 3 + } + + return 0 +} From 3e8535793493b49a1bf57c0beab4c3b7d2e525b9 Mon Sep 17 00:00:00 2001 From: Matthias Loibl Date: Mon, 22 Jul 2019 18:03:27 +0200 Subject: [PATCH 03/15] Actually run go test on packages --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index c59e8a8..451331a 100644 --- a/Makefile +++ b/Makefile @@ -28,7 +28,7 @@ install: build test: @echo ">> running all unit tests" - @go test $(PKGS) + go test -v $(PKGS) test-integration: @echo ">> running all integration tests" From 9110b1417dc64ecbfe51e07c2545d031189483d0 Mon Sep 17 00:00:00 2001 From: Matthias Loibl Date: Mon, 22 Jul 2019 18:04:24 +0200 Subject: [PATCH 04/15] Accept paths instead of URLs --- cmd/jb/install.go | 12 +++++------- cmd/jb/install_test.go | 3 +-- cmd/jb/main.go | 4 ++-- pkg/packages_test.go | 5 +++-- 4 files changed, 11 insertions(+), 13 deletions(-) diff --git a/cmd/jb/install.go b/cmd/jb/install.go index db2c42b..d5a135d 100644 --- a/cmd/jb/install.go +++ b/cmd/jb/install.go @@ -18,7 +18,6 @@ import ( "context" "encoding/json" "io/ioutil" - "net/url" "os" "path/filepath" @@ -28,7 +27,7 @@ import ( "gopkg.in/alecthomas/kingpin.v2" ) -func installCommand(dir, jsonnetHome string, urls ...*url.URL) int { +func installCommand(dir, jsonnetHome string, paths ...string) int { if dir == "" { dir = "." } @@ -45,8 +44,8 @@ func installCommand(dir, jsonnetHome string, urls ...*url.URL) int { return 1 } - if len(urls) > 0 { - for _, url := range urls { + if len(paths) > 0 { + for _, path := range paths { // install package specified in command // $ jsonnetpkg install ksonnet git@github.com:ksonnet/ksonnet-lib // $ jsonnetpkg install grafonnet git@github.com:grafana/grafonnet-lib grafonnet @@ -54,10 +53,9 @@ func installCommand(dir, jsonnetHome string, urls ...*url.URL) int { // // github.com/(slug)/(dir) - urlString := url.String() - newDep := parseDepedency(urlString) + newDep := parseDepedency(path) if newDep == nil { - kingpin.Errorf("ignoring unrecognized url: %s", url) + kingpin.Errorf("ignoring unrecognized path: %s", path) continue } diff --git a/cmd/jb/install_test.go b/cmd/jb/install_test.go index 9de6b69..4ef2918 100644 --- a/cmd/jb/install_test.go +++ b/cmd/jb/install_test.go @@ -18,7 +18,6 @@ package main import ( "io/ioutil" - "net/url" "os" "path/filepath" "testing" @@ -30,7 +29,7 @@ import ( func TestInstallCommand(t *testing.T) { testcases := []struct { Name string - URLs []*url.URL + URLs []string ExpectedCode int ExpectedJsonnetFile []byte ExpectedJsonnetLockFile []byte diff --git a/cmd/jb/main.go b/cmd/jb/main.go index 76e0016..942b409 100644 --- a/cmd/jb/main.go +++ b/cmd/jb/main.go @@ -68,7 +68,7 @@ func Main() int { initCmd := a.Command(initActionName, "Initialize a new empty jsonnetfile") installCmd := a.Command(installActionName, "Install all dependencies or install specific ones") - installCmdURLs := installCmd.Arg("packages", "URLs to package to install").URLList() + installCmdPaths := installCmd.Arg("paths", "paths to packages to install, URLs or file paths").Strings() updateCmd := a.Command(updateActionName, "Update all dependencies.") @@ -88,7 +88,7 @@ func Main() int { case initCmd.FullCommand(): return initCommand(workdir) case installCmd.FullCommand(): - return installCommand(workdir, cfg.JsonnetHome, *installCmdURLs...) + return installCommand(workdir, cfg.JsonnetHome, *installCmdPaths...) case updateCmd.FullCommand(): return updateCommand(cfg.JsonnetHome) default: diff --git a/pkg/packages_test.go b/pkg/packages_test.go index 729ab73..3316c02 100644 --- a/pkg/packages_test.go +++ b/pkg/packages_test.go @@ -20,6 +20,7 @@ import ( "path/filepath" "testing" + "github.com/jsonnet-bundler/jsonnet-bundler/pkg/jsonnetfile" "github.com/jsonnet-bundler/jsonnet-bundler/spec" "github.com/stretchr/testify/assert" ) @@ -110,7 +111,7 @@ func TestLoadJsonnetfile(t *testing.T) { assert.Nil(t, err) }() - tempFile := filepath.Join(tempDir, JsonnetFile) + tempFile := filepath.Join(tempDir, jsonnetfile.File) err = ioutil.WriteFile(tempFile, []byte(`{}`), os.ModePerm) assert.Nil(t, err) @@ -128,7 +129,7 @@ func TestLoadJsonnetfile(t *testing.T) { assert.Nil(t, err) }() - tempFile := filepath.Join(tempDir, JsonnetFile) + tempFile := filepath.Join(tempDir, jsonnetfile.File) err = ioutil.WriteFile(tempFile, []byte(jsonnetfileContent), os.ModePerm) assert.Nil(t, err) From 95226f7f9bc3a17f7b969f61f4d8aa532842ef81 Mon Sep 17 00:00:00 2001 From: Matthias Loibl Date: Mon, 22 Jul 2019 18:12:40 +0200 Subject: [PATCH 05/15] Sort spec types by dependencies --- spec/spec.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/spec/spec.go b/spec/spec.go index 5f10ea8..657571e 100644 --- a/spec/spec.go +++ b/spec/spec.go @@ -18,6 +18,13 @@ type JsonnetFile struct { Dependencies []Dependency `json:"dependencies"` } +type Dependency struct { + Name string `json:"name"` + Source Source `json:"source"` + Version string `json:"version"` + DepSource string `json:"-"` +} + type Source struct { GitSource *GitSource `json:"git"` } @@ -26,10 +33,3 @@ type GitSource struct { Remote string `json:"remote"` Subdir string `json:"subdir"` } - -type Dependency struct { - Name string `json:"name"` - Source Source `json:"source"` - Version string `json:"version"` - DepSource string `json:"-"` -} From 463046600654c0c13a75eb02b15731ce2515ad22 Mon Sep 17 00:00:00 2001 From: Matthias Loibl Date: Mon, 22 Jul 2019 18:37:16 +0200 Subject: [PATCH 06/15] Fix typo in parseDependency name and add tests --- cmd/jb/install.go | 9 +---- cmd/jb/main.go | 2 +- cmd/jb/main_test.go | 80 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 82 insertions(+), 9 deletions(-) create mode 100644 cmd/jb/main_test.go diff --git a/cmd/jb/install.go b/cmd/jb/install.go index d5a135d..c3b22b1 100644 --- a/cmd/jb/install.go +++ b/cmd/jb/install.go @@ -46,14 +46,7 @@ func installCommand(dir, jsonnetHome string, paths ...string) int { if len(paths) > 0 { for _, path := range paths { - // install package specified in command - // $ jsonnetpkg install ksonnet git@github.com:ksonnet/ksonnet-lib - // $ jsonnetpkg install grafonnet git@github.com:grafana/grafonnet-lib grafonnet - // $ jsonnetpkg install github.com/grafana/grafonnet-lib/grafonnet - // - // github.com/(slug)/(dir) - - newDep := parseDepedency(path) + newDep := parseDependency(path) if newDep == nil { kingpin.Errorf("ignoring unrecognized path: %s", path) continue diff --git a/cmd/jb/main.go b/cmd/jb/main.go index 942b409..4005e5d 100644 --- a/cmd/jb/main.go +++ b/cmd/jb/main.go @@ -98,7 +98,7 @@ func Main() int { return 0 } -func parseDepedency(urlString string) *spec.Dependency { +func parseDependency(urlString string) *spec.Dependency { if spec := parseGitSSHDependency(urlString); spec != nil { return spec } diff --git a/cmd/jb/main_test.go b/cmd/jb/main_test.go new file mode 100644 index 0000000..6a83584 --- /dev/null +++ b/cmd/jb/main_test.go @@ -0,0 +1,80 @@ +// Copyright 2018 jsonnet-bundler authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package main + +import ( + "testing" + + "github.com/jsonnet-bundler/jsonnet-bundler/spec" + "github.com/stretchr/testify/assert" +) + +func TestParseDepedency(t *testing.T) { + tests := []struct { + name string + path string + want *spec.Dependency + }{ + { + name: "Empty", + path: "", + want: nil, + }, + { + name: "Invalid", + path: "github.com/foo", + want: nil, + }, + { + name: "GitHub", + path: "github.com/jsonnet-bundler/jsonnet-bundler", + want: &spec.Dependency{ + Name: "jsonnet-bundler", + Source: spec.Source{ + GitSource: &spec.GitSource{ + Remote: "https://github.com/jsonnet-bundler/jsonnet-bundler", + Subdir: "", + }, + }, + Version: "master", + }, + }, + { + name: "SSH", + path: "git+ssh://git@github.com:jsonnet-bundler/jsonnet-bundler.git", + want: &spec.Dependency{ + Name: "jsonnet-bundler", + Source: spec.Source{ + GitSource: &spec.GitSource{ + Remote: "git@github.com:jsonnet-bundler/jsonnet-bundler", + Subdir: "", + }, + }, + Version: "master", + }, + }, + } + for _, tt := range tests { + _ = t.Run(tt.name, func(t *testing.T) { + dependency := parseDependency(tt.path) + + if tt.path == "" { + assert.Nil(t, dependency) + } else { + assert.Equal(t, tt.want, dependency) + } + }) + } +} From e5199342eaae9b437045cb85e63fa55c820a221d Mon Sep 17 00:00:00 2001 From: Matthias Loibl Date: Mon, 22 Jul 2019 19:33:44 +0200 Subject: [PATCH 07/15] Remove unused code in main.go --- cmd/jb/main.go | 6 ------ 1 file changed, 6 deletions(-) diff --git a/cmd/jb/main.go b/cmd/jb/main.go index 4005e5d..aee2b1b 100644 --- a/cmd/jb/main.go +++ b/cmd/jb/main.go @@ -30,15 +30,9 @@ const ( installActionName = "install" updateActionName = "update" initActionName = "init" - basePath = ".jsonnetpkg" - srcDirName = "src" ) var ( - availableSubcommands = []string{ - initActionName, - installActionName, - } gitSSHRegex = regexp.MustCompile("git\\+ssh://git@([^:]+):([^/]+)/([^/]+).git") gitSSHWithVersionRegex = regexp.MustCompile("git\\+ssh://git@([^:]+):([^/]+)/([^/]+).git@(.*)") gitSSHWithPathRegex = regexp.MustCompile("git\\+ssh://git@([^:]+):([^/]+)/([^/]+).git/(.*)") From 6ee790d911a7f9b8137c4e310e1ef3df718fbe31 Mon Sep 17 00:00:00 2001 From: Matthias Loibl Date: Mon, 22 Jul 2019 19:42:43 +0200 Subject: [PATCH 08/15] Add ability to parse local dependency --- cmd/jb/main.go | 87 +++++++++++++++++++++++++++++++++------------ cmd/jb/main_test.go | 22 ++++++++++++ 2 files changed, 86 insertions(+), 23 deletions(-) diff --git a/cmd/jb/main.go b/cmd/jb/main.go index aee2b1b..74f727d 100644 --- a/cmd/jb/main.go +++ b/cmd/jb/main.go @@ -20,6 +20,7 @@ import ( "path" "path/filepath" "regexp" + "strings" "github.com/jsonnet-bundler/jsonnet-bundler/spec" "github.com/pkg/errors" @@ -92,20 +93,24 @@ func Main() int { return 0 } -func parseDependency(urlString string) *spec.Dependency { - if spec := parseGitSSHDependency(urlString); spec != nil { - return spec +func parseDependency(path string) *spec.Dependency { + if d := parseGitSSHDependency(path); d != nil { + return d } - if spec := parseGithubDependency(urlString); spec != nil { - return spec + if d := parseGithubDependency(path); d != nil { + return d + } + + if d := parseLocalDependency(path); d != nil { + return d } return nil } -func parseGitSSHDependency(urlString string) *spec.Dependency { - if !gitSSHRegex.MatchString(urlString) { +func parseGitSSHDependency(p string) *spec.Dependency { + if !gitSSHRegex.MatchString(p) { return nil } @@ -115,27 +120,27 @@ func parseGitSSHDependency(urlString string) *spec.Dependency { repo := "" version := "master" - if gitSSHWithPathAndVersionRegex.MatchString(urlString) { - matches := gitSSHWithPathAndVersionRegex.FindStringSubmatch(urlString) + if gitSSHWithPathAndVersionRegex.MatchString(p) { + matches := gitSSHWithPathAndVersionRegex.FindStringSubmatch(p) host = matches[1] org = matches[2] repo = matches[3] subdir = matches[4] version = matches[5] - } else if gitSSHWithPathRegex.MatchString(urlString) { - matches := gitSSHWithPathRegex.FindStringSubmatch(urlString) + } else if gitSSHWithPathRegex.MatchString(p) { + matches := gitSSHWithPathRegex.FindStringSubmatch(p) host = matches[1] org = matches[2] repo = matches[3] subdir = matches[4] - } else if gitSSHWithVersionRegex.MatchString(urlString) { - matches := gitSSHWithVersionRegex.FindStringSubmatch(urlString) + } else if gitSSHWithVersionRegex.MatchString(p) { + matches := gitSSHWithVersionRegex.FindStringSubmatch(p) host = matches[1] org = matches[2] repo = matches[3] version = matches[4] } else { - matches := gitSSHRegex.FindStringSubmatch(urlString) + matches := gitSSHRegex.FindStringSubmatch(p) host = matches[1] org = matches[2] repo = matches[3] @@ -153,8 +158,8 @@ func parseGitSSHDependency(urlString string) *spec.Dependency { } } -func parseGithubDependency(urlString string) *spec.Dependency { - if !githubSlugRegex.MatchString(urlString) { +func parseGithubDependency(p string) *spec.Dependency { + if !githubSlugRegex.MatchString(p) { return nil } @@ -164,30 +169,30 @@ func parseGithubDependency(urlString string) *spec.Dependency { subdir := "" version := "master" - if githubSlugWithPathRegex.MatchString(urlString) { - if githubSlugWithPathAndVersionRegex.MatchString(urlString) { - matches := githubSlugWithPathAndVersionRegex.FindStringSubmatch(urlString) + if githubSlugWithPathRegex.MatchString(p) { + if githubSlugWithPathAndVersionRegex.MatchString(p) { + matches := githubSlugWithPathAndVersionRegex.FindStringSubmatch(p) user = matches[1] repo = matches[2] subdir = matches[3] version = matches[4] name = path.Base(subdir) } else { - matches := githubSlugWithPathRegex.FindStringSubmatch(urlString) + matches := githubSlugWithPathRegex.FindStringSubmatch(p) user = matches[1] repo = matches[2] subdir = matches[3] name = path.Base(subdir) } } else { - if githubSlugWithVersionRegex.MatchString(urlString) { - matches := githubSlugWithVersionRegex.FindStringSubmatch(urlString) + if githubSlugWithVersionRegex.MatchString(p) { + matches := githubSlugWithVersionRegex.FindStringSubmatch(p) user = matches[1] repo = matches[2] name = repo version = matches[3] } else { - matches := githubSlugRegex.FindStringSubmatch(urlString) + matches := githubSlugRegex.FindStringSubmatch(p) user = matches[1] repo = matches[2] name = repo @@ -205,3 +210,39 @@ func parseGithubDependency(urlString string) *spec.Dependency { Version: version, } } + +func parseLocalDependency(p string) *spec.Dependency { + if p == "" { + return nil + } + if strings.HasPrefix(p, "github.com") { + return nil + } + if strings.HasPrefix(p, "git+ssh") { + return nil + } + + clean := filepath.Clean(p) + + info, err := os.Stat(clean) + if err != nil { + wd, _ := os.Getwd() + fmt.Println(err, wd) + return nil + } + + if !info.IsDir() { + return nil + } + + return &spec.Dependency{ + Name: info.Name(), + Source: spec.Source{ + GitSource: &spec.GitSource{ + Remote: ".", + Subdir: clean, + }, + }, + Version: ".", + } +} diff --git a/cmd/jb/main_test.go b/cmd/jb/main_test.go index 6a83584..ee85eac 100644 --- a/cmd/jb/main_test.go +++ b/cmd/jb/main_test.go @@ -15,6 +15,7 @@ package main import ( + "os" "testing" "github.com/jsonnet-bundler/jsonnet-bundler/spec" @@ -22,6 +23,13 @@ import ( ) func TestParseDepedency(t *testing.T) { + const testFolder = "test/jsonnet/foobar" + err := os.MkdirAll(testFolder, os.ModePerm) + if err != nil { + t.Fatal(err) + } + defer os.RemoveAll("test") + tests := []struct { name string path string @@ -65,6 +73,20 @@ func TestParseDepedency(t *testing.T) { Version: "master", }, }, + { + name: "local", + path: testFolder, + want: &spec.Dependency{ + Name: "foobar", + Source: spec.Source{ + GitSource: &spec.GitSource{ + Remote: ".", + Subdir: "test/jsonnet/foobar", + }, + }, + Version: ".", + }, + }, } for _, tt := range tests { _ = t.Run(tt.name, func(t *testing.T) { From 07801936c0228fc583ba8ea129a645f2660280af Mon Sep 17 00:00:00 2001 From: Matthias Loibl Date: Tue, 23 Jul 2019 13:28:58 -0700 Subject: [PATCH 09/15] Create LocalSource as type for local dependencies --- cmd/jb/install_test.go | 22 ++++++++++++---------- cmd/jb/main.go | 9 +++------ cmd/jb/main_test.go | 9 ++++----- pkg/local.go | 42 ++++++++++++++++++++++++++++++++++++++++++ pkg/packages.go | 5 ++++- spec/spec.go | 7 ++++++- 6 files changed, 71 insertions(+), 23 deletions(-) create mode 100644 pkg/local.go diff --git a/cmd/jb/install_test.go b/cmd/jb/install_test.go index 4ef2918..3c06d64 100644 --- a/cmd/jb/install_test.go +++ b/cmd/jb/install_test.go @@ -40,26 +40,28 @@ func TestInstallCommand(t *testing.T) { ExpectedJsonnetFile: []byte(`{"dependencies":null}`), ExpectedJsonnetLockFile: []byte(`{"dependencies":null}`), }, { - Name: "OneURL", - URLs: []*url.URL{ - { - Scheme: "https", - Host: "github.com", - Path: "jsonnet-bundler/jsonnet-bundler@v0.1.0", - }, - }, + Name: "OneURL", + URLs: []string{"github.com/jsonnet-bundler/jsonnet-bundler@v0.1.0"}, ExpectedCode: 0, ExpectedJsonnetFile: []byte(`{"dependencies": [{"name": "jsonnet-bundler", "source": {"git": {"remote": "https://github.com/jsonnet-bundler/jsonnet-bundler", "subdir": ""}}, "version": "v0.1.0"}]}`), ExpectedJsonnetLockFile: []byte(`{"dependencies": [{"name": "jsonnet-bundler", "source": {"git": {"remote": "https://github.com/jsonnet-bundler/jsonnet-bundler", "subdir": ""}}, "version": "080f157c7fb85ad0281ea78f6c641eaa570a582f"}]}`), + }, { + Name: "Relative", + URLs: []string{"test/jsonnet/foobar"}, + ExpectedCode: 0, + ExpectedJsonnetFile: []byte(`{"dependencies":null}`), + ExpectedJsonnetLockFile: []byte(`{"dependencies":null}`), }, } for _, tc := range testcases { - t.Run(tc.Name, func(t *testing.T) { + _ = t.Run(tc.Name, func(t *testing.T) { tempDir, err := ioutil.TempDir("", "jb-install") assert.NoError(t, err) + err = os.MkdirAll(filepath.Join(tempDir, "test/jsonnet/foobar"), os.ModePerm) + assert.NoError(t, err) defer os.Remove(tempDir) - defer os.RemoveAll("vendor") // delete test vendor folder + defer os.RemoveAll("vendor") // cloning jsonnet-bundler will create this folder jsonnetFile := filepath.Join(tempDir, jsonnetfile.File) jsonnetLockFile := filepath.Join(tempDir, jsonnetfile.LockFile) diff --git a/cmd/jb/main.go b/cmd/jb/main.go index 74f727d..f7137f1 100644 --- a/cmd/jb/main.go +++ b/cmd/jb/main.go @@ -226,8 +226,6 @@ func parseLocalDependency(p string) *spec.Dependency { info, err := os.Stat(clean) if err != nil { - wd, _ := os.Getwd() - fmt.Println(err, wd) return nil } @@ -238,11 +236,10 @@ func parseLocalDependency(p string) *spec.Dependency { return &spec.Dependency{ Name: info.Name(), Source: spec.Source{ - GitSource: &spec.GitSource{ - Remote: ".", - Subdir: clean, + LocalSource: &spec.LocalSource{ + Directory: clean, }, }, - Version: ".", + Version: "", } } diff --git a/cmd/jb/main_test.go b/cmd/jb/main_test.go index ee85eac..594264f 100644 --- a/cmd/jb/main_test.go +++ b/cmd/jb/main_test.go @@ -22,7 +22,7 @@ import ( "github.com/stretchr/testify/assert" ) -func TestParseDepedency(t *testing.T) { +func TestParseDependency(t *testing.T) { const testFolder = "test/jsonnet/foobar" err := os.MkdirAll(testFolder, os.ModePerm) if err != nil { @@ -79,12 +79,11 @@ func TestParseDepedency(t *testing.T) { want: &spec.Dependency{ Name: "foobar", Source: spec.Source{ - GitSource: &spec.GitSource{ - Remote: ".", - Subdir: "test/jsonnet/foobar", + LocalSource: &spec.LocalSource{ + Directory: "test/jsonnet/foobar", }, }, - Version: ".", + Version: "", }, }, } diff --git a/pkg/local.go b/pkg/local.go new file mode 100644 index 0000000..d3aedbc --- /dev/null +++ b/pkg/local.go @@ -0,0 +1,42 @@ +// Copyright 2018 jsonnet-bundler authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package pkg + +import ( + "context" + "fmt" + + "github.com/jsonnet-bundler/jsonnet-bundler/spec" +) + +type LocalPackage struct { + Source *spec.LocalSource +} + +func NewLocalPackage(source *spec.LocalSource) Interface { + return &LocalPackage{ + Source: source, + } +} + +func (p *LocalPackage) Install(ctx context.Context, dir, version string) (lockVersion string, err error) { + fmt.Println("SYMLINK THIS SHIT, HAHA") + + // TODO: Where do I get the name of the package? + + fmt.Println(ctx, dir, version) + + return "", nil +} diff --git a/pkg/packages.go b/pkg/packages.go index d5afaa7..3c7a70a 100644 --- a/pkg/packages.go +++ b/pkg/packages.go @@ -54,6 +54,9 @@ func Install(ctx context.Context, isLock bool, dependencySourceIdentifier string p = NewGitPackage(dep.Source.GitSource) subdir = dep.Source.GitSource.Subdir } + if dep.Source.LocalSource != nil { + p = NewLocalPackage(dep.Source.LocalSource) + } lockVersion, err := p.Install(ctx, tmpDir, dep.Version) if err != nil { @@ -100,7 +103,7 @@ func Install(ctx context.Context, isLock bool, dependencySourceIdentifier string return nil, err } depsDeps, err := LoadJsonnetfile(filepath) - // It is ok for depedencies not to have a JsonnetFile, it just means + // It is ok for dependencies not to have a JsonnetFile, it just means // they do not have transitive dependencies of their own. if err != nil && !os.IsNotExist(err) { return nil, err diff --git a/spec/spec.go b/spec/spec.go index 657571e..0eafee9 100644 --- a/spec/spec.go +++ b/spec/spec.go @@ -26,10 +26,15 @@ type Dependency struct { } type Source struct { - GitSource *GitSource `json:"git"` + GitSource *GitSource `json:"git,omitempty"` + LocalSource *LocalSource `json:"local,omitempty"` } type GitSource struct { Remote string `json:"remote"` Subdir string `json:"subdir"` } + +type LocalSource struct { + Directory string `json:"directory"` +} From e4dcc3e11612af36308ee32cf90d891e36924c66 Mon Sep 17 00:00:00 2001 From: Matthias Loibl Date: Tue, 23 Jul 2019 15:07:35 -0700 Subject: [PATCH 10/15] Refactor git deps install and make local deps install work --- pkg/git.go | 37 ++++++++++++++++++++++++++++++++----- pkg/interface.go | 2 +- pkg/local.go | 16 +++++++++++----- pkg/packages.go | 24 +----------------------- 4 files changed, 45 insertions(+), 34 deletions(-) diff --git a/pkg/git.go b/pkg/git.go index d2cd6f3..8af4a00 100644 --- a/pkg/git.go +++ b/pkg/git.go @@ -17,12 +17,16 @@ package pkg import ( "bytes" "context" + "fmt" + "io/ioutil" "os" "os/exec" "path" + "path/filepath" "strings" "github.com/jsonnet-bundler/jsonnet-bundler/spec" + "github.com/pkg/errors" ) type GitPackage struct { @@ -35,8 +39,16 @@ func NewGitPackage(source *spec.GitSource) Interface { } } -func (p *GitPackage) Install(ctx context.Context, dir, version string) (lockVersion string, err error) { - cmd := exec.CommandContext(ctx, "git", "clone", p.Source.Remote, dir) +func (p *GitPackage) Install(ctx context.Context, name, dir, version string) (string, error) { + destPath := path.Join(dir, name) + + tmpDir, err := ioutil.TempDir(filepath.Join(dir, ".tmp"), fmt.Sprintf("jsonnetpkg-%s-%s", name, version)) + if err != nil { + return "", errors.Wrap(err, "failed to create tmp dir") + } + defer os.RemoveAll(tmpDir) + + cmd := exec.CommandContext(ctx, "git", "clone", p.Source.Remote, tmpDir) cmd.Stdin = os.Stdin cmd.Stdout = os.Stdout cmd.Stderr = os.Stderr @@ -49,7 +61,7 @@ func (p *GitPackage) Install(ctx context.Context, dir, version string) (lockVers cmd.Stdin = os.Stdin cmd.Stdout = os.Stdout cmd.Stderr = os.Stderr - cmd.Dir = dir + cmd.Dir = tmpDir err = cmd.Run() if err != nil { return "", err @@ -58,7 +70,7 @@ func (p *GitPackage) Install(ctx context.Context, dir, version string) (lockVers b := bytes.NewBuffer(nil) cmd = exec.CommandContext(ctx, "git", "rev-parse", "HEAD") cmd.Stdout = b - cmd.Dir = dir + cmd.Dir = tmpDir err = cmd.Run() if err != nil { return "", err @@ -66,10 +78,25 @@ func (p *GitPackage) Install(ctx context.Context, dir, version string) (lockVers commitHash := strings.TrimSpace(b.String()) - err = os.RemoveAll(path.Join(dir, ".git")) + err = os.RemoveAll(path.Join(tmpDir, ".git")) if err != nil { return "", err } + err = os.MkdirAll(path.Dir(destPath), os.ModePerm) + if err != nil { + return "", errors.Wrap(err, "failed to create parent path") + } + + err = os.RemoveAll(destPath) + if err != nil { + return "", errors.Wrap(err, "failed to clean previous destination path") + } + + err = os.Rename(path.Join(tmpDir, p.Source.Subdir), destPath) + if err != nil { + return "", errors.Wrap(err, "failed to move package") + } + return commitHash, nil } diff --git a/pkg/interface.go b/pkg/interface.go index 79384af..a93911c 100644 --- a/pkg/interface.go +++ b/pkg/interface.go @@ -19,5 +19,5 @@ import ( ) type Interface interface { - Install(ctx context.Context, dir, version string) (lockVersion string, err error) + Install(ctx context.Context, name, dir, version string) (lockVersion string, err error) } diff --git a/pkg/local.go b/pkg/local.go index d3aedbc..06c2dd1 100644 --- a/pkg/local.go +++ b/pkg/local.go @@ -17,6 +17,8 @@ package pkg import ( "context" "fmt" + "os" + "path/filepath" "github.com/jsonnet-bundler/jsonnet-bundler/spec" ) @@ -31,12 +33,16 @@ func NewLocalPackage(source *spec.LocalSource) Interface { } } -func (p *LocalPackage) Install(ctx context.Context, dir, version string) (lockVersion string, err error) { - fmt.Println("SYMLINK THIS SHIT, HAHA") +func (p *LocalPackage) Install(ctx context.Context, name, dir, version string) (lockVersion string, err error) { + wd, err := os.Getwd() + if err != nil { + return "", fmt.Errorf("failed to get current working directory: %v", err) + } - // TODO: Where do I get the name of the package? - - fmt.Println(ctx, dir, version) + err = os.Symlink(filepath.Join(wd, p.Source.Directory), filepath.Join(wd, dir, name)) + if err != nil { + return "", fmt.Errorf("failed to create symlink for local dependency: %v", err) + } return "", nil } diff --git a/pkg/packages.go b/pkg/packages.go index 3c7a70a..a5b1494 100644 --- a/pkg/packages.go +++ b/pkg/packages.go @@ -18,7 +18,6 @@ import ( "context" "encoding/json" "fmt" - "io/ioutil" "os" "path" "path/filepath" @@ -42,23 +41,16 @@ func Install(ctx context.Context, isLock bool, dependencySourceIdentifier string if err != nil { return nil, errors.Wrap(err, "failed to create general tmp dir") } - tmpDir, err := ioutil.TempDir(tmp, fmt.Sprintf("jsonnetpkg-%s-%s", dep.Name, dep.Version)) - if err != nil { - return nil, errors.Wrap(err, "failed to create tmp dir") - } - defer os.RemoveAll(tmpDir) - subdir := "" var p Interface if dep.Source.GitSource != nil { p = NewGitPackage(dep.Source.GitSource) - subdir = dep.Source.GitSource.Subdir } if dep.Source.LocalSource != nil { p = NewLocalPackage(dep.Source.LocalSource) } - lockVersion, err := p.Install(ctx, tmpDir, dep.Version) + lockVersion, err := p.Install(ctx, dep.Name, dir, dep.Version) if err != nil { return nil, errors.Wrap(err, "failed to install package") } @@ -67,20 +59,6 @@ func Install(ctx context.Context, isLock bool, dependencySourceIdentifier string destPath := path.Join(dir, dep.Name) - err = os.MkdirAll(path.Dir(destPath), os.ModePerm) - if err != nil { - return nil, errors.Wrap(err, "failed to create parent path") - } - - err = os.RemoveAll(destPath) - if err != nil { - return nil, errors.Wrap(err, "failed to clean previous destination path") - } - err = os.Rename(path.Join(tmpDir, subdir), destPath) - if err != nil { - return nil, errors.Wrap(err, "failed to move package") - } - lockfile.Dependencies, err = insertDependency(lockfile.Dependencies, spec.Dependency{ Name: dep.Name, Source: dep.Source, From e655fcaf600cd14b52e97fc101927cf262467c06 Mon Sep 17 00:00:00 2001 From: Matthias Loibl Date: Tue, 23 Jul 2019 15:09:58 -0700 Subject: [PATCH 11/15] Update README.md with new args name --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index f47ce80..643f26f 100644 --- a/README.md +++ b/README.md @@ -95,7 +95,7 @@ Commands: init Initialize a new empty jsonnetfile - install [...] + install [...] Install all dependencies or install specific ones update From 6ed6c3f3ecbc2b316a37fab07f96f3aa2ef31151 Mon Sep 17 00:00:00 2001 From: Matthias Loibl Date: Mon, 12 Aug 2019 11:50:56 +0200 Subject: [PATCH 12/15] For local dependencies check if abs path exists --- cmd/jb/install.go | 2 +- cmd/jb/install_test.go | 6 ++++-- cmd/jb/main.go | 9 +++++---- cmd/jb/main_test.go | 2 +- 4 files changed, 11 insertions(+), 8 deletions(-) diff --git a/cmd/jb/install.go b/cmd/jb/install.go index c3b22b1..a973af6 100644 --- a/cmd/jb/install.go +++ b/cmd/jb/install.go @@ -46,7 +46,7 @@ func installCommand(dir, jsonnetHome string, paths ...string) int { if len(paths) > 0 { for _, path := range paths { - newDep := parseDependency(path) + newDep := parseDependency(dir, path) if newDep == nil { kingpin.Errorf("ignoring unrecognized path: %s", path) continue diff --git a/cmd/jb/install_test.go b/cmd/jb/install_test.go index 3c06d64..e3a359f 100644 --- a/cmd/jb/install_test.go +++ b/cmd/jb/install_test.go @@ -49,8 +49,8 @@ func TestInstallCommand(t *testing.T) { Name: "Relative", URLs: []string{"test/jsonnet/foobar"}, ExpectedCode: 0, - ExpectedJsonnetFile: []byte(`{"dependencies":null}`), - ExpectedJsonnetLockFile: []byte(`{"dependencies":null}`), + ExpectedJsonnetFile: []byte(`{"dependencies": [{"name": "foobar", "source": {"local": {"directory": "test/jsonnet/foobar"}}, "version": ""}]}`), + ExpectedJsonnetLockFile: []byte(`{"dependencies": [{"name": "foobar", "source": {"local": {"directory": "test/jsonnet/foobar"}}, "version": ""}]}`), }, } @@ -81,6 +81,8 @@ func TestInstallCommand(t *testing.T) { } func jsonnetFileContent(t *testing.T, filename string, content []byte) { + t.Helper() + bytes, err := ioutil.ReadFile(filename) assert.NoError(t, err) if eq := assert.JSONEq(t, string(content), string(bytes)); !eq { diff --git a/cmd/jb/main.go b/cmd/jb/main.go index f7137f1..67366ec 100644 --- a/cmd/jb/main.go +++ b/cmd/jb/main.go @@ -93,7 +93,7 @@ func Main() int { return 0 } -func parseDependency(path string) *spec.Dependency { +func parseDependency(dir, path string) *spec.Dependency { if d := parseGitSSHDependency(path); d != nil { return d } @@ -102,7 +102,7 @@ func parseDependency(path string) *spec.Dependency { return d } - if d := parseLocalDependency(path); d != nil { + if d := parseLocalDependency(dir, path); d != nil { return d } @@ -211,7 +211,7 @@ func parseGithubDependency(p string) *spec.Dependency { } } -func parseLocalDependency(p string) *spec.Dependency { +func parseLocalDependency(dir, p string) *spec.Dependency { if p == "" { return nil } @@ -223,8 +223,9 @@ func parseLocalDependency(p string) *spec.Dependency { } clean := filepath.Clean(p) + abs := filepath.Join(dir, clean) - info, err := os.Stat(clean) + info, err := os.Stat(abs) if err != nil { return nil } diff --git a/cmd/jb/main_test.go b/cmd/jb/main_test.go index 594264f..3a4007e 100644 --- a/cmd/jb/main_test.go +++ b/cmd/jb/main_test.go @@ -89,7 +89,7 @@ func TestParseDependency(t *testing.T) { } for _, tt := range tests { _ = t.Run(tt.name, func(t *testing.T) { - dependency := parseDependency(tt.path) + dependency := parseDependency("", tt.path) if tt.path == "" { assert.Nil(t, dependency) From d3bb1f4ea4101ac2be3ba3a3e57b2b80f2977da5 Mon Sep 17 00:00:00 2001 From: Matthias Loibl Date: Mon, 12 Aug 2019 17:39:09 +0200 Subject: [PATCH 13/15] Use URI as name for packages location paths --- README.md | 2 +- cmd/jb/install.go | 10 +++++----- cmd/jb/install_test.go | 8 ++++---- cmd/jb/main.go | 12 ++++++------ 4 files changed, 16 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 643f26f..196d1dd 100644 --- a/README.md +++ b/README.md @@ -95,7 +95,7 @@ Commands: init Initialize a new empty jsonnetfile - install [...] + install [...] Install all dependencies or install specific ones update diff --git a/cmd/jb/install.go b/cmd/jb/install.go index a973af6..78b5d64 100644 --- a/cmd/jb/install.go +++ b/cmd/jb/install.go @@ -27,7 +27,7 @@ import ( "gopkg.in/alecthomas/kingpin.v2" ) -func installCommand(dir, jsonnetHome string, paths ...string) int { +func installCommand(dir, jsonnetHome string, uris ...string) int { if dir == "" { dir = "." } @@ -44,11 +44,11 @@ func installCommand(dir, jsonnetHome string, paths ...string) int { return 1 } - if len(paths) > 0 { - for _, path := range paths { - newDep := parseDependency(dir, path) + if len(uris) > 0 { + for _, uri := range uris { + newDep := parseDependency(dir, uri) if newDep == nil { - kingpin.Errorf("ignoring unrecognized path: %s", path) + kingpin.Errorf("ignoring unrecognized uri: %s", uri) continue } diff --git a/cmd/jb/install_test.go b/cmd/jb/install_test.go index e3a359f..ae3a78b 100644 --- a/cmd/jb/install_test.go +++ b/cmd/jb/install_test.go @@ -29,7 +29,7 @@ import ( func TestInstallCommand(t *testing.T) { testcases := []struct { Name string - URLs []string + URIs []string ExpectedCode int ExpectedJsonnetFile []byte ExpectedJsonnetLockFile []byte @@ -41,13 +41,13 @@ func TestInstallCommand(t *testing.T) { ExpectedJsonnetLockFile: []byte(`{"dependencies":null}`), }, { Name: "OneURL", - URLs: []string{"github.com/jsonnet-bundler/jsonnet-bundler@v0.1.0"}, + URIs: []string{"github.com/jsonnet-bundler/jsonnet-bundler@v0.1.0"}, ExpectedCode: 0, ExpectedJsonnetFile: []byte(`{"dependencies": [{"name": "jsonnet-bundler", "source": {"git": {"remote": "https://github.com/jsonnet-bundler/jsonnet-bundler", "subdir": ""}}, "version": "v0.1.0"}]}`), ExpectedJsonnetLockFile: []byte(`{"dependencies": [{"name": "jsonnet-bundler", "source": {"git": {"remote": "https://github.com/jsonnet-bundler/jsonnet-bundler", "subdir": ""}}, "version": "080f157c7fb85ad0281ea78f6c641eaa570a582f"}]}`), }, { Name: "Relative", - URLs: []string{"test/jsonnet/foobar"}, + URIs: []string{"test/jsonnet/foobar"}, ExpectedCode: 0, ExpectedJsonnetFile: []byte(`{"dependencies": [{"name": "foobar", "source": {"local": {"directory": "test/jsonnet/foobar"}}, "version": ""}]}`), ExpectedJsonnetLockFile: []byte(`{"dependencies": [{"name": "foobar", "source": {"local": {"directory": "test/jsonnet/foobar"}}, "version": ""}]}`), @@ -71,7 +71,7 @@ func TestInstallCommand(t *testing.T) { jsonnetFileContent(t, jsonnetFile, []byte(`{}`)) - code = installCommand(tempDir, "vendor", tc.URLs...) + code = installCommand(tempDir, "vendor", tc.URIs...) assert.Equal(t, tc.ExpectedCode, code) jsonnetFileContent(t, jsonnetFile, tc.ExpectedJsonnetFile) diff --git a/cmd/jb/main.go b/cmd/jb/main.go index 67366ec..221a56e 100644 --- a/cmd/jb/main.go +++ b/cmd/jb/main.go @@ -63,7 +63,7 @@ func Main() int { initCmd := a.Command(initActionName, "Initialize a new empty jsonnetfile") installCmd := a.Command(installActionName, "Install all dependencies or install specific ones") - installCmdPaths := installCmd.Arg("paths", "paths 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.") @@ -83,7 +83,7 @@ func Main() int { case initCmd.FullCommand(): return initCommand(workdir) case installCmd.FullCommand(): - return installCommand(workdir, cfg.JsonnetHome, *installCmdPaths...) + return installCommand(workdir, cfg.JsonnetHome, *installCmdURIs...) case updateCmd.FullCommand(): return updateCommand(cfg.JsonnetHome) default: @@ -93,16 +93,16 @@ func Main() int { return 0 } -func parseDependency(dir, path string) *spec.Dependency { - if d := parseGitSSHDependency(path); d != nil { +func parseDependency(dir, uri string) *spec.Dependency { + if d := parseGitSSHDependency(uri); d != nil { return d } - if d := parseGithubDependency(path); d != nil { + if d := parseGithubDependency(uri); d != nil { return d } - if d := parseLocalDependency(dir, path); d != nil { + if d := parseLocalDependency(dir, uri); d != nil { return d } From e1580b7968135ea76c7fdd3204565dd2f219b197 Mon Sep 17 00:00:00 2001 From: Matthias Loibl Date: Mon, 12 Aug 2019 18:16:31 +0200 Subject: [PATCH 14/15] Remove symlink before creating new ones --- pkg/local.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/pkg/local.go b/pkg/local.go index 06c2dd1..6406012 100644 --- a/pkg/local.go +++ b/pkg/local.go @@ -21,6 +21,7 @@ import ( "path/filepath" "github.com/jsonnet-bundler/jsonnet-bundler/spec" + "github.com/pkg/errors" ) type LocalPackage struct { @@ -39,7 +40,14 @@ func (p *LocalPackage) Install(ctx context.Context, name, dir, version string) ( return "", fmt.Errorf("failed to get current working directory: %v", err) } - err = os.Symlink(filepath.Join(wd, p.Source.Directory), filepath.Join(wd, dir, name)) + destPath := filepath.Join(dir, name) + + err = os.RemoveAll(destPath) + if err != nil { + return "", errors.Wrap(err, "failed to clean previous destination path") + } + + err = os.Symlink(filepath.Join(wd, p.Source.Directory), filepath.Join(wd, destPath)) if err != nil { return "", fmt.Errorf("failed to create symlink for local dependency: %v", err) } From c734431ebd93240a3ab1ceb9a8fca61ec07181fe Mon Sep 17 00:00:00 2001 From: Frederic Branczyk Date: Tue, 13 Aug 2019 15:27:02 +0200 Subject: [PATCH 15/15] Update README.md Add design doc --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 196d1dd..1aa7f94 100644 --- a/README.md +++ b/README.md @@ -104,3 +104,6 @@ Commands: ``` +## Design + +This is an implemention of the design specified in this document: https://docs.google.com/document/d/1czRScSvvOiAJaIjwf3CogOULgQxhY9MkiBKOQI1yR14/edit#heading=h.upn4d5pcxy4c