Files
civitai__civitai/scripts/graceful-fs-patch.cjs
T
Briant Diehl 4fdb431fba Migrate to Next.js 15
Bump next 14.2.28 -> 15.5.19 (Pages Router app). Also bumps
eslint-config-next and @next/eslint-plugin-next to 15.5.19, and eslint
8.22.0 -> 8.57.1 (Next 15's plugin rules use context.filename, added in
ESLint 8.40).

Config / API changes required by Next 15:
- next.config.mjs: experimental.serverComponentsExternalPackages ->
  top-level serverExternalPackages; removed the now-stable
  experimental.instrumentationHook flag.
- .eslintrc.js: added settings.next.rootDir so the Next ESLint plugin can
  locate the pages dir (otherwise the rules crash on load).
- bot-detection.middleware.ts: dropped request.ip (NextRequest.ip removed
  in 15); cf-connecting-ip / x-forwarded-for fallbacks remain.
- api/trpc/[trpc].ts: assert the default export as NextApiHandler. Next
  15's route-type validator rejected it because withAxiom's NextConfig
  overload (declared first) structurally matches an arrow function.
- Moved api/auth/oauth/__tests__/token.test.ts ->
  server/oauth/__tests__/token-endpoint.test.ts. Next 15 type-validates
  every file under pages/api as a route; the colocated test had no
  default export. Tests still pass (8/8).
- Deleted the unused src/app/layout.tsx stub (whole app is Pages Router);
  removes the spurious "i18n unsupported in App Router" build warning.

Build memory + Windows local-build helpers:
- package.json build:dev / build:analyze heap 8192 -> 16384 (the app
  needs >8GB to compile).
- scripts/graceful-fs-patch.cjs: optional NODE_OPTIONS --require preload
  to mitigate Windows EMFILE during local builds (no-op on Linux/CI).

Validated: typecheck clean; lint at parity with main; build compiles,
type-checks, passes route validation and page-data collection. The full
production build's "Collecting build traces" step is FD-bound on Windows
(EMFILE) and should be run on CI/Linux.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-04 15:58:33 -06:00

28 lines
1011 B
JavaScript

// Windows EMFILE ("too many open files") mitigation for `next build`.
//
// A Pages-Router app this size opens thousands of files during page-data
// collection / output emit. Windows' descriptor limit is lower than Linux's,
// so the build can exhaust it and throw EMFILE. graceful-fs patches the global
// fs module to queue and retry EMFILE/ENFILE operations instead of failing.
//
// Preload via: NODE_OPTIONS="--require ./scripts/graceful-fs-patch.cjs".
// No effect on Linux/macOS builds (they don't hit the limit), so it's safe to
// keep enabled everywhere.
const path = require('path');
const realFs = require('fs');
let gracefulFs;
try {
gracefulFs = require('graceful-fs');
} catch {
// pnpm doesn't hoist graceful-fs to a root-resolvable path; fall back to the
// copy webpack/next already depend on in the pnpm store.
gracefulFs = require(path.resolve(
__dirname,
'..',
'node_modules/.pnpm/graceful-fs@4.2.11/node_modules/graceful-fs'
));
}
gracefulFs.gracefulify(realFs);