1use anyhow::Result;
2use turbo_rcstr::{RcStr, rcstr};
3use turbo_tasks::{ResolvedVc, Vc};
4use turbopack_core::{
5 chunk::ChunkingContext,
6 ident::AssetIdent,
7 module::{Module, ModuleSideEffects},
8 output::OutputAsset,
9 source::Source,
10};
11use turbopack_css::embed::CssEmbed;
12
13use crate::output_asset::StaticOutputAsset;
14
15#[turbo_tasks::value]
16#[derive(Clone)]
17pub struct StaticUrlCssModule {
18 pub source: ResolvedVc<Box<dyn Source>>,
19 tag: Option<RcStr>,
20}
21
22#[turbo_tasks::value_impl]
23impl StaticUrlCssModule {
24 #[turbo_tasks::function]
25 pub fn new(source: ResolvedVc<Box<dyn Source>>, tag: Option<RcStr>) -> Vc<Self> {
26 Self::cell(StaticUrlCssModule { source, tag })
27 }
28
29 #[turbo_tasks::function]
30 fn static_output_asset(
31 &self,
32 chunking_context: ResolvedVc<Box<dyn ChunkingContext>>,
33 ) -> Vc<StaticOutputAsset> {
34 StaticOutputAsset::new(*chunking_context, *self.source, self.tag.clone())
35 }
36}
37
38#[turbo_tasks::value_impl]
39impl Module for StaticUrlCssModule {
40 #[turbo_tasks::function]
41 async fn ident(&self) -> Result<Vc<AssetIdent>> {
42 let mut ident = self
43 .source
44 .ident()
45 .owned()
46 .await?
47 .with_modifier(rcstr!("static in css"));
48 if let Some(tag) = &self.tag {
49 ident = ident.with_modifier(format!("tag {}", tag).into());
50 }
51 Ok(ident.into_vc())
52 }
53
54 #[turbo_tasks::function]
55 fn source(&self) -> Vc<turbopack_core::source::OptionSource> {
56 Vc::cell(Some(self.source))
57 }
58
59 #[turbo_tasks::function]
60 fn side_effects(self: Vc<Self>) -> Vc<ModuleSideEffects> {
61 ModuleSideEffects::SideEffectFree.cell()
62 }
63}
64
65#[turbo_tasks::value_impl]
66impl CssEmbed for StaticUrlCssModule {
67 #[turbo_tasks::function]
68 fn embedded_asset(
69 self: Vc<Self>,
70 chunking_context: Vc<Box<dyn ChunkingContext>>,
71 ) -> Vc<Box<dyn OutputAsset>> {
72 Vc::upcast(self.static_output_asset(chunking_context))
73 }
74}