modules: Add noVendor to module config

Fixes #7647
This commit is contained in:
Bjørn Erik Pedersen 2020-09-09 21:10:28 +02:00
parent 20af9a0781
commit d4611c4322
6 changed files with 122 additions and 60 deletions

View file

@ -26,9 +26,10 @@ import (
"path/filepath"
"regexp"
"github.com/gobwas/glob"
hglob "github.com/gohugoio/hugo/hugofs/glob"
"github.com/gobwas/glob"
"github.com/gohugoio/hugo/hugofs"
"github.com/gohugoio/hugo/hugofs/files"
@ -100,10 +101,16 @@ func NewClient(cfg ClientConfig) *Client {
logger = loggers.NewWarningLogger()
}
var noVendor glob.Glob
if cfg.ModuleConfig.NoVendor != "" {
noVendor, _ = hglob.GetGlob(hglob.NormalizePath(cfg.ModuleConfig.NoVendor))
}
return &Client{
fs: fs,
ccfg: cfg,
logger: logger,
noVendor: noVendor,
moduleConfig: mcfg,
environ: env,
GoModulesFilename: goModFilename}
@ -114,6 +121,8 @@ type Client struct {
fs afero.Fs
logger *loggers.Logger
noVendor glob.Glob
ccfg ClientConfig
// The top level module config
@ -220,6 +229,10 @@ func (c *Client) Vendor() error {
continue
}
if !c.shouldVendor(t.Path()) {
continue
}
if !t.IsGoMod() && !t.Vendor() {
// We currently do not vendor components living in the
// 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
}
func (c *Client) shouldVendor(path string) bool {
return c.noVendor == nil || !c.noVendor.Match(path)
}
// ClientConfig configures the module Client.
type ClientConfig struct {
Fs afero.Fs