-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathconfig.js
50 lines (44 loc) · 1.69 KB
/
config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/* 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 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
let IS_PRODUCTION = true
if (Constants.manifest) {
IS_PRODUCTION = !Constants.manifest.developer
} else if (Constants.manifest2) {
IS_PRODUCTION = !Constants.manifest2?.extra?.expoGo?.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
}, {})
}