// Helper for displaying edit changes so they can be manually verified import {execSync} from 'node:child_process'; /** * Converts a string from UTF-8 to base64. * @param {string} str * @returns {string} */ const toBase64 = str => Buffer.from(str, 'utf-8').toString('base64'); /** * terrible terrible terrible string diff helper for debugging * @param {string} a * @param {string} b */ export function diff (a, b) { // base64 input strings before passing to shell to avoid escaping issues // https://stackoverflow.com/a/60221847 // use tail to cut off useless file info lines execSync(String.raw`bash <<- EOF diff --color=always -u \ <(echo "${toBase64(a)}" | base64 -d) \ <(echo "${toBase64(b)}" | base64 -d) \ | tail -n +3 EOF`, { // display result directly in terminal stdio: 'inherit', }); }