@@ -11,6 +11,7 @@ import webpack, {
1111  version  as  webpackVersion , 
1212}  from  'webpack' ; 
1313import  validateOptions  from  'schema-utils' ; 
14+ import  serialize  from  'serialize-javascript' ; 
1415
1516import  schema  from  './options.json' ; 
1617
@@ -52,7 +53,6 @@ class CompressionPlugin {
5253    } ; 
5354
5455    this . algorithm  =  this . options . algorithm ; 
55-     this . compressionOptions  =  this . options . compressionOptions ; 
5656
5757    if  ( typeof  this . algorithm  ===  'string' )  { 
5858      // eslint-disable-next-line global-require 
@@ -66,9 +66,9 @@ class CompressionPlugin {
6666        ) ; 
6767      } 
6868
69-       this . compressionOptions  =  { 
69+       this . options . compressionOptions  =  { 
7070        ...{  level : 9  } , 
71-         ...this . compressionOptions , 
71+         ...this . options . compressionOptions , 
7272      } ; 
7373    } 
7474  } 
@@ -117,20 +117,22 @@ class CompressionPlugin {
117117
118118  runCompressionAlgorithm ( input )  { 
119119    return  new  Promise ( ( resolve ,  reject )  =>  { 
120-       const  {  algorithm,  compressionOptions }  =  this ; 
120+       this . algorithm ( 
121+         input , 
122+         this . options . compressionOptions , 
123+         ( error ,  result )  =>  { 
124+           if  ( error )  { 
125+             return  reject ( error ) ; 
126+           } 
121127
122-       algorithm ( input ,   compressionOptions ,   ( error ,   result )   =>  { 
123-         if   ( error )   { 
124-           return   reject ( error ) ; 
125-         } 
128+            if   ( ! Buffer . isBuffer ( result ) )  { 
129+              // eslint-disable-next-line no-param-reassign 
130+              result   =   Buffer . from ( result ) ; 
131+            } 
126132
127-         if  ( ! Buffer . isBuffer ( result ) )  { 
128-           // eslint-disable-next-line no-param-reassign 
129-           result  =  Buffer . from ( result ) ; 
133+           return  resolve ( result ) ; 
130134        } 
131- 
132-         return  resolve ( result ) ; 
133-       } ) ; 
135+       ) ; 
134136    } ) ; 
135137  } 
136138
@@ -204,12 +206,16 @@ class CompressionPlugin {
204206              'compression-webpack-plugin' : require ( '../package.json' ) . version , 
205207              algorithm : this . algorithm , 
206208              originalAlgorithm : this . options . algorithm , 
207-               compressionOptions : this . compressionOptions , 
209+               compressionOptions : this . options . compressionOptions , 
208210              name, 
209211              contentHash : crypto . createHash ( 'md4' ) . update ( input ) . digest ( 'hex' ) , 
210212            } ; 
211213          }  else  { 
212-             cacheData . name  =  name ; 
214+             cacheData . name  =  serialize ( { 
215+               name, 
216+               algorithm : this . options . algorithm , 
217+               compressionOptions : this . options . compressionOptions , 
218+             } ) ; 
213219          } 
214220
215221          let  output  =  await  cache . get ( cacheData ,  {  RawSource } ) ; 
@@ -282,7 +288,7 @@ class CompressionPlugin {
282288            // TODO `...` required only for webpack@4 
283289            const  newOriginalInfo  =  { 
284290              ...info , 
285-               related : {  [ relatedName ] : newName  } , 
291+               related : {  [ relatedName ] : newName ,  ... info . related  } , 
286292            } ; 
287293
288294            CompressionPlugin . updateAsset ( 
0 commit comments