fix(tsconfig): prioritize deno.json if it has compiler options (#30056)

This commit is contained in:
Nayeem Rahman 2025-07-10 19:46:34 +01:00 committed by GitHub
parent 6c736b1345
commit a046f2c1bf
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
32 changed files with 136 additions and 84 deletions

View file

@ -1114,6 +1114,12 @@ impl CompilerOptionsResolver {
} }
pub fn for_specifier(&self, specifier: &Url) -> &CompilerOptionsData { pub fn for_specifier(&self, specifier: &Url) -> &CompilerOptionsData {
let workspace_data = self.workspace_configs.get_for_specifier(specifier);
if !workspace_data
.sources
.iter()
.any(|s| s.compiler_options.is_some())
{
if let Ok(path) = url_to_file_path(specifier) { if let Ok(path) = url_to_file_path(specifier) {
for ts_config in &self.ts_configs { for ts_config in &self.ts_configs {
if ts_config.filter.includes_path(&path) { if ts_config.filter.includes_path(&path) {
@ -1121,13 +1127,21 @@ impl CompilerOptionsResolver {
} }
} }
} }
self.workspace_configs.get_for_specifier(specifier) }
workspace_data
} }
pub fn entry_for_specifier( pub fn entry_for_specifier(
&self, &self,
specifier: &Url, specifier: &Url,
) -> (CompilerOptionsKey, &CompilerOptionsData) { ) -> (CompilerOptionsKey, &CompilerOptionsData) {
let (scope, workspace_data) =
self.workspace_configs.entry_for_specifier(specifier);
if !workspace_data
.sources
.iter()
.any(|s| s.compiler_options.is_some())
{
if let Ok(path) = url_to_file_path(specifier) { if let Ok(path) = url_to_file_path(specifier) {
for (i, ts_config) in self.ts_configs.iter().enumerate() { for (i, ts_config) in self.ts_configs.iter().enumerate() {
if ts_config.filter.includes_path(&path) { if ts_config.filter.includes_path(&path) {
@ -1138,8 +1152,11 @@ impl CompilerOptionsResolver {
} }
} }
} }
let (scope, data) = self.workspace_configs.entry_for_specifier(specifier); }
(CompilerOptionsKey::WorkspaceConfig(scope.cloned()), data) (
CompilerOptionsKey::WorkspaceConfig(scope.cloned()),
workspace_data,
)
} }
pub fn entries( pub fn entries(

View file

@ -0,0 +1,5 @@
{
"compilerOptions": {
"lib": ["esnext", "dom"]
}
}

View file

@ -1,11 +1,6 @@
TS2584 [ERROR]: Cannot find name 'document'. Do you need to change your target library? Try changing the 'lib' compiler option to include 'dom'.
document.body.innerHTML = "<div>Hello</div>";
~~~~~~~~
at file:///[WILDLINE]main.deno.ts:2:1
TS2304 [ERROR]: Cannot find name 'Deno'. Do you need to change your target library? Try changing the 'lib' compiler option to include 'deno.ns' or add a triple-slash directive to the top of your entrypoint (main file): /// <reference lib="deno.ns" /> TS2304 [ERROR]: Cannot find name 'Deno'. Do you need to change your target library? Try changing the 'lib' compiler option to include 'deno.ns' or add a triple-slash directive to the top of your entrypoint (main file): /// <reference lib="deno.ns" />
Deno.readTextFileSync("hello.txt"); Deno.readTextFileSync("hello.txt");
~~~~ ~~~~
at file:///[WILDLINE]main.dom.ts:1:1 at file:///[WILDLINE]main.ts:1:1
error: Type checking failed. error: Type checking failed.

View file

@ -1,5 +1 @@
{ {}
"compilerOptions": {
"lib": ["deno.window"]
}
}

View file

@ -0,0 +1,7 @@
{
"exclude": ["*.deno.ts"],
"compilerOptions": {
"composite": true,
"lib": ["esnext", "dom"]
}
}

View file

@ -1,6 +1,8 @@
{ {
"exclude": ["*.deno.ts"],
"compilerOptions": { "compilerOptions": {
"lib": ["esnext", "dom"] "lib": ["deno.window"]
} },
"references": [
{ "path": "tsconfig.dom.json" }
]
} }

View file

@ -1,5 +1 @@
{ {}
"compilerOptions": {
"lib": ["deno.window"]
}
}

View file

@ -0,0 +1,7 @@
{
"extends": "./tsconfig.dom.json",
"files": ["main.dom.ts"],
"compilerOptions": {
"composite": true
}
}

View file

@ -1,4 +1,8 @@
{ {
"extends": "./tsconfig.dom.json", "compilerOptions": {
"files": ["main.dom.ts"] "lib": ["deno.window"]
},
"references": [
{ "path": "tsconfig.extends.json" }
]
} }

View file

@ -1,5 +1 @@
{ {}
"compilerOptions": {
"lib": ["deno.window"]
}
}

View file

@ -0,0 +1,6 @@
{
"extends": ["./tsconfig.dom_files.json", "./tsconfig.dom.json"],
"compilerOptions": {
"composite": true
}
}

View file

@ -1,3 +1,8 @@
{ {
"extends": ["./tsconfig.dom_files.json", "./tsconfig.dom.json"] "compilerOptions": {
"lib": ["deno.window"]
},
"references": [
{ "path": "tsconfig.extends.json" }
]
} }

View file

@ -1,6 +1,3 @@
{ {
"nodeModulesDir": "manual", "nodeModulesDir": "manual"
"compilerOptions": {
"lib": ["deno.window"]
}
} }

View file

@ -0,0 +1,7 @@
{
"extends": "foo/tsconfig.dom",
"files": ["main.dom.ts"],
"compilerOptions": {
"composite": true
}
}

View file

@ -1,4 +1,8 @@
{ {
"extends": "foo/tsconfig.dom", "compilerOptions": {
"files": ["main.dom.ts"] "lib": ["deno.window"]
},
"references": [
{ "path": "tsconfig.dom.json" }
]
} }

View file

@ -1,5 +1 @@
{ {}
"compilerOptions": {
"lib": ["deno.window"]
}
}

View file

@ -1,6 +1,8 @@
{ {
"files": ["main.dom.ts"],
"compilerOptions": { "compilerOptions": {
"lib": ["esnext", "dom"] "lib": ["deno.window"]
} },
"references": [
{ "path": "tsconfig.dom.json" }
]
} }

View file

@ -1,5 +1 @@
{ {}
"compilerOptions": {
"lib": ["deno.window"]
}
}

View file

@ -0,0 +1,6 @@
{
"files": ["main.dom.ts", "globals.d.ts"],
"compilerOptions": {
"composite": true
}
}

View file

@ -1,3 +1,8 @@
{ {
"files": ["main.dom.ts", "globals.d.ts"] "compilerOptions": {
"lib": ["deno.window"]
},
"references": [
{ "path": "tsconfig.dom.json" }
]
} }

View file

@ -1,5 +1 @@
{ {}
"compilerOptions": {
"lib": ["deno.window"]
}
}

View file

@ -0,0 +1,6 @@
{
"include": ["*.dom.ts"],
"compilerOptions": {
"lib": ["esnext", "dom"]
}
}

View file

@ -1,6 +1,8 @@
{ {
"include": ["*.dom.ts"],
"compilerOptions": { "compilerOptions": {
"lib": ["esnext", "dom"] "lib": ["deno.window"]
} },
"references": [
{ "path": "tsconfig.dom.json" }
]
} }

View file

@ -1,2 +0,0 @@
Deno.readTextFileSync("hello.txt");
document.body.innerHTML = "<div>Hello</div>";

View file

@ -1,6 +0,0 @@
{
"files": [],
"references": [
{ "path": "tsconfig.dom.json" }
]
}

View file

@ -1,5 +1 @@
{ {}
"compilerOptions": {
"lib": ["deno.window"]
}
}

View file

@ -0,0 +1,9 @@
{
"files": [],
"compilerOptions": {
"composite": true
},
"references": [
{ "path": "tsconfig_dom" }
]
}

View file

@ -1,6 +1,8 @@
{ {
"files": [], "compilerOptions": {
"lib": ["deno.window"]
},
"references": [ "references": [
{ "path": "tsconfig_dom" } { "path": "tsconfig.dom.json" }
] ]
} }