|
|
use anyhow::{Result, bail}; |
|
|
use turbo_rcstr::RcStr; |
|
|
use turbo_tasks::{ResolvedVc, Vc}; |
|
|
use turbo_tasks_fs::{FileSystemPath, glob::Glob}; |
|
|
|
|
|
use crate::{ |
|
|
compile_time_info::CompileTimeInfo, |
|
|
ident::Layer, |
|
|
issue::module::emit_unknown_module_type_error, |
|
|
module::{Module, OptionModule}, |
|
|
reference_type::ReferenceType, |
|
|
resolve::{ModuleResolveResult, ResolveResult, options::ResolveOptions, parse::Request}, |
|
|
source::Source, |
|
|
}; |
|
|
|
|
|
#[turbo_tasks::value(shared)] |
|
|
pub enum ProcessResult { |
|
|
|
|
|
Module(ResolvedVc<Box<dyn Module>>), |
|
|
|
|
|
|
|
|
Unknown(ResolvedVc<Box<dyn Source>>), |
|
|
|
|
|
|
|
|
|
|
|
Ignore, |
|
|
} |
|
|
|
|
|
#[turbo_tasks::value_impl] |
|
|
impl ProcessResult { |
|
|
#[turbo_tasks::function] |
|
|
pub fn module(&self) -> Result<Vc<Box<dyn Module>>> { |
|
|
match *self { |
|
|
ProcessResult::Module(m) => Ok(*m), |
|
|
ProcessResult::Ignore => { |
|
|
bail!("Expected process result to be a module, but it was ignored") |
|
|
} |
|
|
ProcessResult::Unknown(_) => { |
|
|
bail!("Expected process result to be a module, but it could not be processed") |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
#[turbo_tasks::function] |
|
|
pub async fn try_into_module(&self) -> Result<Vc<OptionModule>> { |
|
|
Ok(Vc::cell(match self { |
|
|
ProcessResult::Module(module) => Some(*module), |
|
|
ProcessResult::Unknown(source) => { |
|
|
emit_unknown_module_type_error(**source).await?; |
|
|
None |
|
|
} |
|
|
ProcessResult::Ignore => None, |
|
|
})) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[turbo_tasks::value_trait] |
|
|
pub trait AssetContext { |
|
|
|
|
|
#[turbo_tasks::function] |
|
|
fn compile_time_info(self: Vc<Self>) -> Vc<CompileTimeInfo>; |
|
|
|
|
|
|
|
|
fn layer(&self) -> Layer; |
|
|
|
|
|
|
|
|
#[turbo_tasks::function] |
|
|
fn resolve_options( |
|
|
self: Vc<Self>, |
|
|
origin_path: FileSystemPath, |
|
|
reference_type: ReferenceType, |
|
|
) -> Vc<ResolveOptions>; |
|
|
|
|
|
|
|
|
#[turbo_tasks::function] |
|
|
fn resolve_asset( |
|
|
self: Vc<Self>, |
|
|
origin_path: FileSystemPath, |
|
|
request: Vc<Request>, |
|
|
resolve_options: Vc<ResolveOptions>, |
|
|
reference_type: ReferenceType, |
|
|
) -> Vc<ModuleResolveResult>; |
|
|
|
|
|
|
|
|
#[turbo_tasks::function] |
|
|
fn process( |
|
|
self: Vc<Self>, |
|
|
asset: Vc<Box<dyn Source>>, |
|
|
reference_type: ReferenceType, |
|
|
) -> Vc<ProcessResult>; |
|
|
|
|
|
|
|
|
#[turbo_tasks::function] |
|
|
fn process_resolve_result( |
|
|
self: Vc<Self>, |
|
|
result: Vc<ResolveResult>, |
|
|
reference_type: ReferenceType, |
|
|
) -> Vc<ModuleResolveResult>; |
|
|
|
|
|
|
|
|
#[turbo_tasks::function] |
|
|
fn with_transition(self: Vc<Self>, transition: RcStr) -> Vc<Box<dyn AssetContext>>; |
|
|
|
|
|
#[turbo_tasks::function] |
|
|
fn side_effect_free_packages(self: Vc<Self>) -> Vc<Glob>; |
|
|
} |
|
|
|