fix(service-worker): deprecate `versionedFiles` in asset-group resources (#23584)
Since `versionedFiles` behaves in the exact same way as `files`, there is no reaason to have both. Users should use `files` instead. This commit deprecates the property and prints a warning when coming across an asset-group that uses it. It should be completely removed in a future version. Note, it has also been removed from the default `ngsw-config.json` template in angular/devkit#754. PR Close #23584
This commit is contained in:
parent
017d67cdf8
commit
1d378e2987
|
@ -7,12 +7,9 @@
|
||||||
"resources": {
|
"resources": {
|
||||||
"files": [
|
"files": [
|
||||||
"/favicon.ico",
|
"/favicon.ico",
|
||||||
"/index.html"
|
"/index.html",
|
||||||
],
|
"/*.css",
|
||||||
"versionedFiles": [
|
"/*.js"
|
||||||
"/*.bundle.css",
|
|
||||||
"/*.bundle.js",
|
|
||||||
"/*.chunk.js"
|
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}, {
|
}, {
|
||||||
|
|
|
@ -70,6 +70,7 @@ interface AssetGroup {
|
||||||
updateMode?: 'prefetch' | 'lazy';
|
updateMode?: 'prefetch' | 'lazy';
|
||||||
resources: {
|
resources: {
|
||||||
files?: string[];
|
files?: string[];
|
||||||
|
/** @deprecated As of v6 `versionedFiles` and `files` options have the same behavior. Use `files` instead. */
|
||||||
versionedFiles?: string[];
|
versionedFiles?: string[];
|
||||||
urls?: string[];
|
urls?: string[];
|
||||||
};
|
};
|
||||||
|
@ -102,7 +103,7 @@ This section describes the resources to cache, broken up into three groups.
|
||||||
|
|
||||||
* `files` lists patterns that match files in the distribution directory. These can be single files or glob-like patterns that match a number of files.
|
* `files` lists patterns that match files in the distribution directory. These can be single files or glob-like patterns that match a number of files.
|
||||||
|
|
||||||
* `versionedFiles` is like `files` but should be used for build artifacts that already include a hash in the filename, which is used for cache busting. The Angular service worker can optimize some aspects of its operation if it can assume file contents are immutable.
|
* `versionedFiles` has been deprecated. As of v6 `versionedFiles` and `files` options have the same behavior. Use `files` instead.
|
||||||
|
|
||||||
* `urls` includes both URLs and URL patterns that will be matched at runtime. These resources are not fetched directly and do not have content hashes, but they will be cached according to their HTTP headers. This is most useful for CDNs such as the Google Fonts service.<br>
|
* `urls` includes both URLs and URL patterns that will be matched at runtime. These resources are not fetched directly and do not have content hashes, but they will be cached according to their HTTP headers. This is most useful for CDNs such as the Google Fonts service.<br>
|
||||||
_(Negative glob patterns are not supported.)_
|
_(Negative glob patterns are not supported.)_
|
||||||
|
|
|
@ -44,6 +44,13 @@ export class Generator {
|
||||||
Promise<Object[]> {
|
Promise<Object[]> {
|
||||||
const seenMap = new Set<string>();
|
const seenMap = new Set<string>();
|
||||||
return Promise.all((config.assetGroups || []).map(async(group) => {
|
return Promise.all((config.assetGroups || []).map(async(group) => {
|
||||||
|
if (group.resources.versionedFiles) {
|
||||||
|
console.warn(
|
||||||
|
`Asset-group '${group.name}' in 'ngsw-config.json' uses the 'versionedFiles' option.\n` +
|
||||||
|
'As of v6 \'versionedFiles\' and \'files\' options have the same behavior. ' +
|
||||||
|
'Use \'files\' instead.');
|
||||||
|
}
|
||||||
|
|
||||||
const fileMatcher = globListToMatcher(group.resources.files || []);
|
const fileMatcher = globListToMatcher(group.resources.files || []);
|
||||||
const versionedMatcher = globListToMatcher(group.resources.versionedFiles || []);
|
const versionedMatcher = globListToMatcher(group.resources.versionedFiles || []);
|
||||||
|
|
||||||
|
|
|
@ -38,7 +38,13 @@ export interface AssetGroup {
|
||||||
name: string;
|
name: string;
|
||||||
installMode?: 'prefetch'|'lazy';
|
installMode?: 'prefetch'|'lazy';
|
||||||
updateMode?: 'prefetch'|'lazy';
|
updateMode?: 'prefetch'|'lazy';
|
||||||
resources: {files?: Glob[]; versionedFiles?: Glob[]; urls?: Glob[];};
|
resources: {
|
||||||
|
files?: Glob[];
|
||||||
|
/** @deprecated As of v6 `versionedFiles` and `files` options have the same behavior. Use
|
||||||
|
`files` instead. */
|
||||||
|
versionedFiles?: Glob[];
|
||||||
|
urls?: Glob[];
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -4,7 +4,7 @@ export interface AssetGroup {
|
||||||
name: string;
|
name: string;
|
||||||
resources: {
|
resources: {
|
||||||
files?: Glob[];
|
files?: Glob[];
|
||||||
versionedFiles?: Glob[];
|
/** @deprecated */ versionedFiles?: Glob[];
|
||||||
urls?: Glob[];
|
urls?: Glob[];
|
||||||
};
|
};
|
||||||
updateMode?: 'prefetch' | 'lazy';
|
updateMode?: 'prefetch' | 'lazy';
|
||||||
|
|
Loading…
Reference in New Issue