Unverified Commit 07847a4b authored by Niklas Mischkulnig's avatar Niklas Mischkulnig Committed by GitHub

Turbopack: skip next-server.js.nft.json for Vercel (#83299)

On Vercel, we only need `next-minimal-server.js.nft.json`

Also, `ci_has_next_support` was implemented correctly, it previously read from `nextConfig.env`, instead of the real (full) environment variables from the system.
parent f37f11ef
...@@ -38,18 +38,28 @@ enum ServerNftType { ...@@ -38,18 +38,28 @@ enum ServerNftType {
#[turbo_tasks::function] #[turbo_tasks::function]
pub async fn next_server_nft_assets(project: Vc<Project>) -> Result<Vc<OutputAssets>> { pub async fn next_server_nft_assets(project: Vc<Project>) -> Result<Vc<OutputAssets>> {
Ok(Vc::cell(vec![ let has_next_support = *project.ci_has_next_support().await?;
ResolvedVc::upcast( let is_standalone = *project.next_config().is_standalone().await?;
ServerNftJsonAsset::new(project, ServerNftType::Full)
let minimal = ResolvedVc::upcast(
ServerNftJsonAsset::new(project, ServerNftType::Minimal)
.to_resolved() .to_resolved()
.await?, .await?,
), );
if has_next_support && !is_standalone {
// When deploying to Vercel, we only need next-minimal-server.js.nft.json
Ok(Vc::cell(vec![minimal]))
} else {
Ok(Vc::cell(vec![
minimal,
ResolvedVc::upcast( ResolvedVc::upcast(
ServerNftJsonAsset::new(project, ServerNftType::Minimal) ServerNftJsonAsset::new(project, ServerNftType::Full)
.to_resolved() .to_resolved()
.await?, .await?,
), ),
])) ]))
}
} }
#[turbo_tasks::value] #[turbo_tasks::value]
...@@ -248,7 +258,7 @@ impl ServerNftJsonAsset { ...@@ -248,7 +258,7 @@ impl ServerNftJsonAsset {
#[turbo_tasks::function] #[turbo_tasks::function]
async fn ignores(&self) -> Result<Vc<Glob>> { async fn ignores(&self) -> Result<Vc<Glob>> {
let is_standalone = *self.project.next_config().is_standalone().await?; let is_standalone = *self.project.next_config().is_standalone().await?;
let has_next_support = *self.project.next_config().ci_has_next_support().await?; let has_next_support = *self.project.ci_has_next_support().await?;
let project_path = self.project.project_path().owned().await?; let project_path = self.project.project_path().owned().await?;
let output_file_tracing_excludes = self let output_file_tracing_excludes = self
......
...@@ -764,6 +764,13 @@ impl Project { ...@@ -764,6 +764,13 @@ impl Project {
*self.env *self.env
} }
#[turbo_tasks::function]
pub async fn ci_has_next_support(&self) -> Result<Vc<bool>> {
Ok(Vc::cell(
self.env.read(rcstr!("NOW_BUILDER")).await?.is_some(),
))
}
#[turbo_tasks::function] #[turbo_tasks::function]
pub(super) fn current_node_js_version(&self) -> Vc<NodeJsVersion> { pub(super) fn current_node_js_version(&self) -> Vc<NodeJsVersion> {
NodeJsVersion::Static(ResolvedVc::cell(self.current_node_js_version.clone())).cell() NodeJsVersion::Static(ResolvedVc::cell(self.current_node_js_version.clone())).cell()
......
...@@ -1328,11 +1328,6 @@ impl NextConfig { ...@@ -1328,11 +1328,6 @@ impl NextConfig {
Vc::cell(self.output == Some(OutputType::Standalone)) Vc::cell(self.output == Some(OutputType::Standalone))
} }
#[turbo_tasks::function]
pub fn ci_has_next_support(&self) -> Vc<bool> {
Vc::cell(self.env.contains_key("NOW_BUILDER"))
}
#[turbo_tasks::function] #[turbo_tasks::function]
pub fn cache_handler(&self, project_path: FileSystemPath) -> Result<Vc<OptionFileSystemPath>> { pub fn cache_handler(&self, project_path: FileSystemPath) -> Result<Vc<OptionFileSystemPath>> {
if let Some(handler) = &self.cache_handler { if let Some(handler) = &self.cache_handler {
......
...@@ -99,6 +99,7 @@ describe('required server files app router', () => { ...@@ -99,6 +99,7 @@ describe('required server files app router', () => {
await setupNext({ nextEnv: true, minimalMode: true }) await setupNext({ nextEnv: true, minimalMode: true })
}) })
afterAll(async () => { afterAll(async () => {
delete process.env.NOW_BUILDER
delete process.env.NEXT_PRIVATE_TEST_HEADERS delete process.env.NEXT_PRIVATE_TEST_HEADERS
await next.destroy() await next.destroy()
if (server) await killApp(server) if (server) await killApp(server)
......
...@@ -112,6 +112,7 @@ describe('required server files app router', () => { ...@@ -112,6 +112,7 @@ describe('required server files app router', () => {
}) })
afterAll(async () => { afterAll(async () => {
delete process.env.NOW_BUILDER
delete process.env.NEXT_PRIVATE_TEST_HEADERS delete process.env.NEXT_PRIVATE_TEST_HEADERS
await next.destroy() await next.destroy()
if (server) await killApp(server) if (server) await killApp(server)
......
...@@ -161,6 +161,7 @@ describe('required server files', () => { ...@@ -161,6 +161,7 @@ describe('required server files', () => {
}) })
afterAll(async () => { afterAll(async () => {
delete process.env.NOW_BUILDER
delete process.env.NEXT_PRIVATE_TEST_HEADERS delete process.env.NEXT_PRIVATE_TEST_HEADERS
await next.destroy() await next.destroy()
}) })
......
...@@ -85,6 +85,7 @@ describe('minimal-mode-response-cache', () => { ...@@ -85,6 +85,7 @@ describe('minimal-mode-response-cache', () => {
appPort = `http://127.0.0.1:${port}` appPort = `http://127.0.0.1:${port}`
}) })
afterAll(async () => { afterAll(async () => {
delete process.env.NOW_BUILDER
delete process.env.NEXT_PRIVATE_TEST_HEADERS delete process.env.NEXT_PRIVATE_TEST_HEADERS
await next.destroy() await next.destroy()
if (server) await killApp(server) if (server) await killApp(server)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment