mirror of
https://github.com/meteor/meteor.git
synced 2026-05-02 03:01:46 -04:00
Merge branch 'package-stats-opt-out' into packaging
This commit is contained in:
1
packages/package-stats-opt-out/.gitignore
vendored
Normal file
1
packages/package-stats-opt-out/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
.build*
|
||||
9
packages/package-stats-opt-out/package.js
Normal file
9
packages/package-stats-opt-out/package.js
Normal file
@@ -0,0 +1,9 @@
|
||||
Package.describe({
|
||||
summary: "Opt out of sending package stats",
|
||||
version: '1.0.0'
|
||||
});
|
||||
|
||||
Package.on_use(function (api) {
|
||||
// Empty. This package's presence tells the meteor tool to stop
|
||||
// sending package stats.
|
||||
});
|
||||
@@ -7,6 +7,10 @@ var project = require("./project.js");
|
||||
var auth = require("./auth.js");
|
||||
var ServiceConnection = require("./service-connection.js");
|
||||
|
||||
// The name of the package that you add to your app to opt out of
|
||||
// sending stats.
|
||||
var optOutPackageName = "package-stats-opt-out";
|
||||
|
||||
// Return a list of packages used by this app, both directly and
|
||||
// indirectly. Formatted as a list of objects with 'name', 'version'
|
||||
// and 'direct', which is how the `recordAppPackages` method on the
|
||||
@@ -27,6 +31,13 @@ var packageList = function (appDir) {
|
||||
};
|
||||
|
||||
var recordPackages = function (appDir) {
|
||||
// Before doing anything, look at the app's dependencies to see if the
|
||||
// opt-out package is there; if present, we don't record any stats.
|
||||
var packages = packageList(appDir);
|
||||
if (_.contains(_.pluck(packages, "name"), optOutPackageName)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// We do this inside a new fiber to avoid blocking anything on talking
|
||||
// to the package stats server. If we can't connect, for example, we
|
||||
// don't care; we'll just miss out on recording these packages.
|
||||
@@ -50,7 +61,7 @@ var recordPackages = function (appDir) {
|
||||
|
||||
conn.call("recordAppPackages",
|
||||
project.getAppIdentifier(appDir),
|
||||
packageList(appDir));
|
||||
packages);
|
||||
} catch (err) {
|
||||
// Do nothing. A failure to record package stats shouldn't be
|
||||
// visible to the end user and shouldn't affect whatever command
|
||||
|
||||
@@ -9,7 +9,7 @@ process.env.METEOR_PACKAGE_STATS_SERVER_URL = testStatsServer;
|
||||
// NOTE: This test will fail if your machine's time is skewed by more
|
||||
// than 30 minutes. This is because the `fetchAppPackageUsage` method
|
||||
// works by passing an hour time range.
|
||||
selftest.define("report-stats", function () {
|
||||
selftest.define("report-stats", ["slow"], function () {
|
||||
var s = new Sandbox;
|
||||
|
||||
var run = s.run("create", "foo");
|
||||
@@ -46,8 +46,23 @@ selftest.define("report-stats", function () {
|
||||
appPackages = stats.getPackagesForAppIdInTest(s.cwd);
|
||||
selftest.expectEqual(appPackages.userId, testUtils.getUserId(s));
|
||||
|
||||
// TODO:
|
||||
// - opt out
|
||||
// Add the opt-out package, verify that no stats are recorded for the
|
||||
// app.
|
||||
run = s.run("add", "package-stats-opt-out");
|
||||
run.waitSecs(15);
|
||||
run.expectExit(0);
|
||||
bundleWithFreshIdentifier(s);
|
||||
appPackages = stats.getPackagesForAppIdInTest(s.cwd);
|
||||
selftest.expectEqual(appPackages, undefined);
|
||||
|
||||
// Remove the opt-out package, verify that stats get sent again.
|
||||
run = s.run("remove", "package-stats-opt-out");
|
||||
run.waitSecs(15);
|
||||
run.expectExit(0);
|
||||
bundle(s);
|
||||
appPackages = stats.getPackagesForAppIdInTest(s.cwd);
|
||||
selftest.expectEqual(appPackages.userId, testUtils.getUserId(s));
|
||||
selftest.expectEqual(appPackages.packages, stats.packageList(s.cwd));
|
||||
});
|
||||
|
||||
// Bundle the app in the current working directory after deleting its
|
||||
@@ -55,6 +70,12 @@ selftest.define("report-stats", function () {
|
||||
// @param s {Sandbox}
|
||||
var bundleWithFreshIdentifier = function (s) {
|
||||
s.unlink(".meteor/identifier");
|
||||
bundle(s);
|
||||
};
|
||||
|
||||
// Bundle the app in the current working directory.
|
||||
// @param s {Sandbox}
|
||||
var bundle = function (s) {
|
||||
var run = s.run("bundle", "foo.tar.gz");
|
||||
run.waitSecs(30);
|
||||
run.expectExit(0);
|
||||
|
||||
Reference in New Issue
Block a user