next.js
9a7733ed - Automatically build and clear native build when running `pnpm build` (#89819)

Commit
91 days ago
Automatically build and clear native build when running `pnpm build` (#89819) ## What? Adds a `maybe-build-native.mjs` script to `packages/next-swc/` that conditionally rebuilds native SWC bindings during `pnpm build`. The script is integrated into the turborepo pipeline as the `build` task for `@next/swc`. ## Why? Developers often forget to run `pnpm swc-build-native` after pulling Rust changes, leading to confusing runtime errors. Conversely, rebuilding native binaries when nothing changed wastes significant time. This automates the decision so `pnpm build` always does the right thing. ## How? The `maybe-build-native.mjs` script runs as `@next/swc`'s `build` task and: 1. **Skips in CI** — exits immediately when the `CI` env var is set, since CI uses prebuilt `@next/swc-*` npm packages 2. **Finds the last version bump** — uses `git log -G` to locate the commit that last changed `"version":` in `packages/next/package.json` 3. **Checks for Rust changes** — compares `*.rs` files against the working tree (committed + staged + unstaged) since that version bump commit 4. **Rebuilds if needed** — runs `build-native` and copies/formats the generated TypeScript definitions 5. **Clears stale binaries** — if no Rust changes are detected, removes any leftover `.node` files from `native/` so the prebuilt npm packages are used instead Turborepo's `turbo.json` is configured with Rust-specific inputs (`crates/`, `Cargo.*`, `rust-toolchain`) and `CI` in `env` so CI and local builds get separate cache keys. ### Files changed - `packages/next-swc/maybe-build-native.mjs` — new script with the conditional build logic - `packages/next-swc/package.json` — added `"build": "node maybe-build-native.mjs"` - `packages/next-swc/turbo.json` — added `build` task with Rust inputs, `CI` env, and `native/*.node` outputs
Author
Parents
Loading