mirror of
https://github.com/TECHNOFAB11/jsonnet-bundler.git
synced 2025-12-11 23:50:05 +01:00
fix: allow other dirs than vendor (#80)
This commit is contained in:
parent
0ba0ff5522
commit
1d729c9517
4 changed files with 36 additions and 6 deletions
|
|
@ -32,6 +32,18 @@ import (
|
||||||
const initContents = `{"dependencies": [], "legacyImports": true}`
|
const initContents = `{"dependencies": [], "legacyImports": true}`
|
||||||
|
|
||||||
func TestInstallCommand(t *testing.T) {
|
func TestInstallCommand(t *testing.T) {
|
||||||
|
testInstallCommandWithJsonnetHome(t, "vendor")
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestInstallCommandCustomJsonnetHome(t *testing.T) {
|
||||||
|
testInstallCommandWithJsonnetHome(t, "custom-vendor-dir")
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestInstallCommandDeepCustomJsonnetHome(t *testing.T) {
|
||||||
|
testInstallCommandWithJsonnetHome(t, "custom/vendor/dir")
|
||||||
|
}
|
||||||
|
|
||||||
|
func testInstallCommandWithJsonnetHome(t *testing.T, jsonnetHome string) {
|
||||||
testcases := []struct {
|
testcases := []struct {
|
||||||
Name string
|
Name string
|
||||||
URIs []string
|
URIs []string
|
||||||
|
|
@ -65,7 +77,7 @@ func TestInstallCommand(t *testing.T) {
|
||||||
cleanup := func() {
|
cleanup := func() {
|
||||||
_ = os.Remove(jsonnetfile.File)
|
_ = os.Remove(jsonnetfile.File)
|
||||||
_ = os.Remove(jsonnetfile.LockFile)
|
_ = os.Remove(jsonnetfile.LockFile)
|
||||||
_ = os.RemoveAll("vendor")
|
_ = os.RemoveAll(jsonnetHome)
|
||||||
_ = os.RemoveAll("jsonnet")
|
_ = os.RemoveAll("jsonnet")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -81,7 +93,7 @@ func TestInstallCommand(t *testing.T) {
|
||||||
jsonnetFileContent(t, jsonnetfile.File, []byte(initContents))
|
jsonnetFileContent(t, jsonnetfile.File, []byte(initContents))
|
||||||
|
|
||||||
// install something, check it writes only if required, etc.
|
// install something, check it writes only if required, etc.
|
||||||
installCommand("", "vendor", tc.URIs)
|
installCommand("", jsonnetHome, tc.URIs)
|
||||||
jsonnetFileContent(t, jsonnetfile.File, tc.ExpectedJsonnetFile)
|
jsonnetFileContent(t, jsonnetfile.File, tc.ExpectedJsonnetFile)
|
||||||
if tc.ExpectedJsonnetLockFile != nil {
|
if tc.ExpectedJsonnetLockFile != nil {
|
||||||
jsonnetFileContent(t, jsonnetfile.LockFile, tc.ExpectedJsonnetLockFile)
|
jsonnetFileContent(t, jsonnetfile.LockFile, tc.ExpectedJsonnetLockFile)
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@ package main
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
|
||||||
"github.com/fatih/color"
|
"github.com/fatih/color"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
|
|
@ -67,6 +68,8 @@ func Main() int {
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cfg.JsonnetHome = filepath.Clean(cfg.JsonnetHome)
|
||||||
|
|
||||||
switch command {
|
switch command {
|
||||||
case initCmd.FullCommand():
|
case initCmd.FullCommand():
|
||||||
return initCommand(workdir)
|
return initCommand(workdir)
|
||||||
|
|
|
||||||
|
|
@ -76,7 +76,10 @@ func Ensure(direct spec.JsonnetFile, vendorDir string, oldLocks map[string]deps.
|
||||||
|
|
||||||
// remove them
|
// remove them
|
||||||
for _, dir := range names {
|
for _, dir := range names {
|
||||||
name := strings.TrimPrefix(dir, "vendor/")
|
name, err := filepath.Rel(vendorDir, dir)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
if !known(locks, name) {
|
if !known(locks, name) {
|
||||||
if err := os.RemoveAll(dir); err != nil {
|
if err := os.RemoveAll(dir); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
@ -147,7 +150,7 @@ func linkLegacy(vendorDir string, locks map[string]deps.Dependency) error {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
legacyName := filepath.Join("vendor", d.LegacyName())
|
legacyName := filepath.Join(vendorDir, d.LegacyName())
|
||||||
pkgName := d.Name()
|
pkgName := d.Name()
|
||||||
|
|
||||||
taken, err := checkLegacyNameTaken(legacyName, pkgName)
|
taken, err := checkLegacyNameTaken(legacyName, pkgName)
|
||||||
|
|
|
||||||
|
|
@ -48,6 +48,18 @@ const want = `
|
||||||
`
|
`
|
||||||
|
|
||||||
func TestRewrite(t *testing.T) {
|
func TestRewrite(t *testing.T) {
|
||||||
|
testRewriteWithJsonnetHome(t, "vendor")
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestRewriteCustomJsonnetHome(t *testing.T) {
|
||||||
|
testRewriteWithJsonnetHome(t, "custom-vendor-dir")
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestRewriteDeepCustomJsonnetHome(t *testing.T) {
|
||||||
|
testRewriteWithJsonnetHome(t, "custom/vendor/dir")
|
||||||
|
}
|
||||||
|
|
||||||
|
func testRewriteWithJsonnetHome(t *testing.T, jsonnetHome string) {
|
||||||
dir, err := ioutil.TempDir("", "jbrewrite")
|
dir, err := ioutil.TempDir("", "jbrewrite")
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
defer os.RemoveAll(dir)
|
defer os.RemoveAll(dir)
|
||||||
|
|
@ -56,11 +68,11 @@ func TestRewrite(t *testing.T) {
|
||||||
err = ioutil.WriteFile(name, []byte(sample), 0644)
|
err = ioutil.WriteFile(name, []byte(sample), 0644)
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
|
|
||||||
vendorDir := filepath.Join(dir, "vendor")
|
vendorDir := filepath.Join(dir, jsonnetHome)
|
||||||
err = os.MkdirAll(vendorDir, os.ModePerm)
|
err = os.MkdirAll(vendorDir, os.ModePerm)
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
|
|
||||||
err = Rewrite(dir, "vendor", locks)
|
err = Rewrite(dir, jsonnetHome, locks)
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
|
|
||||||
content, err := ioutil.ReadFile(name)
|
content, err := ioutil.ReadFile(name)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue