This commit is contained in:
Iliyan Angelov
2025-09-14 23:24:25 +03:00
commit c67067a2a4
71311 changed files with 6800714 additions and 0 deletions

View File

@@ -0,0 +1,17 @@
import { WorkboxPlugin } from 'workbox-core/types.js';
import { PrecacheController } from '../PrecacheController.js';
import '../_version.js';
/**
* A plugin, designed to be used with PrecacheController, to translate URLs into
* the corresponding cache key, based on the current revision info.
*
* @private
*/
declare class PrecacheCacheKeyPlugin implements WorkboxPlugin {
private readonly _precacheController;
constructor({ precacheController }: {
precacheController: PrecacheController;
});
cacheKeyWillBeUsed: WorkboxPlugin['cacheKeyWillBeUsed'];
}
export { PrecacheCacheKeyPlugin };

View File

@@ -0,0 +1,30 @@
/*
Copyright 2020 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 '../_version.js';
/**
* A plugin, designed to be used with PrecacheController, to translate URLs into
* the corresponding cache key, based on the current revision info.
*
* @private
*/
class PrecacheCacheKeyPlugin {
constructor({ precacheController }) {
this.cacheKeyWillBeUsed = async ({ request, params, }) => {
// Params is type any, can't change right now.
/* eslint-disable */
const cacheKey = (params === null || params === void 0 ? void 0 : params.cacheKey) ||
this._precacheController.getCacheKeyForURL(request.url);
/* eslint-enable */
return cacheKey
? new Request(cacheKey, { headers: request.headers })
: request;
};
this._precacheController = precacheController;
}
}
export { PrecacheCacheKeyPlugin };

View File

@@ -0,0 +1 @@
export * from './PrecacheCacheKeyPlugin.js';

View File

@@ -0,0 +1,15 @@
import { WorkboxPlugin } from 'workbox-core/types.js';
import '../_version.js';
/**
* A plugin, designed to be used with PrecacheController, to determine the
* of assets that were updated (or not updated) during the install event.
*
* @private
*/
declare class PrecacheInstallReportPlugin implements WorkboxPlugin {
updatedURLs: string[];
notUpdatedURLs: string[];
handlerWillStart: WorkboxPlugin['handlerWillStart'];
cachedResponseWillBeUsed: WorkboxPlugin['cachedResponseWillBeUsed'];
}
export { PrecacheInstallReportPlugin };

View File

@@ -0,0 +1,44 @@
/*
Copyright 2020 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 '../_version.js';
/**
* A plugin, designed to be used with PrecacheController, to determine the
* of assets that were updated (or not updated) during the install event.
*
* @private
*/
class PrecacheInstallReportPlugin {
constructor() {
this.updatedURLs = [];
this.notUpdatedURLs = [];
this.handlerWillStart = async ({ request, state, }) => {
// TODO: `state` should never be undefined...
if (state) {
state.originalRequest = request;
}
};
this.cachedResponseWillBeUsed = async ({ event, state, cachedResponse, }) => {
if (event.type === 'install') {
if (state &&
state.originalRequest &&
state.originalRequest instanceof Request) {
// TODO: `state` should never be undefined...
const url = state.originalRequest.url;
if (cachedResponse) {
this.notUpdatedURLs.push(url);
}
else {
this.updatedURLs.push(url);
}
}
}
return cachedResponse;
};
}
}
export { PrecacheInstallReportPlugin };

View File

@@ -0,0 +1 @@
export * from './PrecacheInstallReportPlugin.js';

View File

@@ -0,0 +1,17 @@
import { PrecacheEntry } from '../_types.js';
import '../_version.js';
interface CacheKey {
cacheKey: string;
url: string;
}
/**
* Converts a manifest entry into a versioned URL suitable for precaching.
*
* @param {Object|string} entry
* @return {string} A URL with versioning info.
*
* @private
* @memberof workbox-precaching
*/
export declare function createCacheKey(entry: PrecacheEntry | string): CacheKey;
export {};

View File

@@ -0,0 +1,56 @@
/*
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 { WorkboxError } from 'workbox-core/_private/WorkboxError.js';
import '../_version.js';
// Name of the search parameter used to store revision info.
const REVISION_SEARCH_PARAM = '__WB_REVISION__';
/**
* Converts a manifest entry into a versioned URL suitable for precaching.
*
* @param {Object|string} entry
* @return {string} A URL with versioning info.
*
* @private
* @memberof workbox-precaching
*/
export function createCacheKey(entry) {
if (!entry) {
throw new WorkboxError('add-to-cache-list-unexpected-type', { entry });
}
// If a precache manifest entry is a string, it's assumed to be a versioned
// URL, like '/app.abcd1234.js'. Return as-is.
if (typeof entry === 'string') {
const urlObject = new URL(entry, location.href);
return {
cacheKey: urlObject.href,
url: urlObject.href,
};
}
const { revision, url } = entry;
if (!url) {
throw new WorkboxError('add-to-cache-list-unexpected-type', { entry });
}
// If there's just a URL and no revision, then it's also assumed to be a
// versioned URL.
if (!revision) {
const urlObject = new URL(url, location.href);
return {
cacheKey: urlObject.href,
url: urlObject.href,
};
}
// Otherwise, construct a properly versioned URL using the custom Workbox
// search parameter along with the revision info.
const cacheKeyURL = new URL(url, location.href);
const originalURL = new URL(url, location.href);
cacheKeyURL.searchParams.set(REVISION_SEARCH_PARAM, revision);
return {
cacheKey: cacheKeyURL.href,
url: originalURL.href,
};
}

View File

@@ -0,0 +1 @@
export * from './createCacheKey.js';

View File

@@ -0,0 +1,21 @@
import '../_version.js';
/**
* Cleans up incompatible precaches that were created by older versions of
* Workbox, by a service worker registered under the current scope.
*
* This is meant to be called as part of the `activate` event.
*
* This should be safe to use as long as you don't include `substringToFind`
* (defaulting to `-precache-`) in your non-precache cache names.
*
* @param {string} currentPrecacheName The cache name currently in use for
* precaching. This cache won't be deleted.
* @param {string} [substringToFind='-precache-'] Cache names which include this
* substring will be deleted (excluding `currentPrecacheName`).
* @return {Array<string>} A list of all the cache names that were deleted.
*
* @private
* @memberof workbox-precaching
*/
declare const deleteOutdatedCaches: (currentPrecacheName: string, substringToFind?: string) => Promise<string[]>;
export { deleteOutdatedCaches };

View File

@@ -0,0 +1,38 @@
/*
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 '../_version.js';
const SUBSTRING_TO_FIND = '-precache-';
/**
* Cleans up incompatible precaches that were created by older versions of
* Workbox, by a service worker registered under the current scope.
*
* This is meant to be called as part of the `activate` event.
*
* This should be safe to use as long as you don't include `substringToFind`
* (defaulting to `-precache-`) in your non-precache cache names.
*
* @param {string} currentPrecacheName The cache name currently in use for
* precaching. This cache won't be deleted.
* @param {string} [substringToFind='-precache-'] Cache names which include this
* substring will be deleted (excluding `currentPrecacheName`).
* @return {Array<string>} A list of all the cache names that were deleted.
*
* @private
* @memberof workbox-precaching
*/
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;
};
export { deleteOutdatedCaches };

View File

@@ -0,0 +1 @@
export * from './deleteOutdatedCaches.js';

View File

@@ -0,0 +1,13 @@
import { PrecacheRouteOptions } from '../_types.js';
import '../_version.js';
/**
* Generator function that yields possible variations on the original URL to
* check, one at a time.
*
* @param {string} url
* @param {Object} options
*
* @private
* @memberof workbox-precaching
*/
export declare function generateURLVariations(url: string, { ignoreURLParametersMatching, directoryIndex, cleanURLs, urlManipulation, }?: PrecacheRouteOptions): Generator<string, void, unknown>;

View File

@@ -0,0 +1,42 @@
/*
Copyright 2019 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 { removeIgnoredSearchParams } from './removeIgnoredSearchParams.js';
import '../_version.js';
/**
* Generator function that yields possible variations on the original URL to
* check, one at a time.
*
* @param {string} url
* @param {Object} options
*
* @private
* @memberof workbox-precaching
*/
export 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;
}
}
}

View File

@@ -0,0 +1 @@
export * from './generateURLVariations.js';

View File

@@ -0,0 +1,14 @@
import { PrecacheRouteOptions } from '../_types.js';
import '../_version.js';
/**
* This function will take the request URL and manipulate it based on the
* configuration options.
*
* @param {string} url
* @param {Object} options
* @return {string} Returns the URL in the cache that matches the request,
* if possible.
*
* @private
*/
export declare const getCacheKeyForURL: (url: string, options: PrecacheRouteOptions) => string | void;

View File

@@ -0,0 +1,31 @@
/*
Copyright 2019 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 { getOrCreatePrecacheController } from './getOrCreatePrecacheController.js';
import { generateURLVariations } from './generateURLVariations.js';
import '../_version.js';
/**
* This function will take the request URL and manipulate it based on the
* configuration options.
*
* @param {string} url
* @param {Object} options
* @return {string} Returns the URL in the cache that matches the request,
* if possible.
*
* @private
*/
export const getCacheKeyForURL = (url, options) => {
const precacheController = getOrCreatePrecacheController();
const urlsToCacheKeys = precacheController.getURLsToCacheKeys();
for (const possibleURL of generateURLVariations(url, options)) {
const possibleCacheKey = urlsToCacheKeys.get(possibleURL);
if (possibleCacheKey) {
return possibleCacheKey;
}
}
};

View File

@@ -0,0 +1 @@
export * from './getCacheKeyForURL.js';

View File

@@ -0,0 +1,7 @@
import { PrecacheController } from '../PrecacheController.js';
import '../_version.js';
/**
* @return {PrecacheController}
* @private
*/
export declare const getOrCreatePrecacheController: () => PrecacheController;

View File

@@ -0,0 +1,20 @@
/*
Copyright 2019 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 '../_version.js';
let precacheController;
/**
* @return {PrecacheController}
* @private
*/
export const getOrCreatePrecacheController = () => {
if (!precacheController) {
precacheController = new PrecacheController();
}
return precacheController;
};

View File

@@ -0,0 +1 @@
export * from './getOrCreatePrecacheController.js';

View File

@@ -0,0 +1,8 @@
import '../_version.js';
/**
* @param {Array<string>} deletedURLs
*
* @private
* @memberof workbox-precaching
*/
export declare function printCleanupDetails(deletedURLs: string[]): void;

View File

@@ -0,0 +1,38 @@
/*
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 { logger } from 'workbox-core/_private/logger.js';
import '../_version.js';
/**
* @param {string} groupTitle
* @param {Array<string>} deletedURLs
*
* @private
*/
const logGroup = (groupTitle, deletedURLs) => {
logger.groupCollapsed(groupTitle);
for (const url of deletedURLs) {
logger.log(url);
}
logger.groupEnd();
};
/**
* @param {Array<string>} deletedURLs
*
* @private
* @memberof workbox-precaching
*/
export function printCleanupDetails(deletedURLs) {
const deletionCount = deletedURLs.length;
if (deletionCount > 0) {
logger.groupCollapsed(`During precaching cleanup, ` +
`${deletionCount} cached ` +
`request${deletionCount === 1 ? ' was' : 's were'} deleted.`);
logGroup('Deleted Cache Requests', deletedURLs);
logger.groupEnd();
}
}

View File

@@ -0,0 +1 @@
export * from './printCleanupDetails.js';

View File

@@ -0,0 +1,9 @@
import '../_version.js';
/**
* @param {Array<string>} urlsToPrecache
* @param {Array<string>} urlsAlreadyPrecached
*
* @private
* @memberof workbox-precaching
*/
export declare function printInstallDetails(urlsToPrecache: string[], urlsAlreadyPrecached: string[]): void;

View File

@@ -0,0 +1,48 @@
/*
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 { logger } from 'workbox-core/_private/logger.js';
import '../_version.js';
/**
* @param {string} groupTitle
* @param {Array<string>} urls
*
* @private
*/
function _nestedGroup(groupTitle, urls) {
if (urls.length === 0) {
return;
}
logger.groupCollapsed(groupTitle);
for (const url of urls) {
logger.log(url);
}
logger.groupEnd();
}
/**
* @param {Array<string>} urlsToPrecache
* @param {Array<string>} urlsAlreadyPrecached
*
* @private
* @memberof workbox-precaching
*/
export function printInstallDetails(urlsToPrecache, urlsAlreadyPrecached) {
const precachedCount = urlsToPrecache.length;
const alreadyPrecachedCount = urlsAlreadyPrecached.length;
if (precachedCount || alreadyPrecachedCount) {
let message = `Precaching ${precachedCount} file${precachedCount === 1 ? '' : 's'}.`;
if (alreadyPrecachedCount > 0) {
message +=
` ${alreadyPrecachedCount} ` +
`file${alreadyPrecachedCount === 1 ? ' is' : 's are'} already cached.`;
}
logger.groupCollapsed(message);
_nestedGroup(`View newly precached URLs.`, urlsToPrecache);
_nestedGroup(`View previously precached URLs.`, urlsAlreadyPrecached);
logger.groupEnd();
}
}

View File

@@ -0,0 +1 @@
export * from './printInstallDetails.js';

View File

@@ -0,0 +1,14 @@
import '../_version.js';
/**
* Removes any URL search parameters that should be ignored.
*
* @param {URL} urlObject The original URL.
* @param {Array<RegExp>} ignoreURLParametersMatching RegExps to test against
* each search parameter name. Matches mean that the search parameter should be
* ignored.
* @return {URL} The URL with any ignored search parameters removed.
*
* @private
* @memberof workbox-precaching
*/
export declare function removeIgnoredSearchParams(urlObject: URL, ignoreURLParametersMatching?: RegExp[]): URL;

View File

@@ -0,0 +1,30 @@
/*
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 '../_version.js';
/**
* Removes any URL search parameters that should be ignored.
*
* @param {URL} urlObject The original URL.
* @param {Array<RegExp>} ignoreURLParametersMatching RegExps to test against
* each search parameter name. Matches mean that the search parameter should be
* ignored.
* @return {URL} The URL with any ignored search parameters removed.
*
* @private
* @memberof workbox-precaching
*/
export function removeIgnoredSearchParams(urlObject, ignoreURLParametersMatching = []) {
// Convert the iterable into an array at the start of the loop to make sure
// deletion doesn't mess up iteration.
for (const paramName of [...urlObject.searchParams.keys()]) {
if (ignoreURLParametersMatching.some((regExp) => regExp.test(paramName))) {
urlObject.searchParams.delete(paramName);
}
}
return urlObject;
}

View File

@@ -0,0 +1 @@
export * from './removeIgnoredSearchParams.js';