@@ -18,39 +18,43 @@ module.exports = options => {
1818 return ;
1919 }
2020
21- postcss ( autoprefixer ( options ) ) . process ( file . contents . toString ( ) , {
22- map : file . sourceMap ? { annotation : false } : false ,
23- from : file . path ,
24- to : file . path
25- } ) . then ( result => {
26- file . contents = Buffer . from ( result . css ) ;
27-
28- if ( result . map && file . sourceMap ) {
29- const map = result . map . toJSON ( ) ;
30- map . file = file . relative ;
31- map . sources = map . sources . map ( ( ) => file . relative ) ;
32- applySourceMap ( file , map ) ;
21+ ( async ( ) => {
22+ try {
23+ const result = await postcss ( autoprefixer ( options ) ) . process ( file . contents . toString ( ) , {
24+ map : file . sourceMap ? { annotation : false } : false ,
25+ from : file . path ,
26+ to : file . path
27+ } ) ;
28+
29+ file . contents = Buffer . from ( result . css ) ;
30+
31+ if ( result . map && file . sourceMap ) {
32+ const map = result . map . toJSON ( ) ;
33+ map . file = file . relative ;
34+ map . sources = map . sources . map ( ( ) => file . relative ) ;
35+ applySourceMap ( file , map ) ;
36+ }
37+
38+ const warnings = result . warnings ( ) ;
39+
40+ if ( warnings . length > 0 ) {
41+ fancyLog ( 'gulp-autoprefixer:' , '\n ' + warnings . join ( '\n ' ) ) ;
42+ }
43+
44+ setImmediate ( callback , null , file ) ;
45+ } catch ( error ) {
46+ const cssError = error . name === 'CssSyntaxError' ;
47+
48+ if ( cssError ) {
49+ error . message += error . showSourceCode ( ) ;
50+ }
51+
52+ // Prevent stream unhandled exception from being suppressed by Promise
53+ setImmediate ( callback , new PluginError ( 'gulp-autoprefixer' , error , {
54+ fileName : file . path ,
55+ showStack : ! cssError
56+ } ) ) ;
3357 }
34-
35- const warnings = result . warnings ( ) ;
36-
37- if ( warnings . length > 0 ) {
38- fancyLog ( 'gulp-autoprefixer:' , '\n ' + warnings . join ( '\n ' ) ) ;
39- }
40-
41- setImmediate ( callback , null , file ) ;
42- } ) . catch ( error => {
43- const cssError = error . name === 'CssSyntaxError' ;
44-
45- if ( cssError ) {
46- error . message += error . showSourceCode ( ) ;
47- }
48-
49- // Prevent stream unhandled exception from being suppressed by Promise
50- setImmediate ( callback , new PluginError ( 'gulp-autoprefixer' , error , {
51- fileName : file . path ,
52- showStack : ! cssError
53- } ) ) ;
54- } ) ;
58+ } ) ( ) ;
5559 } ) ;
5660} ;
0 commit comments