Backtestshugorun-20261005-133023#15169

Issue #15169 Merged fix PR # Run 5 Oct 2026 · run-20261005-133023 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 B = our agent, Patch A = the merged fix.

Patch B fixes the root cause. TypeScript and VS Code reject non-relative entries in `paths` when `baseUrl` is unset, so B adds a `./` prefix to every entry that does not already start with `../`. The generated config stays valid and keeps the same mapping: `./*` still lets VS Code resolve bare imports like `imp1/index.js` against the assets dir. It also covers sub-roots such as `/a/assets/sub`, which would otherwise produce the non-relative `sub/*`. B's unit test checks parent-relative, same-dir and sub-dir cases. Its integration test reads the generated `assets/jsconfig.json` and asserts `./*`; it would fail before the change. Updating the checked-in `docs/assets/jsconfig.json` is consistent with the change. Patch A takes a different route and skips the root equal to `dir`. In the common single-root case this produces no jsconfig at all, which removes the lint warning but also removes the path mapping that gave editor resolution for non-relative imports. That masks the symptom rather than fixing the format. A also leaves sub-roots non-relative (e.g. `sub/*`), so the same warning can still appear. Its test only asserts a nil config, which checks the suppression rather than validity. B 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

33m 43s

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

59vs 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+57 −2
docs/assets/jsconfig.jsonindex 8f9413a6b..57c6f02ed 100644@@ -2,7 +2,7 @@  "compilerOptions": {   "paths": {    "*": [-    "*"+    "./*"    ]   }  }resources/jsconfig/jsconfig.goindex 4aabf69f7..723db3d76 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,15 @@ func (b *Builder) Build(dir string) *Config { 	return conf } +// toRelativePath makes sure rel starts with "./" or "../".+// Without baseUrl, TypeScript (and VS Code) reject non-relative entries in paths.+func toRelativePath(rel string) string {+	if rel == ".." || strings.HasPrefix(rel, ".."+string(filepath.Separator)) {+		return rel+	}+	return "." + string(filepath.Separator) + rel+}+ // AddSourceRoot adds a new source root. // This method is thread safe. func (b *Builder) AddSourceRoot(root string) {resources/jsconfig/jsconfig_test.goindex ab9b739d1..843855a4c 100644@@ -38,3 +38,20 @@ func TestJsConfigBuilder(t *testing.T) {  	c.Assert(NewBuilder().Build("/a/b"), qt.IsNil) }++// Non-relative paths are not allowed when baseUrl is not set.+func TestJsConfigBuilderPathsAreRelative(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/*"),+	})+}resources/resource_transformers/js/js_integration_test.goindex 2244e8f8e..66d7b3256 100644@@ -14,6 +14,7 @@ package js_test  import (+	"encoding/json" 	"os" 	"path/filepath" 	"strings"@@ -343,6 +344,33 @@ IMPORT_SRC_DIR:imp3/foo.ts 	} } +// The paths in the generated jsconfig.json must be relative (start with ./ or ../),+// as non-relative paths are not allowed when baseUrl is not set.+func TestJSConfigInAssetsRelativePaths(t *testing.T) {+	files := `+-- hugo.toml --+disableKinds = ['page','rss','section','sitemap','taxonomy','term']+-- assets/imp1/index.js --+console.log("imp1");+-- assets/js/main.js --+import 'imp1/index.js';+-- layouts/home.html --+{{ $js := resources.Get "js/main.js" | js.Build }}+{{ $js.RelPermalink }}+`++	b := hugolib.Test(t, files, hugolib.TestOptOsFs())++	b.AssertFileContent("public/js/main.js", "imp1")+	var jsConfig struct {+		CompilerOptions struct {+			Paths map[string][]string `json:"paths"`+		} `json:"compilerOptions"`+	}+	b.Assert(json.Unmarshal([]byte(b.FileContent("assets/jsconfig.json")), &jsConfig), qt.IsNil)+	b.Assert(jsConfig.CompilerOptions.Paths["*"], qt.DeepEquals, []string{filepath.FromSlash("./*")})+}+ // See https://github.com/evanw/esbuild/issues/2745 func TestPreserveLegalComments(t *testing.T) { 	t.Parallel() 
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) }