Skip to content

Instantly share code, notes, and snippets.

@sachithrrra
Created November 12, 2025 15:14
Show Gist options
  • Select an option

  • Save sachithrrra/0405f49d9cd6d4710ca6ebdea013178c to your computer and use it in GitHub Desktop.

Select an option

Save sachithrrra/0405f49d9cd6d4710ca6ebdea013178c to your computer and use it in GitHub Desktop.
Check deprecated API usage in Expo app
#!/bin/bash
# Check deprecated API usage in Expo app by scanning JSDoc @deprecated tags
echo "πŸ“¦ Extracting package names from package.json..."
echo ""
# Get all package names from dependencies and devDependencies
PACKAGES=$(node -pe "
const pkg = require('./package.json');
const deps = {...(pkg.dependencies || {}), ...(pkg.devDependencies || {})};
Object.keys(deps).join('\n');
")
echo "Found $(echo "$PACKAGES" | wc -l) packages"
echo ""
echo "πŸ” Scanning node_modules for @deprecated JSDoc tags..."
echo ""
# Temporary file to store deprecated API names with their packages
DEPRECATED_APIS=$(mktemp)
# Check each package for @deprecated JSDoc tags (non-recursive, only top level)
while IFS= read -r package; do
PKG_DIR="node_modules/$package"
if [ -d "$PKG_DIR" ]; then
# Only check direct files in package, not nested node_modules
# Look in common locations: root, src, lib, dist
for subdir in "" "src" "lib" "dist"; do
SEARCH_DIR="$PKG_DIR/$subdir"
if [ -d "$SEARCH_DIR" ] || [ -z "$subdir" ]; then
# Use find with maxdepth to avoid recursing into nested node_modules
FILES=$(find "$SEARCH_DIR" -maxdepth 3 -type f \
\( -name "*.js" -o -name "*.ts" -o -name "*.jsx" -o -name "*.tsx" -o -name "*.d.ts" \) \
! -path "*/node_modules/*" 2>/dev/null)
if [ ! -z "$FILES" ]; then
# Search for @deprecated with context
RESULT=$(echo "$FILES" | xargs grep -l "@deprecated" 2>/dev/null | \
xargs grep -B 5 -A 2 "@deprecated" 2>/dev/null)
if [ ! -z "$RESULT" ]; then
# Extract API names from lines after @deprecated
echo "$RESULT" | grep -A 2 "@deprecated" | \
grep -oE "(export )?(const|let|var|function|class) [a-zA-Z_$][a-zA-Z0-9_$]*" | \
awk -v pkg="$package" '{print $NF "|||" pkg}' | \
grep -v "^(export|const|let|var|function|class)" >> "$DEPRECATED_APIS"
fi
fi
fi
done
fi
done <<< "$PACKAGES"
# Remove duplicates
sort -u "$DEPRECATED_APIS" -o "$DEPRECATED_APIS"
API_COUNT=$(wc -l < "$DEPRECATED_APIS")
if [ "$API_COUNT" -eq 0 ]; then
echo "βœ… No @deprecated JSDoc tags found in node_modules"
rm "$DEPRECATED_APIS"
echo ""
echo "✨ Check complete!"
exit 0
fi
echo "Found $API_COUNT deprecated APIs:"
while IFS='|||' read -r api pkg; do
echo " - $api (from $pkg)"
done < "$DEPRECATED_APIS"
echo ""
echo "πŸ“ Checking your source code for actual usage of deprecated APIs..."
echo ""
# Source directories to check
SRC_DIRS=("src" "app" "components" "screens" "lib" ".")
FOUND_USAGE=false
while IFS='|||' read -r api pkg; do
if [ ! -z "$api" ]; then
for dir in "${SRC_DIRS[@]}"; do
if [ -d "$dir" ]; then
# Match actual function usage patterns:
# 1. Function calls: api() or api(
# 2. Imports: import { api } or import api
# 3. Property access: .api or something.api(
# 4. Destructuring: { api }
MATCHES=$(grep -rn \
-e "\b$api\s*(" \
-e "import.*\b$api\b" \
-e "from.*\b$api\b" \
-e "\.$api\b" \
-e "{\s*$api\s*[,}]" \
"$dir" \
--include="*.js" --include="*.ts" --include="*.jsx" --include="*.tsx" \
--exclude-dir=node_modules --exclude-dir=.expo --exclude-dir=.git \
--exclude-dir=dist --exclude-dir=build \
2>/dev/null)
if [ ! -z "$MATCHES" ]; then
FOUND_USAGE=true
echo "πŸ”΄ Using deprecated API: $api"
echo " Package: $pkg"
echo " Found in your code:"
echo "$MATCHES" | sed 's/^/ /'
echo ""
fi
fi
done
fi
done < "$DEPRECATED_APIS"
if [ "$FOUND_USAGE" = false ]; then
echo "βœ… No usage of deprecated APIs found in your code!"
fi
# Cleanup
rm "$DEPRECATED_APIS"
echo ""
echo "✨ Check complete!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment