Commit Graph

11 Commits

Author SHA1 Message Date
Alex Eagle 50687e11cf build: fix type-check errors introduced during rules_ts 0.21 (#27586)
PR Close #27586
2018-12-10 16:33:41 -08:00
Igor Minar 95f8b63265 test(service-worker): run the remaining service-worker tests under bazel (#27386)
PR Close #27386
2018-12-05 20:55:31 -08:00
George Kalpakas 250527ca68 feat(service-worker): add support for `?` in SW config globbing (#24105)
The globbing is used in the following sections:
- `assetGroups` > `resources` > `files`/`versionedFiles`
- `assetGroups` > `resources` > `urls`
- `dataGroups` > `urls`
- `navigationUrls`

Query params are ignored for `files`/`versionedFiles` and
`navigationUrls`, but they are still taken into account for
`assetGroups`/`dataGroups` `urls`. To avoid a breaking change, `?` is
matched literally for these patterns.

PR Close #24105
2018-07-06 13:50:17 -07:00
George Kalpakas e01b539ee5 refactor: infer type for `it()` assertion functions (#19904)
PR Close #19904
2018-07-06 13:48:02 -07:00
George Kalpakas f1e4a153f0 refactor(service-worker): sort manifest `url`/`hashTable` entries (#23586)
This makes it easier to quickly check whether a specific file ended up
in the manifest, for example when debugging.

PR Close #23586
2018-05-09 11:51:22 -07:00
George Kalpakas 6c2c95851a fix(service-worker): let `*` match 0 characters in globs (#23339)
In [glob patterns][1], the `*` wildcard is supposed to match 0 or more
characters.

For reference:
- This is also how `*` works in other implementations, such as
  `.gitignore` files or Firebase hosting config.
- Some popular JS implementations (e.g. [minimatch][2], [micromatch][3])
  work differently, matching 1 or more character (but not 0).

This commit "fixes" the minimal glob support in
`@angular/service-worker` to allow `*` to also match 0 characters.

[1]: https://en.wikipedia.org/wiki/Glob_%28programming%29
[2]: https://www.npmjs.com/package/minimatch
[3]: https://www.npmjs.com/package/micromatch

PR Close #23339
2018-04-13 13:13:36 -07:00
George Kalpakas 08325aaffc feat(service-worker): add support for configuring navigations URLs (#23339)
The ServiceWorker will redirect navigation requests that don't match any
`asset` or `data` group to the specified index file. The rules for a
request to be classified as a navigation request are as follows:
1. Its `mode` must be `navigation`.
2. It must accept a `text/html` response.
3. Its URL must match certain criteria (see below).

By default, a navigation request can have any URL except for:
1. URLs containing `__`.
2. URLs to files (i.e. containing a file extension in the last path
   segment).

While these rules are fine in many cases, sometimes it is desirable to
configure different rules for the URLs of navigation requests (e.g.
ignore specific URLs and pass them through to the server).

This commit adds support for specifying an optional `navigationUrls`
list in `ngsw-config.json`, which contains URLs or simple globs
(currently only recognizing `!`, `*` and `**`).
Only requests whose URLs match any of the positive URLs/patterns and
none of the negative ones (i.e. URLs/patterns starting with `!`) will be
considered navigation requests (and handled accordingly by the SW).

(This is an alternative implementation to #23025.)

Fixes #20404

PR Close #23339
2018-04-13 13:13:36 -07:00
Misko Hevery 47e251a80a build: remove `main()` from specs (#21053)
PR Close #21053
2017-12-22 13:10:51 -08:00
Alex Rickabaugh 90d1423fb4 fix(service-worker): include versionedFiles in the manifest hashTable (#19837)
There is no difference in runtime (yet) between versioned and unversioned
files. Theoretically, the SW does not have to cache-bust versioned files,
but the SW doesn't cache bust files on the first request anyway, so in the
common case it doesn't matter. If the hash doesn't match, the SW will cache
bust the file to be sure, which is technically unnecessary, but since the
file itself is versioned, the likelihood of this happening is rare.

This fixes a critical bug where versioned files were erroneously not included
in the hashTable in the generated manifest. This could lead to applications
not updating if only versioned files changed in between versions.

PR Close #19837
2017-10-23 15:11:38 -04:00
Alex Rickabaugh f10f8db5fb fix(service-worker): several misc fixes for corner cases
This commit fixes several issues discovered through use in real apps.

* The sha1() function operated on text content, causing issues for binary-format files.
  A sha1Binary() function which operates on unparsed data now avoids any encoding issues.
* The characters '?' and '+' were not escaped in Glob-to-regex conversion previously, but
  are now.
* URLs from the browser contain the full origin, but were checked against the table of
  hashes from the manifest which only has the path for URLs from the same origin. Now the
  origin is checked and URLs are relativized to the domain root before comparison if
  appropriate.
* ngsw: prefix was missing from data groups, is now added.
* Occasionally servers will return a redirected response for an asset, and caching it could
  cause errors for navigation requests. The SW now handles this by detecting such responses
  and following the redirect manually, to avoid caching a redirected response.
* The request for known assets is now created from scratch from the URL before fetching from
  the network, in order to sanitize it and avoid carrying any special modes or headers that
  might result in opaque responses.
* Debugging log for troubleshooting.
* Avoid creating errors by returning 504 responses on error.
* Fix bug where idle queue doesn't run in some circumstances.
* Add tests for the above.
2017-10-05 13:27:31 -07:00
Alex Rickabaugh d442b6855f feat(service-worker): introduce the @angular/service-worker package (#19274)
This service worker is a conceptual derivative of the existing @angular/service-worker maintained at github.com/angular/mobile-toolkit, but has been rewritten to support use across a much wider variety of applications.

Entrypoints include:

@angular/service-worker: a library for use within Angular client apps to communicate with the service worker.
@angular/service-worker/gen: a library for generating ngsw.json files from glob-based SW config files.
@angular/service-worker/ngsw-worker.js: the bundled service worker script itself.
@angular/service-worker/ngsw-cli.js: a CLI tool for generating ngsw.json files from glob-based SW config files.
2017-09-28 16:18:12 -07:00