@@ -34,10 +34,12 @@ const readAllFilesInsideDirectory = async (directory: string) => {
3434 return allFilePaths ;
3535} ;
3636
37+ const javascriptExtensions = [ '.js' , '.ts' , '.jsx' , '.tsx' , '.mjs' , '.cjs' ] ;
38+
3739const isJavascriptModule = ( filePath : string ) => {
3840 const extensionName = path . extname ( filePath ) ;
3941
40- return [ '.js' , '.ts' , '.jsx' , '.tsx' , '.mjs' , '.cjs' ] . includes ( extensionName ) ;
42+ return javascriptExtensions . includes ( extensionName ) ;
4143} ;
4244
4345const checkFileExtensionsUntilItExists = (
@@ -144,12 +146,17 @@ export const createDependencyGraph = async (directory: string) => {
144146 const pathWithEnsuredExtension = ( ( ) => {
145147 if (
146148 extension . length > 0 &&
147- existsSync ( pathToDependencyFromDirectory )
149+ javascriptExtensions . includes ( extension )
148150 ) {
149- return pathToDependencyFromDirectory ;
151+ if ( existsSync ( pathToDependencyFromDirectory ) ) {
152+ return pathToDependencyFromDirectory ;
153+ }
154+ return checkFileExtensionsUntilItExists (
155+ pathToDependencyFromDirectory . replace ( extension , '' ) ,
156+ ) ;
150157 }
151158 return checkFileExtensionsUntilItExists (
152- pathToDependencyFromDirectory . replace ( extension , '' ) ,
159+ pathToDependencyFromDirectory ,
153160 ) ;
154161 } ) ( ) ;
155162
0 commit comments