| use anyhow::Result; |
| use turbo_rcstr::rcstr; |
| use turbo_tasks::{ResolvedVc, Vc}; |
| use turbopack_core::{ |
| asset::{Asset, AssetContent}, |
| chunk::{ChunkableModule, ChunkingContext, availability_info::AvailabilityInfo}, |
| ident::AssetIdent, |
| module::Module, |
| module_graph::ModuleGraph, |
| reference::{ModuleReferences, SingleModuleReference}, |
| }; |
|
|
| use crate::async_chunk::chunk_item::AsyncLoaderChunkItem; |
|
|
| |
| |
| #[turbo_tasks::value] |
| pub struct AsyncLoaderModule { |
| pub inner: ResolvedVc<Box<dyn ChunkableModule>>, |
| pub chunking_context: ResolvedVc<Box<dyn ChunkingContext>>, |
| pub availability_info: AvailabilityInfo, |
| } |
|
|
| #[turbo_tasks::value_impl] |
| impl AsyncLoaderModule { |
| #[turbo_tasks::function] |
| pub fn new( |
| module: ResolvedVc<Box<dyn ChunkableModule>>, |
| chunking_context: ResolvedVc<Box<dyn ChunkingContext>>, |
| availability_info: AvailabilityInfo, |
| ) -> Vc<Self> { |
| Self::cell(AsyncLoaderModule { |
| inner: module, |
| chunking_context, |
| availability_info, |
| }) |
| } |
|
|
| #[turbo_tasks::function] |
| pub fn asset_ident_for(module: Vc<Box<dyn ChunkableModule>>) -> Vc<AssetIdent> { |
| module.ident().with_modifier(rcstr!("async loader")) |
| } |
| } |
|
|
| #[turbo_tasks::value_impl] |
| impl Module for AsyncLoaderModule { |
| #[turbo_tasks::function] |
| fn ident(&self) -> Vc<AssetIdent> { |
| Self::asset_ident_for(*self.inner) |
| } |
|
|
| #[turbo_tasks::function] |
| async fn references(self: Vc<Self>) -> Result<Vc<ModuleReferences>> { |
| Ok(Vc::cell(vec![ResolvedVc::upcast( |
| SingleModuleReference::new( |
| *ResolvedVc::upcast(self.await?.inner), |
| rcstr!("async module"), |
| ) |
| .to_resolved() |
| .await?, |
| )])) |
| } |
| } |
|
|
| #[turbo_tasks::value_impl] |
| impl Asset for AsyncLoaderModule { |
| #[turbo_tasks::function] |
| fn content(&self) -> Vc<AssetContent> { |
| panic!("content() should not be called"); |
| } |
| } |
|
|
| #[turbo_tasks::value_impl] |
| impl ChunkableModule for AsyncLoaderModule { |
| #[turbo_tasks::function] |
| fn as_chunk_item( |
| self: ResolvedVc<Self>, |
| module_graph: ResolvedVc<ModuleGraph>, |
| chunking_context: ResolvedVc<Box<dyn ChunkingContext>>, |
| ) -> Vc<Box<dyn turbopack_core::chunk::ChunkItem>> { |
| Vc::upcast( |
| AsyncLoaderChunkItem { |
| chunking_context, |
| module_graph, |
| module: self, |
| } |
| .cell(), |
| ) |
| } |
| } |
|
|