Skip to content

Commit 1a3da2a

Browse files
committed
v1.0.6 - fix cjs require statements
1 parent 5a5a125 commit 1a3da2a

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "nestjs-inject-transformer",
3-
"version": "1.0.5",
3+
"version": "1.0.6",
44
"description": "Amp up your NestJS and `class-transformer` stack with dependency injected transforms.",
55
"main": "./dist/cjs/index.js",
66
"module": "./dist/esm/index.mjs",

scripts/rename-cjs.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,24 @@ function renameFiles(dir) {
1111
if (stats.isDirectory()) {
1212
renameFiles(filePath);
1313
}
14-
// If it's a .js file, rename it to .mjs
14+
// If it's a .mjs file, rename it to .js
1515
else if (file.endsWith(".mjs")) {
1616
const newFilePath = filePath.slice(0, -4) + ".js";
1717
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+
/require\(["']([^"']+)\.mjs["']\)/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+
}
1832
}
1933
});
2034
}

0 commit comments

Comments
 (0)