mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-07 20:30:36 -05:00
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
This commit is contained in:
parent
1b5c7e327c
commit
43298f028c
6 changed files with 40 additions and 30 deletions
1
hugolib/config.toml
Executable file
1
hugolib/config.toml
Executable file
|
@ -0,0 +1 @@
|
||||||
|
workingdir = "/private/var/folders/n6/s_85mm8d31j6yctssnmn_g1r0000gn/T/hugo-no-mod217094359"
|
|
@ -541,3 +541,28 @@ title: "My Page"
|
||||||
|
|
||||||
b.AssertFileContent("public/mypage/index.html", "Permalink: https://example.org/mypage/")
|
b.AssertFileContent("public/mypage/index.html", "Permalink: https://example.org/mypage/")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// https://github.com/gohugoio/hugo/issues/6299
|
||||||
|
func TestSiteWithGoModButNoModules(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
c := qt.New(t)
|
||||||
|
// We need to use the OS fs for this.
|
||||||
|
workDir, clean, err := htesting.CreateTempDir(hugofs.Os, "hugo-no-mod")
|
||||||
|
c.Assert(err, qt.IsNil)
|
||||||
|
|
||||||
|
cfg := viper.New()
|
||||||
|
cfg.Set("workingDir", workDir)
|
||||||
|
fs := hugofs.NewFrom(hugofs.Os, cfg)
|
||||||
|
|
||||||
|
defer clean()
|
||||||
|
|
||||||
|
b := newTestSitesBuilder(t)
|
||||||
|
b.Fs = fs
|
||||||
|
|
||||||
|
b.WithWorkingDir(workDir).WithViper(cfg)
|
||||||
|
|
||||||
|
b.WithSourceFile("go.mod", "")
|
||||||
|
b.Build(BuildCfg{})
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -279,12 +279,12 @@ func (c *Client) Init(path string) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) isProbablyModule(path string) bool {
|
func isProbablyModule(path string) bool {
|
||||||
return module.CheckPath(path) == nil
|
return module.CheckPath(path) == nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) listGoMods() (goModules, error) {
|
func (c *Client) listGoMods() (goModules, error) {
|
||||||
if c.GoModulesFilename == "" {
|
if c.GoModulesFilename == "" || !c.moduleConfig.hasModuleImport() {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -250,8 +250,7 @@ func (c *collector) add(owner *moduleAdapter, moduleImport Import, disabled bool
|
||||||
}
|
}
|
||||||
|
|
||||||
if moduleDir == "" {
|
if moduleDir == "" {
|
||||||
|
if c.GoModulesFilename != "" && isProbablyModule(modulePath) {
|
||||||
if c.GoModulesFilename != "" && c.isProbablyModule(modulePath) {
|
|
||||||
// Try to "go get" it and reload the module configuration.
|
// Try to "go get" it and reload the module configuration.
|
||||||
if err := c.Get(modulePath); err != nil {
|
if err := c.Get(modulePath); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -301,10 +300,6 @@ func (c *collector) add(owner *moduleAdapter, moduleImport Import, disabled bool
|
||||||
ma.path = modulePath
|
ma.path = modulePath
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := ma.validateAndApplyDefaults(c.fs); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
if !moduleImport.IgnoreConfig {
|
if !moduleImport.IgnoreConfig {
|
||||||
if err := c.applyThemeConfig(ma); err != nil {
|
if err := c.applyThemeConfig(ma); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
|
@ -235,6 +235,17 @@ type Config struct {
|
||||||
Private string
|
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.
|
// HugoVersion holds Hugo binary version requirements for a module.
|
||||||
type HugoVersion struct {
|
type HugoVersion struct {
|
||||||
// The minimum Hugo version that this module works with.
|
// The minimum Hugo version that this module works with.
|
||||||
|
|
|
@ -18,7 +18,6 @@ package modules
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/gohugoio/hugo/config"
|
"github.com/gohugoio/hugo/config"
|
||||||
"github.com/spf13/afero"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var _ Module = (*moduleAdapter)(nil)
|
var _ Module = (*moduleAdapter)(nil)
|
||||||
|
@ -173,24 +172,3 @@ func (m *moduleAdapter) Watch() bool {
|
||||||
|
|
||||||
return false
|
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
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in a new issue