Backtestshugorun-20261009-153657#15169

Issue #15169 Merged fix PR # Run 9 Oct 2026 · run-20261009-153657 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. TypeScript requires entries in compilerOptions.paths to be relative ('./' or '../') when baseUrl is unset. A normalizes every generated entry, so '*' becomes './*' and a nested root like 'sub/*' becomes './sub/*'. This keeps the mapping that lets VS Code resolve non-relative imports such as 'js/foo' from the assets directory, while removing the lint warning. Patch B instead skips the source root equal to the jsconfig directory. That removes the '*' entry, but it also drops that resolution mapping, which changes IDE behavior, and for a simple site with one root it returns nil so no jsconfig is produced at all. B also misses other non-relative entries, such as a source root nested under dir, which would still trigger the same lint. Tests: A adds a dedicated test covering the self root, a nested root and a sibling root, and checks the serialized JSON has no bare '*'; it would fail before the fix. B's test only checks that a lone self root yields nil, which validates its workaround rather than the lint condition. Both patches inherit the existing filepath separator behavior on Windows, so that does not separate them. A is more correct and better tested.

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

7m 16s

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

36vs 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+35 −1
resources/jsconfig/jsconfig.goindex 4aabf69f7..aed567059 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,16 @@ func (b *Builder) Build(dir string) *Config { 	return conf } +// toRelativePath makes sure that p is a relative path in the TypeScript sense,+// i.e. that it starts with "./" or "../". TypeScript does not allow+// non-relative paths in compilerOptions.paths when baseUrl is not set.+func toRelativePath(p string) string {+	if p == "." || p == ".." || strings.HasPrefix(p, "."+string(filepath.Separator)) || strings.HasPrefix(p, ".."+string(filepath.Separator)) {+		return p+	}+	return "." + string(filepath.Separator) + p+}+ // AddSourceRoot adds a new source root. // This method is thread safe. func (b *Builder) AddSourceRoot(root string) {resources/jsconfig/jsconfig_test.goindex ab9b739d1..4a5d3fa2f 100644@@ -38,3 +38,26 @@ func TestJsConfigBuilder(t *testing.T) {  	c.Assert(NewBuilder().Build("/a/b"), qt.IsNil) }++// Issue: VS Code lints non-relative paths in compilerOptions.paths when+// baseUrl is not set, e.g. "*" when jsconfig.json lives in the source root.+func TestJsConfigBuilderRelativePaths(t *testing.T) {+	c := qt.New(t)++	b := NewBuilder()+	b.AddSourceRoot("/a/assets")+	b.AddSourceRoot("/a/assets/sub")+	b.AddSourceRoot("/c/assets")++	conf := b.Build("/a/assets")+	c.Assert(conf.CompilerOptions.Paths["*"], qt.DeepEquals, []string{+		filepath.FromSlash("../../c/assets/*"),+		filepath.FromSlash("./*"),+		filepath.FromSlash("./sub/*"),+	})++	data, err := json.Marshal(conf)+	c.Assert(err, qt.IsNil)+	c.Assert(string(data), qt.Not(qt.Contains), `["*"`)+	c.Assert(string(data), qt.Not(qt.Contains), `,"*"`)+} 
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) }