-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge
EcmascriptChunkUpdate
s before sending them to the client
- Loading branch information
Showing
47 changed files
with
1,982 additions
and
313 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
use anyhow::Result; | ||
use turbo_tasks_fs::FileSystemPathVc; | ||
|
||
use super::content::ChunkListContentVc; | ||
use crate::{ | ||
asset::{Asset, AssetContentVc, AssetVc}, | ||
chunk::{ChunkGroupVc, ChunkReferenceVc, ChunksVc}, | ||
reference::AssetReferencesVc, | ||
version::{VersionedContent, VersionedContentVc}, | ||
}; | ||
|
||
#[turbo_tasks::value(shared)] | ||
pub(super) struct ChunkListAsset { | ||
server_root: FileSystemPathVc, | ||
chunk_group: ChunkGroupVc, | ||
path: FileSystemPathVc, | ||
} | ||
|
||
#[turbo_tasks::value_impl] | ||
impl ChunkListAssetVc { | ||
#[turbo_tasks::function] | ||
pub fn new( | ||
server_root: FileSystemPathVc, | ||
chunk_group: ChunkGroupVc, | ||
path: FileSystemPathVc, | ||
) -> Self { | ||
ChunkListAsset { | ||
server_root, | ||
chunk_group, | ||
path, | ||
} | ||
.cell() | ||
} | ||
|
||
#[turbo_tasks::function] | ||
async fn get_chunks(self) -> Result<ChunksVc> { | ||
Ok(self.await?.chunk_group.chunks()) | ||
} | ||
|
||
#[turbo_tasks::function] | ||
async fn content(self) -> Result<ChunkListContentVc> { | ||
let this = &*self.await?; | ||
Ok(ChunkListContentVc::new( | ||
this.server_root, | ||
this.chunk_group.chunks(), | ||
)) | ||
} | ||
} | ||
|
||
#[turbo_tasks::value_impl] | ||
impl Asset for ChunkListAsset { | ||
#[turbo_tasks::function] | ||
fn path(&self) -> FileSystemPathVc { | ||
self.path | ||
} | ||
|
||
#[turbo_tasks::function] | ||
async fn references(&self) -> Result<AssetReferencesVc> { | ||
let chunks = self.chunk_group.chunks().await?; | ||
|
||
let mut references = Vec::with_capacity(chunks.len()); | ||
for chunk in chunks.iter() { | ||
references.push(ChunkReferenceVc::new(*chunk).into()); | ||
|
||
// We also need to expand references one step here, because the chunk asset | ||
// graph is lazy. TODO(alexkirsz) Better explaination. | ||
references.extend(chunk.references().await?.iter().copied()); | ||
} | ||
|
||
Ok(AssetReferencesVc::cell(references)) | ||
} | ||
|
||
#[turbo_tasks::function] | ||
fn content(self_vc: ChunkListAssetVc) -> AssetContentVc { | ||
self_vc.content().content() | ||
} | ||
|
||
#[turbo_tasks::function] | ||
fn versioned_content(self_vc: ChunkListAssetVc) -> VersionedContentVc { | ||
self_vc.content().into() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
use anyhow::Result; | ||
use indexmap::IndexMap; | ||
use turbo_tasks::{IntoTraitRef, TraitRef, TryJoinIterExt}; | ||
use turbo_tasks_fs::{FileContent, FileSystemPathReadRef, FileSystemPathVc}; | ||
|
||
use super::{ | ||
update::update_chunk_list, | ||
version::{ChunkListVersion, ChunkListVersionVc}, | ||
}; | ||
use crate::{ | ||
asset::{Asset, AssetContent, AssetContentVc}, | ||
chunk::ChunksVc, | ||
version::{ | ||
MergeableVersionedContent, MergeableVersionedContentVc, UpdateVc, VersionVc, | ||
VersionedContent, VersionedContentMerger, VersionedContentTraitRef, VersionedContentVc, | ||
VersionedContentsVc, | ||
}, | ||
}; | ||
|
||
#[turbo_tasks::value(serialization = "none")] | ||
pub(super) struct ChunkListContent { | ||
pub server_root: FileSystemPathReadRef, | ||
#[turbo_tasks(trace_ignore)] | ||
pub chunks_contents: IndexMap<String, VersionedContentTraitRef>, | ||
} | ||
|
||
#[turbo_tasks::value_impl] | ||
impl ChunkListContentVc { | ||
#[turbo_tasks::function] | ||
pub async fn new(server_root: FileSystemPathVc, chunks: ChunksVc) -> Result<Self> { | ||
let server_root = server_root.await?; | ||
Ok(ChunkListContent { | ||
server_root: server_root.clone(), | ||
chunks_contents: chunks | ||
.await? | ||
.iter() | ||
.map(|chunk| { | ||
let server_root = server_root.clone(); | ||
async move { | ||
Ok(( | ||
server_root | ||
.get_path_to(&*chunk.path().await?) | ||
.map(|path| path.to_string()), | ||
chunk.versioned_content().into_trait_ref().await?, | ||
)) | ||
} | ||
}) | ||
.try_join() | ||
.await? | ||
.into_iter() | ||
.filter_map(|(path, content)| path.map(|path| (path, content))) | ||
.collect(), | ||
} | ||
.cell()) | ||
} | ||
|
||
#[turbo_tasks::function] | ||
pub async fn version(self) -> Result<ChunkListVersionVc> { | ||
let this = self.await?; | ||
|
||
let mut by_merger = IndexMap::<_, Vec<_>>::new(); | ||
let mut by_path = IndexMap::<_, _>::new(); | ||
|
||
for (chunk_path, chunk_content) in &this.chunks_contents { | ||
let chunk_content = TraitRef::cell(chunk_content.clone()); | ||
if let Some(mergeable) = | ||
MergeableVersionedContentVc::resolve_from(chunk_content).await? | ||
{ | ||
let merger = mergeable.get_merger().resolve().await?; | ||
by_merger.entry(merger).or_default().push(chunk_content); | ||
} else { | ||
by_path.insert( | ||
chunk_path.clone(), | ||
chunk_content.version().into_trait_ref().await?, | ||
); | ||
} | ||
} | ||
|
||
let by_merger = by_merger | ||
.into_iter() | ||
.map(|(merger, contents)| { | ||
let merger = merger.clone(); | ||
async move { | ||
Ok(( | ||
merger, | ||
merger | ||
.merge(VersionedContentsVc::cell(contents)) | ||
.version() | ||
.into_trait_ref() | ||
.await?, | ||
)) | ||
} | ||
}) | ||
.try_join() | ||
.await? | ||
.into_iter() | ||
.collect(); | ||
|
||
Ok(ChunkListVersion { by_path, by_merger }.cell()) | ||
} | ||
} | ||
|
||
#[turbo_tasks::value_impl] | ||
impl VersionedContent for ChunkListContent { | ||
#[turbo_tasks::function] | ||
fn content(&self) -> AssetContentVc { | ||
AssetContentVc::cell(AssetContent::File(FileContent::NotFound.into())) | ||
} | ||
|
||
#[turbo_tasks::function] | ||
fn version(self_vc: ChunkListContentVc) -> VersionVc { | ||
self_vc.version().into() | ||
} | ||
|
||
#[turbo_tasks::function] | ||
fn update(self_vc: ChunkListContentVc, from_version: VersionVc) -> UpdateVc { | ||
update_chunk_list(self_vc, from_version) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
pub(crate) mod asset; | ||
pub(crate) mod content; | ||
pub(crate) mod reference; | ||
pub(crate) mod update; | ||
pub(crate) mod version; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
use anyhow::Result; | ||
use turbo_tasks::{primitives::StringVc, ValueToString, ValueToStringVc}; | ||
use turbo_tasks_fs::FileSystemPathVc; | ||
|
||
use super::asset::ChunkListAssetVc; | ||
use crate::{ | ||
chunk::{ | ||
ChunkGroupVc, ChunkableAssetReference, ChunkableAssetReferenceVc, ChunkingContextVc, | ||
ChunkingType, ChunkingTypeOptionVc, | ||
}, | ||
reference::{AssetReference, AssetReferenceVc}, | ||
resolve::{ResolveResult, ResolveResultVc}, | ||
}; | ||
|
||
#[turbo_tasks::value] | ||
pub struct ChunkListReference { | ||
server_root: FileSystemPathVc, | ||
chunk_group: ChunkGroupVc, | ||
path: FileSystemPathVc, | ||
} | ||
|
||
#[turbo_tasks::value_impl] | ||
impl ChunkListReferenceVc { | ||
#[turbo_tasks::function] | ||
pub fn new( | ||
server_root: FileSystemPathVc, | ||
chunk_group: ChunkGroupVc, | ||
path: FileSystemPathVc, | ||
) -> Self { | ||
ChunkListReference { | ||
server_root, | ||
chunk_group, | ||
path, | ||
} | ||
.cell() | ||
} | ||
} | ||
|
||
#[turbo_tasks::value_impl] | ||
impl ValueToString for ChunkListReference { | ||
#[turbo_tasks::function] | ||
async fn to_string(&self) -> Result<StringVc> { | ||
Ok(StringVc::cell(format!( | ||
"referenced chunk list {}", | ||
self.path.to_string().await? | ||
))) | ||
} | ||
} | ||
|
||
#[turbo_tasks::value_impl] | ||
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() | ||
} | ||
} | ||
|
||
#[turbo_tasks::value_impl] | ||
impl ChunkableAssetReference for ChunkListReference { | ||
#[turbo_tasks::function] | ||
fn chunking_type(&self, _context: ChunkingContextVc) -> ChunkingTypeOptionVc { | ||
ChunkingTypeOptionVc::cell(Some(ChunkingType::Separate)) | ||
} | ||
} |
Oops, something went wrong.