turbopack_core/
changed.rs1use anyhow::Result;
2use turbo_tasks::{
3 Completion, Completions, ResolvedVc, TryJoinIterExt, Vc,
4 graph::{AdjacencyMap, GraphTraversal},
5};
6
7use crate::{asset::Asset, module::Module, reference::referenced_modules_and_affecting_sources};
8
9async fn get_referenced_modules_and_affecting_sources(
10 parent: ResolvedVc<Box<dyn Module>>,
11) -> Result<impl Iterator<Item = ResolvedVc<Box<dyn Module>>> + Send> {
12 let modules = referenced_modules_and_affecting_sources(*parent, false)
15 .await?
16 .iter()
17 .flat_map(|(_, resolved)| resolved.modules.iter().copied())
18 .collect::<Vec<_>>();
19 Ok(modules.into_iter())
20}
21
22#[turbo_tasks::function]
26pub async fn any_source_content_changed_of_module(
27 root: ResolvedVc<Box<dyn Module>>,
28) -> Result<Vc<Completion>> {
29 let completions = AdjacencyMap::new()
30 .visit([root], get_referenced_modules_and_affecting_sources)
31 .await
32 .completed()?
33 .into_postorder_topological()
34 .map(|m| source_changed(*m))
35 .map(|v| v.to_resolved())
36 .try_join()
37 .await?;
38
39 Ok(Vc::<Completions>::cell(completions).completed())
40}
41
42#[turbo_tasks::function]
45pub async fn content_changed(asset: Vc<Box<dyn Asset>>) -> Result<Vc<Completion>> {
46 asset.content().file_content().await?;
48 Ok(Completion::new())
49}
50
51#[turbo_tasks::function]
54pub async fn source_changed(asset: Vc<Box<dyn Module>>) -> Result<Vc<Completion>> {
55 if let Some(source) = *asset.source().await? {
56 source.content().file_content().await?;
58 }
59 Ok(Completion::new())
60}