From e70a2b04bd6bcc545e8f994601acecd75d0c6084 Mon Sep 17 00:00:00 2001 From: Alan Agius Date: Wed, 16 Oct 2019 15:01:04 +0200 Subject: [PATCH] refactor(@angular-devkit/build-angular): use compiler parsed value of enableIvy At the moment we are relying on source content to determine if the compilation is under Ivy or VE. However, we do know what compilation we are in from the parsed tsconfig. With this change we use the `enableIvy` to set the analytics metric --- .../build_angular/plugins/webpack/analytics.ts | 15 +++++---------- .../build_angular/src/browser/index.ts | 7 ++++++- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/packages/angular_devkit/build_angular/plugins/webpack/analytics.ts b/packages/angular_devkit/build_angular/plugins/webpack/analytics.ts index a3fceb133f79..7bf7f0a8ba2c 100644 --- a/packages/angular_devkit/build_angular/plugins/webpack/analytics.ts +++ b/packages/angular_devkit/build_angular/plugins/webpack/analytics.ts @@ -69,7 +69,6 @@ export function countOccurrences(source: string, match: string, wordBreak = fals * Holder of statistics related to the build. */ class AnalyticsBuildStats { - public isIvy = false; public errors: string[] = []; public numberOfNgOnInit = 0; public numberOfComponents = 0; @@ -96,7 +95,9 @@ export class NgBuildAnalyticsPlugin { protected _projectRoot: string, protected _analytics: analytics.Analytics, protected _category: string, - ) {} + private _isIvy: boolean, + ) { + } protected _reset() { this._stats = new AnalyticsBuildStats(); @@ -129,7 +130,7 @@ export class NgBuildAnalyticsPlugin { dimensions[analytics.NgCliAnalyticsDimensions.BuildErrors] = `,${this._stats.errors.join()},`; } - dimensions[analytics.NgCliAnalyticsDimensions.NgIvyEnabled] = this._stats.isIvy; + dimensions[analytics.NgCliAnalyticsDimensions.NgIvyEnabled] = this._isIvy; return dimensions; } @@ -159,13 +160,7 @@ export class NgBuildAnalyticsPlugin { // This does not include View Engine AOT compilation, we use the ngfactory for it. this._stats.numberOfComponents += countOccurrences(module._source.source(), ' Component({'); // For Ivy we just count ɵcmp. - const numIvyComponents = countOccurrences(module._source.source(), 'ɵcmp', true); - this._stats.numberOfComponents += numIvyComponents; - - // Check whether this is an Ivy app so that it can reported as part of analytics. - if (!this._stats.isIvy && numIvyComponents > 0) { - this._stats.isIvy = true; - } + this._stats.numberOfComponents += countOccurrences(module._source.source(), '.ɵcmp', true); } } diff --git a/packages/angular_devkit/build_angular/src/browser/index.ts b/packages/angular_devkit/build_angular/src/browser/index.ts index 7cdf275cefd4..67017235899c 100644 --- a/packages/angular_devkit/build_angular/src/browser/index.ts +++ b/packages/angular_devkit/build_angular/src/browser/index.ts @@ -166,7 +166,12 @@ function getAnalyticsConfig( // The category is the builder name if it's an angular builder. return { - plugins: [new NgBuildAnalyticsPlugin(wco.projectRoot, context.analytics, category)], + plugins: [new NgBuildAnalyticsPlugin( + wco.projectRoot, + context.analytics, + category, + !!wco.tsConfig.options.enableIvy, + )], }; }