-
Notifications
You must be signed in to change notification settings - Fork 128
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #87 from Nesopie/feat/hybrid
Add hybrid cjs and esm support
- Loading branch information
Showing
30 changed files
with
2,353 additions
and
4,458 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
Oops, something went wrong.