Skip to content

Commit e70a2b0

Browse files
alan-agius4vikerman
authored andcommitted
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
1 parent f7769b8 commit e70a2b0

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

packages/angular_devkit/build_angular/plugins/webpack/analytics.ts

+5-10
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ export function countOccurrences(source: string, match: string, wordBreak = fals
6969
* Holder of statistics related to the build.
7070
*/
7171
class AnalyticsBuildStats {
72-
public isIvy = false;
7372
public errors: string[] = [];
7473
public numberOfNgOnInit = 0;
7574
public numberOfComponents = 0;
@@ -96,7 +95,9 @@ export class NgBuildAnalyticsPlugin {
9695
protected _projectRoot: string,
9796
protected _analytics: analytics.Analytics,
9897
protected _category: string,
99-
) {}
98+
private _isIvy: boolean,
99+
) {
100+
}
100101

101102
protected _reset() {
102103
this._stats = new AnalyticsBuildStats();
@@ -129,7 +130,7 @@ export class NgBuildAnalyticsPlugin {
129130
dimensions[analytics.NgCliAnalyticsDimensions.BuildErrors] = `,${this._stats.errors.join()},`;
130131
}
131132

132-
dimensions[analytics.NgCliAnalyticsDimensions.NgIvyEnabled] = this._stats.isIvy;
133+
dimensions[analytics.NgCliAnalyticsDimensions.NgIvyEnabled] = this._isIvy;
133134

134135
return dimensions;
135136
}
@@ -159,13 +160,7 @@ export class NgBuildAnalyticsPlugin {
159160
// This does not include View Engine AOT compilation, we use the ngfactory for it.
160161
this._stats.numberOfComponents += countOccurrences(module._source.source(), ' Component({');
161162
// For Ivy we just count ɵcmp.
162-
const numIvyComponents = countOccurrences(module._source.source(), 'ɵcmp', true);
163-
this._stats.numberOfComponents += numIvyComponents;
164-
165-
// Check whether this is an Ivy app so that it can reported as part of analytics.
166-
if (!this._stats.isIvy && numIvyComponents > 0) {
167-
this._stats.isIvy = true;
168-
}
163+
this._stats.numberOfComponents += countOccurrences(module._source.source(), '.ɵcmp', true);
169164
}
170165
}
171166

packages/angular_devkit/build_angular/src/browser/index.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,12 @@ function getAnalyticsConfig(
166166

167167
// The category is the builder name if it's an angular builder.
168168
return {
169-
plugins: [new NgBuildAnalyticsPlugin(wco.projectRoot, context.analytics, category)],
169+
plugins: [new NgBuildAnalyticsPlugin(
170+
wco.projectRoot,
171+
context.analytics,
172+
category,
173+
!!wco.tsConfig.options.enableIvy,
174+
)],
170175
};
171176
}
172177

0 commit comments

Comments
 (0)