-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
400457b
commit 002650b
Showing
18 changed files
with
369 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import { existsSync } from 'fs'; | ||
import { join as joinPath } from 'path'; | ||
import { inquirer, Configstore } from './shim-modules'; | ||
const log = require('../lighthouse-core/lib/log'); | ||
|
||
const MAXIMUM_WAIT_TIME = 20 * 1000; | ||
|
||
const MESSAGE = [ | ||
'Lighthouse would like to report back any errors that might occur while auditing. \n ', | ||
'Information such as the URL you are auditing, its subresources, your operating system, Chrome, ', | ||
'and Lighthouse versions may be recorded. Would you be willing to have Lighthouse automatically ', | ||
'report this information to the team to aid in improving the product?' | ||
].join(''); | ||
|
||
async function prompt() { | ||
if (!process.stdout.isTTY || process.env.CI) { | ||
// Default non-interactive sessions to false | ||
return false; | ||
} | ||
|
||
let timeout: NodeJS.Timer; | ||
|
||
const prompt = inquirer.prompt([ | ||
{ type: 'confirm', name: 'isErrorReportingEnabled', default: false, message: MESSAGE }, | ||
]); | ||
|
||
const timeoutPromise = new Promise((resolve: (a: boolean) => {}) => { | ||
timeout = setTimeout(() => { | ||
prompt.ui.close(); | ||
process.stdout.write('\n'); | ||
log.warn('CLI', 'No response to error logging preference, errors will not be reported.'); | ||
resolve(false); | ||
}, MAXIMUM_WAIT_TIME); | ||
}); | ||
|
||
return Promise.race([ | ||
prompt.then((result: { isErrorReportingEnabled: boolean}) => { | ||
clearTimeout(timeout); | ||
return result.isErrorReportingEnabled; | ||
}), | ||
timeoutPromise, | ||
]); | ||
} | ||
|
||
export async function askPermission() { | ||
const configstore = new Configstore('lighthouse'); | ||
let isErrorReportingEnabled = configstore.get('isErrorReportingEnabled'); | ||
if (typeof isErrorReportingEnabled === 'boolean') { | ||
return isErrorReportingEnabled; | ||
} | ||
|
||
isErrorReportingEnabled = await prompt(); | ||
configstore.set('isErrorReportingEnabled', isErrorReportingEnabled); | ||
return isErrorReportingEnabled; | ||
} | ||
|
||
export function isDev() { | ||
return existsSync(joinPath(__dirname, '../.git')); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
module.exports = function ExpectedError(error) { | ||
if (!(error instanceof Error)) { | ||
error = new Error(error); | ||
} | ||
|
||
error.expected = true; | ||
return error; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
const log = require('./log'); | ||
|
||
// Fix the polyfill. See https://github.com/GoogleChrome/lighthouse/issues/73 | ||
self.setImmediate = function (callback) { | ||
const args = [...arguments].slice(1); | ||
Promise.resolve().then(() => callback(...args)); | ||
return 0; | ||
}; | ||
|
||
const noop = () => undefined; | ||
const sentryDelegate = module.exports = { | ||
config() { | ||
return {install: noop}; | ||
}, | ||
context(data, functionToWrap) { | ||
if (typeof functionToWrap === 'undefined') { | ||
functionToWrap = data; | ||
} | ||
|
||
functionToWrap(); | ||
}, | ||
captureMessage: noop, | ||
captureException: noop, | ||
captureBreadcrumb: noop, | ||
setContext: noop, | ||
mergeContext: noop, | ||
init(useSentry, config) { | ||
if (!useSentry) { | ||
return; | ||
} | ||
|
||
config = Object.assign({}, config, { | ||
allowSecretKey: true, | ||
}); | ||
|
||
try { | ||
const Sentry = require('raven'); | ||
Sentry.config('https://a6bb0da87ee048cc9ae2a345fc09ab2e:63a7029f46f74265981b7e005e0f69f8@sentry.io/174697', config).install(); | ||
Object.keys(sentryDelegate).forEach(functionName => { | ||
if (functionName === 'init') { | ||
return; | ||
} | ||
|
||
sentryDelegate[functionName] = (...args) => Sentry[functionName](...args); | ||
sentryDelegate.captureException = (...args) => { | ||
if (args[0] && args[0].expected) return; | ||
Sentry.captureException(...args); | ||
} | ||
}); | ||
} catch (e) { | ||
log.warn('sentry', 'Could not load raven library, errors will not be reported.'); | ||
} | ||
} | ||
} |
Oops, something went wrong.