Skip to content

Commit

Permalink
Turbopack: Fix Next.js in cross-bundler benchmarks (vercel/turborepo#…
Browse files Browse the repository at this point in the history
…7241)

This:

- Drops Next.js 11 from cross-bundler benchmarks
- Adds Next.js 14 to cross-bundler benchmarks
- Uses support for port `0` to bind to a free port in Next.js 13+


Closes PACK-2371
  • Loading branch information
wbinnssmith authored Feb 2, 2024
1 parent a2cbda3 commit 6fe0a6d
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 16 deletions.
49 changes: 42 additions & 7 deletions crates/turbopack-bench/src/bundlers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,27 @@ pub fn get_bundlers() -> Vec<Box<dyn Bundler>> {
true,
RenderType::ServerSideRenderedWithEvents,
)),
Box::new(NextJs::new(
NextJsVersion::V14,
"Next.js 14 Turbo SSR",
"/page",
true,
RenderType::ServerSidePrerendered,
)),
Box::new(NextJs::new(
NextJsVersion::V14,
"Next.js 14 Turbo RSC",
"/app",
true,
RenderType::ServerSideRenderedWithEvents,
)),
Box::new(NextJs::new(
NextJsVersion::V14,
"Next.js 14 Turbo RCC",
"/client",
true,
RenderType::ServerSidePrerendered,
)),
Box::new(NextJs::new(
NextJsVersion::V13,
"Next.js 13 Turbo SSR",
Expand Down Expand Up @@ -137,6 +158,27 @@ pub fn get_bundlers() -> Vec<Box<dyn Bundler>> {
false,
RenderType::ServerSideRenderedWithEvents,
)),
Box::new(NextJs::new(
NextJsVersion::V14,
"Next.js 14 webpack SSR",
"/page",
false,
RenderType::ServerSidePrerendered,
)),
Box::new(NextJs::new(
NextJsVersion::V14,
"Next.js 14 webpack RSC",
"/app",
false,
RenderType::ServerSideRenderedWithEvents,
)),
Box::new(NextJs::new(
NextJsVersion::V14,
"Next.js 14 webpack RCC",
"/client",
false,
RenderType::ServerSidePrerendered,
)),
Box::new(NextJs::new(
NextJsVersion::V13,
"Next.js 13 webpack SSR",
Expand Down Expand Up @@ -165,13 +207,6 @@ pub fn get_bundlers() -> Vec<Box<dyn Bundler>> {
false,
RenderType::ServerSidePrerendered,
)),
Box::new(NextJs::new(
NextJsVersion::V11,
"Next.js 11 webpack SSR",
"/page",
false,
RenderType::ServerSidePrerendered,
)),
Box::new(Parcel {}),
Box::new(Vite::new(false, false)),
Box::new(Vite::new(true, false)),
Expand Down
26 changes: 17 additions & 9 deletions crates/turbopack-bench/src/bundlers/nextjs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ use crate::{

#[derive(Debug)]
pub enum NextJsVersion {
V11,
V12,
V13,
V14,
Canary,
}

Expand Down Expand Up @@ -102,11 +102,16 @@ impl Bundler for NextJs {
.unwrap(),
"dev",
"--port",
// Next.js currently has a bug where requests for port 0 are ignored and it falls
// back to the default 3000. Use portpicker instead.
&portpicker::pick_unused_port()
.ok_or_else(|| anyhow!("failed to pick unused port"))?
.to_string(),
&match self.version {
NextJsVersion::V12 => {
// Next.js 12 has a bug where requests for port 0 are ignored and it falls
// back to the default 3000. Use portpicker instead.
portpicker::pick_unused_port()
.ok_or_else(|| anyhow!("failed to pick unused port"))?
}
_ => 0,
}
.to_string(),
])
.current_dir(test_dir)
.stdout(Stdio::piped())
Expand All @@ -120,7 +125,10 @@ impl Bundler for NextJs {
proc.stdout
.as_mut()
.ok_or_else(|| anyhow!("missing stdout"))?,
Regex::new("started server.*url: (.*)")?,
match self.version {
NextJsVersion::V12 => Regex::new("started server.*url: (.*)"),
_ => Regex::new("- Local:\\s+(.*)"),
}?,
)
.ok_or_else(|| anyhow!("failed to find devserver address"))?;

Expand All @@ -140,9 +148,9 @@ impl NextJsVersion {
/// Returns the version of Next.js to install from npm.
pub fn version(&self) -> &'static str {
match self {
NextJsVersion::V11 => "^11",
NextJsVersion::V12 => "^12",
NextJsVersion::V13 => "^13",
NextJsVersion::V14 => "^14",
NextJsVersion::Canary => "canary",
}
}
Expand All @@ -151,9 +159,9 @@ impl NextJsVersion {
/// of Next.js.
pub fn react_version(&self) -> &'static str {
match self {
NextJsVersion::V11 => "^17.0.2",
NextJsVersion::V12 => "^18.2.0",
NextJsVersion::V13 => "^18.2.0",
NextJsVersion::V14 => "^18.2.0",
NextJsVersion::Canary => "^18.2.0",
}
}
Expand Down

0 comments on commit 6fe0a6d

Please sign in to comment.