export interface Source { line : number ; file : string ; text : string ; } export type WarningTypes = 'compressed' | 'ignoredFound' ; export class Warnings { ranOnMinifiedFiles = false ; list : Record < WarningTypes , { [ s ] : Source [ ] ; } > = { compressed : { } , ignoredFound : { } , } ; deprecated warningArray : { [ s ] : Source [ ] ; } = { } ; constructor ( ) { this . reset ( ) ; } summary ( text ) { if ( text . length > 120 ) { this . ranOnMinifiedFiles = this . ranOnMinifiedFiles || text . length > 500 ; return `${ text . slice ( 0 , 120 ) }...` ; } return text ; } reset ( ) { this . list = { compressed : { } , ignoredFound : { } , } ; this . ranOnMinifiedFiles = false ; } append ( value , source , warningType = 'compressed' ) { const typeList = this . list [ warningType ] ; if ( value in typeList && ! typeList [ value ] . findIndex ) { return ; } if ( value in typeList ) { if ( source && ( typeList [ value ] . findIndex ( ( e ) => ( ( e . file === source . file && e . line === source . line ) ) ) === - 1 ) ) { typeList [ value ] . push ( source ) ; } } else { typeList [ value ] = source ? [ source ] : [ ] ; } this . warningArray = this . list . compressed ; } private warnList = ( list ) : void => { Object . entries ( list ) . forEach ( ( [ key , line ] ) => { if ( line . length ) { console . warn ( ` - '${ key }' found in: ` ) ; line . forEach ( ( e ) => console . warn ( `    ${ e . file }(${ e . line }): ${ this . summary ( e . text ) }` ) ) ; } else { console . warn ( ` - '${ key }'` ) ; } } ) ; } ; warn ( ) { const compressedEntries = Object . entries ( this . list . compressed ) ; const ignoredFoundEntries = Object . entries ( this . list . ignoredFound ) ; if ( ignoredFoundEntries . length ) { console . warn ( 'WARNING: The following selectors got found but were ignored. ' + 'please check if you do not want to allow these selectors instead' ) ; this . warnList ( this . list . ignoredFound ) ; } if ( compressedEntries . length ) { console . warn ( 'WARNING: The following selectors were not found in the rename table, but ' + 'appears in the compressed map. In order to avoid that some other selectors ' + 'are used instead, they were appended with \'_conflict\'. You need to fix this ' + 'either by:\n' ) ; console . warn ( '- Creating a CSS rule with the selector name and re-run the process, or' ) ; console . warn ( '- Excluding the selectors so it\'s not renamed, or' ) ; console . warn ( '- Adding the value to the reserved selectors table so it\'s not used as a possible short name\n\n' ) ; console . warn ( 'The failing selector are:' ) ; this . warnList ( this . list . compressed ) ; if ( this . ranOnMinifiedFiles ) { console . warn ( 'WARNING: You shouldn\'t run this software on minified files as it\'ll be ' + 'hard to debug errors whenever they happens.\n' ) ; } } } } export default new Warnings ( ) ;