-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
2 additions
and
11 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 |
---|---|---|
@@ -1,33 +1,24 @@ | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
|
||
// Function to update require statements in a file | ||
const updateRequires = (filePath) => { | ||
// Read the content of the file | ||
let content = fs.readFileSync(filePath, 'utf8'); | ||
|
||
// Define the regex pattern to match local require statements | ||
// const regex = /require\((['"])(\.\/[^'"]*)\1\)/g; | ||
|
||
// Replace the matched patterns with the updated path | ||
//replace local imports eg. require('./ecpair') to require('ecpair.cjs') | ||
content = content.replace(/require\('\.\/([^']*)'\)/g, "require('./$1.cjs')"); | ||
|
||
// Write the updated content back to the file | ||
fs.writeFileSync(filePath, content, 'utf8'); | ||
}; | ||
|
||
// Function to process all .cjs files in the src/cjs directory | ||
const processFiles = (dir) => { | ||
fs.readdirSync(dir).forEach((file) => { | ||
const filePath = path.join(dir, file); | ||
if (fs.lstatSync(filePath).isDirectory()) { | ||
processFiles(filePath); // Recursively process subdirectories | ||
processFiles(filePath); | ||
} else if (filePath.endsWith('.cjs')) { | ||
updateRequires(filePath); | ||
} | ||
}); | ||
}; | ||
|
||
// Directory to process | ||
const dir = path.join(__dirname, 'src', 'cjs'); | ||
processFiles(dir); |