]> git.maquefel.me Git - brevno-suite/hugo/commitdiff
Fix a rebuild on resource rename case
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Sun, 15 Dec 2024 09:52:53 +0000 (10:52 +0100)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Mon, 16 Dec 2024 07:33:10 +0000 (08:33 +0100)
hugolib/hugo_sites_build.go
internal/js/esbuild/batch_integration_test.go

index 5346e2e6b2ea4f26610aecf46d3932ad9946b0fb..02ecd57855d772e224295d245069cbd8ab2e295f 100644 (file)
@@ -738,15 +738,15 @@ type pathChange struct {
        // The path to the changed file.
        p *paths.Path
 
-       // If true, this is a delete operation (a delete or a rename).
-       delete bool
+       // If true, this is a structural change (e.g. a delete or a rename).
+       structural bool
 
        // If true, this is a directory.
        isDir bool
 }
 
 func (p pathChange) isStructuralChange() bool {
-       return p.delete || p.isDir
+       return p.structural || p.isDir
 }
 
 func (h *HugoSites) processPartialRebuildChanges(ctx context.Context, l logg.LevelLogger, config *BuildCfg) error {
@@ -912,7 +912,7 @@ func (h *HugoSites) processPartialFileEvents(ctx context.Context, l logg.LevelLo
                                }
                        }
 
-                       addedOrChangedContent = append(addedOrChangedContent, pathChange{p: pathInfo, delete: delete, isDir: isDir})
+                       addedOrChangedContent = append(addedOrChangedContent, pathChange{p: pathInfo, structural: delete, isDir: isDir})
 
                case files.ComponentFolderLayouts:
                        tmplChanged = true
@@ -1033,6 +1033,16 @@ func (h *HugoSites) processPartialFileEvents(ctx context.Context, l logg.LevelLo
                handleChange(id, false, true)
        }
 
+       for _, id := range changes {
+               if id == identity.GenghisKhan {
+                       for i, cp := range addedOrChangedContent {
+                               cp.structural = true
+                               addedOrChangedContent[i] = cp
+                       }
+                       break
+               }
+       }
+
        resourceFiles := h.fileEventsContentPaths(addedOrChangedContent)
 
        changed := &WhatChanged{
index 07f99ee4e23f3d4317db2df3a90413ca2184b59f..3501f820a8682950ec0ebcd9498dea90d08af2c2 100644 (file)
@@ -184,6 +184,20 @@ func TestBatchEditScriptParam(t *testing.T) {
        b.AssertFileContent("public/mybatch/mygroup.js", "param-p1-main-edited")
 }
 
+func TestBatchRenameBundledScript(t *testing.T) {
+       files := jsBatchFilesTemplate
+       b := hugolib.TestRunning(t, files, hugolib.TestOptWithOSFs())
+       b.AssertFileContent("public/mybatch/p1.js", "P1 Script")
+       b.RenameFile("content/p1/p1script.js", "content/p1/p1script2.js")
+       _, err := b.BuildE()
+       b.Assert(err, qt.IsNotNil)
+       b.Assert(err.Error(), qt.Contains, "resource not set")
+
+       // Rename it back.
+       b.RenameFile("content/p1/p1script2.js", "content/p1/p1script.js")
+       b.Build()
+}
+
 func TestBatchErrorScriptResourceNotSet(t *testing.T) {
        files := strings.Replace(jsBatchFilesTemplate, `(resources.Get "js/main.js")`, `(resources.Get "js/doesnotexist.js")`, 1)
        b, err := hugolib.TestE(t, files, hugolib.TestOptWithOSFs())