Hide verbose logs behind debug flag

This commit is contained in:
Michael Jackson
2019-01-15 16:43:52 -08:00
parent a33a7c3ff5
commit 949c40f11e
6 changed files with 76 additions and 17 deletions

2
modules/utils/debug.js Normal file
View File

@ -0,0 +1,2 @@
const debug = process.env.DEBUG ? console.log.bind(console) : () => {};
export default debug;

View File

@ -3,6 +3,7 @@ import https from 'https';
import gunzip from 'gunzip-maybe';
import tar from 'tar-stream';
import debug from './debug';
import bufferStream from './bufferStream';
import agent from './registryAgent';
@ -10,11 +11,7 @@ export default function fetchNpmPackage(packageConfig) {
return new Promise((resolve, reject) => {
const tarballURL = packageConfig.dist.tarball;
console.log(
'Fetching package for %s from %s',
packageConfig.name,
tarballURL
);
debug('Fetching package for %s from %s', packageConfig.name, tarballURL);
const { hostname, pathname } = url.parse(tarballURL);
const options = {

View File

@ -3,6 +3,7 @@ import https from 'https';
import { npmRegistryURL } from '../config';
import debug from './debug';
import bufferStream from './bufferStream';
import agent from './registryAgent';
@ -19,7 +20,7 @@ export default function fetchNpmPackageInfo(packageName) {
const infoURL = `${npmRegistryURL}/${encodedPackageName}`;
console.log('Fetching package info for %s from %s', packageName, infoURL);
debug('Fetching package info for %s from %s', packageName, infoURL);
const { hostname, pathname } = url.parse(infoURL);
const options = {