Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--docs/content/using-npm/config.md17
-rw-r--r--lib/npm.js3
-rw-r--r--lib/utils/config.js4
-rw-r--r--lib/utils/error-handler.js4
-rw-r--r--lib/utils/flat-options.js2
-rw-r--r--lib/utils/metrics-launch.js43
-rw-r--r--lib/utils/metrics.js80
-rw-r--r--tap-snapshots/test-lib-utils-config.js-TAP.test.js21
-rw-r--r--tap-snapshots/test-lib-utils-flat-options.js-TAP.test.js2
-rw-r--r--test/lib/npm.js7
-rw-r--r--test/lib/utils/error-handler.js5
-rw-r--r--test/lib/utils/flat-options.js5
12 files changed, 0 insertions, 193 deletions
diff --git a/docs/content/using-npm/config.md b/docs/content/using-npm/config.md
index 71102d2e2..2d9a4f869 100644
--- a/docs/content/using-npm/config.md
+++ b/docs/content/using-npm/config.md
@@ -744,13 +744,6 @@ Commit message which is used by `npm version` when creating version commit.
Any "%s" in the message will be replaced with the version number.
-#### metrics-registry
-
-* Default: The value of `registry` (which defaults to "https://registry.npmjs.org/")
-* Type: String
-
-The registry you want to send cli metrics to if `send-metrics` is true.
-
#### node-options
* Default: null
@@ -1089,16 +1082,6 @@ searches.
The age of the cache, in seconds, before another registry request is made if
using legacy search endpoint.
-#### send-metrics
-
-* Default: false
-* Type: Boolean
-
-If true, success/failure metrics will be reported to the registry stored in
-`metrics-registry`. These requests contain the number of successful and
-failing runs of the npm CLI and the time period over which those counts were
-gathered. No identifying information is included in these requests.
-
#### shell
* Default: SHELL environment variable, or "bash" on Posix, or "cmd" on
diff --git a/lib/npm.js b/lib/npm.js
index 876432e5b..7a15a29b2 100644
--- a/lib/npm.js
+++ b/lib/npm.js
@@ -207,8 +207,6 @@ const npm = module.exports = new class extends EventEmitter {
this.projectScope = this.config.get('scope') ||
getProjectScope(this.prefix)
-
- startMetrics()
}
get flatOptions () {
@@ -297,7 +295,6 @@ const npm = module.exports = new class extends EventEmitter {
const log = require('npmlog')
const { promisify } = require('util')
-const startMetrics = require('./utils/metrics.js').start
const which = promisify(require('which'))
diff --git a/lib/utils/config.js b/lib/utils/config.js
index 6abb502e2..2b6b96e5c 100644
--- a/lib/utils/config.js
+++ b/lib/utils/config.js
@@ -120,7 +120,6 @@ const defaults = {
long: false,
maxsockets: 50,
message: '%s',
- 'metrics-registry': null,
'node-options': null,
'node-version': process.version,
noproxy: null,
@@ -159,7 +158,6 @@ const defaults = {
searchlimit: 20,
searchopts: '',
searchstaleness: 15 * 60,
- 'send-metrics': false,
shell,
shrinkwrap: true,
'sign-git-commit': false,
@@ -273,7 +271,6 @@ const types = {
long: Boolean,
maxsockets: Number,
message: String,
- 'metrics-registry': [null, String],
'node-options': [null, String],
'node-version': [null, semver],
noproxy: [null, String, Array],
@@ -312,7 +309,6 @@ const types = {
searchlimit: Number,
searchopts: String,
searchstaleness: Number,
- 'send-metrics': Boolean,
shell: String,
shrinkwrap: Boolean,
'sign-git-commit': Boolean,
diff --git a/lib/utils/error-handler.js b/lib/utils/error-handler.js
index cb339523d..f9685c91d 100644
--- a/lib/utils/error-handler.js
+++ b/lib/utils/error-handler.js
@@ -7,7 +7,6 @@ let wroteLogFile = false
let exitCode = 0
const errorMessage = require('./error-message.js')
const replaceInfo = require('./replace-info.js')
-const stopMetrics = require('./metrics.js').stop
const cacheFile = require('./cache-file.js')
@@ -43,9 +42,6 @@ process.on('exit', code => {
}
}
- // kill any outstanding stats reporter if it hasn't finished yet
- stopMetrics()
-
if (code)
itWorked = false
if (itWorked)
diff --git a/lib/utils/flat-options.js b/lib/utils/flat-options.js
index 71edca071..828481930 100644
--- a/lib/utils/flat-options.js
+++ b/lib/utils/flat-options.js
@@ -50,8 +50,6 @@ const flatten = obj => ({
cache: join(obj.cache, '_cacache'),
global: obj.global,
- metricsRegistry: obj['metrics-registry'] || obj.registry,
- sendMetrics: obj['send-metrics'],
registry: obj.registry,
scope: obj.scope,
access: obj.access,
diff --git a/lib/utils/metrics-launch.js b/lib/utils/metrics-launch.js
deleted file mode 100644
index 4a3dcde1a..000000000
--- a/lib/utils/metrics-launch.js
+++ /dev/null
@@ -1,43 +0,0 @@
-/* eslint-disable camelcase */
-module.exports = launchSendMetrics
-var fs = require('graceful-fs')
-var child_process = require('child_process')
-
-if (require.main === module)
- main()
-
-function launchSendMetrics () {
- var path = require('path')
- var npm = require('../npm.js')
- try {
- if (!npm.config.get('send-metrics'))
- return
- var cliMetrics = path.join(npm.config.get('cache'), 'anonymous-cli-metrics.json')
- var targetRegistry = npm.config.get('metrics-registry')
- fs.statSync(cliMetrics)
- return runInBackground(__filename, [cliMetrics, targetRegistry])
- } catch (ex) {
- // if the metrics file doesn't exist, don't run
- }
-}
-
-function runInBackground (js, args, opts) {
- if (!args)
- args = []
- args.unshift(js)
- if (!opts)
- opts = {}
- opts.stdio = 'ignore'
- opts.detached = true
- var child = child_process.spawn(process.execPath, args, opts)
- child.unref()
- return child
-}
-
-function main () {
- var sendMetrics = require('./metrics.js').send
- var metricsFile = process.argv[2]
- var metricsRegistry = process.argv[3]
-
- sendMetrics(metricsFile, metricsRegistry)
-}
diff --git a/lib/utils/metrics.js b/lib/utils/metrics.js
deleted file mode 100644
index 432f8dc70..000000000
--- a/lib/utils/metrics.js
+++ /dev/null
@@ -1,80 +0,0 @@
-exports.start = startMetrics
-exports.stop = stopMetrics
-exports.save = saveMetrics
-exports.send = sendMetrics
-
-const fs = require('fs')
-const path = require('path')
-const npm = require('../npm.js')
-const regFetch = require('npm-registry-fetch')
-const { v4: uuidv4 } = require('uuid')
-const cacheFile = require('./cache-file.js')
-
-let inMetrics = false
-
-function startMetrics () {
- if (inMetrics)
- return
- // loaded on demand to avoid any recursive deps when `./metrics-launch` requires us.
- var metricsLaunch = require('./metrics-launch.js')
- npm.metricsProcess = metricsLaunch()
-}
-
-function stopMetrics () {
- if (inMetrics)
- return
- if (npm.metricsProcess)
- npm.metricsProcess.kill('SIGKILL')
-}
-
-function saveMetrics (itWorked) {
- if (inMetrics)
- return
- // If the metrics reporter hasn't managed to PUT yet then kill it so that it doesn't
- // step on our updating the anonymous-cli-metrics json
- stopMetrics()
- var metricsFile = path.join(npm.config.get('cache'), 'anonymous-cli-metrics.json')
- var metrics
- try {
- metrics = JSON.parse(fs.readFileSync(metricsFile))
- metrics.metrics.to = new Date().toISOString()
- if (itWorked)
- ++metrics.metrics.successfulInstalls
- else
- ++metrics.metrics.failedInstalls
- } catch (ex) {
- metrics = {
- metricId: uuidv4(),
- metrics: {
- from: new Date().toISOString(),
- to: new Date().toISOString(),
- successfulInstalls: itWorked ? 1 : 0,
- failedInstalls: itWorked ? 0 : 1,
- },
- }
- }
- try {
- cacheFile.write(metricsFile, JSON.stringify(metrics))
- } catch (ex) {
- // we couldn't write and/or chown the error metrics file, oh well.
- }
-}
-
-function sendMetrics (metricsFile, metricsRegistry) {
- inMetrics = true
- var cliMetrics = JSON.parse(fs.readFileSync(metricsFile))
- regFetch(
- `/-/npm/anon-metrics/v1/${encodeURIComponent(cliMetrics.metricId)}`,
- // NOTE: skip npmConfig() to prevent auth
- {
- registry: metricsRegistry,
- method: 'PUT',
- body: cliMetrics.metrics,
- retry: false,
- }
- ).then(() => {
- fs.unlinkSync(metricsFile)
- }, err => {
- cacheFile.write(path.join(path.dirname(metricsFile), 'last-send-metrics-error.txt'), err.stack)
- })
-}
diff --git a/tap-snapshots/test-lib-utils-config.js-TAP.test.js b/tap-snapshots/test-lib-utils-config.js-TAP.test.js
index 3bdf905d8..d14c9e950 100644
--- a/tap-snapshots/test-lib-utils-config.js-TAP.test.js
+++ b/tap-snapshots/test-lib-utils-config.js-TAP.test.js
@@ -82,7 +82,6 @@ Object {
"long": false,
"maxsockets": 50,
"message": "%s",
- "metrics-registry": null,
"node-options": null,
"node-version": "v14.8.0",
"noproxy": null,
@@ -120,7 +119,6 @@ Object {
"searchlimit": 20,
"searchopts": "",
"searchstaleness": 900,
- "send-metrics": false,
"shell": "cmd.exe",
"shrinkwrap": true,
"sign-git-commit": false,
@@ -423,10 +421,6 @@ Object {
"long": "{Boolean TYPE}",
"maxsockets": "{Number TYPE}",
"message": "{String TYPE}",
- "metrics-registry": Array [
- null,
- "{String TYPE}",
- ],
"node-options": Array [
null,
"{String TYPE}",
@@ -509,7 +503,6 @@ Object {
"searchlimit": "{Number TYPE}",
"searchopts": "{String TYPE}",
"searchstaleness": "{Number TYPE}",
- "send-metrics": "{Boolean TYPE}",
"shell": "{String TYPE}",
"shrinkwrap": "{Boolean TYPE}",
"sign-git-commit": "{Boolean TYPE}",
@@ -616,7 +609,6 @@ Object {
"long": false,
"maxsockets": 50,
"message": "%s",
- "metrics-registry": null,
"node-options": null,
"node-version": "v14.8.0",
"noproxy": null,
@@ -654,7 +646,6 @@ Object {
"searchlimit": 20,
"searchopts": "",
"searchstaleness": 900,
- "send-metrics": false,
"shell": "cmd.exe",
"shrinkwrap": true,
"sign-git-commit": false,
@@ -957,10 +948,6 @@ Object {
"long": "{Boolean TYPE}",
"maxsockets": "{Number TYPE}",
"message": "{String TYPE}",
- "metrics-registry": Array [
- null,
- "{String TYPE}",
- ],
"node-options": Array [
null,
"{String TYPE}",
@@ -1043,7 +1030,6 @@ Object {
"searchlimit": "{Number TYPE}",
"searchopts": "{String TYPE}",
"searchstaleness": "{Number TYPE}",
- "send-metrics": "{Boolean TYPE}",
"shell": "{String TYPE}",
"shrinkwrap": "{Boolean TYPE}",
"sign-git-commit": "{Boolean TYPE}",
@@ -1150,7 +1136,6 @@ Object {
"long": false,
"maxsockets": 50,
"message": "%s",
- "metrics-registry": null,
"node-options": null,
"node-version": "v14.8.0",
"noproxy": null,
@@ -1188,7 +1173,6 @@ Object {
"searchlimit": 20,
"searchopts": "",
"searchstaleness": 900,
- "send-metrics": false,
"shell": "/usr/local/bin/bash",
"shrinkwrap": true,
"sign-git-commit": false,
@@ -1493,10 +1477,6 @@ Object {
"long": "{Boolean TYPE}",
"maxsockets": "{Number TYPE}",
"message": "{String TYPE}",
- "metrics-registry": Array [
- null,
- "{String TYPE}",
- ],
"node-options": Array [
null,
"{String TYPE}",
@@ -1579,7 +1559,6 @@ Object {
"searchlimit": "{Number TYPE}",
"searchopts": "{String TYPE}",
"searchstaleness": "{Number TYPE}",
- "send-metrics": "{Boolean TYPE}",
"shell": "{String TYPE}",
"shrinkwrap": "{Boolean TYPE}",
"sign-git-commit": "{Boolean TYPE}",
diff --git a/tap-snapshots/test-lib-utils-flat-options.js-TAP.test.js b/tap-snapshots/test-lib-utils-flat-options.js-TAP.test.js
index ae85195d7..36f767124 100644
--- a/tap-snapshots/test-lib-utils-flat-options.js-TAP.test.js
+++ b/tap-snapshots/test-lib-utils-flat-options.js-TAP.test.js
@@ -54,7 +54,6 @@ Object {
"log": Object {},
"long": undefined,
"message": "message",
- "metricsRegistry": "metrics-registry",
"nodeBin": "/path/to/some/node",
"nodeVersion": "1.2.3",
"noProxy": "noproxy",
@@ -100,7 +99,6 @@ Object {
},
"staleness": "searchstaleness",
},
- "sendMetrics": "send-metrics",
"shell": undefined,
"signGitCommit": "sign-git-commit",
"signGitTag": "sign-git-tag",
diff --git a/test/lib/npm.js b/test/lib/npm.js
index dac9696ca..8494af6bb 100644
--- a/test/lib/npm.js
+++ b/test/lib/npm.js
@@ -202,8 +202,6 @@ t.test('npm.load', t => {
t.equal(npm.bin, npm.globalBin, 'bin is global bin after prefix setter')
t.notEqual(npm.bin, npm.localBin, 'bin is not local bin after prefix setter')
- t.equal(npm.config.get('metrics-registry'), npm.config.get('registry'))
-
beWindows()
t.equal(npm.bin, npm.globalBin, 'bin is global bin in windows mode')
t.equal(npm.dir, npm.globalDir, 'dir is global dir in windows mode')
@@ -261,7 +259,6 @@ t.test('npm.load', t => {
process.argv = [
node,
process.argv[1],
- '--metrics-registry', 'http://example.com',
'--prefix', dir,
'--userconfig', `${dir}/.npmrc`,
'--usage',
@@ -292,7 +289,6 @@ t.test('npm.load', t => {
throw er
t.equal(npm.config.get('scope'), '@foo', 'added the @ sign to scope')
- t.equal(npm.config.get('metrics-registry'), 'http://example.com')
t.match(logs.filter(l => l[0] !== 'timing' || !/^config:/.test(l[1])), [
[
'verbose',
@@ -396,7 +392,6 @@ t.test('set process.title', t => {
argv: [
process.execPath,
process.argv[1],
- '--metrics-registry', 'http://example.com',
'--usage',
'--scope=foo',
'ls',
@@ -415,7 +410,6 @@ t.test('set process.title', t => {
argv: [
process.execPath,
process.argv[1],
- '--metrics-registry', 'http://example.com',
'--usage',
'--scope=foo',
'token',
@@ -436,7 +430,6 @@ t.test('set process.title', t => {
argv: [
process.execPath,
process.argv[1],
- '--metrics-registry', 'http://example.com',
'--usage',
'--scope=foo',
'token',
diff --git a/test/lib/utils/error-handler.js b/test/lib/utils/error-handler.js
index 2dc116a4d..0b896fee4 100644
--- a/test/lib/utils/error-handler.js
+++ b/test/lib/utils/error-handler.js
@@ -78,10 +78,6 @@ const npmlog = {
},
}
-const metrics = {
- stop: () => null,
-}
-
// overrides OS type/release for cross platform snapshots
const os = require('os')
os.type = () => 'Foo'
@@ -124,7 +120,6 @@ const mocks = {
summary: [['ERR', err.message]],
detail: [['ERR', err.message]],
}),
- '../../../lib/utils/metrics.js': metrics,
'../../../lib/utils/cache-file.js': cacheFile,
}
diff --git a/test/lib/utils/flat-options.js b/test/lib/utils/flat-options.js
index ee7620fa7..6f580fabc 100644
--- a/test/lib/utils/flat-options.js
+++ b/test/lib/utils/flat-options.js
@@ -34,8 +34,6 @@ class MockConfig {
cache: 'cache',
'node-version': '1.2.3',
global: 'global',
- 'metrics-registry': 'metrics-registry',
- 'send-metrics': 'send-metrics',
registry: 'registry',
access: 'access',
'always-auth': 'always-auth',
@@ -299,15 +297,12 @@ t.test('various default values and falsey fallbacks', t => {
const npm = new Mocknpm({
'script-shell': false,
registry: 'http://example.com',
- 'metrics-registry': null,
searchlimit: 0,
'save-exact': false,
'save-prefix': '>=',
})
const opts = flatOptions(npm)
t.equal(opts.scriptShell, undefined, 'scriptShell is undefined if falsey')
- t.equal(opts.metricsRegistry, 'http://example.com',
- 'metricsRegistry defaults to registry')
t.equal(opts.search.limit, 20, 'searchLimit defaults to 20')
t.equal(opts.savePrefix, '>=', 'save-prefix respected if no save-exact')
t.equal(opts.scope, '', 'scope defaults to empty string')