Remove the environment indirections (#7089)

* Use raw underlying globals for environment

* Set dev EXPO_PUBLIC_ENV by exclusion
This commit is contained in:
dan
2024-12-13 17:16:53 +00:00
committed by GitHub
parent e2a7965e43
commit 356dad1932
18 changed files with 32 additions and 50 deletions
-1
View File
@@ -2,7 +2,6 @@
BITDRIFT_API_KEY= BITDRIFT_API_KEY=
SENTRY_AUTH_TOKEN= SENTRY_AUTH_TOKEN=
EXPO_PUBLIC_ENV=development
EXPO_PUBLIC_LOG_LEVEL=debug EXPO_PUBLIC_LOG_LEVEL=debug
EXPO_PUBLIC_LOG_DEBUG= EXPO_PUBLIC_LOG_DEBUG=
EXPO_PUBLIC_BUNDLE_IDENTIFIER= EXPO_PUBLIC_BUNDLE_IDENTIFIER=
+1 -1
View File
@@ -15,9 +15,9 @@ module.exports = function (config) {
*/ */
const PLATFORM = process.env.EAS_BUILD_PLATFORM const PLATFORM = process.env.EAS_BUILD_PLATFORM
const IS_DEV = process.env.EXPO_PUBLIC_ENV === 'development'
const IS_TESTFLIGHT = process.env.EXPO_PUBLIC_ENV === 'testflight' const IS_TESTFLIGHT = process.env.EXPO_PUBLIC_ENV === 'testflight'
const IS_PRODUCTION = process.env.EXPO_PUBLIC_ENV === 'production' const IS_PRODUCTION = process.env.EXPO_PUBLIC_ENV === 'production'
const IS_DEV = !IS_TESTFLIGHT || !IS_PRODUCTION
const ASSOCIATED_DOMAINS = [ const ASSOCIATED_DOMAINS = [
'applinks:bsky.app', 'applinks:bsky.app',
+1 -2
View File
@@ -8,7 +8,6 @@ import {
renderChildrenWithEmoji, renderChildrenWithEmoji,
TextProps, TextProps,
} from '#/alf/typography' } from '#/alf/typography'
import {IS_DEV} from '#/env'
export type {TextProps} export type {TextProps}
/** /**
@@ -31,7 +30,7 @@ export function Text({
flags, flags,
}) })
if (IS_DEV) { if (__DEV__) {
if (!emoji && childHasEmoji(children)) { if (!emoji && childHasEmoji(children)) {
logger.warn( logger.warn(
`Text: emoji detected but emoji not enabled: "${children}"\n\nPlease add <Text emoji />'`, `Text: emoji detected but emoji not enabled: "${children}"\n\nPlease add <Text emoji />'`,
+2 -3
View File
@@ -15,7 +15,6 @@ import {useOnboardingState} from '#/state/shell'
* NUXs * NUXs
*/ */
import {isSnoozed, snooze, unsnooze} from '#/components/dialogs/nuxs/snoozing' import {isSnoozed, snooze, unsnooze} from '#/components/dialogs/nuxs/snoozing'
import {IS_DEV} from '#/env'
type Context = { type Context = {
activeNux: Nux | undefined activeNux: Nux | undefined
@@ -93,10 +92,10 @@ function Inner({
setActiveNux(undefined) setActiveNux(undefined)
}, [activeNux, setActiveNux]) }, [activeNux, setActiveNux])
if (IS_DEV && typeof window !== 'undefined') { if (__DEV__ && typeof window !== 'undefined') {
// @ts-ignore // @ts-ignore
window.clearNuxDialog = (id: Nux) => { window.clearNuxDialog = (id: Nux) => {
if (!IS_DEV || !id) return if (!__DEV__ || !id) return
resetNuxs([id]) resetNuxs([id])
unsnooze() unsnooze()
} }
-2
View File
@@ -1,5 +1,3 @@
export const IS_DEV = __DEV__
export const IS_PROD = !IS_DEV
export const LOG_DEBUG = process.env.EXPO_PUBLIC_LOG_DEBUG || '' export const LOG_DEBUG = process.env.EXPO_PUBLIC_LOG_DEBUG || ''
export const LOG_LEVEL = (process.env.EXPO_PUBLIC_LOG_LEVEL || 'info') as export const LOG_LEVEL = (process.env.EXPO_PUBLIC_LOG_LEVEL || 'info') as
| 'debug' | 'debug'
+3 -5
View File
@@ -1,9 +1,7 @@
import {nativeApplicationVersion, nativeBuildVersion} from 'expo-application' import {nativeApplicationVersion, nativeBuildVersion} from 'expo-application'
export const BUILD_ENV = process.env.EXPO_PUBLIC_ENV
export const IS_DEV = process.env.EXPO_PUBLIC_ENV === 'development'
export const IS_TESTFLIGHT = process.env.EXPO_PUBLIC_ENV === 'testflight' export const IS_TESTFLIGHT = process.env.EXPO_PUBLIC_ENV === 'testflight'
export const IS_INTERNAL = IS_DEV || IS_TESTFLIGHT export const IS_INTERNAL = __DEV__ || IS_TESTFLIGHT
// This is the commit hash that the current bundle was made from. The user can see the commit hash in the app's settings // This is the commit hash that the current bundle was made from. The user can see the commit hash in the app's settings
// along with the other version info. Useful for debugging/reporting. // along with the other version info. Useful for debugging/reporting.
@@ -12,9 +10,9 @@ export const BUNDLE_IDENTIFIER = process.env.EXPO_PUBLIC_BUNDLE_IDENTIFIER ?? ''
// This will always be in the format of YYMMDD, so that it always increases for each build. This should only be used // This will always be in the format of YYMMDD, so that it always increases for each build. This should only be used
// for Statsig reporting and shouldn't be used to identify a specific bundle. // for Statsig reporting and shouldn't be used to identify a specific bundle.
export const BUNDLE_DATE = export const BUNDLE_DATE =
IS_TESTFLIGHT || IS_DEV ? 0 : Number(process.env.EXPO_PUBLIC_BUNDLE_DATE) IS_TESTFLIGHT || __DEV__ ? 0 : Number(process.env.EXPO_PUBLIC_BUNDLE_DATE)
export const appVersion = `${nativeApplicationVersion}.${nativeBuildVersion}` export const appVersion = `${nativeApplicationVersion}.${nativeBuildVersion}`
export const bundleInfo = `${BUNDLE_IDENTIFIER} (${ export const bundleInfo = `${BUNDLE_IDENTIFIER} (${
IS_DEV ? 'dev' : IS_TESTFLIGHT ? 'tf' : 'prod' __DEV__ ? 'dev' : IS_TESTFLIGHT ? 'tf' : 'prod'
})` })`
+3 -5
View File
@@ -1,9 +1,7 @@
import {version} from '../../package.json' import {version} from '../../package.json'
export const BUILD_ENV = process.env.EXPO_PUBLIC_ENV
export const IS_DEV = process.env.EXPO_PUBLIC_ENV === 'development'
export const IS_TESTFLIGHT = false export const IS_TESTFLIGHT = false
export const IS_INTERNAL = IS_DEV export const IS_INTERNAL = __DEV__
// This is the commit hash that the current bundle was made from. The user can see the commit hash in the app's settings // This is the commit hash that the current bundle was made from. The user can see the commit hash in the app's settings
// along with the other version info. Useful for debugging/reporting. // along with the other version info. Useful for debugging/reporting.
@@ -12,9 +10,9 @@ export const BUNDLE_IDENTIFIER =
// This will always be in the format of YYMMDD, so that it always increases for each build. This should only be used // This will always be in the format of YYMMDD, so that it always increases for each build. This should only be used
// for Statsig reporting and shouldn't be used to identify a specific bundle. // for Statsig reporting and shouldn't be used to identify a specific bundle.
export const BUNDLE_DATE = IS_DEV export const BUNDLE_DATE = __DEV__
? 0 ? 0
: Number(process.env.EXPO_PUBLIC_BUNDLE_DATE) : Number(process.env.EXPO_PUBLIC_BUNDLE_DATE)
export const appVersion = version export const appVersion = version
export const bundleInfo = `${BUNDLE_IDENTIFIER} (${IS_DEV ? 'dev' : 'prod'})` export const bundleInfo = `${BUNDLE_IDENTIFIER} (${__DEV__ ? 'dev' : 'prod'})`
@@ -12,8 +12,6 @@ import {
} from 'react-native-keyboard-controller' } from 'react-native-keyboard-controller'
import {useFocusEffect} from '@react-navigation/native' import {useFocusEffect} from '@react-navigation/native'
import {IS_DEV} from '#/env'
const KeyboardControllerRefCountContext = createContext<{ const KeyboardControllerRefCountContext = createContext<{
incrementRefCount: () => void incrementRefCount: () => void
decrementRefCount: () => void decrementRefCount: () => void
@@ -57,7 +55,7 @@ function KeyboardControllerProviderInner({
refCount.current-- refCount.current--
setEnabled(refCount.current > 0) setEnabled(refCount.current > 0)
if (IS_DEV && refCount.current < 0) { if (__DEV__ && refCount.current < 0) {
console.error('KeyboardController ref count < 0') console.error('KeyboardController ref count < 0')
} }
}, },
+3 -3
View File
@@ -7,7 +7,7 @@ import {Platform} from 'react-native'
import {nativeApplicationVersion, nativeBuildVersion} from 'expo-application' import {nativeApplicationVersion, nativeBuildVersion} from 'expo-application'
import {init} from '@sentry/react-native' import {init} from '@sentry/react-native'
import {BUILD_ENV, IS_DEV, IS_TESTFLIGHT} from '#/lib/app-info' import {IS_TESTFLIGHT} from '#/lib/app-info'
/** /**
* Examples: * Examples:
@@ -27,14 +27,14 @@ const release = nativeApplicationVersion ?? 'dev'
*/ */
const dist = `${Platform.OS}.${nativeBuildVersion}.${ const dist = `${Platform.OS}.${nativeBuildVersion}.${
IS_TESTFLIGHT ? 'tf' : '' IS_TESTFLIGHT ? 'tf' : ''
}${IS_DEV ? 'dev' : ''}` }${__DEV__ ? 'dev' : ''}`
init({ init({
enabled: !__DEV__, enabled: !__DEV__,
autoSessionTracking: false, autoSessionTracking: false,
dsn: 'https://05bc3789bf994b81bd7ce20c86ccd3ae@o4505071687041024.ingest.sentry.io/4505071690514432', dsn: 'https://05bc3789bf994b81bd7ce20c86ccd3ae@o4505071687041024.ingest.sentry.io/4505071690514432',
debug: false, // If `true`, Sentry will try to print out useful debugging information if something goes wrong with sending the event. Set it to `false` in production debug: false, // If `true`, Sentry will try to print out useful debugging information if something goes wrong with sending the event. Set it to `false` in production
environment: BUILD_ENV ?? 'development', environment: process.env.NODE_ENV,
dist, dist,
release, release,
}) })
+2 -2
View File
@@ -17,8 +17,8 @@ logger.error(error[, metadata])
#### Modes #### Modes
The "modes" referred to here are inferred from the values exported from `#/env`. The "modes" referred to here are inferred from `process.env.NODE_ENV`,
Basically, the booleans `IS_DEV` and `IS_PROD`. which matches how React Native sets the `__DEV__` global.
#### Log Levels #### Log Levels
-2
View File
@@ -5,8 +5,6 @@ import {nanoid} from 'nanoid/non-secure'
import {Logger, LogLevel, sentryTransport} from '#/logger' import {Logger, LogLevel, sentryTransport} from '#/logger'
jest.mock('#/env', () => ({ jest.mock('#/env', () => ({
IS_DEV: false,
IS_PROD: false,
/* /*
* Forces debug mode for tests using the default logger. Most tests create * Forces debug mode for tests using the default logger. Most tests create
* their own logger instance. * their own logger instance.
+10 -9
View File
@@ -270,13 +270,14 @@ if (process.env.NODE_ENV !== 'test') {
logger.addTransport(createBitdriftTransport()) logger.addTransport(createBitdriftTransport())
} }
if (env.IS_DEV && process.env.NODE_ENV !== 'test') { if (process.env.NODE_ENV !== 'test') {
logger.addTransport(consoleTransport) if (__DEV__) {
logger.addTransport(consoleTransport)
/* /*
* Comment this out to disable Sentry transport in dev * Comment this out to enable Sentry transport in dev
*/ */
// logger.addTransport(sentryTransport) // logger.addTransport(sentryTransport)
} else if (env.IS_PROD) { } else {
logger.addTransport(sentryTransport) logger.addTransport(sentryTransport)
}
} }
+1 -2
View File
@@ -21,7 +21,6 @@ import {Button, ButtonIcon, ButtonText} from '#/components/Button'
import {ChevronLeft_Stroke2_Corner0_Rounded as ChevronLeft} from '#/components/icons/Chevron' import {ChevronLeft_Stroke2_Corner0_Rounded as ChevronLeft} from '#/components/icons/Chevron'
import {createPortalGroup} from '#/components/Portal' import {createPortalGroup} from '#/components/Portal'
import {P, Text} from '#/components/Typography' import {P, Text} from '#/components/Typography'
import {IS_DEV} from '#/env'
const COL_WIDTH = 420 const COL_WIDTH = 420
@@ -64,7 +63,7 @@ export function Layout({children}: React.PropsWithChildren<{}>) {
a.flex_1, a.flex_1,
t.atoms.bg, t.atoms.bg,
]}> ]}>
{IS_DEV && ( {__DEV__ && (
<View style={[a.absolute, a.p_xl, a.z_10, {right: 0, top: insets.top}]}> <View style={[a.absolute, a.p_xl, a.z_10, {right: 0, top: insets.top}]}>
<Button <Button
variant="ghost" variant="ghost"
+1 -2
View File
@@ -3,7 +3,6 @@ import EventEmitter from 'eventemitter3'
import {networkRetry} from '#/lib/async/retry' import {networkRetry} from '#/lib/async/retry'
import {logger} from '#/logger' import {logger} from '#/logger'
import {IS_DEV} from '#/env'
import {Device, device} from '#/storage' import {Device, device} from '#/storage'
const events = new EventEmitter() const events = new EventEmitter()
@@ -65,7 +64,7 @@ export function beginResolveGeolocation() {
* In dev, IP server is unavailable, so we just set the default geolocation * In dev, IP server is unavailable, so we just set the default geolocation
* and fail closed. * and fail closed.
*/ */
if (IS_DEV) { if (__DEV__) {
geolocationResolution = new Promise(y => y()) geolocationResolution = new Promise(y => y())
device.set(['geolocation'], DEFAULT_GEOLOCATION) device.set(['geolocation'], DEFAULT_GEOLOCATION)
return return
+1 -2
View File
@@ -6,7 +6,6 @@ import {isWeb} from '#/platform/detection'
import * as persisted from '#/state/persisted' import * as persisted from '#/state/persisted'
import {useCloseAllActiveElements} from '#/state/util' import {useCloseAllActiveElements} from '#/state/util'
import {useGlobalDialogsControlContext} from '#/components/dialogs/Context' import {useGlobalDialogsControlContext} from '#/components/dialogs/Context'
import {IS_DEV} from '#/env'
import {emitSessionDropped} from '../events' import {emitSessionDropped} from '../events'
import { import {
agentToSessionAccount, agentToSessionAccount,
@@ -260,7 +259,7 @@ export function Provider({children}: React.PropsWithChildren<{}>) {
) )
// @ts-ignore // @ts-ignore
if (IS_DEV && isWeb) window.agent = state.currentAgentState.agent if (__DEV__ && isWeb) window.agent = state.currentAgentState.agent
const agent = state.currentAgentState.agent as BskyAppAgent const agent = state.currentAgentState.agent as BskyAppAgent
const currentAgentRef = React.useRef(agent) const currentAgentRef = React.useRef(agent)
+1 -2
View File
@@ -1,7 +1,6 @@
import {createContext, useContext, useEffect, useState} from 'react' import {createContext, useContext, useEffect, useState} from 'react'
import {isWeb} from '#/platform/detection' import {isWeb} from '#/platform/detection'
import {IS_DEV} from '#/env'
const LightStatusBarRefCountContext = createContext<boolean>(false) const LightStatusBarRefCountContext = createContext<boolean>(false)
const SetLightStatusBarRefCountContext = createContext<React.Dispatch< const SetLightStatusBarRefCountContext = createContext<React.Dispatch<
@@ -19,7 +18,7 @@ export function useSetLightStatusBar(enabled: boolean) {
if (isWeb) return if (isWeb) return
if (!setRefCount) { if (!setRefCount) {
if (IS_DEV) if (__DEV__)
console.error( console.error(
'useLightStatusBar was used without a SetLightStatusBarRefCountContext provider', 'useLightStatusBar was used without a SetLightStatusBarRefCountContext provider',
) )
+1 -2
View File
@@ -1,6 +1,5 @@
import {MMKV} from 'react-native-mmkv' import {MMKV} from 'react-native-mmkv'
import {IS_DEV} from '#/env'
import {Device} from '#/storage/schema' import {Device} from '#/storage/schema'
export * from '#/storage/schema' export * from '#/storage/schema'
@@ -74,7 +73,7 @@ export class Storage<Scopes extends unknown[], Schema> {
*/ */
export const device = new Storage<[], Device>({id: 'bsky_device'}) export const device = new Storage<[], Device>({id: 'bsky_device'})
if (IS_DEV && typeof window !== 'undefined') { if (__DEV__ && typeof window !== 'undefined') {
// @ts-ignore // @ts-ignore
window.bsky_storage = { window.bsky_storage = {
device, device,
+1 -2
View File
@@ -12,7 +12,6 @@ import {
renderChildrenWithEmoji, renderChildrenWithEmoji,
StringChild, StringChild,
} from '#/alf/typography' } from '#/alf/typography'
import {IS_DEV} from '#/env'
export type CustomTextProps = Omit<TextProps, 'children'> & { export type CustomTextProps = Omit<TextProps, 'children'> & {
type?: TypographyVariant type?: TypographyVariant
@@ -49,7 +48,7 @@ function Text_DEPRECATED({
const theme = useTheme() const theme = useTheme()
const {fonts} = useAlf() const {fonts} = useAlf()
if (IS_DEV) { if (__DEV__) {
if (!emoji && childHasEmoji(children)) { if (!emoji && childHasEmoji(children)) {
logger.warn( logger.warn(
`Text: emoji detected but emoji not enabled: "${children}"\n\nPlease add <Text emoji />'`, `Text: emoji detected but emoji not enabled: "${children}"\n\nPlease add <Text emoji />'`,