@@ -3,9 +3,10 @@ import { fileURLToPath } from 'node:url';
33
44import { log } from '@hey-api/codegen-core' ;
55import type { PostProcessor , UserPostProcessor } from '@hey-api/shared' ;
6- import { findTsConfigPath , loadTsConfig , resolveSource , valueToObject } from '@hey-api/shared' ;
6+ import { findTsConfigPath , resolveSource , valueToObject } from '@hey-api/shared' ;
77import type { MaybeArray } from '@hey-api/types' ;
8- import ts from 'typescript' ;
8+ import type { TsConfigJsonResolved } from 'get-tsconfig' ;
9+ import { parseTsconfig } from 'get-tsconfig' ;
910
1011import { postProcessors } from './postprocess' ;
1112import type { Output , UserOutput } from './types' ;
@@ -64,10 +65,14 @@ export function getOutput(userConfig: { output: MaybeArray<string | UserOutput>
6465 output . tsConfig = loadTsConfig ( findTsConfigPath ( __dirname , output . tsConfigPath ) ) ;
6566 if (
6667 output . importFileExtension === undefined &&
67- ( output . tsConfig ?. options . moduleResolution === ts . ModuleResolutionKind . NodeNext ||
68- output . tsConfig ?. options . moduleResolution === ts . ModuleResolutionKind . Node16 ||
69- output . tsConfig ?. options . module === ts . ModuleKind . NodeNext ||
70- output . tsConfig ?. options . module === ts . ModuleKind . Node16 )
68+ ( output . tsConfig ?. compilerOptions ?. moduleResolution === 'nodenext' ||
69+ output . tsConfig ?. compilerOptions ?. moduleResolution === 'NodeNext' ||
70+ output . tsConfig ?. compilerOptions ?. moduleResolution === 'node16' ||
71+ output . tsConfig ?. compilerOptions ?. moduleResolution === 'Node16' ||
72+ output . tsConfig ?. compilerOptions ?. module === 'nodenext' ||
73+ output . tsConfig ?. compilerOptions ?. module === 'NodeNext' ||
74+ output . tsConfig ?. compilerOptions ?. module === 'node16' ||
75+ output . tsConfig ?. compilerOptions ?. module === 'Node16' )
7176 ) {
7277 output . importFileExtension = '.js' ;
7378 }
@@ -134,3 +139,15 @@ function normalizePostProcess(input: UserOutput['postProcess']): ReadonlyArray<P
134139 } ;
135140 } ) ;
136141}
142+
143+ function loadTsConfig ( configPath : string | null ) : TsConfigJsonResolved | null {
144+ if ( ! configPath ) {
145+ return null ;
146+ }
147+
148+ try {
149+ return parseTsconfig ( configPath ) ;
150+ } catch {
151+ throw new Error ( `Couldn't read tsconfig from path: ${ configPath } ` ) ;
152+ }
153+ }
0 commit comments