File tree Expand file tree Collapse file tree 2 files changed +16
-2
lines changed Expand file tree Collapse file tree 2 files changed +16
-2
lines changed Original file line number Diff line number Diff line change 1
1
{
2
2
"name" : " nestjs-inject-transformer" ,
3
- "version" : " 1.0.5 " ,
3
+ "version" : " 1.0.6 " ,
4
4
"description" : " Amp up your NestJS and `class-transformer` stack with dependency injected transforms." ,
5
5
"main" : " ./dist/cjs/index.js" ,
6
6
"module" : " ./dist/esm/index.mjs" ,
Original file line number Diff line number Diff line change @@ -11,10 +11,24 @@ function renameFiles(dir) {
11
11
if ( stats . isDirectory ( ) ) {
12
12
renameFiles ( filePath ) ;
13
13
}
14
- // If it's a .js file, rename it to .mjs
14
+ // If it's a .mjs file, rename it to .js
15
15
else if ( file . endsWith ( ".mjs" ) ) {
16
16
const newFilePath = filePath . slice ( 0 , - 4 ) + ".js" ;
17
17
fs . renameSync ( filePath , newFilePath ) ;
18
+
19
+ // Now, read the file and replace require statements
20
+ const fileContent = fs . readFileSync ( newFilePath , "utf-8" ) ;
21
+ const updatedContent = fileContent . replace (
22
+ / r e q u i r e \( [ " ' ] ( [ ^ " ' ] + ) \. m j s [ " ' ] \) / g,
23
+ ( match , p1 ) => {
24
+ return `require("${ p1 } .js")` ;
25
+ }
26
+ ) ;
27
+
28
+ // If the content was modified, write it back to the file
29
+ if ( updatedContent !== fileContent ) {
30
+ fs . writeFileSync ( newFilePath , updatedContent , "utf-8" ) ;
31
+ }
18
32
}
19
33
} ) ;
20
34
}
You can’t perform that action at this time.
0 commit comments