get-asset-hash.js 1.0 KB

1234567891011121314151617181920212223242526272829303132
  1. "use strict";
  2. /*
  3. Copyright 2018 Google LLC
  4. Use of this source code is governed by an MIT-style
  5. license that can be found in the LICENSE file or at
  6. https://opensource.org/licenses/MIT.
  7. */
  8. var __importDefault = (this && this.__importDefault) || function (mod) {
  9. return (mod && mod.__esModule) ? mod : { "default": mod };
  10. };
  11. Object.defineProperty(exports, "__esModule", { value: true });
  12. exports.getAssetHash = void 0;
  13. const crypto_1 = __importDefault(require("crypto"));
  14. /**
  15. * @param {Asset} asset
  16. * @return {string} The MD5 hash of the asset's source.
  17. *
  18. * @private
  19. */
  20. function getAssetHash(asset) {
  21. // If webpack has the asset marked as immutable, then we don't need to
  22. // use an out-of-band revision for it.
  23. // See https://github.com/webpack/webpack/issues/9038
  24. if (asset.info && asset.info.immutable) {
  25. return null;
  26. }
  27. return crypto_1.default.createHash('md5')
  28. .update(Buffer.from(asset.source.source()))
  29. .digest('hex');
  30. }
  31. exports.getAssetHash = getAssetHash;