Repository: gohugoio/hugo (language: go)

Issue:
Data race in JS minify
Looks like an old issue, but somehow fails my test today, so I need to fix it.

See https://github.com/tdewolff/minify/issues/582


Discussion / hints:

Fix patch:
diff --git a/commands/commandeer.go b/commands/commandeer.go
index 912a55780ec..08f959579b0 100644
--- a/commands/commandeer.go
+++ b/commands/commandeer.go
@@ -339,7 +339,7 @@ func (r *rootCommand) Run(ctx context.Context, cd *simplecobra.Commandeer, args
 
 	b := newHugoBuilder(r, nil)
 
-	if err := b.loadConfig(cd, true); err != nil {
+	if err := b.loadConfig(cd, false); err != nil {
 		return err
 	}
 
diff --git a/commands/server.go b/commands/server.go
index b42cb1ed32c..a288bb2c806 100644
--- a/commands/server.go
+++ b/commands/server.go
@@ -204,7 +204,7 @@ func (f *fileServer) createEndpoint(i int) (*http.ServeMux, net.Listener, string
 	listener := f.c.serverPorts[i].ln
 	logger := f.c.r.logger
 
-	r.Printf("Environment: %q", f.c.hugoTry().Deps.Site.Hugo().Environment)
+	r.Printf("Environment: %q\n", f.c.hugoTry().Deps.Site.Hugo().Environment)
 
 	if i == 0 {
 		if f.c.renderToDisk {
diff --git a/hugolib/hugo_sites_build.go b/hugolib/hugo_sites_build.go
index 3464385d33e..c801ae3dff6 100644
--- a/hugolib/hugo_sites_build.go
+++ b/hugolib/hugo_sites_build.go
@@ -185,7 +185,7 @@ func (h *HugoSites) initRebuild(config *BuildCfg) error {
 		return errors.New("rebuild does not support 'ResetState'")
 	}
 
-	if !h.Configs.Base.Internal.Running {
+	if !h.Configs.Base.Internal.Watch {
 		return errors.New("rebuild called when not in watch mode")
 	}
 
diff --git a/hugolib/page.go b/hugolib/page.go
index 2e6b6c36fab..2644c8e4e34 100644
--- a/hugolib/page.go
+++ b/hugolib/page.go
@@ -583,7 +583,7 @@ var defaultRenderStringOpts = renderStringOpts{
 }
 
 func (p *pageState) addDependency(dep identity.Provider) {
-	if !p.s.running() || p.pageOutput.cp == nil {
+	if !p.s.watching() || p.pageOutput.cp == nil {
 		return
 	}
 	p.pageOutput.cp.dependencyTracker.Add(dep)
diff --git a/hugolib/page__per_output.go b/hugolib/page__per_output.go
index 4817d9a0c9d..65809a37786 100644
--- a/hugolib/page__per_output.go
+++ b/hugolib/page__per_output.go
@@ -76,7 +76,7 @@ func newPageContentOutput(p *pageState, po *pageOutput) (*pageContentOutput, err
 	parent := p.init
 
 	var dependencyTracker identity.Manager
-	if p.s.running() {
+	if p.s.watching() {
 		dependencyTracker = identity.NewManager(pageContentOutputDependenciesID)
 	}
 
diff --git a/hugolib/site.go b/hugolib/site.go
index 8e220f63369..d23a903856e 100644
--- a/hugolib/site.go
+++ b/hugolib/site.go
@@ -389,8 +389,8 @@ func (s *siteRefLinker) refLink(ref string, source any, relative bool, outputFor
 	return link, nil
 }
 
-func (s *Site) running() bool {
-	return s.h != nil && s.h.Configs.Base.Internal.Running
+func (s *Site) watching() bool {
+	return s.h != nil && s.h.Configs.Base.Internal.Watch
 }
 
 type whatChanged struct {
@@ -1064,7 +1064,7 @@ func (s *Site) renderAndWritePage(statCounter *uint64, name string, targetPath s
 			pd.AbsURLPath = s.absURLPath(targetPath)
 		}
 
-		if s.running() && s.conf.Internal.Watch && !s.conf.Internal.DisableLiveReload {
+		if s.watching() && s.conf.Internal.Watch && !s.conf.Internal.DisableLiveReload {
 			pd.LiveReloadBaseURL = s.Conf.BaseURLLiveReload().URL()
 		}
 
diff --git a/hugolib/site_new.go b/hugolib/site_new.go
index 1262cc3aeea..e5398ba8d3d 100644
--- a/hugolib/site_new.go
+++ b/hugolib/site_new.go
@@ -280,7 +280,7 @@ func newHugoSitesNew(cfg deps.DepsCfg, d *deps.Deps, sites []*Site) (*HugoSites,
 	}
 
 	// Only needed in server mode.
-	if cfg.Configs.Base.Internal.Running {
+	if cfg.Configs.Base.Internal.Watch {
 		h.ContentChanges = &contentChangeMap{
 			pathSpec:      h.PathSpec,
 			symContent:    make(map[string]map[string]bool),
diff --git a/minifiers/config.go b/minifiers/config.go
index 437a72e9db5..58271362d9a 100644
--- a/minifiers/config.go
+++ b/minifiers/config.go
@@ -40,7 +40,9 @@ var defaultTdewolffConfig = TdewolffConfig{
 		Precision: 0,
 		KeepCSS2:  true,
 	},
-	JS:   js.Minifier{},
+	JS: js.Minifier{
+		Version: 2022,
+	},
 	JSON: json.Minifier{},
 	SVG: svg.Minifier{
 		KeepComments: false,


Test patch:
diff --git a/hugolib/integrationtest_builder.go b/hugolib/integrationtest_builder.go
index 02add495c1e..4993d922a54 100644
--- a/hugolib/integrationtest_builder.go
+++ b/hugolib/integrationtest_builder.go
@@ -327,6 +327,7 @@ func (s *IntegrationTestBuilder) initBuilder() error {
 		if s.Cfg.Running {
 			flags.Set("internal", maps.Params{
 				"running": s.Cfg.Running,
+				"watch":   s.Cfg.Running,
 			})
 		}
 
diff --git a/hugolib/testhelpers_test.go b/hugolib/testhelpers_test.go
index 0ba861fdb81..7cf1a55965b 100644
--- a/hugolib/testhelpers_test.go
+++ b/hugolib/testhelpers_test.go
@@ -486,6 +486,7 @@ func (s *sitesBuilder) LoadConfig() error {
 	flags := config.New()
 	flags.Set("internal", map[string]any{
 		"running": s.running,
+		"watch":   s.running,
 	})
 
 	if s.workingDir != "" {
diff --git a/testscripts/commands/hugo.txt b/testscripts/commands/hugo.txt
index 7dfabe59203..9907f525856 100644
--- a/testscripts/commands/hugo.txt
+++ b/testscripts/commands/hugo.txt
@@ -5,12 +5,13 @@ stdout 'Pages.*|1'
 stdout 'Total in'
 checkfile public/index.html
 checkfile public/p1/index.html
+grep 'IsServer: false' public/index.html
 
 -- hugo.toml --
 baseURL = "http://example.org/"
 disableKinds = ["RSS", "sitemap", "robotsTXT", "404", "taxonomy", "term"]
 -- layouts/index.html --
-Home.
+Home|IsServer: {{ .Site.IsServer }}|
 -- layouts/_default/single.html --
 Title: {{ .Title }}
 -- content/p1.md --