Skip to content

Commit

Permalink
use OutputAssetVc
Browse files Browse the repository at this point in the history
  • Loading branch information
sokra committed Jul 13, 2023
1 parent c569158 commit 94d4226
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ use turbo_tasks::TryJoinIterExt;
use turbopack_binding::turbopack::{
build::BuildChunkingContextVc,
core::{
asset::{AssetVc, AssetsVc},
chunk::{ChunkableModule, ChunkingContext},
output::{OutputAssetVc, OutputAssetsVc},
},
ecmascript::chunk::EcmascriptChunkingContextVc,
};
Expand All @@ -22,7 +22,7 @@ pub async fn compute_app_client_references_chunks(
app_client_reference_types: &HashSet<ClientReferenceType>,
client_chunking_context: EcmascriptChunkingContextVc,
ssr_chunking_context: BuildChunkingContextVc,
all_chunks: &mut Vec<AssetVc>,
all_chunks: &mut Vec<OutputAssetVc>,
) -> Result<IndexMap<ClientReferenceType, ClientReferenceChunks>> {
let app_client_references_chunks: IndexMap<_, _> = app_client_reference_types
.iter()
Expand Down Expand Up @@ -50,7 +50,7 @@ pub async fn compute_app_client_references_chunks(
.as_root_chunk(client_chunking_context.into());
ClientReferenceChunks {
client_chunks: client_chunking_context.chunk_group(client_entry_chunk),
ssr_chunks: AssetsVc::empty(),
ssr_chunks: OutputAssetsVc::empty(),
}
}
},
Expand Down Expand Up @@ -82,7 +82,7 @@ pub async fn compute_app_client_references_chunks(
/// Contains the chunks corresponding to a client reference.
pub struct ClientReferenceChunks {
/// Chunks to be loaded on the client.
pub client_chunks: AssetsVc,
pub client_chunks: OutputAssetsVc,
/// Chunks to be loaded on the server for SSR.
pub ssr_chunks: AssetsVc,
pub ssr_chunks: OutputAssetsVc,
}
12 changes: 7 additions & 5 deletions packages/next-swc/crates/next-build/src/next_app/app_entries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,15 @@ use turbopack_binding::{
turbopack::{
build::BuildChunkingContextVc,
core::{
asset::{Asset, AssetVc, AssetsVc},
asset::{Asset, AssetVc},
chunk::{
availability_info::AvailabilityInfo, ChunkingContext, EvaluatableAssetsVc,
ModuleId as TurbopackModuleId,
},
compile_time_info::CompileTimeInfoVc,
file_source::FileSourceVc,
output::{OutputAssetVc, OutputAssetsVc},
raw_output::RawOutputVc,
virtual_source::VirtualSourceVc,
},
ecmascript::{
Expand Down Expand Up @@ -285,7 +287,7 @@ pub async fn compute_app_entries_chunks(
app_build_manifest: &mut AppBuildManifest,
build_manifest: &mut BuildManifest,
app_paths_manifest: &mut AppPathsManifest,
all_chunks: &mut Vec<AssetVc>,
all_chunks: &mut Vec<OutputAssetVc>,
) -> Result<()> {
let node_root_ref = node_root.await?;

Expand Down Expand Up @@ -519,7 +521,7 @@ pub async fn compute_app_entries_chunks(
})
.into(),
);
all_chunks.push(client_reference_manifest_source.into());
all_chunks.push(RawOutputVc::new(client_reference_manifest_source.into()).into());
}

Ok(())
Expand Down Expand Up @@ -553,9 +555,9 @@ pub async fn get_app_shared_client_chunk(
pub async fn get_app_client_shared_chunks(
app_client_runtime_entries: EvaluatableAssetsVc,
client_chunking_context: EcmascriptChunkingContextVc,
) -> Result<AssetsVc> {
) -> Result<OutputAssetsVc> {
if app_client_runtime_entries.await?.is_empty() {
return Ok(AssetsVc::empty());
return Ok(OutputAssetsVc::empty());
}

let app_client_shared_chunk =
Expand Down
12 changes: 8 additions & 4 deletions packages/next-swc/crates/next-build/src/next_build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ use turbopack_binding::{
chunk::ChunkingContext,
environment::ServerAddrVc,
issue::{IssueReporter, IssueReporterVc, IssueSeverity, IssueVc},
output::{OutputAssetVc, OutputAssetsVc},
reference::AssetReference,
virtual_fs::VirtualFileSystemVc,
},
Expand Down Expand Up @@ -501,12 +502,12 @@ async fn handle_issues<T: Into<RawVc> + CollectiblesSource + Copy>(
/// Emits all assets transitively reachable from the given chunks, that are
/// inside the node root or the client root.
async fn emit_all_assets(
chunks: Vec<AssetVc>,
chunks: Vec<OutputAssetVc>,
node_root: &FileSystemPath,
client_relative_path: FileSystemPathVc,
client_output_path: FileSystemPathVc,
) -> Result<CompletionVc> {
let all_assets = all_assets_from_entries(AssetsVc::cell(chunks)).await?;
let all_assets = all_assets_from_entries(OutputAssetsVc::cell(chunks)).await?;
Ok(CompletionsVc::all(
all_assets
.iter()
Expand Down Expand Up @@ -547,11 +548,14 @@ fn emit_rebase(asset: AssetVc, from: FileSystemPathVc, to: FileSystemPathVc) ->
/// Walks the asset graph from multiple assets and collect all referenced
/// assets.
#[turbo_tasks::function]
async fn all_assets_from_entries(entries: AssetsVc) -> Result<AssetsVc> {
async fn all_assets_from_entries(entries: OutputAssetsVc) -> Result<AssetsVc> {
Ok(AssetsVc::cell(
AdjacencyMap::new()
.skip_duplicates()
.visit(entries.await?.iter().copied(), get_referenced_assets)
.visit(
entries.await?.iter().copied().map(Into::into),
get_referenced_assets,
)
.await
.completed()?
.into_inner()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,12 @@ use turbopack_binding::{
turbopack::{
build::BuildChunkingContextVc,
core::{
asset::{Asset, AssetVc},
asset::Asset,
chunk::{ChunkableModule, ChunkingContext, EvaluatableAssetsVc},
compile_time_info::CompileTimeInfoVc,
context::{AssetContext, AssetContextVc},
file_source::FileSourceVc,
output::OutputAssetVc,
reference_type::{EntryReferenceSubType, ReferenceType},
source::SourceVc,
},
Expand Down Expand Up @@ -349,7 +350,7 @@ pub async fn compute_page_entries_chunks(
client_relative_path: &FileSystemPath,
pages_manifest: &mut PagesManifest,
build_manifest: &mut BuildManifest,
all_chunks: &mut Vec<AssetVc>,
all_chunks: &mut Vec<OutputAssetVc>,
) -> Result<()> {
for page_entry in page_entries.entries.iter() {
let page_entry = page_entry.await?;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@ use turbopack_binding::{
},
turbopack::{
core::{
asset::{Asset, AssetContentVc, AssetVc, AssetsVc},
asset::{Asset, AssetContentVc, AssetVc},
chunk::{
availability_info::AvailabilityInfo, ChunkDataVc, ChunkGroupReferenceVc, ChunkItem,
ChunkItemVc, ChunkVc, ChunkableModule, ChunkableModuleVc, ChunkingContext,
ChunkingContextVc, ChunksDataVc,
},
ident::AssetIdentVc,
module::{Module, ModuleVc},
output::OutputAssetsVc,
reference::AssetReferencesVc,
},
ecmascript::{
Expand Down Expand Up @@ -68,7 +69,7 @@ impl WithChunksAssetVc {
}

#[turbo_tasks::function]
async fn chunks(self) -> Result<AssetsVc> {
async fn chunks(self) -> Result<OutputAssetsVc> {
let this = self.await?;
Ok(this.chunking_context.chunk_group(self.entry_chunk()))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use turbopack_binding::{
turbo::tasks_fs::FileSystemPathVc,
turbopack::{
core::{
asset::{Asset, AssetContentVc, AssetVc, AssetsVc},
asset::{Asset, AssetContentVc, AssetVc},
chunk::{
availability_info::AvailabilityInfo, ChunkDataVc, ChunkItem, ChunkItemVc, ChunkVc,
ChunkableModule, ChunkableModuleReference, ChunkableModuleReferenceVc,
Expand All @@ -14,6 +14,7 @@ use turbopack_binding::{
},
ident::AssetIdentVc,
module::{Module, ModuleVc},
output::OutputAssetsVc,
proxied_asset::ProxiedAssetVc,
reference::{
AssetReference, AssetReferenceVc, AssetReferencesVc, SingleAssetReferenceVc,
Expand Down Expand Up @@ -122,7 +123,7 @@ struct WithClientChunksChunkItem {
#[turbo_tasks::value_impl]
impl WithClientChunksChunkItemVc {
#[turbo_tasks::function]
async fn chunks(self) -> Result<AssetsVc> {
async fn chunks(self) -> Result<OutputAssetsVc> {
let this = self.await?;
let inner = this.inner.await?;
Ok(this
Expand All @@ -131,25 +132,26 @@ impl WithClientChunksChunkItemVc {
}

#[turbo_tasks::function]
async fn client_chunks(self) -> Result<AssetsVc> {
async fn client_chunks(self) -> Result<OutputAssetsVc> {
let this = self.await?;
let inner = this.inner.await?;
let chunks = self.chunks();
let output_root = this.context.output_root().await?;

let mut client_chunks = Vec::new();
for chunk in &*chunks.await? {
for &chunk in &*chunks.await? {
let extension = chunk.ident().path().extension().await?;
// Only expose CSS chunks as client chunks.
if &*extension == "css" {
if let Some(path) = output_root.get_path_to(&*chunk.ident().path().await?) {
client_chunks
.push(ProxiedAssetVc::new(*chunk, inner.server_root.join(path)).into());
client_chunks.push(
ProxiedAssetVc::new(chunk.into(), inner.server_root.join(path)).into(),
);
}
}
}

Ok(AssetsVc::cell(client_chunks))
Ok(OutputAssetsVc::cell(client_chunks))
}

#[turbo_tasks::function]
Expand Down Expand Up @@ -227,7 +229,7 @@ impl ChunkItem for WithClientChunksChunkItem {
let client_chunks = client_chunks.await?;
let client_chunk = StringVc::cell("client chunk".to_string());
for &chunk in client_chunks.iter() {
references.push(SingleAssetReferenceVc::new(chunk, client_chunk).into());
references.push(SingleAssetReferenceVc::new(chunk.into(), client_chunk).into());
}
for chunk_data in &*self_vc.chunks_data().await? {
references.extend(chunk_data.references().await?.iter().copied());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
use anyhow::{bail, Result};
use turbo_tasks::primitives::StringVc;
use turbopack_binding::turbopack::core::{
asset::{Asset, AssetContentVc, AssetVc, AssetsVc},
asset::{Asset, AssetContentVc, AssetVc},
chunk::{ChunkableModule, ChunkableModuleVc, ChunkingContext, ChunkingContextVc},
ident::AssetIdentVc,
module::{Module, ModuleVc},
output::OutputAssetsVc,
reference::AssetReferencesVc,
};

Expand All @@ -31,7 +32,7 @@ impl NextDynamicEntryModuleVc {
pub async fn client_chunks(
self,
client_chunking_context: ChunkingContextVc,
) -> Result<AssetsVc> {
) -> Result<OutputAssetsVc> {
let this = self.await?;

let Some(client_entry_module) =
Expand Down
14 changes: 9 additions & 5 deletions packages/next-swc/crates/next-core/src/page_loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@ use turbopack_binding::{
turbo::tasks_fs::{rope::RopeBuilder, File, FileContent, FileSystemPathVc},
turbopack::{
core::{
asset::{Asset, AssetContentVc, AssetVc, AssetsVc},
asset::{Asset, AssetContentVc, AssetVc},
chunk::{
ChunkDataVc, ChunkableModule, ChunkingContext, ChunkingContextVc, ChunksDataVc,
EvaluatableAssetVc, EvaluatableAssetsVc,
},
context::{AssetContext, AssetContextVc},
ident::AssetIdentVc,
module::ModuleVc,
output::OutputAssetsVc,
reference::{AssetReferencesVc, SingleAssetReferenceVc},
reference_type::{EntryReferenceSubType, InnerAssetsVc, ReferenceType},
source::SourceVc,
Expand Down Expand Up @@ -95,7 +96,7 @@ pub async fn create_page_loader_entry_module(
#[turbo_tasks::value_impl]
impl PageLoaderAssetVc {
#[turbo_tasks::function]
async fn get_page_chunks(self) -> Result<AssetsVc> {
async fn get_page_chunks(self) -> Result<OutputAssetsVc> {
let this = &*self.await?;

let page_loader_entry_asset =
Expand Down Expand Up @@ -161,10 +162,13 @@ impl Asset for PageLoaderAsset {
let chunks = self_vc.get_page_chunks().await?;

let mut references = Vec::with_capacity(chunks.len());
for chunk in chunks.iter() {
for &chunk in chunks.iter() {
references.push(
SingleAssetReferenceVc::new(*chunk, page_loader_chunk_reference_description())
.into(),
SingleAssetReferenceVc::new(
chunk.into(),
page_loader_chunk_reference_description(),
)
.into(),
);
}

Expand Down

0 comments on commit 94d4226

Please sign in to comment.