mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
Improve sourcemap validator console report (#9131)
The report printed to the console for invalid source map samples has been improved in a few ways: * The entire message is now printed using `console.error`, so the contents aren't split between STDERR and STDOUT * The code fence is now guaranteed to be a set length, rather than it varying depending on the filename * The code fence is no longer padded on the inside with newlines, which results in a more compact output that is (in my opinion) just as readable.
This commit is contained in:
parent
c5ce4a1ccd
commit
e17c18ff7d
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user