turbopack_core/
proxied_asset.rs

1use turbo_tasks::{ResolvedVc, Vc};
2use turbo_tasks_fs::FileSystemPath;
3
4use crate::{
5    asset::{Asset, AssetContent},
6    output::{OutputAsset, OutputAssets},
7    version::VersionedContent,
8};
9
10/// An [`Asset`] with an overwritten path.
11///
12/// This is helpful to expose an asset at a different path than it was originally set up to be, e.g.
13/// to expose layout CSS chunks under the server FS instead of the output FS when rendering
14/// Next.js apps.
15#[turbo_tasks::value]
16pub struct ProxiedAsset {
17    asset: ResolvedVc<Box<dyn OutputAsset>>,
18    path: FileSystemPath,
19}
20
21#[turbo_tasks::value_impl]
22impl ProxiedAsset {
23    /// Creates a new [`ProxiedAsset`] from an [`Asset`] and a path.
24    #[turbo_tasks::function]
25    pub fn new(asset: ResolvedVc<Box<dyn OutputAsset>>, path: FileSystemPath) -> Vc<Self> {
26        ProxiedAsset { asset, path }.cell()
27    }
28}
29
30#[turbo_tasks::value_impl]
31impl OutputAsset for ProxiedAsset {
32    #[turbo_tasks::function]
33    fn path(&self) -> Vc<FileSystemPath> {
34        self.path.clone().cell()
35    }
36
37    #[turbo_tasks::function]
38    fn references(&self) -> Vc<OutputAssets> {
39        self.asset.references()
40    }
41}
42
43#[turbo_tasks::value_impl]
44impl Asset for ProxiedAsset {
45    #[turbo_tasks::function]
46    fn content(&self) -> Vc<AssetContent> {
47        self.asset.content()
48    }
49
50    #[turbo_tasks::function]
51    fn versioned_content(&self) -> Vc<Box<dyn VersionedContent>> {
52        self.asset.versioned_content()
53    }
54}