turbopack_static/
fixed.rs

1use turbo_tasks::{ResolvedVc, Vc};
2use turbo_tasks_fs::FileSystemPath;
3use turbopack_core::{
4    asset::{Asset, AssetContent},
5    output::{OutputAsset, OutputAssetsReference},
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 OutputAssetsReference for FixedStaticAsset {}
31
32#[turbo_tasks::value_impl]
33impl OutputAsset for FixedStaticAsset {
34    #[turbo_tasks::function]
35    fn path(&self) -> Vc<FileSystemPath> {
36        self.output_path.clone().cell()
37    }
38}
39
40#[turbo_tasks::value_impl]
41impl Asset for FixedStaticAsset {
42    #[turbo_tasks::function]
43    fn content(&self) -> Vc<AssetContent> {
44        self.source.content()
45    }
46}