Remove support for sending analytics (#4077)
diff --git a/lib/pub.dart b/lib/pub.dart index 1751672..a2a4621 100644 --- a/lib/pub.dart +++ b/lib/pub.dart
@@ -15,21 +15,14 @@ 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 @@ -46,7 +39,6 @@ /// Throws a [ResolutionFailedException] if resolution fails. Future<void> ensurePubspecResolved( String dir, { - PubAnalytics? analytics, bool isOffline = false, bool checkForSdkUpdate = false, bool summaryOnly = true, @@ -54,7 +46,6 @@ }) async { try { await Entrypoint(dir, SystemCache(isOffline: isOffline)).ensureUpToDate( - analytics: analytics, checkForSdkUpdate: checkForSdkUpdate, summaryOnly: summaryOnly, onlyOutputWhenTerminal: onlyOutputWhenTerminal,
diff --git a/lib/src/command.dart b/lib/src/command.dart index b2c5fe3..3849468 100644 --- a/lib/src/command.dart +++ b/lib/src/command.dart
@@ -142,8 +142,6 @@ PubTopLevel get _pubTopLevel => _pubEmbeddableCommand ?? runner as PubTopLevel; - PubAnalytics? get analytics => _pubEmbeddableCommand?.analytics; - @override String get invocation { PubCommand? command = this;
diff --git a/lib/src/command/add.dart b/lib/src/command/add.dart index 8f296e2..ad219da 100644 --- a/lib/src/command/add.dart +++ b/lib/src/command/add.dart
@@ -274,7 +274,6 @@ SolveType.get, dryRun: argResults.isDryRun, precompile: !argResults.isDryRun && argResults.shouldPrecompile, - analytics: argResults.isDryRun ? null : analytics, ); if (!argResults.isDryRun && @@ -284,7 +283,6 @@ SolveType.get, precompile: argResults.shouldPrecompile, summaryOnly: true, - analytics: analytics, ); }
diff --git a/lib/src/command/downgrade.dart b/lib/src/command/downgrade.dart index 8c7a17d..940a2ec 100644 --- a/lib/src/command/downgrade.dart +++ b/lib/src/command/downgrade.dart
@@ -69,7 +69,6 @@ SolveType.downgrade, unlock: argResults.rest, dryRun: dryRun, - analytics: analytics, ); var example = entrypoint.example; if (argResults.flag('example') && example != null) { @@ -78,7 +77,6 @@ unlock: argResults.rest, dryRun: dryRun, summaryOnly: true, - analytics: analytics, ); }
diff --git a/lib/src/command/get.dart b/lib/src/command/get.dart index 2544282..700472f 100644 --- a/lib/src/command/get.dart +++ b/lib/src/command/get.dart
@@ -78,7 +78,6 @@ SolveType.get, dryRun: argResults.flag('dry-run'), precompile: argResults.flag('precompile'), - analytics: analytics, enforceLockfile: argResults.flag('enforce-lockfile'), ); @@ -88,7 +87,6 @@ SolveType.get, dryRun: argResults.flag('dry-run'), precompile: argResults.flag('precompile'), - analytics: analytics, summaryOnly: true, enforceLockfile: argResults.flag('enforce-lockfile'), );
diff --git a/lib/src/command/global_activate.dart b/lib/src/command/global_activate.dart index 2080894..7d92471 100644 --- a/lib/src/command/global_activate.dart +++ b/lib/src/command/global_activate.dart
@@ -173,7 +173,6 @@ path, executables, overwriteBinStubs: overwrite, - analytics: analytics, ); }
diff --git a/lib/src/command/lish.dart b/lib/src/command/lish.dart index 8b63718..a9aa9d2 100644 --- a/lib/src/command/lish.dart +++ b/lib/src/command/lish.dart
@@ -258,7 +258,7 @@ } 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.',
diff --git a/lib/src/command/remove.dart b/lib/src/command/remove.dart index 7063c52..b27bb1b 100644 --- a/lib/src/command/remove.dart +++ b/lib/src/command/remove.dart
@@ -95,7 +95,6 @@ SolveType.get, precompile: !isDryRun && argResults.flag('precompile'), dryRun: isDryRun, - analytics: isDryRun ? null : analytics, ); var example = entrypoint.example; @@ -104,7 +103,6 @@ SolveType.get, precompile: argResults.flag('precompile'), summaryOnly: true, - analytics: analytics, ); } }
diff --git a/lib/src/command/upgrade.dart b/lib/src/command/upgrade.dart index 12ad889..5e77a16 100644 --- a/lib/src/command/upgrade.dart +++ b/lib/src/command/upgrade.dart
@@ -169,7 +169,6 @@ dryRun: _dryRun, precompile: _precompile, summaryOnly: onlySummary, - analytics: analytics, ); _showOfflineWarning(); @@ -360,7 +359,6 @@ solveType, dryRun: _dryRun, precompile: !_dryRun && _precompile, - analytics: _dryRun ? null : analytics, // No analytics for dry-run ); _outputChangeSummary(changes);
diff --git a/lib/src/entrypoint.dart b/lib/src/entrypoint.dart index f68f877..1594554 100644 --- a/lib/src/entrypoint.dart +++ b/lib/src/entrypoint.dart
@@ -27,7 +27,6 @@ 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'; @@ -309,9 +308,6 @@ /// 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 @@ -333,7 +329,6 @@ Iterable<String>? unlock, bool dryRun = false, bool precompile = false, - required PubAnalytics? analytics, bool summaryOnly = false, bool enforceLockfile = false, }) async { @@ -408,10 +403,6 @@ _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)); @@ -612,7 +603,6 @@ /// output if no terminal is attached. Future<void> ensureUpToDate({ bool checkForSdkUpdate = false, - PubAnalytics? analytics, bool summaryOnly = true, bool onlyOutputWhenTerminal = true, }) async { @@ -621,14 +611,12 @@ await log.errorsOnlyUnlessTerminal(() async { await acquireDependencies( SolveType.get, - analytics: analytics, summaryOnly: summaryOnly, ); }); } else { await acquireDependencies( SolveType.get, - analytics: analytics, summaryOnly: summaryOnly, ); }
diff --git a/lib/src/executable.dart b/lib/src/executable.dart index c17ea57..c9cf05d 100644 --- a/lib/src/executable.dart +++ b/lib/src/executable.dart
@@ -16,7 +16,6 @@ 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'; @@ -241,8 +240,6 @@ /// * 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>]`. /// @@ -281,7 +278,6 @@ bool allowSnapshot = true, String? root, String? pubCacheDir, - PubAnalytics? analytics, List<String> additionalSources = const [], String? nativeAssets, }) async {
diff --git a/lib/src/global_packages.dart b/lib/src/global_packages.dart index c68c6b0..d216133 100644 --- a/lib/src/global_packages.dart +++ b/lib/src/global_packages.dart
@@ -17,7 +17,6 @@ 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'; @@ -165,15 +164,11 @@ 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); @@ -586,7 +581,6 @@ entrypoint.rootDir, packageExecutables, overwriteBinStubs: true, - analytics: null, ); } successes.add(id.name);
diff --git a/lib/src/pub_embeddable_command.dart b/lib/src/pub_embeddable_command.dart index 3454f58..d217304 100644 --- a/lib/src/pub_embeddable_command.dart +++ b/lib/src/pub_embeddable_command.dart
@@ -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'; @@ -25,15 +23,6 @@ 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 { @@ -51,12 +40,9 @@ @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);
diff --git a/lib/src/solver/result.dart b/lib/src/solver/result.dart index 5de0d00..88e96cb 100644 --- a/lib/src/solver/result.dart +++ b/lib/src/solver/result.dart
@@ -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. @@ -136,42 +131,6 @@ 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- ")}';
diff --git a/pubspec.yaml b/pubspec.yaml index 8634229..14df0c2 100644 --- a/pubspec.yaml +++ b/pubspec.yaml
@@ -25,7 +25,6 @@ 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