silverwolf-x's picture
download
raw
2.77 kB
use anyhow::{Result, bail};
use turbo_tasks::{ResolvedVc, Vc};
use turbopack::{ModuleAssetContext, transition::Transition};
use turbopack_core::{
context::{AssetContext, ProcessResult},
reference_type::ReferenceType,
source::Source,
};
use turbopack_ecmascript::chunk::EcmascriptChunkPlaceable;
use super::NextDynamicEntryModule;
/// This transition is used to create the marker asset for a next/dynamic
/// import. Optionally, it can also apply another transition (i.e. to the client context).
///
/// This will get picked up during module processing and will be used to
/// create the dynamic entry, and the dynamic manifest entry.
#[turbo_tasks::value]
pub struct NextDynamicTransition {
client_transition: Option<ResolvedVc<Box<dyn Transition>>>,
}
#[turbo_tasks::value_impl]
impl NextDynamicTransition {
/// Create a transition that only add a marker `NextDynamicEntryModule`.
#[turbo_tasks::function]
pub fn new_marker() -> Vc<Self> {
NextDynamicTransition {
client_transition: None,
}
.cell()
}
/// Create a transition that applies `client_transition` and adds a marker
/// `NextDynamicEntryModule`.
#[turbo_tasks::function]
pub fn new_client(client_transition: ResolvedVc<Box<dyn Transition>>) -> Vc<Self> {
NextDynamicTransition {
client_transition: Some(client_transition),
}
.cell()
}
}
#[turbo_tasks::value_impl]
impl Transition for NextDynamicTransition {
#[turbo_tasks::function]
async fn process(
self: Vc<Self>,
source: Vc<Box<dyn Source>>,
module_asset_context: Vc<ModuleAssetContext>,
_reference_type: ReferenceType,
) -> Result<Vc<ProcessResult>> {
let module_asset_context = self.process_context(module_asset_context);
let module = match self.await?.client_transition {
Some(client_transition) => {
client_transition.process(source, module_asset_context, ReferenceType::Undefined)
}
None => module_asset_context.process(source, ReferenceType::Undefined),
};
Ok(match &*module.try_into_module().await? {
Some(client_module) => {
let Some(client_module) =
ResolvedVc::try_sidecast::<Box<dyn EcmascriptChunkPlaceable>>(*client_module)
else {
bail!("not an ecmascript client_module");
};
ProcessResult::Module(ResolvedVc::upcast(
NextDynamicEntryModule::new(*client_module)
.to_resolved()
.await?,
))
}
None => ProcessResult::Ignore,
}
.cell())
}
}

Xet Storage Details

Size:
2.77 kB
·
Xet hash:
3b60cbc2b097a8b1a6fca1455f8bb3ce1dc5e5c9d4b8c26ad922deea5632bf94

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.