Skip to content

fix(@angular/cli): prevent nested schematic execution from generating analytics #14417

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 15, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 1 addition & 37 deletions packages/angular/cli/models/schematic-command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -265,48 +265,12 @@ export abstract class SchematicCommand<
analytics: this.analytics,
};
} else {
return {
...context,
analytics: new analytics.NoopAnalytics(),
};
return context;
}
});

workflow.engineHost.registerOptionsTransform(validateOptionsWithSchema(workflow.registry));

// This needs to be the last transform as it reports the flags to analytics (if enabled).
workflow.engineHost.registerOptionsTransform(async (
schematic,
options: { [prop: string]: number | string },
context,
): Promise<{ [prop: string]: number | string }> => {
const analytics = context && context.analytics;
if (!schematic.schemaJson || !context || !analytics) {
return options;
}

const collectionName = context.schematic.collection.description.name;
const schematicName = context.schematic.description.name;

if (!isPackageNameSafeForAnalytics(collectionName)) {
return options;
}

const args = await parseJsonSchemaToOptions(this._workflow.registry, schematic.schemaJson);
const dimensions: (boolean | number | string)[] = [];
for (const option of args) {
const ua = option.userAnalytics;

if (option.name in options && ua) {
dimensions[ua] = options[option.name];
}
}

analytics.event('schematics', collectionName + ':' + schematicName, { dimensions });

return options;
});

if (options.defaults) {
workflow.registry.addPreTransform(schema.transforms.addUndefinedDefaults);
} else {
Expand Down