Buckets:
| use anyhow::Result; | |
| use turbo_tasks::{ResolvedVc, Vc}; | |
| use turbo_tasks_fs::{File, FileContent}; | |
| use turbopack_core::{ | |
| asset::AssetContent, | |
| chunk::{ChunkingContext, MinifyType}, | |
| code_builder::{Code, CodeBuilder}, | |
| output::OutputAsset, | |
| source_map::{GenerateSourceMap, SourceMapAsset}, | |
| version::{Update, Version, VersionedContent}, | |
| }; | |
| use turbopack_ecmascript::{chunk::EcmascriptChunkContent, minify::minify, utils::StringifyJs}; | |
| use super::{ | |
| chunk::EcmascriptBuildNodeChunk, update::update_node_chunk, | |
| version::EcmascriptBuildNodeChunkVersion, | |
| }; | |
| use crate::NodeJsChunkingContext; | |
| pub(super) struct EcmascriptBuildNodeChunkContent { | |
| pub(super) content: ResolvedVc<EcmascriptChunkContent>, | |
| pub(super) chunking_context: ResolvedVc<NodeJsChunkingContext>, | |
| pub(super) chunk: ResolvedVc<EcmascriptBuildNodeChunk>, | |
| pub(super) source_map: ResolvedVc<SourceMapAsset>, | |
| } | |
| impl EcmascriptBuildNodeChunkContent { | |
| pub(crate) fn new( | |
| chunking_context: ResolvedVc<NodeJsChunkingContext>, | |
| chunk: ResolvedVc<EcmascriptBuildNodeChunk>, | |
| content: ResolvedVc<EcmascriptChunkContent>, | |
| source_map: ResolvedVc<SourceMapAsset>, | |
| ) -> Vc<Self> { | |
| EcmascriptBuildNodeChunkContent { | |
| content, | |
| chunking_context, | |
| chunk, | |
| source_map, | |
| } | |
| .cell() | |
| } | |
| } | |
| impl EcmascriptBuildNodeChunkContent { | |
| async fn code(&self) -> Result<Vc<Code>> { | |
| use std::io::Write; | |
| let source_maps = *self | |
| .chunking_context | |
| .reference_chunk_source_maps(*ResolvedVc::upcast(self.chunk)) | |
| .await?; | |
| let mut code = CodeBuilder::new(true, *self.chunking_context.debug_ids_enabled().await?); | |
| write!(code, "module.exports = [")?; | |
| let content = self.content.await?; | |
| let chunk_items = content.chunk_item_code_and_ids().await?; | |
| for item in chunk_items { | |
| for (id, item_code) in item { | |
| write!(code, "\n{}, ", StringifyJs(&id))?; | |
| code.push_code(item_code); | |
| write!(code, ",")?; | |
| } | |
| } | |
| write!(code, "\n];")?; | |
| let mut code = code.build(); | |
| if let MinifyType::Minify { mangle } = *self.chunking_context.minify_type().await? { | |
| code = minify(code, source_maps, mangle)?; | |
| } | |
| Ok(code.cell()) | |
| } | |
| pub(crate) async fn own_version(&self) -> Result<Vc<EcmascriptBuildNodeChunkVersion>> { | |
| Ok(EcmascriptBuildNodeChunkVersion::new( | |
| self.chunking_context.output_root().owned().await?, | |
| self.chunk.path().owned().await?, | |
| *self.content, | |
| *self.chunking_context.minify_type().await?, | |
| )) | |
| } | |
| } | |
| impl GenerateSourceMap for EcmascriptBuildNodeChunkContent { | |
| fn generate_source_map(self: Vc<Self>) -> Vc<FileContent> { | |
| self.code().generate_source_map() | |
| } | |
| } | |
| impl VersionedContent for EcmascriptBuildNodeChunkContent { | |
| async fn content(self: Vc<Self>) -> Result<Vc<AssetContent>> { | |
| let this = self.await?; | |
| Ok(AssetContent::file( | |
| FileContent::Content(File::from( | |
| self.code() | |
| .to_rope_with_magic_comments(|| *this.source_map) | |
| .await?, | |
| )) | |
| .cell(), | |
| )) | |
| } | |
| fn version(self: Vc<Self>) -> Vc<Box<dyn Version>> { | |
| Vc::upcast(self.own_version()) | |
| } | |
| async fn update( | |
| self: Vc<Self>, | |
| from_version: ResolvedVc<Box<dyn Version>>, | |
| ) -> Result<Vc<Update>> { | |
| Ok(update_node_chunk(self, from_version).await?.cell()) | |
| } | |
| } | |
Xet Storage Details
- Size:
- 3.99 kB
- Xet hash:
- 49c71cfd73cdec48e68112411bfe535669ef6daac84de7e2ea442fcdc7879861
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.