2022-06-21 19:00:43 +00:00
"use strict" ;
2020-12-14 10:13:08 +00:00
/ * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
* Copyright ( c ) Microsoft Corporation . All rights reserved .
* Licensed under the MIT License . See License . txt in the project root for license information .
* -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- * /
Object . defineProperty ( exports , "__esModule" , { value : true } ) ;
2024-03-07 20:59:59 +00:00
exports . createReporter = createReporter ;
2020-12-14 10:13:08 +00:00
const es = require ( "event-stream" ) ;
const fancyLog = require ( "fancy-log" ) ;
const ansiColors = require ( "ansi-colors" ) ;
const fs = require ( "fs" ) ;
const path = require ( "path" ) ;
class ErrorLog {
2022-11-03 19:19:54 +00:00
id ;
2020-12-14 10:13:08 +00:00
constructor ( id ) {
this . id = id ;
}
2022-11-03 19:19:54 +00:00
allErrors = [ ] ;
startTime = null ;
count = 0 ;
2020-12-14 10:13:08 +00:00
onStart ( ) {
if ( this . count ++ > 0 ) {
return ;
}
this . startTime = new Date ( ) . getTime ( ) ;
fancyLog ( ` Starting ${ ansiColors . green ( 'compilation' ) } ${ this . id ? ansiColors . blue ( ` ${ this . id } ` ) : '' } ... ` ) ;
}
onEnd ( ) {
if ( -- this . count > 0 ) {
return ;
}
this . log ( ) ;
}
log ( ) {
2023-02-03 11:47:51 +00:00
const errors = this . allErrors . flat ( ) ;
2020-12-14 10:13:08 +00:00
const seen = new Set ( ) ;
errors . map ( err => {
if ( ! seen . has ( err ) ) {
seen . add ( err ) ;
fancyLog ( ` ${ ansiColors . red ( 'Error' ) } : ${ err } ` ) ;
}
} ) ;
fancyLog ( ` Finished ${ ansiColors . green ( 'compilation' ) } ${ this . id ? ansiColors . blue ( ` ${ this . id } ` ) : '' } with ${ errors . length } errors after ${ ansiColors . magenta ( ( new Date ( ) . getTime ( ) - this . startTime ) + ' ms' ) } ` ) ;
const regex = / ^ ( [ ^ ( ] + ) \ ( ( \ d + ) , ( \ d + ) \ ) : ( . * ) $ / s ;
const messages = errors
. map ( err => regex . exec ( err ) )
. filter ( match => ! ! match )
. map ( x => x )
. map ( ( [ , path , line , column , message ] ) => ( { path , line : parseInt ( line ) , column : parseInt ( column ) , message } ) ) ;
try {
const logFileName = 'log' + ( this . id ? ` _ ${ this . id } ` : '' ) ;
fs . writeFileSync ( path . join ( buildLogFolder , logFileName ) , JSON . stringify ( messages ) ) ;
}
catch ( err ) {
//noop
}
}
}
const errorLogsById = new Map ( ) ;
function getErrorLog ( id = '' ) {
let errorLog = errorLogsById . get ( id ) ;
if ( ! errorLog ) {
errorLog = new ErrorLog ( id ) ;
errorLogsById . set ( id , errorLog ) ;
}
return errorLog ;
}
const buildLogFolder = path . join ( path . dirname ( path . dirname ( _ _dirname ) ) , '.build' ) ;
try {
fs . mkdirSync ( buildLogFolder ) ;
}
catch ( err ) {
// ignore
}
function createReporter ( id ) {
const errorLog = getErrorLog ( id ) ;
const errors = [ ] ;
errorLog . allErrors . push ( errors ) ;
const result = ( err ) => errors . push ( err ) ;
result . hasErrors = ( ) => errors . length > 0 ;
result . end = ( emitError ) => {
errors . length = 0 ;
errorLog . onStart ( ) ;
return es . through ( undefined , function ( ) {
errorLog . onEnd ( ) ;
if ( emitError && errors . length > 0 ) {
if ( ! errors . _ _logged _ _ ) {
errorLog . log ( ) ;
}
errors . _ _logged _ _ = true ;
const err = new Error ( ` Found ${ errors . length } errors ` ) ;
err . _ _reporter _ _ = true ;
this . emit ( 'error' , err ) ;
}
else {
this . emit ( 'end' ) ;
}
} ) ;
} ;
return result ;
}
2023-11-22 13:05:46 +00:00
//# sourceMappingURL=reporter.js.map