additional-manifest-entries-transform.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. "use strict";
  2. /*
  3. Copyright 2019 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. Object.defineProperty(exports, "__esModule", { value: true });
  9. exports.additionalManifestEntriesTransform = void 0;
  10. const errors_1 = require("./errors");
  11. function additionalManifestEntriesTransform(additionalManifestEntries) {
  12. return (manifest) => {
  13. const warnings = [];
  14. const stringEntries = new Set();
  15. for (const additionalEntry of additionalManifestEntries) {
  16. // Warn about either a string or an object that lacks a revision property.
  17. // (An object with a revision property set to null is okay.)
  18. if (typeof additionalEntry === 'string') {
  19. stringEntries.add(additionalEntry);
  20. manifest.push({
  21. revision: null,
  22. size: 0,
  23. url: additionalEntry,
  24. });
  25. }
  26. else {
  27. if (additionalEntry && additionalEntry.revision === undefined) {
  28. stringEntries.add(additionalEntry.url);
  29. }
  30. manifest.push(Object.assign({ size: 0 }, additionalEntry));
  31. }
  32. }
  33. if (stringEntries.size > 0) {
  34. let urls = '\n';
  35. for (const stringEntry of stringEntries) {
  36. urls += ` - ${stringEntry}\n`;
  37. }
  38. warnings.push(errors_1.errors['string-entry-warning'] + urls);
  39. }
  40. return {
  41. manifest,
  42. warnings,
  43. };
  44. };
  45. }
  46. exports.additionalManifestEntriesTransform = additionalManifestEntriesTransform;