summaryrefslogtreecommitdiffhomepage
path: root/modules
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <[email protected]>2019-09-03 12:58:02 +0200
committerBjørn Erik Pedersen <[email protected]>2019-09-03 15:12:33 +0200
commit43298f028ccdf38e949b573d03d328bf96b998a3 (patch)
tree9f42576866df3d26e2aee674c2e2c6d28d4efbcb /modules
parent1b5c7e327c7f98cf8e9fff920f3328198f67a598 (diff)
downloadhugo-43298f028ccdf38e949b573d03d328bf96b998a3.tar.gz
hugo-43298f028ccdf38e949b573d03d328bf96b998a3.zip
Make the "is this a Hugo Module" logic more lenient
Now we only try to load modules via Go if there is one or more modules imported in project config. Fixes #6299
Diffstat (limited to 'modules')
-rw-r--r--modules/client.go4
-rw-r--r--modules/collect.go7
-rw-r--r--modules/config.go11
-rw-r--r--modules/module.go22
4 files changed, 14 insertions, 30 deletions
diff --git a/modules/client.go b/modules/client.go
index ae1a6a2b2..a743df5bd 100644
--- a/modules/client.go
+++ b/modules/client.go
@@ -279,12 +279,12 @@ func (c *Client) Init(path string) error {
return nil
}
-func (c *Client) isProbablyModule(path string) bool {
+func isProbablyModule(path string) bool {
return module.CheckPath(path) == nil
}
func (c *Client) listGoMods() (goModules, error) {
- if c.GoModulesFilename == "" {
+ if c.GoModulesFilename == "" || !c.moduleConfig.hasModuleImport() {
return nil, nil
}
diff --git a/modules/collect.go b/modules/collect.go
index 24b80a1d7..731a991b8 100644
--- a/modules/collect.go
+++ b/modules/collect.go
@@ -250,8 +250,7 @@ func (c *collector) add(owner *moduleAdapter, moduleImport Import, disabled bool
}
if moduleDir == "" {
-
- if c.GoModulesFilename != "" && c.isProbablyModule(modulePath) {
+ if c.GoModulesFilename != "" && isProbablyModule(modulePath) {
// Try to "go get" it and reload the module configuration.
if err := c.Get(modulePath); err != nil {
return nil, err
@@ -301,10 +300,6 @@ func (c *collector) add(owner *moduleAdapter, moduleImport Import, disabled bool
ma.path = modulePath
}
- if err := ma.validateAndApplyDefaults(c.fs); err != nil {
- return nil, err
- }
-
if !moduleImport.IgnoreConfig {
if err := c.applyThemeConfig(ma); err != nil {
return nil, err
diff --git a/modules/config.go b/modules/config.go
index 62e6f5e4c..a50845df3 100644
--- a/modules/config.go
+++ b/modules/config.go
@@ -235,6 +235,17 @@ type Config struct {
Private string
}
+// hasModuleImport reports whether the project config have one or more
+// modules imports, e.g. github.com/bep/myshortcodes.
+func (c Config) hasModuleImport() bool {
+ for _, imp := range c.Imports {
+ if isProbablyModule(imp.Path) {
+ return true
+ }
+ }
+ return false
+}
+
// HugoVersion holds Hugo binary version requirements for a module.
type HugoVersion struct {
// The minimum Hugo version that this module works with.
diff --git a/modules/module.go b/modules/module.go
index f71911617..a5f707635 100644
--- a/modules/module.go
+++ b/modules/module.go
@@ -18,7 +18,6 @@ package modules
import (
"github.com/gohugoio/hugo/config"
- "github.com/spf13/afero"
)
var _ Module = (*moduleAdapter)(nil)
@@ -173,24 +172,3 @@ func (m *moduleAdapter) Watch() bool {
return false
}
-
-func (m *moduleAdapter) validateAndApplyDefaults(fs afero.Fs) error {
-
- /*if len(m.modImport.Mounts) == 0 {
- // Create default mount points for every component folder that
- // exists in the module.
- for _, componentFolder := range files.ComponentFolders {
- sourceDir := filepath.Join(dir, componentFolder)
- _, err := fs.Stat(sourceDir)
- if err == nil {
- m.modImport.Mounts = append(m.modImport.Mounts, Mount{
- Source: componentFolder,
- Target: componentFolder,
- })
- }
- }
- }*/
-
- return nil
-
-}