Skip to content
Merged
Show file tree
Hide file tree
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
4 changes: 0 additions & 4 deletions goldens/circular-deps/packages.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,6 @@
"packages/angular/build/src/tools/esbuild/utils.ts",
"packages/angular/build/src/utils/server-rendering/manifest.ts"
],
[
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❤️

"packages/angular/cli/src/analytics/analytics-collector.ts",
"packages/angular/cli/src/command-builder/command-module.ts"
],
[
"packages/angular/cli/src/analytics/analytics.ts",
"packages/angular/cli/src/command-builder/command-module.ts"
Expand Down
13 changes: 7 additions & 6 deletions packages/angular/cli/src/analytics/analytics-collector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
* found in the LICENSE file at https://angular.dev/license
*/

import { logging } from '@angular-devkit/core';
import { randomUUID } from 'node:crypto';
import * as https from 'node:https';
import * as os from 'node:os';
import * as querystring from 'node:querystring';
import * as semver from 'semver';
import type { CommandContext } from '../command-builder/command-module';
import { ngDebug } from '../utilities/environment-options';
import { assertIsError } from '../utilities/error';
import { VERSION } from '../utilities/version';
Expand All @@ -32,8 +32,9 @@ export class AnalyticsCollector {
private readonly userParameters: Record<UserCustomDimension, PrimitiveTypes | undefined>;

constructor(
private context: CommandContext,
private logger: logging.Logger,
userId: string,
packageManagerInfo: { name: string; version: string | undefined },
) {
const requestParameters: Partial<Record<RequestParameter, PrimitiveTypes>> = {
[RequestParameter.ProtocolVersion]: 2,
Expand Down Expand Up @@ -63,7 +64,7 @@ export class AnalyticsCollector {
this.requestParameterStringified = querystring.stringify(requestParameters);

const parsedVersion = semver.parse(process.version);
const packageManagerVersion = context.packageManager.version;
const packageManagerVersion = packageManagerInfo.version;

this.userParameters = {
// While architecture is being collect by GA as UserAgentArchitecture.
Expand All @@ -75,7 +76,7 @@ export class AnalyticsCollector {
? `${parsedVersion.major}.${parsedVersion.minor}.${parsedVersion.patch}`
: 'other',
[UserCustomDimension.NodeMajorVersion]: parsedVersion?.major,
[UserCustomDimension.PackageManager]: context.packageManager.name,
[UserCustomDimension.PackageManager]: packageManagerInfo.name,
[UserCustomDimension.PackageManagerVersion]: packageManagerVersion,
[UserCustomDimension.PackageManagerMajorVersion]: packageManagerVersion
? +packageManagerVersion.split('.', 1)[0]
Expand Down Expand Up @@ -152,7 +153,7 @@ export class AnalyticsCollector {

async flush(): Promise<void> {
const pendingTrackingEvents = this.trackingEventsQueue;
this.context.logger.debug(`Analytics flush size. ${pendingTrackingEvents?.length}.`);
this.logger.debug(`Analytics flush size. ${pendingTrackingEvents?.length}.`);

if (!pendingTrackingEvents?.length) {
return;
Expand All @@ -167,7 +168,7 @@ export class AnalyticsCollector {
} catch (error) {
// Failure to report analytics shouldn't crash the CLI.
assertIsError(error);
this.context.logger.debug(`Send analytics error. ${error.message}.`);
this.logger.debug(`Send analytics error. ${error.message}.`);
}
}

Expand Down
13 changes: 10 additions & 3 deletions packages/angular/cli/src/command-builder/command-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,10 @@ export interface CommandContext {

export type OtherOptions = Record<string, unknown>;

export interface CommandModuleImplementation<T extends {} = {}>
extends Omit<YargsCommandModule<{}, T>, 'builder' | 'handler'> {
export interface CommandModuleImplementation<T extends {} = {}> extends Omit<
YargsCommandModule<{}, T>,
'builder' | 'handler'
> {
/** Scope in which the command can be executed in. */
scope: CommandScope;

Expand Down Expand Up @@ -187,7 +189,12 @@ export abstract class CommandModule<T extends {} = {}> implements CommandModuleI
['version', 'update', 'analytics'].includes(this.commandName),
);

return userId ? new AnalyticsCollector(this.context, userId) : undefined;
return userId
? new AnalyticsCollector(this.context.logger, userId, {
name: this.context.packageManager.name,
version: this.context.packageManager.version,
})
: undefined;
}

/**
Expand Down