Download next.js/crates/next-core/src/hmr_entry.rs from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 5.79 kB
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/next.js/crates/next-core/src/hmr_entry.rs
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset/next.js/crates/next-core/src/hmr_entry.rs
-
curl -L -o hmr_entry.rs https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/next.js/crates/next-core/src/hmr_entry.rs
5.79 kB
| use std::io::Write; | |
| use anyhow::Result; | |
| use turbo_rcstr::{RcStr, rcstr}; | |
| use turbo_tasks::{ResolvedVc, ValueToString, Vc}; | |
| use turbo_tasks_fs::{FileSystem, VirtualFileSystem, glob::Glob, rope::RopeBuilder}; | |
| use turbopack_core::{ | |
| asset::{Asset, AssetContent}, | |
| chunk::{ | |
| ChunkItem, ChunkType, ChunkableModule, ChunkableModuleReference, ChunkingContext, | |
| EvaluatableAsset, | |
| }, | |
| ident::AssetIdent, | |
| module::Module, | |
| module_graph::ModuleGraph, | |
| reference::{ModuleReference, ModuleReferences}, | |
| resolve::ModuleResolveResult, | |
| }; | |
| use turbopack_ecmascript::{ | |
| chunk::{ | |
| EcmascriptChunkItem, EcmascriptChunkItemContent, EcmascriptChunkItemOptions, | |
| EcmascriptChunkPlaceable, EcmascriptChunkType, EcmascriptExports, | |
| }, | |
| 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) | |
| } | |
| async fn references(&self) -> Result<Vc<ModuleReferences>> { | |
| Ok(Vc::cell(vec![ResolvedVc::upcast( | |
| HmrEntryModuleReference::new(Vc::upcast(*self.module)) | |
| .to_resolved() | |
| .await?, | |
| )])) | |
| } | |
| } | |
| 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>> { | |
| Vc::upcast( | |
| HmrEntryChunkItem { | |
| module: self, | |
| module_graph, | |
| chunking_context, | |
| } | |
| .cell(), | |
| ) | |
| } | |
| } | |
| 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() | |
| } | |
| fn is_marked_as_side_effect_free(self: Vc<Self>, _: Vc<Glob>) -> Vc<bool> { | |
| Vc::cell(false) | |
| } | |
| } | |
| 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 ValueToString for HmrEntryModuleReference { | |
| fn to_string(&self) -> Vc<RcStr> { | |
| Vc::cell(rcstr!("entry")) | |
| } | |
| } | |
| impl ModuleReference for HmrEntryModuleReference { | |
| fn resolve_reference(&self) -> Vc<ModuleResolveResult> { | |
| *ModuleResolveResult::module(self.module) | |
| } | |
| } | |
| impl ChunkableModuleReference for HmrEntryModuleReference {} | |
| /// The chunk item for [`HmrEntryModule`]. | |
| struct HmrEntryChunkItem { | |
| module: ResolvedVc<HmrEntryModule>, | |
| module_graph: ResolvedVc<ModuleGraph>, | |
| chunking_context: ResolvedVc<Box<dyn ChunkingContext>>, | |
| } | |
| impl ChunkItem for HmrEntryChunkItem { | |
| fn chunking_context(&self) -> Vc<Box<dyn ChunkingContext>> { | |
| Vc::upcast(*self.chunking_context) | |
| } | |
| fn asset_ident(&self) -> Vc<AssetIdent> { | |
| self.module.ident() | |
| } | |
| fn ty(&self) -> Vc<Box<dyn ChunkType>> { | |
| Vc::upcast(Vc::<EcmascriptChunkType>::default()) | |
| } | |
| fn module(&self) -> Vc<Box<dyn Module>> { | |
| Vc::upcast(*self.module) | |
| } | |
| } | |
| impl EcmascriptChunkItem for HmrEntryChunkItem { | |
| async fn content(&self) -> Result<Vc<EcmascriptChunkItemContent>> { | |
| let this = self.module.await?; | |
| let module = this.module; | |
| let chunk_item = module.as_chunk_item(*self.module_graph, *self.chunking_context); | |
| let id = self.chunking_context.chunk_item_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, | |
| module: true, | |
| ..Default::default() | |
| }, | |
| ..Default::default() | |
| } | |
| .cell()) | |
| } | |
| } | |