Buckets:
| use std::io::Write; | |
| use anyhow::Result; | |
| use turbo_rcstr::rcstr; | |
| use turbo_tasks::{ResolvedVc, ValueToString, Vc}; | |
| use turbo_tasks_fs::{FileSystem, VirtualFileSystem, rope::RopeBuilder}; | |
| use turbopack_core::{ | |
| asset::{Asset, AssetContent}, | |
| chunk::{ | |
| AsyncModuleInfo, ChunkItem, ChunkableModule, ChunkingContext, ChunkingType, | |
| EvaluatableAsset, | |
| }, | |
| ident::AssetIdent, | |
| module::{Module, ModuleSideEffects}, | |
| module_graph::ModuleGraph, | |
| reference::{ModuleReference, ModuleReferences}, | |
| resolve::ModuleResolveResult, | |
| source::OptionSource, | |
| }; | |
| use turbopack_ecmascript::{ | |
| chunk::{ | |
| EcmascriptChunkItemContent, EcmascriptChunkItemOptions, EcmascriptChunkPlaceable, | |
| EcmascriptExports, ecmascript_chunk_item, | |
| }, | |
| runtime_functions::TURBOPACK_REQUIRE, | |
| utils::StringifyJs, | |
| }; | |
| /// Each entry point in the HMR system has an ident with a different nested asset. | |
| /// This produces the 'base' ident for the HMR entry point, which is then modified | |
| async fn hmr_entry_point_base_ident() -> Result<Vc<AssetIdent>> { | |
| Ok(AssetIdent::from_path( | |
| VirtualFileSystem::new_with_name(rcstr!("hmr-entry")) | |
| .root() | |
| .await? | |
| .join("hmr-entry.js")?, | |
| )) | |
| } | |
| pub struct HmrEntryModule { | |
| pub ident: ResolvedVc<AssetIdent>, | |
| pub module: ResolvedVc<Box<dyn ChunkableModule>>, | |
| } | |
| impl HmrEntryModule { | |
| pub fn new( | |
| ident: ResolvedVc<AssetIdent>, | |
| module: ResolvedVc<Box<dyn ChunkableModule>>, | |
| ) -> Vc<Self> { | |
| Self { ident, module }.cell() | |
| } | |
| } | |
| impl Module for HmrEntryModule { | |
| fn ident(&self) -> Vc<AssetIdent> { | |
| hmr_entry_point_base_ident().with_asset(rcstr!("ENTRY"), *self.ident) | |
| } | |
| fn source(&self) -> Vc<OptionSource> { | |
| Vc::cell(None) | |
| } | |
| async fn references(&self) -> Result<Vc<ModuleReferences>> { | |
| Ok(Vc::cell(vec![ResolvedVc::upcast( | |
| HmrEntryModuleReference::new(Vc::upcast(*self.module)) | |
| .to_resolved() | |
| .await?, | |
| )])) | |
| } | |
| fn side_effects(self: Vc<Self>) -> Vc<ModuleSideEffects> { | |
| ModuleSideEffects::SideEffectful.cell() | |
| } | |
| } | |
| impl ChunkableModule for HmrEntryModule { | |
| fn as_chunk_item( | |
| self: ResolvedVc<Self>, | |
| module_graph: ResolvedVc<ModuleGraph>, | |
| chunking_context: ResolvedVc<Box<dyn ChunkingContext>>, | |
| ) -> Vc<Box<dyn ChunkItem>> { | |
| ecmascript_chunk_item(ResolvedVc::upcast(self), module_graph, chunking_context) | |
| } | |
| } | |
| impl Asset for HmrEntryModule { | |
| fn content(self: Vc<Self>) -> Vc<AssetContent> { | |
| todo!("HmrEntryModule doesn't implement content()") | |
| } | |
| } | |
| impl EcmascriptChunkPlaceable for HmrEntryModule { | |
| fn get_exports(self: Vc<Self>) -> Vc<EcmascriptExports> { | |
| EcmascriptExports::None.cell() | |
| } | |
| async fn chunk_item_content( | |
| self: Vc<Self>, | |
| chunking_context: Vc<Box<dyn ChunkingContext>>, | |
| module_graph: Vc<ModuleGraph>, | |
| _async_module_info: Option<Vc<AsyncModuleInfo>>, | |
| _estimated: bool, | |
| ) -> Result<Vc<EcmascriptChunkItemContent>> { | |
| let this = self.await?; | |
| let module = this.module; | |
| let chunk_item = module.as_chunk_item(module_graph, chunking_context); | |
| let id = chunking_context | |
| .chunk_item_id_strategy() | |
| .await? | |
| .get_id(chunk_item) | |
| .await?; | |
| let mut code = RopeBuilder::default(); | |
| writeln!(code, "{TURBOPACK_REQUIRE}({});", StringifyJs(&id))?; | |
| Ok(EcmascriptChunkItemContent { | |
| inner_code: code.build(), | |
| options: EcmascriptChunkItemOptions { | |
| strict: true, | |
| ..Default::default() | |
| }, | |
| ..Default::default() | |
| } | |
| .cell()) | |
| } | |
| } | |
| impl EvaluatableAsset for HmrEntryModule {} | |
| pub struct HmrEntryModuleReference { | |
| pub module: ResolvedVc<Box<dyn Module>>, | |
| } | |
| impl HmrEntryModuleReference { | |
| pub fn new(module: ResolvedVc<Box<dyn Module>>) -> Vc<Self> { | |
| HmrEntryModuleReference { module }.cell() | |
| } | |
| } | |
| impl ModuleReference for HmrEntryModuleReference { | |
| fn resolve_reference(&self) -> Vc<ModuleResolveResult> { | |
| *ModuleResolveResult::module(self.module) | |
| } | |
| fn chunking_type(&self) -> Option<ChunkingType> { | |
| Some(ChunkingType::Parallel { | |
| inherit_async: false, | |
| hoisted: false, | |
| }) | |
| } | |
| } | |
Xet Storage Details
- Size:
- 5.09 kB
- Xet hash:
- 588026b76b1df162c2c99464084b26452216ffb52311d18b5c7604fe5d0a0dda
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.