From f0d34dd0dfafafe9f2baacf6d630ac04a7bc2852 Mon Sep 17 00:00:00 2001 From: Justin Ridgewell Date: Fri, 6 Oct 2023 00:30:28 -0400 Subject: [PATCH] Extract as_chunk into shared ChunkType trait --- .../turbopack-build/src/chunking_context.rs | 38 ++++++++------- crates/turbopack-core/src/chunk/mod.rs | 46 ++++++++++++++----- crates/turbopack-css/src/asset.rs | 21 ++++----- crates/turbopack-css/src/chunk/mod.rs | 39 ++++++++++++++-- crates/turbopack-css/src/module_asset.rs | 22 ++++----- crates/turbopack-dev/src/chunking_context.rs | 25 ++++++---- .../src/chunk/chunk_type.rs | 40 ++++++++++++++++ crates/turbopack-ecmascript/src/chunk/mod.rs | 2 + .../src/chunk_group_files_asset.rs | 23 +++++----- crates/turbopack-ecmascript/src/lib.rs | 19 ++++---- .../src/manifest/chunk_item.rs | 24 +++++----- .../src/manifest/loader_item.rs | 22 ++++----- .../src/references/require_context.rs | 19 ++++---- .../src/tree_shake/chunk_item.rs | 19 ++++---- crates/turbopack-json/src/lib.rs | 21 ++++----- crates/turbopack-mdx/src/lib.rs | 21 ++++----- crates/turbopack-static/src/lib.rs | 23 +++++----- crates/turbopack-wasm/src/module_asset.rs | 19 ++++---- crates/turbopack-wasm/src/raw.rs | 23 +++++----- 19 files changed, 284 insertions(+), 182 deletions(-) create mode 100644 crates/turbopack-ecmascript/src/chunk/chunk_type.rs diff --git a/crates/turbopack-build/src/chunking_context.rs b/crates/turbopack-build/src/chunking_context.rs index 8b034921d0f5cf..589c5dd6bb49db 100644 --- a/crates/turbopack-build/src/chunking_context.rs +++ b/crates/turbopack-build/src/chunking_context.rs @@ -9,8 +9,8 @@ use turbo_tasks::{ use turbo_tasks_fs::FileSystemPath; use turbopack_core::{ chunk::{ - availability_info::AvailabilityInfo, Chunk, ChunkItem, ChunkableModule, ChunkingContext, - Chunks, EvaluatableAssets, + availability_info::AvailabilityInfo, Chunk, ChunkItem, ChunkType, ChunkableModule, + ChunkingContext, Chunks, EvaluatableAssets, }, environment::Environment, ident::AssetIdent, @@ -166,12 +166,13 @@ impl BuildChunkingContext { module: Vc>, evaluatable_assets: Vc, ) -> Result>> { - let entry_chunk = - module - .as_chunk_item(Vc::upcast(self)) - .as_chunk(Value::new(AvailabilityInfo::Root { - current_availability_root: Vc::upcast(module), - })); + let entry_chunk_item = module.as_chunk_item(Vc::upcast(self)); + let entry_chunk = entry_chunk_item.ty().as_chunk( + entry_chunk_item, + Value::new(AvailabilityInfo::Root { + current_availability_root: Vc::upcast(module), + }), + ); let other_chunks = self .get_chunk_assets(entry_chunk, evaluatable_assets) @@ -221,11 +222,15 @@ impl BuildChunkingContext { .iter() .map({ move |evaluatable_asset| async move { - evaluatable_asset - .as_chunk_item(Vc::upcast(self)) - .as_chunk(Value::new(AvailabilityInfo::Root { - current_availability_root: Vc::upcast(*evaluatable_asset), - })) + let chunk_item = evaluatable_asset.as_chunk_item(Vc::upcast(self)); + chunk_item + .ty() + .as_chunk( + chunk_item, + Value::new(AvailabilityInfo::Root { + current_availability_root: Vc::upcast(*evaluatable_asset), + }), + ) .resolve() .await } @@ -364,9 +369,10 @@ impl ChunkingContext for BuildChunkingContext { module: Vc>, availability_info: Value, ) -> Result> { - let entry_chunk = module - .as_chunk_item(Vc::upcast(self)) - .as_chunk(availability_info); + let entry_chunk_item = module.as_chunk_item(Vc::upcast(self)); + let entry_chunk = entry_chunk_item + .ty() + .as_chunk(entry_chunk_item, availability_info); let parallel_chunks = get_parallel_chunks([entry_chunk]).await?; let optimized_chunks = get_optimized_chunks(parallel_chunks).await?; diff --git a/crates/turbopack-core/src/chunk/mod.rs b/crates/turbopack-core/src/chunk/mod.rs index dc0d738870ed12..88a8b16bebebe2 100644 --- a/crates/turbopack-core/src/chunk/mod.rs +++ b/crates/turbopack-core/src/chunk/mod.rs @@ -355,20 +355,25 @@ where } } ChunkingType::Parallel => { - let chunk = chunkable_module - .as_chunk_item(chunk_content_context.chunking_context) - .as_chunk(chunk_content_context.availability_info); + let chunk_item = + chunkable_module.as_chunk_item(chunk_content_context.chunking_context); + let chunk = chunk_item + .ty() + .as_chunk(chunk_item, chunk_content_context.availability_info); graph_nodes.push(( Some((module, chunking_type)), ChunkContentGraphNode::Chunk(chunk), )); } ChunkingType::IsolatedParallel => { - let chunk = chunkable_module - .as_chunk_item(chunk_content_context.chunking_context) - .as_chunk(Value::new(AvailabilityInfo::Root { + let chunk_item = + chunkable_module.as_chunk_item(chunk_content_context.chunking_context); + let chunk = chunk_item.ty().as_chunk( + chunk_item, + Value::new(AvailabilityInfo::Root { current_availability_root: Vc::upcast(chunkable_module), - })); + }), + ); graph_nodes.push(( Some((module, chunking_type)), ChunkContentGraphNode::Chunk(chunk), @@ -397,9 +402,11 @@ where } } - let chunk = chunkable_module - .as_chunk_item(chunk_content_context.chunking_context) - .as_chunk(chunk_content_context.availability_info); + let chunk_item = + chunkable_module.as_chunk_item(chunk_content_context.chunking_context); + let chunk = chunk_item + .ty() + .as_chunk(chunk_item, chunk_content_context.availability_info); graph_nodes.push(( Some((module, chunking_type)), ChunkContentGraphNode::Chunk(chunk), @@ -613,8 +620,6 @@ where #[turbo_tasks::value_trait] pub trait ChunkItem { - fn as_chunk(self: Vc, availability_info: Value) -> Vc>; - /// The [AssetIdent] of the [Module] that this [ChunkItem] was created from. /// For most chunk types this must uniquely identify the asset as it's the /// source of the module id used at runtime. @@ -625,9 +630,26 @@ pub trait ChunkItem { /// references. fn references(self: Vc) -> Vc; + /// The type of chunk this item should be assembled into. + fn ty(self: Vc) -> Vc>; + + /// A temporary method to retrieve the module associated with this + /// ChunkItem. TODO: Remove this as part of the chunk refactoring. + fn module(self: Vc) -> Vc>; + fn chunking_context(self: Vc) -> Vc>; } +#[turbo_tasks::value_trait] +pub trait ChunkType { + /// Create a new chunk for the given subgraph. + fn as_chunk( + &self, + chunk_item: Vc>, + availability_info: Value, + ) -> Vc>; +} + #[turbo_tasks::value(transparent)] pub struct ChunkItems(Vec>>); diff --git a/crates/turbopack-css/src/asset.rs b/crates/turbopack-css/src/asset.rs index 04697bad2ab2cd..8b8c68288a292d 100644 --- a/crates/turbopack-css/src/asset.rs +++ b/crates/turbopack-css/src/asset.rs @@ -7,13 +7,11 @@ use swc_core::{ visit::{VisitMutWith, VisitMutWithPath}, }, }; -use turbo_tasks::{TryJoinIterExt, Value, ValueToString, Vc}; +use turbo_tasks::{TryJoinIterExt, ValueToString, Vc}; use turbo_tasks_fs::FileSystemPath; use turbopack_core::{ asset::{Asset, AssetContent}, - chunk::{ - availability_info::AvailabilityInfo, Chunk, ChunkItem, ChunkableModule, ChunkingContext, - }, + chunk::{ChunkItem, ChunkType, ChunkableModule, ChunkingContext}, context::AssetContext, ident::AssetIdent, module::Module, @@ -23,7 +21,7 @@ use turbopack_core::{ }; use crate::{ - chunk::{CssChunk, CssChunkItem, CssChunkItemContent, CssChunkPlaceable, CssImport}, + chunk::{CssChunkItem, CssChunkItemContent, CssChunkPlaceable, CssChunkType, CssImport}, code_gen::CodeGenerateable, parse::{parse_css, ParseCss, ParseCssResult, ParseCssResultSourceMap}, path_visitor::ApplyVisitors, @@ -163,12 +161,13 @@ impl ChunkItem for CssModuleChunkItem { } #[turbo_tasks::function] - fn as_chunk(&self, availability_info: Value) -> Vc> { - Vc::upcast(CssChunk::new( - self.chunking_context, - Vc::upcast(self.module), - availability_info, - )) + fn ty(&self) -> Vc> { + Vc::upcast(Vc::::default()) + } + + #[turbo_tasks::function] + fn module(&self) -> Vc> { + Vc::upcast(self.module) } } diff --git a/crates/turbopack-css/src/chunk/mod.rs b/crates/turbopack-css/src/chunk/mod.rs index 7b457398caebfa..a6ce10af69949a 100644 --- a/crates/turbopack-css/src/chunk/mod.rs +++ b/crates/turbopack-css/src/chunk/mod.rs @@ -4,16 +4,16 @@ pub(crate) mod writer; use std::fmt::Write; -use anyhow::{anyhow, Result}; +use anyhow::{anyhow, Context, Result}; use indexmap::IndexSet; -use turbo_tasks::{TryJoinIterExt, Value, ValueToString, Vc}; +use turbo_tasks::{TryJoinIterExt, Value, ValueDefault, ValueToString, Vc}; use turbo_tasks_fs::{rope::Rope, File, FileSystemPathOption}; use turbopack_core::{ asset::{Asset, AssetContent}, chunk::{ availability_info::AvailabilityInfo, chunk_content, chunk_content_split, Chunk, - ChunkContentResult, ChunkItem, ChunkItemExt, ChunkableModule, ChunkingContext, Chunks, - FromChunkableModule, ModuleId, OutputChunk, OutputChunkRuntimeInfo, + ChunkContentResult, ChunkItem, ChunkItemExt, ChunkType, ChunkableModule, ChunkingContext, + Chunks, FromChunkableModule, ModuleId, OutputChunk, OutputChunkRuntimeInfo, }, code_builder::{Code, CodeBuilder}, ident::AssetIdent, @@ -614,3 +614,34 @@ impl Introspectable for CssChunk { Ok(Vc::cell(children)) } } + +#[derive(Default)] +#[turbo_tasks::value] +pub struct CssChunkType {} + +#[turbo_tasks::value_impl] +impl ChunkType for CssChunkType { + #[turbo_tasks::function] + async fn as_chunk( + &self, + chunk_item: Vc>, + availability_info: Value, + ) -> Result>> { + let placeable = Vc::try_resolve_sidecast::>(chunk_item.module()) + .await? + .context("Module must implmement CssChunkPlaceable to be used as a CSS Chunk")?; + Ok(Vc::upcast(CssChunk::new( + chunk_item.chunking_context(), + placeable, + availability_info, + ))) + } +} + +#[turbo_tasks::value_impl] +impl ValueDefault for CssChunkType { + #[turbo_tasks::function] + fn value_default() -> Vc { + Self::default().cell() + } +} diff --git a/crates/turbopack-css/src/module_asset.rs b/crates/turbopack-css/src/module_asset.rs index 49523329e9e3da..8935a2ddfff06d 100644 --- a/crates/turbopack-css/src/module_asset.rs +++ b/crates/turbopack-css/src/module_asset.rs @@ -11,10 +11,7 @@ use turbo_tasks::{Value, ValueToString, Vc}; use turbo_tasks_fs::FileSystemPath; use turbopack_core::{ asset::{Asset, AssetContent}, - chunk::{ - availability_info::AvailabilityInfo, Chunk, ChunkItem, ChunkItemExt, ChunkableModule, - ChunkingContext, - }, + chunk::{ChunkItem, ChunkItemExt, ChunkType, ChunkableModule, ChunkingContext}, context::AssetContext, ident::AssetIdent, issue::{Issue, IssueExt, IssueSeverity}, @@ -26,8 +23,8 @@ use turbopack_core::{ }; use turbopack_ecmascript::{ chunk::{ - EcmascriptChunk, EcmascriptChunkItem, EcmascriptChunkItemContent, EcmascriptChunkPlaceable, - EcmascriptChunkingContext, EcmascriptExports, + EcmascriptChunkItem, EcmascriptChunkItemContent, EcmascriptChunkPlaceable, + EcmascriptChunkType, EcmascriptChunkingContext, EcmascriptExports, }, utils::StringifyJs, ParseResultSourceMap, @@ -277,12 +274,13 @@ impl ChunkItem for ModuleChunkItem { } #[turbo_tasks::function] - fn as_chunk(&self, availability_info: Value) -> Vc> { - Vc::upcast(EcmascriptChunk::new( - Vc::upcast(self.chunking_context), - Vc::upcast(self.module), - availability_info, - )) + fn ty(&self) -> Vc> { + Vc::upcast(Vc::::default()) + } + + #[turbo_tasks::function] + fn module(&self) -> Vc> { + Vc::upcast(self.module) } } diff --git a/crates/turbopack-dev/src/chunking_context.rs b/crates/turbopack-dev/src/chunking_context.rs index d700681d6fd5fc..ea2c7a50142bbd 100644 --- a/crates/turbopack-dev/src/chunking_context.rs +++ b/crates/turbopack-dev/src/chunking_context.rs @@ -7,8 +7,8 @@ use turbo_tasks::{ use turbo_tasks_fs::FileSystemPath; use turbopack_core::{ chunk::{ - availability_info::AvailabilityInfo, Chunk, ChunkItem, ChunkableModule, ChunkingContext, - Chunks, EvaluatableAssets, + availability_info::AvailabilityInfo, Chunk, ChunkItem, ChunkType, ChunkableModule, + ChunkingContext, Chunks, EvaluatableAssets, }, environment::Environment, ident::AssetIdent, @@ -346,9 +346,10 @@ impl ChunkingContext for DevChunkingContext { module: Vc>, availability_info: Value, ) -> Result> { - let entry_chunk = module - .as_chunk_item(Vc::upcast(self)) - .as_chunk(availability_info); + let entry_chunk_item = module.as_chunk_item(Vc::upcast(self)); + let entry_chunk = entry_chunk_item + .ty() + .as_chunk(entry_chunk_item, availability_info); let parallel_chunks = get_parallel_chunks([entry_chunk]).await?; let optimized_chunks = get_optimized_chunks(parallel_chunks).await?; @@ -381,11 +382,15 @@ impl ChunkingContext for DevChunkingContext { .iter() .map({ move |evaluatable_asset| async move { - evaluatable_asset - .as_chunk_item(Vc::upcast(self)) - .as_chunk(Value::new(AvailabilityInfo::Root { - current_availability_root: Vc::upcast(*evaluatable_asset), - })) + let chunk_item = evaluatable_asset.as_chunk_item(Vc::upcast(self)); + chunk_item + .ty() + .as_chunk( + chunk_item, + Value::new(AvailabilityInfo::Root { + current_availability_root: Vc::upcast(*evaluatable_asset), + }), + ) .resolve() .await } diff --git a/crates/turbopack-ecmascript/src/chunk/chunk_type.rs b/crates/turbopack-ecmascript/src/chunk/chunk_type.rs new file mode 100644 index 00000000000000..20ddae2ed990d6 --- /dev/null +++ b/crates/turbopack-ecmascript/src/chunk/chunk_type.rs @@ -0,0 +1,40 @@ +use anyhow::{Context, Result}; +use turbo_tasks::{Value, ValueDefault, Vc}; +use turbopack_core::chunk::{availability_info::AvailabilityInfo, Chunk, ChunkItem, ChunkType}; + +use super::{EcmascriptChunk, EcmascriptChunkPlaceable}; + +#[derive(Default)] +#[turbo_tasks::value] +pub struct EcmascriptChunkType {} + +#[turbo_tasks::value_impl] +impl ChunkType for EcmascriptChunkType { + #[turbo_tasks::function] + async fn as_chunk( + &self, + chunk_item: Vc>, + availability_info: Value, + ) -> Result>> { + let placeable = + Vc::try_resolve_sidecast::>(chunk_item.module()) + .await? + .context( + "Module must implmement EcmascriptChunkPlaceable to be used as a EcmaScript \ + Chunk", + )?; + Ok(Vc::upcast(EcmascriptChunk::new( + chunk_item.chunking_context(), + placeable, + availability_info, + ))) + } +} + +#[turbo_tasks::value_impl] +impl ValueDefault for EcmascriptChunkType { + #[turbo_tasks::function] + fn value_default() -> Vc { + Self::default().cell() + } +} diff --git a/crates/turbopack-ecmascript/src/chunk/mod.rs b/crates/turbopack-ecmascript/src/chunk/mod.rs index 3d48a2ba3fcccb..f4e41921bb35fb 100644 --- a/crates/turbopack-ecmascript/src/chunk/mod.rs +++ b/crates/turbopack-ecmascript/src/chunk/mod.rs @@ -1,3 +1,4 @@ +pub(crate) mod chunk_type; pub(crate) mod content; pub(crate) mod context; pub(crate) mod data; @@ -30,6 +31,7 @@ use turbopack_core::{ use self::content::ecmascript_chunk_content; pub use self::{ + chunk_type::EcmascriptChunkType, content::EcmascriptChunkContent, context::EcmascriptChunkingContext, data::EcmascriptChunkData, diff --git a/crates/turbopack-ecmascript/src/chunk_group_files_asset.rs b/crates/turbopack-ecmascript/src/chunk_group_files_asset.rs index 343e7554090913..b5d0ea7b2510e2 100644 --- a/crates/turbopack-ecmascript/src/chunk_group_files_asset.rs +++ b/crates/turbopack-ecmascript/src/chunk_group_files_asset.rs @@ -1,12 +1,12 @@ use anyhow::{Context, Result}; use indexmap::IndexSet; -use turbo_tasks::{TryJoinIterExt, Value, ValueToString, Vc}; +use turbo_tasks::{TryJoinIterExt, ValueToString, Vc}; use turbo_tasks_fs::{File, FileSystemPath}; use turbopack_core::{ asset::{Asset, AssetContent}, chunk::{ - availability_info::AvailabilityInfo, Chunk, ChunkItem, ChunkableModule, ChunkingContext, - ChunkingContextExt, EvaluatableAssets, + ChunkItem, ChunkType, ChunkableModule, ChunkingContext, ChunkingContextExt, + EvaluatableAssets, }, ident::AssetIdent, introspect::{ @@ -22,8 +22,8 @@ use turbopack_core::{ use crate::{ chunk::{ - EcmascriptChunk, EcmascriptChunkItem, EcmascriptChunkItemContent, EcmascriptChunkPlaceable, - EcmascriptChunkingContext, EcmascriptExports, + EcmascriptChunkItem, EcmascriptChunkItemContent, EcmascriptChunkPlaceable, + EcmascriptChunkType, EcmascriptChunkingContext, EcmascriptExports, }, utils::StringifyJs, EcmascriptModuleAsset, @@ -227,12 +227,13 @@ impl ChunkItem for ChunkGroupFilesChunkItem { } #[turbo_tasks::function] - fn as_chunk(&self, availability_info: Value) -> Vc> { - Vc::upcast(EcmascriptChunk::new( - Vc::upcast(self.chunking_context), - Vc::upcast(self.inner), - availability_info, - )) + fn ty(&self) -> Vc> { + Vc::upcast(Vc::::default()) + } + + #[turbo_tasks::function] + fn module(&self) -> Vc> { + Vc::upcast(self.inner) } } diff --git a/crates/turbopack-ecmascript/src/lib.rs b/crates/turbopack-ecmascript/src/lib.rs index 048c6017f803ff..46a99d4e23dff2 100644 --- a/crates/turbopack-ecmascript/src/lib.rs +++ b/crates/turbopack-ecmascript/src/lib.rs @@ -54,8 +54,8 @@ use turbo_tasks_fs::{rope::Rope, FileSystemPath}; use turbopack_core::{ asset::{Asset, AssetContent}, chunk::{ - availability_info::AvailabilityInfo, Chunk, ChunkItem, ChunkableModule, ChunkingContext, - EvaluatableAsset, + availability_info::AvailabilityInfo, Chunk, ChunkItem, ChunkType, ChunkableModule, + ChunkingContext, EvaluatableAsset, }, compile_time_info::CompileTimeInfo, context::AssetContext, @@ -68,7 +68,7 @@ use turbopack_core::{ }; use self::{ - chunk::{EcmascriptChunkItemContent, EcmascriptExports}, + chunk::{EcmascriptChunkItemContent, EcmascriptChunkType, EcmascriptExports}, code_gen::{CodeGen, CodeGenerateableWithAvailabilityInfo, VisitorFactory}, tree_shake::asset::EcmascriptModulePartAsset, }; @@ -488,12 +488,13 @@ impl ChunkItem for ModuleChunkItem { } #[turbo_tasks::function] - fn as_chunk(&self, availability_info: Value) -> Vc> { - Vc::upcast(EcmascriptChunk::new( - Vc::upcast(self.chunking_context), - Vc::upcast(self.module), - availability_info, - )) + fn ty(&self) -> Vc> { + Vc::upcast(Vc::::default()) + } + + #[turbo_tasks::function] + fn module(&self) -> Vc> { + Vc::upcast(self.module) } } diff --git a/crates/turbopack-ecmascript/src/manifest/chunk_item.rs b/crates/turbopack-ecmascript/src/manifest/chunk_item.rs index 7b327dff379876..5dcf38b2038d0b 100644 --- a/crates/turbopack-ecmascript/src/manifest/chunk_item.rs +++ b/crates/turbopack-ecmascript/src/manifest/chunk_item.rs @@ -1,11 +1,8 @@ use anyhow::Result; use indoc::formatdoc; -use turbo_tasks::{TryJoinIterExt, Value, Vc}; +use turbo_tasks::{TryJoinIterExt, Vc}; use turbopack_core::{ - chunk::{ - availability_info::AvailabilityInfo, Chunk, ChunkData, ChunkItem, ChunkingContext, - ChunksData, - }, + chunk::{ChunkData, ChunkItem, ChunkType, ChunkingContext, ChunksData}, ident::AssetIdent, module::Module, reference::{ModuleReferences, SingleOutputAssetReference}, @@ -14,8 +11,8 @@ use turbopack_core::{ use super::chunk_asset::ManifestChunkAsset; use crate::{ chunk::{ - data::EcmascriptChunkData, EcmascriptChunk, EcmascriptChunkItem, - EcmascriptChunkItemContent, EcmascriptChunkingContext, + data::EcmascriptChunkData, EcmascriptChunkItem, EcmascriptChunkItemContent, + EcmascriptChunkType, EcmascriptChunkingContext, }, utils::StringifyJs, }; @@ -101,11 +98,12 @@ impl ChunkItem for ManifestChunkItem { } #[turbo_tasks::function] - fn as_chunk(&self, availability_info: Value) -> Vc> { - Vc::upcast(EcmascriptChunk::new( - Vc::upcast(self.chunking_context), - Vc::upcast(self.manifest), - availability_info, - )) + fn ty(&self) -> Vc> { + Vc::upcast(Vc::::default()) + } + + #[turbo_tasks::function] + fn module(&self) -> Vc> { + Vc::upcast(self.manifest) } } diff --git a/crates/turbopack-ecmascript/src/manifest/loader_item.rs b/crates/turbopack-ecmascript/src/manifest/loader_item.rs index 894a738d22ee20..eb72b77d33996a 100644 --- a/crates/turbopack-ecmascript/src/manifest/loader_item.rs +++ b/crates/turbopack-ecmascript/src/manifest/loader_item.rs @@ -2,11 +2,10 @@ use std::io::Write as _; use anyhow::{anyhow, Result}; use indoc::writedoc; -use turbo_tasks::{TryJoinIterExt, Value, Vc}; +use turbo_tasks::{TryJoinIterExt, Vc}; use turbopack_core::{ chunk::{ - availability_info::AvailabilityInfo, Chunk, ChunkData, ChunkItem, ChunkItemExt, - ChunkableModule, ChunkingContext, ChunksData, + ChunkData, ChunkItem, ChunkItemExt, ChunkType, ChunkableModule, ChunkingContext, ChunksData, }, ident::AssetIdent, module::Module, @@ -16,8 +15,8 @@ use turbopack_core::{ use super::chunk_asset::ManifestChunkAsset; use crate::{ chunk::{ - data::EcmascriptChunkData, EcmascriptChunk, EcmascriptChunkItem, - EcmascriptChunkItemContent, EcmascriptChunkPlaceable, EcmascriptChunkingContext, + data::EcmascriptChunkData, EcmascriptChunkItem, EcmascriptChunkItemContent, + EcmascriptChunkPlaceable, EcmascriptChunkType, EcmascriptChunkingContext, }, utils::StringifyJs, }; @@ -121,12 +120,13 @@ impl ChunkItem for ManifestLoaderItem { } #[turbo_tasks::function] - fn as_chunk(&self, availability_info: Value) -> Vc> { - Vc::upcast(EcmascriptChunk::new( - self.chunking_context, - Vc::upcast(self.manifest), - availability_info, - )) + fn ty(&self) -> Vc> { + Vc::upcast(Vc::::default()) + } + + #[turbo_tasks::function] + fn module(&self) -> Vc> { + Vc::upcast(self.manifest) } } diff --git a/crates/turbopack-ecmascript/src/references/require_context.rs b/crates/turbopack-ecmascript/src/references/require_context.rs index 79a8d3001161e4..006006980039f9 100644 --- a/crates/turbopack-ecmascript/src/references/require_context.rs +++ b/crates/turbopack-ecmascript/src/references/require_context.rs @@ -18,8 +18,8 @@ use turbo_tasks_fs::{DirectoryContent, DirectoryEntry, FileSystemPath}; use turbopack_core::{ asset::{Asset, AssetContent}, chunk::{ - availability_info::AvailabilityInfo, Chunk, ChunkItem, ChunkItemExt, ChunkableModule, - ChunkableModuleReference, ChunkingContext, + ChunkItem, ChunkItemExt, ChunkType, ChunkableModule, ChunkableModuleReference, + ChunkingContext, }, ident::AssetIdent, issue::{IssueSeverity, OptionIssueSource}, @@ -31,7 +31,7 @@ use turbopack_core::{ use crate::{ chunk::{ - EcmascriptChunk, EcmascriptChunkItem, EcmascriptChunkItemContent, + EcmascriptChunkItem, EcmascriptChunkItemContent, EcmascriptChunkType, EcmascriptChunkingContext, EcmascriptExports, }, code_gen::CodeGeneration, @@ -516,11 +516,12 @@ impl ChunkItem for RequireContextChunkItem { } #[turbo_tasks::function] - fn as_chunk(&self, availability_info: Value) -> Vc> { - Vc::upcast(EcmascriptChunk::new( - Vc::upcast(self.chunking_context), - Vc::upcast(self.inner), - availability_info, - )) + fn ty(&self) -> Vc> { + Vc::upcast(Vc::::default()) + } + + #[turbo_tasks::function] + fn module(&self) -> Vc> { + Vc::upcast(self.inner) } } diff --git a/crates/turbopack-ecmascript/src/tree_shake/chunk_item.rs b/crates/turbopack-ecmascript/src/tree_shake/chunk_item.rs index 3d0b9c60854a23..7a1c91e84e3e4d 100644 --- a/crates/turbopack-ecmascript/src/tree_shake/chunk_item.rs +++ b/crates/turbopack-ecmascript/src/tree_shake/chunk_item.rs @@ -1,7 +1,7 @@ use anyhow::Result; use turbo_tasks::{Value, Vc}; use turbopack_core::{ - chunk::{availability_info::AvailabilityInfo, Chunk, ChunkItem, ChunkingContext}, + chunk::{availability_info::AvailabilityInfo, ChunkItem, ChunkType, ChunkingContext}, ident::AssetIdent, module::Module, reference::ModuleReferences, @@ -10,8 +10,8 @@ use turbopack_core::{ use super::{asset::EcmascriptModulePartAsset, part_of_module, split_module}; use crate::{ chunk::{ - placeable::EcmascriptChunkPlaceable, EcmascriptChunk, EcmascriptChunkItem, - EcmascriptChunkItemContent, EcmascriptChunkingContext, + placeable::EcmascriptChunkPlaceable, EcmascriptChunkItem, EcmascriptChunkItemContent, + EcmascriptChunkType, EcmascriptChunkingContext, }, EcmascriptModuleContent, }; @@ -93,11 +93,12 @@ impl ChunkItem for EcmascriptModulePartChunkItem { } #[turbo_tasks::function] - fn as_chunk(&self, availability_info: Value) -> Vc> { - Vc::upcast(EcmascriptChunk::new( - Vc::upcast(self.chunking_context), - Vc::upcast(self.module), - availability_info, - )) + fn ty(&self) -> Vc> { + Vc::upcast(Vc::::default()) + } + + #[turbo_tasks::function] + fn module(&self) -> Vc> { + Vc::upcast(self.module) } } diff --git a/crates/turbopack-json/src/lib.rs b/crates/turbopack-json/src/lib.rs index e9ceeffc3555f2..eae0ea7bcd222c 100644 --- a/crates/turbopack-json/src/lib.rs +++ b/crates/turbopack-json/src/lib.rs @@ -12,20 +12,18 @@ use std::fmt::Write; use anyhow::{bail, Context, Error, Result}; -use turbo_tasks::{Value, ValueToString, Vc}; +use turbo_tasks::{ValueToString, Vc}; use turbo_tasks_fs::{FileContent, FileJsonContent}; use turbopack_core::{ asset::{Asset, AssetContent}, - chunk::{ - availability_info::AvailabilityInfo, Chunk, ChunkItem, ChunkableModule, ChunkingContext, - }, + chunk::{ChunkItem, ChunkType, ChunkableModule, ChunkingContext}, ident::AssetIdent, module::Module, reference::ModuleReferences, source::Source, }; use turbopack_ecmascript::chunk::{ - EcmascriptChunk, EcmascriptChunkItem, EcmascriptChunkItemContent, EcmascriptChunkPlaceable, + EcmascriptChunkItem, EcmascriptChunkItemContent, EcmascriptChunkPlaceable, EcmascriptChunkType, EcmascriptChunkingContext, EcmascriptExports, }; @@ -115,12 +113,13 @@ impl ChunkItem for JsonChunkItem { } #[turbo_tasks::function] - fn as_chunk(&self, availability_info: Value) -> Vc> { - Vc::upcast(EcmascriptChunk::new( - Vc::upcast(self.chunking_context), - Vc::upcast(self.module), - availability_info, - )) + fn ty(&self) -> Vc> { + Vc::upcast(Vc::::default()) + } + + #[turbo_tasks::function] + fn module(&self) -> Vc> { + Vc::upcast(self.module) } } diff --git a/crates/turbopack-mdx/src/lib.rs b/crates/turbopack-mdx/src/lib.rs index 2f0640113077ce..42d06ad0ab5dc1 100644 --- a/crates/turbopack-mdx/src/lib.rs +++ b/crates/turbopack-mdx/src/lib.rs @@ -8,9 +8,7 @@ use turbo_tasks::{Value, ValueDefault, Vc}; use turbo_tasks_fs::{rope::Rope, File, FileContent, FileSystemPath}; use turbopack_core::{ asset::{Asset, AssetContent}, - chunk::{ - availability_info::AvailabilityInfo, Chunk, ChunkItem, ChunkableModule, ChunkingContext, - }, + chunk::{ChunkItem, ChunkType, ChunkableModule, ChunkingContext}, context::AssetContext, ident::AssetIdent, module::Module, @@ -21,8 +19,8 @@ use turbopack_core::{ }; use turbopack_ecmascript::{ chunk::{ - EcmascriptChunk, EcmascriptChunkItem, EcmascriptChunkItemContent, EcmascriptChunkPlaceable, - EcmascriptChunkingContext, EcmascriptExports, + EcmascriptChunkItem, EcmascriptChunkItemContent, EcmascriptChunkPlaceable, + EcmascriptChunkType, EcmascriptChunkingContext, EcmascriptExports, }, AnalyzeEcmascriptModuleResult, EcmascriptInputTransforms, EcmascriptModuleAsset, EcmascriptModuleAssetType, @@ -251,12 +249,13 @@ impl ChunkItem for MdxChunkItem { } #[turbo_tasks::function] - fn as_chunk(&self, availability_info: Value) -> Vc> { - Vc::upcast(EcmascriptChunk::new( - Vc::upcast(self.chunking_context), - Vc::upcast(self.module), - availability_info, - )) + fn ty(&self) -> Vc> { + Vc::upcast(Vc::::default()) + } + + #[turbo_tasks::function] + fn module(&self) -> Vc> { + Vc::upcast(self.module) } } diff --git a/crates/turbopack-static/src/lib.rs b/crates/turbopack-static/src/lib.rs index 1a3b9aeb5d0625..e6f046a5ddabbb 100644 --- a/crates/turbopack-static/src/lib.rs +++ b/crates/turbopack-static/src/lib.rs @@ -15,13 +15,11 @@ pub mod fixed; use anyhow::{anyhow, Context, Result}; -use turbo_tasks::{Value, ValueToString, Vc}; +use turbo_tasks::{ValueToString, Vc}; use turbo_tasks_fs::FileContent; use turbopack_core::{ asset::{Asset, AssetContent}, - chunk::{ - availability_info::AvailabilityInfo, Chunk, ChunkItem, ChunkableModule, ChunkingContext, - }, + chunk::{ChunkItem, ChunkType, ChunkableModule, ChunkingContext}, context::AssetContext, ident::AssetIdent, module::Module, @@ -32,8 +30,8 @@ use turbopack_core::{ use turbopack_css::embed::{CssEmbed, CssEmbeddable}; use turbopack_ecmascript::{ chunk::{ - EcmascriptChunk, EcmascriptChunkItem, EcmascriptChunkItemContent, EcmascriptChunkPlaceable, - EcmascriptChunkingContext, EcmascriptExports, + EcmascriptChunkItem, EcmascriptChunkItemContent, EcmascriptChunkPlaceable, + EcmascriptChunkType, EcmascriptChunkingContext, EcmascriptExports, }, utils::StringifyJs, }; @@ -197,12 +195,13 @@ impl ChunkItem for ModuleChunkItem { } #[turbo_tasks::function] - fn as_chunk(&self, availability_info: Value) -> Vc> { - Vc::upcast(EcmascriptChunk::new( - Vc::upcast(self.chunking_context), - Vc::upcast(self.module), - availability_info, - )) + fn ty(&self) -> Vc> { + Vc::upcast(Vc::::default()) + } + + #[turbo_tasks::function] + fn module(&self) -> Vc> { + Vc::upcast(self.module) } } diff --git a/crates/turbopack-wasm/src/module_asset.rs b/crates/turbopack-wasm/src/module_asset.rs index 1d0a65484b1d0e..03ede8e2c1ee16 100644 --- a/crates/turbopack-wasm/src/module_asset.rs +++ b/crates/turbopack-wasm/src/module_asset.rs @@ -5,7 +5,7 @@ use turbo_tasks_fs::FileSystemPath; use turbopack_core::{ asset::{Asset, AssetContent}, chunk::{ - availability_info::AvailabilityInfo, Chunk, ChunkItem, ChunkableModule, ChunkingContext, + availability_info::AvailabilityInfo, ChunkItem, ChunkType, ChunkableModule, ChunkingContext, }, context::AssetContext, ident::AssetIdent, @@ -17,8 +17,8 @@ use turbopack_core::{ }; use turbopack_ecmascript::{ chunk::{ - EcmascriptChunk, EcmascriptChunkItem, EcmascriptChunkItemContent, - EcmascriptChunkItemOptions, EcmascriptChunkPlaceable, EcmascriptChunkingContext, + EcmascriptChunkItem, EcmascriptChunkItemContent, EcmascriptChunkItemOptions, + EcmascriptChunkPlaceable, EcmascriptChunkType, EcmascriptChunkingContext, EcmascriptExports, }, references::async_module::OptionAsyncModule, @@ -196,12 +196,13 @@ impl ChunkItem for ModuleChunkItem { } #[turbo_tasks::function] - fn as_chunk(&self, availability_info: Value) -> Vc> { - Vc::upcast(EcmascriptChunk::new( - Vc::upcast(self.chunking_context), - Vc::upcast(self.module), - availability_info, - )) + fn ty(&self) -> Vc> { + Vc::upcast(Vc::::default()) + } + + #[turbo_tasks::function] + fn module(&self) -> Vc> { + Vc::upcast(self.module) } } diff --git a/crates/turbopack-wasm/src/raw.rs b/crates/turbopack-wasm/src/raw.rs index 00a80845251a86..0b2194e16c40d9 100644 --- a/crates/turbopack-wasm/src/raw.rs +++ b/crates/turbopack-wasm/src/raw.rs @@ -1,10 +1,8 @@ use anyhow::{bail, Context, Result}; -use turbo_tasks::{Value, ValueToString, Vc}; +use turbo_tasks::{ValueToString, Vc}; use turbopack_core::{ asset::{Asset, AssetContent}, - chunk::{ - availability_info::AvailabilityInfo, Chunk, ChunkItem, ChunkableModule, ChunkingContext, - }, + chunk::{ChunkItem, ChunkType, ChunkableModule, ChunkingContext}, context::AssetContext, ident::AssetIdent, module::Module, @@ -14,8 +12,8 @@ use turbopack_core::{ }; use turbopack_ecmascript::{ chunk::{ - EcmascriptChunk, EcmascriptChunkItem, EcmascriptChunkItemContent, EcmascriptChunkPlaceable, - EcmascriptChunkingContext, EcmascriptExports, + EcmascriptChunkItem, EcmascriptChunkItemContent, EcmascriptChunkPlaceable, + EcmascriptChunkType, EcmascriptChunkingContext, EcmascriptExports, }, utils::StringifyJs, }; @@ -134,12 +132,13 @@ impl ChunkItem for RawModuleChunkItem { } #[turbo_tasks::function] - fn as_chunk(&self, availability_info: Value) -> Vc> { - Vc::upcast(EcmascriptChunk::new( - Vc::upcast(self.chunking_context), - Vc::upcast(self.module), - availability_info, - )) + fn ty(&self) -> Vc> { + Vc::upcast(Vc::::default()) + } + + #[turbo_tasks::function] + fn module(&self) -> Vc> { + Vc::upcast(self.module) } }