-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(check/lsp): fix bugs with tsc type resolution, allow npm packages…
… to augment `ImportMeta` (#27690) Fixes #26224. Fixes #27042. There were three bugs here: - we were only resolving `/// <reference types` directives starting with `npm:`, which meant we failed to resolve bare specifiers (this broke the `/// <reference types="vite/client">` directive in most of the vite templates) - the `$node_modules` workaround caused us to fail to read files for tsc. For instance tsc would construct new paths based on specifiers containing `$node_modules`, and since we hadn't created those we weren't mapping them back to the original (this broke some type resolution within `vite/client`) - our separation of `ImportMeta` across node and deno globals in tsc meant that npm packages couldn't augment `ImportMeta` (this broke `vite/client`'s augmentation to add `import.meta.env` and others) After this, the only remaining issue in the vanilla vite template is our error on `/vite.svg` (which is an ambient module), and I'll look into that next.
- Loading branch information
1 parent
2debe9c
commit 464ee91
Showing
15 changed files
with
311 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
tests/registry/npm/@denotest/augments-global/1.0.0/import-meta.d.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
/// <reference types="./real-import-meta.d.ts" /> | ||
|
||
export type Foo = number; |
10 changes: 9 additions & 1 deletion
10
tests/registry/npm/@denotest/augments-global/1.0.0/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,13 @@ | ||
{ | ||
"name": "@denotest/augments-global", | ||
"version": "1.0.0", | ||
"types": "./index.d.ts" | ||
"types": "./index.d.ts", | ||
"exports": { | ||
".": { | ||
"types": "./index.d.ts" | ||
}, | ||
"./import-meta": { | ||
"types": "./import-meta.d.ts" | ||
} | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
tests/registry/npm/@denotest/augments-global/1.0.0/real-import-meta.d.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
interface ImportMetaEnv { | ||
TEST: string; | ||
} | ||
|
||
interface ImportMeta { | ||
env: ImportMetaEnv; | ||
bar: number; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
{ | ||
"tempDir": true, | ||
"tests": { | ||
"node_modules_dir_none": { | ||
"steps": [ | ||
{ | ||
"args": "run -A ./set_node_modules_dir.ts none", | ||
"output": "" | ||
}, | ||
{ | ||
"args": "install", | ||
"output": "[WILDCARD]" | ||
}, | ||
{ | ||
"args": "check --all ./main.ts", | ||
"output": "Check [WILDCARD]main.ts\n" | ||
} | ||
] | ||
}, | ||
"node_modules_dir_auto": { | ||
"steps": [ | ||
{ | ||
"args": "run -A ./set_node_modules_dir.ts auto", | ||
"output": "" | ||
}, | ||
{ | ||
"args": "install", | ||
"output": "[WILDCARD]" | ||
}, | ||
{ | ||
"args": "check --all ./main.ts", | ||
"output": "Check [WILDCARD]main.ts\n" | ||
} | ||
] | ||
}, | ||
"node_modules_dir_manual": { | ||
"steps": [ | ||
{ | ||
"args": "run -A ./set_node_modules_dir.ts auto", | ||
"output": "" | ||
}, | ||
{ | ||
"args": "install", | ||
"output": "[WILDCARD]" | ||
}, | ||
{ | ||
"args": "check --all ./main.ts", | ||
"output": "Check [WILDCARD]main.ts\n" | ||
} | ||
] | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"imports": { | ||
"@types/node": "npm:@types/node@*" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
/// <reference types="@types/node" /> | ||
|
||
const _foo = import.meta.dirname; |
8 changes: 8 additions & 0 deletions
8
tests/specs/check/import_meta_no_errors/set_node_modules_dir.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
if (Deno.args.length !== 1) { | ||
console.error("Usage: set_node_modules_dir.ts <setting>"); | ||
Deno.exit(1); | ||
} | ||
const setting = Deno.args[0].trim(); | ||
const denoJson = JSON.parse(Deno.readTextFileSync("./deno.json")); | ||
denoJson["nodeModulesDir"] = setting; | ||
Deno.writeTextFileSync("./deno.json", JSON.stringify(denoJson, null, 2)); |
Oops, something went wrong.