8
8
const path = require ( "path" ) ;
9
9
const createHash = require ( "../util/createHash" ) ;
10
10
const makeSerializable = require ( "../util/makeSerializable" ) ;
11
- const { serializer } = require ( "../util/serialization" ) ;
11
+ const { serializer, NOT_SERIALIZABLE } = require ( "../util/serialization" ) ;
12
12
13
13
/** @typedef {import("webpack-sources").Source } Source */
14
14
/** @typedef {import("../../declarations/WebpackOptions").FileCacheOptions } FileCacheOptions */
@@ -23,6 +23,7 @@ class Pack {
23
23
this . unserializable = new Set ( ) ;
24
24
this . used = new Set ( ) ;
25
25
this . invalid = false ;
26
+ this . log = 0 ;
26
27
}
27
28
28
29
get ( identifier ) {
@@ -48,6 +49,10 @@ class Pack {
48
49
}
49
50
}
50
51
52
+ setLogLevel ( log ) {
53
+ this . log = log ;
54
+ }
55
+
51
56
_updateLastAccess ( ) {
52
57
const now = Date . now ( ) ;
53
58
for ( const identifier of this . used ) {
@@ -65,6 +70,13 @@ class Pack {
65
70
write ( identifier ) ;
66
71
write ( data ) ;
67
72
} catch ( err ) {
73
+ if ( this . log >= 1 && err !== NOT_SERIALIZABLE ) {
74
+ console . warn (
75
+ `Caching failed for ${ identifier } : ${
76
+ this . log >= 4 ? err . stack : err
77
+ } \nWe will not try to cache this entry again until the cache file is deleted.`
78
+ ) ;
79
+ }
68
80
rollback ( s ) ;
69
81
this . unserializable . add ( identifier ) ;
70
82
continue ;
@@ -294,6 +306,7 @@ class FileCachePlugin {
294
306
console . warn ( `Storing pack...` ) ;
295
307
}
296
308
pack . collectGarbage ( 1000 * 60 * 60 * 24 * 2 ) ;
309
+ pack . setLogLevel ( log ) ;
297
310
// You might think this breaks all access to the existing pack
298
311
// which are still referenced, but serializing the pack memorizes
299
312
// all data in the pack and makes it no longer need the backing file
0 commit comments