Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix "any" context condition implementation #5794

Merged
merged 2 commits into from
Aug 24, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/turbopack/src/condition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ impl ContextCondition {
// False positive.
#[allow(clippy::manual_try_fold)]
stream::iter(conditions)
.fold(Ok(true), |acc, c| async move {
.fold(Ok(false), |acc, c| async move {
Ok(acc? || c.matches(path).await?)
})
.await
Expand Down
40 changes: 23 additions & 17 deletions crates/turbopack/src/evaluate_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ use turbopack_core::{
use turbopack_node::execution_context::ExecutionContext;

use crate::{
module_options::ModuleOptionsContext, resolve_options_context::ResolveOptionsContext,
transition::TransitionsByName, ModuleAssetContext,
condition::ContextCondition, module_options::ModuleOptionsContext,
resolve_options_context::ResolveOptionsContext, transition::TransitionsByName,
ModuleAssetContext,
};

#[turbo_tasks::function]
Expand Down Expand Up @@ -49,31 +50,36 @@ pub async fn node_evaluate_asset_context(
} else {
"development".to_string()
};
let resolve_options_context = ResolveOptionsContext {
sokra marked this conversation as resolved.
Show resolved Hide resolved
enable_node_modules: Some(execution_context.project_path().root().resolve().await?),
enable_node_externals: true,
enable_node_native_modules: true,
custom_conditions: vec![node_env.clone(), "node".to_string()],
..Default::default()
};
let resolve_options_context = ResolveOptionsContext {
enable_typescript: true,
import_map: Some(import_map),
rules: vec![(
ContextCondition::InDirectory("node_modules".to_string()),
resolve_options_context.clone().cell(),
)],
..resolve_options_context
}
.cell();
Ok(Vc::upcast(ModuleAssetContext::new(
transitions.unwrap_or_else(|| Vc::cell(Default::default())),
CompileTimeInfo::builder(node_build_environment())
.defines(
compile_time_defines!(
process.turbopack = true,
process.env.NODE_ENV = node_env.clone(),
)
.cell(),
compile_time_defines!(process.turbopack = true, process.env.NODE_ENV = node_env,)
.cell(),
)
.cell(),
ModuleOptionsContext {
enable_typescript_transform: Some(Default::default()),
..Default::default()
}
.cell(),
ResolveOptionsContext {
enable_typescript: true,
enable_node_modules: Some(execution_context.project_path().root().resolve().await?),
enable_node_externals: true,
enable_node_native_modules: true,
custom_conditions: vec![node_env, "node".to_string()],
import_map: Some(import_map),
..Default::default()
}
.cell(),
resolve_options_context,
)))
}
Loading