@@ -6,9 +6,26 @@ import * as mockRequire from "mock-require";
66import * as ts_module from "typescript/lib/tsserverlibrary" ;
77
88import { Logger } from "./logger" ;
9+ import { getDenoDir } from "./shared" ;
910
1011let logger : Logger ;
1112
13+ // see https://github.com/denoland/deno/blob/2debbdacb935cfe1eb7bb8d1f40a5063b339d90b/js/compiler.ts#L159-L170
14+ const OPTIONS : ts_module . CompilerOptions = {
15+ allowJs : true ,
16+ checkJs : true ,
17+ esModuleInterop : true ,
18+ module : ts_module . ModuleKind . ESNext ,
19+ moduleResolution : ts_module . ModuleResolutionKind . NodeJs ,
20+ noEmit : true ,
21+ outDir : "$deno$" ,
22+ removeComments : true ,
23+ resolveJsonModule : true ,
24+ sourceMap : true ,
25+ target : ts_module . ScriptTarget . ESNext ,
26+ typeRoots : [ ]
27+ } ;
28+
1229export = function init ( { typescript } : { typescript : typeof ts_module } ) {
1330 // Make sure Deno imports the correct version of TS
1431 mockRequire ( "typescript" , typescript ) ;
@@ -45,6 +62,11 @@ export = function init({ typescript }: { typescript: typeof ts_module }) {
4562 ) ;
4663 } ;
4764
65+ const projectSetting = info . project . getCompilationSettings ( ) ;
66+ info . languageServiceHost . getCompilationSettings = ( ) => {
67+ return { ...OPTIONS , ...projectSetting } ;
68+ } ;
69+
4870 return info . languageService ;
4971 }
5072 } ;
@@ -66,28 +88,7 @@ function convertRemoteToLocalCache(moduleName: string): string {
6688 return moduleName ;
6789 }
6890
69- // ref https://deno.land/manual.html
70- // On Linux/Redox: $XDG_CACHE_HOME/deno or $HOME/.cache/deno
71- // On Windows: %LOCALAPPDATA%/deno (%LOCALAPPDATA% = FOLDERID_LocalAppData)
72- // On macOS: $HOME/Library/Caches/deno
73- // If something fails, it falls back to $HOME/.deno
74- let denoDir = process . env . DENO_DIR ;
75- if ( denoDir === undefined ) {
76- switch ( process . platform ) {
77- case "win32" :
78- denoDir = `${ process . env . LOCALAPPDATA } \\deno` ;
79- break ;
80- case "darwin" :
81- denoDir = `${ process . env . HOME } /Library/Caches/deno` ;
82- break ;
83- case "linux" :
84- denoDir = `${ process . env . HOME } /.cache/deno` ;
85- break ;
86- default :
87- denoDir = `${ process . env . HOME } /.deno` ;
88- }
89- }
90-
91+ const denoDir = getDenoDir ( ) ;
9192 // "https://deno.land/x/std/log/mod" to "$DENO_DIR/deps/https/deno.land/x/std/log/mod" (no ".ts" because stripped)
9293 const name = path . join ( denoDir , "deps" , moduleName . replace ( "://" , "/" ) ) ;
9394 const redirectedName = fallbackHeader ( name ) ;
@@ -114,6 +115,7 @@ function fallbackHeader(modulePath: string): string {
114115 if ( fs . existsSync ( headersPath ) ) {
115116 const headers : IDenoModuleHeaders = JSON . parse ( fs . readFileSync ( headersPath , { encoding : "utf-8" } ) ) ;
116117 logger . info ( `redirect "${ modulePath } " to "${ headers . redirect_to } ".` ) ;
118+ // TODO: avoid Circular
117119 return convertRemoteToLocalCache ( stripExtNameDotTs ( headers . redirect_to ) ) ;
118120 }
119121 return modulePath ;
0 commit comments