turbopack_core/issue/
module.rs1use anyhow::Result;
2use async_trait::async_trait;
3use turbo_rcstr::{RcStr, rcstr};
4use turbo_tasks::{ResolvedVc, Vc};
5use turbo_tasks_fs::FileSystemPath;
6
7use super::{Issue, IssueSource, IssueStage, StyledString};
8use crate::{ident::AssetIdent, issue::IssueExt, source::Source};
9
10#[turbo_tasks::value]
11pub struct ModuleIssue {
12 pub ident: ResolvedVc<AssetIdent>,
13 pub title: ResolvedVc<StyledString>,
14 pub description: ResolvedVc<StyledString>,
15 pub source: Option<IssueSource>,
17}
18#[turbo_tasks::value_impl]
19impl ModuleIssue {
20 #[turbo_tasks::function]
21 pub fn new(
22 ident: ResolvedVc<AssetIdent>,
23 title: RcStr,
24 description: RcStr,
25 source: Option<IssueSource>,
26 ) -> Vc<Self> {
27 ModuleIssue {
28 ident,
29 title: StyledString::Text(title).resolved_cell(),
30 description: StyledString::Text(description).resolved_cell(),
31 source,
32 }
33 .cell()
34 }
35}
36
37#[async_trait]
38#[turbo_tasks::value_impl]
39impl Issue for ModuleIssue {
40 fn stage(&self) -> IssueStage {
41 IssueStage::ProcessModule
42 }
43
44 async fn file_path(&self) -> Result<FileSystemPath> {
45 Ok(self.ident.await?.path.clone())
46 }
47
48 async fn title(&self) -> Result<StyledString> {
49 Ok((*self.title.await?).clone())
50 }
51
52 async fn description(&self) -> Result<Option<StyledString>> {
53 Ok(Some((*self.description.await?).clone()))
54 }
55
56 fn source(&self) -> Option<IssueSource> {
57 self.source
58 }
59}
60
61#[turbo_tasks::function]
62pub async fn emit_unknown_module_type_error(source: Vc<Box<dyn Source>>) -> Result<()> {
63 ModuleIssue {ident: source.ident().to_resolved().await?,
64 title: StyledString::Text(rcstr!("Unknown module type")).resolved_cell(),
65 description: StyledString::Text(
66 r"This module doesn't have an associated type. Use a known file extension, or register a loader for it.
67
68Read more: https://nextjs.org/docs/app/api-reference/next-config-js/turbo#webpack-loaders".into(),
69 )
70 .resolved_cell(),
71 source: Some(IssueSource::from_source_only(source.to_resolved().await?)),}
72 .resolved_cell()
73 .emit();
74
75 Ok(())
76}