mirror of
https://github.com/TECHNOFAB11/jsonnet-bundler.git
synced 2025-12-12 08:00:05 +01:00
Create LocalSource as type for local dependencies
This commit is contained in:
parent
6ee790d911
commit
07801936c0
6 changed files with 71 additions and 23 deletions
|
|
@ -40,26 +40,28 @@ func TestInstallCommand(t *testing.T) {
|
||||||
ExpectedJsonnetFile: []byte(`{"dependencies":null}`),
|
ExpectedJsonnetFile: []byte(`{"dependencies":null}`),
|
||||||
ExpectedJsonnetLockFile: []byte(`{"dependencies":null}`),
|
ExpectedJsonnetLockFile: []byte(`{"dependencies":null}`),
|
||||||
}, {
|
}, {
|
||||||
Name: "OneURL",
|
Name: "OneURL",
|
||||||
URLs: []*url.URL{
|
URLs: []string{"github.com/jsonnet-bundler/jsonnet-bundler@v0.1.0"},
|
||||||
{
|
|
||||||
Scheme: "https",
|
|
||||||
Host: "github.com",
|
|
||||||
Path: "jsonnet-bundler/jsonnet-bundler@v0.1.0",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
ExpectedCode: 0,
|
ExpectedCode: 0,
|
||||||
ExpectedJsonnetFile: []byte(`{"dependencies": [{"name": "jsonnet-bundler", "source": {"git": {"remote": "https://github.com/jsonnet-bundler/jsonnet-bundler", "subdir": ""}}, "version": "v0.1.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"}]}`),
|
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 {
|
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")
|
tempDir, err := ioutil.TempDir("", "jb-install")
|
||||||
assert.NoError(t, err)
|
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.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)
|
jsonnetFile := filepath.Join(tempDir, jsonnetfile.File)
|
||||||
jsonnetLockFile := filepath.Join(tempDir, jsonnetfile.LockFile)
|
jsonnetLockFile := filepath.Join(tempDir, jsonnetfile.LockFile)
|
||||||
|
|
|
||||||
|
|
@ -226,8 +226,6 @@ func parseLocalDependency(p string) *spec.Dependency {
|
||||||
|
|
||||||
info, err := os.Stat(clean)
|
info, err := os.Stat(clean)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
wd, _ := os.Getwd()
|
|
||||||
fmt.Println(err, wd)
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -238,11 +236,10 @@ func parseLocalDependency(p string) *spec.Dependency {
|
||||||
return &spec.Dependency{
|
return &spec.Dependency{
|
||||||
Name: info.Name(),
|
Name: info.Name(),
|
||||||
Source: spec.Source{
|
Source: spec.Source{
|
||||||
GitSource: &spec.GitSource{
|
LocalSource: &spec.LocalSource{
|
||||||
Remote: ".",
|
Directory: clean,
|
||||||
Subdir: clean,
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Version: ".",
|
Version: "",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@ import (
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestParseDepedency(t *testing.T) {
|
func TestParseDependency(t *testing.T) {
|
||||||
const testFolder = "test/jsonnet/foobar"
|
const testFolder = "test/jsonnet/foobar"
|
||||||
err := os.MkdirAll(testFolder, os.ModePerm)
|
err := os.MkdirAll(testFolder, os.ModePerm)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -79,12 +79,11 @@ func TestParseDepedency(t *testing.T) {
|
||||||
want: &spec.Dependency{
|
want: &spec.Dependency{
|
||||||
Name: "foobar",
|
Name: "foobar",
|
||||||
Source: spec.Source{
|
Source: spec.Source{
|
||||||
GitSource: &spec.GitSource{
|
LocalSource: &spec.LocalSource{
|
||||||
Remote: ".",
|
Directory: "test/jsonnet/foobar",
|
||||||
Subdir: "test/jsonnet/foobar",
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Version: ".",
|
Version: "",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
||||||
42
pkg/local.go
Normal file
42
pkg/local.go
Normal file
|
|
@ -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
|
||||||
|
}
|
||||||
|
|
@ -54,6 +54,9 @@ func Install(ctx context.Context, isLock bool, dependencySourceIdentifier string
|
||||||
p = NewGitPackage(dep.Source.GitSource)
|
p = NewGitPackage(dep.Source.GitSource)
|
||||||
subdir = dep.Source.GitSource.Subdir
|
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, tmpDir, dep.Version)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -100,7 +103,7 @@ func Install(ctx context.Context, isLock bool, dependencySourceIdentifier string
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
depsDeps, err := LoadJsonnetfile(filepath)
|
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.
|
// they do not have transitive dependencies of their own.
|
||||||
if err != nil && !os.IsNotExist(err) {
|
if err != nil && !os.IsNotExist(err) {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
|
||||||
|
|
@ -26,10 +26,15 @@ type Dependency struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type Source struct {
|
type Source struct {
|
||||||
GitSource *GitSource `json:"git"`
|
GitSource *GitSource `json:"git,omitempty"`
|
||||||
|
LocalSource *LocalSource `json:"local,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type GitSource struct {
|
type GitSource struct {
|
||||||
Remote string `json:"remote"`
|
Remote string `json:"remote"`
|
||||||
Subdir string `json:"subdir"`
|
Subdir string `json:"subdir"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type LocalSource struct {
|
||||||
|
Directory string `json:"directory"`
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue