| use std::collections::BTreeMap; | |
| use anyhow::Result; | |
| use bincode::{Decode, Encode}; | |
| use serde::Deserialize; | |
| use serde_json::Value as JsonValue; | |
| use turbo_rcstr::RcStr; | |
| use turbo_tasks::{NonLocalValue, ResolvedVc, TryJoinIterExt, trace::TraceRawVcs}; | |
| use turbo_tasks_fs::{File, FileContent, FileSystem}; | |
| use turbopack_core::{ | |
| asset::AssetContent, server_fs::ServerFileSystem, virtual_source::VirtualSource, | |
| }; | |
| pub struct EmittedAsset { | |
| file: RcStr, | |
| content: RcStr, | |
| source_map: Option<JsonValue>, | |
| } | |
| pub async fn emitted_assets_to_virtual_sources( | |
| assets: Option<Vec<EmittedAsset>>, | |
| ) -> Result<Vec<ResolvedVc<VirtualSource>>> { | |
| assets | |
| .into_iter() | |
| .flatten() | |
| .map( | |
| |EmittedAsset { | |
| file, | |
| content, | |
| source_map, | |
| }| (file, (content, source_map)), | |
| ) | |
| // Sort it to make it deterministic | |
| .collect::<BTreeMap<_, _>>() | |
| .into_iter() | |
| .map(|(file, (content, _source_map))| { | |
| async move { | |
| // TODO handle SourceMap | |
| VirtualSource::new( | |
| ServerFileSystem::new().root().await?.join(&file)?, | |
| AssetContent::File(FileContent::Content(File::from(content)).resolved_cell()) | |
| .cell(), | |
| ) | |
| .to_resolved() | |
| .await | |
| } | |
| }) | |
| .try_join() | |
| .await | |
| } | |
Xet Storage Details
- Size:
- 1.66 kB
- Xet hash:
- 46ad1d1caf845c24e1d85aecbb54b02a9731d53593d6e5d70362a2ad00f36f06
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.