From d77d0d1c59cd4c9f6ba8b3ece4120ad60749368e Mon Sep 17 00:00:00 2001 From: ewin Date: Fri, 28 Mar 2025 00:50:22 -0400 Subject: [PATCH] Clean up diff output a bit --- src/util.mjs | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/util.mjs b/src/util.mjs index 60ac2b5..84bc481 100644 --- a/src/util.mjs +++ b/src/util.mjs @@ -7,9 +7,7 @@ import {execSync} from 'node:child_process'; * @param {string} str * @returns {string} */ -function toBase64 (str) { - return Buffer.from(str, 'utf-8').toString('base64'); -} +const toBase64 = str => Buffer.from(str, 'utf-8').toString('base64'); /** * terrible terrible terrible string diff helper for debugging @@ -19,13 +17,14 @@ function toBase64 (str) { export function diff (a, b) { // base64 input strings before passing to shell to avoid escaping issues // https://stackoverflow.com/a/60221847 - // also use `|| true` to not throw an error when `diff` returns non-zero - execSync(`bash -c ' - diff --color -u <(echo ${toBase64(a)} | base64 -d) <(echo ${toBase64(b)} | base64 -d) - ' || true`, { + // 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', }); } - -'yeet'