turbopack_core/
module.rs

1use serde::{Deserialize, Serialize};
2use turbo_tasks::{NonLocalValue, ResolvedVc, Vc, trace::TraceRawVcs};
3
4use crate::{asset::Asset, ident::AssetIdent, reference::ModuleReferences};
5
6#[derive(Clone, Copy, Debug, Serialize, Deserialize, PartialEq, Eq, TraceRawVcs, NonLocalValue)]
7pub enum StyleType {
8    IsolatedStyle,
9    GlobalStyle,
10}
11
12#[turbo_tasks::value(transparent)]
13pub struct OptionStyleType(Option<StyleType>);
14
15/// A module. This usually represents parsed source code, which has references
16/// to other modules.
17#[turbo_tasks::value_trait]
18pub trait Module: Asset {
19    /// The identifier of the [Module]. It's expected to be unique and capture
20    /// all properties of the [Module].
21    #[turbo_tasks::function]
22    fn ident(&self) -> Vc<AssetIdent>;
23
24    /// Other [Module]s or [OutputAsset]s referenced from this [Module].
25    // TODO refactor to avoid returning [OutputAsset]s here
26    #[turbo_tasks::function]
27    fn references(self: Vc<Self>) -> Vc<ModuleReferences> {
28        ModuleReferences::empty()
29    }
30
31    /// Signifies the module itself is async, e.g. it uses top-level await, is a wasm module, etc.
32    #[turbo_tasks::function]
33    fn is_self_async(self: Vc<Self>) -> Vc<bool> {
34        Vc::cell(false)
35    }
36
37    /// The style type of the module.
38    #[turbo_tasks::function]
39    fn style_type(self: Vc<Self>) -> Vc<OptionStyleType> {
40        Vc::cell(None)
41    }
42}
43
44#[turbo_tasks::value(transparent)]
45pub struct OptionModule(Option<ResolvedVc<Box<dyn Module>>>);
46
47#[turbo_tasks::value(transparent)]
48pub struct Modules(Vec<ResolvedVc<Box<dyn Module>>>);
49
50#[turbo_tasks::value_impl]
51impl Modules {
52    #[turbo_tasks::function]
53    pub fn empty() -> Vc<Self> {
54        Vc::cell(Vec::new())
55    }
56}