assemble-prod.sh 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #!/bin/bash
  2. # Assemble production artifacts for GROWI app.
  3. # Run from the workspace root.
  4. set -euo pipefail
  5. echo "[1/4] Deploying production dependencies..."
  6. rm -rf out
  7. pnpm deploy out --prod --legacy --filter @growi/app
  8. rm -rf apps/app/node_modules
  9. mv out/node_modules apps/app/node_modules
  10. echo "[1/4] Done."
  11. # Redirect .next/node_modules/ symlinks from workspace root to deployed apps/app/node_modules/.pnpm/.
  12. # Turbopack generates symlinks pointing to ../../../../node_modules/.pnpm/ (workspace root),
  13. # which will not exist in production environments.
  14. # Rewriting to ../../node_modules/.pnpm/ (apps/app/) uses the pnpm deploy output instead,
  15. # preserving pnpm's isolated structure so transitive deps remain resolvable.
  16. echo "[2/4] Rewriting .next/node_modules symlinks..."
  17. if [ -d apps/app/.next/node_modules ]; then
  18. find apps/app/.next/node_modules -maxdepth 2 -type l | while read -r link; do
  19. target=$(readlink "$link")
  20. new_target=$(echo "$target" | sed 's|../../../../node_modules/\.pnpm/|../../node_modules/.pnpm/|')
  21. [ "$target" != "$new_target" ] && ln -sfn "$new_target" "$link"
  22. done
  23. else
  24. echo "[2/4] Skipped (no .next/node_modules directory)."
  25. fi
  26. echo "[2/4] Done."
  27. echo "[3/4] Removing build cache..."
  28. rm -rf apps/app/.next/cache
  29. echo "[3/4] Done."
  30. # Remove next.config.ts to prevent Next.js from attempting to install TypeScript at server startup,
  31. # which would corrupt node_modules (e.g. @growi/core). The compiled next.config.js is used instead.
  32. echo "[4/4] Removing next.config.ts..."
  33. rm -f apps/app/next.config.ts
  34. echo "[4/4] Done."
  35. echo "Assembly complete."