1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 | const ol = require('common-tags').oneLine;
|
10 |
|
11 |
|
12 | const 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 |
|
28 | options[newOption] = options[oldOption];
|
29 | delete options[oldOption];
|
30 | }
|
31 | }
|
32 | return warnings;
|
33 | };
|
34 |
|
35 |
|
36 | const 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 |
|
59 | entry.handler = newValue;
|
60 | }
|
61 | }
|
62 | }
|
63 | return warnings;
|
64 | };
|
65 |
|
66 | module.exports = (options) => {
|
67 | return [
|
68 | ...checkURLCasing(options),
|
69 | ...checkStrategyClasses(options),
|
70 | ];
|
71 | };
|