Implement defer

Closes #8086
Closes #12589
This commit is contained in:
Bjørn Erik Pedersen 2024-06-08 11:52:22 +02:00
parent 8731d88222
commit 6cd0784e44
33 changed files with 1033 additions and 148 deletions

View file

@ -760,6 +760,9 @@ type ClientConfig struct {
// Absolute path to the project's themes dir.
ThemesDir string
// The publish dir.
PublishDir string
// Eg. "production"
Environment string

View file

@ -51,12 +51,16 @@ github.com/gohugoio/hugoTestModules1_darwin/modh2_2@v1.4.0 github.com/gohugoio/h
themesDir := filepath.Join(workingDir, "themes")
err = os.Mkdir(themesDir, 0o777)
c.Assert(err, qt.IsNil)
publishDir := filepath.Join(workingDir, "public")
err = os.Mkdir(publishDir, 0o777)
c.Assert(err, qt.IsNil)
ccfg := ClientConfig{
Fs: hugofs.Os,
WorkingDir: workingDir,
CacheDir: filepath.Join(workingDir, "modcache"),
WorkingDir: workingDir,
ThemesDir: themesDir,
PublishDir: publishDir,
Exec: hexec.New(security.DefaultConfig),
}

View file

@ -27,6 +27,7 @@ import (
"github.com/bep/debounce"
"github.com/gohugoio/hugo/common/herrors"
"github.com/gohugoio/hugo/common/loggers"
"github.com/gohugoio/hugo/common/paths"
"github.com/spf13/cast"
@ -657,7 +658,13 @@ func (c *collector) normalizeMounts(owner *moduleAdapter, mounts []Mount) ([]Mou
// Verify that Source exists
_, err := c.fs.Stat(sourceDir)
if err != nil {
if strings.HasSuffix(sourceDir, files.FilenameHugoStatsJSON) {
if paths.IsSameFilePath(sourceDir, c.ccfg.PublishDir) {
// This is a little exotic, but there are use cases for mounting the public folder.
// This will typically also be in .gitingore, so create it.
if err := c.fs.MkdirAll(sourceDir, 0o755); err != nil {
return nil, fmt.Errorf("%s: %q", errMsg, err)
}
} else if strings.HasSuffix(sourceDir, files.FilenameHugoStatsJSON) {
// A common pattern for Tailwind 3 is to mount that file to get it on the server watch list.
// A common pattern is also to add hugo_stats.json to .gitignore.
@ -669,6 +676,7 @@ func (c *collector) normalizeMounts(owner *moduleAdapter, mounts []Mount) ([]Mou
}
f.Close()
} else {
c.logger.Warnf("module %q: mount source %q does not exist", owner.Path(), sourceDir)
continue
}
}

View file

@ -402,6 +402,9 @@ type Mount struct {
// Exclude all files matching the given Glob patterns (string or slice).
ExcludeFiles any
// Disable watching in watch mode for this mount.
DisableWatch bool
}
// Used as key to remove duplicates.