Clean up diff output a bit

This commit is contained in:
ewin 2025-03-28 00:50:22 -04:00
parent 8840d1a61f
commit d77d0d1c59
Signed by: erin
SSH key fingerprint: SHA256:swjoHhREbZPbWe+gyJNi24d4NAxJSyUIm3fpZj4z3wc

View file

@ -7,9 +7,7 @@ import {execSync} from 'node:child_process';
* @param {string} str * @param {string} str
* @returns {string} * @returns {string}
*/ */
function toBase64 (str) { const toBase64 = str => Buffer.from(str, 'utf-8').toString('base64');
return Buffer.from(str, 'utf-8').toString('base64');
}
/** /**
* terrible terrible terrible string diff helper for debugging * terrible terrible terrible string diff helper for debugging
@ -19,13 +17,14 @@ function toBase64 (str) {
export function diff (a, b) { export function diff (a, b) {
// base64 input strings before passing to shell to avoid escaping issues // base64 input strings before passing to shell to avoid escaping issues
// https://stackoverflow.com/a/60221847 // https://stackoverflow.com/a/60221847
// also use `|| true` to not throw an error when `diff` returns non-zero // use tail to cut off useless file info lines
execSync(`bash -c ' execSync(String.raw`bash <<- EOF
diff --color -u <(echo ${toBase64(a)} | base64 -d) <(echo ${toBase64(b)} | base64 -d) diff --color=always -u \
' || true`, { <(echo "${toBase64(a)}" | base64 -d) \
<(echo "${toBase64(b)}" | base64 -d) \
| tail -n +3
EOF`, {
// display result directly in terminal // display result directly in terminal
stdio: 'inherit', stdio: 'inherit',
}); });
} }
'yeet'