Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const { schema } = require('@bugsnag/core/config')
const { map } = require('@bugsnag/core/lib/es-utils')
const { stringWithLength } = require('@bugsnag/core/lib/validators')
module.exports = {
releaseStage: {
defaultValue: () => {
if (/^localhost(:\d+)?$/.test(window.location.host)) return 'development'
return 'production'
},
message: 'should be set',
validate: stringWithLength
},
logger: {
...schema.logger,
defaultValue: () =>
// set logger based on browser capability
(typeof console !== 'undefined' && typeof console.debug === 'function')
? getPrefixedConsole()
: undefined
}
}
const getPrefixedConsole = () => {
const logger = {}
const consoleLog = console.log
map(['debug', 'info', 'warn', 'error'], (method) => {
const consoleMethod = console[method]
logger[method] = typeof consoleMethod === 'function'
? consoleMethod.bind(console, '[bugsnag]')
: consoleLog.bind(console, '[bugsnag]')
const { reduce } = require('@bugsnag/core/lib/es-utils')
const Constants = require('expo-constants').default
// If the developer property is not present in the manifest, it means the app is
// not connected to a development tool and is either a published app running in
// the Expo client, or a standalone app (we also assume production for a missing
// manifest, but that should never happen)
const IS_PRODUCTION = !Constants.manifest || !Constants.manifest.developer
// The app can still run in production "mode" in development environments, in which
// cases the global boolean __DEV__ will be set to true
const IS_PRODUCTION_MODE = typeof __DEV__ === 'undefined' || __DEV__ !== true
module.exports = {
logger: {
...schema.logger,
defaultValue: () => getPrefixedConsole()
},
releaseStage: {
...schema.releaseStage,
defaultValue: () => {
if (IS_PRODUCTION) return 'production'
if (IS_PRODUCTION_MODE) return 'local-prod'
return 'local-dev'
}
}
}
const getPrefixedConsole = () => {
return reduce([ 'debug', 'info', 'warn', 'error' ], (accum, method) => {
// console.error causes standalone expo apps to reload on android
// so don't do any logging that level – use console.warn instead
const os = require('os')
const process = require('process')
module.exports = {
projectRoot: {
defaultValue: () => process.cwd(),
validate: value => value === null || stringWithLength(value),
message: 'should be string'
},
hostname: {
defaultValue: () => os.hostname(),
message: 'should be a string',
validate: value => value === null || stringWithLength(value)
},
logger: {
...schema.logger,
defaultValue: () => getPrefixedConsole()
},
releaseStage: {
...schema.releaseStage,
defaultValue: () => process.env.NODE_ENV || 'production'
},
agent: {
defaultValue: () => undefined,
message: 'should be an HTTP(s) agent',
validate: value => value === undefined || isAgent(value)
},
onUncaughtException: {
defaultValue: () => (err, report, logger) => {
logger.error(`Uncaught exception${getContext(report)}, the process will now terminate…\n${(err && err.stack) ? err.stack : err}`)
process.exit(1)
},