assemble-prod.sh 1.3 KB

123456789101112131415161718192021222324252627282930
  1. #!/bin/bash
  2. # Assemble production artifacts for GROWI app.
  3. # Run from the workspace root.
  4. set -euo pipefail
  5. # Deploy production dependencies into out/, then replace apps/app/node_modules/.
  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. # Redirect .next/node_modules/ symlinks from workspace root to deployed apps/app/node_modules/.pnpm/.
  11. # Turbopack generates symlinks pointing to ../../../../node_modules/.pnpm/ (workspace root),
  12. # which will not exist in production environments.
  13. # Rewriting to ../../node_modules/.pnpm/ (apps/app/) uses the pnpm deploy output instead,
  14. # preserving pnpm's isolated structure so transitive deps remain resolvable.
  15. if [ -d apps/app/.next/node_modules ]; then
  16. find apps/app/.next/node_modules -maxdepth 2 -type l | while read -r link; do
  17. target=$(readlink "$link")
  18. new_target=$(echo "$target" | sed 's|../../../../node_modules/\.pnpm/|../../node_modules/.pnpm/|')
  19. [ "$target" != "$new_target" ] && ln -sfn "$new_target" "$link"
  20. done
  21. fi
  22. # Remove build cache
  23. rm -rf apps/app/.next/cache
  24. # Remove next.config.ts to prevent Next.js from attempting to install TypeScript at server startup,
  25. # which would corrupt node_modules (e.g. @growi/core). The compiled next.config.js is used instead.
  26. rm -f apps/app/next.config.ts