Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix(web-react): Replace usage of html-react-parser in CommonJS files #1289

Merged
merged 1 commit into from
Feb 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/web-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,9 @@
"build:umd": "npm-run-all --serial webpack:dev webpack:prod",
"build:es2020": "tsc --module es2020 --outDir dist --project ./config/tsconfig.prod.json",
"build:esNext": "echo tsc --module esNext --outDir dist/_esNext --project ./config/tsconfig.prod.json",
"postbuild": "npm-run-all prepdist resolve build:cjs",
"postbuild": "npm-run-all prepdist resolve build:cjs postprocess",
"prepdist": "node ./scripts/prepareDist.js",
"postprocess": "node ./scripts/postProcess.js",
"types": "tsc",
"webpack:dev": "webpack --mode development --config ./config/webpack.js --progress",
"webpack:prod": "webpack --mode production --config ./config/webpack.js --progress",
Expand Down
35 changes: 35 additions & 0 deletions packages/web-react/scripts/postProcess.js
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);
Loading