@serwist/precaching 8.4.3 → 9.0.0-preview.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (74) hide show
  1. package/dist/PrecacheController.d.ts +4 -3
  2. package/dist/PrecacheController.d.ts.map +1 -0
  3. package/dist/PrecacheFallbackPlugin.d.ts +1 -0
  4. package/dist/PrecacheFallbackPlugin.d.ts.map +1 -0
  5. package/dist/PrecacheRoute.d.ts +1 -0
  6. package/dist/PrecacheRoute.d.ts.map +1 -0
  7. package/dist/PrecacheStrategy.d.ts +1 -0
  8. package/dist/PrecacheStrategy.d.ts.map +1 -0
  9. package/dist/_types.d.ts +3 -2
  10. package/dist/_types.d.ts.map +1 -0
  11. package/dist/addPlugins.d.ts +1 -0
  12. package/dist/addPlugins.d.ts.map +1 -0
  13. package/dist/addRoute.d.ts +1 -0
  14. package/dist/addRoute.d.ts.map +1 -0
  15. package/dist/cleanupOutdatedCaches.d.ts +1 -0
  16. package/dist/cleanupOutdatedCaches.d.ts.map +1 -0
  17. package/dist/createHandlerBoundToURL.d.ts +1 -0
  18. package/dist/createHandlerBoundToURL.d.ts.map +1 -0
  19. package/dist/getCacheKeyForURL.d.ts +1 -0
  20. package/dist/getCacheKeyForURL.d.ts.map +1 -0
  21. package/dist/index.d.ts +1 -0
  22. package/dist/index.d.ts.map +1 -0
  23. package/dist/matchPrecache.d.ts +1 -0
  24. package/dist/matchPrecache.d.ts.map +1 -0
  25. package/dist/precache.d.ts +2 -1
  26. package/dist/precache.d.ts.map +1 -0
  27. package/dist/precacheAndRoute.d.ts +2 -1
  28. package/dist/precacheAndRoute.d.ts.map +1 -0
  29. package/dist/utils/PrecacheCacheKeyPlugin.d.ts +1 -0
  30. package/dist/utils/PrecacheCacheKeyPlugin.d.ts.map +1 -0
  31. package/dist/utils/PrecacheInstallReportPlugin.d.ts +1 -0
  32. package/dist/utils/PrecacheInstallReportPlugin.d.ts.map +1 -0
  33. package/dist/utils/createCacheKey.d.ts +1 -0
  34. package/dist/utils/createCacheKey.d.ts.map +1 -0
  35. package/dist/utils/deleteOutdatedCaches.d.ts +1 -0
  36. package/dist/utils/deleteOutdatedCaches.d.ts.map +1 -0
  37. package/dist/utils/generateURLVariations.d.ts +1 -0
  38. package/dist/utils/generateURLVariations.d.ts.map +1 -0
  39. package/dist/utils/getCacheKeyForURL.d.ts +1 -0
  40. package/dist/utils/getCacheKeyForURL.d.ts.map +1 -0
  41. package/dist/utils/getOrCreatePrecacheController.d.ts +1 -0
  42. package/dist/utils/getOrCreatePrecacheController.d.ts.map +1 -0
  43. package/dist/utils/printCleanupDetails.d.ts +1 -0
  44. package/dist/utils/printCleanupDetails.d.ts.map +1 -0
  45. package/dist/utils/printInstallDetails.d.ts +1 -0
  46. package/dist/utils/printInstallDetails.d.ts.map +1 -0
  47. package/dist/utils/removeIgnoredSearchParams.d.ts +1 -0
  48. package/dist/utils/removeIgnoredSearchParams.d.ts.map +1 -0
  49. package/package.json +20 -18
  50. package/src/PrecacheController.ts +331 -0
  51. package/src/PrecacheFallbackPlugin.ts +61 -0
  52. package/src/PrecacheRoute.ts +50 -0
  53. package/src/PrecacheStrategy.ts +239 -0
  54. package/src/_types.ts +46 -0
  55. package/src/addPlugins.ts +23 -0
  56. package/src/addRoute.ts +33 -0
  57. package/src/cleanupOutdatedCaches.ts +34 -0
  58. package/src/createHandlerBoundToURL.ts +32 -0
  59. package/src/getCacheKeyForURL.ts +33 -0
  60. package/{dist/index.d.cts → src/index.ts} +25 -1
  61. package/src/matchPrecache.ts +28 -0
  62. package/src/precache.ts +33 -0
  63. package/src/precacheAndRoute.ts +29 -0
  64. package/src/utils/PrecacheCacheKeyPlugin.ts +36 -0
  65. package/src/utils/PrecacheInstallReportPlugin.ts +49 -0
  66. package/src/utils/createCacheKey.ts +68 -0
  67. package/src/utils/deleteOutdatedCaches.ts +42 -0
  68. package/src/utils/generateURLVariations.ts +55 -0
  69. package/src/utils/getCacheKeyForURL.ts +36 -0
  70. package/src/utils/getOrCreatePrecacheController.ts +22 -0
  71. package/src/utils/printCleanupDetails.ts +38 -0
  72. package/src/utils/printInstallDetails.ts +53 -0
  73. package/src/utils/removeIgnoredSearchParams.ts +29 -0
  74. package/dist/index.cjs +0 -930
@@ -0,0 +1,38 @@
1
+ /*
2
+ Copyright 2018 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
+
9
+ import { logger } from "@serwist/core/internal";
10
+
11
+ /**
12
+ * @param groupTitle
13
+ * @param deletedURLs
14
+ *
15
+ * @private
16
+ */
17
+ const logGroup = (groupTitle: string, deletedURLs: string[]) => {
18
+ logger.groupCollapsed(groupTitle);
19
+
20
+ for (const url of deletedURLs) {
21
+ logger.log(url);
22
+ }
23
+
24
+ logger.groupEnd();
25
+ };
26
+
27
+ /**
28
+ * @param deletedURLs
29
+ * @private
30
+ */
31
+ export function printCleanupDetails(deletedURLs: string[]): void {
32
+ const deletionCount = deletedURLs.length;
33
+ if (deletionCount > 0) {
34
+ logger.groupCollapsed(`During precaching cleanup, ${deletionCount} cached request${deletionCount === 1 ? " was" : "s were"} deleted.`);
35
+ logGroup("Deleted Cache Requests", deletedURLs);
36
+ logger.groupEnd();
37
+ }
38
+ }
@@ -0,0 +1,53 @@
1
+ /*
2
+ Copyright 2018 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
+
9
+ import { logger } from "@serwist/core/internal";
10
+
11
+ /**
12
+ * @param groupTitle
13
+ * @param urls
14
+ *
15
+ * @private
16
+ */
17
+ function _nestedGroup(groupTitle: string, urls: string[]): void {
18
+ if (urls.length === 0) {
19
+ return;
20
+ }
21
+
22
+ logger.groupCollapsed(groupTitle);
23
+
24
+ for (const url of urls) {
25
+ logger.log(url);
26
+ }
27
+
28
+ logger.groupEnd();
29
+ }
30
+
31
+ /**
32
+ * @param urlsToPrecache
33
+ * @param urlsAlreadyPrecached
34
+ * @private
35
+ */
36
+ export function printInstallDetails(urlsToPrecache: string[], urlsAlreadyPrecached: string[]): void {
37
+ const precachedCount = urlsToPrecache.length;
38
+ const alreadyPrecachedCount = urlsAlreadyPrecached.length;
39
+
40
+ if (precachedCount || alreadyPrecachedCount) {
41
+ let message = `Precaching ${precachedCount} file${precachedCount === 1 ? "" : "s"}.`;
42
+
43
+ if (alreadyPrecachedCount > 0) {
44
+ message += ` ${alreadyPrecachedCount} ` + `file${alreadyPrecachedCount === 1 ? " is" : "s are"} already cached.`;
45
+ }
46
+
47
+ logger.groupCollapsed(message);
48
+
49
+ _nestedGroup("View newly precached URLs.", urlsToPrecache);
50
+ _nestedGroup("View previously precached URLs.", urlsAlreadyPrecached);
51
+ logger.groupEnd();
52
+ }
53
+ }
@@ -0,0 +1,29 @@
1
+ /*
2
+ Copyright 2018 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
+
9
+ /**
10
+ * Removes any URL search parameters that should be ignored.
11
+ *
12
+ * @param urlObject The original URL.
13
+ * @param ignoreURLParametersMatching RegExps to test against
14
+ * each search parameter name. Matches mean that the search parameter should be
15
+ * ignored.
16
+ * @returns The URL with any ignored search parameters removed.
17
+ * @private
18
+ */
19
+ export function removeIgnoredSearchParams(urlObject: URL, ignoreURLParametersMatching: RegExp[] = []): URL {
20
+ // Convert the iterable into an array at the start of the loop to make sure
21
+ // deletion doesn't mess up iteration.
22
+ for (const paramName of [...urlObject.searchParams.keys()]) {
23
+ if (ignoreURLParametersMatching.some((regExp) => regExp.test(paramName))) {
24
+ urlObject.searchParams.delete(paramName);
25
+ }
26
+ }
27
+
28
+ return urlObject;
29
+ }