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

View File

@ -896,6 +896,16 @@
"qs": "6.5.2", "qs": "6.5.2",
"raw-body": "2.3.3", "raw-body": "2.3.3",
"type-is": "~1.6.16" "type-is": "~1.6.16"
},
"dependencies": {
"debug": {
"version": "2.6.9",
"resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz",
"integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==",
"requires": {
"ms": "2.0.0"
}
}
} }
}, },
"boolbase": { "boolbase": {
@ -1338,14 +1348,6 @@
"resolved": "https://registry.npmjs.org/date-fns/-/date-fns-1.30.1.tgz", "resolved": "https://registry.npmjs.org/date-fns/-/date-fns-1.30.1.tgz",
"integrity": "sha512-hBSVCvSmWC+QypYObzwGOd9wqdDpOt+0wl0KbU+R+uuZBS1jN8VsD1ss3irQDknRj5NvxiTF6oj/nDRnN/UQNw==" "integrity": "sha512-hBSVCvSmWC+QypYObzwGOd9wqdDpOt+0wl0KbU+R+uuZBS1jN8VsD1ss3irQDknRj5NvxiTF6oj/nDRnN/UQNw=="
}, },
"debug": {
"version": "2.6.9",
"resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz",
"integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==",
"requires": {
"ms": "2.0.0"
}
},
"decamelize": { "decamelize": {
"version": "1.2.0", "version": "1.2.0",
"resolved": "https://registry.npmjs.org/decamelize/-/decamelize-1.2.0.tgz", "resolved": "https://registry.npmjs.org/decamelize/-/decamelize-1.2.0.tgz",
@ -1653,6 +1655,14 @@
"to-regex": "^3.0.1" "to-regex": "^3.0.1"
}, },
"dependencies": { "dependencies": {
"debug": {
"version": "2.6.9",
"resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz",
"integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==",
"requires": {
"ms": "2.0.0"
}
},
"define-property": { "define-property": {
"version": "0.2.5", "version": "0.2.5",
"resolved": "https://registry.npmjs.org/define-property/-/define-property-0.2.5.tgz", "resolved": "https://registry.npmjs.org/define-property/-/define-property-0.2.5.tgz",
@ -1706,6 +1716,16 @@
"type-is": "~1.6.16", "type-is": "~1.6.16",
"utils-merge": "1.0.1", "utils-merge": "1.0.1",
"vary": "~1.1.2" "vary": "~1.1.2"
},
"dependencies": {
"debug": {
"version": "2.6.9",
"resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz",
"integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==",
"requires": {
"ms": "2.0.0"
}
}
} }
}, },
"extend": { "extend": {
@ -1860,6 +1880,16 @@
"parseurl": "~1.3.2", "parseurl": "~1.3.2",
"statuses": "~1.4.0", "statuses": "~1.4.0",
"unpipe": "~1.0.0" "unpipe": "~1.0.0"
},
"dependencies": {
"debug": {
"version": "2.6.9",
"resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz",
"integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==",
"requires": {
"ms": "2.0.0"
}
}
} }
}, },
"firebase-admin": { "firebase-admin": {
@ -3366,6 +3396,16 @@
"depd": "~1.1.2", "depd": "~1.1.2",
"on-finished": "~2.3.0", "on-finished": "~2.3.0",
"on-headers": "~1.0.1" "on-headers": "~1.0.1"
},
"dependencies": {
"debug": {
"version": "2.6.9",
"resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz",
"integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==",
"requires": {
"ms": "2.0.0"
}
}
} }
}, },
"ms": { "ms": {
@ -3975,6 +4015,14 @@
"statuses": "~1.4.0" "statuses": "~1.4.0"
}, },
"dependencies": { "dependencies": {
"debug": {
"version": "2.6.9",
"resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz",
"integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==",
"requires": {
"ms": "2.0.0"
}
},
"mime": { "mime": {
"version": "1.4.1", "version": "1.4.1",
"resolved": "https://registry.npmjs.org/mime/-/mime-1.4.1.tgz", "resolved": "https://registry.npmjs.org/mime/-/mime-1.4.1.tgz",
@ -4051,6 +4099,14 @@
"use": "^3.1.0" "use": "^3.1.0"
}, },
"dependencies": { "dependencies": {
"debug": {
"version": "2.6.9",
"resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz",
"integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==",
"requires": {
"ms": "2.0.0"
}
},
"define-property": { "define-property": {
"version": "0.2.5", "version": "0.2.5",
"resolved": "https://registry.npmjs.org/define-property/-/define-property-0.2.5.tgz", "resolved": "https://registry.npmjs.org/define-property/-/define-property-0.2.5.tgz",

View File

@ -3,9 +3,8 @@
"name": "functions", "name": "functions",
"description": "Cloud Functions for Firebase", "description": "Cloud Functions for Firebase",
"scripts": { "scripts": {
"serve": "firebase serve --only functions", "start": "firebase serve --only functions",
"shell": "firebase functions:shell", "shell": "firebase functions:shell",
"start": "npm run shell",
"deploy": "firebase deploy --only functions", "deploy": "firebase deploy --only functions",
"logs": "firebase functions:log" "logs": "firebase functions:log"
}, },

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

View File

@ -3,6 +3,7 @@ import https from 'https';
import { npmRegistryURL } from '../config'; import { npmRegistryURL } from '../config';
import debug from './debug';
import bufferStream from './bufferStream'; import bufferStream from './bufferStream';
import agent from './registryAgent'; import agent from './registryAgent';
@ -19,7 +20,7 @@ export default function fetchNpmPackageInfo(packageName) {
const infoURL = `${npmRegistryURL}/${encodedPackageName}`; 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 { hostname, pathname } = url.parse(infoURL);
const options = { const options = {

View File

@ -108,13 +108,17 @@ const functions = [
emitFiles: false emitFiles: false
}), }),
replace({ replace({
'process.env.NODE_ENV': JSON.stringify(env),
'process.env.CLOUDFLARE_EMAIL': JSON.stringify( 'process.env.CLOUDFLARE_EMAIL': JSON.stringify(
process.env.CLOUDFLARE_EMAIL process.env.CLOUDFLARE_EMAIL
), ),
'process.env.CLOUDFLARE_KEY': JSON.stringify( 'process.env.CLOUDFLARE_KEY': JSON.stringify(
process.env.CLOUDFLARE_KEY process.env.CLOUDFLARE_KEY
), ),
'process.env.DEBUG': JSON.stringify(process.env.DEBUG),
'process.env.NODE_ENV': JSON.stringify(env),
'process.env.NPM_REGISTRY_URL': JSON.stringify(
process.env.NPM_REGISTRY_URL
),
'process.env.ORIGIN': JSON.stringify(process.env.ORIGIN), 'process.env.ORIGIN': JSON.stringify(process.env.ORIGIN),
'process.env.SECRET_KEY': JSON.stringify(secretKey) 'process.env.SECRET_KEY': JSON.stringify(secretKey)
}) })