mirror of
https://github.com/TECHNOFAB11/jsonnet-bundler.git
synced 2025-12-11 23:50:05 +01:00
Refactor git deps install and make local deps install work
This commit is contained in:
parent
07801936c0
commit
e4dcc3e116
4 changed files with 45 additions and 34 deletions
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue