turbopack_core/introspect/
module.rs1use anyhow::Result;
2use turbo_rcstr::RcStr;
3use turbo_tasks::{ResolvedVc, ValueToString, Vc};
4
5use super::{
6 Introspectable, IntrospectableChildren,
7 utils::{children_from_module_references, content_to_details},
8};
9use crate::{asset::Asset, module::Module};
10
11#[turbo_tasks::value]
12pub struct IntrospectableModule(ResolvedVc<Box<dyn Module>>);
13
14#[turbo_tasks::value_impl]
15impl IntrospectableModule {
16 #[turbo_tasks::function]
17 pub async fn new(asset: ResolvedVc<Box<dyn Module>>) -> Result<Vc<Box<dyn Introspectable>>> {
18 Ok(*ResolvedVc::try_sidecast::<Box<dyn Introspectable>>(asset)
19 .unwrap_or_else(|| ResolvedVc::upcast(IntrospectableModule(asset).resolved_cell())))
20 }
21}
22
23#[turbo_tasks::function]
24fn ty() -> Vc<RcStr> {
25 Vc::cell("asset".into())
26}
27
28#[turbo_tasks::value_impl]
29impl Introspectable for IntrospectableModule {
30 #[turbo_tasks::function]
31 fn ty(&self) -> Vc<RcStr> {
32 ty()
33 }
34
35 #[turbo_tasks::function]
36 fn title(&self) -> Vc<RcStr> {
37 self.0.ident().to_string()
38 }
39
40 #[turbo_tasks::function]
41 fn details(&self) -> Vc<RcStr> {
42 content_to_details(self.0.content())
43 }
44
45 #[turbo_tasks::function]
46 fn children(&self) -> Vc<IntrospectableChildren> {
47 children_from_module_references(self.0.references())
48 }
49}