Skip to content

Commit

Permalink
refactor(@angular-devkit/build-angular): use compiler parsed value of…
Browse files Browse the repository at this point in the history
… 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
  • Loading branch information
alan-agius4 authored and vikerman committed Nov 1, 2019
1 parent f7769b8 commit e70a2b0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
15 changes: 5 additions & 10 deletions packages/angular_devkit/build_angular/plugins/webpack/analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);
}
}

Expand Down
7 changes: 6 additions & 1 deletion packages/angular_devkit/build_angular/src/browser/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)],
};
}

Expand Down

0 comments on commit e70a2b0

Please sign in to comment.