Skip to content

Commit

Permalink
Merge pull request #87 from Nesopie/feat/hybrid
Browse files Browse the repository at this point in the history
Add hybrid cjs and esm support
  • Loading branch information
junderw authored Sep 8, 2024
2 parents a9c3463 + 59247d2 commit 344db40
Show file tree
Hide file tree
Showing 30 changed files with 2,353 additions and 4,458 deletions.
24 changes: 24 additions & 0 deletions fixup.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
const fs = require('fs');
const path = require('path');

const updateRequires = (filePath) => {
let content = fs.readFileSync(filePath, 'utf8');
//replace local imports eg. require("./ecpair.js") to require("ecpair.cjs")
content = content.replace(/require\("\.\/([^"]*)\.js"\)/g, 'require("./$1.cjs")');

fs.writeFileSync(filePath, content, 'utf8');
};

const processFiles = (dir) => {
fs.readdirSync(dir).forEach((file) => {
const filePath = path.join(dir, file);
if (fs.lstatSync(filePath).isDirectory()) {
processFiles(filePath);
} else if (filePath.endsWith('.cjs')) {
updateRequires(filePath);
}
});
};

const dir = path.join(__dirname, 'src', 'cjs');
processFiles(dir);
Loading

0 comments on commit 344db40

Please sign in to comment.