Webpack5Cache.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = void 0;
  6. class Cache {
  7. constructor(compilation) {
  8. this.cache = compilation.getCache('TerserWebpackPlugin');
  9. }
  10. async get(cacheData) {
  11. // eslint-disable-next-line no-param-reassign
  12. 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);
  13. return this.cache.getPromise(cacheData.name, cacheData.eTag);
  14. }
  15. async store(cacheData) {
  16. let data;
  17. if (cacheData.target === 'comments') {
  18. data = cacheData.output;
  19. } else {
  20. data = {
  21. source: cacheData.source,
  22. extractedCommentsSource: cacheData.extractedCommentsSource,
  23. commentsFilename: cacheData.commentsFilename
  24. };
  25. }
  26. return this.cache.storePromise(cacheData.name, cacheData.eTag, data);
  27. }
  28. }
  29. exports.default = Cache;