mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-17 21:01:26 +02:00
@@ -25,6 +25,8 @@ import (
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
hglob "github.com/gohugoio/hugo/hugofs/glob"
|
||||
|
||||
@@ -36,9 +38,6 @@ import (
|
||||
|
||||
"github.com/gohugoio/hugo/common/loggers"
|
||||
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/gohugoio/hugo/config"
|
||||
|
||||
"github.com/rogpeppe/go-internal/module"
|
||||
@@ -49,9 +48,7 @@ import (
|
||||
"github.com/spf13/afero"
|
||||
)
|
||||
|
||||
var (
|
||||
fileSeparator = string(os.PathSeparator)
|
||||
)
|
||||
var fileSeparator = string(os.PathSeparator)
|
||||
|
||||
const (
|
||||
goBinaryStatusOK goBinaryStatus = iota
|
||||
@@ -93,7 +90,6 @@ func NewClient(cfg ClientConfig) *Client {
|
||||
if cfg.CacheDir != "" {
|
||||
// Module cache stored below $GOPATH/pkg
|
||||
config.SetEnvVars(&env, "GOPATH", cfg.CacheDir)
|
||||
|
||||
}
|
||||
|
||||
logger := cfg.Logger
|
||||
@@ -113,7 +109,8 @@ func NewClient(cfg ClientConfig) *Client {
|
||||
noVendor: noVendor,
|
||||
moduleConfig: mcfg,
|
||||
environ: env,
|
||||
GoModulesFilename: goModFilename}
|
||||
GoModulesFilename: goModFilename,
|
||||
}
|
||||
}
|
||||
|
||||
// Client contains most of the API provided by this package.
|
||||
@@ -165,7 +162,6 @@ func (c *Client) Graph(w io.Writer) error {
|
||||
// Local dir.
|
||||
dep += " => " + replace.Dir()
|
||||
}
|
||||
|
||||
}
|
||||
fmt.Fprintln(w, prefix+dep)
|
||||
}
|
||||
@@ -357,7 +353,6 @@ var verifyErrorDirRe = regexp.MustCompile(`dir has been modified \((.*?)\)`)
|
||||
func (c *Client) Verify(clean bool) error {
|
||||
// TODO1 add path to mod clean
|
||||
err := c.runVerify()
|
||||
|
||||
if err != nil {
|
||||
if clean {
|
||||
m := verifyErrorDirRe.FindAllStringSubmatch(err.Error(), -1)
|
||||
@@ -450,7 +445,6 @@ func (c *Client) listGoMods() (goModules, error) {
|
||||
}
|
||||
|
||||
return modules, err
|
||||
|
||||
}
|
||||
|
||||
func (c *Client) rewriteGoMod(name string, isGoMod map[string]bool) error {
|
||||
@@ -515,7 +509,6 @@ func (c *Client) rewriteGoModRewrite(name string, isGoMod map[string]bool) ([]by
|
||||
}
|
||||
|
||||
return b.Bytes(), nil
|
||||
|
||||
}
|
||||
|
||||
func (c *Client) rmVendorDir(vendorDir string) error {
|
||||
@@ -539,7 +532,6 @@ func (c *Client) runGo(
|
||||
ctx context.Context,
|
||||
stdout io.Writer,
|
||||
args ...string) error {
|
||||
|
||||
if c.goBinaryStatus != 0 {
|
||||
return nil
|
||||
}
|
||||
|
@@ -30,7 +30,6 @@ import (
|
||||
)
|
||||
|
||||
func TestClient(t *testing.T) {
|
||||
|
||||
modName := "hugo-modules-basic-test"
|
||||
modPath := "github.com/gohugoio/tests/" + modName
|
||||
expect := `github.com/gohugoio/tests/hugo-modules-basic-test github.com/gohugoio/hugoTestModules1_darwin/modh2_2@v1.4.0
|
||||
@@ -41,7 +40,6 @@ github.com/gohugoio/hugoTestModules1_darwin/modh2_2@v1.4.0 github.com/gohugoio/h
|
||||
c := qt.New(t)
|
||||
|
||||
newClient := func(c *qt.C, withConfig func(cfg *ClientConfig)) (*Client, func()) {
|
||||
|
||||
workingDir, clean, err := htesting.CreateTempDir(hugofs.Os, modName)
|
||||
c.Assert(err, qt.IsNil)
|
||||
themesDir := filepath.Join(workingDir, "themes")
|
||||
@@ -55,7 +53,7 @@ github.com/gohugoio/hugoTestModules1_darwin/modh2_2@v1.4.0 github.com/gohugoio/h
|
||||
}
|
||||
|
||||
withConfig(&ccfg)
|
||||
ccfg.ModuleConfig.Imports = []Import{Import{Path: "github.com/gohugoio/hugoTestModules1_darwin/modh2_2"}}
|
||||
ccfg.ModuleConfig.Imports = []Import{{Path: "github.com/gohugoio/hugoTestModules1_darwin/modh2_2"}}
|
||||
client := NewClient(ccfg)
|
||||
|
||||
return client, clean
|
||||
@@ -98,7 +96,6 @@ project github.com/gohugoio/hugoTestModules1_darwin/modh2_2_2@v1.3.0+vendor
|
||||
|
||||
// Test Tidy
|
||||
c.Assert(client.Tidy(), qt.IsNil)
|
||||
|
||||
})
|
||||
|
||||
c.Run("IgnoreVendor", func(c *qt.C) {
|
||||
@@ -165,15 +162,12 @@ project github.com/gohugoio/hugoTestModules1_darwin/modh2_2_2@v1.3.0+vendor
|
||||
dirname, err = client.createThemeDirname(absDir, false)
|
||||
fmt.Println(dirname)
|
||||
c.Assert(err, qt.Not(qt.IsNil))
|
||||
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
var globAll, _ = glob.GetGlob("**")
|
||||
|
||||
func TestGetModlineSplitter(t *testing.T) {
|
||||
|
||||
c := qt.New(t)
|
||||
|
||||
gomodSplitter := getModlineSplitter(true)
|
||||
@@ -184,5 +178,4 @@ func TestGetModlineSplitter(t *testing.T) {
|
||||
|
||||
gosumSplitter := getModlineSplitter(false)
|
||||
c.Assert(gosumSplitter("github.com/BurntSushi/toml v0.3.1"), qt.DeepEquals, []string{"github.com/BurntSushi/toml", "v0.3.1"})
|
||||
|
||||
}
|
||||
|
@@ -110,7 +110,6 @@ func (h *Client) collect(tidy bool) (ModulesConfig, *collector) {
|
||||
AllModules: c.modules,
|
||||
GoModulesFilename: c.GoModulesFilename,
|
||||
}, c
|
||||
|
||||
}
|
||||
|
||||
type ModulesConfig struct {
|
||||
@@ -325,7 +324,6 @@ func (c *collector) add(owner *moduleAdapter, moduleImport Import, disabled bool
|
||||
|
||||
c.modules = append(c.modules, ma)
|
||||
return ma, nil
|
||||
|
||||
}
|
||||
|
||||
func (c *collector) addAndRecurse(owner *moduleAdapter, disabled bool) error {
|
||||
@@ -363,7 +361,6 @@ func (c *collector) applyMounts(moduleImport Import, mod *moduleAdapter) error {
|
||||
if len(mounts) == 0 {
|
||||
// Mounts not defined by the import.
|
||||
mounts = modConfig.Mounts
|
||||
|
||||
}
|
||||
|
||||
if !mod.projectMod && len(mounts) == 0 {
|
||||
@@ -397,7 +394,6 @@ func (c *collector) applyMounts(moduleImport Import, mod *moduleAdapter) error {
|
||||
}
|
||||
|
||||
func (c *collector) applyThemeConfig(tc *moduleAdapter) error {
|
||||
|
||||
var (
|
||||
configFilename string
|
||||
cfg config.Provider
|
||||
@@ -477,7 +473,6 @@ func (c *collector) applyThemeConfig(tc *moduleAdapter) error {
|
||||
tc.config = config
|
||||
|
||||
return nil
|
||||
|
||||
}
|
||||
|
||||
func (c *collector) collect() {
|
||||
@@ -502,7 +497,6 @@ func (c *collector) collect() {
|
||||
|
||||
// Add the project mod on top.
|
||||
c.modules = append(Modules{projectMod}, c.modules...)
|
||||
|
||||
}
|
||||
|
||||
func (c *collector) isVendored(dir string) bool {
|
||||
@@ -515,7 +509,6 @@ func (c *collector) collectModulesTXT(owner Module) error {
|
||||
filename := filepath.Join(vendorDir, vendorModulesFilename)
|
||||
|
||||
f, err := c.fs.Open(filename)
|
||||
|
||||
if err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
return nil
|
||||
@@ -656,7 +649,6 @@ func (c *collector) wrapModuleNotFound(err error) error {
|
||||
}
|
||||
|
||||
return err
|
||||
|
||||
}
|
||||
|
||||
type vendoredModule struct {
|
||||
@@ -679,7 +671,6 @@ func createProjectModule(gomod *goModule, workingDir string, conf Config) *modul
|
||||
projectMod: true,
|
||||
config: conf,
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// In the first iteration of Hugo Modules, we do not support multiple
|
||||
|
@@ -34,21 +34,18 @@ func TestPathKey(t *testing.T) {
|
||||
} {
|
||||
c.Assert(pathKey(test.in), qt.Equals, test.expect)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestFilterUnwantedMounts(t *testing.T) {
|
||||
|
||||
mounts := []Mount{
|
||||
Mount{Source: "a", Target: "b", Lang: "en"},
|
||||
Mount{Source: "a", Target: "b", Lang: "en"},
|
||||
Mount{Source: "b", Target: "c", Lang: "en"},
|
||||
{Source: "a", Target: "b", Lang: "en"},
|
||||
{Source: "a", Target: "b", Lang: "en"},
|
||||
{Source: "b", Target: "c", Lang: "en"},
|
||||
}
|
||||
|
||||
filtered := filterUnwantedMounts(mounts)
|
||||
|
||||
c := qt.New(t)
|
||||
c.Assert(len(filtered), qt.Equals, 2)
|
||||
c.Assert(filtered, qt.DeepEquals, []Mount{Mount{Source: "a", Target: "b", Lang: "en"}, Mount{Source: "b", Target: "c", Lang: "en"}})
|
||||
|
||||
c.Assert(filtered, qt.DeepEquals, []Mount{{Source: "a", Target: "b", Lang: "en"}, {Source: "b", Target: "c", Lang: "en"}})
|
||||
}
|
||||
|
@@ -113,10 +113,11 @@ func ApplyProjectConfigDefaults(cfg config.Provider, mod Module) error {
|
||||
source := cfg.GetString(d.key)
|
||||
componentsConfigured[d.component] = true
|
||||
|
||||
return []Mount{Mount{
|
||||
return []Mount{{
|
||||
// No lang set for layouts etc.
|
||||
Source: source,
|
||||
Target: d.component}}
|
||||
Target: d.component,
|
||||
}}
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -166,7 +167,6 @@ func ApplyProjectConfigDefaults(cfg config.Provider, mod Module) error {
|
||||
var mounts []Mount
|
||||
for _, dirKey := range dirKeys {
|
||||
if componentsConfigured[dirKey.component] {
|
||||
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -240,7 +240,6 @@ func decodeConfig(cfg config.Provider, pathReplacements map[string]string) (Conf
|
||||
c.Imports[i] = imp
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
for i, mnt := range c.Mounts {
|
||||
@@ -393,11 +392,9 @@ func getStaticDirs(cfg config.Provider) []string {
|
||||
}
|
||||
|
||||
func getStringOrStringSlice(cfg config.Provider, key string, id int) []string {
|
||||
|
||||
if id >= 0 {
|
||||
key = fmt.Sprintf("%s%d", key, id)
|
||||
}
|
||||
|
||||
return config.GetStringSlicePreserveString(cfg, key)
|
||||
|
||||
}
|
||||
|
@@ -120,7 +120,6 @@ path="github.com/bep/mycomponent"
|
||||
|
||||
}
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
func TestDecodeConfigBothOldAndNewProvided(t *testing.T) {
|
||||
@@ -141,7 +140,6 @@ path="a"
|
||||
c.Assert(err, qt.IsNil)
|
||||
c.Assert(len(modCfg.Imports), qt.Equals, 3)
|
||||
c.Assert(modCfg.Imports[0].Path, qt.Equals, "a")
|
||||
|
||||
}
|
||||
|
||||
// Test old style theme import.
|
||||
|
@@ -45,7 +45,6 @@ const (
|
||||
)
|
||||
|
||||
func Pack(fs afero.Fs, fis []hugofs.FileMetaInfo) error {
|
||||
|
||||
var b *packageBuilder
|
||||
|
||||
// Have a package.hugo.json?
|
||||
@@ -140,7 +139,6 @@ func Pack(fs afero.Fs, fis []hugofs.FileMetaInfo) error {
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
}
|
||||
|
||||
func newPackageBuilder(source string, first io.Reader) *packageBuilder {
|
||||
@@ -220,7 +218,6 @@ func (b *packageBuilder) addm(source string, m map[string]interface{}) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func (b *packageBuilder) unmarshal(r io.Reader) map[string]interface{} {
|
||||
|
Reference in New Issue
Block a user