@@ -44,7 +44,7 @@ class JsonMinimizerPlugin {
4444
4545 static buildError ( error , file , context ) {
4646 return new Error (
47- `${ file } in "${ context } " from Json Minimizer\n${ error . stack } `
47+ `" ${ file } " in "${ context } " from Json Minimizer: \n${ error } `
4848 ) ;
4949 }
5050
@@ -71,20 +71,18 @@ class JsonMinimizerPlugin {
7171 }
7272
7373 async optimize ( compiler , compilation , assets , CacheEngine , weakCache ) {
74- const matchObject = ModuleFilenameHelpers . matchObject . bind (
75- // eslint-disable-next-line no-undefined
76- undefined ,
77- this . options
78- ) ;
79-
8074 const assetNames = Object . keys (
8175 typeof assets === 'undefined' ? compilation . assets : assets
82- ) . filter ( ( assetName ) => matchObject ( assetName ) ) ;
76+ ) . filter ( ( assetName ) =>
77+ // eslint-disable-next-line no-undefined
78+ ModuleFilenameHelpers . matchObject . bind ( undefined , this . options ) ( assetName )
79+ ) ;
8380
8481 if ( assetNames . length === 0 ) {
8582 return Promise . resolve ( ) ;
8683 }
8784
85+ const scheduledTasks = [ ] ;
8886 const cache = new CacheEngine (
8987 compilation ,
9088 {
@@ -93,56 +91,54 @@ class JsonMinimizerPlugin {
9391 weakCache
9492 ) ;
9593
96- const scheduledTasks = [ ] ;
97-
98- for ( const assetName of assetNames ) {
94+ for ( const name of assetNames ) {
9995 scheduledTasks . push (
10096 ( async ( ) => {
101- const { source : assetSource , info } = JsonMinimizerPlugin . getAsset (
97+ const { source : inputSource , info } = JsonMinimizerPlugin . getAsset (
10298 compilation ,
103- assetName
99+ name
104100 ) ;
105101
106102 // Skip double minimize assets from child compilation
107103 if ( info . minimized ) {
108104 return ;
109105 }
110106
111- let input = assetSource . source ( ) ;
107+ let input = inputSource . source ( ) ;
112108
113109 if ( Buffer . isBuffer ( input ) ) {
114110 input = input . toString ( ) ;
115111 }
116112
117- const cacheData = { assetName , assetSource } ;
113+ const cacheData = { inputSource } ;
118114
119115 if ( JsonMinimizerPlugin . isWebpack4 ( ) ) {
120116 if ( this . options . cache ) {
121117 cacheData . input = input ;
122118 cacheData . cacheKeys = this . options . cacheKeys (
123119 {
124- nodeVersion : process . version ,
125120 // eslint-disable-next-line global-require
126121 'json-minimizer-webpack-plugin' : require ( '../package.json' )
127122 . version ,
128123 'json-minimizer-webpack-plugin-options' : this . options ,
129- assetName ,
124+ name ,
130125 contentHash : crypto
131126 . createHash ( 'md4' )
132127 . update ( input )
133128 . digest ( 'hex' ) ,
134129 } ,
135- assetName
130+ name
136131 ) ;
137132 }
133+ } else {
134+ cacheData . name = name ;
138135 }
139136
140137 let output = await cache . get ( cacheData , { RawSource } ) ;
141138
142139 if ( ! output ) {
143140 try {
144141 const minimizerOptions = {
145- assetName,
146142 input,
147143 minimizerOptions : this . options . minimizerOptions ,
148144 minify : this . options . minify ,
@@ -151,11 +147,7 @@ class JsonMinimizerPlugin {
151147 output = await minifyFn ( minimizerOptions ) ;
152148 } catch ( error ) {
153149 compilation . errors . push (
154- JsonMinimizerPlugin . buildError (
155- error ,
156- assetName ,
157- compiler . context
158- )
150+ JsonMinimizerPlugin . buildError ( error , name , compiler . context )
159151 ) ;
160152
161153 return ;
@@ -166,15 +158,11 @@ class JsonMinimizerPlugin {
166158 await cache . store ( { ...output , ...cacheData } ) ;
167159 }
168160
169- JsonMinimizerPlugin . updateAsset (
170- compilation ,
171- assetName ,
172- output . source ,
173- {
174- ...info ,
175- minimized : true ,
176- }
177- ) ;
161+ // TODO `...` required only for webpack@4
162+ JsonMinimizerPlugin . updateAsset ( compilation , name , output . source , {
163+ ...info ,
164+ minimized : true ,
165+ } ) ;
178166 } ) ( )
179167 ) ;
180168 }
0 commit comments