Repository: gohugoio/hugo (language: go)

Issue:
index.{scss,sass} files not handled in imports
Hot reload does not work properly when changing files in assets sub-subfolders (eg, `assets/styles/components/_container.scss`). The server detects a change, but new styles are not applied. 

If you change a file that triggers the rebuild correctly, assets from subfolders also trigger it correctly from that point on.

Minimal reproduction repository: https://github.com/martinjagodic/hugo-sass-debug

### What version of Hugo are you using (`hugo version`)?

<pre>
$ hugo version
v0.139.3+extended+withdeploy darwin/arm64 BuildDate=2024-11-29T15:36:56Z VendorInfo=brew
</pre>

### Does this issue reproduce with the latest release?

Yes. The bug started in v0.123.0 but is still present in v0.139.3. Tested only with hugo extended.


Discussion / hints:
A workaround may be to set up some cache busting config, see https://gohugo.io/getting-started/configuration-build/#configure-cache-busters -- e.g.:

```toml
[build]
  [[build.cachebusters]]
    source = 'assets/.*\.(scss|sass)'
    target = 'css'
```


I had a quick look at the repo, and the reason that particular repo does not work is that Hugo's custom import resolver does not currently resolve `index.scss` files. If you rename that file to `_index.scss` things start working.

Fix patch:
diff --git a/resources/resource_transformers/tocss/dartsass/transform.go b/resources/resource_transformers/tocss/dartsass/transform.go
index c5f97abff3e..0d7b570627d 100644
--- a/resources/resource_transformers/tocss/dartsass/transform.go
+++ b/resources/resource_transformers/tocss/dartsass/transform.go
@@ -170,6 +170,7 @@ func (t importResolver) CanonicalizeURL(url string) (string, error) {
 			"_%s.sass", "%s.sass",
 			"_%s.css", "%s.css",
 			"%s/_index.scss", "%s/_index.sass",
+			"%s/index.scss", "%s/index.sass",
 		}
 	}
 
diff --git a/resources/resource_transformers/tocss/scss/tocss.go b/resources/resource_transformers/tocss/scss/tocss.go
index 4b9c51ce05f..89e95b2f8bd 100644
--- a/resources/resource_transformers/tocss/scss/tocss.go
+++ b/resources/resource_transformers/tocss/scss/tocss.go
@@ -109,6 +109,7 @@ func (t *toCSSTransformation) Transform(ctx *resources.ResourceTransformationCtx
 				"_%s.scss", "%s.scss",
 				"_%s.sass", "%s.sass",
 				"%s/_index.scss", "%s/_index.sass",
+				"%s/index.scss", "%s/index.sass",
 			}
 		}
 


Test patch:
diff --git a/resources/resource_transformers/tocss/dartsass/dartsass_integration_test.go b/resources/resource_transformers/tocss/dartsass/dartsass_integration_test.go
index 5d1b89eaf08..293fdfbcf86 100644
--- a/resources/resource_transformers/tocss/dartsass/dartsass_integration_test.go
+++ b/resources/resource_transformers/tocss/dartsass/dartsass_integration_test.go
@@ -577,23 +577,25 @@ disableKinds = ['page','section','rss','sitemap','taxonomy','term']
 [[module.mounts]]
 source = 'assets'
 target = 'assets'
-
-[[module.imports]]
-path = "github.com/gohugoio/hugoTestModule2"
-
-[[module.imports.mounts]]
+[[module.mounts]]
 source = "miscellaneous/sass"
 target = "assets/sass"
--- go.mod --
-module hugo-github-issue-12849
 -- layouts/index.html --
 {{ $opts := dict "transpiler" "dartsass" "outputStyle" "compressed" }}
 {{ (resources.Get "sass/main.scss" | toCSS $opts).Content }}
 -- assets/sass/main.scss --
-@use "foo"; // directory with index file from OS file system
-@use "bar"; // directory with index file from module mount
--- assets/sass/foo/_index.scss --
-.foo {color: red;}
+@use "foo1"; // directory with _index file from OS file system
+@use "bar1"; // directory with _index file from module mount
+@use "foo2"; // directory with index file from OS file system
+@use "bar2"; // directory with index file from module mount
+-- assets/sass/foo1/_index.scss --
+.foo1 {color: red;}
+-- miscellaneous/sass/bar1/_index.scss --
+.bar1 {color: blue;}
+-- assets/sass/foo2/index.scss --
+.foo2 {color: red;}
+-- miscellaneous/sass/bar2/index.scss --
+.bar2 {color: blue;}
 `
 
 	b := hugolib.NewIntegrationTestBuilder(
@@ -603,7 +605,7 @@ module hugo-github-issue-12849
 			TxtarString: files,
 		}).Build()
 
-	b.AssertFileContent("public/index.html", ".foo{color:red}.bar{color:green}")
+	b.AssertFileContent("public/index.html", ".foo1{color:red}.bar1{color:blue}.foo2{color:red}.bar2{color:blue}")
 }
 
 func TestIgnoreDeprecationWarnings(t *testing.T) {
diff --git a/resources/resource_transformers/tocss/scss/scss_integration_test.go b/resources/resource_transformers/tocss/scss/scss_integration_test.go
index 10309ad20e2..0154a463412 100644
--- a/resources/resource_transformers/tocss/scss/scss_integration_test.go
+++ b/resources/resource_transformers/tocss/scss/scss_integration_test.go
@@ -432,23 +432,25 @@ disableKinds = ['page','section','rss','sitemap','taxonomy','term']
 [[module.mounts]]
 source = 'assets'
 target = 'assets'
-
-[[module.imports]]
-path = "github.com/gohugoio/hugoTestModule2"
-
-[[module.imports.mounts]]
+[[module.mounts]]
 source = "miscellaneous/sass"
 target = "assets/sass"
--- go.mod --
-module hugo-github-issue-12849
 -- layouts/index.html --
 {{ $opts := dict "transpiler" "libsass" "outputStyle" "compressed" }}
 {{ (resources.Get "sass/main.scss" | toCSS $opts).Content }}
 -- assets/sass/main.scss --
-@import "foo"; // directory with index file from OS file system
-@import "bar"; // directory with index file from module mount
--- assets/sass/foo/_index.scss --
-.foo {color: red;}
+@import "foo1"; // directory with _index file from OS file system
+@import "bar1"; // directory with _index file from module mount
+@import "foo2"; // directory with index file from OS file system
+@import "bar2"; // directory with index file from module mount
+-- assets/sass/foo1/_index.scss --
+.foo1 {color: red;}
+-- miscellaneous/sass/bar1/_index.scss --
+.bar1 {color: blue;}
+-- assets/sass/foo2/index.scss --
+.foo2 {color: red;}
+-- miscellaneous/sass/bar2/index.scss --
+.bar2 {color: blue;}
 `
 
 	b := hugolib.NewIntegrationTestBuilder(
@@ -458,5 +460,5 @@ module hugo-github-issue-12849
 			TxtarString: files,
 		}).Build()
 
-	b.AssertFileContent("public/index.html", ".foo{color:red}.bar{color:green}")
+	b.AssertFileContent("public/index.html", ".foo1{color:red}.bar1{color:blue}.foo2{color:red}.bar2{color:blue}")
 }