import request from 'request' ; import validateSourceMap from './validateSourceMap' ; import Report from './report' ; import { SourceMapNotFoundError , UnableToFetchMinifiedError , ResourceTimeoutError , SocketRefusedError } from './errors' ; import { MAX_TIMEOUT } from './constants' ; import { resolveUrl , getSourceMapLocation } from './utils' ; param { string } url param { function } callback export default function validateGeneratedFile ( url , callback ) { const report = new Report ( { url } ) ; request ( url , { timeout : MAX_TIMEOUT } , ( error , response , body ) => { if ( error ) { if ( error . message === 'ESOCKETTIMEDOUT' ) { report . pushError ( new ResourceTimeoutError ( url , MAX_TIMEOUT ) ) ; return void callback ( report ) ; } else if ( error . code === 'ECONNREFUSED' ) { report . pushError ( new SocketRefusedError ( url ) ) ; return void callback ( report ) ; } return void console . error ( error ) ; } if ( response && response . statusCode !== 200 ) { report . pushError ( new UnableToFetchMinifiedError ( url ) ) ; callback ( report ) ; return ; } const sourceMappingURL = getSourceMapLocation ( response , body ) ; if ( ! sourceMappingURL ) { report . pushError ( new SourceMapNotFoundError ( url ) ) ; callback ( report ) ; return ; } const resolvedSourceMappingURL = resolveUrl ( url , sourceMappingURL ) ; validateSourceMap ( resolvedSourceMappingURL , response . body , ( sourceMapReport ) => { const finalReport = report . concat ( sourceMapReport ) ; callback ( finalReport ) ; } ) ; } ) ; }