Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@serwist/precaching

Package Overview
Dependencies
Maintainers
1
Versions
52
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@serwist/precaching - npm Package Compare versions

Comparing version 9.0.0-preview.17 to 9.0.0-preview.18

31

dist/index.d.ts

@@ -1,27 +0,6 @@

import { PrecacheController } from "./PrecacheController.js";
import { PrecacheFallbackPlugin } from "./PrecacheFallbackPlugin.js";
import type { PrecacheFallbackEntry, PrecacheFallbackPluginOptions } from "./PrecacheFallbackPlugin.js";
import { PrecacheRoute } from "./PrecacheRoute.js";
import { PrecacheStrategy } from "./PrecacheStrategy.js";
import { addPlugins } from "./addPlugins.js";
import { addRoute } from "./addRoute.js";
import { cleanupOutdatedCaches } from "./cleanupOutdatedCaches.js";
import { createHandlerBoundToURL } from "./createHandlerBoundToURL.js";
import { getCacheKeyForURL } from "./getCacheKeyForURL.js";
import { matchPrecache } from "./matchPrecache.js";
import { precache } from "./precache.js";
import { precacheAndRoute } from "./precacheAndRoute.js";
/**
* Most consumers of this module will want to use the
* `@serwist/precaching.precacheAndRoute`
* method to add assets to the cache and respond to network requests with these
* cached assets.
*
* If you require more control over caching and routing, you can use the
* `@serwist/precaching.PrecacheController`
* interface.
*/
export { addPlugins, addRoute, cleanupOutdatedCaches, createHandlerBoundToURL, getCacheKeyForURL, matchPrecache, precache, precacheAndRoute, PrecacheController, PrecacheFallbackPlugin, PrecacheRoute, PrecacheStrategy, };
export type * from "./_types.js";
export type { PrecacheFallbackPluginOptions, PrecacheFallbackEntry };
export { addPlugins, addRoute, cleanupOutdatedCaches, createHandlerBoundToURL, getCacheKeyForURL, matchPrecache, precache, precacheAndRoute, PrecacheController, PrecacheRoute, PrecacheStrategy, } from "@serwist/sw/precaching";
export { PrecacheFallbackPlugin } from "@serwist/sw/plugins";
export type * from "@serwist/sw/precaching";
export type { UrlManipulation as urlManipulation } from "@serwist/sw/precaching";
export type { PrecacheFallbackEntry, PrecacheFallbackPluginOptions } from "@serwist/sw/plugins";
//# sourceMappingURL=index.d.ts.map

@@ -1,155 +0,2 @@

import { g as getOrCreatePrecacheController } from './chunks/getOrCreatePrecacheController.js';
export { P as PrecacheController, a as PrecacheStrategy } from './chunks/getOrCreatePrecacheController.js';
import { logger, getFriendlyURL, privateCacheNames } from '@serwist/core/internal';
import { Route, registerRoute } from '@serwist/routing';
import '@serwist/core';
import '@serwist/strategies';
class PrecacheFallbackPlugin {
_fallbackUrls;
_precacheController;
constructor({ fallbackUrls, precacheController }){
this._fallbackUrls = fallbackUrls;
this._precacheController = precacheController || getOrCreatePrecacheController();
}
async handlerDidError(param) {
for (const fallback of this._fallbackUrls){
if (typeof fallback === "string") {
const fallbackResponse = await this._precacheController.matchPrecache(fallback);
if (fallbackResponse !== undefined) {
return fallbackResponse;
}
} else if (fallback.matcher(param)) {
const fallbackResponse = await this._precacheController.matchPrecache(fallback.url);
if (fallbackResponse !== undefined) {
return fallbackResponse;
}
}
}
return undefined;
}
}
function removeIgnoredSearchParams(urlObject, ignoreURLParametersMatching = []) {
for (const paramName of [
...urlObject.searchParams.keys()
]){
if (ignoreURLParametersMatching.some((regExp)=>regExp.test(paramName))) {
urlObject.searchParams.delete(paramName);
}
}
return urlObject;
}
function* generateURLVariations(url, { ignoreURLParametersMatching = [
/^utm_/,
/^fbclid$/
], directoryIndex = "index.html", cleanURLs = true, urlManipulation } = {}) {
const urlObject = new URL(url, location.href);
urlObject.hash = "";
yield urlObject.href;
const urlWithoutIgnoredParams = removeIgnoredSearchParams(urlObject, ignoreURLParametersMatching);
yield urlWithoutIgnoredParams.href;
if (directoryIndex && urlWithoutIgnoredParams.pathname.endsWith("/")) {
const directoryURL = new URL(urlWithoutIgnoredParams.href);
directoryURL.pathname += directoryIndex;
yield directoryURL.href;
}
if (cleanURLs) {
const cleanURL = new URL(urlWithoutIgnoredParams.href);
cleanURL.pathname += ".html";
yield cleanURL.href;
}
if (urlManipulation) {
const additionalURLs = urlManipulation({
url: urlObject
});
for (const urlToAttempt of additionalURLs){
yield urlToAttempt.href;
}
}
}
class PrecacheRoute extends Route {
constructor(precacheController, options){
const match = ({ request })=>{
const urlsToCacheKeys = precacheController.getURLsToCacheKeys();
for (const possibleURL of generateURLVariations(request.url, options)){
const cacheKey = urlsToCacheKeys.get(possibleURL);
if (cacheKey) {
const integrity = precacheController.getIntegrityForCacheKey(cacheKey);
return {
cacheKey,
integrity
};
}
}
if (process.env.NODE_ENV !== "production") {
logger.debug(`Precaching did not find a match for ${getFriendlyURL(request.url)}`);
}
return;
};
super(match, precacheController.strategy);
}
}
function addPlugins(plugins) {
const precacheController = getOrCreatePrecacheController();
precacheController.strategy.plugins.push(...plugins);
}
const addRoute = (options)=>{
const precacheController = getOrCreatePrecacheController();
const precacheRoute = new PrecacheRoute(precacheController, options);
registerRoute(precacheRoute);
};
const SUBSTRING_TO_FIND = "-precache-";
const deleteOutdatedCaches = async (currentPrecacheName, substringToFind = SUBSTRING_TO_FIND)=>{
const cacheNames = await self.caches.keys();
const cacheNamesToDelete = cacheNames.filter((cacheName)=>{
return cacheName.includes(substringToFind) && cacheName.includes(self.registration.scope) && cacheName !== currentPrecacheName;
});
await Promise.all(cacheNamesToDelete.map((cacheName)=>self.caches.delete(cacheName)));
return cacheNamesToDelete;
};
const cleanupOutdatedCaches = ()=>{
self.addEventListener("activate", (event)=>{
const cacheName = privateCacheNames.getPrecacheName();
event.waitUntil(deleteOutdatedCaches(cacheName).then((cachesDeleted)=>{
if (process.env.NODE_ENV !== "production") {
if (cachesDeleted.length > 0) {
logger.log("The following out-of-date precaches were cleaned up automatically:", cachesDeleted);
}
}
}));
});
};
const createHandlerBoundToURL = (url)=>{
const precacheController = getOrCreatePrecacheController();
return precacheController.createHandlerBoundToURL(url);
};
function getCacheKeyForURL(url) {
const precacheController = getOrCreatePrecacheController();
return precacheController.getCacheKeyForURL(url);
}
function matchPrecache(request) {
const precacheController = getOrCreatePrecacheController();
return precacheController.matchPrecache(request);
}
const precache = (entries)=>{
const precacheController = getOrCreatePrecacheController();
precacheController.precache(entries);
};
const precacheAndRoute = (entries, options)=>{
precache(entries);
addRoute(options);
};
export { PrecacheFallbackPlugin, PrecacheRoute, addPlugins, addRoute, cleanupOutdatedCaches, createHandlerBoundToURL, getCacheKeyForURL, matchPrecache, precache, precacheAndRoute };
export { PrecacheController, PrecacheRoute, PrecacheStrategy, addPlugins, addRoute, cleanupOutdatedCaches, createHandlerBoundToURL, getCacheKeyForURL, matchPrecache, precache, precacheAndRoute } from '@serwist/sw/precaching';
export { PrecacheFallbackPlugin } from '@serwist/sw/plugins';
{
"name": "@serwist/precaching",
"version": "9.0.0-preview.17",
"version": "9.0.0-preview.18",
"type": "module",

@@ -23,9 +23,2 @@ "description": "A module that efficiently precaches assets.",

"types": "./dist/index.d.ts",
"typesVersions": {
"*": {
"internal": [
"./dist/index.internal.d.ts"
]
}
},
"exports": {

@@ -36,12 +29,6 @@ ".": {

},
"./internal": {
"types": "./dist/index.internal.d.ts",
"default": "./dist/index.internal.js"
},
"./package.json": "./package.json"
},
"dependencies": {
"@serwist/core": "9.0.0-preview.17",
"@serwist/routing": "9.0.0-preview.17",
"@serwist/strategies": "9.0.0-preview.17"
"@serwist/sw": "9.0.0-preview.18"
},

@@ -51,4 +38,3 @@ "devDependencies": {

"typescript": "5.5.0-dev.20240323",
"@serwist/constants": "9.0.0-preview.17",
"@serwist/utils": "9.0.0-preview.17"
"@serwist/constants": "9.0.0-preview.18"
},

@@ -55,0 +41,0 @@ "peerDependencies": {

@@ -1,34 +0,1 @@

/*
Copyright 2018 Google LLC
Use of this source code is governed by an MIT-style
license that can be found in the LICENSE file or at
https://opensource.org/licenses/MIT.
*/
import { PrecacheController } from "./PrecacheController.js";
import { PrecacheFallbackPlugin } from "./PrecacheFallbackPlugin.js";
import type { PrecacheFallbackEntry, PrecacheFallbackPluginOptions } from "./PrecacheFallbackPlugin.js";
import { PrecacheRoute } from "./PrecacheRoute.js";
import { PrecacheStrategy } from "./PrecacheStrategy.js";
import { addPlugins } from "./addPlugins.js";
import { addRoute } from "./addRoute.js";
import { cleanupOutdatedCaches } from "./cleanupOutdatedCaches.js";
import { createHandlerBoundToURL } from "./createHandlerBoundToURL.js";
import { getCacheKeyForURL } from "./getCacheKeyForURL.js";
import { matchPrecache } from "./matchPrecache.js";
import { precache } from "./precache.js";
import { precacheAndRoute } from "./precacheAndRoute.js";
/**
* Most consumers of this module will want to use the
* `@serwist/precaching.precacheAndRoute`
* method to add assets to the cache and respond to network requests with these
* cached assets.
*
* If you require more control over caching and routing, you can use the
* `@serwist/precaching.PrecacheController`
* interface.
*/
export {

@@ -44,9 +11,8 @@ addPlugins,

PrecacheController,
PrecacheFallbackPlugin,
PrecacheRoute,
PrecacheStrategy,
};
export type * from "./_types.js";
export type { PrecacheFallbackPluginOptions, PrecacheFallbackEntry };
} from "@serwist/sw/precaching";
export { PrecacheFallbackPlugin } from "@serwist/sw/plugins";
export type * from "@serwist/sw/precaching";
export type { UrlManipulation as urlManipulation } from "@serwist/sw/precaching";
export type { PrecacheFallbackEntry, PrecacheFallbackPluginOptions } from "@serwist/sw/plugins";

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc