]> git.maquefel.me Git - brevno-suite/hugo/commitdiff
modules: Make the module.workspace=off as default (note)
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Mon, 19 Dec 2022 14:40:47 +0000 (15:40 +0100)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Mon, 19 Dec 2022 19:17:33 +0000 (20:17 +0100)
Also, resolve any workspace file relative to the workingDir.

Fixes #10553

hugolib/hugo_sites_build_test.go
hugolib/page_permalink_test.go
modules/config.go
modules/config_test.go

index c31f94713045ea9aa98475169cb20d637eed86f4..d7e8a89c4d635ffc72ebba25c0fed6085908d600 100644 (file)
@@ -206,6 +206,7 @@ func TestMultiSitesBuild(t *testing.T) {
                {multiSiteYAMLConfigTemplate, "yml"},
                {multiSiteJSONConfigTemplate, "json"},
        } {
+               config := config
                t.Run(config.suffix, func(t *testing.T) {
                        t.Parallel()
                        doTestMultiSitesBuild(t, config.content, config.suffix)
index 0939cc1ff510ef5938b5811755b662b5bf305a3c..7ea672330f488166e3848be43ea3e9822d175a36 100644 (file)
@@ -63,6 +63,7 @@ func TestPermalink(t *testing.T) {
        }
 
        for i, test := range tests {
+               i := i
                test := test
                t.Run(fmt.Sprintf("%s-%d", test.file, i), func(t *testing.T) {
                        t.Parallel()
index 08154bc110fa8413d563960c31c7b7de26252f2e..86166300a6338d440541b8528542616693989958 100644 (file)
@@ -26,6 +26,8 @@ import (
        "github.com/mitchellh/mapstructure"
 )
 
+const WorkspaceDisabled = "off"
+
 var DefaultModuleConfig = Config{
 
        // Default to direct, which means "git clone" and similar. We
@@ -41,6 +43,9 @@ var DefaultModuleConfig = Config{
        // treated as private.
        Private: "*.*",
 
+       // Default is no workspace resolution.
+       Workspace: WorkspaceDisabled,
+
        // A list of replacement directives mapping a module path to a directory
        // or a theme component in the themes folder.
        // Note that this will turn the component into a traditional theme component
@@ -247,6 +252,16 @@ func decodeConfig(cfg config.Provider, pathReplacements map[string]string) (Conf
                        c.Mounts[i] = mnt
                }
 
+               if c.Workspace == "" {
+                       c.Workspace = WorkspaceDisabled
+               }
+               if c.Workspace != WorkspaceDisabled {
+                       c.Workspace = filepath.Clean(c.Workspace)
+                       if !filepath.IsAbs(c.Workspace) {
+                               workingDir := cfg.GetString("workingDir")
+                               c.Workspace = filepath.Join(workingDir, c.Workspace)
+                       }
+               }
        }
 
        if themeSet {
@@ -294,8 +309,9 @@ type Config struct {
        // Configures GOPRIVATE.
        Private string
 
-       // Set the workspace file to use, e.g. hugo.work.
-       // Enables Go "Workspace" mode.
+       // Defaults to "off".
+       // Set to a work file, e.g. hugo.work, to enable Go "Workspace" mode.
+       // Can be relative to the working directory or absolute.
        // Requires Go 1.18+
        // See https://tip.golang.org/doc/go1.18
        Workspace string
index 371aab0561714d0b82e015c767fe3ec88af66554..4ded2be66a1cbaa55459a4c850974b3812f08648 100644 (file)
@@ -44,13 +44,13 @@ func TestDecodeConfig(t *testing.T) {
 
        c.Run("Basic", func(c *qt.C) {
                tomlConfig := `
+workingDir = "/src/project"
 [module]
-
+workspace = "hugo.work"
 [module.hugoVersion]
 min = "0.54.2"
 max = "0.199.0"
 extended = true
-
 [[module.mounts]]
 source="src/project/blog"
 target="content/blog"
@@ -83,6 +83,8 @@ lang="en"
                        c.Assert(hv.IsValid(), qt.Equals, true)
                }
 
+               c.Assert(mcfg.Workspace, qt.Equals, "/src/project/hugo.work")
+
                c.Assert(len(mcfg.Mounts), qt.Equals, 1)
                c.Assert(len(mcfg.Imports), qt.Equals, 1)
                imp := mcfg.Imports[0]
@@ -90,6 +92,7 @@ lang="en"
                c.Assert(imp.Mounts[1].Source, qt.Equals, "src/markdown/blog")
                c.Assert(imp.Mounts[1].Target, qt.Equals, "content/blog")
                c.Assert(imp.Mounts[1].Lang, qt.Equals, "en")
+
        })
 
        c.Run("Replacements", func(c *qt.C) {