about summary refs log tree commit diff
diff options
context:
space:
mode:
authordan <dan.abramov@gmail.com>2024-12-13 17:16:53 +0000
committerGitHub <noreply@github.com>2024-12-13 17:16:53 +0000
commit356dad1932c3404f581b747127ae251dbe165bb3 (patch)
treed966d4c5fd4645f9897a984a018d7258399e1674
parente2a7965e438db9f70d76d2d7a911aa4c4a42c122 (diff)
downloadvoidsky-356dad1932c3404f581b747127ae251dbe165bb3.tar.zst
Remove the environment indirections (#7089)
* Use raw underlying globals for environment

* Set dev EXPO_PUBLIC_ENV by exclusion
-rw-r--r--.env.example1
-rw-r--r--app.config.js2
-rw-r--r--src/components/Typography.tsx3
-rw-r--r--src/components/dialogs/nuxs/index.tsx5
-rw-r--r--src/env.ts2
-rw-r--r--src/lib/app-info.ts8
-rw-r--r--src/lib/app-info.web.ts8
-rw-r--r--src/lib/hooks/useEnableKeyboardController.tsx4
-rw-r--r--src/lib/sentry.ts6
-rw-r--r--src/logger/README.md4
-rw-r--r--src/logger/__tests__/logger.test.ts2
-rw-r--r--src/logger/index.ts19
-rw-r--r--src/screens/Onboarding/Layout.tsx3
-rw-r--r--src/state/geolocation.tsx3
-rw-r--r--src/state/session/index.tsx3
-rw-r--r--src/state/shell/light-status-bar.tsx3
-rw-r--r--src/storage/index.ts3
-rw-r--r--src/view/com/util/text/Text.tsx3
18 files changed, 32 insertions, 50 deletions
diff --git a/.env.example b/.env.example
index 979589f58..a4d21ac33 100644
--- a/.env.example
+++ b/.env.example
@@ -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=
diff --git a/app.config.js b/app.config.js
index bc283152b..d47481e62 100644
--- a/app.config.js
+++ b/app.config.js
@@ -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',
diff --git a/src/components/Typography.tsx b/src/components/Typography.tsx
index 3e202cb8f..4ed7f8371 100644
--- a/src/components/Typography.tsx
+++ b/src/components/Typography.tsx
@@ -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 />'`,
diff --git a/src/components/dialogs/nuxs/index.tsx b/src/components/dialogs/nuxs/index.tsx
index 11d622a4d..10cae887b 100644
--- a/src/components/dialogs/nuxs/index.tsx
+++ b/src/components/dialogs/nuxs/index.tsx
@@ -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()
     }
diff --git a/src/env.ts b/src/env.ts
index 4d1b55a4e..32ce70670 100644
--- a/src/env.ts
+++ b/src/env.ts
@@ -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'
diff --git a/src/lib/app-info.ts b/src/lib/app-info.ts
index 4da70d75d..0749087ea 100644
--- a/src/lib/app-info.ts
+++ b/src/lib/app-info.ts
@@ -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'
 })`
diff --git a/src/lib/app-info.web.ts b/src/lib/app-info.web.ts
index 742ccfe97..94c787cbc 100644
--- a/src/lib/app-info.web.ts
+++ b/src/lib/app-info.web.ts
@@ -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'})`
diff --git a/src/lib/hooks/useEnableKeyboardController.tsx b/src/lib/hooks/useEnableKeyboardController.tsx
index c7205d016..366791c0c 100644
--- a/src/lib/hooks/useEnableKeyboardController.tsx
+++ b/src/lib/hooks/useEnableKeyboardController.tsx
@@ -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')
         }
       },
diff --git a/src/lib/sentry.ts b/src/lib/sentry.ts
index 2c390d7de..b2695694d 100644
--- a/src/lib/sentry.ts
+++ b/src/lib/sentry.ts
@@ -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,
 })
diff --git a/src/logger/README.md b/src/logger/README.md
index 17dd61cb3..8da7deb14 100644
--- a/src/logger/README.md
+++ b/src/logger/README.md
@@ -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
 
diff --git a/src/logger/__tests__/logger.test.ts b/src/logger/__tests__/logger.test.ts
index 02039d26e..be2391e12 100644
--- a/src/logger/__tests__/logger.test.ts
+++ b/src/logger/__tests__/logger.test.ts
@@ -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.
diff --git a/src/logger/index.ts b/src/logger/index.ts
index d99bfeb13..102bccef7 100644
--- a/src/logger/index.ts
+++ b/src/logger/index.ts
@@ -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)
+  }
 }
diff --git a/src/screens/Onboarding/Layout.tsx b/src/screens/Onboarding/Layout.tsx
index 059cdfd5c..bdc1664f6 100644
--- a/src/screens/Onboarding/Layout.tsx
+++ b/src/screens/Onboarding/Layout.tsx
@@ -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"
diff --git a/src/state/geolocation.tsx b/src/state/geolocation.tsx
index 4d45bb574..0024cd41d 100644
--- a/src/state/geolocation.tsx
+++ b/src/state/geolocation.tsx
@@ -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
diff --git a/src/state/session/index.tsx b/src/state/session/index.tsx
index ab3352bf3..48b258863 100644
--- a/src/state/session/index.tsx
+++ b/src/state/session/index.tsx
@@ -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)
diff --git a/src/state/shell/light-status-bar.tsx b/src/state/shell/light-status-bar.tsx
index eb213adb9..6f47689d1 100644
--- a/src/state/shell/light-status-bar.tsx
+++ b/src/state/shell/light-status-bar.tsx
@@ -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',
         )
diff --git a/src/storage/index.ts b/src/storage/index.ts
index 7ef226d3a..ce17d4c36 100644
--- a/src/storage/index.ts
+++ b/src/storage/index.ts
@@ -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,
diff --git a/src/view/com/util/text/Text.tsx b/src/view/com/util/text/Text.tsx
index f05274f44..785cef09a 100644
--- a/src/view/com/util/text/Text.tsx
+++ b/src/view/com/util/text/Text.tsx
@@ -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 />'`,