cchubber 0.4.0 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/cli/index.js +3 -2
- package/src/telemetry.js +23 -18
package/package.json
CHANGED
package/src/cli/index.js
CHANGED
|
@@ -164,8 +164,9 @@ async function main() {
|
|
|
164
164
|
|
|
165
165
|
// Anonymous telemetry (opt out: --no-telemetry or CC_HUBBER_TELEMETRY=0)
|
|
166
166
|
if (shouldSendTelemetry(flags)) {
|
|
167
|
-
|
|
168
|
-
|
|
167
|
+
console.log(' ○ Sharing anonymous stats...');
|
|
168
|
+
await sendTelemetry(report);
|
|
169
|
+
console.log(' ✓ Stats shared (opt out: --no-telemetry)');
|
|
169
170
|
}
|
|
170
171
|
|
|
171
172
|
const outputPath = flags.output || join(process.cwd(), 'cchubber-report.html');
|
package/src/telemetry.js
CHANGED
|
@@ -136,24 +136,29 @@ export function sendTelemetry(report) {
|
|
|
136
136
|
...gatherEnvironmentData(),
|
|
137
137
|
};
|
|
138
138
|
|
|
139
|
-
//
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
139
|
+
// Returns a promise that resolves when the request completes (or times out)
|
|
140
|
+
// CLI must await this before exiting, otherwise the process kills the request
|
|
141
|
+
return new Promise((resolve) => {
|
|
142
|
+
try {
|
|
143
|
+
const data = JSON.stringify(payload);
|
|
144
|
+
const url = new URL(TELEMETRY_URL);
|
|
145
|
+
const req = https.request({
|
|
146
|
+
hostname: url.hostname,
|
|
147
|
+
path: url.pathname,
|
|
148
|
+
method: 'POST',
|
|
149
|
+
headers: { 'Content-Type': 'application/json', 'Content-Length': Buffer.byteLength(data) },
|
|
150
|
+
}, (res) => {
|
|
151
|
+
res.resume(); // drain response
|
|
152
|
+
res.on('end', () => { markTelemetrySent(); resolve(); });
|
|
153
|
+
});
|
|
154
|
+
req.on('error', () => resolve()); // silent fail, still resolve
|
|
155
|
+
req.setTimeout(4000, () => { req.destroy(); resolve(); });
|
|
156
|
+
req.write(data);
|
|
157
|
+
req.end();
|
|
158
|
+
} catch {
|
|
159
|
+
resolve(); // never block on telemetry failure
|
|
160
|
+
}
|
|
161
|
+
});
|
|
157
162
|
}
|
|
158
163
|
|
|
159
164
|
function costBucket(cost) {
|