11import { access } from 'node:fs/promises' ;
2- // eslint-disable-next-line unicorn/import-style
3- import { dirname } from 'node:path' ;
2+ import { dirname , join } from 'node:path' ;
43import {
54 type CompilerOptions ,
65 type Diagnostic ,
@@ -11,6 +10,7 @@ import {
1110 parseJsonConfigFileContent ,
1211 sys ,
1312} from 'typescript' ;
13+ // eslint-disable-next-line unicorn/import-style
1414import type { Issue } from '@code-pushup/models' ;
1515import {
1616 executeProcess ,
@@ -90,42 +90,50 @@ export function getIssueFromDiagnostic(diag: Diagnostic) {
9090}
9191
9292const _TS_CONFIG_MAP = new Map < string , ParsedCommandLine > ( ) ;
93+
9394export async function loadTargetConfig ( tsConfigPath : string ) {
94- if ( _TS_CONFIG_MAP . get ( tsConfigPath ) === undefined ) {
95- const { config } = parseConfigFileTextToJson (
96- tsConfigPath ,
97- await readTextFile ( tsConfigPath ) ,
98- ) ;
95+ if ( _TS_CONFIG_MAP . has ( tsConfigPath ) ) {
96+ return _TS_CONFIG_MAP . get ( tsConfigPath ) as ParsedCommandLine ;
97+ }
9998
100- const parsedConfig = parseJsonConfigFileContent (
101- config ,
102- sys ,
103- dirname ( tsConfigPath ) ,
104- ) ;
99+ const { config } = parseConfigFileTextToJson (
100+ tsConfigPath ,
101+ await readTextFile ( tsConfigPath ) ,
102+ ) ;
105103
106- if ( parsedConfig . fileNames . length === 0 ) {
107- throw new Error (
108- 'No files matched by the TypeScript configuration. Check your "include", "exclude" or "files" settings.' ,
109- ) ;
110- }
104+ const parsedConfig = parseJsonConfigFileContent (
105+ config ,
106+ sys ,
107+ dirname ( tsConfigPath ) ,
108+ ) ;
111109
112- _TS_CONFIG_MAP . set ( tsConfigPath , parsedConfig ) ;
110+ if ( parsedConfig . fileNames . length === 0 ) {
111+ throw new Error (
112+ 'No files matched by the TypeScript configuration. Check your "include", "exclude" or "files" settings.' ,
113+ ) ;
113114 }
115+
116+ _TS_CONFIG_MAP . set ( tsConfigPath , parsedConfig ) ;
114117 return _TS_CONFIG_MAP . get ( tsConfigPath ) as ParsedCommandLine ;
115118}
116119
117- export async function getCurrentTsVersion ( ) : Promise < SemVerString > {
120+ async function _getCurrentTsVersion ( ) : Promise < SemVerString > {
118121 const { stdout } = await executeProcess ( {
119122 command : 'npx' ,
120123 args : [ '-y' , 'tsc' , '--version' ] ,
121124 } ) ;
122125 return stdout . split ( ' ' ) . slice ( - 1 ) . join ( '' ) . trim ( ) as SemVerString ;
123126}
124127
125- export async function loadTsConfigDefaultsByVersion ( version : SemVerString ) {
128+ export async function loadTsConfigDefaultsByVersion ( ) {
129+ const version = await _getCurrentTsVersion ( ) ;
126130 const __dirname = new URL ( '.' , import . meta. url ) . pathname ;
127- const configPath = `${ __dirname } default-ts-configs/${ version } .ts` ;
128-
131+ const configPath = join (
132+ __dirname ,
133+ '..' ,
134+ 'default-ts-configs' ,
135+ `${ version } .ts` ,
136+ ) ;
129137 try {
130138 await access ( configPath ) ;
131139 } catch {
0 commit comments