Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 846ddcc

Browse filesBrowse files
committed
anon-metrics: stop using npm-registry-client
1 parent 45aff0e commit 846ddcc
Copy full SHA for 846ddcc

File tree

Expand file treeCollapse file tree

1 file changed

+19
-15
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+19
-15
lines changed

‎lib/utils/metrics.js

Copy file name to clipboardExpand all lines: lib/utils/metrics.js
+19-15Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@ exports.stop = stopMetrics
44
exports.save = saveMetrics
55
exports.send = sendMetrics
66

7-
var fs = require('fs')
8-
var path = require('path')
9-
var npm = require('../npm.js')
10-
var uuid = require('uuid')
7+
const fs = require('fs')
8+
const path = require('path')
9+
const npm = require('../npm.js')
10+
const regFetch = require('libnpm/fetch')
11+
const uuid = require('uuid')
1112

12-
var inMetrics = false
13+
let inMetrics = false
1314

1415
function startMetrics () {
1516
if (inMetrics) return
@@ -59,15 +60,18 @@ function saveMetrics (itWorked) {
5960
function sendMetrics (metricsFile, metricsRegistry) {
6061
inMetrics = true
6162
var cliMetrics = JSON.parse(fs.readFileSync(metricsFile))
62-
npm.load({}, function (err) {
63-
if (err) return
64-
npm.registry.config.retry.retries = 0
65-
npm.registry.sendAnonymousCLIMetrics(metricsRegistry, cliMetrics, function (err) {
66-
if (err) {
67-
fs.writeFileSync(path.join(path.dirname(metricsFile), 'last-send-metrics-error.txt'), err.stack)
68-
} else {
69-
fs.unlinkSync(metricsFile)
70-
}
71-
})
63+
regFetch(
64+
`/-/npm/anon-metrics/v1/${encodeURIComponent(cliMetrics.metricId)}`,
65+
// NOTE: skip npmConfig() to prevent auth
66+
{
67+
registry: metricsRegistry,
68+
method: 'PUT',
69+
body: cliMetrics.metrics,
70+
retry: false
71+
}
72+
).then(() => {
73+
fs.unlinkSync(metricsFile)
74+
}, err => {
75+
fs.writeFileSync(path.join(path.dirname(metricsFile), 'last-send-metrics-error.txt'), err.stack)
7276
})
7377
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.