Sha256: 980baf0d525a825f6187b968468064c401e492efbbf2f4b950f62af51122ad70

Contents?: true

Size: 1.97 KB

Versions: 15

Compression:

Stored size: 1.97 KB

Contents

"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;

var _getLazyHashedEtag = _interopRequireDefault(require("webpack/lib/cache/getLazyHashedEtag"));

var _webpack = require("webpack");

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

// eslint-disable-next-line import/extensions,import/no-unresolved
class Cache {
  // eslint-disable-next-line no-unused-vars
  constructor(compilation, ignored) {
    this.compilation = compilation;
  }

  isEnabled() {
    return Boolean(this.compilation.cache);
  }

  createCacheIdent(task) {
    const {
      outputOptions: {
        hashSalt,
        hashDigest,
        hashDigestLength,
        hashFunction
      }
    } = this.compilation;

    const hash = _webpack.util.createHash(hashFunction);

    if (hashSalt) {
      hash.update(hashSalt);
    }

    hash.update(JSON.stringify(task.cacheKeys));
    const digest = hash.digest(hashDigest);
    const cacheKeys = digest.substr(0, hashDigestLength);
    return `${this.compilation.compilerPath}/CompressionPlugin/${cacheKeys}/${task.filename}`;
  }

  get(task) {
    // eslint-disable-next-line no-param-reassign
    task.cacheIdent = task.cacheIdent || this.createCacheIdent(task); // eslint-disable-next-line no-param-reassign

    task.cacheETag = task.cacheETag || (0, _getLazyHashedEtag.default)(task.assetSource);
    return new Promise((resolve, reject) => {
      this.compilation.cache.get(task.cacheIdent, task.cacheETag, (err, result) => {
        if (err) {
          reject(err);
        } else if (result) {
          resolve(result);
        } else {
          reject();
        }
      });
    });
  }

  store(task, data) {
    return new Promise((resolve, reject) => {
      this.compilation.cache.store(task.cacheIdent, task.cacheETag, data, err => {
        if (err) {
          reject(err);
        } else {
          resolve(data);
        }
      });
    });
  }

}

exports.default = Cache;

Version data entries

15 entries across 14 versions & 4 rubygems

Version Path
disco_app-0.16.1 test/dummy/node_modules/compression-webpack-plugin/dist/Webpack5Cache.js
disco_app-0.15.2 test/dummy/node_modules/compression-webpack-plugin/dist/Webpack5Cache.js
disco_app-0.18.4 test/dummy/node_modules/compression-webpack-plugin/dist/Webpack5Cache.js
disco_app-0.18.1 test/dummy/node_modules/compression-webpack-plugin/dist/Webpack5Cache.js
disco_app-0.12.7.pre.puma.pre.3 test/dummy/node_modules/compression-webpack-plugin/dist/Webpack5Cache.js
disco_app-0.14.0 test/dummy/node_modules/compression-webpack-plugin/dist/Webpack5Cache.js
disco_app-0.13.6.pre.puma.pre.3 test/dummy/node_modules/compression-webpack-plugin/dist/Webpack5Cache.js
tang-0.2.1 spec/tang_app/node_modules/compression-webpack-plugin/dist/Webpack5Cache.js
groonga-client-model-6.0.0 test/apps/rails6.1.3/node_modules/compression-webpack-plugin/dist/Webpack5Cache.js
groonga-client-model-6.0.0 test/apps/rails6.0.3.5/node_modules/compression-webpack-plugin/dist/Webpack5Cache.js
ruby2js-4.0.4 lib/tasks/testrails/node_modules/compression-webpack-plugin/dist/Webpack5Cache.js
ruby2js-4.0.3 lib/tasks/testrails/node_modules/compression-webpack-plugin/dist/Webpack5Cache.js
tang-0.2.0 spec/tang_app/node_modules/compression-webpack-plugin/dist/Webpack5Cache.js
tang-0.1.0 spec/tang_app/node_modules/compression-webpack-plugin/dist/Webpack5Cache.js
tang-0.0.9 spec/tang_app/node_modules/compression-webpack-plugin/dist/Webpack5Cache.js