From 749a6de40095720ae39b5e0adcae70b3e151a40d Mon Sep 17 00:00:00 2001 From: Benjamin Woodruff Date: Fri, 25 Oct 2024 17:55:32 -0700 Subject: [PATCH] Manually clean up LLM output --- turbopack/crates/turbopack-css/src/chunk/mod.rs | 2 +- .../turbopack-dev-server/src/source/resolve.rs | 2 +- .../turbopack-dev-server/src/source/route_tree.rs | 5 ++--- .../src/chunk_group_files_asset.rs | 12 ++++++------ .../src/references/esm/export.rs | 2 +- .../turbopack-ecmascript/src/references/mod.rs | 2 +- .../src/references/require_context.rs | 8 ++------ turbopack/crates/turbopack-node/src/lib.rs | 7 ++----- .../turbopack-node/src/render/render_static.rs | 4 +++- .../crates/turbopack-node/src/transforms/postcss.rs | 13 +++---------- .../crates/turbopack-node/src/transforms/util.rs | 11 +++++++---- .../crates/turbopack-node/src/transforms/webpack.rs | 6 +++++- turbopack/crates/turbopack/src/graph/mod.rs | 7 +++---- 13 files changed, 37 insertions(+), 44 deletions(-) diff --git a/turbopack/crates/turbopack-css/src/chunk/mod.rs b/turbopack/crates/turbopack-css/src/chunk/mod.rs index 500b77a6f78f15..f822c60d61d2eb 100644 --- a/turbopack/crates/turbopack-css/src/chunk/mod.rs +++ b/turbopack/crates/turbopack-css/src/chunk/mod.rs @@ -286,7 +286,7 @@ impl OutputAsset for CssChunk { } else { *ServerFileSystem::new().root().to_resolved().await? }, - query: *Vc::::default().to_resolved().await?, + query: Vc::::default(), fragment: None, assets, modifiers: Vec::new(), diff --git a/turbopack/crates/turbopack-dev-server/src/source/resolve.rs b/turbopack/crates/turbopack-dev-server/src/source/resolve.rs index 96882dc3f56118..82328f500121df 100644 --- a/turbopack/crates/turbopack-dev-server/src/source/resolve.rs +++ b/turbopack/crates/turbopack-dev-server/src/source/resolve.rs @@ -107,7 +107,7 @@ pub async fn resolve_source_request( } ContentSourceContent::Static(static_content) => { return Ok(ResolveSourceRequestResult::Static( - static_content.to_resolved().await?, + *static_content, HeaderList::new(response_header_overwrites) .to_resolved() .await?, diff --git a/turbopack/crates/turbopack-dev-server/src/source/route_tree.rs b/turbopack/crates/turbopack-dev-server/src/source/route_tree.rs index de51f2ad133562..8f108a0e740353 100644 --- a/turbopack/crates/turbopack-dev-server/src/source/route_tree.rs +++ b/turbopack/crates/turbopack-dev-server/src/source/route_tree.rs @@ -334,7 +334,7 @@ impl RouteTree { match selector_segment { BaseSegment::Static(value) => Ok(RouteTree { base, - static_segments: fxindexmap! { value => *inner.resolved_cell() }, + static_segments: fxindexmap! { value => inner.cell() }, ..Default::default() } .cell()), @@ -380,9 +380,8 @@ impl RouteTree { for s in not_found_sources.iter_mut() { *s = mapper.map_get_content(*s); } - for r in static_segments.values_mut() { - *r = *r.map_routes(mapper).to_resolved().await?; + *r = r.map_routes(mapper); } for r in dynamic_segments.iter_mut() { *r = r.map_routes(mapper).to_resolved().await?; diff --git a/turbopack/crates/turbopack-ecmascript/src/chunk_group_files_asset.rs b/turbopack/crates/turbopack-ecmascript/src/chunk_group_files_asset.rs index b27c391930326f..d2ff4b0fe76c1f 100644 --- a/turbopack/crates/turbopack-ecmascript/src/chunk_group_files_asset.rs +++ b/turbopack/crates/turbopack-ecmascript/src/chunk_group_files_asset.rs @@ -126,22 +126,22 @@ impl ChunkGroupFilesChunkItem { async fn chunks(&self) -> Result> { let inner = self.inner.await?; let chunks = if let Some(ecma) = - ResolvedVc::try_sidecast::>(inner.module.to_resolved().await?) - .await? + Vc::try_resolve_sidecast::>(inner.module).await? { - let empty_assets = EvaluatableAssets::empty().to_resolved().await?; inner.chunking_context.evaluated_chunk_group_assets( inner.module.ident(), inner .runtime_entries - .unwrap_or_else(|| empty_assets) - .with_entry(*ecma), + .as_deref() + .copied() + .unwrap_or_else(EvaluatableAssets::empty) + .with_entry(ecma), Value::new(AvailabilityInfo::Root), ) } else { inner .chunking_context - .root_chunk_group_assets(*ResolvedVc::upcast(inner.module.to_resolved().await?)) + .root_chunk_group_assets(Vc::upcast(inner.module)) }; Ok(chunks) } diff --git a/turbopack/crates/turbopack-ecmascript/src/references/esm/export.rs b/turbopack/crates/turbopack-ecmascript/src/references/esm/export.rs index 5ff73aee21d816..30beabbc7a3119 100644 --- a/turbopack/crates/turbopack-ecmascript/src/references/esm/export.rs +++ b/turbopack/crates/turbopack-ecmascript/src/references/esm/export.rs @@ -458,7 +458,7 @@ impl EsmExports { } if export_info.has_dynamic_exports { - dynamic_exports.push((**asset).to_resolved().await?); + dynamic_exports.push(*asset); } } diff --git a/turbopack/crates/turbopack-ecmascript/src/references/mod.rs b/turbopack/crates/turbopack-ecmascript/src/references/mod.rs index 89405921c5a927..f3178fef42b29f 100644 --- a/turbopack/crates/turbopack-ecmascript/src/references/mod.rs +++ b/turbopack/crates/turbopack-ecmascript/src/references/mod.rs @@ -316,7 +316,7 @@ impl AnalyzeEcmascriptModuleResultBuilder { for c in self.code_gens.iter_mut() { match c { CodeGen::CodeGenerateable(c) => { - *c = *c.to_resolved().await?; + *c = c.resolve().await?; } CodeGen::CodeGenerateableWithAsyncModuleInfo(c) => { *c = c.to_resolved().await?; diff --git a/turbopack/crates/turbopack-ecmascript/src/references/require_context.rs b/turbopack/crates/turbopack-ecmascript/src/references/require_context.rs index f0a3f25cc68b1e..2fe179515f4ee8 100644 --- a/turbopack/crates/turbopack-ecmascript/src/references/require_context.rs +++ b/turbopack/crates/turbopack-ecmascript/src/references/require_context.rs @@ -83,10 +83,7 @@ impl DirList { DirectoryEntry::File(path) => { if let Some(relative_path) = root_val.get_relative_path_to(&*path.await?) { if regex.is_match(&relative_path) { - list.insert( - relative_path, - DirListEntry::File(path.to_resolved().await?), - ); + list.insert(relative_path, DirListEntry::File(*path)); } } } @@ -124,8 +121,7 @@ impl DirList { for (k, entry) in &*dir { match entry { DirListEntry::File(path) => { - // Don't dereference the path, store it as a Vc - list.insert(k.clone(), path.resolve().await?); + list.insert(k.clone(), **path); } DirListEntry::Dir(d) => { queue.push_back(d.await?); diff --git a/turbopack/crates/turbopack-node/src/lib.rs b/turbopack/crates/turbopack-node/src/lib.rs index 0a8a04088534ae..4a2bb0a4b06927 100644 --- a/turbopack/crates/turbopack-node/src/lib.rs +++ b/turbopack/crates/turbopack-node/src/lib.rs @@ -127,7 +127,7 @@ pub async fn external_asset_entrypoints( /// assets. #[turbo_tasks::function] async fn separate_assets( - intermediate_asset: Vc>, + intermediate_asset: ResolvedVc>, intermediate_output_path: Vc, ) -> Result> { let intermediate_output_path = &*intermediate_output_path.await?; @@ -166,10 +166,7 @@ async fn separate_assets( let graph = AdjacencyMap::new() .skip_duplicates() - .visit( - once(Type::Internal(intermediate_asset.to_resolved().await?)), - get_asset_children, - ) + .visit(once(Type::Internal(intermediate_asset)), get_asset_children) .await .completed()? .into_inner(); diff --git a/turbopack/crates/turbopack-node/src/render/render_static.rs b/turbopack/crates/turbopack-node/src/render/render_static.rs index 3f8e11188ce1d3..0bd2c47e4623f4 100644 --- a/turbopack/crates/turbopack-node/src/render/render_static.rs +++ b/turbopack/crates/turbopack-node/src/render/render_static.rs @@ -317,7 +317,9 @@ async fn render_stream_internal( RenderStaticIncomingMessage::Headers { data } => yield RenderItem::Headers(data), RenderStaticIncomingMessage::Rewrite { path } => { drop(guard); - yield RenderItem::Response(StaticResult::rewrite(RewriteBuilder::new(path).build()).to_resolved().await?); + yield RenderItem::Response( + StaticResult::rewrite(RewriteBuilder::new(path).build()).to_resolved().await? + ); return; } RenderStaticIncomingMessage::Response { diff --git a/turbopack/crates/turbopack-node/src/transforms/postcss.rs b/turbopack/crates/turbopack-node/src/transforms/postcss.rs index 4c695ef8c51629..3072608b4fc275 100644 --- a/turbopack/crates/turbopack-node/src/transforms/postcss.rs +++ b/turbopack/crates/turbopack-node/src/transforms/postcss.rs @@ -511,16 +511,9 @@ impl PostCssTransformedAsset { // TODO handle SourceMap let file = File::from(processed_css.css); - let mut resolved_assets = Vec::new(); - for asset in emitted_assets_to_virtual_sources(processed_css.assets) { - resolved_assets.push(asset.to_resolved().await?); - } - let content = AssetContent::File(*FileContent::Content(file).resolved_cell()).cell(); - Ok(ProcessPostCssResult { - content, - assets: resolved_assets, - } - .cell()) + let assets = emitted_assets_to_virtual_sources(processed_css.assets).await?; + let content = AssetContent::File(FileContent::Content(file).cell()).cell(); + Ok(ProcessPostCssResult { content, assets }.cell()) } } diff --git a/turbopack/crates/turbopack-node/src/transforms/util.rs b/turbopack/crates/turbopack-node/src/transforms/util.rs index bb1fb69eff09b3..658aef1a302c7b 100644 --- a/turbopack/crates/turbopack-node/src/transforms/util.rs +++ b/turbopack/crates/turbopack-node/src/transforms/util.rs @@ -1,8 +1,9 @@ use std::collections::BTreeMap; +use anyhow::Result; use serde::{Deserialize, Serialize}; use serde_json::Value as JsonValue; -use turbo_tasks::{RcStr, Vc}; +use turbo_tasks::{RcStr, ResolvedVc, TryJoinIterExt}; use turbo_tasks_fs::{File, FileContent, FileSystem}; use turbopack_core::{ asset::AssetContent, server_fs::ServerFileSystem, virtual_source::VirtualSource, @@ -16,9 +17,9 @@ pub struct EmittedAsset { source_map: Option, } -pub fn emitted_assets_to_virtual_sources( +pub async fn emitted_assets_to_virtual_sources( assets: Option>, -) -> Vec> { +) -> Result>> { assets .into_iter() .flatten() @@ -38,6 +39,8 @@ pub fn emitted_assets_to_virtual_sources( ServerFileSystem::new().root().join(file), AssetContent::File(FileContent::Content(File::from(content)).cell()).cell(), ) + .to_resolved() }) - .collect() + .try_join() + .await } diff --git a/turbopack/crates/turbopack-node/src/transforms/webpack.rs b/turbopack/crates/turbopack-node/src/transforms/webpack.rs index 3e3e829d1f6db7..117ca8ace9949e 100644 --- a/turbopack/crates/turbopack-node/src/transforms/webpack.rs +++ b/turbopack/crates/turbopack-node/src/transforms/webpack.rs @@ -268,7 +268,11 @@ impl WebpackLoadersProcessedAsset { Either::Left(str) => File::from(str), Either::Right(bytes) => File::from(bytes.binary), }; - let assets = emitted_assets_to_virtual_sources(processed.assets); + let assets = emitted_assets_to_virtual_sources(processed.assets) + .await? + .into_iter() + .map(|asset| *asset) + .collect(); let content = AssetContent::File(FileContent::Content(file).cell()).cell(); Ok(ProcessWebpackLoadersResult { content, diff --git a/turbopack/crates/turbopack/src/graph/mod.rs b/turbopack/crates/turbopack/src/graph/mod.rs index 3689bedfc4ebb6..18d8e3fa1878d5 100644 --- a/turbopack/crates/turbopack/src/graph/mod.rs +++ b/turbopack/crates/turbopack/src/graph/mod.rs @@ -96,13 +96,12 @@ impl AggregatedGraph { .collect::>() { let cost = cost.await?.0; - let resolved_reference = reference.to_resolved().await?; if cost == 0 { - inner.insert(resolved_reference); + inner.insert(reference); } else if cost > self_cost { - references.insert(resolved_reference); + references.insert(reference); } else { - outer.insert(resolved_reference); + outer.insert(reference); } } Ok(AggregatedGraphsValuedReferences {