Skip to content
Permalink
Browse files

fix(service-worker): throw when using the unsupported `versionedFiles…

…` option in config (#33903)

In 5d5c94d, the deprecated `versionedFiles` option from the SW
asset-group configuration in `ngsw-config.json`. As a result, the
option would be silently ignored and the runtime behavior of the SW
would change (i.e. some files might not be cached and available offline
any more). This change could be easily go unnoticed by the developer.

This commit ensures this does not happen by throwing a build-time error,
when detecting the unsupported `versionedFiles` option with an error
message prompting the user to use the `files` option instead.

Jira issue: [FW-1727](https://angular-team.atlassian.net/browse/FW-1727)

PR Close #33903
  • Loading branch information
gkalpak authored and alxhub committed Nov 18, 2019
1 parent 196808e commit 250e6fdd39b19458964a37d0bcaa50eca90c335e
@@ -45,6 +45,12 @@ export class Generator {
Promise<Object[]> {
const seenMap = new Set<string>();
return Promise.all((config.assetGroups || []).map(async(group) => {
if ((group.resources as any).versionedFiles) {
throw new Error(
`Asset-group '${group.name}' in 'ngsw-config.json' uses the 'versionedFiles' option, ` +
'which is no longer supported. Use \'files\' instead.');
}

const fileMatcher = globListToMatcher(group.resources.files || []);
const allFiles = await this.fs.list('/');

@@ -7,6 +7,7 @@
*/

import {Generator} from '../src/generator';
import {AssetGroup} from '../src/in';
import {MockFilesystem} from '../testing/mock';

describe('Generator', () => {
@@ -149,4 +150,35 @@ describe('Generator', () => {
hashTable: {},
});
});

it('throws if the obsolete `versionedFiles` is used', async() => {
const fs = new MockFilesystem({
'/index.html': 'This is a test',
'/main.js': 'This is a JS file',
});
const gen = new Generator(fs, '/test');

try {
await gen.process({
index: '/index.html',
assetGroups: [{
name: 'test',
resources: {
files: [
'/*.html',
],
versionedFiles: [
'/*.js',
],
} as AssetGroup['resources'] &
{versionedFiles: string[]},
}],
});
throw new Error('Processing should have failed due to \'versionedFiles\'.');
} catch (err) {
expect(err).toEqual(new Error(
'Asset-group \'test\' in \'ngsw-config.json\' uses the \'versionedFiles\' option, ' +
'which is no longer supported. Use \'files\' instead.'));
}
});
});

0 comments on commit 250e6fd

Please sign in to comment.
You can’t perform that action at this time.