@@ -103,43 +103,73 @@ export class ModuleParser {
103103
104104 private extractImports ( sourceFile : SourceFile , _modulePath : string ) : Array < { Path : string } > {
105105 const imports : Array < { Path : string } > = [ ] ;
106-
107- // Track unique import paths to avoid duplicates
108106 const uniquePaths = new Set < string > ( ) ;
109-
110- // Import declarations
111- const importDeclarations = sourceFile . getImportDeclarations ( ) ;
112- for ( const importDecl of importDeclarations ) {
113- const originalPath = importDecl . getModuleSpecifierValue ( ) ;
114- const resolvedPath = importDecl . getModuleSpecifierSourceFile ( ) ?. getFilePath ( ) ;
115- if ( resolvedPath ) {
116- const relativePath = path . relative ( this . projectRoot , resolvedPath ) ;
117-
118- if ( uniquePaths . has ( relativePath ) ) {
119- continue ;
107+
108+ // Safely process import declarations
109+ try {
110+ const importDeclarations = sourceFile . getImportDeclarations ( ) ;
111+ for ( const importDecl of importDeclarations ) {
112+ try {
113+ const originalPath = importDecl . getModuleSpecifierValue ( ) ;
114+ if ( ! originalPath ) continue ;
115+
116+ const resolvedPathMaybe = importDecl . getModuleSpecifierSourceFile ( ) ?. getFilePath ( ) ;
117+ if ( typeof resolvedPathMaybe === 'string' ) {
118+ const relativePath = path . relative ( this . projectRoot , resolvedPathMaybe ) ;
119+ if ( ! uniquePaths . has ( relativePath ) ) {
120+ uniquePaths . add ( relativePath ) ;
121+ imports . push ( { Path : relativePath } ) ;
122+ }
123+ } else {
124+ const externalPath = `external:${ originalPath } ` ;
125+ if ( ! uniquePaths . has ( externalPath ) ) {
126+ uniquePaths . add ( externalPath ) ;
127+ imports . push ( { Path : externalPath } ) ;
128+ }
129+ }
130+ } catch ( error ) {
131+ console . warn ( `[Worker ${ process . pid } ] Skipping problematic import in ${ sourceFile . getFilePath ( ) } :` , error ) ;
120132 }
121- uniquePaths . add ( relativePath ) ;
122- imports . push ( { Path : relativePath } ) ;
123- } else {
124- imports . push ( { Path : "external:" + originalPath } ) ;
125133 }
134+ } catch ( error ) {
135+ console . error ( `[Worker ${ process . pid } ] Failed to process import declarations in ${ sourceFile . getFilePath ( ) } :` , error ) ;
126136 }
127-
128- // Export declarations (re-exports)
129- const exportDeclarations = sourceFile . getExportDeclarations ( ) ;
130- for ( const exportDecl of exportDeclarations ) {
131- const originalPath = exportDecl . getModuleSpecifierValue ( ) ;
132- if ( originalPath ) {
133- const resolvedPath = exportDecl . getModuleSpecifierSourceFile ( ) ?. getFilePath ( ) ;
134- if ( resolvedPath ) {
135- const relativePath = path . relative ( this . projectRoot , resolvedPath ) ;
136- imports . push ( { Path : relativePath } ) ;
137- } else {
138- imports . push ( { Path : "external:" + originalPath } ) ;
137+
138+ // Safely process export declarations
139+ try {
140+ const exportDeclarations = sourceFile . getExportDeclarations ( ) ;
141+ for ( const exportDecl of exportDeclarations ) {
142+ try {
143+ const specNode = exportDecl . getModuleSpecifier ( ) ;
144+ if ( ! specNode ) continue ;
145+
146+ const originalPath = specNode . getLiteralText ?.( ) ?? specNode . getText ?.( ) ?? '' ;
147+ if ( ! originalPath ) continue ;
148+
149+ const sourceFileObj = exportDecl . getModuleSpecifierSourceFile ( ) ;
150+ const resolvedPathMaybe = sourceFileObj ? sourceFileObj . getFilePath ( ) : undefined ;
151+
152+ if ( typeof resolvedPathMaybe === 'string' ) {
153+ const relativePath = path . relative ( this . projectRoot , resolvedPathMaybe ) ;
154+ if ( ! uniquePaths . has ( relativePath ) ) {
155+ uniquePaths . add ( relativePath ) ;
156+ imports . push ( { Path : relativePath } ) ;
157+ }
158+ } else {
159+ const externalPath = `external:${ originalPath } ` ;
160+ if ( ! uniquePaths . has ( externalPath ) ) {
161+ uniquePaths . add ( externalPath ) ;
162+ imports . push ( { Path : externalPath } ) ;
163+ }
164+ }
165+ } catch ( error ) {
166+ console . warn ( `[Worker ${ process . pid } ] Skipping problematic export in ${ sourceFile . getFilePath ( ) } :` , error ) ;
139167 }
140168 }
169+ } catch ( error ) {
170+ console . error ( `[Worker ${ process . pid } ] Failed to process export declarations in ${ sourceFile . getFilePath ( ) } :` , error ) ;
141171 }
172+
142173 return imports ;
143174 }
144-
145175}
0 commit comments