turbopack_static/
fixed.rs

1use turbo_tasks::{ResolvedVc, Vc};
2use turbo_tasks_fs::FileSystemPath;
3use turbopack_core::{
4    asset::{Asset, AssetContent},
5    output::OutputAsset,
6    source::Source,
7};
8
9/// A static asset that is served at a fixed output path. It won't use
10/// content hashing to generate a long term cacheable URL.
11#[turbo_tasks::value]
12pub struct FixedStaticAsset {
13    output_path: FileSystemPath,
14    source: ResolvedVc<Box<dyn Source>>,
15}
16
17#[turbo_tasks::value_impl]
18impl FixedStaticAsset {
19    #[turbo_tasks::function]
20    pub fn new(output_path: FileSystemPath, source: ResolvedVc<Box<dyn Source>>) -> Vc<Self> {
21        FixedStaticAsset {
22            output_path,
23            source,
24        }
25        .cell()
26    }
27}
28
29#[turbo_tasks::value_impl]
30impl OutputAsset for FixedStaticAsset {
31    #[turbo_tasks::function]
32    fn path(&self) -> Vc<FileSystemPath> {
33        self.output_path.clone().cell()
34    }
35}
36
37#[turbo_tasks::value_impl]
38impl Asset for FixedStaticAsset {
39    #[turbo_tasks::function]
40    fn content(&self) -> Vc<AssetContent> {
41        self.source.content()
42    }
43}