mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
Non-zero exit code upon failure to validate source maps (#9132)
The source map validator will now exit with a non-zero exit code when an error occurs, or when the source maps cannot be validated.
This commit is contained in:
parent
943d637cd2
commit
5df42c09d6
@ -13,13 +13,23 @@ const fsAsync = pify(fs)
|
|||||||
// if not working it may error or print minified garbage
|
// if not working it may error or print minified garbage
|
||||||
//
|
//
|
||||||
|
|
||||||
start().catch(console.error)
|
start().catch((error) => {
|
||||||
|
console.error(error)
|
||||||
|
process.exit(1)
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
async function start () {
|
async function start () {
|
||||||
const targetFiles = [`inpage.js`, `contentscript.js`, `ui.js`, `background.js`]
|
const targetFiles = [`inpage.js`, `contentscript.js`, `ui.js`, `background.js`]
|
||||||
|
let valid = true
|
||||||
|
|
||||||
for (const buildName of targetFiles) {
|
for (const buildName of targetFiles) {
|
||||||
await validateSourcemapForFile({ buildName })
|
const fileIsValid = await validateSourcemapForFile({ buildName })
|
||||||
|
valid = valid && fileIsValid
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!valid) {
|
||||||
|
process.exit(1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -59,6 +69,7 @@ async function validateSourcemapForFile ({ buildName }) {
|
|||||||
|
|
||||||
console.log(` sampling from ${consumer.sources.length} files`)
|
console.log(` sampling from ${consumer.sources.length} files`)
|
||||||
let sampleCount = 0
|
let sampleCount = 0
|
||||||
|
let valid = true
|
||||||
|
|
||||||
const buildLines = rawBuild.split('\n')
|
const buildLines = rawBuild.split('\n')
|
||||||
const targetString = 'new Error'
|
const targetString = 'new Error'
|
||||||
@ -71,6 +82,7 @@ async function validateSourcemapForFile ({ buildName }) {
|
|||||||
const result = consumer.originalPositionFor(position)
|
const result = consumer.originalPositionFor(position)
|
||||||
// warn if source content is missing
|
// warn if source content is missing
|
||||||
if (!result.source) {
|
if (!result.source) {
|
||||||
|
valid = false
|
||||||
console.warn(`!! missing source for position: ${JSON.stringify(position)}`)
|
console.warn(`!! missing source for position: ${JSON.stringify(position)}`)
|
||||||
// const buildLine = buildLines[position.line - 1]
|
// const buildLine = buildLines[position.line - 1]
|
||||||
console.warn(` origin in build:`)
|
console.warn(` origin in build:`)
|
||||||
@ -86,6 +98,7 @@ async function validateSourcemapForFile ({ buildName }) {
|
|||||||
const portion = line.slice(result.column)
|
const portion = line.slice(result.column)
|
||||||
const isMaybeValid = portion.includes(targetString)
|
const isMaybeValid = portion.includes(targetString)
|
||||||
if (!isMaybeValid) {
|
if (!isMaybeValid) {
|
||||||
|
valid = false
|
||||||
console.error('Sourcemap seems invalid:')
|
console.error('Sourcemap seems invalid:')
|
||||||
console.log(`\n========================== ${result.source} ====================================\n`)
|
console.log(`\n========================== ${result.source} ====================================\n`)
|
||||||
console.log(line)
|
console.log(line)
|
||||||
@ -94,6 +107,7 @@ async function validateSourcemapForFile ({ buildName }) {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
console.log(` checked ${sampleCount} samples`)
|
console.log(` checked ${sampleCount} samples`)
|
||||||
|
return valid
|
||||||
}
|
}
|
||||||
|
|
||||||
function indicesOf (substring, string) {
|
function indicesOf (substring, string) {
|
||||||
|
Loading…
Reference in New Issue
Block a user