mirror of
https://github.com/denoland/deno.git
synced 2025-09-26 12:19:12 +00:00
fix(tsconfig): prioritize deno.json if it has compiler options (#30056)
This commit is contained in:
parent
6c736b1345
commit
a046f2c1bf
32 changed files with 136 additions and 84 deletions
|
@ -1114,6 +1114,12 @@ impl CompilerOptionsResolver {
|
|||
}
|
||||
|
||||
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) {
|
||||
for ts_config in &self.ts_configs {
|
||||
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(
|
||||
&self,
|
||||
specifier: &Url,
|
||||
) -> (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) {
|
||||
for (i, ts_config) in self.ts_configs.iter().enumerate() {
|
||||
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(
|
||||
|
|
5
tests/specs/check/tsconfig_deno_json_priority/deno.json
Normal file
5
tests/specs/check/tsconfig_deno_json_priority/deno.json
Normal file
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"compilerOptions": {
|
||||
"lib": ["esnext", "dom"]
|
||||
}
|
||||
}
|
|
@ -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" />
|
||||
Deno.readTextFileSync("hello.txt");
|
||||
~~~~
|
||||
at file:///[WILDLINE]main.dom.ts:1:1
|
||||
at file:///[WILDLINE]main.ts:1:1
|
||||
|
||||
error: Type checking failed.
|
|
@ -1,5 +1 @@
|
|||
{
|
||||
"compilerOptions": {
|
||||
"lib": ["deno.window"]
|
||||
}
|
||||
}
|
||||
{}
|
||||
|
|
7
tests/specs/check/tsconfig_exclude/tsconfig.dom.json
Normal file
7
tests/specs/check/tsconfig_exclude/tsconfig.dom.json
Normal file
|
@ -0,0 +1,7 @@
|
|||
{
|
||||
"exclude": ["*.deno.ts"],
|
||||
"compilerOptions": {
|
||||
"composite": true,
|
||||
"lib": ["esnext", "dom"]
|
||||
}
|
||||
}
|
|
@ -1,6 +1,8 @@
|
|||
{
|
||||
"exclude": ["*.deno.ts"],
|
||||
"compilerOptions": {
|
||||
"lib": ["esnext", "dom"]
|
||||
}
|
||||
"lib": ["deno.window"]
|
||||
},
|
||||
"references": [
|
||||
{ "path": "tsconfig.dom.json" }
|
||||
]
|
||||
}
|
||||
|
|
|
@ -1,5 +1 @@
|
|||
{
|
||||
"compilerOptions": {
|
||||
"lib": ["deno.window"]
|
||||
}
|
||||
}
|
||||
{}
|
||||
|
|
7
tests/specs/check/tsconfig_extends/tsconfig.extends.json
Normal file
7
tests/specs/check/tsconfig_extends/tsconfig.extends.json
Normal file
|
@ -0,0 +1,7 @@
|
|||
{
|
||||
"extends": "./tsconfig.dom.json",
|
||||
"files": ["main.dom.ts"],
|
||||
"compilerOptions": {
|
||||
"composite": true
|
||||
}
|
||||
}
|
|
@ -1,4 +1,8 @@
|
|||
{
|
||||
"extends": "./tsconfig.dom.json",
|
||||
"files": ["main.dom.ts"]
|
||||
"compilerOptions": {
|
||||
"lib": ["deno.window"]
|
||||
},
|
||||
"references": [
|
||||
{ "path": "tsconfig.extends.json" }
|
||||
]
|
||||
}
|
||||
|
|
|
@ -1,5 +1 @@
|
|||
{
|
||||
"compilerOptions": {
|
||||
"lib": ["deno.window"]
|
||||
}
|
||||
}
|
||||
{}
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
"extends": ["./tsconfig.dom_files.json", "./tsconfig.dom.json"],
|
||||
"compilerOptions": {
|
||||
"composite": true
|
||||
}
|
||||
}
|
|
@ -1,3 +1,8 @@
|
|||
{
|
||||
"extends": ["./tsconfig.dom_files.json", "./tsconfig.dom.json"]
|
||||
"compilerOptions": {
|
||||
"lib": ["deno.window"]
|
||||
},
|
||||
"references": [
|
||||
{ "path": "tsconfig.extends.json" }
|
||||
]
|
||||
}
|
||||
|
|
|
@ -1,6 +1,3 @@
|
|||
{
|
||||
"nodeModulesDir": "manual",
|
||||
"compilerOptions": {
|
||||
"lib": ["deno.window"]
|
||||
}
|
||||
"nodeModulesDir": "manual"
|
||||
}
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
{
|
||||
"extends": "foo/tsconfig.dom",
|
||||
"files": ["main.dom.ts"],
|
||||
"compilerOptions": {
|
||||
"composite": true
|
||||
}
|
||||
}
|
|
@ -1,4 +1,8 @@
|
|||
{
|
||||
"extends": "foo/tsconfig.dom",
|
||||
"files": ["main.dom.ts"]
|
||||
"compilerOptions": {
|
||||
"lib": ["deno.window"]
|
||||
},
|
||||
"references": [
|
||||
{ "path": "tsconfig.dom.json" }
|
||||
]
|
||||
}
|
||||
|
|
|
@ -1,5 +1 @@
|
|||
{
|
||||
"compilerOptions": {
|
||||
"lib": ["deno.window"]
|
||||
}
|
||||
}
|
||||
{}
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
{
|
||||
"files": ["main.dom.ts"],
|
||||
"compilerOptions": {
|
||||
"lib": ["esnext", "dom"]
|
||||
}
|
||||
"lib": ["deno.window"]
|
||||
},
|
||||
"references": [
|
||||
{ "path": "tsconfig.dom.json" }
|
||||
]
|
||||
}
|
||||
|
|
|
@ -1,5 +1 @@
|
|||
{
|
||||
"compilerOptions": {
|
||||
"lib": ["deno.window"]
|
||||
}
|
||||
}
|
||||
{}
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
"files": ["main.dom.ts", "globals.d.ts"],
|
||||
"compilerOptions": {
|
||||
"composite": true
|
||||
}
|
||||
}
|
|
@ -1,3 +1,8 @@
|
|||
{
|
||||
"files": ["main.dom.ts", "globals.d.ts"]
|
||||
"compilerOptions": {
|
||||
"lib": ["deno.window"]
|
||||
},
|
||||
"references": [
|
||||
{ "path": "tsconfig.dom.json" }
|
||||
]
|
||||
}
|
||||
|
|
|
@ -1,5 +1 @@
|
|||
{
|
||||
"compilerOptions": {
|
||||
"lib": ["deno.window"]
|
||||
}
|
||||
}
|
||||
{}
|
||||
|
|
6
tests/specs/check/tsconfig_include/tsconfig.dom.json
Normal file
6
tests/specs/check/tsconfig_include/tsconfig.dom.json
Normal file
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
"include": ["*.dom.ts"],
|
||||
"compilerOptions": {
|
||||
"lib": ["esnext", "dom"]
|
||||
}
|
||||
}
|
|
@ -1,6 +1,8 @@
|
|||
{
|
||||
"include": ["*.dom.ts"],
|
||||
"compilerOptions": {
|
||||
"lib": ["esnext", "dom"]
|
||||
}
|
||||
"lib": ["deno.window"]
|
||||
},
|
||||
"references": [
|
||||
{ "path": "tsconfig.dom.json" }
|
||||
]
|
||||
}
|
||||
|
|
|
@ -1,2 +0,0 @@
|
|||
Deno.readTextFileSync("hello.txt");
|
||||
document.body.innerHTML = "<div>Hello</div>";
|
|
@ -1,6 +0,0 @@
|
|||
{
|
||||
"files": [],
|
||||
"references": [
|
||||
{ "path": "tsconfig.dom.json" }
|
||||
]
|
||||
}
|
|
@ -1,5 +1 @@
|
|||
{
|
||||
"compilerOptions": {
|
||||
"lib": ["deno.window"]
|
||||
}
|
||||
}
|
||||
{}
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
{
|
||||
"files": [],
|
||||
"compilerOptions": {
|
||||
"composite": true
|
||||
},
|
||||
"references": [
|
||||
{ "path": "tsconfig_dom" }
|
||||
]
|
||||
}
|
|
@ -1,6 +1,8 @@
|
|||
{
|
||||
"files": [],
|
||||
"compilerOptions": {
|
||||
"lib": ["deno.window"]
|
||||
},
|
||||
"references": [
|
||||
{ "path": "tsconfig_dom" }
|
||||
{ "path": "tsconfig.dom.json" }
|
||||
]
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue