parent
20af9a0781
commit
d4611c4322
6 changed files with 122 additions and 60 deletions
5
cache/filecache/filecache_test.go
vendored
5
cache/filecache/filecache_test.go
vendored
|
@ -25,6 +25,8 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/gobwas/glob"
|
||||||
|
|
||||||
"github.com/gohugoio/hugo/langs"
|
"github.com/gohugoio/hugo/langs"
|
||||||
"github.com/gohugoio/hugo/modules"
|
"github.com/gohugoio/hugo/modules"
|
||||||
|
|
||||||
|
@ -314,12 +316,13 @@ func initConfig(fs afero.Fs, cfg config.Provider) error {
|
||||||
if !filepath.IsAbs(themesDir) {
|
if !filepath.IsAbs(themesDir) {
|
||||||
themesDir = filepath.Join(workingDir, themesDir)
|
themesDir = filepath.Join(workingDir, themesDir)
|
||||||
}
|
}
|
||||||
|
globAll := glob.MustCompile("**", '/')
|
||||||
modulesClient := modules.NewClient(modules.ClientConfig{
|
modulesClient := modules.NewClient(modules.ClientConfig{
|
||||||
Fs: fs,
|
Fs: fs,
|
||||||
WorkingDir: workingDir,
|
WorkingDir: workingDir,
|
||||||
ThemesDir: themesDir,
|
ThemesDir: themesDir,
|
||||||
ModuleConfig: modConfig,
|
ModuleConfig: modConfig,
|
||||||
IgnoreVendor: true,
|
IgnoreVendor: globAll,
|
||||||
})
|
})
|
||||||
|
|
||||||
moduleConfig, err := modulesClient.Collect()
|
moduleConfig, err := modulesClient.Collect()
|
||||||
|
|
|
@ -18,11 +18,16 @@ toc: true
|
||||||
|
|
||||||
{{< code-toggle file="config">}}
|
{{< code-toggle file="config">}}
|
||||||
[module]
|
[module]
|
||||||
|
noVendor = ""
|
||||||
proxy = "direct"
|
proxy = "direct"
|
||||||
noProxy = "none"
|
noProxy = "none"
|
||||||
private = "*.*"
|
private = "*.*"
|
||||||
{{< /code-toggle >}}
|
{{< /code-toggle >}}
|
||||||
|
|
||||||
|
|
||||||
|
noVendor {{< new-in "0.75.0" >}}
|
||||||
|
: A optional Glob pattern matching module paths to skip when vendoring, e.g. "github.com/**"
|
||||||
|
|
||||||
proxy
|
proxy
|
||||||
: Defines the proxy server to use to download remote modules. Default is `direct`, which means "git clone" and similar.
|
: Defines the proxy server to use to download remote modules. Default is `direct`, which means "git clone" and similar.
|
||||||
|
|
||||||
|
|
|
@ -21,6 +21,8 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/gobwas/glob"
|
||||||
|
|
||||||
"github.com/gohugoio/hugo/config"
|
"github.com/gohugoio/hugo/config"
|
||||||
|
|
||||||
"github.com/gohugoio/hugo/langs"
|
"github.com/gohugoio/hugo/langs"
|
||||||
|
@ -49,12 +51,13 @@ func initConfig(fs afero.Fs, cfg config.Provider) error {
|
||||||
if !filepath.IsAbs(themesDir) {
|
if !filepath.IsAbs(themesDir) {
|
||||||
themesDir = filepath.Join(workingDir, themesDir)
|
themesDir = filepath.Join(workingDir, themesDir)
|
||||||
}
|
}
|
||||||
|
globAll := glob.MustCompile("**", '/')
|
||||||
modulesClient := modules.NewClient(modules.ClientConfig{
|
modulesClient := modules.NewClient(modules.ClientConfig{
|
||||||
Fs: fs,
|
Fs: fs,
|
||||||
WorkingDir: workingDir,
|
WorkingDir: workingDir,
|
||||||
ThemesDir: themesDir,
|
ThemesDir: themesDir,
|
||||||
ModuleConfig: modConfig,
|
ModuleConfig: modConfig,
|
||||||
IgnoreVendor: true,
|
IgnoreVendor: globAll,
|
||||||
})
|
})
|
||||||
|
|
||||||
moduleConfig, err := modulesClient.Collect()
|
moduleConfig, err := modulesClient.Collect()
|
||||||
|
|
|
@ -26,9 +26,10 @@ import (
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
|
||||||
"github.com/gobwas/glob"
|
|
||||||
hglob "github.com/gohugoio/hugo/hugofs/glob"
|
hglob "github.com/gohugoio/hugo/hugofs/glob"
|
||||||
|
|
||||||
|
"github.com/gobwas/glob"
|
||||||
|
|
||||||
"github.com/gohugoio/hugo/hugofs"
|
"github.com/gohugoio/hugo/hugofs"
|
||||||
|
|
||||||
"github.com/gohugoio/hugo/hugofs/files"
|
"github.com/gohugoio/hugo/hugofs/files"
|
||||||
|
@ -100,10 +101,16 @@ func NewClient(cfg ClientConfig) *Client {
|
||||||
logger = loggers.NewWarningLogger()
|
logger = loggers.NewWarningLogger()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var noVendor glob.Glob
|
||||||
|
if cfg.ModuleConfig.NoVendor != "" {
|
||||||
|
noVendor, _ = hglob.GetGlob(hglob.NormalizePath(cfg.ModuleConfig.NoVendor))
|
||||||
|
}
|
||||||
|
|
||||||
return &Client{
|
return &Client{
|
||||||
fs: fs,
|
fs: fs,
|
||||||
ccfg: cfg,
|
ccfg: cfg,
|
||||||
logger: logger,
|
logger: logger,
|
||||||
|
noVendor: noVendor,
|
||||||
moduleConfig: mcfg,
|
moduleConfig: mcfg,
|
||||||
environ: env,
|
environ: env,
|
||||||
GoModulesFilename: goModFilename}
|
GoModulesFilename: goModFilename}
|
||||||
|
@ -114,6 +121,8 @@ type Client struct {
|
||||||
fs afero.Fs
|
fs afero.Fs
|
||||||
logger *loggers.Logger
|
logger *loggers.Logger
|
||||||
|
|
||||||
|
noVendor glob.Glob
|
||||||
|
|
||||||
ccfg ClientConfig
|
ccfg ClientConfig
|
||||||
|
|
||||||
// The top level module config
|
// The top level module config
|
||||||
|
@ -220,6 +229,10 @@ func (c *Client) Vendor() error {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !c.shouldVendor(t.Path()) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
if !t.IsGoMod() && !t.Vendor() {
|
if !t.IsGoMod() && !t.Vendor() {
|
||||||
// We currently do not vendor components living in the
|
// We currently do not vendor components living in the
|
||||||
// theme directory, see https://github.com/gohugoio/hugo/issues/5993
|
// theme directory, see https://github.com/gohugoio/hugo/issues/5993
|
||||||
|
@ -596,6 +609,10 @@ func (c *Client) tidy(mods Modules, goModOnly bool) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *Client) shouldVendor(path string) bool {
|
||||||
|
return c.noVendor == nil || !c.noVendor.Match(path)
|
||||||
|
}
|
||||||
|
|
||||||
// ClientConfig configures the module Client.
|
// ClientConfig configures the module Client.
|
||||||
type ClientConfig struct {
|
type ClientConfig struct {
|
||||||
Fs afero.Fs
|
Fs afero.Fs
|
||||||
|
|
|
@ -19,8 +19,6 @@ import (
|
||||||
|
|
||||||
"github.com/gohugoio/hugo/hugofs/glob"
|
"github.com/gohugoio/hugo/hugofs/glob"
|
||||||
|
|
||||||
"github.com/gohugoio/hugo/common/hugo"
|
|
||||||
|
|
||||||
"github.com/gohugoio/hugo/htesting"
|
"github.com/gohugoio/hugo/htesting"
|
||||||
|
|
||||||
"github.com/gohugoio/hugo/hugofs"
|
"github.com/gohugoio/hugo/hugofs"
|
||||||
|
@ -29,77 +27,109 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestClient(t *testing.T) {
|
func TestClient(t *testing.T) {
|
||||||
if hugo.GoMinorVersion() < 12 {
|
|
||||||
// https://github.com/golang/go/issues/26794
|
|
||||||
// There were some concurrent issues with Go modules in < Go 12.
|
|
||||||
t.Skip("skip this for Go <= 1.11 due to a bug in Go's stdlib")
|
|
||||||
}
|
|
||||||
|
|
||||||
t.Parallel()
|
|
||||||
|
|
||||||
modName := "hugo-modules-basic-test"
|
modName := "hugo-modules-basic-test"
|
||||||
modPath := "github.com/gohugoio/tests/" + modName
|
modPath := "github.com/gohugoio/tests/" + modName
|
||||||
modConfig := DefaultModuleConfig
|
|
||||||
modConfig.Imports = []Import{Import{Path: "github.com/gohugoio/hugoTestModules1_darwin/modh2_2"}}
|
|
||||||
|
|
||||||
c := qt.New(t)
|
|
||||||
|
|
||||||
workingDir, clean, err := htesting.CreateTempDir(hugofs.Os, modName)
|
|
||||||
c.Assert(err, qt.IsNil)
|
|
||||||
defer clean()
|
|
||||||
|
|
||||||
client := NewClient(ClientConfig{
|
|
||||||
Fs: hugofs.Os,
|
|
||||||
WorkingDir: workingDir,
|
|
||||||
ModuleConfig: modConfig,
|
|
||||||
})
|
|
||||||
|
|
||||||
// Test Init
|
|
||||||
c.Assert(client.Init(modPath), qt.IsNil)
|
|
||||||
|
|
||||||
// Test Collect
|
|
||||||
mc, err := client.Collect()
|
|
||||||
c.Assert(err, qt.IsNil)
|
|
||||||
c.Assert(len(mc.AllModules), qt.Equals, 4)
|
|
||||||
for _, m := range mc.AllModules {
|
|
||||||
c.Assert(m, qt.Not(qt.IsNil))
|
|
||||||
}
|
|
||||||
|
|
||||||
// Test Graph
|
|
||||||
var graphb bytes.Buffer
|
|
||||||
c.Assert(client.Graph(&graphb), qt.IsNil)
|
|
||||||
|
|
||||||
expect := `github.com/gohugoio/tests/hugo-modules-basic-test github.com/gohugoio/hugoTestModules1_darwin/modh2_2@v1.4.0
|
expect := `github.com/gohugoio/tests/hugo-modules-basic-test github.com/gohugoio/hugoTestModules1_darwin/modh2_2@v1.4.0
|
||||||
github.com/gohugoio/hugoTestModules1_darwin/modh2_2@v1.4.0 github.com/gohugoio/hugoTestModules1_darwin/modh2_2_1v@v1.3.0
|
github.com/gohugoio/hugoTestModules1_darwin/modh2_2@v1.4.0 github.com/gohugoio/hugoTestModules1_darwin/modh2_2_1v@v1.3.0
|
||||||
github.com/gohugoio/hugoTestModules1_darwin/modh2_2@v1.4.0 github.com/gohugoio/hugoTestModules1_darwin/modh2_2_2@v1.3.0
|
github.com/gohugoio/hugoTestModules1_darwin/modh2_2@v1.4.0 github.com/gohugoio/hugoTestModules1_darwin/modh2_2_2@v1.3.0
|
||||||
`
|
`
|
||||||
|
|
||||||
c.Assert(graphb.String(), qt.Equals, expect)
|
c := qt.New(t)
|
||||||
|
|
||||||
// Test Vendor
|
newClient := func(c *qt.C, withConfig func(cfg *ClientConfig)) (*Client, func()) {
|
||||||
c.Assert(client.Vendor(), qt.IsNil)
|
|
||||||
graphb.Reset()
|
workingDir, clean, err := htesting.CreateTempDir(hugofs.Os, modName)
|
||||||
c.Assert(client.Graph(&graphb), qt.IsNil)
|
c.Assert(err, qt.IsNil)
|
||||||
expectVendored := `project github.com/gohugoio/hugoTestModules1_darwin/modh2_2@v1.4.0+vendor
|
|
||||||
|
ccfg := ClientConfig{
|
||||||
|
Fs: hugofs.Os,
|
||||||
|
WorkingDir: workingDir,
|
||||||
|
}
|
||||||
|
|
||||||
|
withConfig(&ccfg)
|
||||||
|
ccfg.ModuleConfig.Imports = []Import{Import{Path: "github.com/gohugoio/hugoTestModules1_darwin/modh2_2"}}
|
||||||
|
client := NewClient(ccfg)
|
||||||
|
|
||||||
|
return client, clean
|
||||||
|
}
|
||||||
|
|
||||||
|
c.Run("All", func(c *qt.C) {
|
||||||
|
client, clean := newClient(c, func(cfg *ClientConfig) {
|
||||||
|
cfg.ModuleConfig = DefaultModuleConfig
|
||||||
|
})
|
||||||
|
defer clean()
|
||||||
|
|
||||||
|
// Test Init
|
||||||
|
c.Assert(client.Init(modPath), qt.IsNil)
|
||||||
|
|
||||||
|
// Test Collect
|
||||||
|
mc, err := client.Collect()
|
||||||
|
c.Assert(err, qt.IsNil)
|
||||||
|
c.Assert(len(mc.AllModules), qt.Equals, 4)
|
||||||
|
for _, m := range mc.AllModules {
|
||||||
|
c.Assert(m, qt.Not(qt.IsNil))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Test Graph
|
||||||
|
var graphb bytes.Buffer
|
||||||
|
c.Assert(client.Graph(&graphb), qt.IsNil)
|
||||||
|
|
||||||
|
c.Assert(graphb.String(), qt.Equals, expect)
|
||||||
|
|
||||||
|
// Test Vendor
|
||||||
|
c.Assert(client.Vendor(), qt.IsNil)
|
||||||
|
graphb.Reset()
|
||||||
|
c.Assert(client.Graph(&graphb), qt.IsNil)
|
||||||
|
|
||||||
|
expectVendored := `project github.com/gohugoio/hugoTestModules1_darwin/modh2_2@v1.4.0+vendor
|
||||||
project github.com/gohugoio/hugoTestModules1_darwin/modh2_2_1v@v1.3.0+vendor
|
project github.com/gohugoio/hugoTestModules1_darwin/modh2_2_1v@v1.3.0+vendor
|
||||||
project github.com/gohugoio/hugoTestModules1_darwin/modh2_2_2@v1.3.0+vendor
|
project github.com/gohugoio/hugoTestModules1_darwin/modh2_2_2@v1.3.0+vendor
|
||||||
`
|
`
|
||||||
c.Assert(graphb.String(), qt.Equals, expectVendored)
|
|
||||||
|
|
||||||
// Test the ignoreVendor setting
|
c.Assert(graphb.String(), qt.Equals, expectVendored)
|
||||||
clientIgnoreVendor := NewClient(ClientConfig{
|
|
||||||
Fs: hugofs.Os,
|
// Test Tidy
|
||||||
WorkingDir: workingDir,
|
c.Assert(client.Tidy(), qt.IsNil)
|
||||||
ModuleConfig: modConfig,
|
|
||||||
IgnoreVendor: globAll,
|
|
||||||
})
|
})
|
||||||
|
|
||||||
graphb.Reset()
|
c.Run("IgnoreVendor", func(c *qt.C) {
|
||||||
c.Assert(clientIgnoreVendor.Graph(&graphb), qt.IsNil)
|
client, clean := newClient(
|
||||||
c.Assert(graphb.String(), qt.Equals, expect)
|
c, func(cfg *ClientConfig) {
|
||||||
|
cfg.ModuleConfig = DefaultModuleConfig
|
||||||
|
cfg.IgnoreVendor = globAll
|
||||||
|
})
|
||||||
|
defer clean()
|
||||||
|
|
||||||
// Test Tidy
|
c.Assert(client.Init(modPath), qt.IsNil)
|
||||||
c.Assert(client.Tidy(), qt.IsNil)
|
_, err := client.Collect()
|
||||||
|
c.Assert(err, qt.IsNil)
|
||||||
|
c.Assert(client.Vendor(), qt.IsNil)
|
||||||
|
|
||||||
|
var graphb bytes.Buffer
|
||||||
|
c.Assert(client.Graph(&graphb), qt.IsNil)
|
||||||
|
c.Assert(graphb.String(), qt.Equals, expect)
|
||||||
|
})
|
||||||
|
|
||||||
|
c.Run("NoVendor", func(c *qt.C) {
|
||||||
|
mcfg := DefaultModuleConfig
|
||||||
|
mcfg.NoVendor = "**"
|
||||||
|
client, clean := newClient(
|
||||||
|
c, func(cfg *ClientConfig) {
|
||||||
|
cfg.ModuleConfig = mcfg
|
||||||
|
})
|
||||||
|
defer clean()
|
||||||
|
|
||||||
|
c.Assert(client.Init(modPath), qt.IsNil)
|
||||||
|
_, err := client.Collect()
|
||||||
|
c.Assert(err, qt.IsNil)
|
||||||
|
c.Assert(client.Vendor(), qt.IsNil)
|
||||||
|
|
||||||
|
var graphb bytes.Buffer
|
||||||
|
c.Assert(client.Graph(&graphb), qt.IsNil)
|
||||||
|
c.Assert(graphb.String(), qt.Equals, expect)
|
||||||
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -227,6 +227,10 @@ type Config struct {
|
||||||
// Will be validated against the running Hugo version.
|
// Will be validated against the running Hugo version.
|
||||||
HugoVersion HugoVersion
|
HugoVersion HugoVersion
|
||||||
|
|
||||||
|
// A optional Glob pattern matching module paths to skip when vendoring, e.g.
|
||||||
|
// "github.com/**".
|
||||||
|
NoVendor string
|
||||||
|
|
||||||
// Configures GOPROXY.
|
// Configures GOPROXY.
|
||||||
Proxy string
|
Proxy string
|
||||||
// Configures GONOPROXY.
|
// Configures GONOPROXY.
|
||||||
|
|
Loading…
Add table
Reference in a new issue