Add `next internal post-build` CLI command for Turbopack database compaction (#91336)
### What?
Adds a \`next internal post-build\` CLI command that performs Turbopack
persistent cache database compaction as a separate step after \`next
build\`.
### Why?
Database compaction during shutdown can be slow and blocks the build
process. By deferring compaction to a separate post-build step, we can:
- Keep the main \`next build\` fast by skipping compaction at shutdown
(controlled via \`NEXT_USE_POST_BUILD=1\`)
- Run compaction independently, e.g. as a separate CI step or in the
background
- Perform a full compaction (\`max_merge_segment_count: usize::MAX\`)
that is more thorough than the runtime shutdown compaction
**Intended usage in a build pipeline:**
\`\`\`sh
NEXT_USE_POST_BUILD=1 next build # fast build, skips compaction at
shutdown
next internal post-build # separate step: full compaction of the cache
\`\`\`
### How?
**Rust side:**
- Added \`compact_database()\` to \`turbo-tasks-backend\` that opens the
database and runs a full compaction using
\`TurboTasksParallelScheduler\` backed by a dedicated multi-threaded
Tokio runtime (same scheduler as the normal runtime path, enabling
parallel work-stealing)
- Added \`turbopack_database_compact\` NAPI binding that resolves the
versioned DB path and calls \`compact_database()\`
- Added \`skip_compaction\` flag to \`NapiTurboEngineOptions\` /
\`TurboKeyValueDatabase\` to skip compaction during normal shutdown when
post-build will handle it; asserted that \`skip_compaction=true\`
requires \`is_short_session=true\` (enforcing the logical dependency)
- Extracted shared \`DB_CONFIG\`, \`FAMILIES\`, and \`COMPACT_CONFIG\`
constants and \`git_version_info()\` helper to avoid duplication between
the runtime DB and standalone compaction paths
**TypeScript side:**
- Added \`next internal post-build\` command that loads the Next.js
config, finds the Turbopack cache directory, and calls the native
compaction binding
- Added \`databaseCompact\` to the turbo bindings interface (native +
WASM stub)
- \`turbopack-build/impl.ts\` sets \`skipCompaction: true\` when
\`NEXT_USE_POST_BUILD=1\`
**Tests:**
- Added \`test/production/app-dir/post-build/\` integration test that
verifies compaction runs successfully on a persistent-cache build and
reports nothing to do when persistent caching is disabled
---------
Co-authored-by: Tobias Koppers <sokra@users.noreply.github.com>
Co-authored-by: Claude <noreply@anthropic.com>