Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ use anyhow::{Context, Result, bail};
use indoc::writedoc;
use turbo_rcstr::{RcStr, rcstr};
use turbo_tasks::{IntoTraitRef, ResolvedVc, ValueToString, Vc};
use turbo_tasks_fs::{File, FileContent};
use turbo_tasks_fs::File;
use turbopack_core::{
asset::{Asset, AssetContent},
asset::AssetContent,
chunk::{
AsyncModuleInfo, ChunkGroupType, ChunkItem, ChunkType, ChunkableModule,
ChunkableModuleReference, ChunkingContext, ChunkingType, ChunkingTypeOption,
Expand Down Expand Up @@ -243,18 +243,6 @@ impl Module for EcmascriptClientReferenceModule {
}
}

#[turbo_tasks::value_impl]
impl Asset for EcmascriptClientReferenceModule {
#[turbo_tasks::function]
fn content(&self) -> Vc<AssetContent> {
AssetContent::File(
FileContent::Content("// This is a proxy module for Next.js client references.".into())
.resolved_cell(),
)
.cell()
}
}

#[turbo_tasks::value_impl]
impl ChunkableModule for EcmascriptClientReferenceModule {
#[turbo_tasks::function]
Expand Down
14 changes: 0 additions & 14 deletions crates/next-core/src/next_dynamic/dynamic_module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ use anyhow::Result;
use indoc::formatdoc;
use turbo_rcstr::{RcStr, rcstr};
use turbo_tasks::{ResolvedVc, Vc};
use turbo_tasks_fs::FileContent;
use turbopack_core::{
asset::{Asset, AssetContent},
chunk::{ChunkItem, ChunkType, ChunkableModule, ChunkingContext, ModuleChunkItemIdExt},
ident::AssetIdent,
module::Module,
Expand Down Expand Up @@ -73,18 +71,6 @@ impl Module for NextDynamicEntryModule {
}
}

#[turbo_tasks::value_impl]
impl Asset for NextDynamicEntryModule {
#[turbo_tasks::function]
fn content(&self) -> Vc<AssetContent> {
AssetContent::File(
FileContent::Content("// This is a marker module for Next.js dynamic.".into())
.resolved_cell(),
)
.cell()
}
}

#[turbo_tasks::value_impl]
impl ChunkableModule for NextDynamicEntryModule {
#[turbo_tasks::function]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ use anyhow::Result;
use indoc::formatdoc;
use turbo_rcstr::rcstr;
use turbo_tasks::{ResolvedVc, Vc};
use turbo_tasks_fs::{FileContent, FileSystemPath};
use turbo_tasks_fs::FileSystemPath;
use turbopack_core::{
asset::{Asset, AssetContent},
chunk::{ChunkItem, ChunkType, ChunkableModule, ChunkingContext, ModuleChunkItemIdExt},
ident::AssetIdent,
module::Module,
Expand Down Expand Up @@ -69,20 +68,6 @@ impl Module for NextServerComponentModule {
}
}

#[turbo_tasks::value_impl]
impl Asset for NextServerComponentModule {
#[turbo_tasks::function]
fn content(&self) -> Vc<AssetContent> {
AssetContent::File(
FileContent::Content(
"// This is a marker module for Next.js server components.".into(),
)
.resolved_cell(),
)
.cell()
}
}

#[turbo_tasks::value_impl]
impl ChunkableModule for NextServerComponentModule {
#[turbo_tasks::function]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ use anyhow::Result;
use indoc::formatdoc;
use turbo_rcstr::rcstr;
use turbo_tasks::{ResolvedVc, Vc};
use turbo_tasks_fs::{FileContent, FileSystemPath};
use turbo_tasks_fs::FileSystemPath;
use turbopack_core::{
asset::{Asset, AssetContent},
chunk::{ChunkItem, ChunkType, ChunkableModule, ChunkingContext, ModuleChunkItemIdExt},
ident::AssetIdent,
module::Module,
Expand Down Expand Up @@ -69,18 +68,6 @@ impl Module for NextServerUtilityModule {
}
}

#[turbo_tasks::value_impl]
impl Asset for NextServerUtilityModule {
#[turbo_tasks::function]
fn content(&self) -> Vc<AssetContent> {
AssetContent::File(
FileContent::Content("// This is a marker module for Next.js server utilities.".into())
.resolved_cell(),
)
.cell()
}
}

#[turbo_tasks::value_impl]
impl ChunkableModule for NextServerUtilityModule {
#[turbo_tasks::function]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,12 @@ pub async fn get_swc_ecma_transform_rule_impl(
enable_mdx_rs: bool,
) -> Result<Option<ModuleRule>> {
use anyhow::bail;
use turbo_tasks::TryFlatJoinIterExt;
use turbo_tasks::{TryFlatJoinIterExt, ValueToString};
use turbo_tasks_fs::FileContent;
use turbopack::{resolve_options, resolve_options_context::ResolveOptionsContext};
use turbopack_core::{
asset::Asset,
module::Module,
reference_type::{CommonJsReferenceSubType, ReferenceType},
resolve::{handle_resolve_error, parse::Request, resolve},
};
Expand Down Expand Up @@ -99,7 +100,16 @@ pub async fn get_swc_ecma_transform_rule_impl(
return Ok(None);
};

let content = &*plugin_module.content().file_content().await?;
let Some(plugin_source) = &*plugin_module.source().await? else {
use anyhow::bail;

bail!(
"Expected source for plugin module: {}",
plugin_module.ident().to_string().await?
);
};

let content = &*plugin_source.content().file_content().await?;
let FileContent::Content(file) = content else {
bail!("Expected file content for plugin module");
};
Expand Down
10 changes: 1 addition & 9 deletions crates/next-core/src/raw_ecmascript_module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use turbo_tasks::{FxIndexMap, FxIndexSet, ResolvedVc, TryJoinIterExt, ValueToStr
use turbo_tasks_fs::{FileContent, glob::Glob, rope::Rope};
use turbopack::{ModuleAssetContext, module_options::CustomModuleType};
use turbopack_core::{
asset::{Asset, AssetContent},
asset::Asset,
chunk::{ChunkItem, ChunkType, ChunkableModule, ChunkingContext},
code_builder::CodeBuilder,
compile_time_info::{
Expand Down Expand Up @@ -107,14 +107,6 @@ impl Module for RawEcmascriptModule {
}
}

#[turbo_tasks::value_impl]
impl Asset for RawEcmascriptModule {
#[turbo_tasks::function]
fn content(&self) -> Vc<AssetContent> {
self.source.content()
}
}

#[turbo_tasks::value_impl]
impl ChunkableModule for RawEcmascriptModule {
#[turbo_tasks::function]
Expand Down
19 changes: 16 additions & 3 deletions turbopack/crates/turbopack-core/src/changed.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use anyhow::Result;
use anyhow::{Result, bail};
use turbo_tasks::{
Completion, Completions, ResolvedVc, TryJoinIterExt, Vc,
Completion, Completions, ResolvedVc, TryJoinIterExt, ValueToString, Vc,
graph::{AdjacencyMap, GraphTraversal},
};

Expand Down Expand Up @@ -33,7 +33,7 @@ pub async fn any_content_changed_of_module(
.completed()?
.into_inner()
.into_postorder_topological()
.map(|m| content_changed(*ResolvedVc::upcast(m)))
.map(|m| source_changed(*m))
.map(|v| v.to_resolved())
.try_join()
.await?;
Expand Down Expand Up @@ -85,3 +85,16 @@ pub async fn content_changed(asset: Vc<Box<dyn Asset>>) -> Result<Vc<Completion>
asset.content().file_content().await?;
Ok(Completion::new())
}

/// Returns a completion that changes when the content of the given asset
/// changes.
#[turbo_tasks::function]
pub async fn source_changed(asset: Vc<Box<dyn Module>>) -> Result<Vc<Completion>> {
if let Some(source) = *asset.source().await? {
// Reading the file content is enough to add as dependency
source.content().file_content().await?;
} else {
bail!("Module {} has no source", asset.ident().to_string().await?)
}
Ok(Completion::new())
}
3 changes: 1 addition & 2 deletions turbopack/crates/turbopack-core/src/chunk/evaluate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use turbo_tasks::{ResolvedVc, Upcast, ValueToString, Vc};

use super::ChunkableModule;
use crate::{
asset::Asset,
context::AssetContext,
module::Module,
reference_type::{EntryReferenceSubType, ReferenceType},
Expand All @@ -15,7 +14,7 @@ use crate::{
/// The chunking context implementation will resolve the dynamic entry to a
/// well-known value or trait object.
#[turbo_tasks::value_trait]
pub trait EvaluatableAsset: Asset + Module + ChunkableModule {}
pub trait EvaluatableAsset: Module + ChunkableModule {}

pub trait EvaluatableAssetExt {
fn to_evaluatable(
Expand Down
4 changes: 2 additions & 2 deletions turbopack/crates/turbopack-core/src/chunk/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ pub struct ModuleIds(Vec<ResolvedVc<ModuleId>>);

/// A [Module] that can be converted into a [Chunk].
#[turbo_tasks::value_trait]
pub trait ChunkableModule: Module + Asset {
pub trait ChunkableModule: Module {
#[turbo_tasks::function]
fn as_chunk_item(
self: Vc<Self>,
Expand All @@ -115,7 +115,7 @@ impl ChunkableModules {
// with other module types (as a MergeableModule cannot prevent itself from being merged with other
// module types)
#[turbo_tasks::value_trait]
pub trait MergeableModule: Module + Asset {
pub trait MergeableModule: Module {
/// Even though MergeableModule is implemented, this allows a dynamic condition to determine
/// mergeability
#[turbo_tasks::function]
Expand Down
8 changes: 6 additions & 2 deletions turbopack/crates/turbopack-core/src/introspect/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,12 @@ impl Introspectable for IntrospectableModule {
}

#[turbo_tasks::function]
fn details(&self) -> Vc<RcStr> {
content_to_details(self.0.content())
async fn details(&self) -> Result<Vc<RcStr>> {
if let Some(source) = *self.0.source().await? {
Ok(content_to_details(source.content()))
} else {
Ok(Vc::cell("No source".into()))
}
}

#[turbo_tasks::function]
Expand Down
6 changes: 3 additions & 3 deletions turbopack/crates/turbopack-core/src/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use turbo_rcstr::RcStr;
use turbo_tasks::{ResolvedVc, TaskInput, ValueToString, Vc};
use turbo_tasks_fs::glob::Glob;

use crate::{asset::Asset, ident::AssetIdent, reference::ModuleReferences, source::OptionSource};
use crate::{ident::AssetIdent, reference::ModuleReferences, source::OptionSource};

#[derive(Clone, Copy, Debug, TaskInput, Hash)]
#[turbo_tasks::value(shared)]
Expand All @@ -14,7 +14,7 @@ pub enum StyleType {
/// A module. This usually represents parsed source code, which has references
/// to other modules.
#[turbo_tasks::value_trait]
pub trait Module: Asset {
pub trait Module {
/// The identifier of the [Module]. It's expected to be unique and capture
/// all properties of the [Module].
#[turbo_tasks::function]
Expand Down Expand Up @@ -55,7 +55,7 @@ pub trait Module: Asset {
}

#[turbo_tasks::value_trait]
pub trait StyleModule: Module + Asset {
pub trait StyleModule: Module {
/// The style type of the module.
#[turbo_tasks::function]
fn style_type(&self) -> Vc<StyleType>;
Expand Down
9 changes: 0 additions & 9 deletions turbopack/crates/turbopack-core/src/node_addon_module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use turbo_tasks::{FxIndexSet, ResolvedVc, TryJoinIterExt, Vc};
use turbo_tasks_fs::{FileSystemEntryType, FileSystemPath};

use crate::{
asset::{Asset, AssetContent},
file_source::FileSource,
ident::AssetIdent,
module::Module,
Expand Down Expand Up @@ -102,14 +101,6 @@ impl Module for NodeAddonModule {
}
}

#[turbo_tasks::value_impl]
impl Asset for NodeAddonModule {
#[turbo_tasks::function]
fn content(&self) -> Vc<AssetContent> {
self.source.content()
}
}

#[turbo_tasks::function]
async fn dir_references(package_dir: FileSystemPath) -> Result<Vc<ModuleReferences>> {
let matches = read_matches(
Expand Down
9 changes: 0 additions & 9 deletions turbopack/crates/turbopack-core/src/raw_module.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use turbo_tasks::{ResolvedVc, Vc};

use crate::{
asset::{Asset, AssetContent},
ident::AssetIdent,
module::Module,
source::{OptionSource, Source},
Expand All @@ -27,14 +26,6 @@ impl Module for RawModule {
}
}

#[turbo_tasks::value_impl]
impl Asset for RawModule {
#[turbo_tasks::function]
fn content(&self) -> Vc<AssetContent> {
self.source.content()
}
}

#[turbo_tasks::value_impl]
impl RawModule {
#[turbo_tasks::function]
Expand Down
15 changes: 11 additions & 4 deletions turbopack/crates/turbopack-core/src/rebase.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::hash::Hash;

use anyhow::Result;
use turbo_tasks::{ResolvedVc, TryJoinIterExt, Vc};
use anyhow::{Result, bail};
use turbo_tasks::{ResolvedVc, TryJoinIterExt, ValueToString, Vc};
use turbo_tasks_fs::FileSystemPath;

use crate::{
Expand Down Expand Up @@ -74,7 +74,14 @@ impl OutputAsset for RebasedAsset {
#[turbo_tasks::value_impl]
impl Asset for RebasedAsset {
#[turbo_tasks::function]
fn content(&self) -> Vc<AssetContent> {
self.module.content()
async fn content(&self) -> Result<Vc<AssetContent>> {
if let Some(source) = *self.module.source().await? {
Ok(source.content())
} else {
bail!(
"Module {} has no source",
self.module.ident().to_string().await?
)
}
}
}
15 changes: 11 additions & 4 deletions turbopack/crates/turbopack-core/src/traced_asset.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use anyhow::Result;
use turbo_tasks::{ResolvedVc, TryJoinIterExt, Vc};
use anyhow::{Result, bail};
use turbo_tasks::{ResolvedVc, TryJoinIterExt, ValueToString, Vc};
use turbo_tasks_fs::FileSystemPath;

use crate::{
Expand Down Expand Up @@ -54,7 +54,14 @@ impl OutputAsset for TracedAsset {
#[turbo_tasks::value_impl]
impl Asset for TracedAsset {
#[turbo_tasks::function]
fn content(&self) -> Vc<AssetContent> {
self.module.content()
async fn content(&self) -> Result<Vc<AssetContent>> {
if let Some(source) = *self.module.source().await? {
Ok(source.content())
} else {
bail!(
"Module {} has no source",
self.module.ident().to_string().await?,
)
}
}
}
Loading
Loading