Backtestshugorun-20261007-020926#15169

Issue #15169 Merged fix PR # Run 7 Oct 2026 · run-20261007-020926 gohugoio/hugo

resources/jsconfig: Address VS Code linting notice in jsconfig.json

Better

Our patch was judged better than the merged fix.

In this judgment, Patch A = our agent, Patch B = the merged fix.

Patch A fixes the root cause. The VS Code notice fires because a mapping target is non-relative while baseUrl is unset. Patch A prefixes './' to every generated target that does not already start with '../', so all source roots become valid relative mappings. That includes the reported "*": ["*"] case, which becomes "./*", and nested roots like 'c/*', which become './c/*'. The '*' mapping is kept, so editors can still resolve non-relative imports such as 'js/util.js' from the assets directory. Without baseUrl, removing that mapping would leave those imports unresolved. Patch B instead skips the source root equal to the config directory. For the single-root example this makes Build return nil, so the lint warning goes away only because the mapping is gone, and the import-resolution benefit is lost with it. B also leaves the problem in place for any other root under the directory: Build('/a/b') with root '/a/b/c' still emits the non-relative 'c/*'. On tests, A adds a unit test covering same-dir, child and parent roots, plus an integration test that checks the exact jsconfig.json content. Both would fail before the fix. B adds only a nil-config assertion for the single-root case. Both patches are small in scope. A wins on correctness and on test coverage.

The judge saw only the two patches, labelled A and B in random order, with issue links and version numbers removed. The reasoning above is shown verbatim.

Solve

42m 29s

Wall-clock time in the container

Full test suite

No new failures

3,697 passed · 99 skipped · 3,805 total

Contamination audit

Clean

No sign the agent saw the real fix

Patch size

49vs 11 merged

Changed lines, ours vs merged

When building a site that calls js.Build, the assets/jsconfig.json file looks like this:

{
 "compilerOptions": {
  "paths": {
   "*": [
    "*"
   ]
  }
 }
}

VS Code lints line 5 as follows:

Non-relative paths are not allowed when 'baseUrl' is not set. Did you forget a leading './'?

The two patches

Our patch+49 −0
resources/jsconfig/jsconfig.goindex 4aabf69f7..c5a6a3161 100644@@ -16,6 +16,7 @@ package jsconfig import ( 	"path/filepath" 	"sort"+	"strings"  	"github.com/bep/helpers/maphelpers" )@@ -41,6 +42,11 @@ func (b *Builder) Build(dir string) *Config { 	for root := range b.sourceRoots.All() { 		rel, err := filepath.Rel(dir, filepath.Join(root, "*")) 		if err == nil {+			// Path mappings must be relative (start with ./ or ../)+			// when baseUrl is not set.+			if !strings.HasPrefix(rel, ".."+string(filepath.Separator)) {+				rel = "." + string(filepath.Separator) + rel+			} 			roots = append(roots, rel) 		} 	}resources/jsconfig/jsconfig_test.goindex ab9b739d1..42d78b33a 100644@@ -38,3 +38,20 @@ func TestJsConfigBuilder(t *testing.T) {  	c.Assert(NewBuilder().Build("/a/b"), qt.IsNil) }++func TestJsConfigBuilderRelativePaths(t *testing.T) {+	c := qt.New(t)++	b := NewBuilder()+	b.AddSourceRoot("/a/b")+	b.AddSourceRoot("/a/b/c")+	b.AddSourceRoot("/a/d")++	// Non-relative paths are not allowed when baseUrl is not set.+	conf := b.Build("/a/b")+	c.Assert(conf.CompilerOptions.Paths["*"], qt.DeepEquals, []string{+		filepath.FromSlash("../d/*"),+		filepath.FromSlash("./*"),+		filepath.FromSlash("./c/*"),+	})+}resources/resource_transformers/js/js_integration_test.goindex 2244e8f8e..37bb713ce 100644@@ -431,6 +431,32 @@ Home. 	b.AssertFileContent("public/js/main.js", "! abcd") } +func TestJSConfigRelativePaths(t *testing.T) {+	files := `+-- assets/js/util.js --+export function hello() {+	return 'abcd';+}+-- assets/js/main.js --+import { hello } from 'js/util.js';++hello();+-- layouts/home.html --+Home.+{{ $js := resources.Get "js/main.js" | js.Build }}+{{ $js.Publish }}+`++	b := hugolib.Test(t, files, hugolib.TestOptOsFs())++	b.AssertFileContent("public/js/main.js", "abcd")++	filename := filepath.Join(b.H.Configs.Base.WorkingDir, "assets", "jsconfig.json")+	data, err := os.ReadFile(filename)+	b.Assert(err, qt.IsNil)+	b.Assert(string(data), qt.Equals, "{\n \"compilerOptions\": {\n  \"paths\": {\n   \"*\": [\n    \""+strings.ReplaceAll(filepath.FromSlash("./*"), `\`, `\\`)+"\"\n   ]\n  }\n }\n}")+}+ func TestBuildErrorStack(t *testing.T) { 	files := ` -- hugo.toml -- 
Merged fix · PR #+11 −0
resources/jsconfig/jsconfig.goindex 4aabf69f7..d347cab19 100644@@ -39,6 +39,11 @@ func (b *Builder) Build(dir string) *Config { 	} 	var roots []string 	for root := range b.sourceRoots.All() {+		if root == dir {+			// We need mappings for other source roots (e.g. mounted modules), but not for the current one.+			// See issue 15169.+			continue+		} 		rel, err := filepath.Rel(dir, filepath.Join(root, "*")) 		if err == nil { 			roots = append(roots, rel)resources/jsconfig/jsconfig_test.goindex ab9b739d1..1fb8ef3cd 100644@@ -37,4 +37,10 @@ func TestJsConfigBuilder(t *testing.T) { 	c.Assert(string(data), qt.Not(qt.Contains), "baseUrl")  	c.Assert(NewBuilder().Build("/a/b"), qt.IsNil)++	// Issue 15169.+	b = NewBuilder()+	b.AddSourceRoot("/c/assets")+	conf = b.Build("/c/assets")+	c.Assert(conf, qt.IsNil) }