From 9d0f73658156565912b443140910fe38be42a05f Mon Sep 17 00:00:00 2001 From: Benjamin Woodruff Date: Mon, 6 Jan 2025 15:17:51 -0800 Subject: [PATCH] refactor(turbopack-core): Use ResolvedVc in ContextCondition --- crates/next-core/src/next_client/context.rs | 24 ++++++++++---- crates/next-core/src/next_server/context.rs | 32 ++++++++++++------- crates/next-core/src/util.rs | 5 ++- .../crates/turbopack-core/src/condition.rs | 6 ++-- .../src/resolve_options_context.rs | 2 +- 5 files changed, 46 insertions(+), 23 deletions(-) diff --git a/crates/next-core/src/next_client/context.rs b/crates/next-core/src/next_client/context.rs index 77e35284c3d36..3d2336f02d46d 100644 --- a/crates/next-core/src/next_client/context.rs +++ b/crates/next-core/src/next_client/context.rs @@ -212,12 +212,22 @@ pub async fn get_client_resolve_options_context( .cell()) } -fn internal_assets_conditions() -> ContextCondition { - ContextCondition::any(vec![ - ContextCondition::InPath(next_js_fs().root()), - ContextCondition::InPath(turbopack_ecmascript_runtime::embed_fs().root()), - ContextCondition::InPath(turbopack_node::embed_js::embed_fs().root()), - ]) +async fn internal_assets_conditions() -> Result { + Ok(ContextCondition::any(vec![ + ContextCondition::InPath(next_js_fs().root().to_resolved().await?), + ContextCondition::InPath( + turbopack_ecmascript_runtime::embed_fs() + .root() + .to_resolved() + .await?, + ), + ContextCondition::InPath( + turbopack_node::embed_js::embed_fs() + .root() + .to_resolved() + .await?, + ), + ])) } #[turbo_tasks::function] @@ -387,7 +397,7 @@ pub async fn get_client_module_options_context( foreign_codes_options_context.resolved_cell(), ), ( - internal_assets_conditions(), + internal_assets_conditions().await?, internal_context.resolved_cell(), ), ], diff --git a/crates/next-core/src/next_server/context.rs b/crates/next-core/src/next_server/context.rs index 0273af182d3c6..5df6583b073b5 100644 --- a/crates/next-core/src/next_server/context.rs +++ b/crates/next-core/src/next_server/context.rs @@ -403,12 +403,22 @@ pub async fn get_server_compile_time_info( /// turbopack itself and user config should not try to leak this. However, /// currently we apply few transform options subject to next.js's configuration /// even if it's embedded assets. -fn internal_assets_conditions() -> ContextCondition { - ContextCondition::any(vec![ - ContextCondition::InPath(next_js_fs().root()), - ContextCondition::InPath(turbopack_ecmascript_runtime::embed_fs().root()), - ContextCondition::InPath(turbopack_node::embed_js::embed_fs().root()), - ]) +async fn internal_assets_conditions() -> Result { + Ok(ContextCondition::any(vec![ + ContextCondition::InPath(next_js_fs().root().to_resolved().await?), + ContextCondition::InPath( + turbopack_ecmascript_runtime::embed_fs() + .root() + .to_resolved() + .await?, + ), + ContextCondition::InPath( + turbopack_node::embed_js::embed_fs() + .root() + .to_resolved() + .await?, + ), + ])) } #[turbo_tasks::function] @@ -648,7 +658,7 @@ pub async fn get_server_module_options_context( foreign_code_module_options_context.resolved_cell(), ), ( - internal_assets_conditions(), + internal_assets_conditions().await?, internal_module_options_context.resolved_cell(), ), ], @@ -713,7 +723,7 @@ pub async fn get_server_module_options_context( foreign_code_module_options_context.resolved_cell(), ), ( - internal_assets_conditions(), + internal_assets_conditions().await?, internal_module_options_context.resolved_cell(), ), ], @@ -789,7 +799,7 @@ pub async fn get_server_module_options_context( foreign_code_module_options_context.resolved_cell(), ), ( - internal_assets_conditions(), + internal_assets_conditions().await?, internal_module_options_context.resolved_cell(), ), ], @@ -864,7 +874,7 @@ pub async fn get_server_module_options_context( foreign_code_module_options_context.resolved_cell(), ), ( - internal_assets_conditions(), + internal_assets_conditions().await?, internal_module_options_context.resolved_cell(), ), ], @@ -961,7 +971,7 @@ pub async fn get_server_module_options_context( foreign_code_module_options_context.resolved_cell(), ), ( - internal_assets_conditions(), + internal_assets_conditions().await?, internal_module_options_context.resolved_cell(), ), ], diff --git a/crates/next-core/src/util.rs b/crates/next-core/src/util.rs index b1191f04625cb..e70ee92cdb190 100644 --- a/crates/next-core/src/util.rs +++ b/crates/next-core/src/util.rs @@ -121,7 +121,10 @@ pub async fn foreign_code_context_condition( // of the `node_modules` specific resolve options (the template files are // technically node module files). let not_next_template_dir = ContextCondition::not(ContextCondition::InPath( - get_next_package(*project_path).join(NEXT_TEMPLATE_PATH.into()), + get_next_package(*project_path) + .join(NEXT_TEMPLATE_PATH.into()) + .to_resolved() + .await?, )); let result = ContextCondition::all(vec![ diff --git a/turbopack/crates/turbopack-core/src/condition.rs b/turbopack/crates/turbopack-core/src/condition.rs index bd0060de9e6e7..9085d4c9ede08 100644 --- a/turbopack/crates/turbopack-core/src/condition.rs +++ b/turbopack/crates/turbopack-core/src/condition.rs @@ -1,16 +1,16 @@ use anyhow::Result; use futures::{stream, StreamExt}; use serde::{Deserialize, Serialize}; -use turbo_tasks::{trace::TraceRawVcs, Vc}; +use turbo_tasks::{trace::TraceRawVcs, NonLocalValue, ResolvedVc}; use turbo_tasks_fs::FileSystemPath; -#[derive(Debug, Clone, Serialize, Deserialize, TraceRawVcs, PartialEq, Eq)] +#[derive(Debug, Clone, Serialize, Deserialize, TraceRawVcs, PartialEq, Eq, NonLocalValue)] pub enum ContextCondition { All(Vec), Any(Vec), Not(Box), InDirectory(String), - InPath(Vc), + InPath(ResolvedVc), } impl ContextCondition { diff --git a/turbopack/crates/turbopack-resolve/src/resolve_options_context.rs b/turbopack/crates/turbopack-resolve/src/resolve_options_context.rs index 4607b1ff479a8..b7e009fab215f 100644 --- a/turbopack/crates/turbopack-resolve/src/resolve_options_context.rs +++ b/turbopack/crates/turbopack-resolve/src/resolve_options_context.rs @@ -11,7 +11,7 @@ use turbopack_core::{ }, }; -#[turbo_tasks::value(shared, local)] +#[turbo_tasks::value(shared)] #[derive(Default, Clone)] pub struct ResolveOptionsContext { #[serde(default)]