@@ -112,11 +112,11 @@ function compile(bannerWidth, transforms) {
112112 * @return {string } The transformed file path
113113 */
114114 function rootRelative ( filePath , i , array ) {
115- var rootRelative = slash ( path . relative ( process . cwd ( ) , path . resolve ( filePath ) ) ) ; // resolve relative references
116- var isProject = ( rootRelative . slice ( 0 , 2 ) !== '..' ) ;
117- var result = [
115+ var rootRelPath = slash ( path . relative ( process . cwd ( ) , path . resolve ( filePath ) ) ) ; // resolve relative references
116+ var isProject = ( rootRelPath . slice ( 0 , 2 ) !== '..' ) ;
117+ var result = [
118118 sourceMapBase || '' ,
119- isProject ? rootRelative : path . basename ( rootRelative )
119+ isProject ? rootRelPath : path . basename ( rootRelPath )
120120 ] . join ( path . sep ) ;
121121 if ( ( typeof i === 'number' ) && ( typeof array === 'object' ) ) {
122122 array [ i ] = result ;
@@ -179,43 +179,52 @@ function compile(bannerWidth, transforms) {
179179 var timeout ;
180180 function errorHandler ( error ) {
181181 var text = error . toString ( ) ;
182- var analysis ;
183- var message ;
184-
185- // SyntaxError: <file>:<reason>:<line>:<column>
186- if ( analysis = / ^ \s * S y n t a x E r r o r \: \s * ( [ ^ : ] * ) \s * \: \s * ( [ ^ ( ] * ) \s * \( ( \d + : \d + ) \) \s * \n / . exec ( text ) ) {
187- message = [ analysis [ 1 ] , analysis [ 3 ] , analysis [ 2 ] ] . join ( ':' ) + '\n' ;
188-
189- // Error: SyntaxError: <reason> while parsing json file <file>
190- } else if ( analysis = / ^ \s * E r r o r : S y n t a x E r r o r \: \s * ( .* ) \s * w h i l e p a r s i n g j s o n f i l e \s * ( [ ^ ] * ) / . exec ( text ) ) {
191- message = [ analysis [ 2 ] , '0' , '0' , ' ' + analysis [ 1 ] ] . join ( ':' ) + '\n' ;
192-
193- // Line <line>: <reason>: <file>
194- } else if ( analysis = / L i n e \s * ( \d + ) \s * \: \s * ( [ ^ : ] * ) \s * : \s * ( .* ) \s * / . exec ( text ) ) {
195- message = [ analysis [ 3 ] , analysis [ 1 ] , 0 , ' ' + analysis [ 2 ] ] . join ( ':' ) + '\n' ;
196-
197- // Error: Cannot find module '<reason>' from '<directory>'
198- // find the first text match for any text quoted in <reason>
199- } else if ( analysis = / ^ \s * E r r o r \: C a n n o t f i n d m o d u l e ' ( .* ) \' \s * f r o m \s * \' ( .* ) \' \s * $ / . exec ( text ) ) {
200- var filename = fs . readdirSync ( analysis [ 2 ] )
201- . filter ( RegExp . prototype . test . bind ( / \. j s $ / i) )
202- . filter ( function ( jsFilename ) {
203- var fullPath = path . join ( analysis [ 2 ] , jsFilename ) ;
204- var fileText = fs . readFileSync ( fullPath ) . toString ( ) ;
205- return ( new RegExp ( '[\'"]' + analysis [ 1 ] + '[\'"]' ) ) . test ( fileText ) ;
206- } )
207- . shift ( ) ;
208- message = path . join ( analysis [ 2 ] , filename ) + ':0:0: Cannot find import ' + analysis [ 1 ] + '\n' ;
209-
210- // Unknown
211- } else {
212- message = 'TODO parse this error\n' + text + '\n' ;
213- }
214-
215- // add unique
216- if ( output . indexOf ( message ) < 0 ) {
217- output . push ( message ) ;
218- }
182+ [
183+ // SyntaxError: <file>:<reason>:<line>:<column>
184+ function ( ) {
185+ var analysis = / ^ \s * S y n t a x E r r o r \: \s * ( [ ^ : ] * ) \s * \: \s * ( [ ^ ( ] * ) \s * \( ( \d + : \d + ) \) \s * \n / . exec ( text ) ;
186+ return analysis && ( [ analysis [ 1 ] , analysis [ 3 ] , analysis [ 2 ] ] . join ( ':' ) + '\n' ) ;
187+ } ,
188+ // Error: SyntaxError: <reason> while parsing json file <file>
189+ function ( ) {
190+ var analysis = / ^ \s * E r r o r : S y n t a x E r r o r \: \s * ( .* ) \s * w h i l e p a r s i n g j s o n f i l e \s * ( [ ^ ] * ) / . exec ( text ) ;
191+ return analysis && ( [ analysis [ 2 ] , '0' , '0' , ' ' + analysis [ 1 ] ] . join ( ':' ) + '\n' ) ;
192+ } ,
193+ // Line <line>: <reason>: <file>
194+ function ( ) {
195+ var analysis = / L i n e \s * ( \d + ) \s * \: \s * ( [ ^ : ] * ) \s * : \s * ( .* ) \s * / . exec ( text ) ;
196+ return analysis && ( [ analysis [ 3 ] , analysis [ 1 ] , 0 , ' ' + analysis [ 2 ] ] . join ( ':' ) + '\n' ) ;
197+ } ,
198+ // Error: Cannot find module '<reason>' from '<directory>'
199+ // find the first text match for any text quoted in <reason>
200+ function ( ) {
201+ var analysis = / ^ \s * E r r o r \: C a n n o t f i n d m o d u l e ' ( .* ) \' \s * f r o m \s * \' ( .* ) \' \s * $ / . exec ( text ) ;
202+ if ( analysis ) {
203+ var filename = fs . readdirSync ( analysis [ 2 ] )
204+ . filter ( RegExp . prototype . test . bind ( / \. j s $ / i) )
205+ . filter ( function ( jsFilename ) {
206+ var fullPath = path . join ( analysis [ 2 ] , jsFilename ) ;
207+ var fileText = fs . readFileSync ( fullPath ) . toString ( ) ;
208+ return ( new RegExp ( '[\'"]' + analysis [ 1 ] + '[\'"]' ) ) . test ( fileText ) ;
209+ } )
210+ . shift ( ) ;
211+ return path . join ( analysis [ 2 ] , filename ) + ':0:0: Cannot find import ' + analysis [ 1 ] + '\n' ;
212+ }
213+ } ,
214+ // Unknown
215+ function ( ) {
216+ return 'TODO parse this error\n' + text + '\n' ;
217+ }
218+ ]
219+ . map ( function ( method ) {
220+ return method ( ) ;
221+ } )
222+ . filter ( Boolean )
223+ . forEach ( function addUnique ( message ) {
224+ if ( output . indexOf ( message ) < 0 ) {
225+ output . push ( message ) ;
226+ }
227+ } ) ;
219228
220229 // complete overall only once there are no further errors
221230 clearTimeout ( timeout ) ;
0 commit comments