mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-21 20:46:30 -05:00
parent
84adecf97b
commit
9a1e6d15a3
9 changed files with 124 additions and 83 deletions
|
@ -273,6 +273,7 @@ func (cc *hugoBuilderCommon) handleCommonBuilderFlags(cmd *cobra.Command) {
|
||||||
cmd.PersistentFlags().StringVarP(&cc.environment, "environment", "e", "", "build environment")
|
cmd.PersistentFlags().StringVarP(&cc.environment, "environment", "e", "", "build environment")
|
||||||
cmd.PersistentFlags().StringP("themesDir", "", "", "filesystem path to themes directory")
|
cmd.PersistentFlags().StringP("themesDir", "", "", "filesystem path to themes directory")
|
||||||
cmd.PersistentFlags().BoolP("ignoreVendor", "", false, "ignores any _vendor directory")
|
cmd.PersistentFlags().BoolP("ignoreVendor", "", false, "ignores any _vendor directory")
|
||||||
|
cmd.PersistentFlags().StringP("ignoreVendorPaths", "", "", "ignores any _vendor for module paths matching the given Glob pattern")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cc *hugoBuilderCommon) handleFlags(cmd *cobra.Command) {
|
func (cc *hugoBuilderCommon) handleFlags(cmd *cobra.Command) {
|
||||||
|
|
|
@ -151,7 +151,7 @@ func readFileFrom(c *qt.C, filename string) string {
|
||||||
return string(b)
|
return string(b)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestCommandsPersistentFlags(t *testing.T) {
|
func TestFlags(t *testing.T) {
|
||||||
c := qt.New(t)
|
c := qt.New(t)
|
||||||
|
|
||||||
noOpRunE := func(cmd *cobra.Command, args []string) error {
|
noOpRunE := func(cmd *cobra.Command, args []string) error {
|
||||||
|
@ -159,9 +159,33 @@ func TestCommandsPersistentFlags(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
|
name string
|
||||||
args []string
|
args []string
|
||||||
check func(command []cmder)
|
check func(c *qt.C, cmd *serverCmd)
|
||||||
}{{[]string{"server",
|
}{
|
||||||
|
{
|
||||||
|
// https://github.com/gohugoio/hugo/issues/7642
|
||||||
|
name: "ignoreVendor as bool",
|
||||||
|
args: []string{"server", "--ignoreVendor"},
|
||||||
|
check: func(c *qt.C, cmd *serverCmd) {
|
||||||
|
cfg := viper.New()
|
||||||
|
cmd.flagsToConfig(cfg)
|
||||||
|
c.Assert(cfg.Get("ignoreVendor"), qt.Equals, true)
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
// https://github.com/gohugoio/hugo/issues/7642
|
||||||
|
name: "ignoreVendorPaths",
|
||||||
|
args: []string{"server", "--ignoreVendorPaths=github.com/**"},
|
||||||
|
check: func(c *qt.C, cmd *serverCmd) {
|
||||||
|
cfg := viper.New()
|
||||||
|
cmd.flagsToConfig(cfg)
|
||||||
|
c.Assert(cfg.Get("ignoreVendorPaths"), qt.Equals, "github.com/**")
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Persistent flags",
|
||||||
|
args: []string{"server",
|
||||||
"--config=myconfig.toml",
|
"--config=myconfig.toml",
|
||||||
"--configDir=myconfigdir",
|
"--configDir=myconfigdir",
|
||||||
"--contentDir=mycontent",
|
"--contentDir=mycontent",
|
||||||
|
@ -183,22 +207,8 @@ func TestCommandsPersistentFlags(t *testing.T) {
|
||||||
"--renderToDisk",
|
"--renderToDisk",
|
||||||
"--source=mysource",
|
"--source=mysource",
|
||||||
"--path-warnings",
|
"--path-warnings",
|
||||||
}, func(commands []cmder) {
|
},
|
||||||
var sc *serverCmd
|
check: func(c *qt.C, sc *serverCmd) {
|
||||||
for _, command := range commands {
|
|
||||||
if b, ok := command.(commandsBuilderGetter); ok {
|
|
||||||
v := b.getCommandsBuilder().hugoBuilderCommon
|
|
||||||
c.Assert(v.cfgFile, qt.Equals, "myconfig.toml")
|
|
||||||
c.Assert(v.cfgDir, qt.Equals, "myconfigdir")
|
|
||||||
c.Assert(v.source, qt.Equals, "mysource")
|
|
||||||
c.Assert(v.baseURL, qt.Equals, "https://example.com/b/")
|
|
||||||
}
|
|
||||||
|
|
||||||
if srvCmd, ok := command.(*serverCmd); ok {
|
|
||||||
sc = srvCmd
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
c.Assert(sc, qt.Not(qt.IsNil))
|
c.Assert(sc, qt.Not(qt.IsNil))
|
||||||
c.Assert(sc.navigateToChanged, qt.Equals, true)
|
c.Assert(sc.navigateToChanged, qt.Equals, true)
|
||||||
c.Assert(sc.disableLiveReload, qt.Equals, true)
|
c.Assert(sc.disableLiveReload, qt.Equals, true)
|
||||||
|
@ -229,20 +239,23 @@ func TestCommandsPersistentFlags(t *testing.T) {
|
||||||
}}}
|
}}}
|
||||||
|
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
|
c.Run(test.name, func(c *qt.C) {
|
||||||
|
|
||||||
b := newCommandsBuilder()
|
b := newCommandsBuilder()
|
||||||
root := b.addAll().build()
|
root := b.addAll().build()
|
||||||
|
|
||||||
for _, c := range b.commands {
|
for _, cmd := range b.commands {
|
||||||
if c.getCommand() == nil {
|
if cmd.getCommand() == nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
// We are only intereseted in the flag handling here.
|
// We are only intereseted in the flag handling here.
|
||||||
c.getCommand().RunE = noOpRunE
|
cmd.getCommand().RunE = noOpRunE
|
||||||
}
|
}
|
||||||
rootCmd := root.getCommand()
|
rootCmd := root.getCommand()
|
||||||
rootCmd.SetArgs(test.args)
|
rootCmd.SetArgs(test.args)
|
||||||
c.Assert(rootCmd.Execute(), qt.IsNil)
|
c.Assert(rootCmd.Execute(), qt.IsNil)
|
||||||
test.check(b.commands)
|
test.check(c, b.commands[0].(*serverCmd))
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -200,6 +200,7 @@ func initializeFlags(cmd *cobra.Command, cfg config.Provider) {
|
||||||
"noTimes",
|
"noTimes",
|
||||||
"noChmod",
|
"noChmod",
|
||||||
"ignoreVendor",
|
"ignoreVendor",
|
||||||
|
"ignoreVendorPaths",
|
||||||
"templateMetrics",
|
"templateMetrics",
|
||||||
"templateMetricsHints",
|
"templateMetricsHints",
|
||||||
|
|
||||||
|
|
|
@ -120,7 +120,7 @@ Note that:
|
||||||
|
|
||||||
* You can run `hugo mod vendor` on any level in the module tree.
|
* You can run `hugo mod vendor` on any level in the module tree.
|
||||||
* Vendoring will not store modules stored in your `themes` folder.
|
* Vendoring will not store modules stored in your `themes` folder.
|
||||||
* Most commands accept a `--ignoreVendor` flag, which will then run as if the none of the `_vendor` folders in the module tree existed.
|
* Most commands accept a `--ignoreVendorPaths` flag, which will then not use the vendored modules in `_vendor` for the module paths matching the [Glob](https://github.com/gobwas/glob) pattern given. Note that before Hugo 0.75 this flag was named `--ignoreVendor` and was a "all or nothing". {{< new-in "0.75.0" >}}
|
||||||
|
|
||||||
Also see the [CLI Doc](/commands/hugo_mod_vendor/).
|
Also see the [CLI Doc](/commands/hugo_mod_vendor/).
|
||||||
|
|
||||||
|
|
|
@ -18,6 +18,9 @@ import (
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/gobwas/glob"
|
||||||
|
hglob "github.com/gohugoio/hugo/hugofs/glob"
|
||||||
|
|
||||||
"github.com/gohugoio/hugo/common/loggers"
|
"github.com/gohugoio/hugo/common/loggers"
|
||||||
|
|
||||||
"github.com/gohugoio/hugo/cache/filecache"
|
"github.com/gohugoio/hugo/cache/filecache"
|
||||||
|
@ -202,6 +205,12 @@ func LoadConfig(d ConfigSourceDescriptor, doWithConfig ...func(cfg config.Provid
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// We made this a Glob pattern in Hugo 0.75, we don't need both.
|
||||||
|
if v.GetBool("ignoreVendor") {
|
||||||
|
helpers.Deprecated("--ignoreVendor", "--ignoreVendorPaths **", false)
|
||||||
|
v.Set("ignoreVendorPaths", "**")
|
||||||
|
}
|
||||||
|
|
||||||
modulesConfig, err := l.loadModulesConfig(v)
|
modulesConfig, err := l.loadModulesConfig(v)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return v, configFiles, err
|
return v, configFiles, err
|
||||||
|
@ -417,7 +426,10 @@ func (l configLoader) collectModules(modConfig modules.Config, v1 *viper.Viper,
|
||||||
|
|
||||||
themesDir := paths.AbsPathify(l.WorkingDir, v1.GetString("themesDir"))
|
themesDir := paths.AbsPathify(l.WorkingDir, v1.GetString("themesDir"))
|
||||||
|
|
||||||
ignoreVendor := v1.GetBool("ignoreVendor")
|
var ignoreVendor glob.Glob
|
||||||
|
if s := v1.GetString("ignoreVendorPaths"); s != "" {
|
||||||
|
ignoreVendor, _ = hglob.GetGlob(hglob.NormalizePath(s))
|
||||||
|
}
|
||||||
|
|
||||||
filecacheConfigs, err := filecache.DecodeConfig(l.Fs, v1)
|
filecacheConfigs, err := filecache.DecodeConfig(l.Fs, v1)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -126,11 +126,15 @@ baseURL = "https://example.com"
|
||||||
title = "My Modular Site"
|
title = "My Modular Site"
|
||||||
workingDir = %q
|
workingDir = %q
|
||||||
theme = %q
|
theme = %q
|
||||||
ignoreVendor = %t
|
ignoreVendorPaths = %q
|
||||||
|
|
||||||
`
|
`
|
||||||
|
|
||||||
config := fmt.Sprintf(configTemplate, workingDir, m.Path(), ignoreVendor)
|
ignoreVendorPaths := ""
|
||||||
|
if ignoreVendor {
|
||||||
|
ignoreVendorPaths = "github.com/**"
|
||||||
|
}
|
||||||
|
config := fmt.Sprintf(configTemplate, workingDir, m.Path(), ignoreVendorPaths)
|
||||||
|
|
||||||
b := newTestSitesBuilder(t)
|
b := newTestSitesBuilder(t)
|
||||||
|
|
||||||
|
|
|
@ -605,8 +605,9 @@ type ClientConfig struct {
|
||||||
// etc.
|
// etc.
|
||||||
HookBeforeFinalize func(m *ModulesConfig) error
|
HookBeforeFinalize func(m *ModulesConfig) error
|
||||||
|
|
||||||
// Ignore any _vendor directory.
|
// Ignore any _vendor directory for module paths matching the given pattern.
|
||||||
IgnoreVendor bool
|
// This can be nil.
|
||||||
|
IgnoreVendor glob.Glob
|
||||||
|
|
||||||
// Absolute path to the project dir.
|
// Absolute path to the project dir.
|
||||||
WorkingDir string
|
WorkingDir string
|
||||||
|
@ -618,6 +619,10 @@ type ClientConfig struct {
|
||||||
ModuleConfig Config
|
ModuleConfig Config
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c ClientConfig) shouldIgnoreVendor(path string) bool {
|
||||||
|
return c.IgnoreVendor != nil && c.IgnoreVendor.Match(path)
|
||||||
|
}
|
||||||
|
|
||||||
type goBinaryStatus int
|
type goBinaryStatus int
|
||||||
|
|
||||||
type goModule struct {
|
type goModule struct {
|
||||||
|
|
|
@ -17,6 +17,8 @@ import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/gohugoio/hugo/hugofs/glob"
|
||||||
|
|
||||||
"github.com/gohugoio/hugo/common/hugo"
|
"github.com/gohugoio/hugo/common/hugo"
|
||||||
|
|
||||||
"github.com/gohugoio/hugo/htesting"
|
"github.com/gohugoio/hugo/htesting"
|
||||||
|
@ -89,7 +91,7 @@ project github.com/gohugoio/hugoTestModules1_darwin/modh2_2_2@v1.3.0+vendor
|
||||||
Fs: hugofs.Os,
|
Fs: hugofs.Os,
|
||||||
WorkingDir: workingDir,
|
WorkingDir: workingDir,
|
||||||
ModuleConfig: modConfig,
|
ModuleConfig: modConfig,
|
||||||
IgnoreVendor: true,
|
IgnoreVendor: globAll,
|
||||||
})
|
})
|
||||||
|
|
||||||
graphb.Reset()
|
graphb.Reset()
|
||||||
|
@ -101,6 +103,8 @@ project github.com/gohugoio/hugoTestModules1_darwin/modh2_2_2@v1.3.0+vendor
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var globAll, _ = glob.GetGlob("**")
|
||||||
|
|
||||||
func TestGetModlineSplitter(t *testing.T) {
|
func TestGetModlineSplitter(t *testing.T) {
|
||||||
|
|
||||||
c := qt.New(t)
|
c := qt.New(t)
|
||||||
|
|
|
@ -196,7 +196,8 @@ func (c *collector) initModules() error {
|
||||||
gomods: goModules{},
|
gomods: goModules{},
|
||||||
}
|
}
|
||||||
|
|
||||||
if !c.ccfg.IgnoreVendor && c.isVendored(c.ccfg.WorkingDir) {
|
// If both these are true, we don't even need Go installed to build.
|
||||||
|
if c.ccfg.IgnoreVendor == nil && c.isVendored(c.ccfg.WorkingDir) {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -229,7 +230,7 @@ func (c *collector) add(owner *moduleAdapter, moduleImport Import, disabled bool
|
||||||
modulePath := moduleImport.Path
|
modulePath := moduleImport.Path
|
||||||
var realOwner Module = owner
|
var realOwner Module = owner
|
||||||
|
|
||||||
if !c.ccfg.IgnoreVendor {
|
if !c.ccfg.shouldIgnoreVendor(modulePath) {
|
||||||
if err := c.collectModulesTXT(owner); err != nil {
|
if err := c.collectModulesTXT(owner); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue