|
|
use anyhow::Result; |
|
|
use turbo_rcstr::RcStr; |
|
|
use turbo_tasks::{ResolvedVc, ValueDefault, Vc}; |
|
|
use turbo_tasks_fs::FileSystemPath; |
|
|
use turbopack_core::{ |
|
|
condition::ContextCondition, |
|
|
environment::Environment, |
|
|
resolve::{ |
|
|
options::{ImportMap, ResolvedMap}, |
|
|
plugin::{AfterResolvePlugin, BeforeResolvePlugin}, |
|
|
}, |
|
|
}; |
|
|
|
|
|
#[turbo_tasks::value(shared)] |
|
|
#[derive(Default, Clone)] |
|
|
pub struct ResolveOptionsContext { |
|
|
#[serde(default)] |
|
|
pub emulate_environment: Option<ResolvedVc<Environment>>, |
|
|
#[serde(default)] |
|
|
pub enable_types: bool, |
|
|
#[serde(default)] |
|
|
pub enable_typescript: bool, |
|
|
#[serde(default)] |
|
|
pub enable_react: bool, |
|
|
#[serde(default)] |
|
|
pub enable_node_native_modules: bool, |
|
|
#[serde(default)] |
|
|
|
|
|
pub enable_mjs_extension: bool, |
|
|
#[serde(default)] |
|
|
|
|
|
|
|
|
pub enable_node_modules: Option<FileSystemPath>, |
|
|
#[serde(default)] |
|
|
|
|
|
|
|
|
pub tsconfig_path: Option<FileSystemPath>, |
|
|
#[serde(default)] |
|
|
|
|
|
|
|
|
pub enable_node_externals: bool, |
|
|
|
|
|
|
|
|
pub enable_edge_node_externals: bool, |
|
|
#[serde(default)] |
|
|
|
|
|
pub browser: bool, |
|
|
#[serde(default)] |
|
|
|
|
|
pub module: bool, |
|
|
#[serde(default)] |
|
|
pub custom_conditions: Vec<RcStr>, |
|
|
#[serde(default)] |
|
|
pub custom_extensions: Option<Vec<RcStr>>, |
|
|
#[serde(default)] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pub import_map: Option<ResolvedVc<ImportMap>>, |
|
|
#[serde(default)] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pub fallback_import_map: Option<ResolvedVc<ImportMap>>, |
|
|
#[serde(default)] |
|
|
|
|
|
pub resolved_map: Option<ResolvedVc<ResolvedMap>>, |
|
|
#[serde(default)] |
|
|
|
|
|
|
|
|
pub rules: Vec<(ContextCondition, ResolvedVc<ResolveOptionsContext>)>, |
|
|
#[serde(default)] |
|
|
|
|
|
pub after_resolve_plugins: Vec<ResolvedVc<Box<dyn AfterResolvePlugin>>>, |
|
|
pub before_resolve_plugins: Vec<ResolvedVc<Box<dyn BeforeResolvePlugin>>>, |
|
|
|
|
|
pub loose_errors: bool, |
|
|
|
|
|
#[serde(default)] |
|
|
pub placeholder_for_future_extensions: (), |
|
|
} |
|
|
|
|
|
#[turbo_tasks::value_impl] |
|
|
impl ResolveOptionsContext { |
|
|
#[turbo_tasks::function] |
|
|
pub async fn with_types_enabled(self: Vc<Self>) -> Result<Vc<Self>> { |
|
|
let mut clone = self.owned().await?; |
|
|
clone.enable_types = true; |
|
|
clone.enable_typescript = true; |
|
|
Ok(Self::cell(clone)) |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#[turbo_tasks::function] |
|
|
pub async fn with_extended_import_map( |
|
|
self: Vc<Self>, |
|
|
import_map: Vc<ImportMap>, |
|
|
) -> Result<Vc<Self>> { |
|
|
let mut resolve_options_context = self.owned().await?; |
|
|
resolve_options_context.import_map = Some( |
|
|
resolve_options_context |
|
|
.import_map |
|
|
.map(|current_import_map| current_import_map.extend(import_map)) |
|
|
.unwrap_or(import_map) |
|
|
.to_resolved() |
|
|
.await?, |
|
|
); |
|
|
Ok(resolve_options_context.into()) |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#[turbo_tasks::function] |
|
|
pub async fn with_extended_fallback_import_map( |
|
|
self: Vc<Self>, |
|
|
fallback_import_map: Vc<ImportMap>, |
|
|
) -> Result<Vc<Self>> { |
|
|
let mut resolve_options_context = self.owned().await?; |
|
|
resolve_options_context.fallback_import_map = Some( |
|
|
resolve_options_context |
|
|
.fallback_import_map |
|
|
.map(|current_fallback_import_map| { |
|
|
current_fallback_import_map.extend(fallback_import_map) |
|
|
}) |
|
|
.unwrap_or(fallback_import_map) |
|
|
.to_resolved() |
|
|
.await?, |
|
|
); |
|
|
Ok(resolve_options_context.into()) |
|
|
} |
|
|
} |
|
|
|
|
|
#[turbo_tasks::value_impl] |
|
|
impl ValueDefault for ResolveOptionsContext { |
|
|
#[turbo_tasks::function] |
|
|
fn value_default() -> Vc<Self> { |
|
|
Self::cell(Default::default()) |
|
|
} |
|
|
} |
|
|
|