#!/not/executable/bash
# direnv activation for sentry: environment variables and PATH, nothing else.
# `devenv sync` installs and repairs the environment; `devenv doctor` diagnoses it.
# Put local overrides in a .env file.
set -eu

export PYTHONUNBUFFERED=1
unset PYTHONPATH

# increase node's memory limit, required for our webpacking
export NODE_OPTIONS="--max-old-space-size=5120"

# Frontend hot module reloader using `react-refresh`
# Enable this by default for development envs (CI/deploys do not use envrc)
export SENTRY_UI_HOT_RELOAD=1

# Watches .env even while it's absent, so creating it triggers a reload.
dotenv_if_exists

# Development environment errors are reported to Sentry.io. Set SENTRY_DEVENV_NO_REPORT to opt out.
if [ -z "${SENTRY_DEVENV_NO_REPORT+x}" ]; then
    export SENTRY_DEVSERVICES_DSN=https://23670f54c6254bfd9b7de106637808e9@o1.ingest.sentry.io/1492057
fi

# PATH_add prepends, so later entries take precedence. Homebrew is moved ahead
# of the system paths, but the checkout's tools must win over it.
PATH_rm /opt/homebrew/bin
PATH_add /opt/homebrew/bin
PATH_add /opt/homebrew/share/google-cloud-sdk/bin
# npm ships a binary named `sentry`, which must not shadow the venv's.
PATH_add node_modules/.bin
PATH_add .devenv/bin

export VIRTUAL_ENV="${PWD}/.venv"
PATH_add "${VIRTUAL_ENV}/bin"

# The global devenv, not the copy pinned in the venv.
export SENTRY_DEVENV_HOME="${SENTRY_DEVENV_HOME:-${XDG_DATA_HOME:-$HOME/.local/share}/sentry-devenv}"
PATH_add "${SENTRY_DEVENV_HOME}/bin"

if ! has devenv; then
    log_error "devenv isn't installed. See https://github.com/getsentry/devenv#install"
elif [ ! -x "${VIRTUAL_ENV}/bin/sentry" ]; then
    log_error "sentry isn't installed in ${VIRTUAL_ENV}. Run: devenv sync"
fi
