Files
forumlify/scripts/build.js
T
lezi-fun 6d41c6208c feat: upgrade Next.js 16 + React 19, R2 binding storage, adaptive build
- Next.js 14 → 16.3.0, React 18 → 19.2.8
- Route handlers: async params (await params) for Next 15+ — 17 files
- Fix destructuring params pattern (const {id} = await params) in
  users/[id] and users/[id]/role
- storage.js: prefer Cloudflare R2 binding (FORUMLIFY_BUCKET, no S3
  keys) on Workers; fallback S3-compatible API (Vercel/local)
- wrangler.jsonc: add FORUMLIFY_BUCKET binding to forum bucket
- scripts/build.js: adaptive build (CF env → OpenNext, else next build);
  fix recursion via NEXT_PRIVATE_STANDALONE detection
- 40/40 tests pass on Next 16
2026-08-11 09:45:56 +08:00

27 lines
1.1 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// 构建入口:自动适配部署平台
// - Cloudflare Workers/Pages(CF_PAGES=1 / CF_WORKERS_BUILDS / CLOUDFLARE_ACCOUNT_ID):OpenNext build
// - 其他(本地/Vercel/Docker):next build
//
// 注意:OpenNext 内部构建 Next.js 时会调用 `bun run build`(packager 检测),
// 它设置 NEXT_PRIVATE_STANDALONE=true,此时必须走 next build 避免递归。
const { spawnSync } = require('child_process');
const insideOpenNext = process.env.NEXT_PRIVATE_STANDALONE === 'true';
const isCF = !insideOpenNext && (
process.env.CF_PAGES === '1'
|| process.env.CF_WORKERS_BUILDS === '1'
|| !!process.env.CLOUDFLARE_ACCOUNT_ID
|| !!process.env.CF_ACCOUNT_ID
);
const args = isCF
? ['opennextjs-cloudflare', 'build', '--dangerouslyUseUnsupportedNextVersion']
: ['next', 'build'];
console.log(`[build] 平台: ${isCF ? 'Cloudflare Workers (OpenNext)' : 'Next.js 标准构建'}${insideOpenNext ? ' (OpenNext 内部)' : ''}`);
const r = spawnSync('bun', ['run', ...args], { stdio: 'inherit', shell: false });
if (r.status !== 0) {
console.error(`[build] 失败 (exit ${r.status})`);
process.exit(r.status ?? 1);
}