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