1+ import * as path from "path" ;
12import * as resolve from "resolve" ;
23import * as ts from "typescript" ;
3- import * as path from "path" ;
44// TODO: Don't depend on CLI?
55import * as cliDiagnostics from "../cli/diagnostics" ;
6+ import * as diagnosticFactories from "./diagnostics" ;
67
78export const getConfigDirectory = ( options : ts . CompilerOptions ) =>
89 options . configFilePath ? path . dirname ( options . configFilePath ) : process . cwd ( ) ;
910
10- interface ResolvePluginDiagnostics {
11- couldNotResolveFrom ( query : string , base : string ) : ts . Diagnostic ;
12- toLoadItShouldBeTranspiled ( query : string ) : ts . Diagnostic ;
13- shouldHaveAExport ( query : string , importName : string ) : ts . Diagnostic ;
14- }
15-
1611export function resolvePlugin (
17- diagnostics : ResolvePluginDiagnostics ,
18- basedir : string ,
12+ kind : string ,
1913 optionName : string ,
14+ basedir : string ,
2015 query : string ,
2116 importName = "default"
2217) : { error ?: ts . Diagnostic ; result ?: unknown } {
@@ -29,7 +24,7 @@ export function resolvePlugin(
2924 resolved = resolve . sync ( query , { basedir, extensions : [ ".js" , ".ts" , ".tsx" ] } ) ;
3025 } catch ( err ) {
3126 if ( err . code !== "MODULE_NOT_FOUND" ) throw err ;
32- return { error : diagnostics . couldNotResolveFrom ( query , basedir ) } ;
27+ return { error : diagnosticFactories . couldNotResolveFrom ( kind , query , basedir ) } ;
3328 }
3429
3530 // tslint:disable-next-line: deprecation
@@ -41,13 +36,13 @@ export function resolvePlugin(
4136 tsNode . register ( { transpileOnly : true } ) ;
4237 } catch ( err ) {
4338 if ( err . code !== "MODULE_NOT_FOUND" ) throw err ;
44- return { error : diagnostics . toLoadItShouldBeTranspiled ( query ) } ;
39+ return { error : diagnosticFactories . toLoadItShouldBeTranspiled ( kind , query ) } ;
4540 }
4641 }
4742
4843 const result = require ( resolved ) [ importName ] ;
4944 if ( result === undefined ) {
50- return { error : diagnostics . shouldHaveAExport ( query , importName ) } ;
45+ return { error : diagnosticFactories . shouldHaveAExport ( kind , query , importName ) } ;
5146 }
5247
5348 return { result } ;
0 commit comments