angular/packages/compiler-cli
Paul Gschwendtner b6c6dfd278 fix(compiler-cli): do not persist component analysis if template/styles are missing (#49184)
Consider the following scenario:

1. A TS file with a component and templateUrl exists
2. The template file does not exist.
3. First build: ngtsc will properly report the error, via a FatalDiagnosticError
4. The template file is now created
5. Second build: ngtsc still reports the same errror.

ngtsc persists the analysis data of the component and never invalidates
it when the template/style file becomes available later.

This breaks incremental builds and potentially common workflows
where resource files are added later after the TS file is created. This
did surface as an issue in the Angular CLI yet because Webpack requires
users to re-start the process when a new file is added. With ESBuild
this will change and this also breaks incremental builds with
Bazel/Blaze workers.

To fix this, we have a few options:

* Invalidate the analysis when e.g. the template file is missing. Never
  caching it means that it will be re-analyzed on every build iteration.
* Add the resource dependency to ngtsc's incremental file graph. ngtsc
  will then know via `host.getModifiedResources` when the file becomes
  available- and fresh analysis of component would occur.

The first approach is straightforward to implement and was chosen here.
The second approach would allow ngtsc to re-use more of the analysis
when we know that e.g. the template file still not there, but it
increases complexity unnecessarily because there is no **single**
obvious resource path for e.g. a `templateUrl`. The URL is attempted
to be resolved using multiple strategies, such as TS program root dirs,
or there is support for a custom resolution through
`host.resourceNameToFileName`.

It would be possible to determine some candidate paths and add them to
the dependency tracker, but it seems incomplete given possible external
resolvers like `resourceNameToFileName` and also would likely not have
a sufficient-enough impact given that a broken component decorator is
not expected to remain for too long between N incremental build
iterations.

PR Close #49184
2023-02-24 08:24:07 -08:00
..
integrationtest refactor(compiler): drop obsolete NgFactory and NgSummary config options (#48268) 2023-02-21 13:03:59 -08:00
linker refactor: update compiler-cli babel linker to be ESM only (#48521) 2022-12-19 19:50:43 +00:00
private refactor(compiler): rework and expose APIs to be used in schematics (#48730) 2023-01-13 12:24:32 -08:00
src fix(compiler-cli): do not persist component analysis if template/styles are missing (#49184) 2023-02-24 08:24:07 -08:00
test fix(compiler-cli): do not persist component analysis if template/styles are missing (#49184) 2023-02-24 08:24:07 -08:00
BUILD.bazel refactor: remove Angular Compatibility Compiler (ngcc) (#49101) 2023-02-16 16:01:17 -08:00
esbuild.config.js refactor: remove __ESM_IMPORT_META_URL__ workaround now that we can use ESM (#48521) 2022-12-19 19:50:41 +00:00
index.ts refactor(compiler-cli): Export the interface PluginCompilerHost for 1p use. (#48874) 2023-02-02 09:44:18 -08:00
package.json feat(compiler): drop support for TypeScript 4.8 (#49155) 2023-02-23 10:39:43 -08:00
tsconfig-build.json refactor(compiler-cli): dismantle View Engine implementation of ngc (#44269) 2021-12-01 10:36:30 -08:00
tsconfig.json build: update tsconfigs to use ES2020 as target and module (#43431) 2021-10-01 18:28:42 +00:00