Download next.js/turbopack/crates/turbopack-nodejs/src/ecmascript/node/chunk.rs from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 4.8 kB
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/next.js/turbopack/crates/turbopack-nodejs/src/ecmascript/node/chunk.rs
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset/next.js/turbopack/crates/turbopack-nodejs/src/ecmascript/node/chunk.rs
-
curl -L -o chunk.rs https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/next.js/turbopack/crates/turbopack-nodejs/src/ecmascript/node/chunk.rs
4.8 kB
| use anyhow::Result; | |
| use turbo_rcstr::{RcStr, rcstr}; | |
| use turbo_tasks::{FxIndexSet, ResolvedVc, ValueToString, Vc}; | |
| use turbo_tasks_fs::FileSystemPath; | |
| use turbopack_core::{ | |
| asset::{Asset, AssetContent}, | |
| chunk::{Chunk, ChunkingContext}, | |
| introspect::{Introspectable, IntrospectableChildren}, | |
| output::{OutputAsset, OutputAssets}, | |
| source_map::{GenerateSourceMap, OptionStringifiedSourceMap, SourceMapAsset}, | |
| version::VersionedContent, | |
| }; | |
| use turbopack_ecmascript::chunk::EcmascriptChunk; | |
| use super::content::EcmascriptBuildNodeChunkContent; | |
| use crate::NodeJsChunkingContext; | |
| /// Production Ecmascript chunk targeting Node.js. | |
| pub(crate) struct EcmascriptBuildNodeChunk { | |
| chunking_context: ResolvedVc<NodeJsChunkingContext>, | |
| chunk: ResolvedVc<EcmascriptChunk>, | |
| } | |
| impl EcmascriptBuildNodeChunk { | |
| /// Creates a new [`Vc<EcmascriptBuildNodeChunk>`]. | |
| pub fn new( | |
| chunking_context: ResolvedVc<NodeJsChunkingContext>, | |
| chunk: ResolvedVc<EcmascriptChunk>, | |
| ) -> Vc<Self> { | |
| EcmascriptBuildNodeChunk { | |
| chunking_context, | |
| chunk, | |
| } | |
| .cell() | |
| } | |
| async fn source_map(self: Vc<Self>) -> Result<Vc<SourceMapAsset>> { | |
| let this = self.await?; | |
| Ok(SourceMapAsset::new( | |
| Vc::upcast(*this.chunking_context), | |
| this.chunk.ident().with_modifier(modifier()), | |
| Vc::upcast(self), | |
| )) | |
| } | |
| } | |
| impl ValueToString for EcmascriptBuildNodeChunk { | |
| fn to_string(&self) -> Vc<RcStr> { | |
| Vc::cell(rcstr!("Ecmascript Build Node Chunk")) | |
| } | |
| } | |
| fn modifier() -> RcStr { | |
| rcstr!("ecmascript build node chunk") | |
| } | |
| impl EcmascriptBuildNodeChunk { | |
| async fn own_content(self: Vc<Self>) -> Result<Vc<EcmascriptBuildNodeChunkContent>> { | |
| let this = self.await?; | |
| Ok(EcmascriptBuildNodeChunkContent::new( | |
| *this.chunking_context, | |
| self, | |
| this.chunk.chunk_content(), | |
| self.source_map(), | |
| )) | |
| } | |
| } | |
| impl OutputAsset for EcmascriptBuildNodeChunk { | |
| async fn path(self: Vc<Self>) -> Result<Vc<FileSystemPath>> { | |
| let this = self.await?; | |
| let ident = this.chunk.ident().with_modifier(modifier()); | |
| Ok(this | |
| .chunking_context | |
| .chunk_path(Some(Vc::upcast(self)), ident, None, rcstr!(".js"))) | |
| } | |
| async fn references(self: Vc<Self>) -> Result<Vc<OutputAssets>> { | |
| let this = self.await?; | |
| let chunk_references = this.chunk.references().await?; | |
| let include_source_map = *this | |
| .chunking_context | |
| .reference_chunk_source_maps(Vc::upcast(self)) | |
| .await?; | |
| let mut references = | |
| Vec::with_capacity(chunk_references.len() + if include_source_map { 1 } else { 0 }); | |
| for reference in &*chunk_references { | |
| references.push(*reference); | |
| } | |
| if include_source_map { | |
| references.push(ResolvedVc::upcast(self.source_map().to_resolved().await?)); | |
| } | |
| Ok(Vc::cell(references)) | |
| } | |
| } | |
| impl Asset for EcmascriptBuildNodeChunk { | |
| fn content(self: Vc<Self>) -> Vc<AssetContent> { | |
| self.own_content().content() | |
| } | |
| fn versioned_content(self: Vc<Self>) -> Vc<Box<dyn VersionedContent>> { | |
| Vc::upcast(self.own_content()) | |
| } | |
| } | |
| impl GenerateSourceMap for EcmascriptBuildNodeChunk { | |
| fn generate_source_map(self: Vc<Self>) -> Vc<OptionStringifiedSourceMap> { | |
| self.own_content().generate_source_map() | |
| } | |
| } | |
| impl Introspectable for EcmascriptBuildNodeChunk { | |
| fn ty(&self) -> Vc<RcStr> { | |
| Vc::cell(rcstr!("ecmascript build node chunk")) | |
| } | |
| fn title(self: Vc<Self>) -> Vc<RcStr> { | |
| self.path().to_string() | |
| } | |
| fn details(&self) -> Vc<RcStr> { | |
| Vc::cell(rcstr!( | |
| "generates a production EcmaScript chunk targeting Node.js" | |
| )) | |
| } | |
| fn children(&self) -> Result<Vc<IntrospectableChildren>> { | |
| let mut children = FxIndexSet::default(); | |
| let introspectable_chunk = ResolvedVc::upcast::<Box<dyn Introspectable>>(self.chunk); | |
| children.insert((rcstr!("chunk"), introspectable_chunk)); | |
| Ok(Vc::cell(children)) | |
| } | |
| } | |