Unverified Commit 403c50bb authored by Benjamin Woodruff's avatar Benjamin Woodruff Committed by GitHub

refactor(turbopack-dev-server): Remove unresolved Vc from DevHtmlEntry, use a named struct (#74707)

parent 3651a450
...@@ -16,7 +16,7 @@ use turbopack_core::{ ...@@ -16,7 +16,7 @@ use turbopack_core::{
}, },
}; };
use turbopack_dev_server::{ use turbopack_dev_server::{
html::DevHtmlAsset, html::{DevHtmlAsset, DevHtmlEntry},
source::{asset_graph::AssetGraphContentSource, ContentSource}, source::{asset_graph::AssetGraphContentSource, ContentSource},
}; };
use turbopack_ecmascript_runtime::RuntimeType; use turbopack_ecmascript_runtime::RuntimeType;
...@@ -112,7 +112,9 @@ pub async fn create_web_entry_source( ...@@ -112,7 +112,9 @@ pub async fn create_web_entry_source(
server_root, server_root,
*server_root_to_root_path, *server_root_to_root_path,
compile_time_info.environment(), compile_time_info.environment(),
); )
.to_resolved()
.await?;
let entries = get_client_runtime_entries(root_path, node_env); let entries = get_client_runtime_entries(root_path, node_env);
let runtime_entries = entries.resolve_entries(asset_context); let runtime_entries = entries.resolve_entries(asset_context);
...@@ -138,21 +140,25 @@ pub async fn create_web_entry_source( ...@@ -138,21 +140,25 @@ pub async fn create_web_entry_source(
.into_iter() .into_iter()
.flatten() .flatten()
.map(|module| async move { .map(|module| async move {
if let (Some(chnkable), Some(entry)) = ( if let (Some(chunkable_module), Some(entry)) = (
ResolvedVc::try_sidecast::<Box<dyn ChunkableModule>>(module).await?, ResolvedVc::try_sidecast::<Box<dyn ChunkableModule>>(module).await?,
ResolvedVc::try_sidecast::<Box<dyn EvaluatableAsset>>(module).await?, ResolvedVc::try_sidecast::<Box<dyn EvaluatableAsset>>(module).await?,
) { ) {
Ok(( Ok(DevHtmlEntry {
chnkable, chunkable_module,
chunking_context, chunking_context,
Some(runtime_entries.with_entry(*entry)), runtime_entries: Some(runtime_entries.with_entry(*entry).to_resolved().await?),
)) })
} else if let Some(chunkable) = } else if let Some(chunkable_module) =
ResolvedVc::try_sidecast::<Box<dyn ChunkableModule>>(module).await? ResolvedVc::try_sidecast::<Box<dyn ChunkableModule>>(module).await?
{ {
// TODO this is missing runtime code, so it's probably broken and we should also // TODO this is missing runtime code, so it's probably broken and we should also
// add an ecmascript chunk with the runtime code // add an ecmascript chunk with the runtime code
Ok((chunkable, chunking_context, None)) Ok(DevHtmlEntry {
chunkable_module,
chunking_context,
runtime_entries: None,
})
} else { } else {
// TODO convert into a serve-able asset // TODO convert into a serve-able asset
Err(anyhow!( Err(anyhow!(
......
use anyhow::Result; use anyhow::Result;
use mime_guess::mime::TEXT_HTML_UTF_8; use mime_guess::mime::TEXT_HTML_UTF_8;
use serde::{Deserialize, Serialize};
use turbo_rcstr::RcStr; use turbo_rcstr::RcStr;
use turbo_tasks::{ReadRef, ResolvedVc, TryJoinIterExt, Value, Vc}; use turbo_tasks::{
trace::TraceRawVcs, NonLocalValue, ReadRef, ResolvedVc, TaskInput, TryJoinIterExt, Value, Vc,
};
use turbo_tasks_fs::{File, FileSystemPath}; use turbo_tasks_fs::{File, FileSystemPath};
use turbo_tasks_hash::{encode_hex, Xxh3Hash64Hasher}; use turbo_tasks_hash::{encode_hex, Xxh3Hash64Hasher};
use turbopack_core::{ use turbopack_core::{
...@@ -16,18 +19,19 @@ use turbopack_core::{ ...@@ -16,18 +19,19 @@ use turbopack_core::{
version::{Version, VersionedContent}, version::{Version, VersionedContent},
}; };
// TODO(WEB-945) This should become a struct once we have a #[derive(
// `turbo_tasks::input` attribute macro/`Input` derive macro. Clone, Debug, Deserialize, Eq, Hash, NonLocalValue, PartialEq, Serialize, TaskInput, TraceRawVcs,
type DevHtmlEntry = ( )]
ResolvedVc<Box<dyn ChunkableModule>>, pub struct DevHtmlEntry {
Vc<Box<dyn ChunkingContext>>, pub chunkable_module: ResolvedVc<Box<dyn ChunkableModule>>,
Option<Vc<EvaluatableAssets>>, pub chunking_context: ResolvedVc<Box<dyn ChunkingContext>>,
); pub runtime_entries: Option<ResolvedVc<EvaluatableAssets>>,
}
/// The HTML entry point of the dev server. /// The HTML entry point of the dev server.
/// ///
/// Generates an HTML page that includes the ES and CSS chunks. /// Generates an HTML page that includes the ES and CSS chunks.
#[turbo_tasks::value(shared, local)] #[turbo_tasks::value(shared)]
#[derive(Clone)] #[derive(Clone)]
pub struct DevHtmlAsset { pub struct DevHtmlAsset {
path: ResolvedVc<FileSystemPath>, path: ResolvedVc<FileSystemPath>,
...@@ -132,19 +136,26 @@ impl DevHtmlAsset { ...@@ -132,19 +136,26 @@ impl DevHtmlAsset {
.entries .entries
.iter() .iter()
.map(|entry| async move { .map(|entry| async move {
let &(chunkable_module, chunking_context, runtime_entries) = entry; let &DevHtmlEntry {
chunkable_module,
chunking_context,
runtime_entries,
} = entry;
let assets = if let Some(runtime_entries) = runtime_entries { let assets = if let Some(runtime_entries) = runtime_entries {
let runtime_entries = if let Some(evaluatable) = let runtime_entries = if let Some(evaluatable) =
ResolvedVc::try_downcast(chunkable_module).await? ResolvedVc::try_downcast(chunkable_module).await?
{ {
runtime_entries.with_entry(*evaluatable) runtime_entries
.with_entry(*evaluatable)
.to_resolved()
.await?
} else { } else {
runtime_entries runtime_entries
}; };
chunking_context.evaluated_chunk_group_assets( chunking_context.evaluated_chunk_group_assets(
chunkable_module.ident(), chunkable_module.ident(),
runtime_entries, *runtime_entries,
Value::new(AvailabilityInfo::Root), Value::new(AvailabilityInfo::Root),
) )
} else { } else {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment