Skip to content

Commit 0b74ff9

Browse files
authored
feat: Acquire a lockfile on distDir in next dev and next build (#84428)
#83961 lets you run both `next dev` and `next build` at the same time, however it's still problematic to run two instances of `next dev` or two instances of `next build` at the same time with the same `distDir`. This sort of thing can happen to anyone by accident, but we've seen reports of this sort of behavior with AI agents. #84378 adds a lockfile around just the persistent cache database in Turbopack, which helps, but it's not the only reason this is problematic, so we also need a lock around all of Next.js itself. I was not able to find a cross-platform lockfile implementation in node that I felt was of sufficient quality, so on POSIX platforms this uses the recently-stabilized Rust stdlib implementation, which appears to be derived from rustc's own lockfile implementation, which has seen widespread use/deployment. On Windows, since we'd rather have an advisory lock than a mandatory one, this emulates that by instead opening a file with write permissions, and a sharing mode that prohibits shared write access. That means that other processes can safely read the (empty) lockfile without blowing up. <img width="500" src="https://github.com/user-attachments/assets/1ee4a6c6-2280-4f64-8bf2-ec5369c26db1" /> <img width="500" src="https://github.com/user-attachments/assets/2b04b566-c0b4-42ce-af34-912f3f6afa72" /> Tested on Windows as well: <img width="1224" height="690" alt="Screenshot 2025-10-07 at 5 44 33 PM" src="https://github.com/user-attachments/assets/e36085b6-9c32-40ac-aca6-4c83e2a53842" />
1 parent ab99f9a commit 0b74ff9

File tree

18 files changed

+542
-57
lines changed

18 files changed

+542
-57
lines changed

Cargo.lock

Lines changed: 89 additions & 36 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/napi/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,8 @@ turbopack-trace-utils = { workspace = true }
123123
turbopack-trace-server = { workspace = true }
124124
turbopack-ecmascript-plugins = { workspace = true, optional = true }
125125

126+
[target.'cfg(windows)'.dependencies]
127+
windows-sys = "0.60"
126128

127129
# Dependencies for the wasm32 build.
128130
[target.'cfg(target_arch = "wasm32")'.dependencies]

crates/napi/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,10 @@ use swc_core::{
4343
base::{Compiler, TransformOutput},
4444
common::{FilePathMapping, SourceMap},
4545
};
46+
4647
#[cfg(not(target_arch = "wasm32"))]
4748
pub mod css;
49+
pub mod lockfile;
4850
pub mod mdx;
4951
pub mod minify;
5052
#[cfg(not(target_arch = "wasm32"))]

0 commit comments

Comments
 (0)