UNPKG

2.12 kBJavaScriptView Raw
1/*
2 Copyright 2019 Google LLC
3
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
9const ol = require('common-tags').oneLine;
10
11
12const checkURLCasing = (options) => {
13 const oldToNewOptionNames = {
14 dontCacheBustUrlsMatching: 'dontCacheBustURLsMatching',
15 ignoreUrlParametersMatching: 'ignoreURLParametersMatching',
16 modifyUrlPrefix: 'modifyURLPrefix',
17 templatedUrls: 'templatedURLs',
18 };
19
20 const warnings = [];
21 for (const [oldOption, newOption] of Object.entries(oldToNewOptionNames)) {
22 if (oldOption in options) {
23 warnings.push(ol`The '${oldOption}' option has been renamed to
24 '${newOption}'. Please update your config. '${oldOption}' is now
25 deprecated and will be removed in a future release of Workbox.`);
26
27 // Rename the option so the config will be valid.
28 options[newOption] = options[oldOption];
29 delete options[oldOption];
30 }
31 }
32 return warnings;
33};
34
35
36const checkStrategyClasses = (options) => {
37 const oldToNewOptionValues = {
38 cacheFirst: 'CacheFirst',
39 cacheOnly: 'CacheOnly',
40 networkFirst: 'NetworkFirst',
41 networkOnly: 'NetworkOnly',
42 staleWhileRevalidate: 'StaleWhileRevalidate',
43 };
44
45 const warnings = [];
46 if (options.runtimeCaching) {
47 for (const entry of options.runtimeCaching) {
48 if (typeof entry.handler === 'string' &&
49 oldToNewOptionValues.hasOwnProperty(entry.handler)) {
50 const oldValue = entry.handler;
51 const newValue = oldToNewOptionValues[entry.handler];
52
53 warnings.push(ol`Specifying '${oldValue}'' in a
54 'runtimeCaching[].handler' option is deprecated. Please update your
55 config to use '${newValue}' instead. In v4 Workbox strategies are now
56 classes instead of functions.`);
57
58 // Set the new value so the config will be valid.
59 entry.handler = newValue;
60 }
61 }
62 }
63 return warnings;
64};
65
66module.exports = (options) => {
67 return [
68 ...checkURLCasing(options),
69 ...checkStrategyClasses(options),
70 ];
71};