@bugsnag/expo
Version:
Bugsnag error reporter for Expo applications
45 lines (39 loc) • 1.61 kB
JavaScript
/* global __DEV__ */
const { schema } = require('@bugsnag/core/config')
const Constants = require('expo-constants').default
const stringWithLength = require('@bugsnag/core/lib/validators/string-with-length')
// If the developer property is not present 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
const IS_PRODUCTION = !Constants.expoConfig?.developer && !Constants.expoGoConfig?.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'
}
},
codeBundleId: {
defaultValue: () => undefined,
message: 'should be a string',
validate: val => val === undefined || stringWithLength(val)
}
}
const getPrefixedConsole = () => {
return ['debug', 'info', 'warn', 'error'].reduce((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 consoleMethod = (IS_PRODUCTION && method === 'error') ? console.warn : console[method]
accum[method] = consoleMethod.bind(console, '[bugsnag]')
return accum
}, {})
}