echo "🔍 Checking for uncommented eruda imports..."
if grep -r "import.*eruda" src/ --include="*.ts" --include="*.tsx" --include="*.js" --include="*.jsx" | grep -v ":.*[[:space:]]*//.*import.*eruda"; then
  echo "❌ Found uncommented eruda imports in the codebase!"
  echo "Please comment out or remove eruda imports before pushing."
  exit 1
else
  echo "✅ No uncommented eruda imports found."
fi

echo "🔍 Checking for local link overrides in pnpm-lock.yaml..."
# `pnpm link` adds `link:` overrides that point at a local checkout. Other
# overrides, such as a security fix for a transitive package, are allowed.
if awk '/^overrides:/ { inside = 1; next } /^[^ ]/ { inside = 0 } inside && /: link:/' pnpm-lock.yaml | grep .; then
  echo "❌ Found local link overrides in pnpm-lock.yaml!"
  echo "Please remove them before pushing. Use pnpm unlink:local"
  exit 1
else
  echo "✅ No local link overrides found in pnpm-lock.yaml."
fi

pnpm exec nx fmt:check
pnpm exec nx lint
# pnpm exec nx build

# Check if SKIP_FREE_API environment variable is set
if [ "$SKIP_FREE_API" = "true" ]; then
  pnpm exec nx test -- --exclude="**/free-api.test.ts"
else
  pnpm exec nx test
fi
