Skip to content

Commit 2224a99

Browse files
committed
Turbopack: remove Asset supertrait from Module trait. Modules don't have content
1 parent a832748 commit 2224a99

File tree

6 files changed

+36
-19
lines changed

6 files changed

+36
-19
lines changed

turbopack/crates/turbopack-core/src/changed.rs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use anyhow::Result;
1+
use anyhow::{Result, bail};
22
use turbo_tasks::{
33
Completion, Completions, ResolvedVc, TryJoinIterExt, Vc,
44
graph::{AdjacencyMap, GraphTraversal},
@@ -33,7 +33,7 @@ pub async fn any_content_changed_of_module(
3333
.completed()?
3434
.into_inner()
3535
.into_postorder_topological()
36-
.map(|m| content_changed(*ResolvedVc::upcast(m)))
36+
.map(|m| source_changed(*m))
3737
.map(|v| v.to_resolved())
3838
.try_join()
3939
.await?;
@@ -85,3 +85,16 @@ pub async fn content_changed(asset: Vc<Box<dyn Asset>>) -> Result<Vc<Completion>
8585
asset.content().file_content().await?;
8686
Ok(Completion::new())
8787
}
88+
89+
/// Returns a completion that changes when the content of the given asset
90+
/// changes.
91+
#[turbo_tasks::function]
92+
pub async fn source_changed(asset: Vc<Box<dyn Module>>) -> Result<Vc<Completion>> {
93+
if let Some(source) = *asset.source().await? {
94+
// Reading the file content is enough to add as dependency
95+
source.content().file_content().await?;
96+
} else {
97+
bail!("Module has no source")
98+
}
99+
Ok(Completion::new())
100+
}

turbopack/crates/turbopack-core/src/introspect/module.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,12 @@ impl Introspectable for IntrospectableModule {
3333
}
3434

3535
#[turbo_tasks::function]
36-
fn details(&self) -> Vc<RcStr> {
37-
content_to_details(self.0.content())
36+
async fn details(&self) -> Result<Vc<RcStr>> {
37+
if let Some(source) = *self.0.source().await? {
38+
Ok(content_to_details(source.content()))
39+
} else {
40+
Ok(Vc::cell("No source".into()))
41+
}
3842
}
3943

4044
#[turbo_tasks::function]

turbopack/crates/turbopack-core/src/module.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ pub enum StyleType {
1414
/// A module. This usually represents parsed source code, which has references
1515
/// to other modules.
1616
#[turbo_tasks::value_trait]
17-
pub trait Module: Asset {
17+
pub trait Module {
1818
/// The identifier of the [Module]. It's expected to be unique and capture
1919
/// all properties of the [Module].
2020
#[turbo_tasks::function]

turbopack/crates/turbopack-core/src/rebase.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::hash::Hash;
22

3-
use anyhow::Result;
3+
use anyhow::{Result, bail};
44
use turbo_tasks::{ResolvedVc, TryJoinIterExt, Vc};
55
use turbo_tasks_fs::FileSystemPath;
66

@@ -74,7 +74,11 @@ impl OutputAsset for RebasedAsset {
7474
#[turbo_tasks::value_impl]
7575
impl Asset for RebasedAsset {
7676
#[turbo_tasks::function]
77-
fn content(&self) -> Vc<AssetContent> {
78-
self.module.content()
77+
async fn content(&self) -> Result<Vc<AssetContent>> {
78+
if let Some(source) = *self.module.source().await? {
79+
Ok(source.content())
80+
} else {
81+
bail!("Module has no source")
82+
}
7983
}
8084
}

turbopack/crates/turbopack-core/src/traced_asset.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use anyhow::Result;
1+
use anyhow::{Result, bail};
22
use turbo_tasks::{ResolvedVc, TryJoinIterExt, Vc};
33
use turbo_tasks_fs::FileSystemPath;
44

@@ -54,7 +54,11 @@ impl OutputAsset for TracedAsset {
5454
#[turbo_tasks::value_impl]
5555
impl Asset for TracedAsset {
5656
#[turbo_tasks::function]
57-
fn content(&self) -> Vc<AssetContent> {
58-
self.module.content()
57+
async fn content(&self) -> Result<Vc<AssetContent>> {
58+
if let Some(source) = *self.module.source().await? {
59+
Ok(source.content())
60+
} else {
61+
bail!("Module has no source")
62+
}
5963
}
6064
}

turbopack/crates/turbopack-ecmascript/src/references/external_module.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -445,14 +445,6 @@ impl ModuleWithoutSelfAsync {
445445
}
446446
}
447447

448-
#[turbo_tasks::value_impl]
449-
impl Asset for ModuleWithoutSelfAsync {
450-
#[turbo_tasks::function]
451-
fn content(&self) -> Vc<AssetContent> {
452-
self.module.content()
453-
}
454-
}
455-
456448
#[turbo_tasks::value_impl]
457449
impl Module for ModuleWithoutSelfAsync {
458450
#[turbo_tasks::function]

0 commit comments

Comments
 (0)