use anyhow::Result; use turbo_tasks::{ResolvedVc, Vc}; use turbo_tasks_fs::{File, FileSystemPath}; use turbopack_core::{ asset::{Asset, AssetContent}, chunk::ChunkingContext, output::OutputAsset, source_map::{GenerateSourceMap, SourceMap}, }; use super::CssChunk; /// Represents the source map of an css chunk. #[turbo_tasks::value] pub struct CssChunkSourceMapAsset { chunk: ResolvedVc, } #[turbo_tasks::value_impl] impl CssChunkSourceMapAsset { #[turbo_tasks::function] pub fn new(chunk: ResolvedVc) -> Vc { CssChunkSourceMapAsset { chunk }.cell() } } #[turbo_tasks::value_impl] impl OutputAsset for CssChunkSourceMapAsset { #[turbo_tasks::function] async fn path(self: Vc) -> Result> { let this = self.await?; let ident = this.chunk.ident_for_path(); Ok(this .chunk .await? .chunking_context .chunk_path(Some(Vc::upcast(self)), ident, None, ".css".into()) .await? .append(".map")? .cell()) } } #[turbo_tasks::value_impl] impl Asset for CssChunkSourceMapAsset { #[turbo_tasks::function] async fn content(&self) -> Result> { if let Some(sm) = &*self.chunk.generate_source_map().await? { Ok(AssetContent::file(File::from(sm.clone()).into())) } else { Ok(AssetContent::file( File::from(SourceMap::empty_rope()).into(), )) } } }