check-next-symlinks.sh 1.2 KB

123456789101112131415161718192021222324252627282930313233343536
  1. #!/bin/bash
  2. # Check that all .next/node_modules/ symlinks resolve correctly after assemble-prod.sh.
  3. # Usage: bash apps/app/bin/check-next-symlinks.sh (from monorepo root)
  4. set -euo pipefail
  5. NEXT_MODULES="apps/app/.next/node_modules"
  6. # Packages that are intentionally broken symlinks.
  7. # These are only imported via useEffect + dynamic import() and never accessed during SSR.
  8. ALLOWED_BROKEN=(
  9. fslightbox-react
  10. @emoji-mart/data
  11. @emoji-mart/react
  12. )
  13. # Build a grep -v pattern from the allowlist
  14. grep_args=()
  15. for pkg in "${ALLOWED_BROKEN[@]}"; do
  16. grep_args+=(-e "$pkg")
  17. done
  18. broken=$(find "$NEXT_MODULES" -maxdepth 2 -type l | while read -r link; do
  19. linkdir=$(dirname "$link")
  20. target=$(readlink "$link")
  21. resolved=$(cd "$linkdir" 2>/dev/null && realpath -m "$target" 2>/dev/null || echo "UNRESOLVABLE")
  22. { [ "$resolved" = "UNRESOLVABLE" ] || [ ! -e "$resolved" ]; } && echo "BROKEN: $link"
  23. done | grep -v "${grep_args[@]}" || true)
  24. if [ -n "$broken" ]; then
  25. echo "ERROR: Broken symlinks found in $NEXT_MODULES:"
  26. echo "$broken"
  27. echo "Move these packages from devDependencies to dependencies in apps/app/package.json."
  28. exit 1
  29. fi
  30. echo "OK: All $NEXT_MODULES symlinks resolve correctly."