-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix(web-react): Replace usage of
html-react-parser
in CommonJS files
* @see: https://www.npmjs.com/package/html-react-parser#usage * according to docs the `html-react-parser` should be required in CommonJS as `require('html-react-parser').default` but our build process creates the files without the `.default` export * this replacement post process is the workaround to fix this issue
- Loading branch information
Showing
2 changed files
with
37 additions
and
1 deletion.
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
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,35 @@ | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
|
||
const directoryPath = path.join(__dirname, '../dist'); | ||
|
||
/** | ||
* Replace the require statement in all files in the given directory. | ||
* | ||
* @param directory string | ||
*/ | ||
function replaceInDirs(directory) { | ||
fs.readdir(directory, (error, files) => { | ||
if (error) { | ||
// eslint-disable-next-line no-console -- This is a CLI script | ||
return console.log(`Unable to scan directory: ${error}`); | ||
} | ||
|
||
files.forEach((file) => { | ||
const filePath = path.join(directory, file); | ||
if (fs.statSync(filePath).isDirectory()) { | ||
// If the path is a directory, call this function recursively | ||
replaceInDirs(filePath); | ||
} else { | ||
let fileContent = fs.readFileSync(filePath, 'utf8'); | ||
|
||
// eslint-disable-next-line quotes -- Two conflicting rules, we do not won't to escape the quotes | ||
fileContent = fileContent.replace("require('html-react-parser')", "require('html-react-parser').default"); | ||
|
||
fs.writeFileSync(filePath, fileContent, 'utf8'); | ||
} | ||
}); | ||
}); | ||
} | ||
|
||
replaceInDirs(directoryPath); |