Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
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
20 changes: 5 additions & 15 deletions crates/next-core/src/next_client_chunks/with_chunks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use turbopack_core::{
chunk::{
availability_info::AvailabilityInfo, Chunk, ChunkGroupReferenceVc, ChunkGroupVc, ChunkItem,
ChunkItemVc, ChunkListReferenceVc, ChunkVc, ChunkableAsset, ChunkableAssetVc,
ChunkingContext, ChunkingContextVc,
ChunkingContextVc,
},
ident::AssetIdentVc,
reference::AssetReferencesVc,
Expand Down Expand Up @@ -49,14 +49,10 @@ impl Asset for WithChunksAsset {
#[turbo_tasks::function]
async fn references(self_vc: WithChunksAssetVc) -> Result<AssetReferencesVc> {
let this = self_vc.await?;
let chunk_group = self_vc.chunk_group();
Ok(AssetReferencesVc::cell(vec![
ChunkGroupReferenceVc::new(self_vc.chunk_group()).into(),
ChunkListReferenceVc::new(
this.server_root,
self_vc.chunk_group(),
self_vc.chunk_list_path(),
)
.into(),
ChunkGroupReferenceVc::new(chunk_group).into(),
ChunkListReferenceVc::new(this.server_root, chunk_group).into(),
]))
}
}
Expand Down Expand Up @@ -102,12 +98,6 @@ impl EcmascriptChunkPlaceable for WithChunksAsset {

#[turbo_tasks::value_impl]
impl WithChunksAssetVc {
#[turbo_tasks::function]
async fn chunk_list_path(self) -> Result<FileSystemPathVc> {
let this = self.await?;
Ok(this.chunking_context.chunk_list_path(self.ident()))
}

#[turbo_tasks::function]
async fn chunk_group(self) -> Result<ChunkGroupVc> {
let this = self.await?;
Expand Down Expand Up @@ -142,7 +132,7 @@ impl EcmascriptChunkItem for WithChunksChunkItem {
let server_root = inner.server_root.await?;
let mut client_chunks = Vec::new();

let chunk_list_path = self.inner.chunk_list_path().await?;
let chunk_list_path = group.chunk_list_path().await?;
let chunk_list_path = if let Some(path) = server_root.get_path_to(&chunk_list_path) {
path
} else {
Expand Down
9 changes: 7 additions & 2 deletions crates/turbopack-core/src/chunk/chunk_in_group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use turbo_tasks::{primitives::StringVc, ValueToString};
use super::{Chunk, ChunkVc, ParallelChunkReferenceVc};
use crate::{
asset::{Asset, AssetContentVc, AssetVc},
chunk::ParallelChunkReference,
chunk::{ChunkingContextVc, ParallelChunkReference},
ident::AssetIdentVc,
introspect::{
asset::{children_from_asset_references, content_to_details, IntrospectableAssetVc},
Expand Down Expand Up @@ -37,7 +37,12 @@ impl ChunkInGroupVc {
}

#[turbo_tasks::value_impl]
impl Chunk for ChunkInGroup {}
impl Chunk for ChunkInGroup {
#[turbo_tasks::function]
fn chunking_context(&self) -> ChunkingContextVc {
self.inner.chunking_context()
}
}

#[turbo_tasks::value_impl]
impl Asset for ChunkInGroup {
Expand Down
10 changes: 8 additions & 2 deletions crates/turbopack-core/src/chunk/dev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,14 @@ impl ChunkingContext for DevChunkingContext {
}

#[turbo_tasks::function]
fn chunk_list_path(self_vc: DevChunkingContextVc, ident: AssetIdentVc) -> FileSystemPathVc {
self_vc.chunk_path(ident.with_modifier(chunk_list_modifier()), ".json")
fn chunk_list_path(
self_vc: DevChunkingContextVc,
entry_chunk_path: FileSystemPathVc,
) -> FileSystemPathVc {
self_vc.chunk_path(
AssetIdentVc::from_path(entry_chunk_path).with_modifier(chunk_list_modifier()),
".json",
)
}

#[turbo_tasks::function]
Expand Down
10 changes: 2 additions & 8 deletions crates/turbopack-core/src/chunk/list/asset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,16 @@ use crate::{
pub(super) struct ChunkListAsset {
server_root: FileSystemPathVc,
chunk_group: ChunkGroupVc,
path: FileSystemPathVc,
}

#[turbo_tasks::value_impl]
impl ChunkListAssetVc {
/// Creates a new [`ChunkListAsset`].
#[turbo_tasks::function]
pub fn new(
server_root: FileSystemPathVc,
chunk_group: ChunkGroupVc,
path: FileSystemPathVc,
) -> Self {
pub fn new(server_root: FileSystemPathVc, chunk_group: ChunkGroupVc) -> Self {
ChunkListAsset {
server_root,
chunk_group,
path,
}
.cell()
}
Expand All @@ -61,7 +55,7 @@ impl ChunkListAssetVc {
impl Asset for ChunkListAsset {
#[turbo_tasks::function]
fn ident(&self) -> AssetIdentVc {
AssetIdentVc::from_path(self.path)
AssetIdentVc::from_path(self.chunk_group.chunk_list_path())
}

#[turbo_tasks::function]
Expand Down
16 changes: 4 additions & 12 deletions crates/turbopack-core/src/chunk/list/reference.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,16 @@ use crate::{
pub struct ChunkListReference {
server_root: FileSystemPathVc,
chunk_group: ChunkGroupVc,
path: FileSystemPathVc,
}

#[turbo_tasks::value_impl]
impl ChunkListReferenceVc {
/// Creates a new [`ChunkListReference`].
#[turbo_tasks::function]
pub fn new(
server_root: FileSystemPathVc,
chunk_group: ChunkGroupVc,
path: FileSystemPathVc,
) -> Self {
pub fn new(server_root: FileSystemPathVc, chunk_group: ChunkGroupVc) -> Self {
ChunkListReference {
server_root,
chunk_group,
path,
}
.cell()
}
Expand All @@ -49,7 +43,7 @@ impl ValueToString for ChunkListReference {
async fn to_string(&self) -> Result<StringVc> {
Ok(StringVc::cell(format!(
"referenced chunk list {}",
self.path.to_string().await?
self.chunk_group.chunk_list_path().to_string().await?
)))
}
}
Expand All @@ -58,10 +52,8 @@ impl ValueToString for ChunkListReference {
impl AssetReference for ChunkListReference {
#[turbo_tasks::function]
fn resolve_reference(&self) -> ResolveResultVc {
ResolveResult::asset(
ChunkListAssetVc::new(self.server_root, self.chunk_group, self.path).into(),
)
.cell()
ResolveResult::asset(ChunkListAssetVc::new(self.server_root, self.chunk_group).into())
.cell()
}
}

Expand Down
23 changes: 20 additions & 3 deletions crates/turbopack-core/src/chunk/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,9 @@ pub trait ChunkingContext {

fn chunk_path(&self, ident: AssetIdentVc, extension: &str) -> FileSystemPathVc;

/// Returns the path to the chunk list file for the given entry module
/// ident.
fn chunk_list_path(&self, ident: AssetIdentVc) -> FileSystemPathVc;
/// Returns the path to the chunk list file for the given unoptimized entry
/// chunk path.
fn chunk_list_path(&self, entry_chunk_path: FileSystemPathVc) -> FileSystemPathVc;

fn can_be_in_same_chunk(&self, asset_a: AssetVc, asset_b: AssetVc) -> BoolVc;

Expand Down Expand Up @@ -144,6 +144,22 @@ impl ChunkGroupVc {
Self::cell(ChunkGroup { entry: chunk })
}

/// Returns the entry chunk of this chunk group.
#[turbo_tasks::function]
pub async fn entry(self) -> Result<ChunkVc> {
Ok(self.await?.entry)
}

/// Returns the chunk list path for this chunk group.
#[turbo_tasks::function]
pub async fn chunk_list_path(self) -> Result<FileSystemPathVc> {
let this = self.await?;
Ok(this
.entry
.chunking_context()
.chunk_list_path(this.entry.ident().path()))
}

/// Lists all chunks that are in this chunk group.
/// These chunks need to be loaded to fulfill that chunk group.
/// All chunks should be loaded in parallel.
Expand Down Expand Up @@ -231,6 +247,7 @@ impl ValueToString for ChunkGroup {
/// same chunk group.
#[turbo_tasks::value_trait]
pub trait Chunk: Asset {
fn chunking_context(&self) -> ChunkingContextVc;
// TODO Once output assets have their own trait, this path() method will move
// into that trait and ident() will be removed from that. Assets on the
// output-level only have a path and no complex ident.
Expand Down
7 changes: 6 additions & 1 deletion crates/turbopack-css/src/chunk/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,12 @@ async fn css_chunk_content_single_entry(
}

#[turbo_tasks::value_impl]
impl Chunk for CssChunk {}
impl Chunk for CssChunk {
#[turbo_tasks::function]
fn chunking_context(&self) -> ChunkingContextVc {
self.context
}
}

#[turbo_tasks::value_impl]
impl OptimizableChunk for CssChunk {
Expand Down
17 changes: 4 additions & 13 deletions crates/turbopack-ecmascript/src/chunk/evaluate.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use anyhow::Result;
use turbo_tasks_fs::FileSystemPathVc;
use turbopack_core::chunk::{
chunk_in_group::ChunkInGroupVc, Chunk, ChunkGroupVc, ChunkingContext, ChunkingContextVc,
ModuleIdVc,
Expand All @@ -21,9 +20,6 @@ pub struct EcmascriptChunkEvaluate {
/// All chunks of this chunk group need to be ready for execution to start.
/// When None, it will use a chunk group created from the current chunk.
pub chunk_group: Option<ChunkGroupVc>,
/// The path to the chunk list asset. This will be used to register the
/// chunk list when this chunk is evaluated.
pub chunk_list_path: Option<FileSystemPathVc>,
}

#[turbo_tasks::value_impl]
Expand All @@ -37,7 +33,6 @@ impl EcmascriptChunkEvaluateVc {
let &EcmascriptChunkEvaluate {
evaluate_entries,
chunk_group,
chunk_list_path,
} = &*self.await?;
let chunk_group =
chunk_group.unwrap_or_else(|| ChunkGroupVc::from_chunk(origin_chunk.into()));
Expand Down Expand Up @@ -68,14 +63,10 @@ impl EcmascriptChunkEvaluateVc {
.iter()
.map(|entry| entry.as_chunk_item(context).id())
.collect();
let chunk_list_path = if let Some(chunk_list_path) = chunk_list_path {
let chunk_list_path = chunk_list_path.await?;
output_root
.get_path_to(&chunk_list_path)
.map(|path| path.to_string())
} else {
None
};
let chunk_list_path = chunk_group.chunk_list_path().await?;
let chunk_list_path = output_root
.get_path_to(&chunk_list_path)
.map(|path| path.to_string());
Ok(EcmascriptChunkContentEvaluate {
ecma_chunks_server_paths,
other_chunks_server_paths,
Expand Down
33 changes: 15 additions & 18 deletions crates/turbopack-ecmascript/src/chunk/manifest/chunk_asset.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
use std::iter::once;

use anyhow::Result;
use turbo_tasks::{primitives::StringVc, Value};
use turbo_tasks_fs::FileSystemPathVc;
use turbopack_core::{
asset::{Asset, AssetContentVc, AssetVc},
chunk::{
availability_info::AvailabilityInfo, ChunkGroupVc, ChunkReferenceVc, ChunkVc,
ChunkableAsset, ChunkableAssetVc, ChunkingContext, ChunkingContextVc,
availability_info::AvailabilityInfo, ChunkGroupVc, ChunkListReferenceVc, ChunkReferenceVc,
ChunkVc, ChunkableAsset, ChunkableAssetVc, ChunkingContext, ChunkingContextVc,
},
ident::AssetIdentVc,
reference::AssetReferencesVc,
Expand Down Expand Up @@ -73,25 +74,11 @@ impl ManifestChunkAssetVc {
))
}

#[turbo_tasks::function]
pub(super) async fn chunk_list_path(self) -> Result<FileSystemPathVc> {
let this = &*self.await?;
Ok(this.chunking_context.chunk_list_path(self.ident()))
}

#[turbo_tasks::function]
pub async fn manifest_chunk(self) -> Result<ChunkVc> {
let this = self.await?;
Ok(self.as_chunk(this.chunking_context, Value::new(this.availability_info)))
}

#[turbo_tasks::function]
async fn chunks_list_path(self) -> Result<FileSystemPathVc> {
Ok(self
.await?
.chunking_context
.chunk_path(self.ident().with_modifier(chunk_list_modifier()), ".json"))
}
}

#[turbo_tasks::value_impl]
Expand All @@ -108,7 +95,8 @@ impl Asset for ManifestChunkAsset {

#[turbo_tasks::function]
async fn references(self_vc: ManifestChunkAssetVc) -> Result<AssetReferencesVc> {
let chunks = self_vc.chunk_group().chunks();
let chunk_group = self_vc.chunk_group();
let chunks = chunk_group.chunks();

Ok(AssetReferencesVc::cell(
chunks
Expand All @@ -117,6 +105,15 @@ impl Asset for ManifestChunkAsset {
.copied()
.map(ChunkReferenceVc::new)
.map(Into::into)
.chain(once(
// This creates the chunk list corresponding to the manifest chunk's chunk
// group.
ChunkListReferenceVc::new(
self_vc.await?.chunking_context.output_root(),
chunk_group,
)
.into(),
))
.collect(),
))
}
Expand Down
17 changes: 12 additions & 5 deletions crates/turbopack-ecmascript/src/chunk/manifest/chunk_item.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use anyhow::{bail, Result};
use anyhow::{anyhow, bail, Result};
use indexmap::IndexSet;
use indoc::formatdoc;
use turbo_tasks::ValueToString;
Expand Down Expand Up @@ -36,7 +36,9 @@ impl EcmascriptChunkItem for ManifestChunkItem {

#[turbo_tasks::function]
async fn content(&self) -> Result<EcmascriptChunkItemContentVc> {
let chunks = self.manifest.chunk_group().chunks().await?;
let chunk_group = self.manifest.chunk_group();
let chunks = chunk_group.chunks().await?;
let output_root = self.context.output_root().await?;

let mut chunk_server_paths = IndexSet::new();
for chunk in chunks.iter() {
Expand All @@ -45,7 +47,6 @@ impl EcmascriptChunkItem for ManifestChunkItem {
// item is one of several that are contained in that chunk file.
let chunk_path = &*chunk.path().await?;
// The pathname is the file path necessary to load the chunk from the server.
let output_root = self.context.output_root().await?;
let chunk_server_path = if let Some(path) = output_root.get_path_to(chunk_path) {
path
} else {
Expand All @@ -58,11 +59,17 @@ impl EcmascriptChunkItem for ManifestChunkItem {
chunk_server_paths.insert(chunk_server_path.to_string());
}

let chunk_list_path = chunk_group.chunk_list_path().await?;
let chunk_list_path = output_root
.get_path_to(&*chunk_list_path)
.ok_or(anyhow!("chunk list path is not in output root"))?;

let code = formatdoc! {
r#"
__turbopack_export_value__({chunk_paths});
__turbopack_export_value__({{ chunks: {chunk_paths}, list: {chunk_list_path} }});
"#,
chunk_paths = stringify_js_pretty(&chunk_server_paths)
chunk_paths = stringify_js_pretty(&chunk_server_paths),
chunk_list_path = stringify_js_pretty(&chunk_list_path),
};

Ok(EcmascriptChunkItemContent {
Expand Down
Loading