Unverified Commit a63e11a0 authored by Benjamin Woodruff's avatar Benjamin Woodruff Committed by GitHub

refactor(turbopack-core): Change `OutputAssets` type to use ResolvedVc (#72041)

A hand refactor of the `OutputAssets` type in `turbopack-core` to use `ResolvedVc`. This is one of the more common types passed around turbopack, so this touches a lot of code.

Closes PACK-3358
parent 9bec7a23
...@@ -994,15 +994,17 @@ impl AppEndpoint { ...@@ -994,15 +994,17 @@ impl AppEndpoint {
.collect(), .collect(),
}; };
let manifest_path_prefix = &app_entry.original_name; let manifest_path_prefix = &app_entry.original_name;
let app_build_manifest_output = Vc::upcast(VirtualOutputAsset::new( let app_build_manifest_output = VirtualOutputAsset::new(
node_root.join( node_root.join(
format!("server/app{manifest_path_prefix}/app-build-manifest.json",).into(), format!("server/app{manifest_path_prefix}/app-build-manifest.json",).into(),
), ),
AssetContent::file( AssetContent::file(
File::from(serde_json::to_string_pretty(&app_build_manifest)?).into(), File::from(serde_json::to_string_pretty(&app_build_manifest)?).into(),
), ),
)); )
server_assets.insert(app_build_manifest_output); .to_resolved()
.await?;
server_assets.insert(ResolvedVc::upcast(app_build_manifest_output));
// polyfill-nomodule.js is a pre-compiled asset distributed as part of next, // polyfill-nomodule.js is a pre-compiled asset distributed as part of next,
// load it as a RawModule. // load it as a RawModule.
...@@ -1013,13 +1015,15 @@ impl AppEndpoint { ...@@ -1013,13 +1015,15 @@ impl AppEndpoint {
let polyfill_output_path = let polyfill_output_path =
client_chunking_context.chunk_path(polyfill_source.ident(), ".js".into()); client_chunking_context.chunk_path(polyfill_source.ident(), ".js".into());
let polyfill_output_asset = let polyfill_output_asset =
RawOutput::new(polyfill_output_path, Vc::upcast(polyfill_source)); RawOutput::new(polyfill_output_path, Vc::upcast(polyfill_source))
.to_resolved()
.await?;
let polyfill_client_path = client_relative_path_ref let polyfill_client_path = client_relative_path_ref
.get_path_to(&*polyfill_output_path.await?) .get_path_to(&*polyfill_output_path.await?)
.context("failed to resolve client-relative path to polyfill")? .context("failed to resolve client-relative path to polyfill")?
.into(); .into();
let polyfill_client_paths = vec![polyfill_client_path]; let polyfill_client_paths = vec![polyfill_client_path];
client_assets.insert(Vc::upcast(polyfill_output_asset)); client_assets.insert(ResolvedVc::upcast(polyfill_output_asset));
if *this if *this
.app_project .app_project
...@@ -1029,15 +1033,17 @@ impl AppEndpoint { ...@@ -1029,15 +1033,17 @@ impl AppEndpoint {
{ {
let webpack_stats = let webpack_stats =
generate_webpack_stats(app_entry.original_name.clone(), &client_assets).await?; generate_webpack_stats(app_entry.original_name.clone(), &client_assets).await?;
let stats_output: Vc<Box<dyn OutputAsset>> = Vc::upcast(VirtualOutputAsset::new( let stats_output = VirtualOutputAsset::new(
node_root.join( node_root.join(
format!("server/app{manifest_path_prefix}/webpack-stats.json",).into(), format!("server/app{manifest_path_prefix}/webpack-stats.json",).into(),
), ),
AssetContent::file( AssetContent::file(
File::from(serde_json::to_string_pretty(&webpack_stats)?).into(), File::from(serde_json::to_string_pretty(&webpack_stats)?).into(),
), ),
)); )
server_assets.insert(Vc::upcast(stats_output)); .to_resolved()
.await?;
server_assets.insert(ResolvedVc::upcast(stats_output));
} }
let build_manifest = BuildManifest { let build_manifest = BuildManifest {
...@@ -1045,14 +1051,16 @@ impl AppEndpoint { ...@@ -1045,14 +1051,16 @@ impl AppEndpoint {
polyfill_files: polyfill_client_paths, polyfill_files: polyfill_client_paths,
..Default::default() ..Default::default()
}; };
let build_manifest_output = Vc::upcast(VirtualOutputAsset::new( let build_manifest_output = VirtualOutputAsset::new(
node_root node_root
.join(format!("server/app{manifest_path_prefix}/build-manifest.json",).into()), .join(format!("server/app{manifest_path_prefix}/build-manifest.json",).into()),
AssetContent::file( AssetContent::file(
File::from(serde_json::to_string_pretty(&build_manifest)?).into(), File::from(serde_json::to_string_pretty(&build_manifest)?).into(),
), ),
)); )
server_assets.insert(build_manifest_output); .to_resolved()
.await?;
server_assets.insert(ResolvedVc::upcast(build_manifest_output));
if runtime == NextRuntime::Edge { if runtime == NextRuntime::Edge {
// as the edge runtime doesn't support chunk loading we need to add all client // as the edge runtime doesn't support chunk loading we need to add all client
...@@ -1132,14 +1140,16 @@ impl AppEndpoint { ...@@ -1132,14 +1140,16 @@ impl AppEndpoint {
ssr_chunking_context, ssr_chunking_context,
this.app_project.project().next_config(), this.app_project.project().next_config(),
runtime, runtime,
); )
.to_resolved()
.await?;
server_assets.insert(entry_manifest); server_assets.insert(entry_manifest);
if runtime == NextRuntime::Edge { if runtime == NextRuntime::Edge {
middleware_assets.push(entry_manifest); middleware_assets.push(entry_manifest);
} }
} }
let client_assets = OutputAssets::new(client_assets.iter().cloned().collect::<Vec<_>>()); let client_assets = OutputAssets::new(client_assets.iter().map(|asset| **asset).collect());
let next_font_manifest_output = create_font_manifest( let next_font_manifest_output = create_font_manifest(
this.app_project.project().client_root(), this.app_project.project().client_root(),
...@@ -1219,23 +1229,28 @@ impl AppEndpoint { ...@@ -1219,23 +1229,28 @@ impl AppEndpoint {
..Default::default() ..Default::default()
}; };
let manifest_path_prefix = &app_entry.original_name; let manifest_path_prefix = &app_entry.original_name;
let middleware_manifest_v2 = Vc::upcast(VirtualOutputAsset::new( let middleware_manifest_v2 = ResolvedVc::upcast(
node_root.join( VirtualOutputAsset::new(
format!("server/app{manifest_path_prefix}/middleware-manifest.json",) node_root.join(
.into(), format!("server/app{manifest_path_prefix}/middleware-manifest.json",)
), .into(),
AssetContent::file( ),
FileContent::Content(File::from(serde_json::to_string_pretty( AssetContent::file(
&middleware_manifest_v2, FileContent::Content(File::from(serde_json::to_string_pretty(
)?)) &middleware_manifest_v2,
.cell(), )?))
), .cell(),
)); ),
)
.to_resolved()
.await?,
);
server_assets.insert(middleware_manifest_v2); server_assets.insert(middleware_manifest_v2);
// create app paths manifest // create app paths manifest
let app_paths_manifest_output = let app_paths_manifest_output =
create_app_paths_manifest(node_root, &app_entry.original_name, entry_file)?; create_app_paths_manifest(node_root, &app_entry.original_name, entry_file)
.await?;
server_assets.insert(app_paths_manifest_output); server_assets.insert(app_paths_manifest_output);
// create react-loadable-manifest for next/dynamic // create react-loadable-manifest for next/dynamic
...@@ -1284,7 +1299,8 @@ impl AppEndpoint { ...@@ -1284,7 +1299,8 @@ impl AppEndpoint {
.get_path_to(&*rsc_chunk.ident().path().await?) .get_path_to(&*rsc_chunk.ident().path().await?)
.context("RSC chunk path should be within app paths manifest directory")? .context("RSC chunk path should be within app paths manifest directory")?
.into(), .into(),
)?; )
.await?;
server_assets.insert(app_paths_manifest_output); server_assets.insert(app_paths_manifest_output);
// create react-loadable-manifest for next/dynamic // create react-loadable-manifest for next/dynamic
...@@ -1476,11 +1492,11 @@ impl AppEndpoint { ...@@ -1476,11 +1492,11 @@ impl AppEndpoint {
} }
} }
fn create_app_paths_manifest( async fn create_app_paths_manifest(
node_root: Vc<FileSystemPath>, node_root: Vc<FileSystemPath>,
original_name: &str, original_name: &str,
filename: RcStr, filename: RcStr,
) -> Result<Vc<Box<dyn OutputAsset>>> { ) -> Result<ResolvedVc<Box<dyn OutputAsset>>> {
let manifest_path_prefix = original_name; let manifest_path_prefix = original_name;
let path = let path =
node_root.join(format!("server/app{manifest_path_prefix}/app-paths-manifest.json",).into()); node_root.join(format!("server/app{manifest_path_prefix}/app-paths-manifest.json",).into());
...@@ -1490,10 +1506,16 @@ fn create_app_paths_manifest( ...@@ -1490,10 +1506,16 @@ fn create_app_paths_manifest(
}, },
..Default::default() ..Default::default()
}; };
Ok(Vc::upcast(VirtualOutputAsset::new( Ok(ResolvedVc::upcast(
path, VirtualOutputAsset::new(
AssetContent::file(File::from(serde_json::to_string_pretty(&app_paths_manifest)?).into()), path,
))) AssetContent::file(
File::from(serde_json::to_string_pretty(&app_paths_manifest)?).into(),
),
)
.to_resolved()
.await?,
))
} }
#[turbo_tasks::value_impl] #[turbo_tasks::value_impl]
...@@ -1596,7 +1618,7 @@ impl Endpoint for AppEndpoint { ...@@ -1596,7 +1618,7 @@ impl Endpoint for AppEndpoint {
#[turbo_tasks::value] #[turbo_tasks::value]
enum AppEndpointOutput { enum AppEndpointOutput {
NodeJs { NodeJs {
rsc_chunk: Vc<Box<dyn OutputAsset>>, rsc_chunk: ResolvedVc<Box<dyn OutputAsset>>,
server_assets: Vc<OutputAssets>, server_assets: Vc<OutputAssets>,
client_assets: Vc<OutputAssets>, client_assets: Vc<OutputAssets>,
}, },
......
use anyhow::Result; use anyhow::Result;
use next_core::{all_assets_from_entries, next_manifests::NextFontManifest}; use next_core::{all_assets_from_entries, next_manifests::NextFontManifest};
use turbo_tasks::{RcStr, ValueToString, Vc}; use turbo_tasks::{RcStr, ResolvedVc, ValueToString, Vc};
use turbo_tasks_fs::{File, FileSystemPath}; use turbo_tasks_fs::{File, FileSystemPath};
use turbopack_core::{ use turbopack_core::{
asset::AssetContent, asset::AssetContent,
...@@ -19,7 +19,7 @@ pub(crate) async fn create_font_manifest( ...@@ -19,7 +19,7 @@ pub(crate) async fn create_font_manifest(
pathname: &str, pathname: &str,
client_assets: Vc<OutputAssets>, client_assets: Vc<OutputAssets>,
app_dir: bool, app_dir: bool,
) -> Result<Vc<Box<dyn OutputAsset>>> { ) -> Result<ResolvedVc<Box<dyn OutputAsset>>> {
let all_client_output_assets = all_assets_from_entries(client_assets).await?; let all_client_output_assets = all_assets_from_entries(client_assets).await?;
// `_next` gets added again later, so we "strip" it here via // `_next` gets added again later, so we "strip" it here via
...@@ -65,8 +65,14 @@ pub(crate) async fn create_font_manifest( ...@@ -65,8 +65,14 @@ pub(crate) async fn create_font_manifest(
} }
}; };
Ok(Vc::upcast(VirtualOutputAsset::new( Ok(ResolvedVc::upcast(
path, VirtualOutputAsset::new(
AssetContent::file(File::from(serde_json::to_string_pretty(&next_font_manifest)?).into()), path,
))) AssetContent::file(
File::from(serde_json::to_string_pretty(&next_font_manifest)?).into(),
),
)
.to_resolved()
.await?,
))
} }
...@@ -163,7 +163,7 @@ impl InstrumentationEndpoint { ...@@ -163,7 +163,7 @@ impl InstrumentationEndpoint {
Value::new(AvailabilityInfo::Root), Value::new(AvailabilityInfo::Root),
) )
.await?; .await?;
Ok(chunk) Ok(*chunk)
} }
#[turbo_tasks::function] #[turbo_tasks::function]
...@@ -195,7 +195,7 @@ impl InstrumentationEndpoint { ...@@ -195,7 +195,7 @@ impl InstrumentationEndpoint {
instrumentation: Some(instrumentation_definition), instrumentation: Some(instrumentation_definition),
..Default::default() ..Default::default()
}; };
let middleware_manifest_v2 = Vc::upcast(VirtualOutputAsset::new( let middleware_manifest_v2 = VirtualOutputAsset::new(
node_root.join("server/instrumentation/middleware-manifest.json".into()), node_root.join("server/instrumentation/middleware-manifest.json".into()),
AssetContent::file( AssetContent::file(
FileContent::Content(File::from(serde_json::to_string_pretty( FileContent::Content(File::from(serde_json::to_string_pretty(
...@@ -203,12 +203,14 @@ impl InstrumentationEndpoint { ...@@ -203,12 +203,14 @@ impl InstrumentationEndpoint {
)?)) )?))
.cell(), .cell(),
), ),
)); )
output_assets.push(middleware_manifest_v2); .to_resolved()
.await?;
output_assets.push(ResolvedVc::upcast(middleware_manifest_v2));
Ok(Vc::cell(output_assets)) Ok(Vc::cell(output_assets))
} else { } else {
Ok(Vc::cell(vec![self.node_chunk()])) Ok(Vc::cell(vec![self.node_chunk().to_resolved().await?]))
} }
} }
} }
......
...@@ -2,7 +2,7 @@ use std::collections::HashMap; ...@@ -2,7 +2,7 @@ use std::collections::HashMap;
use anyhow::Result; use anyhow::Result;
use next_core::next_manifests::LoadableManifest; use next_core::next_manifests::LoadableManifest;
use turbo_tasks::{RcStr, TryFlatJoinIterExt, Vc}; use turbo_tasks::{RcStr, ResolvedVc, TryFlatJoinIterExt, Vc};
use turbo_tasks_fs::{File, FileContent, FileSystemPath}; use turbo_tasks_fs::{File, FileContent, FileSystemPath};
use turbopack_core::{ use turbopack_core::{
asset::AssetContent, asset::AssetContent,
...@@ -56,7 +56,7 @@ pub async fn create_react_loadable_manifest( ...@@ -56,7 +56,7 @@ pub async fn create_react_loadable_manifest(
} }
} }
let loadable_manifest = Vc::upcast(VirtualOutputAsset::new( let loadable_manifest = VirtualOutputAsset::new(
output_path, output_path,
AssetContent::file( AssetContent::file(
FileContent::Content(File::from(serde_json::to_string_pretty( FileContent::Content(File::from(serde_json::to_string_pretty(
...@@ -64,8 +64,10 @@ pub async fn create_react_loadable_manifest( ...@@ -64,8 +64,10 @@ pub async fn create_react_loadable_manifest(
)?)) )?))
.cell(), .cell(),
), ),
)); )
.to_resolved()
.await?;
output.push(loadable_manifest); output.push(ResolvedVc::upcast(loadable_manifest));
Ok(Vc::cell(output)) Ok(Vc::cell(output))
} }
...@@ -239,7 +239,7 @@ impl MiddlewareEndpoint { ...@@ -239,7 +239,7 @@ impl MiddlewareEndpoint {
.collect(), .collect(),
..Default::default() ..Default::default()
}; };
let middleware_manifest_v2 = Vc::upcast(VirtualOutputAsset::new( let middleware_manifest_v2 = VirtualOutputAsset::new(
node_root.join("server/middleware/middleware-manifest.json".into()), node_root.join("server/middleware/middleware-manifest.json".into()),
AssetContent::file( AssetContent::file(
FileContent::Content(File::from(serde_json::to_string_pretty( FileContent::Content(File::from(serde_json::to_string_pretty(
...@@ -247,8 +247,10 @@ impl MiddlewareEndpoint { ...@@ -247,8 +247,10 @@ impl MiddlewareEndpoint {
)?)) )?))
.cell(), .cell(),
), ),
)); )
output_assets.push(middleware_manifest_v2); .to_resolved()
.await?;
output_assets.push(ResolvedVc::upcast(middleware_manifest_v2));
Ok(Vc::cell(output_assets)) Ok(Vc::cell(output_assets))
} }
......
...@@ -1039,8 +1039,8 @@ impl PageEndpoint { ...@@ -1039,8 +1039,8 @@ impl PageEndpoint {
let ssr_chunk = match this.ty { let ssr_chunk = match this.ty {
PageEndpointType::Html => { PageEndpointType::Html => {
let client_chunks = self.client_chunks(); let client_chunks = self.client_chunks();
client_assets.extend(client_chunks.await?.iter().copied()); client_assets.extend(client_chunks.await?.iter().map(|asset| **asset));
let build_manifest = self.build_manifest(client_chunks); let build_manifest = self.build_manifest(client_chunks).to_resolved().await?;
let page_loader = self.page_loader(client_chunks); let page_loader = self.page_loader(client_chunks);
client_assets.push(page_loader); client_assets.push(page_loader);
server_assets.push(build_manifest); server_assets.push(build_manifest);
...@@ -1079,14 +1079,16 @@ impl PageEndpoint { ...@@ -1079,14 +1079,16 @@ impl PageEndpoint {
{ {
let webpack_stats = let webpack_stats =
generate_webpack_stats(original_name.to_owned(), &client_assets.await?).await?; generate_webpack_stats(original_name.to_owned(), &client_assets.await?).await?;
let stats_output: Vc<Box<dyn OutputAsset>> = Vc::upcast(VirtualOutputAsset::new( let stats_output = VirtualOutputAsset::new(
node_root node_root
.join(format!("server/pages{manifest_path_prefix}/webpack-stats.json",).into()), .join(format!("server/pages{manifest_path_prefix}/webpack-stats.json",).into()),
AssetContent::file( AssetContent::file(
File::from(serde_json::to_string_pretty(&webpack_stats)?).into(), File::from(serde_json::to_string_pretty(&webpack_stats)?).into(),
), ),
)); )
server_assets.push(Vc::upcast(stats_output)); .to_resolved()
.await?;
server_assets.push(ResolvedVc::upcast(stats_output));
} }
let page_output = match *ssr_chunk.await? { let page_output = match *ssr_chunk.await? {
...@@ -1094,7 +1096,7 @@ impl PageEndpoint { ...@@ -1094,7 +1096,7 @@ impl PageEndpoint {
entry, entry,
dynamic_import_entries, dynamic_import_entries,
} => { } => {
let pages_manifest = self.pages_manifest(entry); let pages_manifest = self.pages_manifest(*entry).to_resolved().await?;
server_assets.push(pages_manifest); server_assets.push(pages_manifest);
server_assets.push(entry); server_assets.push(entry);
...@@ -1114,7 +1116,7 @@ impl PageEndpoint { ...@@ -1114,7 +1116,7 @@ impl PageEndpoint {
let node_root = this.pages_project.project().node_root(); let node_root = this.pages_project.project().node_root();
let files_value = files.await?; let files_value = files.await?;
if let Some(&file) = files_value.first() { if let Some(&file) = files_value.first() {
let pages_manifest = self.pages_manifest(file); let pages_manifest = self.pages_manifest(*file).to_resolved().await?;
server_assets.push(pages_manifest); server_assets.push(pages_manifest);
} }
server_assets.extend(files_value.iter().copied()); server_assets.extend(files_value.iter().copied());
...@@ -1170,7 +1172,7 @@ impl PageEndpoint { ...@@ -1170,7 +1172,7 @@ impl PageEndpoint {
..Default::default() ..Default::default()
}; };
let manifest_path_prefix = get_asset_prefix_from_pathname(&this.pathname.await?); let manifest_path_prefix = get_asset_prefix_from_pathname(&this.pathname.await?);
let middleware_manifest_v2 = Vc::upcast(VirtualOutputAsset::new( let middleware_manifest_v2 = VirtualOutputAsset::new(
node_root.join( node_root.join(
format!("server/pages{manifest_path_prefix}/middleware-manifest.json") format!("server/pages{manifest_path_prefix}/middleware-manifest.json")
.into(), .into(),
...@@ -1181,8 +1183,10 @@ impl PageEndpoint { ...@@ -1181,8 +1183,10 @@ impl PageEndpoint {
)?)) )?))
.cell(), .cell(),
), ),
)); )
server_assets.push(middleware_manifest_v2); .to_resolved()
.await?;
server_assets.push(ResolvedVc::upcast(middleware_manifest_v2));
let loadable_manifest_output = self.react_loadable_manifest(dynamic_import_entries); let loadable_manifest_output = self.react_loadable_manifest(dynamic_import_entries);
server_assets.extend(loadable_manifest_output.await?.iter().copied()); server_assets.extend(loadable_manifest_output.await?.iter().copied());
...@@ -1319,7 +1323,7 @@ impl Endpoint for PageEndpoint { ...@@ -1319,7 +1323,7 @@ impl Endpoint for PageEndpoint {
#[turbo_tasks::value] #[turbo_tasks::value]
enum PageEndpointOutput { enum PageEndpointOutput {
NodeJs { NodeJs {
entry_chunk: Vc<Box<dyn OutputAsset>>, entry_chunk: ResolvedVc<Box<dyn OutputAsset>>,
server_assets: Vc<OutputAssets>, server_assets: Vc<OutputAssets>,
client_assets: Vc<OutputAssets>, client_assets: Vc<OutputAssets>,
}, },
...@@ -1365,7 +1369,7 @@ impl PageEndpointOutput { ...@@ -1365,7 +1369,7 @@ impl PageEndpointOutput {
#[turbo_tasks::value] #[turbo_tasks::value]
pub enum SsrChunk { pub enum SsrChunk {
NodeJs { NodeJs {
entry: Vc<Box<dyn OutputAsset>>, entry: ResolvedVc<Box<dyn OutputAsset>>,
dynamic_import_entries: Vc<DynamicImportedChunks>, dynamic_import_entries: Vc<DynamicImportedChunks>,
}, },
Edge { Edge {
......
use anyhow::Result; use anyhow::Result;
use next_core::{all_assets_from_entries, next_manifests::AssetBinding}; use next_core::{all_assets_from_entries, next_manifests::AssetBinding};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use turbo_tasks::{trace::TraceRawVcs, RcStr, TryFlatJoinIterExt, Vc}; use turbo_tasks::{trace::TraceRawVcs, RcStr, ResolvedVc, TryFlatJoinIterExt, Vc};
use turbo_tasks_fs::FileSystemPath; use turbo_tasks_fs::FileSystemPath;
use turbopack_core::{ use turbopack_core::{
asset::{Asset, AssetContent}, asset::{Asset, AssetContent},
...@@ -71,24 +71,22 @@ pub async fn all_paths_in_root( ...@@ -71,24 +71,22 @@ pub async fn all_paths_in_root(
pub(crate) async fn get_paths_from_root( pub(crate) async fn get_paths_from_root(
root: &FileSystemPath, root: &FileSystemPath,
output_assets: &[Vc<Box<dyn OutputAsset>>], output_assets: &[ResolvedVc<Box<dyn OutputAsset>>],
filter: impl FnOnce(&str) -> bool + Copy, filter: impl FnOnce(&str) -> bool + Copy,
) -> Result<Vec<RcStr>> { ) -> Result<Vec<RcStr>> {
output_assets output_assets
.iter() .iter()
.map({ .map(move |&file| async move {
move |&file| async move { let path = &*file.ident().path().await?;
let path = &*file.ident().path().await?; let Some(relative) = root.get_path_to(path) else {
let Some(relative) = root.get_path_to(path) else { return Ok(None);
return Ok(None); };
};
Ok(if filter(relative) {
Ok(if filter(relative) { Some(relative.into())
Some(relative.into()) } else {
} else { None
None })
})
}
}) })
.try_flat_join() .try_flat_join()
.await .await
...@@ -96,21 +94,21 @@ pub(crate) async fn get_paths_from_root( ...@@ -96,21 +94,21 @@ pub(crate) async fn get_paths_from_root(
pub(crate) async fn get_js_paths_from_root( pub(crate) async fn get_js_paths_from_root(
root: &FileSystemPath, root: &FileSystemPath,
output_assets: &[Vc<Box<dyn OutputAsset>>], output_assets: &[ResolvedVc<Box<dyn OutputAsset>>],
) -> Result<Vec<RcStr>> { ) -> Result<Vec<RcStr>> {
get_paths_from_root(root, output_assets, |path| path.ends_with(".js")).await get_paths_from_root(root, output_assets, |path| path.ends_with(".js")).await
} }
pub(crate) async fn get_wasm_paths_from_root( pub(crate) async fn get_wasm_paths_from_root(
root: &FileSystemPath, root: &FileSystemPath,
output_assets: &[Vc<Box<dyn OutputAsset>>], output_assets: &[ResolvedVc<Box<dyn OutputAsset>>],
) -> Result<Vec<RcStr>> { ) -> Result<Vec<RcStr>> {
get_paths_from_root(root, output_assets, |path| path.ends_with(".wasm")).await get_paths_from_root(root, output_assets, |path| path.ends_with(".wasm")).await
} }
pub(crate) async fn get_font_paths_from_root( pub(crate) async fn get_font_paths_from_root(
root: &FileSystemPath, root: &FileSystemPath,
output_assets: &[Vc<Box<dyn OutputAsset>>], output_assets: &[ResolvedVc<Box<dyn OutputAsset>>],
) -> Result<Vec<RcStr>> { ) -> Result<Vec<RcStr>> {
get_paths_from_root(root, output_assets, |path| { get_paths_from_root(root, output_assets, |path| {
path.ends_with(".woff") path.ends_with(".woff")
......
...@@ -27,8 +27,8 @@ use turbo_tasks::{ ...@@ -27,8 +27,8 @@ use turbo_tasks::{
fxindexmap, fxindexmap,
graph::{AdjacencyMap, GraphTraversal}, graph::{AdjacencyMap, GraphTraversal},
trace::TraceRawVcs, trace::TraceRawVcs,
Completion, Completions, FxIndexMap, IntoTraitRef, RcStr, ReadRef, State, TaskInput, Completion, Completions, FxIndexMap, IntoTraitRef, RcStr, ReadRef, ResolvedVc, State,
TransientInstance, TryFlatJoinIterExt, Value, Vc, TaskInput, TransientInstance, TryFlatJoinIterExt, Value, Vc,
}; };
use turbo_tasks_env::{EnvMap, ProcessEnv}; use turbo_tasks_env::{EnvMap, ProcessEnv};
use turbo_tasks_fs::{DiskFileSystem, FileSystem, FileSystemPath, VirtualFileSystem}; use turbo_tasks_fs::{DiskFileSystem, FileSystem, FileSystemPath, VirtualFileSystem};
...@@ -1324,7 +1324,7 @@ async fn any_output_changed( ...@@ -1324,7 +1324,7 @@ async fn any_output_changed(
&& (!server || !asset_path.path.ends_with(".css")) && (!server || !asset_path.path.ends_with(".css"))
&& asset_path.is_inside_ref(path) && asset_path.is_inside_ref(path)
{ {
Ok(Some(content_changed(Vc::upcast(m)))) Ok(Some(content_changed(*ResolvedVc::upcast(m))))
} else { } else {
Ok(None) Ok(None)
} }
...@@ -1336,8 +1336,8 @@ async fn any_output_changed( ...@@ -1336,8 +1336,8 @@ async fn any_output_changed(
} }
async fn get_referenced_output_assets( async fn get_referenced_output_assets(
parent: Vc<Box<dyn OutputAsset>>, parent: ResolvedVc<Box<dyn OutputAsset>>,
) -> Result<impl Iterator<Item = Vc<Box<dyn OutputAsset>>> + Send> { ) -> Result<impl Iterator<Item = ResolvedVc<Box<dyn OutputAsset>>> + Send> {
Ok(parent.references().await?.clone_value().into_iter()) Ok(parent.references().await?.clone_value().into_iter())
} }
......
...@@ -43,7 +43,7 @@ use turbopack_ecmascript::{ ...@@ -43,7 +43,7 @@ use turbopack_ecmascript::{
#[turbo_tasks::value] #[turbo_tasks::value]
pub(crate) struct ServerActionsManifest { pub(crate) struct ServerActionsManifest {
pub loader: Vc<Box<dyn EvaluatableAsset>>, pub loader: Vc<Box<dyn EvaluatableAsset>>,
pub manifest: Vc<Box<dyn OutputAsset>>, pub manifest: ResolvedVc<Box<dyn OutputAsset>>,
} }
/// Scans the RSC entry point's full module graph looking for exported Server /// Scans the RSC entry point's full module graph looking for exported Server
...@@ -141,7 +141,7 @@ async fn build_manifest( ...@@ -141,7 +141,7 @@ async fn build_manifest(
runtime: NextRuntime, runtime: NextRuntime,
actions: Vc<AllActions>, actions: Vc<AllActions>,
chunk_item: Vc<Box<dyn ChunkItem>>, chunk_item: Vc<Box<dyn ChunkItem>>,
) -> Result<Vc<Box<dyn OutputAsset>>> { ) -> Result<ResolvedVc<Box<dyn OutputAsset>>> {
let manifest_path_prefix = &page_name; let manifest_path_prefix = &page_name;
let manifest_path = node_root let manifest_path = node_root
.join(format!("server/app{manifest_path_prefix}/server-reference-manifest.json",).into()); .join(format!("server/app{manifest_path_prefix}/server-reference-manifest.json",).into());
...@@ -170,10 +170,14 @@ async fn build_manifest( ...@@ -170,10 +170,14 @@ async fn build_manifest(
entry.layer.insert(&key, *layer); entry.layer.insert(&key, *layer);
} }
Ok(Vc::upcast(VirtualOutputAsset::new( Ok(ResolvedVc::upcast(
manifest_path, VirtualOutputAsset::new(
AssetContent::file(File::from(serde_json::to_string_pretty(&manifest)?).into()), manifest_path,
))) AssetContent::file(File::from(serde_json::to_string_pretty(&manifest)?).into()),
)
.to_resolved()
.await?,
))
} }
/// Traverses the entire module graph starting from [Module], looking for magic /// Traverses the entire module graph starting from [Module], looking for magic
......
...@@ -4,7 +4,7 @@ use anyhow::{bail, Result}; ...@@ -4,7 +4,7 @@ use anyhow::{bail, Result};
use next_core::emit_assets; use next_core::emit_assets;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use turbo_tasks::{ use turbo_tasks::{
debug::ValueDebugFormat, trace::TraceRawVcs, Completion, FxIndexSet, RcStr, State, debug::ValueDebugFormat, trace::TraceRawVcs, Completion, FxIndexSet, RcStr, ResolvedVc, State,
TryFlatJoinIterExt, TryJoinIterExt, ValueDefault, ValueToString, Vc, TryFlatJoinIterExt, TryJoinIterExt, ValueDefault, ValueToString, Vc,
}; };
use turbo_tasks_fs::FileSystemPath; use turbo_tasks_fs::FileSystemPath;
...@@ -26,13 +26,13 @@ struct MapEntry { ...@@ -26,13 +26,13 @@ struct MapEntry {
assets_operation: Vc<OutputAssets>, assets_operation: Vc<OutputAssets>,
side_effects: Vc<Completion>, side_effects: Vc<Completion>,
/// Precomputed map for quick access to output asset by filepath /// Precomputed map for quick access to output asset by filepath
path_to_asset: HashMap<Vc<FileSystemPath>, Vc<Box<dyn OutputAsset>>>, path_to_asset: HashMap<ResolvedVc<FileSystemPath>, Vc<Box<dyn OutputAsset>>>,
} }
#[turbo_tasks::value(transparent)] #[turbo_tasks::value(transparent)]
struct OptionMapEntry(Option<MapEntry>); struct OptionMapEntry(Option<MapEntry>);
type PathToOutputOperation = HashMap<Vc<FileSystemPath>, FxIndexSet<Vc<OutputAssets>>>; type PathToOutputOperation = HashMap<ResolvedVc<FileSystemPath>, FxIndexSet<Vc<OutputAssets>>>;
// A precomputed map for quick access to output asset by filepath // A precomputed map for quick access to output asset by filepath
type OutputOperationToComputeEntry = HashMap<Vc<OutputAssets>, Vc<OptionMapEntry>>; type OutputOperationToComputeEntry = HashMap<Vc<OutputAssets>, Vc<OptionMapEntry>>;
...@@ -90,7 +90,7 @@ impl VersionedContentMap { ...@@ -90,7 +90,7 @@ impl VersionedContentMap {
Ok(entry.side_effects) Ok(entry.side_effects)
} }
/// Creates a ComputEntry (a pre-computed map for optimized lookup) for an output assets /// Creates a [`MapEntry`] (a pre-computed map for optimized lookup) for an output assets
/// operation. When assets change, map_path_to_op is updated. /// operation. When assets change, map_path_to_op is updated.
#[turbo_tasks::function] #[turbo_tasks::function]
async fn compute_entry( async fn compute_entry(
...@@ -103,13 +103,13 @@ impl VersionedContentMap { ...@@ -103,13 +103,13 @@ impl VersionedContentMap {
let assets = *assets_operation.await?; let assets = *assets_operation.await?;
async fn get_entries( async fn get_entries(
assets: Vc<OutputAssets>, assets: Vc<OutputAssets>,
) -> Result<Vec<(Vc<FileSystemPath>, Vc<Box<dyn OutputAsset>>)>> { ) -> Result<Vec<(ResolvedVc<FileSystemPath>, Vc<Box<dyn OutputAsset>>)>> {
let assets_ref = assets.await?; let assets_ref = assets.await?;
let entries = assets_ref let entries = assets_ref
.iter() .iter()
.map(|&asset| async move { .map(|&asset| async move {
let path = asset.ident().path().resolve().await?; let path = asset.ident().path().to_resolved().await?;
Ok((path, asset)) Ok((path, *asset))
}) })
.try_join() .try_join()
.await?; .await?;
...@@ -189,9 +189,9 @@ impl VersionedContentMap { ...@@ -189,9 +189,9 @@ impl VersionedContentMap {
#[turbo_tasks::function] #[turbo_tasks::function]
pub async fn get_asset( pub async fn get_asset(
self: Vc<Self>, self: Vc<Self>,
path: Vc<FileSystemPath>, path: ResolvedVc<FileSystemPath>,
) -> Result<Vc<OptionOutputAsset>> { ) -> Result<Vc<OptionOutputAsset>> {
let result = self.raw_get(path).await?; let result = self.raw_get(*path).await?;
if let Some(MapEntry { if let Some(MapEntry {
assets_operation: _, assets_operation: _,
side_effects, side_effects,
...@@ -230,7 +230,7 @@ impl VersionedContentMap { ...@@ -230,7 +230,7 @@ impl VersionedContentMap {
} }
#[turbo_tasks::function] #[turbo_tasks::function]
fn raw_get(&self, path: Vc<FileSystemPath>) -> Vc<OptionMapEntry> { fn raw_get(&self, path: ResolvedVc<FileSystemPath>) -> Vc<OptionMapEntry> {
let assets = { let assets = {
let map = self.map_path_to_op.get(); let map = self.map_path_to_op.get();
map.get(&path).and_then(|m| m.iter().last().copied()) map.get(&path).and_then(|m| m.iter().last().copied())
......
use anyhow::Result; use anyhow::Result;
use serde::Serialize; use serde::Serialize;
use turbo_tasks::{FxIndexMap, FxIndexSet, RcStr, Vc}; use turbo_tasks::{FxIndexMap, FxIndexSet, RcStr, ResolvedVc, Vc};
use turbopack_browser::ecmascript::EcmascriptDevChunk; use turbopack_browser::ecmascript::EcmascriptDevChunk;
use turbopack_core::{ use turbopack_core::{
chunk::{Chunk, ChunkItem}, chunk::{Chunk, ChunkItem},
...@@ -12,7 +12,7 @@ pub async fn generate_webpack_stats<'a, I>( ...@@ -12,7 +12,7 @@ pub async fn generate_webpack_stats<'a, I>(
entry_assets: I, entry_assets: I,
) -> Result<WebpackStats> ) -> Result<WebpackStats>
where where
I: IntoIterator<Item = &'a Vc<Box<dyn OutputAsset>>>, I: IntoIterator<Item = &'a ResolvedVc<Box<dyn OutputAsset>>>,
{ {
let mut assets = vec![]; let mut assets = vec![];
let mut chunks = vec![]; let mut chunks = vec![];
...@@ -26,7 +26,7 @@ where ...@@ -26,7 +26,7 @@ where
continue; continue;
}; };
if let Some(chunk) = Vc::try_resolve_downcast_type::<EcmascriptDevChunk>(*asset).await? { if let Some(chunk) = ResolvedVc::try_downcast_type::<EcmascriptDevChunk>(*asset).await? {
let chunk_ident = normalize_client_path(&chunk.ident().path().await?.path); let chunk_ident = normalize_client_path(&chunk.ident().path().await?.path);
chunks.push(WebpackStatsChunk { chunks.push(WebpackStatsChunk {
size: asset_len, size: asset_len,
......
...@@ -2,7 +2,7 @@ use anyhow::Result; ...@@ -2,7 +2,7 @@ use anyhow::Result;
use tracing::Instrument; use tracing::Instrument;
use turbo_tasks::{ use turbo_tasks::{
graph::{AdjacencyMap, GraphTraversal}, graph::{AdjacencyMap, GraphTraversal},
Completion, Completions, TryFlatJoinIterExt, ValueToString, Vc, Completion, Completions, ResolvedVc, TryFlatJoinIterExt, ValueToString, Vc,
}; };
use turbo_tasks_fs::{rebase, FileSystemPath}; use turbo_tasks_fs::{rebase, FileSystemPath};
use turbopack_core::{ use turbopack_core::{
...@@ -108,8 +108,8 @@ pub async fn all_assets_from_entries(entries: Vc<OutputAssets>) -> Result<Vc<Out ...@@ -108,8 +108,8 @@ pub async fn all_assets_from_entries(entries: Vc<OutputAssets>) -> Result<Vc<Out
/// Computes the list of all chunk children of a given chunk. /// Computes the list of all chunk children of a given chunk.
async fn get_referenced_assets( async fn get_referenced_assets(
asset: Vc<Box<dyn OutputAsset>>, asset: ResolvedVc<Box<dyn OutputAsset>>,
) -> Result<impl Iterator<Item = Vc<Box<dyn OutputAsset>>> + Send> { ) -> Result<impl Iterator<Item = ResolvedVc<Box<dyn OutputAsset>>> + Send> {
Ok(asset Ok(asset
.references() .references()
.await? .await?
......
use std::io::Write; use std::io::Write;
use anyhow::Result; use anyhow::Result;
use turbo_tasks::{RcStr, ValueToString, Vc}; use turbo_tasks::{RcStr, ResolvedVc, ValueToString, Vc};
use turbo_tasks_fs::{glob::Glob, rope::RopeBuilder}; use turbo_tasks_fs::{glob::Glob, rope::RopeBuilder};
use turbopack_core::{ use turbopack_core::{
asset::{Asset, AssetContent}, asset::{Asset, AssetContent},
...@@ -99,13 +99,13 @@ impl EvaluatableAsset for HmrEntryModule {} ...@@ -99,13 +99,13 @@ impl EvaluatableAsset for HmrEntryModule {}
#[turbo_tasks::value] #[turbo_tasks::value]
pub struct HmrEntryModuleReference { pub struct HmrEntryModuleReference {
pub module: Vc<Box<dyn Module>>, pub module: ResolvedVc<Box<dyn Module>>,
} }
#[turbo_tasks::value_impl] #[turbo_tasks::value_impl]
impl HmrEntryModuleReference { impl HmrEntryModuleReference {
#[turbo_tasks::function] #[turbo_tasks::function]
pub fn new(module: Vc<Box<dyn Module>>) -> Vc<Self> { pub fn new(module: ResolvedVc<Box<dyn Module>>) -> Vc<Self> {
HmrEntryModuleReference { module }.cell() HmrEntryModuleReference { module }.cell()
} }
} }
......
...@@ -143,13 +143,13 @@ impl EcmascriptChunkItem for IncludeModulesChunkItem { ...@@ -143,13 +143,13 @@ impl EcmascriptChunkItem for IncludeModulesChunkItem {
/// [`IncludeModulesModule`]. /// [`IncludeModulesModule`].
#[turbo_tasks::value] #[turbo_tasks::value]
pub struct IncludedModuleReference { pub struct IncludedModuleReference {
pub module: Vc<Box<dyn Module>>, pub module: ResolvedVc<Box<dyn Module>>,
} }
#[turbo_tasks::value_impl] #[turbo_tasks::value_impl]
impl IncludedModuleReference { impl IncludedModuleReference {
#[turbo_tasks::function] #[turbo_tasks::function]
pub fn new(module: Vc<Box<dyn Module>>) -> Vc<Self> { pub fn new(module: ResolvedVc<Box<dyn Module>>) -> Vc<Self> {
IncludedModuleReference { module }.cell() IncludedModuleReference { module }.cell()
} }
} }
......
use anyhow::{bail, Result}; use anyhow::{bail, Result};
use turbo_tasks::{RcStr, Value, Vc}; use turbo_tasks::{RcStr, ResolvedVc, Value, Vc};
use turbopack::{ use turbopack::{
transition::{ContextTransition, Transition}, transition::{ContextTransition, Transition},
ModuleAssetContext, ModuleAssetContext,
...@@ -101,13 +101,13 @@ impl Transition for NextEcmascriptClientReferenceTransition { ...@@ -101,13 +101,13 @@ impl Transition for NextEcmascriptClientReferenceTransition {
}; };
let Some(client_module) = let Some(client_module) =
Vc::try_resolve_sidecast::<Box<dyn EcmascriptChunkPlaceable>>(client_module).await? ResolvedVc::try_sidecast::<Box<dyn EcmascriptChunkPlaceable>>(client_module).await?
else { else {
bail!("client asset is not ecmascript chunk placeable"); bail!("client asset is not ecmascript chunk placeable");
}; };
let Some(ssr_module) = let Some(ssr_module) =
Vc::try_resolve_sidecast::<Box<dyn EcmascriptChunkPlaceable>>(ssr_module).await? ResolvedVc::try_sidecast::<Box<dyn EcmascriptChunkPlaceable>>(ssr_module).await?
else { else {
bail!("SSR asset is not ecmascript chunk placeable"); bail!("SSR asset is not ecmascript chunk placeable");
}; };
...@@ -123,14 +123,16 @@ impl Transition for NextEcmascriptClientReferenceTransition { ...@@ -123,14 +123,16 @@ impl Transition for NextEcmascriptClientReferenceTransition {
module_asset_context.layer, module_asset_context.layer,
); );
Ok( Ok(ProcessResult::Module(ResolvedVc::upcast(
ProcessResult::Module(Vc::upcast(EcmascriptClientReferenceProxyModule::new( EcmascriptClientReferenceProxyModule::new(
ident, ident,
Vc::upcast(server_context), Vc::upcast(server_context),
client_module, *client_module,
ssr_module, *ssr_module,
))) )
.cell(), .to_resolved()
) .await?,
))
.cell())
} }
} }
use anyhow::Result; use anyhow::Result;
use turbo_tasks::{RcStr, Value, Vc}; use turbo_tasks::{RcStr, ResolvedVc, Value, Vc};
use turbopack::{transition::Transition, ModuleAssetContext}; use turbopack::{transition::Transition, ModuleAssetContext};
use turbopack_core::{context::ProcessResult, reference_type::ReferenceType, source::Source}; use turbopack_core::{context::ProcessResult, reference_type::ReferenceType, source::Source};
...@@ -50,9 +50,11 @@ impl Transition for NextDynamicTransition { ...@@ -50,9 +50,11 @@ impl Transition for NextDynamicTransition {
) )
.await? .await?
{ {
ProcessResult::Module(client_module) => { ProcessResult::Module(client_module) => ProcessResult::Module(ResolvedVc::upcast(
ProcessResult::Module(Vc::upcast(NextDynamicEntryModule::new(client_module))) NextDynamicEntryModule::new(*client_module)
} .to_resolved()
.await?,
)),
ProcessResult::Ignore => ProcessResult::Ignore, ProcessResult::Ignore => ProcessResult::Ignore,
} }
.cell()) .cell())
......
use anyhow::Result; use anyhow::Result;
use turbo_tasks::{RcStr, ValueToString, Vc}; use turbo_tasks::{RcStr, ResolvedVc, ValueToString, Vc};
use turbopack_core::{ use turbopack_core::{
chunk::ChunkableModuleReference, module::Module, reference::ModuleReference, chunk::ChunkableModuleReference, module::Module, reference::ModuleReference,
resolve::ModuleResolveResult, resolve::ModuleResolveResult,
...@@ -7,13 +7,13 @@ use turbopack_core::{ ...@@ -7,13 +7,13 @@ use turbopack_core::{
#[turbo_tasks::value] #[turbo_tasks::value]
pub struct NextServerComponentModuleReference { pub struct NextServerComponentModuleReference {
asset: Vc<Box<dyn Module>>, asset: ResolvedVc<Box<dyn Module>>,
} }
#[turbo_tasks::value_impl] #[turbo_tasks::value_impl]
impl NextServerComponentModuleReference { impl NextServerComponentModuleReference {
#[turbo_tasks::function] #[turbo_tasks::function]
pub fn new(asset: Vc<Box<dyn Module>>) -> Vc<Self> { pub fn new(asset: ResolvedVc<Box<dyn Module>>) -> Vc<Self> {
NextServerComponentModuleReference { asset }.cell() NextServerComponentModuleReference { asset }.cell()
} }
} }
......
...@@ -109,13 +109,15 @@ impl PageLoaderAsset { ...@@ -109,13 +109,15 @@ impl PageLoaderAsset {
let rebased = chunks let rebased = chunks
.await? .await?
.iter() .iter()
.map(|chunk| { .map(|&chunk| {
Vc::upcast(ProxiedAsset::new( Vc::upcast::<Box<dyn OutputAsset>>(ProxiedAsset::new(
*chunk, *chunk,
FileSystemPath::rebase(chunk.ident().path(), **rebase_path, root_path), FileSystemPath::rebase(chunk.ident().path(), **rebase_path, root_path),
)) ))
.to_resolved()
}) })
.collect(); .try_join()
.await?;
chunks = Vc::cell(rebased); chunks = Vc::cell(rebased);
}; };
......
use anyhow::{bail, Context, Result}; use anyhow::{bail, Context, Result};
use tracing::Instrument; use tracing::Instrument;
use turbo_tasks::{RcStr, Value, ValueToString, Vc}; use turbo_tasks::{RcStr, ResolvedVc, TryJoinIterExt, Value, ValueToString, Vc};
use turbo_tasks_fs::FileSystemPath; use turbo_tasks_fs::FileSystemPath;
use turbopack_core::{ use turbopack_core::{
chunk::{ chunk::{
...@@ -384,10 +384,11 @@ impl ChunkingContext for BrowserChunkingContext { ...@@ -384,10 +384,11 @@ impl ChunkingContext for BrowserChunkingContext {
) )
.await?; .await?;
let mut assets: Vec<Vc<Box<dyn OutputAsset>>> = chunks let mut assets = chunks
.iter() .iter()
.map(|chunk| self.generate_chunk(**chunk)) .map(|chunk| self.generate_chunk(**chunk).to_resolved())
.collect(); .try_join()
.await?;
if this.enable_hot_module_replacement { if this.enable_hot_module_replacement {
let mut ident = ident; let mut ident = ident;
...@@ -404,17 +405,16 @@ impl ChunkingContext for BrowserChunkingContext { ...@@ -404,17 +405,16 @@ impl ChunkingContext for BrowserChunkingContext {
)); ));
} }
} }
assets.push(self.generate_chunk_list_register_chunk( assets.push(
ident, self.generate_chunk_list_register_chunk(
EvaluatableAssets::empty(), ident,
Vc::cell(assets.clone()), EvaluatableAssets::empty(),
Value::new(EcmascriptDevChunkListSource::Dynamic), Vc::cell(assets.clone()),
)); Value::new(EcmascriptDevChunkListSource::Dynamic),
} )
.to_resolved()
// Resolve assets .await?,
for asset in assets.iter_mut() { );
*asset = asset.resolve().await?;
} }
Ok(ChunkGroupResult { Ok(ChunkGroupResult {
...@@ -453,28 +453,32 @@ impl ChunkingContext for BrowserChunkingContext { ...@@ -453,28 +453,32 @@ impl ChunkingContext for BrowserChunkingContext {
availability_info, availability_info,
} = make_chunk_group(Vc::upcast(self), entries, availability_info).await?; } = make_chunk_group(Vc::upcast(self), entries, availability_info).await?;
let mut assets: Vec<Vc<Box<dyn OutputAsset>>> = chunks let mut assets: Vec<ResolvedVc<Box<dyn OutputAsset>>> = chunks
.iter() .iter()
.map(|chunk| self.generate_chunk(**chunk)) .map(|chunk| self.generate_chunk(**chunk).to_resolved())
.collect(); .try_join()
.await?;
let other_assets = Vc::cell(assets.clone()); let other_assets = Vc::cell(assets.clone());
if this.enable_hot_module_replacement { if this.enable_hot_module_replacement {
assets.push(self.generate_chunk_list_register_chunk( assets.push(
ident, self.generate_chunk_list_register_chunk(
evaluatable_assets, ident,
other_assets, evaluatable_assets,
Value::new(EcmascriptDevChunkListSource::Entry), other_assets,
)); Value::new(EcmascriptDevChunkListSource::Entry),
)
.to_resolved()
.await?,
);
} }
assets.push(self.generate_evaluate_chunk(ident, other_assets, evaluatable_assets)); assets.push(
self.generate_evaluate_chunk(ident, other_assets, evaluatable_assets)
// Resolve assets .to_resolved()
for asset in assets.iter_mut() { .await?,
*asset = asset.resolve().await?; );
}
Ok(ChunkGroupResult { Ok(ChunkGroupResult {
assets: Vc::cell(assets), assets: Vc::cell(assets),
......
use anyhow::Result; use anyhow::Result;
use turbo_tasks::{FxIndexSet, RcStr, ValueToString, Vc}; use turbo_tasks::{FxIndexSet, RcStr, ResolvedVc, ValueToString, Vc};
use turbopack_core::{ use turbopack_core::{
asset::{Asset, AssetContent}, asset::{Asset, AssetContent},
chunk::{Chunk, ChunkingContext, OutputChunk, OutputChunkRuntimeInfo}, chunk::{Chunk, ChunkingContext, OutputChunk, OutputChunkRuntimeInfo},
...@@ -106,7 +106,9 @@ impl OutputAsset for EcmascriptDevChunk { ...@@ -106,7 +106,9 @@ impl OutputAsset for EcmascriptDevChunk {
references.extend(chunk_references.iter().copied()); references.extend(chunk_references.iter().copied());
if include_source_map { if include_source_map {
references.push(Vc::upcast(SourceMapAsset::new(Vc::upcast(self)))); references.push(ResolvedVc::upcast(
SourceMapAsset::new(Vc::upcast(self)).to_resolved().await?,
));
} }
Ok(Vc::cell(references)) Ok(Vc::cell(references))
......
...@@ -3,7 +3,7 @@ use std::io::Write; ...@@ -3,7 +3,7 @@ use std::io::Write;
use anyhow::{bail, Result}; use anyhow::{bail, Result};
use indoc::writedoc; use indoc::writedoc;
use serde::Serialize; use serde::Serialize;
use turbo_tasks::{RcStr, ReadRef, TryJoinIterExt, Value, ValueToString, Vc}; use turbo_tasks::{RcStr, ReadRef, ResolvedVc, TryJoinIterExt, Value, ValueToString, Vc};
use turbo_tasks_fs::File; use turbo_tasks_fs::File;
use turbopack_core::{ use turbopack_core::{
asset::{Asset, AssetContent}, asset::{Asset, AssetContent},
...@@ -234,7 +234,9 @@ impl OutputAsset for EcmascriptDevEvaluateChunk { ...@@ -234,7 +234,9 @@ impl OutputAsset for EcmascriptDevEvaluateChunk {
.await?; .await?;
if include_source_map { if include_source_map {
references.push(Vc::upcast(SourceMapAsset::new(Vc::upcast(self)))); references.push(ResolvedVc::upcast(
SourceMapAsset::new(Vc::upcast(self)).to_resolved().await?,
));
} }
for chunk_data in &*self.chunks_data().await? { for chunk_data in &*self.chunks_data().await? {
......
...@@ -305,7 +305,7 @@ async fn build_internal( ...@@ -305,7 +305,7 @@ async fn build_internal(
.try_join() .try_join()
.await?; .await?;
let mut chunks: HashSet<Vc<Box<dyn OutputAsset>>> = HashSet::new(); let mut chunks: HashSet<ResolvedVc<Box<dyn OutputAsset>>> = HashSet::new();
for chunk_group in entry_chunk_groups { for chunk_group in entry_chunk_groups {
chunks.extend(&*all_assets_from_entries(chunk_group).await?); chunks.extend(&*all_assets_from_entries(chunk_group).await?);
} }
......
...@@ -12,8 +12,8 @@ use crate::{ ...@@ -12,8 +12,8 @@ use crate::{
}; };
async fn get_referenced_output_assets( async fn get_referenced_output_assets(
parent: Vc<Box<dyn OutputAsset>>, parent: ResolvedVc<Box<dyn OutputAsset>>,
) -> Result<impl Iterator<Item = Vc<Box<dyn OutputAsset>>> + Send> { ) -> Result<impl Iterator<Item = ResolvedVc<Box<dyn OutputAsset>>> + Send> {
Ok(parent.references().await?.clone_value().into_iter()) Ok(parent.references().await?.clone_value().into_iter())
} }
...@@ -49,7 +49,7 @@ pub async fn any_content_changed_of_module( ...@@ -49,7 +49,7 @@ pub async fn any_content_changed_of_module(
/// asset graph changes. /// asset graph changes.
#[turbo_tasks::function] #[turbo_tasks::function]
pub async fn any_content_changed_of_output_asset( pub async fn any_content_changed_of_output_asset(
root: Vc<Box<dyn OutputAsset>>, root: ResolvedVc<Box<dyn OutputAsset>>,
) -> Result<Vc<Completion>> { ) -> Result<Vc<Completion>> {
let completions = NonDeterministic::new() let completions = NonDeterministic::new()
.skip_duplicates() .skip_duplicates()
...@@ -58,7 +58,7 @@ pub async fn any_content_changed_of_output_asset( ...@@ -58,7 +58,7 @@ pub async fn any_content_changed_of_output_asset(
.completed()? .completed()?
.into_inner() .into_inner()
.into_iter() .into_iter()
.map(|m| content_changed(Vc::upcast(m))) .map(|m| content_changed(*ResolvedVc::upcast(m)))
.collect(); .collect();
Ok(Vc::<Completions>::cell(completions).completed()) Ok(Vc::<Completions>::cell(completions).completed())
...@@ -74,7 +74,7 @@ pub async fn any_content_changed_of_output_assets( ...@@ -74,7 +74,7 @@ pub async fn any_content_changed_of_output_assets(
roots roots
.await? .await?
.iter() .iter()
.map(|&a| any_content_changed_of_output_asset(a)) .map(|&a| any_content_changed_of_output_asset(*a))
.collect(), .collect(),
) )
.completed()) .completed())
......
...@@ -195,6 +195,7 @@ async fn references_to_output_assets( ...@@ -195,6 +195,7 @@ async fn references_to_output_assets(
.flatten() .flatten()
.copied() .copied()
.filter(|&asset| set.insert(asset)) .filter(|&asset| set.insert(asset))
.map(|asset| *asset)
.collect::<Vec<_>>(); .collect::<Vec<_>>();
Ok(OutputAssets::new(output_assets)) Ok(OutputAssets::new(output_assets))
} }
use anyhow::Result; use anyhow::Result;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use turbo_tasks::{trace::TraceRawVcs, RcStr, TaskInput, Upcast, Value, Vc}; use turbo_tasks::{trace::TraceRawVcs, RcStr, ResolvedVc, TaskInput, Upcast, Value, Vc};
use turbo_tasks_fs::FileSystemPath; use turbo_tasks_fs::FileSystemPath;
use turbo_tasks_hash::DeterministicHash; use turbo_tasks_hash::DeterministicHash;
...@@ -43,7 +43,7 @@ pub struct ChunkGroupResult { ...@@ -43,7 +43,7 @@ pub struct ChunkGroupResult {
#[turbo_tasks::value(shared)] #[turbo_tasks::value(shared)]
pub struct EntryChunkGroupResult { pub struct EntryChunkGroupResult {
pub asset: Vc<Box<dyn OutputAsset>>, pub asset: ResolvedVc<Box<dyn OutputAsset>>,
pub availability_info: AvailabilityInfo, pub availability_info: AvailabilityInfo,
} }
...@@ -311,7 +311,7 @@ async fn entry_chunk_group_asset( ...@@ -311,7 +311,7 @@ async fn entry_chunk_group_asset(
extra_chunks: Vc<OutputAssets>, extra_chunks: Vc<OutputAssets>,
availability_info: Value<AvailabilityInfo>, availability_info: Value<AvailabilityInfo>,
) -> Result<Vc<Box<dyn OutputAsset>>> { ) -> Result<Vc<Box<dyn OutputAsset>>> {
Ok(chunking_context Ok(*chunking_context
.entry_chunk_group( .entry_chunk_group(
path, path,
module, module,
......
...@@ -126,7 +126,7 @@ impl ChunkData { ...@@ -126,7 +126,7 @@ impl ChunkData {
chunks chunks
.await? .await?
.iter() .iter()
.map(|&chunk| ChunkData::from_asset(output_root, chunk)) .map(|&chunk| ChunkData::from_asset(output_root, *chunk))
.try_join() .try_join()
.await? .await?
.into_iter() .into_iter()
......
use anyhow::{bail, Result}; use anyhow::{bail, Result};
use turbo_tasks::{RcStr, Value, Vc}; use turbo_tasks::{RcStr, ResolvedVc, Value, Vc};
use turbo_tasks_fs::{glob::Glob, FileSystemPath}; use turbo_tasks_fs::{glob::Glob, FileSystemPath};
use crate::{ use crate::{
...@@ -13,7 +13,7 @@ use crate::{ ...@@ -13,7 +13,7 @@ use crate::{
#[turbo_tasks::value(shared)] #[turbo_tasks::value(shared)]
pub enum ProcessResult { pub enum ProcessResult {
/// A module was created. /// A module was created.
Module(Vc<Box<dyn Module>>), Module(ResolvedVc<Box<dyn Module>>),
/// Reference is ignored. This should lead to no module being included by /// Reference is ignored. This should lead to no module being included by
/// the reference. /// the reference.
...@@ -25,7 +25,7 @@ impl ProcessResult { ...@@ -25,7 +25,7 @@ impl ProcessResult {
#[turbo_tasks::function] #[turbo_tasks::function]
pub async fn module(&self) -> Result<Vc<Box<dyn Module>>> { pub async fn module(&self) -> Result<Vc<Box<dyn Module>>> {
match *self { match *self {
ProcessResult::Module(m) => Ok(m), ProcessResult::Module(m) => Ok(*m),
ProcessResult::Ignore => { ProcessResult::Ignore => {
bail!("Expected process result to be a module, but it was ignored") bail!("Expected process result to be a module, but it was ignored")
} }
......
use anyhow::Result; use anyhow::Result;
use turbo_tasks::{FxIndexSet, RcStr, Vc}; use turbo_tasks::{FxIndexSet, RcStr, ResolvedVc, Vc};
use turbo_tasks_fs::FileContent; use turbo_tasks_fs::FileContent;
use super::{ use super::{
...@@ -95,7 +95,7 @@ pub async fn children_from_module_references( ...@@ -95,7 +95,7 @@ pub async fn children_from_module_references(
.await? .await?
.iter() .iter()
{ {
children.insert((key, IntrospectableOutputAsset::new(output_asset))); children.insert((key, IntrospectableOutputAsset::new(*output_asset)));
} }
} }
Ok(Vc::cell(children)) Ok(Vc::cell(children))
...@@ -109,7 +109,10 @@ pub async fn children_from_output_assets( ...@@ -109,7 +109,10 @@ pub async fn children_from_output_assets(
let mut children = FxIndexSet::default(); let mut children = FxIndexSet::default();
let references = references.await?; let references = references.await?;
for &reference in &*references { for &reference in &*references {
children.insert((key, IntrospectableOutputAsset::new(Vc::upcast(reference)))); children.insert((
key,
IntrospectableOutputAsset::new(*ResolvedVc::upcast(reference)),
));
} }
Ok(Vc::cell(children)) Ok(Vc::cell(children))
} }
...@@ -26,12 +26,12 @@ pub trait OutputAsset: Asset { ...@@ -26,12 +26,12 @@ pub trait OutputAsset: Asset {
} }
#[turbo_tasks::value(transparent)] #[turbo_tasks::value(transparent)]
pub struct OutputAssets(Vec<Vc<Box<dyn OutputAsset>>>); pub struct OutputAssets(Vec<ResolvedVc<Box<dyn OutputAsset>>>);
#[turbo_tasks::value_impl] #[turbo_tasks::value_impl]
impl OutputAssets { impl OutputAssets {
#[turbo_tasks::function] #[turbo_tasks::function]
pub fn new(assets: Vec<Vc<Box<dyn OutputAsset>>>) -> Vc<Self> { pub fn new(assets: Vec<ResolvedVc<Box<dyn OutputAsset>>>) -> Vc<Self> {
Vc::cell(assets) Vc::cell(assets)
} }
...@@ -51,7 +51,7 @@ impl OutputAssets { ...@@ -51,7 +51,7 @@ impl OutputAssets {
/// A set of [OutputAsset]s /// A set of [OutputAsset]s
#[turbo_tasks::value(transparent)] #[turbo_tasks::value(transparent)]
pub struct OutputAssetsSet(FxIndexSet<Vc<Box<dyn OutputAsset>>>); pub struct OutputAssetsSet(FxIndexSet<ResolvedVc<Box<dyn OutputAsset>>>);
// TODO All Vc::try_resolve_downcast::<Box<dyn OutputAsset>> calls should be // TODO All Vc::try_resolve_downcast::<Box<dyn OutputAsset>> calls should be
// removed // removed
...@@ -47,17 +47,10 @@ impl ModuleReferences { ...@@ -47,17 +47,10 @@ impl ModuleReferences {
/// A reference that always resolves to a single module. /// A reference that always resolves to a single module.
#[turbo_tasks::value] #[turbo_tasks::value]
pub struct SingleModuleReference { pub struct SingleModuleReference {
asset: Vc<Box<dyn Module>>, asset: ResolvedVc<Box<dyn Module>>,
description: Vc<RcStr>, description: Vc<RcStr>,
} }
impl SingleModuleReference {
/// Returns the asset that this reference resolves to.
pub fn asset_ref(&self) -> Vc<Box<dyn Module>> {
self.asset
}
}
#[turbo_tasks::value_impl] #[turbo_tasks::value_impl]
impl ModuleReference for SingleModuleReference { impl ModuleReference for SingleModuleReference {
#[turbo_tasks::function] #[turbo_tasks::function]
...@@ -79,31 +72,24 @@ impl SingleModuleReference { ...@@ -79,31 +72,24 @@ impl SingleModuleReference {
/// Create a new [Vc<SingleModuleReference>] that resolves to the given /// Create a new [Vc<SingleModuleReference>] that resolves to the given
/// asset. /// asset.
#[turbo_tasks::function] #[turbo_tasks::function]
pub fn new(asset: Vc<Box<dyn Module>>, description: Vc<RcStr>) -> Vc<Self> { pub fn new(asset: ResolvedVc<Box<dyn Module>>, description: Vc<RcStr>) -> Vc<Self> {
Self::cell(SingleModuleReference { asset, description }) Self::cell(SingleModuleReference { asset, description })
} }
/// The [Vc<Box<dyn Asset>>] that this reference resolves to. /// The [Vc<Box<dyn Asset>>] that this reference resolves to.
#[turbo_tasks::function] #[turbo_tasks::function]
pub fn asset(&self) -> Vc<Box<dyn Module>> { pub fn asset(&self) -> Vc<Box<dyn Module>> {
self.asset *self.asset
} }
} }
/// A reference that always resolves to a single module. /// A reference that always resolves to a single module.
#[turbo_tasks::value] #[turbo_tasks::value]
pub struct SingleOutputAssetReference { pub struct SingleOutputAssetReference {
asset: Vc<Box<dyn OutputAsset>>, asset: ResolvedVc<Box<dyn OutputAsset>>,
description: Vc<RcStr>, description: Vc<RcStr>,
} }
impl SingleOutputAssetReference {
/// Returns the asset that this reference resolves to.
pub fn asset_ref(&self) -> Vc<Box<dyn OutputAsset>> {
self.asset
}
}
#[turbo_tasks::value_impl] #[turbo_tasks::value_impl]
impl ModuleReference for SingleOutputAssetReference { impl ModuleReference for SingleOutputAssetReference {
#[turbo_tasks::function] #[turbo_tasks::function]
...@@ -125,14 +111,14 @@ impl SingleOutputAssetReference { ...@@ -125,14 +111,14 @@ impl SingleOutputAssetReference {
/// Create a new [Vc<SingleOutputAssetReference>] that resolves to the given /// Create a new [Vc<SingleOutputAssetReference>] that resolves to the given
/// asset. /// asset.
#[turbo_tasks::function] #[turbo_tasks::function]
pub fn new(asset: Vc<Box<dyn OutputAsset>>, description: Vc<RcStr>) -> Vc<Self> { pub fn new(asset: ResolvedVc<Box<dyn OutputAsset>>, description: Vc<RcStr>) -> Vc<Self> {
Self::cell(SingleOutputAssetReference { asset, description }) Self::cell(SingleOutputAssetReference { asset, description })
} }
/// The [Vc<Box<dyn Asset>>] that this reference resolves to. /// The [Vc<Box<dyn Asset>>] that this reference resolves to.
#[turbo_tasks::function] #[turbo_tasks::function]
pub fn asset(&self) -> Vc<Box<dyn OutputAsset>> { pub fn asset(&self) -> Vc<Box<dyn OutputAsset>> {
self.asset *self.asset
} }
} }
...@@ -157,7 +143,13 @@ pub async fn referenced_modules_and_affecting_sources( ...@@ -157,7 +143,13 @@ pub async fn referenced_modules_and_affecting_sources(
modules.extend( modules.extend(
resolve_result resolve_result
.affecting_sources_iter() .affecting_sources_iter()
.map(|source| Vc::upcast(RawModule::new(source))), .map(|source| async move {
Ok(ResolvedVc::upcast(
RawModule::new(source).to_resolved().await?,
))
})
.try_join()
.await?,
); );
} }
let mut resolved_modules = FxIndexSet::default(); let mut resolved_modules = FxIndexSet::default();
...@@ -230,7 +222,7 @@ pub async fn all_assets_from_entries(entries: Vc<OutputAssets>) -> Result<Vc<Out ...@@ -230,7 +222,7 @@ pub async fn all_assets_from_entries(entries: Vc<OutputAssets>) -> Result<Vc<Out
AdjacencyMap::new() AdjacencyMap::new()
.skip_duplicates() .skip_duplicates()
.visit( .visit(
entries.await?.iter().copied().map(Vc::upcast), entries.await?.iter().copied().map(ResolvedVc::upcast),
get_referenced_assets, get_referenced_assets,
) )
.await .await
...@@ -243,8 +235,8 @@ pub async fn all_assets_from_entries(entries: Vc<OutputAssets>) -> Result<Vc<Out ...@@ -243,8 +235,8 @@ pub async fn all_assets_from_entries(entries: Vc<OutputAssets>) -> Result<Vc<Out
/// Computes the list of all chunk children of a given chunk. /// Computes the list of all chunk children of a given chunk.
pub async fn get_referenced_assets( pub async fn get_referenced_assets(
asset: Vc<Box<dyn OutputAsset>>, asset: ResolvedVc<Box<dyn OutputAsset>>,
) -> Result<impl Iterator<Item = Vc<Box<dyn OutputAsset>>> + Send> { ) -> Result<impl Iterator<Item = ResolvedVc<Box<dyn OutputAsset>>> + Send> {
Ok(asset Ok(asset
.references() .references()
.await? .await?
......
use anyhow::Result; use anyhow::Result;
use turbo_tasks::{RcStr, ValueToString, Vc}; use turbo_tasks::{RcStr, ResolvedVc, ValueToString, Vc};
use turbo_tasks_fs::{FileSystemEntryType, FileSystemPath}; use turbo_tasks_fs::{FileSystemEntryType, FileSystemPath};
use super::ModuleReference; use super::ModuleReference;
...@@ -39,14 +39,16 @@ impl SourceMapReference { ...@@ -39,14 +39,16 @@ impl SourceMapReference {
#[turbo_tasks::value_impl] #[turbo_tasks::value_impl]
impl ModuleReference for SourceMapReference { impl ModuleReference for SourceMapReference {
#[turbo_tasks::function] #[turbo_tasks::function]
async fn resolve_reference(&self) -> Vc<ModuleResolveResult> { async fn resolve_reference(&self) -> Result<Vc<ModuleResolveResult>> {
if let Some(file) = self.get_file().await { if let Some(file) = self.get_file().await {
return ModuleResolveResult::module(Vc::upcast(RawModule::new(Vc::upcast( return Ok(ModuleResolveResult::module(ResolvedVc::upcast(
FileSource::new(file), RawModule::new(Vc::upcast(FileSource::new(file)))
)))) .to_resolved()
.cell(); .await?,
))
.cell());
} }
ModuleResolveResult::unresolvable().into() Ok(ModuleResolveResult::unresolvable().cell())
} }
} }
......
...@@ -63,8 +63,8 @@ use crate::{error::PrettyPrintError, issue::IssueSeverity}; ...@@ -63,8 +63,8 @@ use crate::{error::PrettyPrintError, issue::IssueSeverity};
#[turbo_tasks::value(shared)] #[turbo_tasks::value(shared)]
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub enum ModuleResolveResultItem { pub enum ModuleResolveResultItem {
Module(Vc<Box<dyn Module>>), Module(ResolvedVc<Box<dyn Module>>),
OutputAsset(Vc<Box<dyn OutputAsset>>), OutputAsset(ResolvedVc<Box<dyn OutputAsset>>),
External(RcStr, ExternalType), External(RcStr, ExternalType),
Ignore, Ignore,
Error(ResolvedVc<RcStr>), Error(ResolvedVc<RcStr>),
...@@ -102,24 +102,13 @@ impl ModuleResolveResult { ...@@ -102,24 +102,13 @@ impl ModuleResolveResult {
} }
} }
pub fn ignored() -> ModuleResolveResult { pub fn module(module: ResolvedVc<Box<dyn Module>>) -> ModuleResolveResult {
Self::ignored_with_key(RequestKey::default())
}
pub fn ignored_with_key(request_key: RequestKey) -> ModuleResolveResult {
ModuleResolveResult {
primary: fxindexmap! { request_key => ModuleResolveResultItem::Ignore },
affecting_sources: Vec::new(),
}
}
pub fn module(module: Vc<Box<dyn Module>>) -> ModuleResolveResult {
Self::module_with_key(RequestKey::default(), module) Self::module_with_key(RequestKey::default(), module)
} }
pub fn module_with_key( pub fn module_with_key(
request_key: RequestKey, request_key: RequestKey,
module: Vc<Box<dyn Module>>, module: ResolvedVc<Box<dyn Module>>,
) -> ModuleResolveResult { ) -> ModuleResolveResult {
ModuleResolveResult { ModuleResolveResult {
primary: fxindexmap! { request_key => ModuleResolveResultItem::Module(module) }, primary: fxindexmap! { request_key => ModuleResolveResultItem::Module(module) },
...@@ -129,7 +118,7 @@ impl ModuleResolveResult { ...@@ -129,7 +118,7 @@ impl ModuleResolveResult {
pub fn output_asset( pub fn output_asset(
request_key: RequestKey, request_key: RequestKey,
output_asset: Vc<Box<dyn OutputAsset>>, output_asset: ResolvedVc<Box<dyn OutputAsset>>,
) -> ModuleResolveResult { ) -> ModuleResolveResult {
ModuleResolveResult { ModuleResolveResult {
primary: fxindexmap! { request_key => ModuleResolveResultItem::OutputAsset(output_asset) }, primary: fxindexmap! { request_key => ModuleResolveResultItem::OutputAsset(output_asset) },
...@@ -138,7 +127,7 @@ impl ModuleResolveResult { ...@@ -138,7 +127,7 @@ impl ModuleResolveResult {
} }
pub fn modules( pub fn modules(
modules: impl IntoIterator<Item = (RequestKey, Vc<Box<dyn Module>>)>, modules: impl IntoIterator<Item = (RequestKey, ResolvedVc<Box<dyn Module>>)>,
) -> ModuleResolveResult { ) -> ModuleResolveResult {
ModuleResolveResult { ModuleResolveResult {
primary: modules primary: modules
...@@ -149,20 +138,8 @@ impl ModuleResolveResult { ...@@ -149,20 +138,8 @@ impl ModuleResolveResult {
} }
} }
pub fn output_assets(
output_assets: impl IntoIterator<Item = (RequestKey, Vc<Box<dyn OutputAsset>>)>,
) -> ModuleResolveResult {
ModuleResolveResult {
primary: output_assets
.into_iter()
.map(|(k, v)| (k, ModuleResolveResultItem::OutputAsset(v)))
.collect(),
affecting_sources: Vec::new(),
}
}
pub fn modules_with_affecting_sources( pub fn modules_with_affecting_sources(
modules: impl IntoIterator<Item = (RequestKey, Vc<Box<dyn Module>>)>, modules: impl IntoIterator<Item = (RequestKey, ResolvedVc<Box<dyn Module>>)>,
affecting_sources: Vec<Vc<Box<dyn Source>>>, affecting_sources: Vec<Vc<Box<dyn Source>>>,
) -> ModuleResolveResult { ) -> ModuleResolveResult {
ModuleResolveResult { ModuleResolveResult {
...@@ -174,7 +151,7 @@ impl ModuleResolveResult { ...@@ -174,7 +151,7 @@ impl ModuleResolveResult {
} }
} }
pub fn primary_modules_iter(&self) -> impl Iterator<Item = Vc<Box<dyn Module>>> + '_ { pub fn primary_modules_iter(&self) -> impl Iterator<Item = ResolvedVc<Box<dyn Module>>> + '_ {
self.primary.iter().filter_map(|(_, item)| match item { self.primary.iter().filter_map(|(_, item)| match item {
&ModuleResolveResultItem::Module(a) => Some(a), &ModuleResolveResultItem::Module(a) => Some(a),
_ => None, _ => None,
...@@ -346,17 +323,15 @@ impl ModuleResolveResult { ...@@ -346,17 +323,15 @@ impl ModuleResolveResult {
let Some(first) = iter.next() else { let Some(first) = iter.next() else {
return Ok(Vc::cell(vec![])); return Ok(Vc::cell(vec![]));
}; };
let first = first.to_resolved().await?;
let Some(second) = iter.next() else { let Some(second) = iter.next() else {
return Ok(Vc::cell(vec![first])); return Ok(Vc::cell(vec![first]));
}; };
let second = second.to_resolved().await?;
// We have at least two items, so we need to deduplicate them // We have at least two items, so we need to deduplicate them
let mut set = fxindexset![first, second]; let mut set = fxindexset![first, second];
for module in self.primary_modules_iter() { for module in self.primary_modules_iter() {
set.insert(module.to_resolved().await?); set.insert(module);
} }
Ok(Vc::cell(set.into_iter().collect())) Ok(Vc::cell(set.into_iter().collect()))
} }
...@@ -740,9 +715,9 @@ impl ResolveResult { ...@@ -740,9 +715,9 @@ impl ResolveResult {
pub async fn as_raw_module_result(&self) -> Result<Vc<ModuleResolveResult>> { pub async fn as_raw_module_result(&self) -> Result<Vc<ModuleResolveResult>> {
Ok(self Ok(self
.map_module(|asset| async move { .map_module(|asset| async move {
Ok(ModuleResolveResultItem::Module(Vc::upcast(RawModule::new( Ok(ModuleResolveResultItem::Module(ResolvedVc::upcast(
asset, RawModule::new(asset).to_resolved().await?,
)))) )))
}) })
.await? .await?
.cell()) .cell())
......
...@@ -84,7 +84,7 @@ async fn resolve_asset( ...@@ -84,7 +84,7 @@ async fn resolve_asset(
reference_type: Value<ReferenceType>, reference_type: Value<ReferenceType>,
) -> Result<Vc<ModuleResolveResult>> { ) -> Result<Vc<ModuleResolveResult>> {
if let Some(asset) = *resolve_origin.get_inner_asset(request).await? { if let Some(asset) = *resolve_origin.get_inner_asset(request).await? {
return Ok(ModuleResolveResult::module(*asset).cell()); return Ok(ModuleResolveResult::module(asset).cell());
} }
Ok(resolve_origin Ok(resolve_origin
.asset_context() .asset_context()
......
...@@ -224,12 +224,19 @@ impl OutputChunk for CssChunk { ...@@ -224,12 +224,19 @@ impl OutputChunk for CssChunk {
.into_iter() .into_iter()
.flatten() .flatten()
.collect(); .collect();
let module_chunks: Vec<_> = content let module_chunks = content
.chunk_items .chunk_items
.iter() .iter()
.chain(imports_chunk_items.iter()) .chain(imports_chunk_items.iter())
.map(|item| Vc::upcast(SingleItemCssChunk::new(self.chunking_context, *item))) .map(|item| {
.collect(); Vc::upcast::<Box<dyn OutputAsset>>(SingleItemCssChunk::new(
self.chunking_context,
*item,
))
.to_resolved()
})
.try_join()
.await?;
Ok(OutputChunkRuntimeInfo { Ok(OutputChunkRuntimeInfo {
included_ids: Some(ResolvedVc::cell(included_ids)), included_ids: Some(ResolvedVc::cell(included_ids)),
module_chunks: Some(ResolvedVc::cell(module_chunks)), module_chunks: Some(ResolvedVc::cell(module_chunks)),
...@@ -306,17 +313,20 @@ impl OutputAsset for CssChunk { ...@@ -306,17 +313,20 @@ impl OutputAsset for CssChunk {
let content = this.content.await?; let content = this.content.await?;
let mut references = content.referenced_output_assets.await?.clone_value(); let mut references = content.referenced_output_assets.await?.clone_value();
for item in content.chunk_items.iter() { for item in content.chunk_items.iter() {
references.push(Vc::upcast(SingleItemCssChunk::new( references.push(ResolvedVc::upcast(
this.chunking_context, SingleItemCssChunk::new(this.chunking_context, *item)
*item, .to_resolved()
))); .await?,
));
} }
if *this if *this
.chunking_context .chunking_context
.reference_chunk_source_maps(Vc::upcast(self)) .reference_chunk_source_maps(Vc::upcast(self))
.await? .await?
{ {
references.push(Vc::upcast(CssChunkSourceMapAsset::new(self))); references.push(ResolvedVc::upcast(
CssChunkSourceMapAsset::new(self).to_resolved().await?,
));
} }
Ok(Vc::cell(references)) Ok(Vc::cell(references))
} }
......
use std::fmt::Write; use std::fmt::Write;
use anyhow::Result; use anyhow::Result;
use turbo_tasks::{RcStr, ValueToString, Vc}; use turbo_tasks::{RcStr, ResolvedVc, ValueToString, Vc};
use turbo_tasks_fs::File; use turbo_tasks_fs::File;
use turbopack_core::{ use turbopack_core::{
asset::{Asset, AssetContent}, asset::{Asset, AssetContent},
...@@ -120,7 +120,11 @@ impl OutputAsset for SingleItemCssChunk { ...@@ -120,7 +120,11 @@ impl OutputAsset for SingleItemCssChunk {
.reference_chunk_source_maps(Vc::upcast(self)) .reference_chunk_source_maps(Vc::upcast(self))
.await? .await?
{ {
references.push(Vc::upcast(SingleItemCssChunkSourceMapAsset::new(self))); references.push(ResolvedVc::upcast(
SingleItemCssChunkSourceMapAsset::new(self)
.to_resolved()
.await?,
));
} }
Ok(Vc::cell(references)) Ok(Vc::cell(references))
} }
......
...@@ -83,7 +83,7 @@ impl Module for ModuleCssAsset { ...@@ -83,7 +83,7 @@ impl Module for ModuleCssAsset {
.copied() .copied()
.chain(match *self.inner().await? { .chain(match *self.inner().await? {
ProcessResult::Module(inner) => { ProcessResult::Module(inner) => {
Some(Vc::upcast(InternalCssAssetReference::new(inner))) Some(Vc::upcast(InternalCssAssetReference::new(*inner)))
} }
ProcessResult::Ignore => None, ProcessResult::Ignore => None,
}) })
......
use anyhow::Result; use anyhow::Result;
use turbo_tasks::{RcStr, ValueToString, Vc}; use turbo_tasks::{RcStr, ResolvedVc, ValueToString, Vc};
use turbopack_core::{ use turbopack_core::{
chunk::ChunkableModuleReference, module::Module, reference::ModuleReference, chunk::ChunkableModuleReference, module::Module, reference::ModuleReference,
resolve::ModuleResolveResult, resolve::ModuleResolveResult,
...@@ -9,14 +9,14 @@ use turbopack_core::{ ...@@ -9,14 +9,14 @@ use turbopack_core::{
#[turbo_tasks::value] #[turbo_tasks::value]
#[derive(Hash, Debug)] #[derive(Hash, Debug)]
pub struct InternalCssAssetReference { pub struct InternalCssAssetReference {
module: Vc<Box<dyn Module>>, module: ResolvedVc<Box<dyn Module>>,
} }
#[turbo_tasks::value_impl] #[turbo_tasks::value_impl]
impl InternalCssAssetReference { impl InternalCssAssetReference {
/// Creates a new [`Vc<InternalCssAssetReference>`]. /// Creates a new [`Vc<InternalCssAssetReference>`].
#[turbo_tasks::function] #[turbo_tasks::function]
pub fn new(module: Vc<Box<dyn Module>>) -> Vc<Self> { pub fn new(module: ResolvedVc<Box<dyn Module>>) -> Vc<Self> {
Self::cell(InternalCssAssetReference { module }) Self::cell(InternalCssAssetReference { module })
} }
} }
......
...@@ -22,7 +22,7 @@ use super::{ ...@@ -22,7 +22,7 @@ use super::{
}; };
#[turbo_tasks::value(transparent)] #[turbo_tasks::value(transparent)]
struct OutputAssetsMap(FxIndexMap<RcStr, Vc<Box<dyn OutputAsset>>>); struct OutputAssetsMap(FxIndexMap<RcStr, ResolvedVc<Box<dyn OutputAsset>>>);
type ExpandedState = State<HashSet<RcStr>>; type ExpandedState = State<HashSet<RcStr>>;
...@@ -39,7 +39,7 @@ impl AssetGraphContentSource { ...@@ -39,7 +39,7 @@ impl AssetGraphContentSource {
#[turbo_tasks::function] #[turbo_tasks::function]
pub fn new_eager( pub fn new_eager(
root_path: Vc<FileSystemPath>, root_path: Vc<FileSystemPath>,
root_asset: Vc<Box<dyn OutputAsset>>, root_asset: ResolvedVc<Box<dyn OutputAsset>>,
) -> Vc<Self> { ) -> Vc<Self> {
Self::cell(AssetGraphContentSource { Self::cell(AssetGraphContentSource {
root_path, root_path,
...@@ -53,7 +53,7 @@ impl AssetGraphContentSource { ...@@ -53,7 +53,7 @@ impl AssetGraphContentSource {
#[turbo_tasks::function] #[turbo_tasks::function]
pub fn new_lazy( pub fn new_lazy(
root_path: Vc<FileSystemPath>, root_path: Vc<FileSystemPath>,
root_asset: Vc<Box<dyn OutputAsset>>, root_asset: ResolvedVc<Box<dyn OutputAsset>>,
) -> Vc<Self> { ) -> Vc<Self> {
Self::cell(AssetGraphContentSource { Self::cell(AssetGraphContentSource {
root_path, root_path,
...@@ -103,10 +103,10 @@ impl AssetGraphContentSource { ...@@ -103,10 +103,10 @@ impl AssetGraphContentSource {
} }
async fn expand( async fn expand(
root_assets: &FxIndexSet<Vc<Box<dyn OutputAsset>>>, root_assets: &FxIndexSet<ResolvedVc<Box<dyn OutputAsset>>>,
root_path: &FileSystemPath, root_path: &FileSystemPath,
expanded: Option<&ExpandedState>, expanded: Option<&ExpandedState>,
) -> Result<FxIndexMap<RcStr, Vc<Box<dyn OutputAsset>>>> { ) -> Result<FxIndexMap<RcStr, ResolvedVc<Box<dyn OutputAsset>>>> {
let mut map = FxIndexMap::default(); let mut map = FxIndexMap::default();
let mut assets = Vec::new(); let mut assets = Vec::new();
let mut queue = VecDeque::with_capacity(32); let mut queue = VecDeque::with_capacity(32);
...@@ -177,7 +177,7 @@ async fn expand( ...@@ -177,7 +177,7 @@ async fn expand(
} }
} }
for (sub_path, asset) in assets { for (sub_path, asset) in assets {
let asset = asset.resolve().await?; let asset = asset.to_resolved().await?;
if &*sub_path == "index.html" { if &*sub_path == "index.html" {
map.insert("".into(), asset); map.insert("".into(), asset);
} else if let Some(p) = sub_path.strip_suffix("/index.html") { } else if let Some(p) = sub_path.strip_suffix("/index.html") {
...@@ -225,7 +225,7 @@ impl ContentSource for AssetGraphContentSource { ...@@ -225,7 +225,7 @@ impl ContentSource for AssetGraphContentSource {
Vc::upcast(AssetGraphGetContentSourceContent::new( Vc::upcast(AssetGraphGetContentSourceContent::new(
self, self,
path.clone(), path.clone(),
*asset, **asset,
)), )),
) )
}) })
...@@ -320,18 +320,21 @@ impl Introspectable for AssetGraphContentSource { ...@@ -320,18 +320,21 @@ impl Introspectable for AssetGraphContentSource {
let expanded_key = Vc::cell("expanded".into()); let expanded_key = Vc::cell("expanded".into());
let root_assets = this.root_assets.await?; let root_assets = this.root_assets.await?;
let root_asset_children = root_assets let root_asset_children = root_assets.iter().map(|&asset| {
.iter() (
.map(|&asset| (key, IntrospectableOutputAsset::new(Vc::upcast(asset)))); key,
IntrospectableOutputAsset::new(*ResolvedVc::upcast(asset)),
)
});
let expanded_assets = self.all_assets_map().await?; let expanded_assets = self.all_assets_map().await?;
let expanded_asset_children = expanded_assets let expanded_asset_children = expanded_assets
.values() .values()
.filter(|a| !root_assets.contains(*a)) .filter(|&a| !root_assets.contains(a))
.map(|asset| { .map(|&asset| {
( (
inner_key, inner_key,
IntrospectableOutputAsset::new(Vc::upcast(*asset)), IntrospectableOutputAsset::new(*ResolvedVc::upcast(asset)),
) )
}); });
...@@ -376,7 +379,7 @@ impl Introspectable for FullyExpaned { ...@@ -376,7 +379,7 @@ impl Introspectable for FullyExpaned {
expand(&*source.root_assets.await?, &*source.root_path.await?, None).await?; expand(&*source.root_assets.await?, &*source.root_path.await?, None).await?;
let children = expanded_assets let children = expanded_assets
.iter() .iter()
.map(|(_k, &v)| (key, IntrospectableOutputAsset::new(v))) .map(|(_k, &v)| (key, IntrospectableOutputAsset::new(*v)))
.collect(); .collect();
Ok(Vc::cell(children)) Ok(Vc::cell(children))
......
...@@ -187,7 +187,7 @@ impl ChunkItem for AsyncLoaderChunkItem { ...@@ -187,7 +187,7 @@ impl ChunkItem for AsyncLoaderChunkItem {
.copied() .copied()
.map(|chunk| { .map(|chunk| {
Vc::upcast(SingleOutputAssetReference::new( Vc::upcast(SingleOutputAssetReference::new(
chunk, *chunk,
chunk_reference_description(), chunk_reference_description(),
)) ))
}) })
......
use turbo_tasks::Vc; use turbo_tasks::{ResolvedVc, Vc};
use turbopack_core::{chunk::AsyncModuleInfo, output::OutputAsset}; use turbopack_core::{chunk::AsyncModuleInfo, output::OutputAsset};
use super::item::EcmascriptChunkItem; use super::item::EcmascriptChunkItem;
...@@ -11,5 +11,5 @@ type EcmascriptChunkItemWithAsyncInfo = ( ...@@ -11,5 +11,5 @@ type EcmascriptChunkItemWithAsyncInfo = (
#[turbo_tasks::value(shared)] #[turbo_tasks::value(shared)]
pub struct EcmascriptChunkContent { pub struct EcmascriptChunkContent {
pub chunk_items: Vec<EcmascriptChunkItemWithAsyncInfo>, pub chunk_items: Vec<EcmascriptChunkItemWithAsyncInfo>,
pub referenced_output_assets: Vec<Vc<Box<dyn OutputAsset>>>, pub referenced_output_assets: Vec<ResolvedVc<Box<dyn OutputAsset>>>,
} }
...@@ -205,7 +205,7 @@ impl ChunkItem for ChunkGroupFilesChunkItem { ...@@ -205,7 +205,7 @@ impl ChunkItem for ChunkGroupFilesChunkItem {
.copied() .copied()
.map(|chunk| { .map(|chunk| {
SingleOutputAssetReference::new( SingleOutputAssetReference::new(
chunk, *chunk,
chunk_group_chunk_reference_description(), chunk_group_chunk_reference_description(),
) )
}) })
......
...@@ -119,7 +119,7 @@ impl Module for ManifestAsyncModule { ...@@ -119,7 +119,7 @@ impl Module for ManifestAsyncModule {
.copied() .copied()
.map(|chunk| { .map(|chunk| {
Vc::upcast(SingleOutputAssetReference::new( Vc::upcast(SingleOutputAssetReference::new(
chunk, *chunk,
manifest_chunk_reference_description(), manifest_chunk_reference_description(),
)) ))
}) })
......
...@@ -86,7 +86,7 @@ impl ChunkItem for ManifestChunkItem { ...@@ -86,7 +86,7 @@ impl ChunkItem for ManifestChunkItem {
for chunk_data in &*self.chunks_data().await? { for chunk_data in &*self.chunks_data().await? {
references.extend(chunk_data.references().await?.iter().map(|&output_asset| { references.extend(chunk_data.references().await?.iter().map(|&output_asset| {
Vc::upcast(SingleOutputAssetReference::new(output_asset, key)) Vc::upcast(SingleOutputAssetReference::new(*output_asset, key))
})); }));
} }
......
...@@ -104,7 +104,7 @@ impl ChunkItem for ManifestLoaderChunkItem { ...@@ -104,7 +104,7 @@ impl ChunkItem for ManifestLoaderChunkItem {
.iter() .iter()
.map(|&chunk| { .map(|&chunk| {
Vc::upcast(SingleOutputAssetReference::new( Vc::upcast(SingleOutputAssetReference::new(
chunk, *chunk,
manifest_loader_chunk_reference_description(), manifest_loader_chunk_reference_description(),
)) ))
}) })
...@@ -113,7 +113,7 @@ impl ChunkItem for ManifestLoaderChunkItem { ...@@ -113,7 +113,7 @@ impl ChunkItem for ManifestLoaderChunkItem {
for chunk_data in &*self.chunks_data().await? { for chunk_data in &*self.chunks_data().await? {
references.extend(chunk_data.references().await?.iter().map(|&output_asset| { references.extend(chunk_data.references().await?.iter().map(|&output_asset| {
Vc::upcast(SingleOutputAssetReference::new( Vc::upcast(SingleOutputAssetReference::new(
output_asset, *output_asset,
chunk_data_reference_description(), chunk_data_reference_description(),
)) ))
})); }));
......
...@@ -84,10 +84,10 @@ impl ReferencedAsset { ...@@ -84,10 +84,10 @@ impl ReferencedAsset {
} }
&ModuleResolveResultItem::Module(module) => { &ModuleResolveResultItem::Module(module) => {
if let Some(placeable) = if let Some(placeable) =
Vc::try_resolve_downcast::<Box<dyn EcmascriptChunkPlaceable>>(module) ResolvedVc::try_downcast::<Box<dyn EcmascriptChunkPlaceable>>(module)
.await? .await?
{ {
return Ok(ReferencedAsset::Some(placeable.to_resolved().await?).cell()); return Ok(ReferencedAsset::Some(placeable).cell());
} }
} }
// TODO ignore should probably be handled differently // TODO ignore should probably be handled differently
...@@ -167,7 +167,9 @@ impl ModuleReference for EsmAssetReference { ...@@ -167,7 +167,9 @@ impl ModuleReference for EsmAssetReference {
.expect("EsmAssetReference origin should be a EcmascriptModuleAsset"); .expect("EsmAssetReference origin should be a EcmascriptModuleAsset");
return Ok(ModuleResolveResult::module( return Ok(ModuleResolveResult::module(
EcmascriptModulePartAsset::select_part(module, *part), EcmascriptModulePartAsset::select_part(module, *part)
.to_resolved()
.await?,
) )
.cell()); .cell());
} }
......
use anyhow::Result; use anyhow::Result;
use either::Either; use either::Either;
use turbo_tasks::{RcStr, ValueToString, Vc}; use turbo_tasks::{RcStr, ResolvedVc, ValueToString, Vc};
use turbo_tasks_fs::FileSystemPath; use turbo_tasks_fs::FileSystemPath;
use turbopack_core::{ use turbopack_core::{
file_source::FileSource, file_source::FileSource,
...@@ -30,11 +30,13 @@ impl PackageJsonReference { ...@@ -30,11 +30,13 @@ impl PackageJsonReference {
#[turbo_tasks::value_impl] #[turbo_tasks::value_impl]
impl ModuleReference for PackageJsonReference { impl ModuleReference for PackageJsonReference {
#[turbo_tasks::function] #[turbo_tasks::function]
fn resolve_reference(&self) -> Vc<ModuleResolveResult> { async fn resolve_reference(&self) -> Result<Vc<ModuleResolveResult>> {
ModuleResolveResult::module(Vc::upcast(RawModule::new(Vc::upcast(FileSource::new( Ok(ModuleResolveResult::module(ResolvedVc::upcast(
self.package_json, RawModule::new(Vc::upcast(FileSource::new(self.package_json)))
))))) .to_resolved()
.cell() .await?,
))
.cell())
} }
} }
...@@ -126,7 +128,11 @@ async fn resolve_reference_from_dir( ...@@ -126,7 +128,11 @@ async fn resolve_reference_from_dir(
} }
results.push(( results.push((
RequestKey::new(matched_path.clone()), RequestKey::new(matched_path.clone()),
Vc::upcast(RawModule::new(Vc::upcast(FileSource::new(*realpath.path)))), ResolvedVc::upcast(
RawModule::new(Vc::upcast(FileSource::new(*realpath.path)))
.to_resolved()
.await?,
),
)); ));
} }
PatternMatch::Directory(..) => {} PatternMatch::Directory(..) => {}
......
...@@ -11,7 +11,8 @@ use swc_core::{ ...@@ -11,7 +11,8 @@ use swc_core::{
quote, quote_expr, quote, quote_expr,
}; };
use turbo_tasks::{ use turbo_tasks::{
debug::ValueDebugFormat, trace::TraceRawVcs, FxIndexMap, RcStr, TryJoinIterExt, Value, Vc, debug::ValueDebugFormat, trace::TraceRawVcs, FxIndexMap, RcStr, ResolvedVc, TryJoinIterExt,
Value, Vc,
}; };
use turbopack_core::{ use turbopack_core::{
chunk::{ChunkItemExt, ChunkableModule, ChunkingContext, ModuleId}, chunk::{ChunkItemExt, ChunkableModule, ChunkingContext, ModuleId},
...@@ -340,10 +341,10 @@ async fn to_single_pattern_mapping( ...@@ -340,10 +341,10 @@ async fn to_single_pattern_mapping(
return Ok(SinglePatternMapping::Invalid); return Ok(SinglePatternMapping::Invalid);
} }
}; };
if let Some(chunkable) = Vc::try_resolve_downcast::<Box<dyn ChunkableModule>>(module).await? { if let Some(chunkable) = ResolvedVc::try_downcast::<Box<dyn ChunkableModule>>(module).await? {
match resolve_type { match resolve_type {
ResolveType::AsyncChunkLoader => { ResolveType::AsyncChunkLoader => {
let loader_id = chunking_context.async_loader_chunk_item_id(chunkable); let loader_id = chunking_context.async_loader_chunk_item_id(*chunkable);
return Ok(SinglePatternMapping::ModuleLoader( return Ok(SinglePatternMapping::ModuleLoader(
loader_id.await?.clone_value(), loader_id.await?.clone_value(),
)); ));
......
...@@ -201,7 +201,7 @@ impl RequireContextMap { ...@@ -201,7 +201,7 @@ impl RequireContextMap {
#[turbo_tasks::value] #[turbo_tasks::value]
#[derive(Hash, Debug)] #[derive(Hash, Debug)]
pub struct RequireContextAssetReference { pub struct RequireContextAssetReference {
pub inner: Vc<RequireContextAsset>, pub inner: ResolvedVc<RequireContextAsset>,
pub dir: RcStr, pub dir: RcStr,
pub include_subdirs: bool, pub include_subdirs: bool,
...@@ -239,7 +239,7 @@ impl RequireContextAssetReference { ...@@ -239,7 +239,7 @@ impl RequireContextAssetReference {
dir: dir.clone(), dir: dir.clone(),
include_subdirs, include_subdirs,
} }
.cell(); .resolved_cell();
Self::cell(RequireContextAssetReference { Self::cell(RequireContextAssetReference {
inner, inner,
...@@ -256,7 +256,7 @@ impl RequireContextAssetReference { ...@@ -256,7 +256,7 @@ impl RequireContextAssetReference {
impl ModuleReference for RequireContextAssetReference { impl ModuleReference for RequireContextAssetReference {
#[turbo_tasks::function] #[turbo_tasks::function]
fn resolve_reference(&self) -> Vc<ModuleResolveResult> { fn resolve_reference(&self) -> Vc<ModuleResolveResult> {
ModuleResolveResult::module(Vc::upcast(self.inner)).cell() ModuleResolveResult::module(ResolvedVc::upcast(self.inner)).cell()
} }
} }
......
use anyhow::Result; use anyhow::Result;
use turbo_tasks::{RcStr, Value, ValueToString, Vc}; use turbo_tasks::{RcStr, ResolvedVc, Value, ValueToString, Vc};
use turbo_tasks_fs::FileSystemPath; use turbo_tasks_fs::FileSystemPath;
use turbopack_core::{ use turbopack_core::{
context::AssetContext, context::AssetContext,
...@@ -30,12 +30,13 @@ impl TsConfigReference { ...@@ -30,12 +30,13 @@ impl TsConfigReference {
#[turbo_tasks::value_impl] #[turbo_tasks::value_impl]
impl ModuleReference for TsConfigReference { impl ModuleReference for TsConfigReference {
#[turbo_tasks::function] #[turbo_tasks::function]
fn resolve_reference(&self) -> Vc<ModuleResolveResult> { async fn resolve_reference(&self) -> Result<Vc<ModuleResolveResult>> {
ModuleResolveResult::module(Vc::upcast(TsConfigModuleAsset::new( Ok(ModuleResolveResult::module(ResolvedVc::upcast(
self.origin, TsConfigModuleAsset::new(self.origin, Vc::upcast(FileSource::new(self.tsconfig)))
Vc::upcast(FileSource::new(self.tsconfig)), .to_resolved()
))) .await?,
.into() ))
.cell())
} }
} }
...@@ -85,7 +86,9 @@ impl ModuleReference for TsReferencePathAssetReference { ...@@ -85,7 +86,9 @@ impl ModuleReference for TsReferencePathAssetReference {
TypeScriptReferenceSubType::Undefined, TypeScriptReferenceSubType::Undefined,
)), )),
) )
.module(); .module()
.to_resolved()
.await?;
ModuleResolveResult::module(module).cell() ModuleResolveResult::module(module).cell()
} else { } else {
ModuleResolveResult::unresolvable().cell() ModuleResolveResult::unresolvable().cell()
......
...@@ -88,7 +88,10 @@ impl ModuleReference for WorkerAssetReference { ...@@ -88,7 +88,10 @@ impl ModuleReference for WorkerAssetReference {
#[turbo_tasks::function] #[turbo_tasks::function]
async fn resolve_reference(&self) -> Result<Vc<ModuleResolveResult>> { async fn resolve_reference(&self) -> Result<Vc<ModuleResolveResult>> {
if let Some(worker_loader_module) = self.worker_loader_module().await? { if let Some(worker_loader_module) = self.worker_loader_module().await? {
Ok(ModuleResolveResult::module(Vc::upcast(worker_loader_module)).cell()) Ok(ModuleResolveResult::module(ResolvedVc::upcast(
worker_loader_module.to_resolved().await?,
))
.cell())
} else { } else {
Ok(ModuleResolveResult::unresolvable().cell()) Ok(ModuleResolveResult::unresolvable().cell())
} }
......
...@@ -6,6 +6,7 @@ use turbopack_core::{ ...@@ -6,6 +6,7 @@ use turbopack_core::{
ChunkItemExt, ChunkableModule, ChunkableModuleReference, ChunkingContext, ChunkingType, ChunkItemExt, ChunkableModule, ChunkableModuleReference, ChunkingContext, ChunkingType,
ChunkingTypeOption, ChunkingTypeOption,
}, },
module::Module,
reference::ModuleReference, reference::ModuleReference,
resolve::{ModulePart, ModuleResolveResult}, resolve::{ModulePart, ModuleResolveResult},
}; };
...@@ -24,7 +25,7 @@ use crate::{ ...@@ -24,7 +25,7 @@ use crate::{
/// module. /// module.
#[turbo_tasks::value] #[turbo_tasks::value]
pub struct EcmascriptModulePartReference { pub struct EcmascriptModulePartReference {
pub module: Vc<Box<dyn EcmascriptChunkPlaceable>>, pub module: ResolvedVc<Box<dyn EcmascriptChunkPlaceable>>,
pub part: Option<ResolvedVc<ModulePart>>, pub part: Option<ResolvedVc<ModulePart>>,
} }
...@@ -32,7 +33,7 @@ pub struct EcmascriptModulePartReference { ...@@ -32,7 +33,7 @@ pub struct EcmascriptModulePartReference {
impl EcmascriptModulePartReference { impl EcmascriptModulePartReference {
#[turbo_tasks::function] #[turbo_tasks::function]
pub fn new_part( pub fn new_part(
module: Vc<Box<dyn EcmascriptChunkPlaceable>>, module: ResolvedVc<Box<dyn EcmascriptChunkPlaceable>>,
part: ResolvedVc<ModulePart>, part: ResolvedVc<ModulePart>,
) -> Vc<Self> { ) -> Vc<Self> {
EcmascriptModulePartReference { EcmascriptModulePartReference {
...@@ -43,7 +44,7 @@ impl EcmascriptModulePartReference { ...@@ -43,7 +44,7 @@ impl EcmascriptModulePartReference {
} }
#[turbo_tasks::function] #[turbo_tasks::function]
pub fn new(module: Vc<Box<dyn EcmascriptChunkPlaceable>>) -> Vc<Self> { pub fn new(module: ResolvedVc<Box<dyn EcmascriptChunkPlaceable>>) -> Vc<Self> {
EcmascriptModulePartReference { module, part: None }.cell() EcmascriptModulePartReference { module, part: None }.cell()
} }
} }
...@@ -64,20 +65,20 @@ impl ModuleReference for EcmascriptModulePartReference { ...@@ -64,20 +65,20 @@ impl ModuleReference for EcmascriptModulePartReference {
let module = if let Some(part) = self.part { let module = if let Some(part) = self.part {
match *part.await? { match *part.await? {
ModulePart::Locals => { ModulePart::Locals => {
let Some(module) = Vc::try_resolve_downcast_type(self.module).await? else { let Some(module) = ResolvedVc::try_downcast_type(self.module).await? else {
bail!( bail!(
"Expected EcmascriptModuleAsset for a EcmascriptModulePartReference \ "Expected EcmascriptModuleAsset for a EcmascriptModulePartReference \
with ModulePart::Locals" with ModulePart::Locals"
); );
}; };
Vc::upcast(EcmascriptModuleLocalsModule::new(module)) Vc::upcast::<Box<dyn Module>>(EcmascriptModuleLocalsModule::new(*module))
} }
ModulePart::Exports ModulePart::Exports
| ModulePart::Evaluation | ModulePart::Evaluation
| ModulePart::Facade | ModulePart::Facade
| ModulePart::RenamedExport { .. } | ModulePart::RenamedExport { .. }
| ModulePart::RenamedNamespace { .. } => { | ModulePart::RenamedNamespace { .. } => {
Vc::upcast(EcmascriptModuleFacadeModule::new(self.module, *part)) Vc::upcast(EcmascriptModuleFacadeModule::new(*self.module, *part))
} }
ModulePart::Export(..) | ModulePart::Internal(..) => { ModulePart::Export(..) | ModulePart::Internal(..) => {
bail!( bail!(
...@@ -86,8 +87,10 @@ impl ModuleReference for EcmascriptModulePartReference { ...@@ -86,8 +87,10 @@ impl ModuleReference for EcmascriptModulePartReference {
); );
} }
} }
.to_resolved()
.await?
} else { } else {
Vc::upcast(self.module) ResolvedVc::upcast(self.module)
}; };
Ok(ModuleResolveResult::module(module).cell()) Ok(ModuleResolveResult::module(module).cell())
} }
......
use anyhow::Result; use anyhow::Result;
use serde_json::Value as JsonValue; use serde_json::Value as JsonValue;
use turbo_tasks::{RcStr, Value, ValueToString, Vc}; use turbo_tasks::{RcStr, ResolvedVc, Value, ValueToString, Vc};
use turbo_tasks_fs::DirectoryContent; use turbo_tasks_fs::DirectoryContent;
use turbopack_core::{ use turbopack_core::{
asset::{Asset, AssetContent}, asset::{Asset, AssetContent},
...@@ -212,8 +212,13 @@ impl TsExtendsReference { ...@@ -212,8 +212,13 @@ impl TsExtendsReference {
#[turbo_tasks::value_impl] #[turbo_tasks::value_impl]
impl ModuleReference for TsExtendsReference { impl ModuleReference for TsExtendsReference {
#[turbo_tasks::function] #[turbo_tasks::function]
fn resolve_reference(&self) -> Vc<ModuleResolveResult> { async fn resolve_reference(&self) -> Result<Vc<ModuleResolveResult>> {
ModuleResolveResult::module(Vc::upcast(RawModule::new(Vc::upcast(self.config)))).cell() Ok(ModuleResolveResult::module(ResolvedVc::upcast(
RawModule::new(Vc::upcast(self.config))
.to_resolved()
.await?,
))
.cell())
} }
} }
......
use anyhow::Result; use anyhow::Result;
use swc_core::ecma::ast::Lit; use swc_core::ecma::ast::Lit;
use turbo_tasks::{RcStr, Value, ValueToString, Vc}; use turbo_tasks::{RcStr, ResolvedVc, Value, ValueToString, Vc};
use turbopack_core::{ use turbopack_core::{
asset::{Asset, AssetContent}, asset::{Asset, AssetContent},
file_source::FileSource, file_source::FileSource,
...@@ -99,14 +99,14 @@ impl ModuleReference for WebpackChunkAssetReference { ...@@ -99,14 +99,14 @@ impl ModuleReference for WebpackChunkAssetReference {
let filename = format!("./chunks/{}.js", chunk_id).into(); let filename = format!("./chunks/{}.js", chunk_id).into();
let source = Vc::upcast(FileSource::new(context_path.join(filename))); let source = Vc::upcast(FileSource::new(context_path.join(filename)));
ModuleResolveResult::module(Vc::upcast(WebpackModuleAsset::new( ModuleResolveResult::module(ResolvedVc::upcast(
source, WebpackModuleAsset::new(source, self.runtime, self.transforms)
self.runtime, .to_resolved()
self.transforms, .await?,
))) ))
.into() .cell()
} }
WebpackRuntime::None => ModuleResolveResult::unresolvable().into(), WebpackRuntime::None => ModuleResolveResult::unresolvable().cell(),
}) })
} }
} }
...@@ -134,13 +134,13 @@ pub struct WebpackEntryAssetReference { ...@@ -134,13 +134,13 @@ pub struct WebpackEntryAssetReference {
#[turbo_tasks::value_impl] #[turbo_tasks::value_impl]
impl ModuleReference for WebpackEntryAssetReference { impl ModuleReference for WebpackEntryAssetReference {
#[turbo_tasks::function] #[turbo_tasks::function]
fn resolve_reference(&self) -> Vc<ModuleResolveResult> { async fn resolve_reference(&self) -> Result<Vc<ModuleResolveResult>> {
ModuleResolveResult::module(Vc::upcast(WebpackModuleAsset::new( Ok(ModuleResolveResult::module(ResolvedVc::upcast(
self.source, WebpackModuleAsset::new(self.source, self.runtime, self.transforms)
self.runtime, .to_resolved()
self.transforms, .await?,
))) ))
.into() .cell())
} }
} }
...@@ -179,8 +179,10 @@ impl ModuleReference for WebpackRuntimeAssetReference { ...@@ -179,8 +179,10 @@ impl ModuleReference for WebpackRuntimeAssetReference {
Ok(resolved Ok(resolved
.await? .await?
.map_module(|source| async move { .map_module(|source| async move {
Ok(ModuleResolveResultItem::Module(Vc::upcast( Ok(ModuleResolveResultItem::Module(ResolvedVc::upcast(
WebpackModuleAsset::new(source, self.runtime, self.transforms), WebpackModuleAsset::new(source, self.runtime, self.transforms)
.to_resolved()
.await?,
))) )))
}) })
.await? .await?
......
...@@ -127,7 +127,7 @@ impl ChunkItem for WorkerLoaderChunkItem { ...@@ -127,7 +127,7 @@ impl ChunkItem for WorkerLoaderChunkItem {
.copied() .copied()
.map(|chunk| { .map(|chunk| {
Vc::upcast(SingleOutputAssetReference::new( Vc::upcast(SingleOutputAssetReference::new(
chunk, *chunk,
chunk_reference_description(), chunk_reference_description(),
)) ))
}) })
......
...@@ -78,7 +78,7 @@ async fn internal_assets( ...@@ -78,7 +78,7 @@ async fn internal_assets(
} }
#[turbo_tasks::value(transparent)] #[turbo_tasks::value(transparent)]
pub struct AssetsForSourceMapping(HashMap<String, Vc<Box<dyn GenerateSourceMap>>>); pub struct AssetsForSourceMapping(HashMap<String, ResolvedVc<Box<dyn GenerateSourceMap>>>);
/// Extracts a map of "internal" assets ([`internal_assets`]) which implement /// Extracts a map of "internal" assets ([`internal_assets`]) which implement
/// the [GenerateSourceMap] trait. /// the [GenerateSourceMap] trait.
...@@ -92,7 +92,7 @@ async fn internal_assets_for_source_mapping( ...@@ -92,7 +92,7 @@ async fn internal_assets_for_source_mapping(
let mut internal_assets_for_source_mapping = HashMap::new(); let mut internal_assets_for_source_mapping = HashMap::new();
for asset in internal_assets.iter() { for asset in internal_assets.iter() {
if let Some(generate_source_map) = if let Some(generate_source_map) =
Vc::try_resolve_sidecast::<Box<dyn GenerateSourceMap>>(*asset).await? ResolvedVc::try_sidecast::<Box<dyn GenerateSourceMap>>(*asset).await?
{ {
if let Some(path) = intermediate_output_path.get_path_to(&*asset.ident().path().await?) if let Some(path) = intermediate_output_path.get_path_to(&*asset.ident().path().await?)
{ {
...@@ -177,10 +177,10 @@ async fn separate_assets( ...@@ -177,10 +177,10 @@ async fn separate_assets(
for item in graph.into_reverse_topological() { for item in graph.into_reverse_topological() {
match item { match item {
Type::Internal(asset) => { Type::Internal(asset) => {
internal_assets.insert(*asset); internal_assets.insert(asset);
} }
Type::External(asset) => { Type::External(asset) => {
external_asset_entrypoints.insert(*asset); external_asset_entrypoints.insert(asset);
} }
} }
} }
......
...@@ -211,7 +211,7 @@ async fn extra_configs_changed( ...@@ -211,7 +211,7 @@ async fn extra_configs_changed(
.await? .await?
{ {
ProcessResult::Module(module) => { ProcessResult::Module(module) => {
Some(any_content_changed_of_module(module)) Some(any_content_changed_of_module(*module))
} }
ProcessResult::Ignore => None, ProcessResult::Ignore => None,
} }
......
...@@ -2,7 +2,7 @@ use std::iter::once; ...@@ -2,7 +2,7 @@ use std::iter::once;
use anyhow::{bail, Context, Result}; use anyhow::{bail, Context, Result};
use tracing::Instrument; use tracing::Instrument;
use turbo_tasks::{RcStr, Value, ValueToString, Vc}; use turbo_tasks::{RcStr, ResolvedVc, TryJoinIterExt, Value, ValueToString, Vc};
use turbo_tasks_fs::FileSystemPath; use turbo_tasks_fs::FileSystemPath;
use turbopack_core::{ use turbopack_core::{
chunk::{ chunk::{
...@@ -280,15 +280,11 @@ impl ChunkingContext for NodeJsChunkingContext { ...@@ -280,15 +280,11 @@ impl ChunkingContext for NodeJsChunkingContext {
) )
.await?; .await?;
let mut assets: Vec<Vc<Box<dyn OutputAsset>>> = chunks let assets = chunks
.iter() .iter()
.map(|chunk| self.generate_chunk(**chunk)) .map(|chunk| self.generate_chunk(**chunk).to_resolved())
.collect(); .try_join()
.await?;
// Resolve assets
for asset in assets.iter_mut() {
*asset = asset.resolve().await?;
}
Ok(ChunkGroupResult { Ok(ChunkGroupResult {
assets: Vc::cell(assets), assets: Vc::cell(assets),
...@@ -333,20 +329,30 @@ impl ChunkingContext for NodeJsChunkingContext { ...@@ -333,20 +329,30 @@ impl ChunkingContext for NodeJsChunkingContext {
let other_chunks: Vec<_> = extra_chunks let other_chunks: Vec<_> = extra_chunks
.iter() .iter()
.copied() .copied()
.chain(chunks.iter().map(|chunk| self.generate_chunk(**chunk))) .chain(
chunks
.iter()
.map(|chunk| self.generate_chunk(**chunk).to_resolved())
.try_join()
.await?,
)
.collect(); .collect();
let Some(module) = Vc::try_resolve_downcast(module).await? else { let Some(module) = Vc::try_resolve_downcast(module).await? else {
bail!("module must be placeable in an ecmascript chunk"); bail!("module must be placeable in an ecmascript chunk");
}; };
let asset = Vc::upcast(EcmascriptBuildNodeEntryChunk::new( let asset = ResolvedVc::upcast(
path, EcmascriptBuildNodeEntryChunk::new(
self, path,
Vc::cell(other_chunks), self,
evaluatable_assets, Vc::cell(other_chunks),
module, evaluatable_assets,
)); module,
)
.to_resolved()
.await?,
);
Ok(EntryChunkGroupResult { Ok(EntryChunkGroupResult {
asset, asset,
......
use anyhow::Result; use anyhow::Result;
use turbo_tasks::{FxIndexSet, RcStr, ValueToString, Vc}; use turbo_tasks::{FxIndexSet, RcStr, ResolvedVc, ValueToString, Vc};
use turbopack_core::{ use turbopack_core::{
asset::{Asset, AssetContent}, asset::{Asset, AssetContent},
chunk::{Chunk, ChunkingContext}, chunk::{Chunk, ChunkingContext},
...@@ -87,7 +87,9 @@ impl OutputAsset for EcmascriptBuildNodeChunk { ...@@ -87,7 +87,9 @@ impl OutputAsset for EcmascriptBuildNodeChunk {
} }
if include_source_map { if include_source_map {
references.push(Vc::upcast(SourceMapAsset::new(Vc::upcast(self)))); references.push(ResolvedVc::upcast(
SourceMapAsset::new(Vc::upcast(self)).to_resolved().await?,
));
} }
Ok(Vc::cell(references)) Ok(Vc::cell(references))
......
...@@ -2,7 +2,7 @@ use std::io::Write; ...@@ -2,7 +2,7 @@ use std::io::Write;
use anyhow::{bail, Result}; use anyhow::{bail, Result};
use indoc::writedoc; use indoc::writedoc;
use turbo_tasks::{RcStr, ValueToString, Vc}; use turbo_tasks::{RcStr, ResolvedVc, ValueToString, Vc};
use turbo_tasks_fs::{File, FileSystemPath}; use turbo_tasks_fs::{File, FileSystemPath};
use turbopack_core::{ use turbopack_core::{
asset::{Asset, AssetContent}, asset::{Asset, AssetContent},
...@@ -177,19 +177,23 @@ impl OutputAsset for EcmascriptBuildNodeEntryChunk { ...@@ -177,19 +177,23 @@ impl OutputAsset for EcmascriptBuildNodeEntryChunk {
#[turbo_tasks::function] #[turbo_tasks::function]
async fn references(self: Vc<Self>) -> Result<Vc<OutputAssets>> { async fn references(self: Vc<Self>) -> Result<Vc<OutputAssets>> {
let this = self.await?; let this = self.await?;
let mut references = vec![Vc::upcast(self.runtime_chunk())]; let mut references = vec![ResolvedVc::upcast(
self.runtime_chunk().to_resolved().await?,
)];
if *this if *this
.chunking_context .chunking_context
.reference_chunk_source_maps(Vc::upcast(self)) .reference_chunk_source_maps(Vc::upcast(self))
.await? .await?
{ {
references.push(Vc::upcast(SourceMapAsset::new(Vc::upcast(self)))) references.push(ResolvedVc::upcast(
SourceMapAsset::new(Vc::upcast(self)).to_resolved().await?,
))
} }
let other_chunks = this.other_chunks.await?; let other_chunks = this.other_chunks.await?;
for &other_chunk in &*other_chunks { for &other_chunk in &*other_chunks {
references.push(Vc::upcast(other_chunk)); references.push(ResolvedVc::upcast(other_chunk));
} }
Ok(Vc::cell(references)) Ok(Vc::cell(references))
......
...@@ -2,7 +2,7 @@ use std::io::Write; ...@@ -2,7 +2,7 @@ use std::io::Write;
use anyhow::{bail, Result}; use anyhow::{bail, Result};
use indoc::writedoc; use indoc::writedoc;
use turbo_tasks::{RcStr, ValueToString, Vc}; use turbo_tasks::{RcStr, ResolvedVc, ValueToString, Vc};
use turbo_tasks_fs::{File, FileSystem}; use turbo_tasks_fs::{File, FileSystem};
use turbopack_core::{ use turbopack_core::{
asset::{Asset, AssetContent}, asset::{Asset, AssetContent},
...@@ -119,7 +119,9 @@ impl OutputAsset for EcmascriptBuildNodeRuntimeChunk { ...@@ -119,7 +119,9 @@ impl OutputAsset for EcmascriptBuildNodeRuntimeChunk {
.reference_chunk_source_maps(Vc::upcast(self)) .reference_chunk_source_maps(Vc::upcast(self))
.await? .await?
{ {
references.push(Vc::upcast(SourceMapAsset::new(Vc::upcast(self)))) references.push(ResolvedVc::upcast(
SourceMapAsset::new(Vc::upcast(self)).to_resolved().await?,
))
} }
Ok(Vc::cell(references)) Ok(Vc::cell(references))
......
...@@ -2,7 +2,9 @@ use anyhow::Result; ...@@ -2,7 +2,9 @@ use anyhow::Result;
use lazy_static::lazy_static; use lazy_static::lazy_static;
use regex::Regex; use regex::Regex;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use turbo_tasks::{FxIndexMap, RcStr, TryFlatJoinIterExt, ValueToString, Vc}; use turbo_tasks::{
FxIndexMap, RcStr, ResolvedVc, TryFlatJoinIterExt, TryJoinIterExt, ValueToString, Vc,
};
use turbo_tasks_fs::{ use turbo_tasks_fs::{
glob::Glob, json::parse_json_rope_with_source_context, DirectoryEntry, FileContent, glob::Glob, json::parse_json_rope_with_source_context, DirectoryEntry, FileContent,
FileSystemEntryType, FileSystemPath, FileSystemEntryType, FileSystemPath,
...@@ -195,19 +197,26 @@ pub async fn resolve_node_pre_gyp_files( ...@@ -195,19 +197,26 @@ pub async fn resolve_node_pre_gyp_files(
} }
} }
return Ok(ModuleResolveResult::modules_with_affecting_sources( return Ok(ModuleResolveResult::modules_with_affecting_sources(
sources.into_iter().map(|(key, source)| { sources
(RequestKey::new(key), Vc::upcast(RawModule::new(source))) .into_iter()
}), .map(|(key, source)| async move {
Ok((
RequestKey::new(key),
ResolvedVc::upcast(RawModule::new(source).to_resolved().await?),
))
})
.try_join()
.await?,
affecting_paths affecting_paths
.into_iter() .into_iter()
.map(|p| Vc::upcast(FileSource::new(p))) .map(|p| Vc::upcast(FileSource::new(p)))
.collect(), .collect(),
) )
.into()); .cell());
} }
}; };
} }
Ok(ModuleResolveResult::unresolvable().into()) Ok(ModuleResolveResult::unresolvable().cell())
} }
#[turbo_tasks::value] #[turbo_tasks::value]
...@@ -293,9 +302,19 @@ pub async fn resolve_node_gyp_build_files( ...@@ -293,9 +302,19 @@ pub async fn resolve_node_gyp_build_files(
} }
if !resolved.is_empty() { if !resolved.is_empty() {
return Ok(ModuleResolveResult::modules_with_affecting_sources( return Ok(ModuleResolveResult::modules_with_affecting_sources(
resolved.into_iter().map(|(key, source)| { resolved
(RequestKey::new(key), Vc::upcast(RawModule::new(source))) .into_iter()
}), .map(|(key, source)| async move {
Ok((
RequestKey::new(key),
ResolvedVc::upcast(
RawModule::new(source).to_resolved().await?,
),
))
})
.try_join()
.await?
.into_iter(),
merged_affecting_sources, merged_affecting_sources,
) )
.into()); .into());
...@@ -401,7 +420,11 @@ pub async fn resolve_node_bindings_files( ...@@ -401,7 +420,11 @@ pub async fn resolve_node_bindings_files(
if matches!(*path.get_type().await?, FileSystemEntryType::File) { if matches!(*path.get_type().await?, FileSystemEntryType::File) {
Some(( Some((
RequestKey::new(sub_path), RequestKey::new(sub_path),
Vc::upcast(RawModule::new(Vc::upcast(FileSource::new(path)))), ResolvedVc::upcast(
RawModule::new(Vc::upcast(FileSource::new(path)))
.to_resolved()
.await?,
),
)) ))
} else { } else {
None None
......
...@@ -14,7 +14,8 @@ use dunce::canonicalize; ...@@ -14,7 +14,8 @@ use dunce::canonicalize;
use serde::Deserialize; use serde::Deserialize;
use serde_json::json; use serde_json::json;
use turbo_tasks::{ use turbo_tasks::{
RcStr, ReadConsistency, ReadRef, TryJoinIterExt, TurboTasks, Value, ValueToString, Vc, RcStr, ReadConsistency, ReadRef, ResolvedVc, TryJoinIterExt, TurboTasks, Value, ValueToString,
Vc,
}; };
use turbo_tasks_env::DotenvProcessEnv; use turbo_tasks_env::DotenvProcessEnv;
use turbo_tasks_fs::{ use turbo_tasks_fs::{
...@@ -440,10 +441,10 @@ async fn run_test(resource: RcStr) -> Result<Vc<FileSystemPath>> { ...@@ -440,10 +441,10 @@ async fn run_test(resource: RcStr) -> Result<Vc<FileSystemPath>> {
} }
async fn walk_asset( async fn walk_asset(
asset: Vc<Box<dyn OutputAsset>>, asset: ResolvedVc<Box<dyn OutputAsset>>,
output_path: &ReadRef<FileSystemPath>, output_path: &ReadRef<FileSystemPath>,
seen: &mut HashSet<Vc<FileSystemPath>>, seen: &mut HashSet<Vc<FileSystemPath>>,
queue: &mut VecDeque<Vc<Box<dyn OutputAsset>>>, queue: &mut VecDeque<ResolvedVc<Box<dyn OutputAsset>>>,
) -> Result<()> { ) -> Result<()> {
let path = asset.ident().path().resolve().await?; let path = asset.ident().path().resolve().await?;
...@@ -463,7 +464,7 @@ async fn walk_asset( ...@@ -463,7 +464,7 @@ async fn walk_asset(
.iter() .iter()
.copied() .copied()
.map(|asset| async move { .map(|asset| async move {
Ok(Vc::try_resolve_downcast::<Box<dyn OutputAsset>>(asset).await?) Ok(ResolvedVc::try_downcast::<Box<dyn OutputAsset>>(asset).await?)
}) })
.try_join() .try_join()
.await? .await?
......
...@@ -164,7 +164,7 @@ async fn apply_module_type( ...@@ -164,7 +164,7 @@ async fn apply_module_type(
} }
if runtime_code { if runtime_code {
Vc::upcast(builder.build()) ResolvedVc::upcast(builder.build().to_resolved().await?)
} else { } else {
let module = builder.build(); let module = builder.build();
let part_ref = if let Some(part) = part { let part_ref = if let Some(part) = part {
...@@ -246,47 +246,64 @@ async fn apply_module_type( ...@@ -246,47 +246,64 @@ async fn apply_module_type(
} }
None => Vc::upcast(module), None => Vc::upcast(module),
} }
.to_resolved()
.await?
} }
} }
ModuleType::Json => Vc::upcast(JsonModuleAsset::new(source)), ModuleType::Json => ResolvedVc::upcast(JsonModuleAsset::new(source).to_resolved().await?),
ModuleType::Raw => Vc::upcast(RawModule::new(source)), ModuleType::Raw => ResolvedVc::upcast(RawModule::new(source).to_resolved().await?),
ModuleType::CssGlobal => { ModuleType::CssGlobal => {
return Ok(module_asset_context.process( return Ok(module_asset_context.process(
source, source,
Value::new(ReferenceType::Css(CssReferenceSubType::Internal)), Value::new(ReferenceType::Css(CssReferenceSubType::Internal)),
)) ))
} }
ModuleType::CssModule => Vc::upcast(ModuleCssAsset::new( ModuleType::CssModule => ResolvedVc::upcast(
source, ModuleCssAsset::new(source, Vc::upcast(module_asset_context))
Vc::upcast(module_asset_context), .to_resolved()
)), .await?,
ModuleType::Css { ty, use_swc_css } => Vc::upcast(CssModuleAsset::new( ),
source, ModuleType::Css { ty, use_swc_css } => ResolvedVc::upcast(
Vc::upcast(module_asset_context), CssModuleAsset::new(
*ty, source,
module_asset_context Vc::upcast(module_asset_context),
.module_options_context() *ty,
module_asset_context
.module_options_context()
.await?
.css
.minify_type,
*use_swc_css,
if let ReferenceType::Css(CssReferenceSubType::AtImport(import)) =
reference_type.into_value()
{
import
} else {
None
},
)
.to_resolved()
.await?,
),
ModuleType::Static => ResolvedVc::upcast(
StaticModuleAsset::new(source, Vc::upcast(module_asset_context))
.to_resolved()
.await?,
),
ModuleType::WebAssembly { source_ty } => ResolvedVc::upcast(
WebAssemblyModuleAsset::new(
WebAssemblySource::new(source, *source_ty),
Vc::upcast(module_asset_context),
)
.to_resolved()
.await?,
),
ModuleType::Custom(custom) => {
custom
.create_module(source, module_asset_context, part)
.to_resolved()
.await? .await?
.css }
.minify_type,
*use_swc_css,
if let ReferenceType::Css(CssReferenceSubType::AtImport(import)) =
reference_type.into_value()
{
import
} else {
None
},
)),
ModuleType::Static => Vc::upcast(StaticModuleAsset::new(
source,
Vc::upcast(module_asset_context),
)),
ModuleType::WebAssembly { source_ty } => Vc::upcast(WebAssemblyModuleAsset::new(
WebAssemblySource::new(source, *source_ty),
Vc::upcast(module_asset_context),
)),
ModuleType::Custom(custom) => custom.create_module(source, module_asset_context, part),
}) })
.cell()) .cell())
} }
...@@ -717,7 +734,9 @@ impl AssetContext for ModuleAssetContext { ...@@ -717,7 +734,9 @@ impl AssetContext for ModuleAssetContext {
self.process_with_transition_rules(source, reference_type) self.process_with_transition_rules(source, reference_type)
}; };
Ok(match *process_result.await? { Ok(match *process_result.await? {
ProcessResult::Module(m) => ModuleResolveResultItem::Module(Vc::upcast(m)), ProcessResult::Module(m) => {
ModuleResolveResultItem::Module(ResolvedVc::upcast(m))
}
ProcessResult::Ignore => ModuleResolveResultItem::Ignore, ProcessResult::Ignore => ModuleResolveResultItem::Ignore,
}) })
} }
...@@ -937,10 +956,10 @@ pub async fn replace_externals( ...@@ -937,10 +956,10 @@ pub async fn replace_externals(
}; };
let module = CachedExternalModule::new(request.clone(), external_type) let module = CachedExternalModule::new(request.clone(), external_type)
.resolve() .to_resolved()
.await?; .await?;
*item = ModuleResolveResultItem::Module(Vc::upcast(module)); *item = ModuleResolveResultItem::Module(ResolvedVc::upcast(module));
} }
Ok(result) Ok(result)
......
use std::hash::Hash; use std::hash::Hash;
use anyhow::Result; use anyhow::Result;
use turbo_tasks::Vc; use turbo_tasks::{ResolvedVc, Vc};
use turbo_tasks_fs::FileSystemPath; use turbo_tasks_fs::FileSystemPath;
use turbopack_core::{ use turbopack_core::{
asset::{Asset, AssetContent}, asset::{Asset, AssetContent},
...@@ -55,11 +55,11 @@ impl OutputAsset for RebasedAsset { ...@@ -55,11 +55,11 @@ impl OutputAsset for RebasedAsset {
.await? .await?
.iter() .iter()
{ {
references.push(Vc::upcast(RebasedAsset::new( references.push(ResolvedVc::upcast(
*module, RebasedAsset::new(*module, self.input_dir, self.output_dir)
self.input_dir, .to_resolved()
self.output_dir, .await?,
))); ));
} }
Ok(Vc::cell(references)) Ok(Vc::cell(references))
} }
......
...@@ -93,9 +93,11 @@ pub trait Transition { ...@@ -93,9 +93,11 @@ pub trait Transition {
let module_asset_context = self.process_context(module_asset_context); let module_asset_context = self.process_context(module_asset_context);
let m = module_asset_context.process_default(asset, reference_type); let m = module_asset_context.process_default(asset, reference_type);
Ok(match *m.await? { Ok(match *m.await? {
ProcessResult::Module(m) => { ProcessResult::Module(m) => ProcessResult::Module(
ProcessResult::Module(self.process_module(m, module_asset_context)) self.process_module(*m, module_asset_context)
} .to_resolved()
.await?,
),
ProcessResult::Ignore => ProcessResult::Ignore, ProcessResult::Ignore => ProcessResult::Ignore,
} }
.cell()) .cell())
......
...@@ -29,7 +29,9 @@ use rstest_reuse::{ ...@@ -29,7 +29,9 @@ use rstest_reuse::{
}; };
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use tokio::{process::Command, time::timeout}; use tokio::{process::Command, time::timeout};
use turbo_tasks::{backend::Backend, RcStr, ReadRef, TurboTasks, Value, ValueToString, Vc}; use turbo_tasks::{
backend::Backend, RcStr, ReadRef, ResolvedVc, TurboTasks, Value, ValueToString, Vc,
};
use turbo_tasks_fs::{DiskFileSystem, FileSystem, FileSystemPath}; use turbo_tasks_fs::{DiskFileSystem, FileSystem, FileSystemPath};
use turbo_tasks_memory::MemoryBackend; use turbo_tasks_memory::MemoryBackend;
use turbopack::{ use turbopack::{
...@@ -452,14 +454,16 @@ fn node_file_trace<B: Backend + 'static>( ...@@ -452,14 +454,16 @@ fn node_file_trace<B: Backend + 'static>(
let module = module_asset_context let module = module_asset_context
.process(Vc::upcast(source), Value::new(ReferenceType::Undefined)) .process(Vc::upcast(source), Value::new(ReferenceType::Undefined))
.module(); .module();
let rebased = RebasedAsset::new(Vc::upcast(module), *input_dir, output_dir); let rebased = RebasedAsset::new(Vc::upcast(module), *input_dir, output_dir)
.to_resolved()
.await?;
#[cfg(not(feature = "bench_against_node_nft"))] #[cfg(not(feature = "bench_against_node_nft"))]
let output_path = rebased.ident().path(); let output_path = rebased.ident().path();
print_graph(Vc::upcast(rebased)).await?; print_graph(ResolvedVc::upcast(rebased)).await?;
emit_with_completion(Vc::upcast(rebased), output_dir).await?; emit_with_completion(*ResolvedVc::upcast(rebased), output_dir).await?;
#[cfg(not(feature = "bench_against_node_nft"))] #[cfg(not(feature = "bench_against_node_nft"))]
{ {
...@@ -748,7 +752,7 @@ impl std::str::FromStr for CaseInput { ...@@ -748,7 +752,7 @@ impl std::str::FromStr for CaseInput {
} }
} }
async fn print_graph(asset: Vc<Box<dyn OutputAsset>>) -> Result<()> { async fn print_graph(asset: ResolvedVc<Box<dyn OutputAsset>>) -> Result<()> {
let mut visited = HashSet::new(); let mut visited = HashSet::new();
let mut queue = Vec::new(); let mut queue = Vec::new();
queue.push((0, asset)); queue.push((0, asset));
......
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