File size: 1,548 Bytes
1e92f2d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
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<CssChunk>,
}
#[turbo_tasks::value_impl]
impl CssChunkSourceMapAsset {
#[turbo_tasks::function]
pub fn new(chunk: ResolvedVc<CssChunk>) -> Vc<Self> {
CssChunkSourceMapAsset { chunk }.cell()
}
}
#[turbo_tasks::value_impl]
impl OutputAsset for CssChunkSourceMapAsset {
#[turbo_tasks::function]
async fn path(self: Vc<Self>) -> Result<Vc<FileSystemPath>> {
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<Vc<AssetContent>> {
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(),
))
}
}
}
|