warn-about-config.js 1.4 KB

123456789101112131415161718192021222324252627
  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. module.exports = config => {
  9. const moreInfoURL = 'https://goo.gl/EQ4Rhm';
  10. const globOptions = ['globDirectory', 'globFollow', 'globIgnores', 'globPatterns', 'globStrict'];
  11. const usedGlobOptions = globOptions.filter(option => option in config);
  12. if (usedGlobOptions.length > 0) {
  13. return `You're using the following Workbox configuration option` + `${usedGlobOptions.length === 1 ? '' : 's'}: ` + `[${usedGlobOptions.join(', ')}]. In Workbox v3 and later, this is ` + `usually not needed. Please see ${moreInfoURL} for more info.`;
  14. }
  15. const optionsToWarnAboutWhenGlobPatternsIsNotSet = ['dontCacheBustURLsMatching', 'manifestTransforms', 'maximumFileSizeToCacheInBytes', 'modifyURLPrefix'];
  16. const usedNoopOptions = optionsToWarnAboutWhenGlobPatternsIsNotSet.filter(option => option in config);
  17. if (usedNoopOptions.length > 0) {
  18. return `You're using the following Workbox configuration option` + `${usedGlobOptions.length === 1 ? '' : 's'}: ` + `[${usedNoopOptions.join(', ')}]. This will not have any effect, as ` + `it will only modify files that are matched via 'globPatterns'. You ` + `can remove them from your config, and learn more at ${moreInfoURL}`;
  19. }
  20. return null;
  21. };