-
Notifications
You must be signed in to change notification settings - Fork 27
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 #22 from Nesopie/feat/hybrid
Add cjs and esm support
- Loading branch information
Showing
36 changed files
with
2,402 additions
and
3,041 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,4 @@ | ||
{ | ||
"$schema": "https://json.schemastore.org/mocharc.json", | ||
"require": "tsx" | ||
} |
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
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') to require('ecpair.cjs') | ||
content = content.replace(/require\('\.\/([^']*)'\)/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.