George Kalpakas 586234bb01 fix(service-worker): detect new version even if files are identical to an old one (#26006)
Previously, if an app version contained the same files as an older
version (e.g. making a change, then rolling it back), the SW would not
detect it as the latest version (and update clients).

This commit fixes it by adding a `timestamp` field in `ngsw.json`, which
makes each build unique (with sufficiently high probability).

Fixes #24338

PR Close #26006
2019-03-05 09:41:44 -08:00

46 lines
1.0 KiB
TypeScript

/**
* @license
* Copyright Google Inc. All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
import {sha1} from './sha1';
export type ManifestHash = string;
export interface Manifest {
configVersion: number;
timestamp: number;
appData?: {[key: string]: string};
index: string;
assetGroups?: AssetGroupConfig[];
dataGroups?: DataGroupConfig[];
navigationUrls: {positive: boolean, regex: string}[];
hashTable: {[url: string]: string};
}
export interface AssetGroupConfig {
name: string;
installMode: 'prefetch'|'lazy';
updateMode: 'prefetch'|'lazy';
urls: string[];
patterns: string[];
}
export interface DataGroupConfig {
name: string;
version: number;
strategy: 'freshness'|'performance';
patterns: string[];
maxSize: number;
timeoutMs?: number;
refreshAheadMs?: number;
maxAge: number;
}
export function hashManifest(manifest: Manifest): ManifestHash {
return sha1(JSON.stringify(manifest));
}