46 Commits

Author SHA1 Message Date
Charles Lyding
720feee34f fix(@ngtools/webpack): avoid non-actionable template type-checker syntax diagnostics
The AOT compiler's internal template type-checking files are not intended to be directly analyzed for diagnostics by the emitting program and are instead analyzed during the template type-checking phase. Previously, only semantic diagnostics were ignored. Now both syntactic and semantic diagnostics are ignored. This change prevents non-actionable diagnostics from being shown during a build.

Addresses: https://github.com/angular/angular/issues/42667
2021-07-09 17:02:10 +01:00
Charles Lyding
492c879cd4 refactor(@ngtools/webpack): consolidate diagnostic helper functions
All the webpack related diagnostic helplers are now located in one file which simplifies maintenance and reduces the number of required imports.
2021-07-07 09:24:25 -04:00
Alan Agius
cef94e10b5 docs(@ngtools/webpack): update options in readme 2021-06-21 11:01:33 +01:00
Alan Agius
277b356e2f refactor(@ngtools/webpack): improve symbols description 2021-06-16 10:55:21 -04:00
Charles Lyding
ca6e9fec94 refactor(@ngtools/webpack): use Webpack loader context hook to access file emitters
The Angular Webpack loader will now access the Angular Webpack Plugin's file emitters via the loader context directly. This is instead of using the not fully public Webpack compilation property on the loader context. This change also removes the need to directly alter the Webpack compilation object which previously added an additional property.
2021-06-10 08:11:05 +02:00
Charles Lyding
f2f15c0893 fix(@ngtools/webpack): disable caching for ngcc synchronous Webpack resolver
The ngcc resolver must be synchronous to integrate with TypeScript which is only synchronous. If the Webpack resolver cache option is enabled when creating a resolver, the resolver will become asynchronous after a rebuild due to the internal implementation of the resolver caching. To prevent this change in behavior, caching is disabled for the ngcc resolver. The ngcc resolver is only used the first time each dependency is used by the application.
2021-06-10 07:59:57 +02:00
Charles Lyding
0c2a862db0 fix(@ngtools/webpack): ensure plugin provided Webpack instance is used
Webpack 5 provides the Webpack instance as a property on the Webpack compiler which allows Webpack plugins to leverage the same Webpack instance that was used to initiate the build. The `AngularWebpackPlugin` now will only use the provided instance to ensure that differing Webpack instances and/or versions are not used.
2021-06-09 08:00:49 +02:00
Charles Lyding
bf11f2bc2b refactor(@ngtools/webpack): create ngcc resolver from Webpack Compiler
By using the Webpack compiler to request a resolver, configuration supplied options will automatically be used (such as symlinks) and also ensures that the same version of the resolver code will be used. Additionally, this removes one of the reasons to directly depend on the `enhanced-resolve` package.
2021-06-09 07:59:52 +02:00
Alan Agius
3a287beab3 refactor: remove left over webpack version 4 code 2021-06-03 15:12:23 +02:00
Alan Agius
3afa5567cb fix(@ngtools/webpack): normalize paths when adding file dependencies
This caused Webpack to mark all TypeScript files as removed after the first compilation on Windows because the file separators didn't match

Closes #20891
2021-05-31 12:50:22 +01:00
Charles Lyding
7a6a4ecb59 refactor(@ngtools/webpack): use Webpack inline resource matching for inline resources
Webpack provides a method to construct a special request string that will remap a loader chain to appear to be from a specific resource path. This requires a custom loader, however, it allows rule matching to leverage the existing file extension based approach and allows providing a path to other loaders which simplifies relative request handling.
2021-05-26 10:51:33 -04:00
Charles Lyding
4f2df00511 perf(@ngtools/webpack): reduce non-watch mode TypeScript diagnostic analysis overhead
When not in a watch mode, the analyis performed by TypeScript to improve incremental type checking can be avoided by creating an abstract builder program that only wraps the underlying TypeScript program.
Performance enhancements in the upcoming TypeScript 4.3 may remove the need for this.  However, TypeScript 4.3 is not yet released and is not yet supported. In addition, TypeScript 4.2 will continue to be supported throughout the v12 major even when TypeScript 4.3 is also supported.
2021-05-19 20:51:23 +02:00
Charles Lyding
6fc84ff1b9 perf(@ngtools/webpack): reduce source file and Webpack module iteration
During a build, the number of iterations over both the TypeScript program's source files and Webpack's modules has been reduced. Both of these collections can contain a significant number of elements especially in larger applications.
2021-05-03 16:00:26 -04:00
Charles Lyding
f62b0423b3 perf(@ngtools/webpack): rebuild Angular required files asynchronously
This change adjusts the Angular required files rebuilding logic to not block on each individual file's Webpack module rebuild. Now all required Webpack modules are discovered then rebuilt asynchrounously and only blocked on the full list of rebuilds. The promise-based Webpack rebuild function is also now only created if a rebuild is required.
2021-05-03 16:00:26 -04:00
Charles Lyding
c1512e4274 build: update files to be eslint compliant
All TypeScript files have been updated to pass the new eslint-based linting checks. eslint compatible disabling comments have also been added in place of the previous tslint comments.
2021-05-03 07:31:02 -04:00
Joey Perrott
003854257c build: migrate all file header to use Google LLC rather than Google Inc 2021-04-27 08:35:22 +02:00
Charles Lyding
86754e4750 refactor(@ngtools/webpack): use Webpack 5 modified/removed file sets for changed list
Webpack 5 directly provides the set of modified and removed files. This feature allows for the removal of the file timestamp logic within the plugin that was previously used to generated the set of changed files on a rebuild.
2021-04-21 12:41:35 -07:00
Charles Lyding
e8f22ab36d refactor(@ngtools/webpack): remove Webpack 4 specific type casting
Webpack 5 contains improved types and exports that reduce the need to perform additional type casting throughout the Angular Webpack Plugin.
2021-04-21 12:40:19 -07:00
Charles Lyding
8dfc8e73f3 perf(@ngtools/webpack): cache results of processed inline resources
When in watch mode, both the file and inline resources will now be cached between rebuilds. This removes the need to reprocess inline resources that have not changed even if the containing TypeScript file has changed.
2021-04-21 12:34:37 -07:00
Charles Lyding
d92805e361 refactor(@ngtools/webpack): reduce stored resource data between rebuilds
This change makes several changes to attempt to reduce retained memory within the resource loader. The first is the preemptive clearing of the resource loader's parent compilation after all modules are built. The second removes the cached sourcemaps for each resource which are not yet used by the system. And finally, the child compilations are no longer stored on the parent compilation and instead the dependencies, errors, and warnings are propagated to the parent compilation.
2021-04-21 12:34:37 -07:00
Alan Agius
0396d0839e build: update angular packages
With this change we also remove the workaround to fix stale reuse program. Which was fixed in https://github.com/angular/angular/pull/41289
2021-04-19 20:27:28 +02:00
Alan Agius
1532e32cc2 refactor: clean up webpack 4 code 2021-04-13 10:49:17 -04:00
Charles Lyding
8c7d56e03a feat(@ngtools/webpack): support processing inline component styles in AOT
This change updates the Angular Webpack Plugin's resource loader to support processing styles that do not exist on disk when the `inlineStyleMimeType` option is used.
2021-04-12 14:08:43 -04:00
Charles Lyding
5e5b2d9b1a feat(@ngtools/webpack): support generating data URIs for inline component styles in JIT
This change adds the new `inlineStyleMimeType` option. When set to a valid MIME type, enables conversion of an Angular Component's inline styles into data URIs.  This allows a Webpack 5 configuration rule to use the `mimetype` condition to process the inline styles. A valid MIME type is a string starting with `text/` (Example for CSS: `text/css`).
2021-04-12 14:08:43 -04:00
Alan Agius
dee6b79489 refactor: remove @types/webpack 2021-04-12 10:02:07 -04:00
Charles Lyding
46e9d0e8a6 feat(@ngtools/webpack): support multiple plugin instances per compilation
This change allows multiple instances of the `AngularWebpackPlugin` to be present in a Webpack configuration.
Each plugin instance should reference a different TypeScript configuration file (`tsconfig.json`) and the TypeScript configuration files should be setup to not include source files present in the other TypeScript configuration files. If files are included in more than one TypeScript configuration, the first plugin present in the Webpack configuration that can emit the file will be used.

Closes: #5072
2021-04-08 09:42:47 -04:00
Charles Lyding
160102ae57 fix(@ngtools/webpack): remove Webpack plugin for deprecated ViewEngine compiler
BREAKING CHANGE: Removal of View Engine support from application builds
With the removal of the deprecated View Engine compiler in Angular version 12 for applications, the View Engine Webpack plugin has been removed.
The Ivy-based Webpack plugin is the default used within the Angular CLI.
If using a custom standalone Webpack configuration, the removed `AngularCompilerPlugin` should be replaced with the Ivy-based `AngularWebpackPlugin`.
2021-04-05 19:20:56 +02:00
Charles Lyding
aeebd14f04 perf(@ngtools/webpack): only check affected files for Angular semantic diagnostics
This change improves the performance of incremental type checking of Angular templates by reducing the number of calls to retrieve the diagnostics.
Only the set of affected files will be queried on a rebuild. The affected set includes files TypeScript deems affected, files that
are required to be emitted by the Angular compiler, and the original file for any TTC shim file that TypeScript deems affected.
2021-03-29 08:16:36 -06:00
Alan Agius
6cc8c26083 refactor(@ngtools/webpack): remove suppressZoneJsIncompatibilityWarning option
BREAKING CHANGE

`suppressZoneJsIncompatibilityWarning` option has been removed. If you are using this plugin directly and `async/await` in ES2017 make sure you downlevel the async syntax using Babel.

See: https://github.com/angular/zone.js/pull/1140 for more information.
2021-03-15 20:31:25 +01:00
Charles Lyding
dfefd6ba4f perf(@ngtools/webpack): use precalculated dependencies in unused file check
This change uses the newly introduced precalculated file dependencies for each TypeScript file instead of querying TypeScript for the SourceFile's dependencies when performing the unused file check at the end of the build cycle. This change removes the need to recalculate the dependencies for each TypeScript file present in the Webpack compilation.
2021-03-12 17:04:22 +01:00
Charles Lyding
95aa2b8f92 perf(@ngtools/webpack): avoid adding transitive dependencies to Webpack's dependency graph
This change augments a TypeScript Compiler Host's resolveModuleNames function to collect dependencies of the containing file based on the module names passed to the resolveModuleNames function. This process assumes that consumers of the Compiler Host will call resolveModuleNames with modules that are actually present in a containing file.  The TypeScript compiler exhibits such behavior making this process effective at generating a set of all direct dependencies for a given source file.
This process is a workaround for gathering a TypeScript SourceFile's dependencies as there is no currently exposed public method to do so. A BuilderProgram does have a `getAllDependencies` function. However, that function returns all transitive dependencies as well which can cause excessive Webpack rebuilds especially in larger programs.
2021-03-11 08:55:08 +01:00
Alan Agius
0dc73276ca feat(@ngtools/webpack): drop support for string based lazy loading
BREAKING CHANGE:

With this change we drop support for string based lazy loading `./lazy.module#LazyModule`  use dynamic imports instead.

The following options which were used to support the above syntax were removed without replacement.
- discoverLazyRoutes
- additionalLazyModules
- additionalLazyModuleResources
- contextElementDependencyConstructor
2021-03-10 12:44:04 -06:00
Charles Lyding
2e3b9541e7 refactor(@ngtools/webpack): initialize paths plugin in resolve options hook
This change reduces the number of different Webpack resolver factory hooks required to initialize the compiler plugins.
Webpack 5 also requires the path plugin to be configured earlier in the process and the options hook provides that ability.
2021-02-23 08:40:53 +01:00
Charles Lyding
c6e65e4346 fix(@ngtools/webpack): normalize paths when pruning AOT rebuild requests 2021-02-17 12:42:40 -06:00
Charles Lyding
789e05d800 feat(@ngtools/webpack): support Webpack 5
The `@ngtools/webpack` package now officially supports Webpack 5.
It is also now built against Webpack 5 types.  Webpack 4 support is temporarily maintained while the remainder of the tooling is transitioned.
2021-02-17 12:42:40 -06:00
Charles Lyding
b203378821 refactor(@ngtools/webpack): limit Webpack module iteration when rebuilding 2021-02-08 09:27:13 -05:00
Charles Lyding
9eb7fb53bb fix(@ngtools/webpack): reduce overhead of Angular compiler rebuild requests
This change adds additional checks to reduce the number of Webpack `rebuildModule` calls when the Angular compiler requests additional files to be rebuilt. Now if an emitted file's output does not change from its previous emit, a Webpack rebuild of the module is not performed. This can greatly reduce the amount of computation needed during a rebuild as any files that required re-analysis by the Angular compiler but whose final output did not change will not trigger potential expensive Webpack module graph analysis and additonal module rebuilds.
2021-02-08 09:27:13 -05:00
Alan Agius
d2ce3e7d62 fix(@ngtools/webpack): don't use skipTemplateCodegen to determine if compilation is JIT mode
With this change we add a new `jitMode` option to the ivy AngularWebpackPlugin.
`readConfiguration` from `@angular/compiler-cli` will use file configuration options over programmaticly supplied options. By using a separate option the options precedence issue can be avoided.

Closes #19949
2021-02-03 20:44:07 +01:00
Alan Agius
5fdc0a666a fix(@ngtools/webpack): use getDiagnosticsForFile instead of getDiagnostics
With this change we replace `getDiagnostics` with `getDiagnosticsForFile`. `getDiagnostics` no longer accept a parameter and is intended to be used instead of `getDiagnostics`.

I used `OptimizeFor.WholeProgram` based on the comments in https://github.com/angular/angular/pull/40331#discussion_r555953776 which suggests that if you iterate through files one at a time the `WholeProgram` flag should be used.

For more context see: https://github.com/angular/angular/pull/40331
2021-01-14 12:34:04 -05:00
Charles Lyding
391d60cc3d fix(@ngtools/webpack): remove use of Webpack compilation fileTimestamps property
The `fileTimestamps` property on the Webpack compilation object no longer exists with Webpack 5.  This change uses the Webpack compiler's property of the same name instead.  The cache invalidation is also moved to a separate file and now calculates the changed file set as well.  This eliminates the second iteration of the file timestamps within the resource loader.
2020-11-30 10:55:13 +01:00
Charles Lyding
8994da6d74 fix(@ngtools/webpack): normalize dependency paths before webpack use 2020-11-26 09:36:29 +01:00
Charles Lyding
ff9e245a51 refactor(@ngtools/webpack): remove forwardSlashPath utility usage from Ivy plugin
A cached path normalization helper is now used in places that still require normalization.  Usage was also removed completely in locations that are not needed either because the path was later normalized or the normalization would provide no benefit.
2020-11-26 09:36:29 +01:00
Charles Lyding
4c46c191c7 fix(@ngtools/webpack): normalize resource path before rebuild check 2020-11-26 09:36:29 +01:00
Charles Lyding
c322a29283 fix(@ngtools/webpack): remove use of Webpack 5 deprecated compilationDependencies
The `Compilation.compilationDependencies` property is now deprecated in Webpack 5.  The `Compilation.fileDependencies` property is now used instead with Webpack 5.
2020-11-18 13:08:38 -05:00
Alan Agius
eb313f7dc2 fix(@ngtools/webpack): only use require.resolve as a fallback in NGCC processing
Use `enhanced-resolve` instead of `require.resolve` to ensure that we can use symlink path instead of real-path when resolving a linked module.

Closes #19395
2020-11-16 15:43:40 -05:00
Charles Lyding
71a0e11fc1 refactor(@ngtools/webpack): introduce Ivy Webpack compiler plugin/loader
This change introduces a new Ivy Webpack compiler plugin. The plugin leverages the Ivy APIs from the @angular/compiler-cli package. The plugin also simplifies and reduces the amount of code within the plugin by leveraging newer TypeScript features and capabilities. The need for the virtual filesystem has also been removed. The file replacements capability was the primary driver for the previous need for the virtual filesystem. File replacements are now implemented using a two-pronged approach. The first, for TypeScript, is to hook TypeScript module resolution and adjust the resolved modules based on the configured file replacements. This is similar in behavior to TypeScript path mapping. The second, for Webpack, is the use of the NormalModuleReplacementPlugin to facilitate bundling of the configured file replacements. An advantage to this approach is that the build system (both TypeScript and Webpack) are now aware of the replacements and can operate without augmenting multiple aspects of system as was needed previously.
The plugin also introduces the use of TypeScript’s builder programs. The current primary benefit is more accurate and simplified dependency discovery. Further, they also provide for the introduction of incremental build support and incremental type checking.
2020-11-05 08:31:12 +01:00