44 */
55
66const path = require ( 'path' ) ;
7- const ts = require ( 'typescript' ) ;
7+
88const { parseCustomFunctionSignature } = require ( './utils/customFunctionParser' ) ;
99const { getAllFiles } = require ( '../utils/fileProcessor' ) ;
1010const { analyzeJsFile } = require ( './javascript' ) ;
@@ -19,29 +19,6 @@ async function analyzeDirectory(dirPath, customFunctions) {
1919 const customFunctionSignatures = ( customFunctions && customFunctions ?. length > 0 ) ? customFunctions . map ( parseCustomFunctionSignature ) : null ;
2020
2121 const files = getAllFiles ( dirPath ) ;
22- const tsFiles = files . filter ( file => / \. ( t s x ? ) $ / . test ( file ) ) ;
23-
24- // Attempt to reuse project tsconfig.json compiler options for proper module resolution (e.g., path aliases)
25- let tsCompilerOptions = {
26- target : ts . ScriptTarget . ESNext ,
27- module : ts . ModuleKind . CommonJS ,
28- jsx : ts . JsxEmit . Preserve ,
29- allowJs : true ,
30- noEmit : true ,
31- } ;
32-
33- const tsConfigPath = ts . findConfigFile ( dirPath , ts . sys . fileExists , 'tsconfig.json' ) ;
34- if ( tsConfigPath ) {
35- const readResult = ts . readConfigFile ( tsConfigPath , ts . sys . readFile ) ;
36- if ( ! readResult . error && readResult . config ) {
37- const parsedConfig = ts . parseJsonConfigFileContent ( readResult . config , ts . sys , path . dirname ( tsConfigPath ) ) ;
38- if ( ! parsedConfig . errors || parsedConfig . errors . length === 0 ) {
39- tsCompilerOptions = { ...tsCompilerOptions , ...parsedConfig . options } ;
40- }
41- }
42- }
43-
44- const tsProgram = ts . createProgram ( tsFiles , tsCompilerOptions ) ;
4522
4623 for ( const file of files ) {
4724 let events = [ ] ;
@@ -55,7 +32,8 @@ async function analyzeDirectory(dirPath, customFunctions) {
5532 if ( isJsFile ) {
5633 events = analyzeJsFile ( file , customFunctionSignatures ) ;
5734 } else if ( isTsFile ) {
58- events = analyzeTsFile ( file , tsProgram , customFunctionSignatures ) ;
35+ // Pass null program so analyzeTsFile will create a per-file program using the file's nearest tsconfig.json
36+ events = analyzeTsFile ( file , null , customFunctionSignatures ) ;
5937 } else if ( isPythonFile ) {
6038 events = await analyzePythonFile ( file , customFunctionSignatures ) ;
6139 } else if ( isRubyFile ) {
0 commit comments