Skip to content

Commit

Permalink
Remove support for sending analytics (#4077)
Browse files Browse the repository at this point in the history
  • Loading branch information
sigurdm authored Dec 19, 2023
1 parent 61e2834 commit a47a4de
Show file tree
Hide file tree
Showing 15 changed files with 5 additions and 105 deletions.
13 changes: 2 additions & 11 deletions lib/pub.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,14 @@ export 'src/executable.dart'
CommandResolutionFailedException,
CommandResolutionIssue,
DartExecutableWithPackageConfig;
export 'src/pub_embeddable_command.dart' show PubAnalytics;

/// Returns a [Command] for pub functionality that can be used by an embedding
/// CommandRunner.
///
/// If [analytics] is given, pub will use that analytics instance to send
/// statistics about resolutions.
///
/// [isVerbose] should return `true` (after argument resolution) if the
/// embedding top-level is in verbose mode.
Command<int> pubCommand({
PubAnalytics? analytics,
required bool Function() isVerbose,
}) =>
PubEmbeddableCommand(analytics, isVerbose);
Command<int> pubCommand({required bool Function() isVerbose}) =>
PubEmbeddableCommand(isVerbose);

/// Makes sure that [dir]/pubspec.yaml is resolved such that pubspec.lock and
/// .dart_tool/package_config.json are up-to-date and all packages are
Expand All @@ -46,15 +39,13 @@ Command<int> pubCommand({
/// Throws a [ResolutionFailedException] if resolution fails.
Future<void> ensurePubspecResolved(
String dir, {
PubAnalytics? analytics,
bool isOffline = false,
bool checkForSdkUpdate = false,
bool summaryOnly = true,
bool onlyOutputWhenTerminal = true,
}) async {
try {
await Entrypoint(dir, SystemCache(isOffline: isOffline)).ensureUpToDate(
analytics: analytics,
checkForSdkUpdate: checkForSdkUpdate,
summaryOnly: summaryOnly,
onlyOutputWhenTerminal: onlyOutputWhenTerminal,
Expand Down
2 changes: 0 additions & 2 deletions lib/src/command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,6 @@ abstract class PubCommand extends Command<int> {
PubTopLevel get _pubTopLevel =>
_pubEmbeddableCommand ?? runner as PubTopLevel;

PubAnalytics? get analytics => _pubEmbeddableCommand?.analytics;

@override
String get invocation {
PubCommand? command = this;
Expand Down
2 changes: 0 additions & 2 deletions lib/src/command/add.dart
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,6 @@ Specify multiple sdk packages with descriptors.''');
SolveType.get,
dryRun: argResults.isDryRun,
precompile: !argResults.isDryRun && argResults.shouldPrecompile,
analytics: argResults.isDryRun ? null : analytics,
);

if (!argResults.isDryRun &&
Expand All @@ -284,7 +283,6 @@ Specify multiple sdk packages with descriptors.''');
SolveType.get,
precompile: argResults.shouldPrecompile,
summaryOnly: true,
analytics: analytics,
);
}

Expand Down
2 changes: 0 additions & 2 deletions lib/src/command/downgrade.dart
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ class DowngradeCommand extends PubCommand {
SolveType.downgrade,
unlock: argResults.rest,
dryRun: dryRun,
analytics: analytics,
);
var example = entrypoint.example;
if (argResults.flag('example') && example != null) {
Expand All @@ -78,7 +77,6 @@ class DowngradeCommand extends PubCommand {
unlock: argResults.rest,
dryRun: dryRun,
summaryOnly: true,
analytics: analytics,
);
}

Expand Down
2 changes: 0 additions & 2 deletions lib/src/command/get.dart
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ class GetCommand extends PubCommand {
SolveType.get,
dryRun: argResults.flag('dry-run'),
precompile: argResults.flag('precompile'),
analytics: analytics,
enforceLockfile: argResults.flag('enforce-lockfile'),
);

Expand All @@ -88,7 +87,6 @@ class GetCommand extends PubCommand {
SolveType.get,
dryRun: argResults.flag('dry-run'),
precompile: argResults.flag('precompile'),
analytics: analytics,
summaryOnly: true,
enforceLockfile: argResults.flag('enforce-lockfile'),
);
Expand Down
1 change: 0 additions & 1 deletion lib/src/command/global_activate.dart
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,6 @@ class GlobalActivateCommand extends PubCommand {
path,
executables,
overwriteBinStubs: overwrite,
analytics: analytics,
);
}

Expand Down
2 changes: 1 addition & 1 deletion lib/src/command/lish.dart
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ the \$PUB_HOSTED_URL environment variable.''',
}

if (!skipValidation) {
await entrypoint.acquireDependencies(SolveType.get, analytics: analytics);
await entrypoint.acquireDependencies(SolveType.get);
} else {
log.warning(
'Running with `skip-validation`. No client-side validation is done.',
Expand Down
2 changes: 0 additions & 2 deletions lib/src/command/remove.dart
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ To remove a dependency override of a package prefix the package name with
SolveType.get,
precompile: !isDryRun && argResults.flag('precompile'),
dryRun: isDryRun,
analytics: isDryRun ? null : analytics,
);

var example = entrypoint.example;
Expand All @@ -104,7 +103,6 @@ To remove a dependency override of a package prefix the package name with
SolveType.get,
precompile: argResults.flag('precompile'),
summaryOnly: true,
analytics: analytics,
);
}
}
Expand Down
2 changes: 0 additions & 2 deletions lib/src/command/upgrade.dart
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,6 @@ Consider using the Dart 2.19 sdk to migrate to null safety.''');
dryRun: _dryRun,
precompile: _precompile,
summaryOnly: onlySummary,
analytics: analytics,
);

_showOfflineWarning();
Expand Down Expand Up @@ -360,7 +359,6 @@ be direct 'dependencies' or 'dev_dependencies', following packages are not:
solveType,
dryRun: _dryRun,
precompile: !_dryRun && _precompile,
analytics: _dryRun ? null : analytics, // No analytics for dry-run
);

_outputChangeSummary(changes);
Expand Down
12 changes: 0 additions & 12 deletions lib/src/entrypoint.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import 'package_config.dart' show PackageConfig;
import 'package_config.dart';
import 'package_graph.dart';
import 'package_name.dart';
import 'pub_embeddable_command.dart';
import 'pubspec.dart';
import 'sdk.dart';
import 'solver.dart';
Expand Down Expand Up @@ -309,9 +308,6 @@ class Entrypoint {
/// The iterable [unlock] specifies the list of packages whose versions can be
/// changed even if they are locked in the pubspec.lock file.
///
/// [analytics] holds the information needed for the embedded pub command to
/// send analytics.
///
/// Shows a report of the changes made relative to the previous lockfile. If
/// this is an upgrade or downgrade, all transitive dependencies are shown in
/// the report. Otherwise, only dependencies that were changed are shown. If
Expand All @@ -333,7 +329,6 @@ class Entrypoint {
Iterable<String>? unlock,
bool dryRun = false,
bool precompile = false,
required PubAnalytics? analytics,
bool summaryOnly = false,
bool enforceLockfile = false,
}) async {
Expand Down Expand Up @@ -408,10 +403,6 @@ To update `$lockFilePath` run `$topLevelProgram pub get`$suffix without
_lockFile = newLockFile;

if (!dryRun) {
if (analytics != null) {
result.sendAnalytics(analytics);
}

/// Build a package graph from the version solver results so we don't
/// have to reload and reparse all the pubspecs.
_packageGraph = Future.value(PackageGraph.fromSolveResult(this, result));
Expand Down Expand Up @@ -612,7 +603,6 @@ To update `$lockFilePath` run `$topLevelProgram pub get`$suffix without
/// output if no terminal is attached.
Future<void> ensureUpToDate({
bool checkForSdkUpdate = false,
PubAnalytics? analytics,
bool summaryOnly = true,
bool onlyOutputWhenTerminal = true,
}) async {
Expand All @@ -621,14 +611,12 @@ To update `$lockFilePath` run `$topLevelProgram pub get`$suffix without
await log.errorsOnlyUnlessTerminal(() async {
await acquireDependencies(
SolveType.get,
analytics: analytics,
summaryOnly: summaryOnly,
);
});
} else {
await acquireDependencies(
SolveType.get,
analytics: analytics,
summaryOnly: summaryOnly,
);
}
Expand Down
4 changes: 0 additions & 4 deletions lib/src/executable.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import 'io.dart';
import 'isolate.dart' as isolate;
import 'log.dart' as log;
import 'log.dart';
import 'pub_embeddable_command.dart';
import 'system_cache.dart';
import 'utils.dart';

Expand Down Expand Up @@ -241,8 +240,6 @@ final class DartExecutableWithPackageConfig {
/// * Otherwise if the current package resolution is outdated do an implicit
/// `pub get`, if that fails, throw a [CommandResolutionFailedException].
///
/// This pub get will send analytics events to [analytics] if provided.
///
/// * Otherwise let `<current>` be the name of the package at [root], and
/// interpret [descriptor] as `[<package>][:<command>]`.
///
Expand Down Expand Up @@ -281,7 +278,6 @@ Future<DartExecutableWithPackageConfig> getExecutableForCommand(
bool allowSnapshot = true,
String? root,
String? pubCacheDir,
PubAnalytics? analytics,
List<String> additionalSources = const [],
String? nativeAssets,
}) async {
Expand Down
8 changes: 1 addition & 7 deletions lib/src/global_packages.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import 'lock_file.dart';
import 'log.dart' as log;
import 'package.dart';
import 'package_name.dart';
import 'pub_embeddable_command.dart';
import 'pubspec.dart';
import 'sdk.dart';
import 'sdk/dart.dart';
Expand Down Expand Up @@ -165,15 +164,11 @@ class GlobalPackages {
String path,
List<String>? executables, {
required bool overwriteBinStubs,
required PubAnalytics? analytics,
}) async {
var entrypoint = Entrypoint(path, cache);

// Get the package's dependencies.
await entrypoint.acquireDependencies(
SolveType.get,
analytics: analytics,
);
await entrypoint.acquireDependencies(SolveType.get);
var name = entrypoint.root.name;
_describeActive(name, cache);

Expand Down Expand Up @@ -586,7 +581,6 @@ try:
entrypoint.rootDir,
packageExecutables,
overwriteBinStubs: true,
analytics: null,
);
}
successes.add(id.name);
Expand Down
16 changes: 1 addition & 15 deletions lib/src/pub_embeddable_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

import 'package:unified_analytics/unified_analytics.dart';

import 'command.dart' show PubCommand, PubTopLevel;
import 'command.dart';
import 'command/add.dart';
Expand All @@ -25,15 +23,6 @@ import 'log.dart' as log;
import 'log.dart';
import 'utils.dart';

/// The information needed for the embedded pub command to send analytics.
final class PubAnalytics {
final Analytics? Function() _analyticsGetter;

Analytics? get analytics => _analyticsGetter();

PubAnalytics(this._analyticsGetter);
}

/// Exposes the `pub` commands as a command to be embedded in another command
/// runner such as `dart pub`.
class PubEmbeddableCommand extends PubCommand implements PubTopLevel {
Expand All @@ -51,12 +40,9 @@ class PubEmbeddableCommand extends PubCommand implements PubTopLevel {
@override
String get directory => argResults.option('directory');

@override
final PubAnalytics? analytics;

final bool Function() isVerbose;

PubEmbeddableCommand(this.analytics, this.isVerbose) : super() {
PubEmbeddableCommand(this.isVerbose) : super() {
// This flag was never honored in the embedding but since it was accepted we
// leave it as a hidden flag to avoid breaking clients that pass it.
argParser.addFlag('trace', hide: true);
Expand Down
41 changes: 0 additions & 41 deletions lib/src/solver/result.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,13 @@

import 'package:collection/collection.dart';
import 'package:pub_semver/pub_semver.dart';
import 'package:unified_analytics/unified_analytics.dart';

import '../http.dart';
import '../io.dart';
import '../lock_file.dart';
import '../log.dart' as log;
import '../package.dart';
import '../package_name.dart';
import '../pub_embeddable_command.dart';
import '../pubspec.dart';
import '../source/cached.dart';
import '../source/hosted.dart';
import '../system_cache.dart';

/// The result of a successful version resolution.
Expand Down Expand Up @@ -136,42 +131,6 @@ class SolveResult {
this.resolutionTime,
);

/// Send analytics about the package resolution.
void sendAnalytics(PubAnalytics pubAnalytics) {
ArgumentError.checkNotNull(pubAnalytics);
final analytics = pubAnalytics.analytics;
if (analytics == null) return;

final dependenciesForAnalytics = <PackageId>[];
for (final package in packages) {
// Only send analytics for packages from pub.dev.
if (HostedSource.isFromPubDev(package) ||
(package.source is HostedSource && runningFromTest)) {
dependenciesForAnalytics.add(package);
}
}
// Randomize the dependencies, such that even if some analytics events don't
// get sent, the results will still be representative.
shuffle(dependenciesForAnalytics);
for (final package in dependenciesForAnalytics) {
final dependencyKind = const {
DependencyType.dev: 'dev',
DependencyType.direct: 'direct',
DependencyType.none: 'transitive',
}[_root.pubspec.dependencyType(package.name)]!;
analytics.send(
Event.pubGet(
packageName: package.name,
version: package.version.canonicalizedVersion,
dependencyType: dependencyKind,
),
);
log.fine(
'Sending analytics hit for "pub-get" of ${package.name} version ${package.version} as dependency-kind $dependencyKind',
);
}
}

@override
String toString() => 'Took $attemptedSolutions tries to resolve to\n'
'- ${packages.join("\n- ")}';
Expand Down
1 change: 0 additions & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ dependencies:
stack_trace: ^1.10.0
tar: ^1.0.1
typed_data: ^1.3.1
unified_analytics: ^5.1.0
yaml: ^3.1.0
yaml_edit: ^2.0.0

Expand Down

0 comments on commit a47a4de

Please sign in to comment.