turbopack_core/
traced_asset.rs

1use 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, OutputAssets},
9    reference::referenced_modules_and_affecting_sources,
10};
11
12/// Converts a traced external [Module] graph into a graph consisting of [TracedAsset]s.
13#[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 OutputAsset for TracedAsset {
28    #[turbo_tasks::function]
29    fn path(&self) -> Vc<FileSystemPath> {
30        self.module.ident().path()
31    }
32
33    #[turbo_tasks::function]
34    async fn references(&self) -> Result<Vc<OutputAssets>> {
35        let references = referenced_modules_and_affecting_sources(*self.module)
36            .await?
37            .iter()
38            .map(async |module| {
39                Ok(ResolvedVc::upcast(
40                    TracedAsset::new(**module).to_resolved().await?,
41                ))
42            })
43            .try_join()
44            .await?;
45        Ok(Vc::cell(references))
46    }
47}
48
49#[turbo_tasks::value_impl]
50impl Asset for TracedAsset {
51    #[turbo_tasks::function]
52    fn content(&self) -> Vc<AssetContent> {
53        panic!("TracedAsset::content() should never be called");
54    }
55}