Skip to content

Commit 2303a04

Browse files
committed
feat(@angular-devkit/build-angular): add analytics for ivy/non-ivy builds
Look for `ngComponentDef` or `ngModuleDef` in the webpack analytics plugin to report back whether the current build is built with Ivy enabled.
1 parent 42155fc commit 2303a04

File tree

4 files changed

+18
-4
lines changed

4 files changed

+18
-4
lines changed

docs/design/analytics.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ To create a new dimension (tracking a new flag):
2828
defined on GA.
2929
1. Use the ID of the dimension as the `x-user-analytics` value in the `schema.json` file.
3030
1. Add a new row to the table below in the same PR as the one adding the dimension to the code.
31-
1. New dimensions PRs need to be approved by [bradgreen@google.com](mailto:bradgreen@google.com),
32-
[stephenfluin@google.com](mailto:stephenfluin@google.com) and
31+
1. New dimensions PRs need to be approved by [stephenfluin@google.com](mailto:stephenfluin@google.com) and
3332
[iminar@google.com](mailto:iminar@google.com). **This is not negotiable.**
3433

3534
**DO NOT ADD `x-user-analytics` FOR VALUES THAT ARE USER IDENTIFIABLE (PII), FOR EXAMPLE A
@@ -48,6 +47,7 @@ Note: There's a limit of 20 custom dimensions.
4847
| 5 | `Flag: --style` | `string` |
4948
| 6 | `--collection` | `string` |
5049
| 7 | `--buildEventLog` | `boolean` |
50+
| 8 | `Ivy Enabled` | `boolean` |
5151
| 9 | `Flag: --inlineStyle` | `boolean` |
5252
| 10 | `Flag: --inlineTemplate` | `boolean` |
5353
| 11 | `Flag: --viewEncapsulation` | `string` |

etc/api/angular_devkit/core/src/_golden-api.d.ts

+1
Original file line numberDiff line numberDiff line change
@@ -618,6 +618,7 @@ export declare enum NgCliAnalyticsDimensions {
618618
NodeVersion = 4,
619619
NgAddCollection = 6,
620620
NgBuildBuildEventLog = 7,
621+
NgIvyEnabled = 8,
621622
BuildErrors = 20
622623
}
623624

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

+13-2
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ 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;
7273
public errors: string[] = [];
7374
public numberOfNgOnInit = 0;
7475
public numberOfComponents = 0;
@@ -121,13 +122,15 @@ export class NgBuildAnalyticsPlugin {
121122
return metrics;
122123
}
123124
protected _getDimensions(stats: Stats) {
124-
const dimensions: (string | number)[] = [];
125+
const dimensions: (string | number | boolean)[] = [];
125126

126127
if (this._stats.errors.length) {
127128
// Adding commas before and after so the regex are easier to define filters.
128129
dimensions[analytics.NgCliAnalyticsDimensions.BuildErrors] = `,${this._stats.errors.join()},`;
129130
}
130131

132+
dimensions[analytics.NgCliAnalyticsDimensions.NgIvyEnabled] = this._stats.isIvy;
133+
131134
return dimensions;
132135
}
133136

@@ -156,7 +159,15 @@ export class NgBuildAnalyticsPlugin {
156159
// This does not include View Engine AOT compilation, we use the ngfactory for it.
157160
this._stats.numberOfComponents += countOccurrences(module._source.source(), ' Component({');
158161
// For Ivy we just count ngComponentDef.
159-
this._stats.numberOfComponents += countOccurrences(module._source.source(), 'ngComponentDef', true);
162+
const numIvyComponents = countOccurrences(module._source.source(), 'ngComponentDef', 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) {
167+
if (numIvyComponents > 0 || module._source.source().includes('ngModuleDef')) {
168+
this._stats.isIvy = true;
169+
}
170+
}
160171
}
161172
}
162173

packages/angular_devkit/core/src/analytics/index.ts

+2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export enum NgCliAnalyticsDimensions {
2626
NodeVersion = 4,
2727
NgAddCollection = 6,
2828
NgBuildBuildEventLog = 7,
29+
NgIvyEnabled = 8,
2930
BuildErrors = 20,
3031
}
3132

@@ -56,6 +57,7 @@ export const NgCliAnalyticsDimensionsFlagInfo: { [name: string]: [string, string
5657
NodeVersion: ['Node Version', 'number'],
5758
NgAddCollection: ['--collection', 'string'],
5859
NgBuildBuildEventLog: ['--buildEventLog', 'boolean'],
60+
NgIvyEnabled: ['Ivy Enabled', 'boolean'],
5961
BuildErrors: ['Build Errors (comma separated)', 'string'],
6062
};
6163

0 commit comments

Comments
 (0)