diff --git a/development/sourcemap-validator.js b/development/sourcemap-validator.js index 2fda2a114..d4d9b8293 100644 --- a/development/sourcemap-validator.js +++ b/development/sourcemap-validator.js @@ -99,10 +99,7 @@ async function validateSourcemapForFile ({ buildName }) { const isMaybeValid = portion.includes(targetString) if (!isMaybeValid) { valid = false - console.error('Sourcemap seems invalid:') - console.log(`\n========================== ${result.source} ====================================\n`) - console.log(line) - console.log(`\n==============================================================================\n`) + console.error(`Sourcemap seems invalid:\n${getFencedCode(result.source, line)}`) } }) }) @@ -110,6 +107,20 @@ async function validateSourcemapForFile ({ buildName }) { return valid } +const CODE_FENCE_LENGTH = 80 +const TITLE_PADDING_LENGTH = 1 + +function getFencedCode (filename, code) { + const title = `${' '.repeat(TITLE_PADDING_LENGTH)}${filename}${' '.repeat(TITLE_PADDING_LENGTH)}` + const openingFenceLength = Math.max(CODE_FENCE_LENGTH - (filename.length + (TITLE_PADDING_LENGTH * 2)), 0) + const startOpeningFenceLength = Math.floor(openingFenceLength / 2) + const endOpeningFenceLength = Math.ceil(openingFenceLength / 2) + const openingFence = `${'='.repeat(startOpeningFenceLength)}${title}${'='.repeat(endOpeningFenceLength)}` + const closingFence = '='.repeat(CODE_FENCE_LENGTH) + + return `${openingFence}\n${code}\n${closingFence}\n` +} + function indicesOf (substring, string) { const a = [] let i = -1