turbopack_core/issue/
module.rs

1use anyhow::Result;
2use turbo_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(shared)]
14pub struct ModuleIssue {
15    pub ident: ResolvedVc<AssetIdent>,
16    pub title: ResolvedVc<StyledString>,
17    pub description: ResolvedVc<StyledString>,
18    // TODO(PACK-4879): make this mandatory and drop `ident`
19    pub source: Option<IssueSource>,
20}
21
22#[turbo_tasks::value_impl]
23impl Issue for ModuleIssue {
24    #[turbo_tasks::function]
25    fn stage(&self) -> Vc<IssueStage> {
26        IssueStage::ProcessModule.cell()
27    }
28
29    #[turbo_tasks::function]
30    fn file_path(&self) -> Vc<FileSystemPath> {
31        self.ident.path()
32    }
33
34    #[turbo_tasks::function]
35    fn title(&self) -> Vc<StyledString> {
36        *self.title
37    }
38
39    #[turbo_tasks::function]
40    fn description(&self) -> Vc<OptionStyledString> {
41        Vc::cell(Some(self.description))
42    }
43
44    #[turbo_tasks::function]
45    fn source(&self) -> Vc<OptionIssueSource> {
46        Vc::cell(self.source)
47    }
48}
49
50#[turbo_tasks::function]
51pub async fn emit_unknown_module_type_error(source: Vc<Box<dyn Source>>) -> Result<()> {
52    ModuleIssue {
53        ident: source.ident().to_resolved().await?,
54        title: StyledString::Text(rcstr!("Unknown module type")).resolved_cell(),
55        description: StyledString::Text(
56            r"This module doesn't have an associated type. Use a known file extension, or register a loader for it.
57
58Read more: https://nextjs.org/docs/app/api-reference/next-config-js/turbo#webpack-loaders".into(),
59        )
60        .resolved_cell(),
61        source: Some(IssueSource::from_source_only(source.to_resolved().await?)),
62    }
63    .resolved_cell()
64    .emit();
65
66    Ok(())
67}