From 864b577820f681b66c9e94db634e1c1e97393d25 Mon Sep 17 00:00:00 2001 From: Benjamin Woodruff Date: Mon, 28 Oct 2024 17:04:43 -0700 Subject: [PATCH] codemod(turbopack): Rewrite Vc fields in structs as ResolvedVc (part 5) (#71861) Generated using a version of https://github.com/vercel/turbopack-resolved-vc-codemod . This uses Anthropic Claude Sonnet 3.5 for more complicated errors we don't have hardcoded logic for. - Part 1: #70927 - Part 2: #71172 - Part 3: #71665 - Part 4: #71804 Closes PACK-3339 --- turbopack/crates/node-file-trace/src/lib.rs | 6 ++- turbopack/crates/turbopack-core/src/ident.rs | 4 +- .../crates/turbopack-css/src/chunk/mod.rs | 18 ++++---- .../src/source/resolve.rs | 4 +- .../src/source/route_tree.rs | 45 ++++++++++--------- .../turbopack-ecmascript/src/chunk/mod.rs | 20 ++++----- .../src/chunk_group_files_asset.rs | 6 ++- .../turbopack-ecmascript/src/code_gen.rs | 4 +- .../crates/turbopack-ecmascript/src/lib.rs | 5 ++- .../src/references/esm/export.rs | 8 ++-- .../src/references/mod.rs | 10 ++--- .../src/references/require_context.rs | 18 ++++---- turbopack/crates/turbopack-node/src/lib.rs | 16 +++---- .../src/render/render_static.rs | 22 +++++---- .../turbopack-node/src/transforms/postcss.rs | 12 ++--- .../turbopack-node/src/transforms/util.rs | 11 +++-- .../turbopack-node/src/transforms/webpack.rs | 6 ++- .../src/resolve_options_context.rs | 4 +- .../turbopack/benches/node_file_trace.rs | 4 +- turbopack/crates/turbopack/src/graph/mod.rs | 18 ++++---- 20 files changed, 133 insertions(+), 108 deletions(-) diff --git a/turbopack/crates/node-file-trace/src/lib.rs b/turbopack/crates/node-file-trace/src/lib.rs index 993cbf5e681c6..36b746e90e2f9 100644 --- a/turbopack/crates/node-file-trace/src/lib.rs +++ b/turbopack/crates/node-file-trace/src/lib.rs @@ -576,8 +576,10 @@ async fn create_module_asset( ..Default::default() } .into(), - ))); - let compile_time_info = CompileTimeInfo::builder(env).cell(); + ))) + .to_resolved() + .await?; + let compile_time_info = CompileTimeInfo::builder(*env).cell(); let glob_mappings = vec![ ( root, diff --git a/turbopack/crates/turbopack-core/src/ident.rs b/turbopack/crates/turbopack-core/src/ident.rs index 5e8f583d0bbff..0a5e98adcb05e 100644 --- a/turbopack/crates/turbopack-core/src/ident.rs +++ b/turbopack/crates/turbopack-core/src/ident.rs @@ -17,7 +17,7 @@ pub struct AssetIdent { /// The fragment of the asset (e.g. `#foo`) pub fragment: Option>, /// The assets that are nested in this asset - pub assets: Vec<(Vc, Vc)>, + pub assets: Vec<(ResolvedVc, ResolvedVc)>, /// The modifiers of this asset (e.g. `client chunks`) pub modifiers: Vec>, /// The part of the asset that is a (ECMAScript) module @@ -31,7 +31,7 @@ impl AssetIdent { self.modifiers.push(modifier); } - pub fn add_asset(&mut self, key: Vc, asset: Vc) { + pub fn add_asset(&mut self, key: ResolvedVc, asset: ResolvedVc) { self.assets.push((key, asset)); } diff --git a/turbopack/crates/turbopack-css/src/chunk/mod.rs b/turbopack/crates/turbopack-css/src/chunk/mod.rs index 649d9cd3b126d..f822c60d61d2e 100644 --- a/turbopack/crates/turbopack-css/src/chunk/mod.rs +++ b/turbopack/crates/turbopack-css/src/chunk/mod.rs @@ -252,7 +252,7 @@ impl OutputAsset for CssChunk { let CssChunkContent { chunk_items, .. } = &*self.content.await?; let mut common_path = if let Some(chunk_item) = chunk_items.first() { - let path = chunk_item.asset_ident().path().resolve().await?; + let path = chunk_item.asset_ident().path().to_resolved().await?; Some((path, path.await?)) } else { None @@ -265,7 +265,7 @@ impl OutputAsset for CssChunk { if let Some((common_path_vc, common_path_ref)) = common_path.as_mut() { let path = chunk_item.asset_ident().path().await?; while !path.is_inside_or_equal_ref(common_path_ref) { - let parent = common_path_vc.parent().resolve().await?; + let parent = common_path_vc.parent().to_resolved().await?; if parent == *common_path_vc { common_path = None; break; @@ -274,19 +274,17 @@ impl OutputAsset for CssChunk { *common_path_ref = (*common_path_vc).await?; } } - assets.push((chunk_item_key, chunk_item.content_ident())); - } - - // Make sure the idents are resolved - for (_, ident) in assets.iter_mut() { - *ident = ident.resolve().await?; + assets.push(( + chunk_item_key.to_resolved().await?, + chunk_item.content_ident().to_resolved().await?, + )); } let ident = AssetIdent { path: if let Some((common_path, _)) = common_path { - common_path + *common_path } else { - ServerFileSystem::new().root() + *ServerFileSystem::new().root().to_resolved().await? }, query: Vc::::default(), fragment: None, diff --git a/turbopack/crates/turbopack-dev-server/src/source/resolve.rs b/turbopack/crates/turbopack-dev-server/src/source/resolve.rs index 0db0873fbbed0..82328f500121d 100644 --- a/turbopack/crates/turbopack-dev-server/src/source/resolve.rs +++ b/turbopack/crates/turbopack-dev-server/src/source/resolve.rs @@ -24,7 +24,7 @@ use super::{ #[turbo_tasks::value(serialization = "none")] pub enum ResolveSourceRequestResult { NotFound, - Static(Vc, ResolvedVc), + Static(ResolvedVc, ResolvedVc), HttpProxy(Vc), } @@ -107,7 +107,7 @@ pub async fn resolve_source_request( } ContentSourceContent::Static(static_content) => { return Ok(ResolveSourceRequestResult::Static( - **static_content, + *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 dcfee2284c71c..8f108a0e74035 100644 --- a/turbopack/crates/turbopack-dev-server/src/source/route_tree.rs +++ b/turbopack/crates/turbopack-dev-server/src/source/route_tree.rs @@ -3,7 +3,8 @@ use std::{fmt::Write, mem::replace}; use anyhow::Result; use serde::{Deserialize, Serialize}; use turbo_tasks::{ - fxindexmap, trace::TraceRawVcs, FxIndexMap, RcStr, TaskInput, TryJoinIterExt, ValueToString, Vc, + fxindexmap, trace::TraceRawVcs, FxIndexMap, RcStr, ResolvedVc, TaskInput, TryJoinIterExt, + ValueToString, Vc, }; use super::{GetContentSourceContent, GetContentSourceContents}; @@ -101,7 +102,7 @@ pub struct RouteTree { base: Vec, sources: Vec>>, static_segments: FxIndexMap>, - dynamic_segments: Vec>, + dynamic_segments: Vec>, catch_all_sources: Vec>>, fallback_sources: Vec>>, not_found_sources: Vec>>, @@ -339,7 +340,7 @@ impl RouteTree { .cell()), BaseSegment::Dynamic => Ok(RouteTree { base, - dynamic_segments: vec![inner.cell()], + dynamic_segments: vec![inner.resolved_cell()], ..Default::default() } .cell()), @@ -366,24 +367,26 @@ impl RouteTree { fallback_sources, not_found_sources, } = &mut this; - sources - .iter_mut() - .for_each(|s| *s = mapper.map_get_content(*s)); - catch_all_sources - .iter_mut() - .for_each(|s| *s = mapper.map_get_content(*s)); - fallback_sources - .iter_mut() - .for_each(|s| *s = mapper.map_get_content(*s)); - not_found_sources - .iter_mut() - .for_each(|s| *s = mapper.map_get_content(*s)); - static_segments - .values_mut() - .for_each(|r| *r = r.map_routes(mapper)); - dynamic_segments - .iter_mut() - .for_each(|r| *r = r.map_routes(mapper)); + + for s in sources.iter_mut() { + *s = mapper.map_get_content(*s); + } + for s in catch_all_sources.iter_mut() { + *s = mapper.map_get_content(*s); + } + for s in fallback_sources.iter_mut() { + *s = mapper.map_get_content(*s); + } + 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); + } + for r in dynamic_segments.iter_mut() { + *r = r.map_routes(mapper).to_resolved().await?; + } + Ok(this.cell()) } } diff --git a/turbopack/crates/turbopack-ecmascript/src/chunk/mod.rs b/turbopack/crates/turbopack-ecmascript/src/chunk/mod.rs index 00ae0fe2633e4..095e09e28a91e 100644 --- a/turbopack/crates/turbopack-ecmascript/src/chunk/mod.rs +++ b/turbopack/crates/turbopack-ecmascript/src/chunk/mod.rs @@ -78,7 +78,7 @@ impl Chunk for EcmascriptChunk { let EcmascriptChunkContent { chunk_items, .. } = &*self.content.await?; let mut common_path = if let Some((chunk_item, _)) = chunk_items.first() { - let path = chunk_item.asset_ident().path().resolve().await?; + let path = chunk_item.asset_ident().path().to_resolved().await?; Some((path, path.await?)) } else { None @@ -90,7 +90,7 @@ impl Chunk for EcmascriptChunk { if let Some((common_path_vc, common_path_ref)) = common_path.as_mut() { let path = chunk_item.asset_ident().path().await?; while !path.is_inside_or_equal_ref(common_path_ref) { - let parent = common_path_vc.parent().resolve().await?; + let parent = common_path_vc.parent().to_resolved().await?; if parent == *common_path_vc { common_path = None; break; @@ -99,21 +99,21 @@ impl Chunk for EcmascriptChunk { *common_path_ref = (*common_path_vc).await?; } } - assets.push((chunk_item_key, chunk_item.content_ident())); + assets.push(( + chunk_item_key.to_resolved().await?, + chunk_item.content_ident().to_resolved().await?, + )); } - // Make sure the idents are resolved - for (_, ident) in assets.iter_mut() { - *ident = ident.resolve().await?; - } + // The previous resolve loop is no longer needed since we're already using ResolvedVc let ident = AssetIdent { path: if let Some((common_path, _)) = common_path { - common_path + *common_path } else { - ServerFileSystem::new().root() + *ServerFileSystem::new().root().to_resolved().await? }, - query: Vc::::default(), + query: *Vc::::default().to_resolved().await?, fragment: None, assets, modifiers: Vec::new(), 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 9bad806ee51b3..d2ff4b0fe76c1 100644 --- a/turbopack/crates/turbopack-ecmascript/src/chunk_group_files_asset.rs +++ b/turbopack/crates/turbopack-ecmascript/src/chunk_group_files_asset.rs @@ -1,5 +1,5 @@ use anyhow::Result; -use turbo_tasks::{FxIndexSet, RcStr, TryJoinIterExt, Value, ValueToString, Vc}; +use turbo_tasks::{FxIndexSet, RcStr, ResolvedVc, TryJoinIterExt, Value, ValueToString, Vc}; use turbo_tasks_fs::{File, FileSystemPath}; use turbopack_core::{ asset::{Asset, AssetContent}, @@ -39,7 +39,7 @@ pub struct ChunkGroupFilesAsset { pub module: Vc>, pub client_root: Vc, pub chunking_context: Vc>, - pub runtime_entries: Option>, + pub runtime_entries: Option>, } #[turbo_tasks::function] @@ -132,6 +132,8 @@ impl ChunkGroupFilesChunkItem { inner.module.ident(), inner .runtime_entries + .as_deref() + .copied() .unwrap_or_else(EvaluatableAssets::empty) .with_entry(ecma), Value::new(AvailabilityInfo::Root), diff --git a/turbopack/crates/turbopack-ecmascript/src/code_gen.rs b/turbopack/crates/turbopack-ecmascript/src/code_gen.rs index 0663275da1980..6d4eb65bfd9fd 100644 --- a/turbopack/crates/turbopack-ecmascript/src/code_gen.rs +++ b/turbopack/crates/turbopack-ecmascript/src/code_gen.rs @@ -3,7 +3,7 @@ use swc_core::ecma::{ ast::Stmt, visit::{AstParentKind, VisitMut}, }; -use turbo_tasks::{debug::ValueDebugFormat, trace::TraceRawVcs, RcStr, Vc}; +use turbo_tasks::{debug::ValueDebugFormat, trace::TraceRawVcs, RcStr, ResolvedVc, Vc}; use turbopack_core::chunk::{AsyncModuleInfo, ChunkingContext}; /// impl of code generation inferred from a ModuleReference. @@ -108,7 +108,7 @@ pub trait CodeGenerateableWithAsyncModuleInfo { #[derive(Clone, Copy, PartialEq, Eq, Serialize, Deserialize, TraceRawVcs, ValueDebugFormat)] pub enum CodeGen { CodeGenerateable(Vc>), - CodeGenerateableWithAsyncModuleInfo(Vc>), + CodeGenerateableWithAsyncModuleInfo(ResolvedVc>), } #[turbo_tasks::value(transparent)] diff --git a/turbopack/crates/turbopack-ecmascript/src/lib.rs b/turbopack/crates/turbopack-ecmascript/src/lib.rs index d17a376706aa2..6b6b37f17709f 100644 --- a/turbopack/crates/turbopack-ecmascript/src/lib.rs +++ b/turbopack/crates/turbopack-ecmascript/src/lib.rs @@ -523,7 +523,10 @@ impl Module for EcmascriptModuleAsset { if let Some(inner_assets) = self.inner_assets { let mut ident = self.source.ident().await?.clone_value(); for (name, asset) in inner_assets.await?.iter() { - ident.add_asset(Vc::cell(name.to_string().into()), asset.ident()); + ident.add_asset( + ResolvedVc::cell(name.to_string().into()), + asset.ident().to_resolved().await?, + ); } ident.add_modifier(modifier()); ident.layer = Some(self.asset_context.layer().to_resolved().await?); diff --git a/turbopack/crates/turbopack-ecmascript/src/references/esm/export.rs b/turbopack/crates/turbopack-ecmascript/src/references/esm/export.rs index 62862f5a329d2..30beabbc7a311 100644 --- a/turbopack/crates/turbopack-ecmascript/src/references/esm/export.rs +++ b/turbopack/crates/turbopack-ecmascript/src/references/esm/export.rs @@ -14,7 +14,9 @@ use swc_core::{ }, quote, quote_expr, }; -use turbo_tasks::{trace::TraceRawVcs, FxIndexMap, RcStr, TryFlatJoinIterExt, ValueToString, Vc}; +use turbo_tasks::{ + trace::TraceRawVcs, FxIndexMap, RcStr, ResolvedVc, TryFlatJoinIterExt, ValueToString, Vc, +}; use turbo_tasks_fs::glob::Glob; use turbopack_core::{ chunk::ChunkingContext, @@ -425,7 +427,7 @@ pub struct EsmExports { pub struct ExpandedExports { pub exports: BTreeMap, /// Modules we couldn't analyse all exports of. - pub dynamic_exports: Vec>>, + pub dynamic_exports: Vec>>, } #[turbo_tasks::value_impl] @@ -456,7 +458,7 @@ impl EsmExports { } if export_info.has_dynamic_exports { - dynamic_exports.push(**asset); + 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 9dd4100eb6f17..f3178fef42b29 100644 --- a/turbopack/crates/turbopack-ecmascript/src/references/mod.rs +++ b/turbopack/crates/turbopack-ecmascript/src/references/mod.rs @@ -240,14 +240,14 @@ impl AnalyzeEcmascriptModuleResultBuilder { /// Adds a codegen to the analysis result. #[allow(dead_code)] - pub fn add_code_gen_with_availability_info(&mut self, code_gen: Vc) + pub fn add_code_gen_with_availability_info(&mut self, code_gen: ResolvedVc) where C: Upcast>, { self.code_gens - .push(CodeGen::CodeGenerateableWithAsyncModuleInfo(Vc::upcast( - code_gen, - ))); + .push(CodeGen::CodeGenerateableWithAsyncModuleInfo( + ResolvedVc::upcast(code_gen), + )); } pub fn add_binding(&mut self, binding: EsmBinding) { @@ -319,7 +319,7 @@ impl AnalyzeEcmascriptModuleResultBuilder { *c = c.resolve().await?; } CodeGen::CodeGenerateableWithAsyncModuleInfo(c) => { - *c = c.resolve().await?; + *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 0092285be2d91..2fe179515f4ee 100644 --- a/turbopack/crates/turbopack-ecmascript/src/references/require_context.rs +++ b/turbopack/crates/turbopack-ecmascript/src/references/require_context.rs @@ -12,7 +12,7 @@ use swc_core::{ }, quote, quote_expr, }; -use turbo_tasks::{primitives::Regex, FxIndexMap, RcStr, Value, ValueToString, Vc}; +use turbo_tasks::{primitives::Regex, FxIndexMap, RcStr, ResolvedVc, Value, ValueToString, Vc}; use turbo_tasks_fs::{DirectoryContent, DirectoryEntry, FileSystemPath}; use turbopack_core::{ asset::{Asset, AssetContent}, @@ -46,8 +46,8 @@ use crate::{ #[turbo_tasks::value] #[derive(Debug)] pub(crate) enum DirListEntry { - File(Vc), - Dir(Vc), + File(ResolvedVc), + Dir(ResolvedVc), } #[turbo_tasks::value(transparent)] @@ -83,7 +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)); + list.insert(relative_path, DirListEntry::File(*path)); } } } @@ -91,9 +91,11 @@ impl DirList { if let Some(relative_path) = root_val.get_relative_path_to(&*path.await?) { list.insert( relative_path, - DirListEntry::Dir(DirList::read_internal( - root, **path, recursive, filter, - )), + DirListEntry::Dir( + DirList::read_internal(root, **path, recursive, filter) + .to_resolved() + .await?, + ), ); } } @@ -119,7 +121,7 @@ impl DirList { for (k, entry) in &*dir { match entry { DirListEntry::File(path) => { - list.insert(k.clone(), *path); + 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 978ed0d270756..4a2bb0a4b0692 100644 --- a/turbopack/crates/turbopack-node/src/lib.rs +++ b/turbopack/crates/turbopack-node/src/lib.rs @@ -10,7 +10,7 @@ use anyhow::{bail, Result}; pub use node_entry::{NodeEntry, NodeRenderingEntries, NodeRenderingEntry}; use turbo_tasks::{ graph::{AdjacencyMap, GraphTraversal}, - Completion, Completions, FxIndexSet, RcStr, TryJoinIterExt, ValueToString, Vc, + Completion, Completions, FxIndexSet, RcStr, ResolvedVc, TryJoinIterExt, ValueToString, Vc, }; use turbo_tasks_env::ProcessEnv; use turbo_tasks_fs::{to_sys_path, File, FileSystemPath}; @@ -127,14 +127,14 @@ 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?; #[derive(PartialEq, Eq, Hash, Clone, Copy)] enum Type { - Internal(Vc>), - External(Vc>), + Internal(ResolvedVc>), + External(ResolvedVc>), } let get_asset_children = |asset| async move { let Type::Internal(asset) = asset else { @@ -155,9 +155,9 @@ async fn separate_assets( .await? .is_inside_ref(intermediate_output_path) { - Ok(Type::Internal(*asset)) + Ok(Type::Internal(asset.to_resolved().await?)) } else { - Ok(Type::External(*asset)) + Ok(Type::External(asset.to_resolved().await?)) } }) .try_join() @@ -177,10 +177,10 @@ async fn separate_assets( for item in graph.into_reverse_topological() { match item { Type::Internal(asset) => { - internal_assets.insert(asset); + internal_assets.insert(*asset); } Type::External(asset) => { - external_asset_entrypoints.insert(asset); + external_asset_entrypoints.insert(*asset); } } } diff --git a/turbopack/crates/turbopack-node/src/render/render_static.rs b/turbopack/crates/turbopack-node/src/render/render_static.rs index a9053d1c90897..0bd2c47e4623f 100644 --- a/turbopack/crates/turbopack-node/src/render/render_static.rs +++ b/turbopack/crates/turbopack-node/src/render/render_static.rs @@ -114,7 +114,7 @@ pub async fn render_static( }; Ok(match first { - RenderItem::Response(response) => response, + RenderItem::Response(response) => *response, RenderItem::Headers(data) => { let body = stream.map(|item| match item { Ok(RenderItem::BodyChunk(b)) => Ok(b), @@ -183,7 +183,7 @@ async fn static_error( #[derive(Clone, Debug)] #[turbo_tasks::value] enum RenderItem { - Response(Vc), + Response(ResolvedVc), Headers(ResponseHeaders), BodyChunk(Bytes), } @@ -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())); + yield RenderItem::Response( + StaticResult::rewrite(RewriteBuilder::new(path).build()).to_resolved().await? + ); return; } RenderStaticIncomingMessage::Response { @@ -326,11 +328,13 @@ async fn render_stream_internal( body, } => { drop(guard); - yield RenderItem::Response(StaticResult::content( - AssetContent::file(File::from(body).into()), - status_code, - Vc::cell(headers), - )); + yield RenderItem::Response( + StaticResult::content( + AssetContent::file(File::from(body).into()), + status_code, + Vc::cell(headers), + ).to_resolved().await? + ); return; } RenderStaticIncomingMessage::Error(error) => { @@ -349,7 +353,7 @@ async fn render_stream_internal( static_error(path, anyhow!(trace), Some(operation), fallback_page).await?, 500, HeaderList::empty(), - ) + ).to_resolved().await? ); return; } diff --git a/turbopack/crates/turbopack-node/src/transforms/postcss.rs b/turbopack/crates/turbopack-node/src/transforms/postcss.rs index ada73e4fa6bd2..3072608b4fc27 100644 --- a/turbopack/crates/turbopack-node/src/transforms/postcss.rs +++ b/turbopack/crates/turbopack-node/src/transforms/postcss.rs @@ -2,8 +2,8 @@ use anyhow::{bail, Context, Result}; use indoc::formatdoc; use serde::{Deserialize, Serialize}; use turbo_tasks::{ - fxindexmap, trace::TraceRawVcs, Completion, Completions, RcStr, TaskInput, TryFlatJoinIterExt, - Value, Vc, + fxindexmap, trace::TraceRawVcs, Completion, Completions, RcStr, ResolvedVc, TaskInput, + TryFlatJoinIterExt, Value, Vc, }; use turbo_tasks_bytes::stream::SingleValue; use turbo_tasks_fs::{ @@ -164,7 +164,7 @@ impl Asset for PostCssTransformedAsset { #[turbo_tasks::value] struct ProcessPostCssResult { content: Vc, - assets: Vec>, + assets: Vec>, } #[turbo_tasks::function] @@ -458,7 +458,7 @@ impl PostCssTransformedAsset { }; let FileContent::Content(content) = &*file.await? else { return Ok(ProcessPostCssResult { - content: AssetContent::File(FileContent::NotFound.cell()).cell(), + content: AssetContent::File(*FileContent::NotFound.resolved_cell()).cell(), assets: Vec::new(), } .cell()); @@ -501,7 +501,7 @@ impl PostCssTransformedAsset { let SingleValue::Single(val) = config_value.try_into_single().await? else { // An error happened, which has already been converted into an issue. return Ok(ProcessPostCssResult { - content: AssetContent::File(FileContent::NotFound.cell()).cell(), + content: AssetContent::File(*FileContent::NotFound.resolved_cell()).cell(), assets: Vec::new(), } .cell()); @@ -511,7 +511,7 @@ impl PostCssTransformedAsset { // TODO handle SourceMap let file = File::from(processed_css.css); - let assets = emitted_assets_to_virtual_sources(processed_css.assets); + 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 bb1fb69eff09b..658aef1a302c7 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 3e3e829d1f6db..117ca8ace9949 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-resolve/src/resolve_options_context.rs b/turbopack/crates/turbopack-resolve/src/resolve_options_context.rs index de678d9421711..6efa18a592e76 100644 --- a/turbopack/crates/turbopack-resolve/src/resolve_options_context.rs +++ b/turbopack/crates/turbopack-resolve/src/resolve_options_context.rs @@ -1,5 +1,5 @@ use anyhow::Result; -use turbo_tasks::{RcStr, ValueDefault, Vc}; +use turbo_tasks::{RcStr, ResolvedVc, ValueDefault, Vc}; use turbo_tasks_fs::FileSystemPath; use turbopack_core::{ condition::ContextCondition, @@ -14,7 +14,7 @@ use turbopack_core::{ #[derive(Default, Clone)] pub struct ResolveOptionsContext { #[serde(default)] - pub emulate_environment: Option>, + pub emulate_environment: Option>, #[serde(default)] pub enable_types: bool, #[serde(default)] diff --git a/turbopack/crates/turbopack/benches/node_file_trace.rs b/turbopack/crates/turbopack/benches/node_file_trace.rs index c05315ae75765..d2a23ebd06cff 100644 --- a/turbopack/crates/turbopack/benches/node_file_trace.rs +++ b/turbopack/crates/turbopack/benches/node_file_trace.rs @@ -98,7 +98,9 @@ fn bench_emit(b: &mut Bencher, bench_input: &BenchInput) { } .cell(), ResolveOptionsContext { - emulate_environment: Some(compile_time_info.environment().resolve().await?), + emulate_environment: Some( + compile_time_info.environment().to_resolved().await?, + ), ..Default::default() } .cell(), diff --git a/turbopack/crates/turbopack/src/graph/mod.rs b/turbopack/crates/turbopack/src/graph/mod.rs index a096cb0f8a024..18d8e3fa1878d 100644 --- a/turbopack/crates/turbopack/src/graph/mod.rs +++ b/turbopack/crates/turbopack/src/graph/mod.rs @@ -51,7 +51,7 @@ impl AggregatedGraph { for reference in asset.references().await?.iter() { let reference = reference.resolve().await?; if asset != reference.to_resolved().await? { - refs.insert(AggregatedGraph::leaf(reference)); + refs.insert(AggregatedGraph::leaf(reference).to_resolved().await?); } } AggregatedGraphsSet { set: refs }.into() @@ -64,7 +64,7 @@ impl AggregatedGraph { .collect::>() .into_iter() { - set.insert(item.resolve().await?); + set.insert(item.to_resolved().await?); } AggregatedGraphsSet { set }.into() } @@ -152,20 +152,20 @@ async fn aggregate_more(node: Vc) -> Result for valued_refs in valued_refs { let valued_refs = valued_refs.await?; for &reference in valued_refs.inner.iter() { - content.insert(reference); + content.insert(*reference); } for &reference in valued_refs.references.iter() { if content.contains(&reference) { continue; } - references.insert(reference); + references.insert(*reference); } for &reference in valued_refs.outer.iter() { if content.contains(&reference) { continue; } references.remove(&reference); - in_progress.insert(reference); + in_progress.insert(*reference); } } } @@ -182,7 +182,7 @@ async fn aggregate_more(node: Vc) -> Result #[turbo_tasks::value(shared)] struct AggregatedGraphsSet { - pub set: HashSet>, + pub set: HashSet>, } #[turbo_tasks::value(shared)] @@ -193,7 +193,7 @@ pub enum AggregatedGraphNodeContent { #[turbo_tasks::value(shared)] struct AggregatedGraphsValuedReferences { - pub inner: HashSet>, - pub outer: HashSet>, - pub references: HashSet>, + pub inner: HashSet>, + pub outer: HashSet>, + pub references: HashSet>, }