@@ -56,18 +56,20 @@ export const findInstance = (fileContent) => {
5656 return matches [ 0 ] [ 2 ] ;
5757} ;
5858
59- function processAllJsFilesInDir ( directory ) {
59+ function processJsFilesInDir ( directory ) {
6060 const files = fs . readdirSync ( directory ) ;
6161
6262 files . forEach ( ( file ) => {
6363 const filePath = path . join ( directory , file ) ;
6464
6565 if ( fs . statSync ( filePath ) . isDirectory ( ) ) {
66- processAllJsFilesInDir ( filePath ) ;
66+ processJsFilesInDir ( filePath ) ;
6767 } else if ( file . endsWith ( ".js" ) ) {
6868 try {
69- const fileContent = fs . readFileSync ( filePath , "utf-8" ) ;
70- const updatedContent = fileContent . replace (
69+ let fileContent = fs . readFileSync ( filePath , "utf-8" ) ;
70+
71+ // Add .js to relative imports if missing
72+ fileContent = fileContent . replace (
7173 / i m p o r t ( .+ ?) f r o m [ " ' ] ( .+ ?) [ " ' ] ; / g,
7274 ( match , imports , modulePath ) => {
7375 if (
@@ -79,7 +81,16 @@ function processAllJsFilesInDir(directory) {
7981 return match ;
8082 }
8183 ) ;
82- fs . writeFileSync ( filePath , updatedContent , "utf-8" ) ;
84+
85+ // Remove /index.js from imports
86+ fileContent = fileContent . replace (
87+ / i m p o r t ( .+ ?) f r o m [ " ' ] ( .+ ?) \/ i n d e x \. j s [ " ' ] ; / g,
88+ ( match , imports , modulePath ) => {
89+ return `import ${ imports } from "${ modulePath } ";` ;
90+ }
91+ ) ;
92+
93+ fs . writeFileSync ( filePath , fileContent , "utf-8" ) ;
8394 } catch ( error ) {
8495 console . error ( `Error processing file '${ filePath } ':` , error ) ;
8596 }
@@ -101,11 +112,10 @@ export async function getInstance(file, currentDirectory) {
101112 }
102113 ) ;
103114 } catch ( error ) {
104- console . log ( `Error: Could not compile TypeScript file '${ file } '` ) ;
115+ // console.log(`Error: Could not compile TypeScript file '${file}'`);
105116 }
106-
107117 const distDir = path . join ( currentDirectory , "dist" ) ;
108- processAllJsFilesInDir ( distDir ) ;
118+ processJsFilesInDir ( distDir ) ;
109119
110120 filePath = filePath
111121 . replace ( ".ts" , ".js" )
0 commit comments