Commit Graph

21339 Commits

Author SHA1 Message Date
George Kalpakas c88e18a051 ci: exclude `service-worker/` sub-directories from `fw-testing` PullApprove group (#42631)
The `fw-testing` PullApprove group, which by default owns all `testing/`
sub-directories, is supposed to own resources related to testing Angular
applications (from an end-user's perspective). The `service-worker`
package source code includes some `testing/` sub-directories which are
intended for internal use only (i.e. to test the `service-worker`
package itself) and are not distributed to end-users of the package.

Previously, changes in these `testing/` sub-directories would
incorrectly require approval from the `fw-testing` group.

This commit fixes this by excluding the `service-worker` package
sub-directories from the files owned by the `fw-testing` group.

PR Close #42631
2021-06-24 12:26:51 -07:00
Renovate Bot 4e46aef17b build: update dependency madge to v5 (#42629)
PR Close #42629
2021-06-24 10:10:32 -07:00
George Kalpakas cc30dc0713 fix(service-worker): ensure obsolete caches are always cleaned up (#42622)
Previously, the SW was only able to clean up caches for app-versions
found in the `Driver`'s `versions` map. If (for some reason) the
`Driver` failed to load a valid stored state (including app-versions)
and ended up with an [empty `versions` map][1], any obsolete versions
would remain in the cache storage. This case was rare but possible.

This commit makes the cache clean-up logic more robust by ensuring that
all app-version caches are removed unless they are currently used by the
SW to serve active clients (with the exception of the latest
app-version, which is always retained).

Fixes #41728

[1]: 9de65dbdce/packages/service-worker/worker/src/driver.ts (L515-L529)

PR Close #42622
2021-06-24 09:55:32 -07:00
George Kalpakas 01128f5b5d fix(service-worker): ensure caches are cleaned up when failing to load state (#42622)
Previously, obsolete caches were only cleaned up when successfully
loading the stored state. When the state failed to be loaded, cleaning
up the caches would be skipped until the next SW initialization.

This commit changes this, ensuring that the caches are cleaned up
regardless if the stored state was loaded successfully or not.

PR Close #42622
2021-06-24 09:55:32 -07:00
George Kalpakas 356dd2107b refactor(service-worker): simplify accessing `CacheStorage` throughout the ServiceWorker (#42622)
This commit simplifies/systemizes accessing the `CacheStorage` through a
wrapper, with the following benefits:
- Ensuring a consistent cache name prefix is used for all caches
  (without having to repeat the prefix in different places).
- Allowing referring to caches using their name without the common
  cache name prefix.
- Exposing the cache name on cache instances, which for example makes it
  easier to delete caches without having to keep track of the name used
  to create them.

PR Close #42622
2021-06-24 09:55:32 -07:00
George Kalpakas 73b0275dc2 fix(service-worker): improve ServiceWorker cache names (#42622)
This commit improves the cache names generated by the ServiceWorker by
making them shorter and non-repetitive. In particular, the following
changes are made:

- Data-group cache names no longer include the `dynamic` infix, since it
  does not add any value.
  Before: `ngsw:<...>:data:dynamic:<...>`
  After:  `ngsw:<...>:data:<...>`

- `CacheDatabase` table names no longer include the `ngsw:<path>` prefix
  twice.
  Before: `ngsw:<path>:db:ngsw:<path>:<...>`
  After:  `ngsw:<path>:db:<...>`

NOTE 1:
This change will result in different cache names being generated for the
same app-versions with the new SericeWorker script. This means that some
of the previously cached data will need to be re-downloaded (because the
ServiceWorker will not be able to re-use the old caches), but that
should be transparent for the end user.
While possible, adding logic to allow the ServiceWorker to retrieve data
from the old caches is not worth the extra complecity and maintenance
cost.

NOTE 2:
Generating different cache names for some of the caches means that the
ServiceWorker will not be able to clean-up some of the old caches. This
will be taken care of in a subsequent commit that will rework the
clean-up logic to be more robust (covering changes such as this one and
other edgecases).

PR Close #42622
2021-06-24 09:55:32 -07:00
George Kalpakas 7507ed2e54 fix(service-worker): use correct names when listing `CacheDatabase` tables (#42622)
`CacheDatabase` uses the un-prefixed table names to interact with
database tables. However, the `list()` method returns the raw, prefixed
table names (which are not useful, since they cannot be used to
open/delete a table).

This commit fixes this by removing the prefix from the cache names
returned by the `list()` method.

NOTE:
This method is currently not used anywhere, so this change does not
affect the ServiceWorker behavior.

PR Close #42622
2021-06-24 09:55:32 -07:00
George Kalpakas 53fe557da7 feat(service-worker): include ServiceWorker version in debug info (#42622)
This commit includes the ServiceWorker version in the debug info shown
at `/ngsw/state` to make it easier to know what version of the
ServiceWorker script is controlling the page.

PR Close #42622
2021-06-24 09:55:32 -07:00
George Kalpakas 4962ef5330 refactor(service-worker): minor refactorings to improve readability/maintainability (#42622)
This commit makes some minor refactorings to improve the code
readability and maintainability, including:
- Avoiding code duplication.
- Using more descriptive variable names.
- Using `async/await` instead of `Promise#then()`.
- Accessing variables directly instead of via `this` when possible.

PR Close #42622
2021-06-24 09:55:32 -07:00
Pete Bacon Darwin 874de59d35 fix(compiler-cli): change default ngcc hash algorithm to be FIPS compliant (#42582)
The previous default algorithm was `md5`, which is not compliant with FIPS.
The default is now set to `sha256`, which is compliant.

Fixes #42577

PR Close #42582
2021-06-24 08:42:38 -07:00
Pete Bacon Darwin b8ef83b10f refactor(compiler-cli): ngcc entry-point manifest hash is now configurable (#42582)
The hash algorithm for the entry-point manifest was hardcoded to `md5`.
This can now be configured by the `hashAlgorithm` property on the
ngcc.config.js project configuration.

PR Close #42582
2021-06-24 08:42:38 -07:00
Pete Bacon Darwin a3b6d65580 refactor(compiler-cli): make ngcc configuration hash algorithm configurable! (#42582)
The ngcc configuration gets hashed to be used when caching
but it was hardcoded to use the `md5` algorithm, which is
not FIPS compliant.

Now the hash algorithm can be configured in the ngcc.config.js
file at the project level.

PR Close #42582
2021-06-24 08:42:38 -07:00
Paul Gschwendtner 8da6f66f7b ci: replace RBE instance name for components-repo-unit-tests job (#42636)
Temporarily replaces the RBE instance name for the
`components-repo-unit-tests` job until
https://github.com/angular/components/pull/23056 is available.

PR Close #42636
2021-06-24 08:28:57 -07:00
Joey Perrott 2340cbcab8 build: update to new remote instance name for RBE (#42636)
Update to use remote instance name, primary_instance, for RBE

PR Close #42636
2021-06-24 08:28:57 -07:00
Renovate Bot 356723158a build: lock file maintenance (#42568)
PR Close #42568
2021-06-23 17:36:41 +00:00
codingnuclei d546501ab5 feat(service-worker): add `openWindow`, `focusLastFocusedOrOpen` and `navigateLastFocusedOrOpen` (#42520)
Add `openWindow`, `focusLastFocusedOrOpen` and `navigateLastFocusedOrOpen` abilty to the notificationclick handler such that when either a notification or notification action is clicked the service-worker can act accordinly without the need for the app to be open

PR Close #26907

PR Close #42520
2021-06-23 16:31:09 +00:00
Pete Bacon Darwin 9de65dbdce fix(compiler): should not break a text token on a non-valid start tag (#42605)
Previously the lexer would break out of consuming a text token if it contains
a `<` character. Then if the next characters did not indicate an HTML syntax
item, such as a tag or comment, then it would start a new text token. These
consecutive text tokens are then merged into each other in a post tokenization
step.

In the commit before this, interpolation no longer leaks across text tokens.
The approach given above to handling `<` characters that appear in text is
no longer adequate. This change ensures that the lexer only breaks out of
a text token if the next characters indicate a valid HTML tag, comment,
CDATA etc.

PR Close #42605
2021-06-22 16:37:00 +00:00
Pete Bacon Darwin c873440ad2 fix(compiler): do not allow unterminated interpolation to leak into later tokens (#42605)
When consuming a text token, the lexer tracks whether it is reading characters
from inside an interpolation so that it can identify invalid ICU expressions.
Inside an interpolation there will be no ICU expression so it is safe to
have unmatched `{` characters, but outside an interpolation this is an error.

Previously, if an interpolation was started, by an opening marker (e.g. `{{`)
in a text token but the text came to an end before the closing marker (e.g. `}}`)
then the lexer was not clearing its internal state that tracked that it was
inside an interpolation. When the next text token was being consumed,
the lexer, incorrectly thought it was already within an interpolation.
This resulted in invalid ICU expression errors not being reported.

For example, in the following snippet, the first text block has a prematurely
ended interpolation, and the second text block contains an invalid `{` character.

```
<div>{{</div>
<div>{</div>
```

Previously, the lexer would not have identified this as an error. Now there
will be an EOF error that looks like:

```
TS-995002: Unexpected character "EOF"
(Do you have an unescaped "{" in your template? Use "{{ '{' }}") to escape it.)
```

PR Close #42605
2021-06-22 16:37:00 +00:00
Umair Hafeez 8a67770687 docs(core): improve applicationref.bootstrap docs (#42407)
add proper examples and update usage notes
add references to the method at relevant places in the docs

PR Close #42407
2021-06-22 16:30:37 +00:00
George Kalpakas 9498da1038 fix(service-worker): correctly determine client ID on navigation requests (#42607)
The ServiceWorker assigns an app-version to a each client to ensure that
all subsequent requests for a client are served using the same
app-version. The assignment is done based on the client ID.

Previously, the ServiceWorker would only try to read the client's ID off
of the `FetchEvent`'s `clientId` property. However, for navigation
requests the new client's ID will be set on [resultingClientId][1],
while `clientId` will either be empty or hold the ID of the client where
the request initiated from. See also related discussions in
w3c/ServiceWorker#870 and w3c/ServiceWorker#1266.

In theory, this could lead to the navigation request (i.e. `index.html`)
being served from a different app-version than the subsequent
sub-resource requests (i.e. assets). In practice, the likelihood of this
happening is probably very low though, since it would require the latest
app-version to be updated between the initial navigation request and the
first sub-resource request, which should happen very shortly after the
navigation request.

This commit ensures that the correct client ID is determined even for
navigation requests by also taking the `resultingClientId` property into
account.

[1]: https://developer.mozilla.org/en-US/docs/Web/API/FetchEvent/resultingClientId

PR Close #42607
2021-06-22 16:28:24 +00:00
Joey Perrott 81a19e4e65 feat(dev-infra): update pullapprove verification to ensure all groups have reviewers (#42614)
Update the pullapprove verification tooling to ensure a reviewer is defined for
each group. This is being done in preparation for the upcoming change to how
pullapprove billing works. The new billing will work on a seats based approach
rather than flat usage.

PR Close #42614
2021-06-22 16:27:36 +00:00
mgechev 75bbcf7c2f docs: improve styles of the roadmap done section (#42616)
The "Done" section was previously broken in dark mode. This PR:
- Fixes the dark mode styles
- Expands the done section by default

PR Close #42616
2021-06-22 16:26:47 +00:00
Kristiyan Kostadinov cc672f05bf feat(compiler): add support for shorthand property declarations in templates (#42421)
Adds support for shorthand property declarations inside Angular templates. E.g. doing `{foo, bar}` instead of `{foo: foo, bar: bar}`.

Fixes #10277.

PR Close #42421
2021-06-21 23:40:47 +00:00
Kristiyan Kostadinov 699a8b43cb test(compiler-cli): add additional safe keyed read tests (#42421)
This commit adds some tests that were mistakenly omitted from the original
change for safe keyed reads/writes.

PR Close #42421
2021-06-21 23:40:47 +00:00
Németh Tamás 6b2a475532 docs: add new i18n formats to i18n guide (#42597)
PR Close #42597
2021-06-21 18:48:19 +00:00
JoostK a9dd7e21a2 refactor(compiler-cli): enable relative imports in the type parameter emitter (#42492)
Previously, the template type checker would only opt-in to inline type
constructors if it could import all type references from absolute module
specifiers. This limitation was put into place in an abundance of
caution as there was a safe, but less performant, fallback available.

The language service is not capable of using this fallback, which now
means that the limitation of absolute module specifiers limits the
language service's ability to use accurate types for component/directive
classes that have generic type parameters.

This commit loosens the restriction such that type references are now
eligible for emit as long as they are exported.

PR Close #42492
2021-06-21 18:34:05 +00:00
JoostK 729eea5716 fix(compiler-cli): transform type references in generic type parameter default (#42492)
When a component/directive has a generic type parameter, the template
type checker attempts to translate the type parameter such that the
type parameters can be replicated in the type constructor that is
emitted into the typecheck file.

Type parameters with a default clause would incorrectly be emitted into
the typecheck file using the original `ts.TypeNode` for the default
clause, such that `ts.TypeReferenceNode`s within the default clause
would likely be invalid (i.e. referencing a type for which no import is
present in the typecheck file). This did not result in user-facing
type-check errors as errors reported in type constructors are not
translated into template positions Regardless, this commit ensures that
`ts.TypeReferenceNode`s within defaults are properly translated into the
typecheck file.

PR Close #42492
2021-06-21 18:34:05 +00:00
JoostK 16aaa23d4e refactor(compiler-cli): use TypeScript transform to emit type parameters (#42492)
The template type checker is capable of recreating generic type bounds
in a different context, rewriting type references along the way (if
possible). This was previously done using a visitor that only supported
a limited set of types, resulting in the inability to emit all sorts of
types (even if they don't contain type references at all).

The inability to emit generic type bounds was not critical when the type
parameter emitting logic was introduced, as the compiler also has a
fallback strategy of creating inline type constructors. However, this
fallback is not available to the language service, resulting in
inaccurate types when components/directives use a complex generic type.

To mitigate this problem, the specialized visitor has been replaced with
a generalized TypeScript transform, where only type references get
special treatment. This allows for more complex types to be emitted,
such as union and intersection types, object literal types and tuple
types.

PR Close #42492
2021-06-21 18:34:05 +00:00
Kristiyan Kostadinov f52df99fe3 fix(compiler): generate view restoration for keyed write inside template listener (#42603)
If an implcit receiver is accessed in a listener inside of an `ng-template`, we generate some extra code in order to ensure that we're assigning to the correct object. The problem is that the logic wasn't covering keyed writes which caused it to write to the wrong object and throw an assertion error at runtime.

These changes expand the logic to cover keyed writes.

Fixes #41267.

PR Close #42603
2021-06-21 18:30:37 +00:00
Joey Perrott 8793d1a046 ci: update pullapprove config (#42613)
Update the fallback group in pullapprove to define a reviewer for the group,
in preparation for the upcoming change to how pullapprove billing works. The
new billing will work on a seats based approach rather than flat usage.

PR Close #42613
2021-06-21 17:36:56 +00:00
Alex Rickabaugh e83d7cb2d3 refactor(compiler-cli): support xi18n in ngtsc (#42485)
xi18n is the operation of extracting i18n messages from templates in the
compilation. Previously, only View Engine was able to perform xi18n. This
commit implements xi18n in the Ivy compiler, and a copy of the View Engine
test for Ivy verifies that the results are identical.

PR Close #42485
2021-06-21 16:50:28 +00:00
Alex Rickabaugh 4538bd6c96 refactor(compiler-cli): extract xi18n utility functions to a separate file (#42485)
This commit moves some xi18n-related functions in the View Engine
ng.Program into a new file. This is necessary in order to depend on them
from the Ivy ng.Program while avoiding a cycle.

PR Close #42485
2021-06-21 16:50:28 +00:00
Paul Gschwendtner d77f560403 build: update to typescript 4.3.4 (#42600)
Updates to TypeScript 4.3.4 which contains a fix for a printer
regression that caused unexpected JavaScript output with our
compiler transforms.

See: https://github.com/microsoft/TypeScript/pull/44070.
Updates to TypeScript 4.3.4 which contains a fix for a printer

PR Close #42600
2021-06-21 16:42:49 +00:00
Paul Gschwendtner b8eb24e0fb Revert "test: update compiler-cli compliance goldens due to TS 4.3 emit format regression (#42022)" (#42600)
This reverts commit 71e14a71f5.

PR Close #42600
2021-06-21 16:42:48 +00:00
George Kalpakas 44291889ee docs(docs-infra): document how to configure redirects (#42452)
PR Close #42452
2021-06-18 17:32:58 +00:00
George Kalpakas d07e736f17 build(docs-infra): auto-generate SW `navigationUrls` from Firebase config (#42452)
Previously, redirects had to be configured in both the Firebase config
(`firebase.json`) and the ServiceWorker config (`ngsw-config.json`).
This made it challenging to correctly configure redirects, since one had
to understand the different formats of the two configs, and was also
prone to getting out-of-sync configs.

This commit simplifies the process of adding redirects by removing the
need to update the ServiceWorker config (`ngsw-config.json`) and keep it
in sync with the Firebase config (`firebase.json`). Instead the
ServiceWorker `navigationUrls` are automatically generated from the list
of redirects in the Firebase config.

NOTE:
Currently, the automatic generation only supports the limited set of
patterns that are necessary to translate the existing redirects. It can
be made more sophisticated in the future, should the need arise.

PR Close #42452
2021-06-18 17:32:58 +00:00
George Kalpakas 982521f284 build(docs-infra): align `navigationUrls` in `ngsw-config.json` with Firebase redirects (#42452)
The ServiceWorker `navigationUrls` globs defined in `ngsw-config.json`
are supposed to exclude any URLs that are redirected on the server (as
configured in `firebase.json`). However, the list of redirected
URLs/globs in `firebase.json` and `ngsw-config.json` have gotten out of
sync.

This commit updates the globs in `ngsw-config.json` to match the ones in
`firebase.json`.

This is in preparation of automatically generating the ServiceWorker
`navigationUrls` based on `firebase.json`.

PR Close #42452
2021-06-18 17:32:58 +00:00
George Kalpakas fe3c79fe40 build(docs-infra): alphabetically sort all `navigationUrls` in `ngsw-config.json` (#42452)
This commit sorts all `navigationUrls` in `ngsw-config.json`
alphabetically.

This is in preparation of automatically generating the ServiceWorker
`navigationUrls` based on `firebase.json`.

PR Close #42452
2021-06-18 17:32:58 +00:00
George Kalpakas 932f246454 build(docs-infra): allow a trailing `/` in more `navigationUrls` globs in `ngsw-config.json` (#42452)
Previously, we were not consistent in allowing a trailing `/` in
`navigationUrls` globs in `ngsw-config.json`. And when we did, we used
two globs: one with and one without the trailing `/`.

This commit updates all appropriate `navigationUrls` globs to allow a
trailing `/`. It also merges the two glob patterns (the one with and the
one without the `/`) into one.

This is in preparation of automatically generating the ServiceWorker
`navigationUrls` based on `firebase.json`.

PR Close #42452
2021-06-18 17:32:58 +00:00
George Kalpakas 4635d4f957 build(docs-infra): remove redundant `navigationUrls` globs from `ngsw-config.json` (#42452)
This commit removes some `navigationUrls` globs from `ngsw-config.json`
that have no effect. More specifically:
- It removes globs of the form `!/**/xyz.html`, since these are already
  covered by the more generic `!/**/*.*` glob.
- It removes `!/api/**/NgFor`, since it does not have a corresponding
  redirect rule in `firebase.json`.

This is in preparation of automatically generating the ServiceWorker
`navigationUrls` based on `firebase.json`.

PR Close #42452
2021-06-18 17:32:58 +00:00
George Kalpakas 36fb5744db build(docs-infra): add missing redirect rule for `api/http` in `firebase.json` (#42452)
Previously, only sub-paths, such as `api/http/foo`, were redirected to
`guide/deprecations#http`.

This commit ensures that also `api/http` itself (which used to point to
the `http` module's API page) is redirected as well.

PR Close #42452
2021-06-18 17:32:58 +00:00
George Kalpakas c397b59855 test(docs-infra): ensure all redirect rules are tested (#42452)
This commit adds a test assertion to verify that all redirect rules
defined in `firebase.json` are tested, i.e. that each rule is applied to
at least one testcase from `URLS_TO_REDIRECT.txt`.

This will ensure that any redirect rules added in the future will be
tested.

PR Close #42452
2021-06-18 17:32:57 +00:00
George Kalpakas c66423ab2a test(docs-infra): unnest unnecessarily nested test suite (#42452)
Previously, the `destinations` test suite in
`testFirebaseRedirection.spec.ts` was nested under the
`with legacy URLs` test suite. However, the two suites are unrelated and
there is no reason to have them nested.

This commit moves the `destinations` test suite to be beside (instead of
inside) the `with legacy URLs` one.

PR Close #42452
2021-06-18 17:32:57 +00:00
George Kalpakas e0338189b3 test(docs-infra): add testcases for all redirect rules (#42452)
This commit adds testcases in `URLS_TO_REDIRECT.txt` for all redirect
rules defined in `firebase.json`. This ensures that all rules are tested
and work as expected.

PR Close #42452
2021-06-18 17:32:57 +00:00
George Kalpakas 0c105c38da fix(docs-infra): make `NotificationComponent` elements non-focusable when hidden (#42584)
Previously, the `NotificationComponent` would be hidden by reducing its
height to `0`. This allowed for a smoother hide animation when closing
the notification, but left the component's interactive elements
focusable via keyboard navigation. This was confusing for users, because
the focused elements would not be visible on the page.

This commit fixes the issue be also setting the `display` CSS property
to `none` when the `NotificationComponent` is hidden, thus ensuring that
its contents are not focusable via keyboard navigation.
(This does not affect the hide animation, since the `display` style is
not animatable and is only applied at the end of the animation.)

PR Close #42584
2021-06-18 17:32:26 +00:00
George Kalpakas 29302e3baa fix(docs-infra): remove redundant `MatIcon` element (#42584)
Previously, we included a dummy `MatIcon` element in `AppComponent` in
order to ensure that the `Material Icons` font would be requested (and
thus cached by the ServiceWorker) on every navigation. However, #41129
introduced the `ThemeToggleComponent`, which will be present on all
pages (since it is located in the top-menu) and relies on the
`Material Icons` font. Therefore, the work-around for loading the
`Material Icons` font is no longer necessary.

This commit removes the now redundant `MatIcon` from `AppComponent`.

PR Close #42584
2021-06-18 17:32:26 +00:00
George Kalpakas fd8f9ab4e8 fix(docs-infra): convert external links to `MatIconButton`s (#42584)
This commit changes the anchor elements used for external links to
`MatIconButton`s. While the appearance remains the same (with the
exception of hover/focus styles), this better aligns the styling of
external link icons with other nearby icon buttons (i.e. the theme
toggle) and alows as to simplify the CSS for external links (since much
of their styling is handled by Angular Material).

PR Close #42584
2021-06-18 17:32:26 +00:00
George Kalpakas 0f6ebe1ab5 refactor(docs-infra): remove redundant CSS rule (#42584)
Since we now use SVG for external link icons, there are no `<img>`
elements inside the anchor elements. So, the CSS rule does not match any
element and can be removed.

PR Close #42584
2021-06-18 17:32:26 +00:00
George Kalpakas 12644486f4 ci: start tracking CSS payload sizes for angular.io (#42584)
Previously, we only tracked the sizes of the eagerly loaded JS bundles.
However, the CSS styles (which also have a non-negligible size) must
also be downloaded and parsed by the browser, thus affecting the initial
rendering time.

This commit starts tracking the CSS styles payload sizes.
(Originally discussed in
https://github.com/angular/angular/pull/42584#discussion_r653787961)

PR Close #42584
2021-06-18 17:32:26 +00:00
Pete Bacon Darwin 983c540191 docs: fix pipe params (#42593)
The addition of overloads to some of the number pipes caused
the documentation to lose the parameter descriptions.

This change fixes that by moving the JSDOC block in from of the
primary method signature, rather than the first overload.

Fixes #42590

PR Close #42593
2021-06-17 23:03:08 +00:00