diff --git a/CHANGELOG.md b/CHANGELOG.md index 4e152339446..188f58fed36 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,10 @@ Syntax trees with millions of sequential binary operators nested inside each other can cause the parser to stack overflow because it uses a recursive visitor pattern, so each binary operator added an entry to the call stack. Now code like this no longer triggers a stack overflow because the visitor uses the heap instead of the stack in this case. This is unlikely to matter in real-world code but can show up in certain artificial test cases, especially when `--minify-syntax` is enabled. +* Resolve implicitly-named `tsconfig.json` base files ([#279](https://github.com/evanw/esbuild/issues/279)) + + The official TypeScript compiler lets you specify a package path as the `extends` property of a `tsconfig.json` file. The base file is then searched for in the relevant `node_modules` directory. Previously the package path had to end with the name of the base file. Now you can additionally omit the name of the base file if the file name is `tsconfig.json`. This more closely matches the behavior of the official TypeScript compiler. + ## 0.6.8 * Attempt to support the taobao.org registry ([#291](https://github.com/evanw/esbuild/issues/291)) diff --git a/internal/bundler/bundler_tsconfig_test.go b/internal/bundler/bundler_tsconfig_test.go index 3c4d1a829b1..f4f1840d5bd 100644 --- a/internal/bundler/bundler_tsconfig_test.go +++ b/internal/bundler/bundler_tsconfig_test.go @@ -682,3 +682,36 @@ console.log("good"); }, }) } + +func TestTsconfigJsonNodeModulesImplicitFile(t *testing.T) { + expectBundled(t, bundled{ + files: map[string]string{ + "/Users/user/project/src/app/entry.tsx": ` + console.log(
) + `, + "/Users/user/project/src/tsconfig.json": ` + { + "extends": "foo" + } + `, + "/Users/user/project/src/node_modules/foo/tsconfig.json": ` + { + "compilerOptions": { + "jsx": "react", + "jsxFactory": "worked" + } + } + `, + }, + entryPaths: []string{"/Users/user/project/src/app/entry.tsx"}, + options: config.Options{ + IsBundling: true, + AbsOutputFile: "/Users/user/project/out.js", + }, + expected: map[string]string{ + "/Users/user/project/out.js": `// /Users/user/project/src/app/entry.tsx +console.log(/* @__PURE__ */ worked("div", null)); +`, + }, + }) +} diff --git a/internal/resolver/resolver.go b/internal/resolver/resolver.go index 6cc4944d934..7f63effe670 100644 --- a/internal/resolver/resolver.go +++ b/internal/resolver/resolver.go @@ -424,8 +424,9 @@ func (r *resolver) parseJsTsConfig(file string, visited map[string]bool) (*tsCon for !found { // Skip "node_modules" folders if r.fs.Base(current) != "node_modules" { - extendsFile := r.fs.Join(current, "node_modules", extends) - for _, fileToCheck := range []string{extendsFile, extendsFile + ".json"} { + join := r.fs.Join(current, "node_modules", extends) + filesToCheck := []string{join, join + ".json", r.fs.Join(join, "tsconfig.json")} + for _, fileToCheck := range filesToCheck { base, baseStatus := r.parseJsTsConfig(fileToCheck, visited) if baseStatus == parseReadFailure { continue