Webpack5Cache.js
1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
class Cache {
constructor(compilation) {
this.cache = compilation.getCache('TerserWebpackPlugin');
}
async get(cacheData) {
// eslint-disable-next-line no-param-reassign
cacheData.eTag = cacheData.eTag || Array.isArray(cacheData.inputSource) ? cacheData.inputSource.map(item => this.cache.getLazyHashedEtag(item)).reduce((previousValue, currentValue) => this.cache.mergeEtags(previousValue, currentValue)) : this.cache.getLazyHashedEtag(cacheData.inputSource);
return this.cache.getPromise(cacheData.name, cacheData.eTag);
}
async store(cacheData) {
let data;
if (cacheData.target === 'comments') {
data = cacheData.output;
} else {
data = {
source: cacheData.source,
extractedCommentsSource: cacheData.extractedCommentsSource,
commentsFilename: cacheData.commentsFilename
};
}
return this.cache.storePromise(cacheData.name, cacheData.eTag, data);
}
}
exports.default = Cache;