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
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
18 changed files with 32 additions and 50 deletions

View File

@ -2,7 +2,6 @@
BITDRIFT_API_KEY=
SENTRY_AUTH_TOKEN=
EXPO_PUBLIC_ENV=development
EXPO_PUBLIC_LOG_LEVEL=debug
EXPO_PUBLIC_LOG_DEBUG=
EXPO_PUBLIC_BUNDLE_IDENTIFIER=

View File

@ -15,9 +15,9 @@ module.exports = function (config) {
*/
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_PRODUCTION = process.env.EXPO_PUBLIC_ENV === 'production'
const IS_DEV = !IS_TESTFLIGHT || !IS_PRODUCTION
const ASSOCIATED_DOMAINS = [
'applinks:bsky.app',

View File

@ -8,7 +8,6 @@ import {
renderChildrenWithEmoji,
TextProps,
} from '#/alf/typography'
import {IS_DEV} from '#/env'
export type {TextProps}
/**
@ -31,7 +30,7 @@ export function Text({
flags,
})
if (IS_DEV) {
if (__DEV__) {
if (!emoji && childHasEmoji(children)) {
logger.warn(
`Text: emoji detected but emoji not enabled: "${children}"\n\nPlease add <Text emoji />'`,

View File

@ -15,7 +15,6 @@ import {useOnboardingState} from '#/state/shell'
* NUXs
*/
import {isSnoozed, snooze, unsnooze} from '#/components/dialogs/nuxs/snoozing'
import {IS_DEV} from '#/env'
type Context = {
activeNux: Nux | undefined
@ -93,10 +92,10 @@ function Inner({
setActiveNux(undefined)
}, [activeNux, setActiveNux])
if (IS_DEV && typeof window !== 'undefined') {
if (__DEV__ && typeof window !== 'undefined') {
// @ts-ignore
window.clearNuxDialog = (id: Nux) => {
if (!IS_DEV || !id) return
if (!__DEV__ || !id) return
resetNuxs([id])
unsnooze()
}

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_LEVEL = (process.env.EXPO_PUBLIC_LOG_LEVEL || 'info') as
| 'debug'

View File

@ -1,9 +1,7 @@
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_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
// 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
// for Statsig reporting and shouldn't be used to identify a specific bundle.
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 bundleInfo = `${BUNDLE_IDENTIFIER} (${
IS_DEV ? 'dev' : IS_TESTFLIGHT ? 'tf' : 'prod'
__DEV__ ? 'dev' : IS_TESTFLIGHT ? 'tf' : 'prod'
})`

View File

@ -1,9 +1,7 @@
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_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
// 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
// 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
: Number(process.env.EXPO_PUBLIC_BUNDLE_DATE)
export const appVersion = version
export const bundleInfo = `${BUNDLE_IDENTIFIER} (${IS_DEV ? 'dev' : 'prod'})`
export const bundleInfo = `${BUNDLE_IDENTIFIER} (${__DEV__ ? 'dev' : 'prod'})`

View File

@ -12,8 +12,6 @@ import {
} from 'react-native-keyboard-controller'
import {useFocusEffect} from '@react-navigation/native'
import {IS_DEV} from '#/env'
const KeyboardControllerRefCountContext = createContext<{
incrementRefCount: () => void
decrementRefCount: () => void
@ -57,7 +55,7 @@ function KeyboardControllerProviderInner({
refCount.current--
setEnabled(refCount.current > 0)
if (IS_DEV && refCount.current < 0) {
if (__DEV__ && refCount.current < 0) {
console.error('KeyboardController ref count < 0')
}
},

View File

@ -7,7 +7,7 @@ import {Platform} from 'react-native'
import {nativeApplicationVersion, nativeBuildVersion} from 'expo-application'
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:
@ -27,14 +27,14 @@ const release = nativeApplicationVersion ?? 'dev'
*/
const dist = `${Platform.OS}.${nativeBuildVersion}.${
IS_TESTFLIGHT ? 'tf' : ''
}${IS_DEV ? 'dev' : ''}`
}${__DEV__ ? 'dev' : ''}`
init({
enabled: !__DEV__,
autoSessionTracking: false,
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
environment: BUILD_ENV ?? 'development',
environment: process.env.NODE_ENV,
dist,
release,
})

View File

@ -17,8 +17,8 @@ logger.error(error[, metadata])
#### Modes
The "modes" referred to here are inferred from the values exported from `#/env`.
Basically, the booleans `IS_DEV` and `IS_PROD`.
The "modes" referred to here are inferred from `process.env.NODE_ENV`,
which matches how React Native sets the `__DEV__` global.
#### Log Levels

View File

@ -5,8 +5,6 @@ import {nanoid} from 'nanoid/non-secure'
import {Logger, LogLevel, sentryTransport} from '#/logger'
jest.mock('#/env', () => ({
IS_DEV: false,
IS_PROD: false,
/*
* Forces debug mode for tests using the default logger. Most tests create
* their own logger instance.

View File

@ -270,13 +270,14 @@ if (process.env.NODE_ENV !== 'test') {
logger.addTransport(createBitdriftTransport())
}
if (env.IS_DEV && process.env.NODE_ENV !== 'test') {
logger.addTransport(consoleTransport)
/*
* Comment this out to disable Sentry transport in dev
*/
// logger.addTransport(sentryTransport)
} else if (env.IS_PROD) {
logger.addTransport(sentryTransport)
if (process.env.NODE_ENV !== 'test') {
if (__DEV__) {
logger.addTransport(consoleTransport)
/*
* Comment this out to enable Sentry transport in dev
*/
// logger.addTransport(sentryTransport)
} else {
logger.addTransport(sentryTransport)
}
}

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 {createPortalGroup} from '#/components/Portal'
import {P, Text} from '#/components/Typography'
import {IS_DEV} from '#/env'
const COL_WIDTH = 420
@ -64,7 +63,7 @@ export function Layout({children}: React.PropsWithChildren<{}>) {
a.flex_1,
t.atoms.bg,
]}>
{IS_DEV && (
{__DEV__ && (
<View style={[a.absolute, a.p_xl, a.z_10, {right: 0, top: insets.top}]}>
<Button
variant="ghost"

View File

@ -3,7 +3,6 @@ import EventEmitter from 'eventemitter3'
import {networkRetry} from '#/lib/async/retry'
import {logger} from '#/logger'
import {IS_DEV} from '#/env'
import {Device, device} from '#/storage'
const events = new EventEmitter()
@ -65,7 +64,7 @@ export function beginResolveGeolocation() {
* In dev, IP server is unavailable, so we just set the default geolocation
* and fail closed.
*/
if (IS_DEV) {
if (__DEV__) {
geolocationResolution = new Promise(y => y())
device.set(['geolocation'], DEFAULT_GEOLOCATION)
return

View File

@ -6,7 +6,6 @@ import {isWeb} from '#/platform/detection'
import * as persisted from '#/state/persisted'
import {useCloseAllActiveElements} from '#/state/util'
import {useGlobalDialogsControlContext} from '#/components/dialogs/Context'
import {IS_DEV} from '#/env'
import {emitSessionDropped} from '../events'
import {
agentToSessionAccount,
@ -260,7 +259,7 @@ export function Provider({children}: React.PropsWithChildren<{}>) {
)
// @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 currentAgentRef = React.useRef(agent)

View File

@ -1,7 +1,6 @@
import {createContext, useContext, useEffect, useState} from 'react'
import {isWeb} from '#/platform/detection'
import {IS_DEV} from '#/env'
const LightStatusBarRefCountContext = createContext<boolean>(false)
const SetLightStatusBarRefCountContext = createContext<React.Dispatch<
@ -19,7 +18,7 @@ export function useSetLightStatusBar(enabled: boolean) {
if (isWeb) return
if (!setRefCount) {
if (IS_DEV)
if (__DEV__)
console.error(
'useLightStatusBar was used without a SetLightStatusBarRefCountContext provider',
)

View File

@ -1,6 +1,5 @@
import {MMKV} from 'react-native-mmkv'
import {IS_DEV} from '#/env'
import {Device} 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'})
if (IS_DEV && typeof window !== 'undefined') {
if (__DEV__ && typeof window !== 'undefined') {
// @ts-ignore
window.bsky_storage = {
device,

View File

@ -12,7 +12,6 @@ import {
renderChildrenWithEmoji,
StringChild,
} from '#/alf/typography'
import {IS_DEV} from '#/env'
export type CustomTextProps = Omit<TextProps, 'children'> & {
type?: TypographyVariant
@ -49,7 +48,7 @@ function Text_DEPRECATED({
const theme = useTheme()
const {fonts} = useAlf()
if (IS_DEV) {
if (__DEV__) {
if (!emoji && childHasEmoji(children)) {
logger.warn(
`Text: emoji detected but emoji not enabled: "${children}"\n\nPlease add <Text emoji />'`,