turbopack_core/
traced_asset.rs1use anyhow::Result;
2use turbo_tasks::{ResolvedVc, TryJoinIterExt, Vc};
3use turbo_tasks_fs::FileSystemPath;
4
5use crate::{
6 asset::{Asset, AssetContent},
7 module::Module,
8 output::{OutputAsset, OutputAssetsReference, OutputAssetsWithReferenced},
9 reference::referenced_modules_and_affecting_sources,
10};
11
12#[turbo_tasks::value]
14pub struct TracedAsset {
15 module: ResolvedVc<Box<dyn Module>>,
16}
17
18#[turbo_tasks::value_impl]
19impl TracedAsset {
20 #[turbo_tasks::function]
21 pub fn new(module: ResolvedVc<Box<dyn Module>>) -> Vc<Self> {
22 Self::cell(TracedAsset { module })
23 }
24}
25
26#[turbo_tasks::value_impl]
27impl OutputAssetsReference for TracedAsset {
28 #[turbo_tasks::function]
29 async fn references(&self) -> Result<Vc<OutputAssetsWithReferenced>> {
30 let references = referenced_modules_and_affecting_sources(*self.module)
31 .await?
32 .iter()
33 .map(async |module| {
34 Ok(ResolvedVc::upcast(
35 TracedAsset::new(**module).to_resolved().await?,
36 ))
37 })
38 .try_join()
39 .await?;
40 Ok(OutputAssetsWithReferenced::from_assets(Vc::cell(
41 references,
42 )))
43 }
44}
45
46#[turbo_tasks::value_impl]
47impl OutputAsset for TracedAsset {
48 #[turbo_tasks::function]
49 fn path(&self) -> Vc<FileSystemPath> {
50 self.module.ident().path()
51 }
52}
53
54#[turbo_tasks::value_impl]
55impl Asset for TracedAsset {
56 #[turbo_tasks::function]
57 fn content(&self) -> Vc<AssetContent> {
58 self.module.content()
59 }
60}