turbopack_core/issue/
module.rs

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