Clean up diff output a bit
This commit is contained in:
parent
8840d1a61f
commit
d77d0d1c59
1 changed files with 8 additions and 9 deletions
17
src/util.mjs
17
src/util.mjs
|
|
@ -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'
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue