maximum-size-transform.js 1.1 KB

123456789101112131415161718192021222324252627282930
  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.maximumSizeTransform = void 0;
  13. const pretty_bytes_1 = __importDefault(require("pretty-bytes"));
  14. function maximumSizeTransform(maximumFileSizeToCacheInBytes) {
  15. return (originalManifest) => {
  16. const warnings = [];
  17. const manifest = originalManifest.filter((entry) => {
  18. if (entry.size <= maximumFileSizeToCacheInBytes) {
  19. return true;
  20. }
  21. warnings.push(`${entry.url} is ${(0, pretty_bytes_1.default)(entry.size)}, and won't ` +
  22. `be precached. Configure maximumFileSizeToCacheInBytes to change ` +
  23. `this limit.`);
  24. return false;
  25. });
  26. return { manifest, warnings };
  27. };
  28. }
  29. exports.maximumSizeTransform = maximumSizeTransform;