]> git.maquefel.me Git - brevno-suite/hugo/commitdiff
modules: Adjust watch logic vs workspace use definitions
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Mon, 19 Dec 2022 16:49:45 +0000 (17:49 +0100)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Mon, 19 Dec 2022 19:17:33 +0000 (20:17 +0100)
docs/content/en/hugo-modules/configuration.md
modules/config_test.go
modules/module.go

index c05201f8a88eb72945a37dea942b7b92a54c252a..5b19d2419f3dc3a6057a5e32b4db253d707e19e3 100644 (file)
@@ -23,7 +23,7 @@ proxy = "direct"
 noProxy = "none"
 private = "*.*"
 replacements = ""
-workspace = ""
+workspace = "off"
 {{< /code-toggle >}}
 
 noVendor
@@ -42,7 +42,7 @@ private
 : Comma separated glob list matching paths that should be treated as private.
 
 workspace
-: The workspace file to use. This enables Go workspace mode. Note that this can also be set via OS env, e.g. `export HUGO_MODULE_WORKSPACE=/my/hugo.work` This only works with Go 1.18+.
+: The workspace file to use. This enables Go workspace mode. Note that this can also be set via OS env, e.g. `export HUGO_MODULE_WORKSPACE=/my/hugo.work` This only works with Go 1.18+. In Hugo `v0.109.0` we changed the default to `off` and we now resolve any relative work filenames relative to the working directory.
 
 replacements
 : A comma separated (or a slice) list of module path to directory replacement mapping, e.g. `github.com/bep/my-theme -> ../..,github.com/bep/shortcodes -> /some/path`. This is mostly useful for temporary locally development of a module, and then it makes sense to set it as an OS environment variable, e.g: `env HUGO_MODULE_REPLACEMENTS="github.com/bep/my-theme -> ../.."`. Any relative path is relate to [themesDir](https://gohugo.io/getting-started/configuration/#all-configuration-settings), and absolute paths are allowed.
index 4ded2be66a1cbaa55459a4c850974b3812f08648..5c97caaa2ba8b94f06e526809c86160c88f5ab77 100644 (file)
@@ -14,6 +14,9 @@
 package modules
 
 import (
+       "fmt"
+       "os"
+       "path/filepath"
        "testing"
 
        "github.com/gohugoio/hugo/common/hugo"
@@ -43,8 +46,9 @@ func TestDecodeConfig(t *testing.T) {
        c := qt.New(t)
 
        c.Run("Basic", func(c *qt.C) {
+               tempDir := c.TempDir()
                tomlConfig := `
-workingDir = "/src/project"
+workingDir = %q
 [module]
 workspace = "hugo.work"
 [module.hugoVersion]
@@ -65,7 +69,11 @@ source="src/markdown/blog"
 target="content/blog"
 lang="en"
 `
-               cfg, err := config.FromConfigString(tomlConfig, "toml")
+
+               hugoWorkFilename := filepath.Join(tempDir, "hugo.work")
+               f, _ := os.Create(hugoWorkFilename)
+               f.Close()
+               cfg, err := config.FromConfigString(fmt.Sprintf(tomlConfig, tempDir), "toml")
                c.Assert(err, qt.IsNil)
 
                mcfg, err := DecodeConfig(cfg)
@@ -83,7 +91,7 @@ lang="en"
                        c.Assert(hv.IsValid(), qt.Equals, true)
                }
 
-               c.Assert(mcfg.Workspace, qt.Equals, "/src/project/hugo.work")
+               c.Assert(mcfg.Workspace, qt.Equals, hugoWorkFilename)
 
                c.Assert(len(mcfg.Mounts), qt.Equals, 1)
                c.Assert(len(mcfg.Imports), qt.Equals, 1)
index 0d094fe87f738bbcf3bb64d7ef79b230a398bf3a..42bd94e7be165844b03ad978fe3c0ded70665053 100644 (file)
@@ -184,5 +184,7 @@ func (m *moduleAdapter) Watch() bool {
                return m.Replace().Version() == ""
        }
 
-       return false
+       // Any module set up in a workspace file will have Indirect set to false.
+       // That leaves modules inside the read-only module cache.
+       return !m.gomod.Indirect
 }