Skip to content

Commit

Permalink
refactor(turbopack-core): Use ResolvedVc in ContextCondition
Browse files Browse the repository at this point in the history
  • Loading branch information
bgw committed Jan 10, 2025
1 parent e0d0daa commit 9d0f736
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 23 deletions.
24 changes: 17 additions & 7 deletions crates/next-core/src/next_client/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<ContextCondition> {
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]
Expand Down Expand Up @@ -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(),
),
],
Expand Down
32 changes: 21 additions & 11 deletions crates/next-core/src/next_server/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<ContextCondition> {
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]
Expand Down Expand Up @@ -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(),
),
],
Expand Down Expand Up @@ -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(),
),
],
Expand Down Expand Up @@ -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(),
),
],
Expand Down Expand Up @@ -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(),
),
],
Expand Down Expand Up @@ -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(),
),
],
Expand Down
5 changes: 4 additions & 1 deletion crates/next-core/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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![
Expand Down
6 changes: 3 additions & 3 deletions turbopack/crates/turbopack-core/src/condition.rs
Original file line number Diff line number Diff line change
@@ -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<ContextCondition>),
Any(Vec<ContextCondition>),
Not(Box<ContextCondition>),
InDirectory(String),
InPath(Vc<FileSystemPath>),
InPath(ResolvedVc<FileSystemPath>),
}

impl ContextCondition {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use turbopack_core::{
},
};

#[turbo_tasks::value(shared, local)]
#[turbo_tasks::value(shared)]
#[derive(Default, Clone)]
pub struct ResolveOptionsContext {
#[serde(default)]
Expand Down

0 comments on commit 9d0f736

Please sign in to comment.