additional-manifest-entries-transform.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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. const errors = require('./errors');
  9. module.exports = additionalManifestEntries => {
  10. return manifest => {
  11. const warnings = [];
  12. const stringEntries = new Set();
  13. for (const additionalEntry of additionalManifestEntries) {
  14. // Warn about either a string or an object that lacks a precache property.
  15. // (An object with a revision property set to null is okay.)
  16. if (typeof additionalEntry === 'string') {
  17. stringEntries.add(additionalEntry);
  18. } else if (additionalEntry && additionalEntry.revision === undefined) {
  19. stringEntries.add(additionalEntry.url);
  20. }
  21. manifest.push(additionalEntry);
  22. }
  23. if (stringEntries.size > 0) {
  24. let urls = '\n';
  25. for (const stringEntry of stringEntries) {
  26. urls += ` - ${stringEntry}\n`;
  27. }
  28. warnings.push(errors['string-entry-warning'] + urls);
  29. }
  30. return {
  31. manifest,
  32. warnings
  33. };
  34. };
  35. };