Skip to content

Commit 90988aa

Browse files
alan-agius4clydin
authored andcommitted
fix(@angular/cli): collect analytics option usage from workspace config and prompts
With this change we fix two analytics collection bugs: - We now collect the usage of options defined in the workspace config (angular.json). - We now also collect values set via schematic prompts. Closes: #17900
1 parent 290fe43 commit 90988aa

File tree

7 files changed

+22
-43
lines changed

7 files changed

+22
-43
lines changed

packages/angular/cli/commands/build-impl.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,4 @@ export class BuildCommand extends ArchitectCommand<BuildCommandSchema> {
1515
public async run(options: ArchitectCommandOptions & Arguments) {
1616
return this.runArchitectTarget(options);
1717
}
18-
19-
async reportAnalytics(
20-
paths: string[],
21-
options: BuildCommandSchema & Arguments,
22-
dimensions: (boolean | number | string)[] = [],
23-
metrics: (boolean | number | string)[] = [],
24-
): Promise<void> {
25-
return super.reportAnalytics(paths, options, dimensions, metrics);
26-
}
2718
}

packages/angular/cli/commands/deploy-impl.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,4 @@ export class DeployCommand extends ArchitectCommand<DeployCommandSchema> {
3737
return super.initialize(options);
3838
}
3939
}
40-
41-
async reportAnalytics(
42-
paths: string[],
43-
options: DeployCommandSchema & Arguments,
44-
dimensions: (boolean | number | string)[] = [],
45-
metrics: (boolean | number | string)[] = [],
46-
): Promise<void> {
47-
return super.reportAnalytics(paths, options, dimensions, metrics);
48-
}
4940
}

packages/angular/cli/commands/generate-impl.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -78,22 +78,18 @@ export class GenerateCommand extends SchematicCommand<GenerateCommandSchema> {
7878
paths: string[],
7979
options: GenerateCommandSchema & Arguments,
8080
): Promise<void> {
81-
const [collectionName, schematicName] = await this.parseSchematicInfo(options);
82-
83-
if (!schematicName || !collectionName) {
81+
if (!this.collectionName || !this.schematicName) {
8482
return;
8583
}
86-
const escapedSchematicName = (this.longSchematicName || schematicName).replace(/\//g, '_');
84+
const escapedSchematicName = (this.longSchematicName || this.schematicName).replace(/\//g, '_');
8785

8886
return super.reportAnalytics(
89-
['generate', collectionName.replace(/\//g, '_'), escapedSchematicName],
87+
['generate', this.collectionName.replace(/\//g, '_'), escapedSchematicName],
9088
options,
9189
);
9290
}
9391

94-
private async parseSchematicInfo(options: {
95-
schematic?: string;
96-
}): Promise<[string, string | undefined]> {
92+
private async parseSchematicInfo(options: GenerateCommandSchema): Promise<[string, string | undefined]> {
9793
let collectionName = await this.getDefaultSchematicCollection();
9894

9995
let schematicName = options.schematic;

packages/angular/cli/commands/serve-impl.ts

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
*/
88
import { ArchitectCommand, ArchitectCommandOptions } from '../models/architect-command';
99
import { Arguments } from '../models/interface';
10-
import { Schema as BuildCommandSchema } from './build';
1110
import { Schema as ServeCommandSchema } from './serve';
1211

1312
export class ServeCommand extends ArchitectCommand<ServeCommandSchema> {
@@ -20,13 +19,4 @@ export class ServeCommand extends ArchitectCommand<ServeCommandSchema> {
2019
public async run(options: ArchitectCommandOptions & Arguments) {
2120
return this.runArchitectTarget(options);
2221
}
23-
24-
async reportAnalytics(
25-
paths: string[],
26-
options: BuildCommandSchema & Arguments,
27-
dimensions: (boolean | number | string)[] = [],
28-
metrics: (boolean | number | string)[] = [],
29-
): Promise<void> {
30-
return super.reportAnalytics(paths, options, dimensions, metrics);
31-
}
3222
}

packages/angular/cli/models/architect-command.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ export abstract class ArchitectCommand<
2727
protected _architect!: Architect;
2828
protected _architectHost!: WorkspaceNodeModulesArchitectHost;
2929
protected _registry!: json.schema.SchemaRegistry;
30+
protected readonly useReportAnalytics = false;
3031

3132
// If this command supports running multiple targets.
3233
protected multiTarget = false;
@@ -192,7 +193,6 @@ export abstract class ArchitectCommand<
192193
protected async runSingleTarget(
193194
target: Target,
194195
targetOptions: string[],
195-
commandOptions: ArchitectCommandOptions & Arguments,
196196
) {
197197
// We need to build the builderSpec twice because architect does not understand
198198
// overrides separately (getting the configuration builds the whole project, including
@@ -216,6 +216,11 @@ export abstract class ArchitectCommand<
216216
return 1;
217217
}
218218

219+
await this.reportAnalytics([this.description.name], {
220+
...await this._architectHost.getOptionsForTarget(target) as unknown as T,
221+
...overrides,
222+
});
223+
219224
const run = await this._architect.scheduleTarget(target, overrides as json.JsonObject, {
220225
logger: this.logger,
221226
analytics: isPackageNameSafeForAnalytics(builderConf) ? this.analytics : undefined,
@@ -246,13 +251,12 @@ export abstract class ArchitectCommand<
246251
result |= await this.runSingleTarget(
247252
{ ...targetSpec, project } as Target,
248253
extra,
249-
options,
250254
);
251255
}
252256

253257
return result;
254258
} else {
255-
return await this.runSingleTarget(targetSpec, extra, options);
259+
return await this.runSingleTarget(targetSpec, extra);
256260
}
257261
} catch (e) {
258262
if (e instanceof schema.SchemaValidationException) {

packages/angular/cli/models/command.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ export interface BaseCommandOptions {
2323
}
2424

2525
export abstract class Command<T extends BaseCommandOptions = BaseCommandOptions> {
26-
public allowMissingWorkspace = false;
26+
protected allowMissingWorkspace = false;
27+
protected useReportAnalytics = true;
2728
readonly workspace?: AngularWorkspace;
2829
readonly analytics: analytics.Analytics;
2930

@@ -143,7 +144,7 @@ export abstract class Command<T extends BaseCommandOptions = BaseCommandOptions>
143144

144145
async reportAnalytics(
145146
paths: string[],
146-
options: T & Arguments,
147+
options: Arguments,
147148
dimensions: (boolean | number | string)[] = [],
148149
metrics: (boolean | number | string)[] = [],
149150
): Promise<void> {
@@ -173,7 +174,9 @@ export abstract class Command<T extends BaseCommandOptions = BaseCommandOptions>
173174
return this.printJsonHelp(options);
174175
} else {
175176
const startTime = +new Date();
176-
await this.reportAnalytics([this.description.name], options);
177+
if (this.useReportAnalytics) {
178+
await this.reportAnalytics([this.description.name], options);
179+
}
177180
const result = await this.run(options);
178181
const endTime = +new Date();
179182

packages/angular/cli/models/schematic-command.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ export class UnknownCollectionError extends Error {
7070
export abstract class SchematicCommand<
7171
T extends BaseSchematicSchema & BaseCommandOptions
7272
> extends Command<T> {
73-
readonly allowPrivateSchematics: boolean = false;
73+
protected readonly allowPrivateSchematics: boolean = false;
74+
protected readonly useReportAnalytics = false;
7475
protected _workflow!: NodeWorkflow;
7576

7677
protected defaultCollectionName = '@schematics/angular';
@@ -482,6 +483,9 @@ export abstract class SchematicCommand<
482483
...options.additionalOptions,
483484
};
484485

486+
const transformOptions = await workflow.engine.transformOptions(schematic, input).toPromise();
487+
await this.reportAnalytics([this.description.name], transformOptions as Arguments);
488+
485489
workflow.reporter.subscribe((event: DryRunEvent) => {
486490
nothingDone = false;
487491

0 commit comments

Comments
 (0)