/
verify-npm-registry.js
34 lines (27 loc) · 1.06 KB
/
verify-npm-registry.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
"use strict";
const log = require("npmlog");
const childProcess = require("@lerna/child-process");
const getExecOpts = require("@lerna/get-npm-exec-opts");
const ValidationError = require("@lerna/validation-error");
module.exports = verifyNpmRegistry;
function verifyNpmRegistry(location, { registry }) {
log.silly("verifyNpmRegistry");
const args = [
"ping",
// immediate feedback from request errors, not excruciatingly slow retries
// @see https://docs.npmjs.com/misc/config#fetch-retries
"--fetch-retries=0",
// including http requests makes raw logging easier to debug for end users
"--loglevel=http",
];
const opts = getExecOpts({ location }, registry);
// we do not need special log handling
delete opts.pkg;
return childProcess.exec("npm", args, opts).catch(({ stderr }) => {
// Log the error cleanly to stderr, it already has npmlog decorations
log.pause();
console.error(stderr); // eslint-disable-line no-console
log.resume();
throw new ValidationError("EREGISTRY", "Connection to npm registry failed");
});
}