Skip to content

Commit

Permalink
fix(service-worker): throw when using the unsupported `versionedFiles…
Browse files Browse the repository at this point in the history
…` 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 21, 2019
1 parent 196808e commit 250e6fd
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
6 changes: 6 additions & 0 deletions packages/service-worker/config/src/generator.ts
Expand Up @@ -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('/');

Expand Down
32 changes: 32 additions & 0 deletions packages/service-worker/config/test/generator_spec.ts
Expand Up @@ -7,6 +7,7 @@
*/

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

describe('Generator', () => {
Expand Down Expand Up @@ -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.