@@ -7,7 +7,7 @@ import mockRequire from "mock-require";
77import ts_module from "typescript/lib/tsserverlibrary" ;
88
99import { Logger } from "./logger" ;
10- import { getDenoDir } from "./shared " ;
10+ import { getDenoDir , getGlobalDtsPath , getLocalDtsPath , getDtsPathForVscode } from "./utils " ;
1111
1212let logger : Logger ;
1313
@@ -19,7 +19,6 @@ module.exports = function init({ typescript }: { typescript: typeof ts_module })
1919 const OPTIONS : ts_module . CompilerOptions = {
2020 allowJs : true ,
2121 checkJs : true ,
22- allowNonTsExtensions : true ,
2322 esModuleInterop : true ,
2423 module : typescript . ModuleKind . ESNext ,
2524 moduleResolution : typescript . ModuleResolutionKind . NodeJs ,
@@ -36,6 +35,7 @@ module.exports = function init({ typescript }: { typescript: typeof ts_module })
3635 } ;
3736
3837 const OPTIONS_OVERWRITE_BY_DENO : ts_module . CompilerOptions = {
38+ allowNonTsExtensions : false ,
3939 jsx : OPTIONS . jsx ,
4040 module : OPTIONS . module ,
4141 moduleResolution : OPTIONS . moduleResolution ,
@@ -44,6 +44,10 @@ module.exports = function init({ typescript }: { typescript: typeof ts_module })
4444 noEmit : OPTIONS . noEmit ,
4545 noEmitHelpers : OPTIONS . noEmitHelpers ,
4646 target : typescript . ScriptTarget . ESNext ,
47+ paths : {
48+ "abc" : [ './c.ts' ] ,
49+ "abc.ts" : [ './c.ts' ] ,
50+ } ,
4751 } ;
4852
4953 return {
@@ -66,7 +70,9 @@ module.exports = function init({ typescript }: { typescript: typeof ts_module })
6670 redirectedReference ?: ts_module . ResolvedProjectReference ,
6771 options : ts_module . CompilerOptions = OPTIONS ,
6872 ) => {
69- moduleNames = moduleNames . map ( convertRemoteToLocalCache ) . map ( stripExtNameDotTs ) ;
73+ moduleNames = moduleNames
74+ . map ( convertRemoteToLocalCache )
75+ . map ( stripExtNameDotTs ) ;
7076
7177 return resolveModuleNames . call (
7278 info . languageServiceHost ,
@@ -83,6 +89,7 @@ module.exports = function init({ typescript }: { typescript: typeof ts_module })
8389 info . languageServiceHost . getCompilationSettings = ( ) => {
8490 const projectConfig = getCompilationSettings . call ( info . languageServiceHost ) ;
8591 const compilationSettings = merge ( merge ( OPTIONS , projectConfig ) , OPTIONS_OVERWRITE_BY_DENO ) ;
92+ compilationSettings . baseUrl = info . project . getCurrentDirectory ( ) ;
8693 logger . info ( `compilationSettings:${ JSON . stringify ( compilationSettings ) } ` ) ;
8794 return compilationSettings ;
8895 } ;
@@ -142,6 +149,46 @@ module.exports = function init({ typescript }: { typescript: typeof ts_module })
142149 return details ;
143150 } ;
144151
152+ // const getSemanticDiagnostics = info.languageService.getSemanticDiagnostics;
153+
154+ // info.languageService.getSemanticDiagnostics = (filename: string) => {
155+ // const diagnostics = getSemanticDiagnostics(filename);
156+
157+ // // ref: https://github.com/denoland/deno/blob/da8cb408c878aa6e90542e26173f1f14b5254d29/cli/js/compiler/util.ts#L262
158+ // const ignoredDiagnostics = [
159+ // // TS2306: File 'file:///Users/rld/src/deno/cli/tests/subdir/amd_like.js' is
160+ // // not a module.
161+ // 2306,
162+ // // TS1375: 'await' expressions are only allowed at the top level of a file
163+ // // when that file is a module, but this file has no imports or exports.
164+ // // Consider adding an empty 'export {}' to make this file a module.
165+ // 1375,
166+ // // TS1103: 'for-await-of' statement is only allowed within an async function
167+ // // or async generator.
168+ // 1103,
169+ // // TS2691: An import path cannot end with a '.ts' extension. Consider
170+ // // importing 'bad-module' instead.
171+ // 2691,
172+ // // TS5009: Cannot find the common subdirectory path for the input files.
173+ // 5009,
174+ // // TS5055: Cannot write file
175+ // // 'http://localhost:4545/cli/tests/subdir/mt_application_x_javascript.j4.js'
176+ // // because it would overwrite input file.
177+ // 5055,
178+ // // TypeScript is overly opinionated that only CommonJS modules kinds can
179+ // // support JSON imports. Allegedly this was fixed in
180+ // // Microsoft/TypeScript#26825 but that doesn't seem to be working here,
181+ // // so we will ignore complaints about this compiler setting.
182+ // 5070,
183+ // // TS7016: Could not find a declaration file for module '...'. '...'
184+ // // implicitly has an 'any' type. This is due to `allowJs` being off by
185+ // // default but importing of a JavaScript module.
186+ // 7016,
187+ // ];
188+
189+ // return diagnostics.filter((v: ts_module.Diagnostic) => !ignoredDiagnostics.includes(v.code));
190+ // };
191+
145192 return info . languageService ;
146193 } ,
147194
@@ -213,40 +260,3 @@ function fallbackHeader(modulePath: string): string {
213260 }
214261 return modulePath ;
215262}
216-
217- function getDtsPathForVscode ( info : ts_module . server . PluginCreateInfo ) : string | undefined {
218- const bundledDtsPath = info . config . dtsPath ;
219-
220- if ( bundledDtsPath && fs . existsSync ( bundledDtsPath ) ) {
221- return bundledDtsPath ;
222- }
223-
224- return undefined ;
225- }
226-
227- function getGlobalDtsPath ( ) : string | undefined {
228- const denoDir = getDenoDir ( ) ;
229- const globalDtsPath = path . resolve ( denoDir , "lib.deno_runtime.d.ts" ) ;
230-
231- if ( fs . existsSync ( globalDtsPath ) ) {
232- return globalDtsPath ;
233- }
234-
235- return undefined ;
236- }
237-
238- function getLocalDtsPath ( info : ts . server . PluginCreateInfo ) : string | undefined {
239- const localDtsPath = path . resolve (
240- info . project . getCurrentDirectory ( ) ,
241- "node_modules" ,
242- "typescript-deno-plugin" ,
243- "lib" ,
244- "lib.deno_runtime.d.ts" ,
245- ) ;
246-
247- if ( fs . existsSync ( localDtsPath ) ) {
248- return localDtsPath ;
249- }
250-
251- return undefined ;
252- }
0 commit comments