Backtestshugorun-20261024-162305#15169

Issue #15169 Merged fix PR # Run 24 Oct 2026 · run-20261024-162305 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: every mapping emitted into compilerOptions.paths is made relative (prefixed with './' unless it already starts with '..'), which is exactly what the VS Code/TypeScript rule demands when baseUrl is unset. It covers the project's own assets ('./*'), themes/modules ('../...'), and nested mounts inside assets ('./sub/*'). Patch B instead sidesteps the symptom by dropping the mapping for the current directory, so in the single-root case no jsconfig.json is written at all. That avoids the lint notice for the simplest site but leaves any other root that resolves to a non-'..' relative path (e.g. a mount whose source lies inside assets, yielding 'sub/*') still non-relative and still flagged. The independent tests confirm this: both patches pass the project-only and theme scenarios, but only A passes the nested-mount scenario while B fails it. B also silently changes behaviour (no file emitted) rather than fixing the content. Tests: A adds a dedicated test asserting the relative forms for mixed roots plus the JSON shape, which would fail on base; B's added assertion only checks the nil case. Scope and craft: A's helper is small, documented, and uses filepath.Separator consistently with the existing filepath.Rel usage; the docs/assets/jsconfig.json tweak is a trivial, consistent companion change. A is clearly the better fix.

Four judges ruled on this ticket in parallel, and the verdict comes from counting their votes. Each saw the issue and the two patches, labelled A and B in random order (two of them saw ours as A), with issue links and version numbers removed. Where tests could check the fix, they also saw the results of tests a separate agent wrote for the issue, run on both patches. None was told which patch was ours. The reasoning above is one judge's, shown verbatim.

Solve

43m 36s

Wall-clock time in the container

Full test suite

No new failures

47 passed · 0 skipped · 47 total

Contamination audit

Clean

No sign the agent saw the real fix

Patch size

41vs 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+39 −2
docs/assets/jsconfig.jsonindex 8f9413a6b..57c6f02ed 100644@@ -2,7 +2,7 @@  "compilerOptions": {   "paths": {    "*": [-    "*"+    "./*"    ]   }  }resources/jsconfig/jsconfig.goindex 4aabf69f7..57d10f3cb 100644@@ -16,6 +16,7 @@ package jsconfig import ( 	"path/filepath" 	"sort"+	"strings"  	"github.com/bep/helpers/maphelpers" )@@ -41,7 +42,7 @@ func (b *Builder) Build(dir string) *Config { 	for root := range b.sourceRoots.All() { 		rel, err := filepath.Rel(dir, filepath.Join(root, "*")) 		if err == nil {-			roots = append(roots, rel)+			roots = append(roots, toRelativePath(rel)) 		} 	} 	if len(roots) == 0 {@@ -53,6 +54,17 @@ func (b *Builder) Build(dir string) *Config { 	return conf } +// toRelativePath makes sure that rel starts with "./" or "../".+// TypeScript (and VS Code) does not allow non-relative paths in+// compilerOptions.paths when baseUrl is not set.+func toRelativePath(rel string) string {+	sep := string(filepath.Separator)+	if rel == ".." || strings.HasPrefix(rel, ".."+sep) {+		return rel+	}+	return "." + sep + rel+}+ // AddSourceRoot adds a new source root. // This method is thread safe. func (b *Builder) AddSourceRoot(root string) {resources/jsconfig/jsconfig_test.goindex ab9b739d1..d95abdb7d 100644@@ -38,3 +38,28 @@ func TestJsConfigBuilder(t *testing.T) {  	c.Assert(NewBuilder().Build("/a/b"), qt.IsNil) }++// Issue 14991: paths must be relative (start with ./ or ../) as baseUrl is not set.+func TestJsConfigBuilderRelativePaths(t *testing.T) {+	c := qt.New(t)++	b := NewBuilder()+	b.AddSourceRoot("/a/b")+	b.AddSourceRoot("/a/b/sub")+	b.AddSourceRoot("/a/..c/assets")++	conf := b.Build("/a/b")+	c.Assert(conf.CompilerOptions.Paths["*"], qt.DeepEquals, []string{+		filepath.FromSlash("../..c/assets/*"),+		filepath.FromSlash("./*"),+		filepath.FromSlash("./sub/*"),+	})++	b = NewBuilder()+	b.AddSourceRoot("/a/b")+	data, err := json.Marshal(b.Build("/a/b"))+	c.Assert(err, qt.IsNil)+	expected, err := json.Marshal(map[string]any{"compilerOptions": map[string]any{"paths": map[string][]string{"*": {filepath.FromSlash("./*")}}}})+	c.Assert(err, qt.IsNil)+	c.Assert(string(data), qt.Equals, string(expected))+} 
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) }