Download next.js/turbopack/crates/turbopack-node/src/transforms/util.rs from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 1.57 kB
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/next.js/turbopack/crates/turbopack-node/src/transforms/util.rs
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset/next.js/turbopack/crates/turbopack-node/src/transforms/util.rs
-
curl -L -o util.rs https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/next.js/turbopack/crates/turbopack-node/src/transforms/util.rs
1.57 kB
| use std::collections::BTreeMap; | |
| use anyhow::Result; | |
| use serde::{Deserialize, Serialize}; | |
| 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 | |
| } | |