Unverified Commit 8643014b authored by Tobias Koppers's avatar Tobias Koppers Committed by GitHub

turbopack: Module Trait (#52401)

### What?

refactoring see https://github.com/vercel/turbo/pull/5477

---------
Co-authored-by: 's avatarkodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
parent 73e2979c
This diff is collapsed.
......@@ -42,11 +42,11 @@ swc_core = { version = "0.79.13" }
testing = { version = "0.33.20" }
# Turbo crates
turbopack-binding = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-230707.3" }
turbopack-binding = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-230710.2" }
# [TODO]: need to refactor embed_directory! macro usages, as well as resolving turbo_tasks::function, macros..
turbo-tasks = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-230707.3" }
turbo-tasks = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-230710.2" }
# [TODO]: need to refactor embed_directory! macro usage in next-core
turbo-tasks-fs = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-230707.3" }
turbo-tasks-fs = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-230710.2" }
# General Deps
......
......@@ -11,7 +11,7 @@ use turbopack_binding::{
turbopack::{
core::{
asset::AssetVc,
chunk::{ChunkableAsset, ChunkingContext, ChunkingContextVc},
chunk::{ChunkableModule, ChunkingContext, ChunkingContextVc},
context::{AssetContext, AssetContextVc},
reference_type::ReferenceType,
},
......@@ -70,8 +70,11 @@ impl PagesBuildClientContextVc {
let this = self.await?;
let client_asset_page = this.client_asset_context.process(asset, reference_type);
let client_asset_page =
create_page_loader_entry_asset(this.client_asset_context, client_asset_page, pathname);
let client_asset_page = create_page_loader_entry_asset(
this.client_asset_context,
client_asset_page.into(),
pathname,
);
let Some(client_module_asset) =
EcmascriptModuleAssetVc::resolve_from(client_asset_page).await?
......
......@@ -10,8 +10,8 @@
"check": "tsc --noEmit"
},
"dependencies": {
"@vercel/turbopack-ecmascript-runtime": "https://gitpkg-fork.vercel.sh/vercel/turbo/crates/turbopack-ecmascript-runtime/js?turbopack-230707.3",
"@vercel/turbopack-node": "https://gitpkg-fork.vercel.sh/vercel/turbo/crates/turbopack-node/js?turbopack-230707.3",
"@vercel/turbopack-ecmascript-runtime": "https://gitpkg-fork.vercel.sh/vercel/turbo/crates/turbopack-ecmascript-runtime/js?turbopack-230710.2",
"@vercel/turbopack-node": "https://gitpkg-fork.vercel.sh/vercel/turbo/crates/turbopack-node/js?turbopack-230710.2",
"anser": "^2.1.1",
"css.escape": "^1.5.1",
"next": "*",
......
......@@ -2,7 +2,7 @@ use anyhow::{bail, Result};
use turbopack_binding::{
turbo::tasks_fs::FileSystemPathVc,
turbopack::{
core::{asset::AssetVc, compile_time_info::CompileTimeInfoVc},
core::{compile_time_info::CompileTimeInfoVc, module::ModuleVc},
ecmascript::chunk::EcmascriptChunkPlaceableVc,
turbopack::{
module_options::ModuleOptionsContextVc,
......@@ -55,10 +55,10 @@ impl Transition for NextServerComponentTransition {
#[turbo_tasks::function]
async fn process_module(
&self,
asset: AssetVc,
module: ModuleVc,
_context: ModuleAssetContextVc,
) -> Result<AssetVc> {
let Some(asset) = EcmascriptChunkPlaceableVc::resolve_from(asset).await? else {
) -> Result<ModuleVc> {
let Some(asset) = EcmascriptChunkPlaceableVc::resolve_from(module).await? else {
bail!("Not an ecmascript module");
};
......
......@@ -17,6 +17,7 @@ use turbopack_binding::turbopack::{
issue::{
Issue, IssueSeverity, IssueSeverityVc, IssueSourceVc, IssueVc, OptionIssueSourceVc,
},
module::ModuleVc,
reference_type::{EcmaScriptModulesReferenceSubType, ReferenceType},
source_asset::SourceAssetVc,
},
......@@ -211,7 +212,7 @@ impl Issue for NextSegmentConfigParsingIssue {
#[turbo_tasks::function]
pub async fn parse_segment_config_from_source(
module_asset: AssetVc,
module_asset: ModuleVc,
) -> Result<NextSegmentConfigVc> {
let Some(ecmascript_asset) = EcmascriptModuleAssetVc::resolve_from(module_asset).await? else {
return Ok(NextSegmentConfigVc::default());
......@@ -256,7 +257,7 @@ fn issue_source(source: AssetVc, span: Span) -> IssueSourceVc {
}
fn parse_config_value(
module_asset: AssetVc,
module: ModuleVc,
config: &mut NextSegmentConfig,
ident: &Ident,
init: &Expr,
......@@ -266,9 +267,9 @@ fn parse_config_value(
let invalid_config = |detail: &str, value: &JsValue| {
let (explainer, hints) = value.explain(2, 0);
NextSegmentConfigParsingIssue {
ident: module_asset.ident(),
ident: module.ident(),
detail: StringVc::cell(format!("{detail} Got {explainer}.{hints}")),
source: issue_source(module_asset, span),
source: issue_source(module.into(), span),
}
.cell()
.as_issue()
......
......@@ -872,12 +872,16 @@ import {}, {{ chunks as {} }} from "COMPONENT_{}";
state.inner_assets.insert(
format!("COMPONENT_{i}"),
state.context.with_transition(state.rsc_transition).process(
SourceAssetVc::new(component).into(),
Value::new(ReferenceType::EcmaScriptModules(
EcmaScriptModulesReferenceSubType::Undefined,
)),
),
state
.context
.with_transition(state.rsc_transition)
.process(
SourceAssetVc::new(component).into(),
Value::new(ReferenceType::EcmaScriptModules(
EcmaScriptModulesReferenceSubType::Undefined,
)),
)
.into(),
);
}
Ok(())
......@@ -978,7 +982,8 @@ import {}, {{ chunks as {} }} from "COMPONENT_{}";
SourceAssetVc::new(*path).into(),
BlurPlaceholderMode::None,
state.context,
),
)
.into(),
);
writeln!(state.loader_tree_code, "{s}(async (props) => [{{")?;
writeln!(state.loader_tree_code, "{s} url: {identifier}.src,")?;
......@@ -1000,11 +1005,16 @@ import {}, {{ chunks as {} }} from "COMPONENT_{}";
.push(format!("import {identifier} from \"{inner_module_id}\";"));
state.inner_assets.insert(
inner_module_id,
state.context.process(
TextContentSourceAssetVc::new(SourceAssetVc::new(*alt_path).into())
state
.context
.process(
TextContentSourceAssetVc::new(
SourceAssetVc::new(*alt_path).into(),
)
.into(),
Value::new(ReferenceType::Internal(InnerAssetsVc::empty())),
),
Value::new(ReferenceType::Internal(InnerAssetsVc::empty())),
)
.into(),
);
writeln!(state.loader_tree_code, "{s} alt: {identifier},")?;
}
......@@ -1125,13 +1135,13 @@ import {}, {{ chunks as {} }} from "COMPONENT_{}";
"APP_ENTRY".to_string() => context.with_transition(rsc_transition).process(
asset.into(),
Value::new(ReferenceType::Internal(InnerAssetsVc::cell(inner_assets))),
),
).into(),
"APP_BOOTSTRAP".to_string() => context.with_transition("next-client").process(
SourceAssetVc::new(next_js_file_path("entry/app/hydrate.tsx")).into(),
Value::new(ReferenceType::EcmaScriptModules(
EcmaScriptModulesReferenceSubType::Undefined,
)),
),
).into(),
}))),
),
Some(NextRuntime::Edge) =>
......@@ -1141,7 +1151,7 @@ import {}, {{ chunks as {} }} from "COMPONENT_{}";
"INNER_EDGE_CHUNK_GROUP".to_string() => context.with_transition("next-edge-page").process(
asset.into(),
Value::new(ReferenceType::Internal(InnerAssetsVc::cell(inner_assets))),
),
).into(),
}))),
)
};
......@@ -1225,7 +1235,7 @@ impl AppRouteVc {
let bootstrap_asset = next_asset("entry/app/route.ts");
route_bootstrap(
entry_asset,
entry_asset.into(),
this.context.into(),
this.project_path,
bootstrap_asset,
......@@ -1243,7 +1253,7 @@ impl AppRouteVc {
let module = this.context.process(
internal_asset,
Value::new(ReferenceType::Internal(InnerAssetsVc::cell(indexmap! {
"ROUTE_CHUNK_GROUP".to_string() => entry
"ROUTE_CHUNK_GROUP".to_string() => entry.into()
}))),
);
......
......@@ -122,7 +122,7 @@ pub async fn bootstrap(
let mut inner_assets = inner_assets.await?.clone_value();
inner_assets.insert("ENTRY".to_string(), asset);
inner_assets.insert("BOOTSTRAP_CONFIG".to_string(), config_asset);
inner_assets.insert("BOOTSTRAP_CONFIG".to_string(), config_asset.into());
let asset = context.process(
bootstrap_asset,
......
......@@ -3,10 +3,10 @@ use indexmap::indexmap;
use turbo_tasks::Value;
use turbopack_binding::turbopack::{
core::{
asset::AssetVc,
chunk::{ChunkingContext, ChunkingContextVc},
compile_time_info::CompileTimeInfoVc,
context::AssetContext,
module::ModuleVc,
reference_type::{InnerAssetsVc, ReferenceType},
},
ecmascript::chunk::EcmascriptChunkPlaceableVc,
......@@ -66,16 +66,16 @@ impl Transition for NextClientTransition {
#[turbo_tasks::function]
async fn process_module(
&self,
asset: AssetVc,
asset: ModuleVc,
context: ModuleAssetContextVc,
) -> Result<AssetVc> {
) -> Result<ModuleVc> {
let asset = if !self.is_app {
let internal_asset = next_asset("entry/next-hydrate.tsx");
context.process(
internal_asset,
Value::new(ReferenceType::Internal(InnerAssetsVc::cell(indexmap! {
"PAGE".to_string() => asset
"PAGE".to_string() => asset.into()
}))),
)
} else {
......@@ -88,7 +88,7 @@ impl Transition for NextClientTransition {
let runtime_entries = self.runtime_entries.resolve_entries(context.into());
let asset = ChunkGroupFilesAsset {
asset: asset.into(),
module: asset.into(),
// This ensures that the chunk group files asset will strip out the _next prefix from
// all chunk paths, which is what the Next.js renderer code expects.
client_root: self.client_chunking_context.output_root().join("_next"),
......
......@@ -3,7 +3,7 @@ use turbo_tasks::Value;
use turbopack_binding::{
turbo::tasks_fs::FileSystemPathVc,
turbopack::{
core::{asset::AssetVc, chunk::ChunkingContextVc, compile_time_info::CompileTimeInfoVc},
core::{chunk::ChunkingContextVc, compile_time_info::CompileTimeInfoVc, module::ModuleVc},
node::execution_context::ExecutionContextVc,
turbopack::{
ecmascript::chunk::EcmascriptChunkPlaceableVc,
......@@ -106,9 +106,9 @@ impl Transition for NextClientChunksTransition {
#[turbo_tasks::function]
async fn process_module(
&self,
asset: AssetVc,
asset: ModuleVc,
_context: ModuleAssetContextVc,
) -> Result<AssetVc> {
) -> Result<ModuleVc> {
Ok(
if let Some(placeable) = EcmascriptChunkPlaceableVc::resolve_from(asset).await? {
WithChunksAsset {
......
......@@ -4,10 +4,11 @@ use turbopack_binding::turbopack::{
core::{
asset::{Asset, AssetContentVc, AssetVc},
chunk::{
availability_info::AvailabilityInfo, ChunkVc, ChunkableAsset, ChunkableAssetVc,
availability_info::AvailabilityInfo, ChunkVc, ChunkableModule, ChunkableModuleVc,
ChunkingContextVc,
},
ident::AssetIdentVc,
module::{Module, ModuleVc},
reference::AssetReferencesVc,
},
ecmascript::chunk::EcmascriptChunkingContextVc,
......@@ -47,7 +48,10 @@ impl Asset for InChunkingContextAsset {
}
#[turbo_tasks::value_impl]
impl ChunkableAsset for InChunkingContextAsset {
impl Module for InChunkingContextAsset {}
#[turbo_tasks::value_impl]
impl ChunkableModule for InChunkingContextAsset {
#[turbo_tasks::function]
fn as_chunk(
&self,
......
......@@ -12,10 +12,11 @@ use turbopack_binding::{
asset::{Asset, AssetContentVc, AssetVc, AssetsVc},
chunk::{
availability_info::AvailabilityInfo, ChunkDataVc, ChunkGroupReferenceVc, ChunkItem,
ChunkItemVc, ChunkVc, ChunkableAsset, ChunkableAssetVc, ChunkingContext,
ChunkItemVc, ChunkVc, ChunkableModule, ChunkableModuleVc, ChunkingContext,
ChunkingContextVc, ChunksDataVc,
},
ident::AssetIdentVc,
module::{Module, ModuleVc},
reference::AssetReferencesVc,
},
ecmascript::{
......@@ -67,7 +68,10 @@ impl Asset for WithChunksAsset {
}
#[turbo_tasks::value_impl]
impl ChunkableAsset for WithChunksAsset {
impl Module for WithChunksAsset {}
#[turbo_tasks::value_impl]
impl ChunkableModule for WithChunksAsset {
#[turbo_tasks::function]
fn as_chunk(
self_vc: WithChunksAssetVc,
......
......@@ -5,6 +5,7 @@ use turbopack_binding::turbopack::{
core::{
asset::AssetVc,
context::AssetContext,
module::ModuleVc,
reference_type::{EntryReferenceSubType, InnerAssetsVc, ReferenceType},
},
turbopack::{
......@@ -28,7 +29,7 @@ impl Transition for NextServerToClientTransition {
asset: AssetVc,
context: ModuleAssetContextVc,
_reference_type: Value<ReferenceType>,
) -> Result<AssetVc> {
) -> Result<ModuleVc> {
let internal_asset = next_asset(if self_vc.await?.ssr {
"entry/app/server-to-client-ssr.tsx"
} else {
......@@ -50,8 +51,8 @@ impl Transition for NextServerToClientTransition {
Ok(context.process(
internal_asset,
Value::new(ReferenceType::Internal(InnerAssetsVc::cell(indexmap! {
"CLIENT_MODULE".to_string() => client_module,
"CLIENT_CHUNKS".to_string() => client_chunks,
"CLIENT_MODULE".to_string() => client_module.into(),
"CLIENT_CHUNKS".to_string() => client_chunks.into(),
}))),
))
}
......
use anyhow::Result;
use turbopack_binding::turbopack::{
core::{asset::AssetVc, compile_time_info::CompileTimeInfoVc},
core::{compile_time_info::CompileTimeInfoVc, module::ModuleVc},
turbopack::{
ecmascript::chunk::EcmascriptChunkPlaceableVc,
module_options::ModuleOptionsContextVc,
......@@ -48,9 +48,9 @@ impl Transition for NextSSRClientModuleTransition {
#[turbo_tasks::function]
async fn process_module(
&self,
asset: AssetVc,
asset: ModuleVc,
_context: ModuleAssetContextVc,
) -> Result<AssetVc> {
) -> Result<ModuleVc> {
Ok(
if let Some(placeable) = EcmascriptChunkPlaceableVc::resolve_from(asset).await? {
WithChunkingContextScopeAsset {
......
......@@ -4,10 +4,11 @@ use turbopack_binding::turbopack::{
core::{
asset::{Asset, AssetContentVc, AssetVc},
chunk::{
availability_info::AvailabilityInfo, ChunkVc, ChunkableAsset, ChunkableAssetVc,
availability_info::AvailabilityInfo, ChunkVc, ChunkableModule, ChunkableModuleVc,
ChunkingContext, ChunkingContextVc,
},
ident::AssetIdentVc,
module::{Module, ModuleVc},
reference::AssetReferencesVc,
},
ecmascript::chunk::EcmascriptChunkingContextVc,
......@@ -47,7 +48,10 @@ impl Asset for WithChunkingContextScopeAsset {
}
#[turbo_tasks::value_impl]
impl ChunkableAsset for WithChunkingContextScopeAsset {
impl Module for WithChunkingContextScopeAsset {}
#[turbo_tasks::value_impl]
impl ChunkableModule for WithChunkingContextScopeAsset {
#[turbo_tasks::function]
fn as_chunk(
&self,
......
......@@ -8,11 +8,12 @@ use turbopack_binding::{
asset::{Asset, AssetContentVc, AssetVc, AssetsVc},
chunk::{
availability_info::AvailabilityInfo, ChunkDataVc, ChunkItem, ChunkItemVc, ChunkVc,
ChunkableAsset, ChunkableAssetReference, ChunkableAssetReferenceVc,
ChunkableAssetVc, ChunkingContext, ChunkingContextVc, ChunkingType,
ChunkableModule, ChunkableModuleReference, ChunkableModuleReferenceVc,
ChunkableModuleVc, ChunkingContext, ChunkingContextVc, ChunkingType,
ChunkingTypeOptionVc, ChunksDataVc,
},
ident::AssetIdentVc,
module::{Module, ModuleVc},
proxied_asset::ProxiedAssetVc,
reference::{
AssetReference, AssetReferenceVc, AssetReferencesVc, SingleAssetReferenceVc,
......@@ -66,7 +67,10 @@ impl Asset for WithClientChunksAsset {
}
#[turbo_tasks::value_impl]
impl ChunkableAsset for WithClientChunksAsset {
impl Module for WithClientChunksAsset {}
#[turbo_tasks::value_impl]
impl ChunkableModule for WithClientChunksAsset {
#[turbo_tasks::function]
fn as_chunk(
self_vc: WithClientChunksAssetVc,
......@@ -257,7 +261,7 @@ impl AssetReference for WithClientChunksAssetReference {
}
#[turbo_tasks::value_impl]
impl ChunkableAssetReference for WithClientChunksAssetReference {
impl ChunkableModuleReference for WithClientChunksAssetReference {
#[turbo_tasks::function]
fn chunking_type(&self) -> ChunkingTypeOptionVc {
ChunkingTypeOptionVc::cell(Some(ChunkingType::IsolatedParallel))
......
......@@ -684,14 +684,14 @@ pub async fn load_next_config_internal(
config_asset.into(),
Value::new(ReferenceType::Internal(InnerAssetsVc::empty())),
);
any_content_changed(config_asset)
any_content_changed(config_asset.into())
});
let load_next_config_asset = context.process(
next_asset("entry/config/next.js"),
Value::new(ReferenceType::Entry(EntryReferenceSubType::Undefined)),
);
let config_value = evaluate(
load_next_config_asset,
load_next_config_asset.into(),
project_path,
env,
config_asset.map_or_else(|| AssetIdentVc::from_path(project_path), |c| c.ident()),
......
......@@ -6,9 +6,10 @@ use turbopack_binding::{
turbopack::{
core::{
asset::AssetVc,
chunk::{ChunkableAssetVc, ChunkingContextVc},
chunk::{ChunkableModuleVc, ChunkingContextVc},
compile_time_info::CompileTimeInfoVc,
context::AssetContext,
module::ModuleVc,
reference_type::{EcmaScriptModulesReferenceSubType, InnerAssetsVc, ReferenceType},
source_asset::SourceAssetVc,
},
......@@ -68,28 +69,28 @@ impl Transition for NextEdgePageTransition {
#[turbo_tasks::function]
async fn process_module(
&self,
asset: AssetVc,
asset: ModuleVc,
context: ModuleAssetContextVc,
) -> Result<AssetVc> {
let asset = context.process(
) -> Result<ModuleVc> {
let module = context.process(
self.bootstrap_asset,
Value::new(ReferenceType::Internal(InnerAssetsVc::cell(indexmap! {
"APP_ENTRY".to_string() => asset,
"APP_ENTRY".to_string() => asset.into(),
"APP_BOOTSTRAP".to_string() => context.with_transition("next-client").process(
SourceAssetVc::new(next_js_file_path("entry/app/hydrate.tsx")).into(),
Value::new(ReferenceType::EcmaScriptModules(
EcmaScriptModulesReferenceSubType::Undefined,
)),
),
).into(),
}))),
);
let Some(asset) = ChunkableAssetVc::resolve_from(asset).await? else {
bail!("Internal module is not evaluatable");
let Some(module) = ChunkableModuleVc::resolve_from(module).await? else {
bail!("Internal module is not chunkable");
};
let asset = ChunkGroupFilesAsset {
asset,
module,
client_root: self.output_path,
chunking_context: self.edge_chunking_context,
runtime_entries: None,
......
......@@ -3,7 +3,10 @@ use indexmap::indexmap;
use turbopack_binding::{
turbo::tasks_fs::FileSystemPathVc,
turbopack::{
core::{asset::AssetVc, chunk::ChunkingContextVc, compile_time_info::CompileTimeInfoVc},
core::{
asset::AssetVc, chunk::ChunkingContextVc, compile_time_info::CompileTimeInfoVc,
module::ModuleVc,
},
ecmascript::chunk_group_files_asset::ChunkGroupFilesAsset,
turbopack::{
module_options::ModuleOptionsContextVc,
......@@ -57,11 +60,11 @@ impl Transition for NextEdgeRouteTransition {
#[turbo_tasks::function]
async fn process_module(
&self,
asset: AssetVc,
asset: ModuleVc,
context: ModuleAssetContextVc,
) -> Result<AssetVc> {
) -> Result<ModuleVc> {
let new_asset = route_bootstrap(
asset,
asset.into(),
context.into(),
self.base_path,
self.bootstrap_asset,
......@@ -71,7 +74,7 @@ impl Transition for NextEdgeRouteTransition {
);
let asset = ChunkGroupFilesAsset {
asset: new_asset.into(),
module: new_asset.into(),
client_root: self.output_path,
chunking_context: self.edge_chunking_context,
runtime_entries: None,
......
......@@ -458,7 +458,7 @@ async fn get_mock_stylesheet(
let root = mock_fs.root();
let val = evaluate(
mocked_response_asset,
mocked_response_asset.into(),
root,
env,
AssetIdentVc::from_path(loader_path),
......
......@@ -6,6 +6,7 @@ use turbopack_binding::{
core::{
asset::AssetVc,
context::AssetContext,
module::ModuleVc,
reference_type::{InnerAssetsVc, ReferenceType},
resolve::ModulePartVc,
},
......@@ -47,7 +48,7 @@ impl StructuredImageModuleType {
source: AssetVc,
blur_placeholder_mode: BlurPlaceholderMode,
context: ModuleAssetContextVc,
) -> AssetVc {
) -> ModuleVc {
let static_asset = StaticModuleAssetVc::new(source, context.into());
context.process(
StructuredImageSourceAsset {
......@@ -81,7 +82,7 @@ impl CustomModuleType for StructuredImageModuleType {
source: AssetVc,
context: ModuleAssetContextVc,
_part: Option<ModulePartVc>,
) -> AssetVc {
) -> ModuleVc {
StructuredImageModuleType::create_module(source, self.blur_placeholder_mode, context)
}
}
......@@ -9,11 +9,12 @@ use turbopack_binding::{
core::{
asset::{Asset, AssetContentVc, AssetVc, AssetsVc},
chunk::{
ChunkDataVc, ChunkableAsset, ChunkingContext, ChunkingContextVc, ChunksDataVc,
ChunkDataVc, ChunkableModule, ChunkingContext, ChunkingContextVc, ChunksDataVc,
EvaluatableAssetVc, EvaluatableAssetsVc,
},
context::{AssetContext, AssetContextVc},
ident::AssetIdentVc,
module::ModuleVc,
reference::{AssetReferencesVc, SingleAssetReferenceVc},
reference_type::{EntryReferenceSubType, InnerAssetsVc, ReferenceType},
virtual_asset::VirtualAssetVc,
......@@ -59,7 +60,7 @@ pub async fn create_page_loader_entry_asset(
client_context: AssetContextVc,
entry_asset: AssetVc,
pathname: StringVc,
) -> Result<AssetVc> {
) -> Result<ModuleVc> {
let mut result = RopeBuilder::default();
writeln!(
result,
......@@ -81,12 +82,13 @@ pub async fn create_page_loader_entry_asset(
Ok(client_context.process(
virtual_asset,
Value::new(ReferenceType::Internal(
InnerAssetsVc::cell(indexmap! {
"PAGE".to_string() => client_context.process(entry_asset, Value::new(ReferenceType::Entry(EntryReferenceSubType::Page)))
})
)))
)
Value::new(ReferenceType::Internal(InnerAssetsVc::cell(indexmap! {
"PAGE".to_string() => client_context.process(
entry_asset,
Value::new(ReferenceType::Entry(EntryReferenceSubType::Page))
).into(),
}))),
))
}
#[turbo_tasks::value_impl]
......
use anyhow::{bail, Result};
use indexmap::indexmap;
use indexmap::{indexmap, IndexMap};
use serde::{Deserialize, Serialize};
use turbo_tasks::{
primitives::{JsonValueVc, StringVc, StringsVc},
......@@ -536,10 +536,12 @@ async fn create_not_found_page_source(
)
};
let entry_asset = server_context.process(
page_asset,
Value::new(ReferenceType::Entry(EntryReferenceSubType::Page)),
);
let entry_asset = server_context
.process(
page_asset,
Value::new(ReferenceType::Entry(EntryReferenceSubType::Page)),
)
.into();
let ssr_entry = SsrEntry {
runtime_entries,
......@@ -802,12 +804,12 @@ impl SsrEntryVc {
} else {
this.ty
};
let (internal_asset, inner_assets) = match ty {
let (internal_asset, inner_assets): (_, IndexMap<_, AssetVc>) = match ty {
SsrType::AutoApi => unreachable!(),
SsrType::Api => (
next_asset("entry/server-api.tsx"),
indexmap! {
"INNER".to_string() => entry_asset_page,
"INNER".to_string() => entry_asset_page.into(),
},
),
SsrType::EdgeApi => {
......@@ -819,14 +821,14 @@ impl SsrEntryVc {
(
next_asset("entry/server-edge-api.tsx"),
indexmap! {
"INNER_EDGE_CHUNK_GROUP".to_string() => entry_asset_edge_chunk_group,
"INNER_EDGE_CHUNK_GROUP".to_string() => entry_asset_edge_chunk_group.into(),
},
)
}
SsrType::Data => (
next_asset("entry/server-data.tsx"),
indexmap! {
"INNER".to_string() => entry_asset_page,
"INNER".to_string() => entry_asset_page.into(),
},
),
SsrType::Html => {
......@@ -838,8 +840,8 @@ impl SsrEntryVc {
(
next_asset("entry/server-renderer.tsx"),
indexmap! {
"INNER".to_string() => entry_asset_page,
"INNER_CLIENT_CHUNK_GROUP".to_string() => entry_asset_client_chunk_group,
"INNER".to_string() => entry_asset_page.into(),
"INNER_CLIENT_CHUNK_GROUP".to_string() => entry_asset_client_chunk_group.into(),
},
)
}
......
......@@ -16,13 +16,13 @@ use turbopack_binding::{
},
turbopack::{
core::{
asset::{AssetOptionVc, AssetVc},
changed::any_content_changed,
chunk::ChunkingContext,
context::{AssetContext, AssetContextVc},
environment::{ServerAddrVc, ServerInfo},
ident::AssetIdentVc,
issue::IssueVc,
module::ModuleVc,
reference_type::{EcmaScriptModulesReferenceSubType, InnerAssetsVc, ReferenceType},
resolve::{find_context_file, FindContextFileResult},
source_asset::SourceAssetVc,
......@@ -137,33 +137,21 @@ pub enum RouterResult {
Error(#[turbo_tasks(trace_ignore)] SharedError),
}
#[turbo_tasks::function]
async fn get_config(
context: AssetContextVc,
project_path: FileSystemPathVc,
configs: StringsVc,
) -> Result<AssetOptionVc> {
let find_config_result = find_context_file(project_path, configs);
let config_asset = match &*find_config_result.await? {
FindContextFileResult::Found(config_path, _) => Some(context.process(
SourceAssetVc::new(*config_path).as_asset(),
Value::new(ReferenceType::Internal(InnerAssetsVc::empty())),
)),
FindContextFileResult::NotFound(_) => None,
};
Ok(AssetOptionVc::cell(config_asset))
}
#[turbo_tasks::function]
async fn next_config_changed(
context: AssetContextVc,
project_path: FileSystemPathVc,
) -> Result<CompletionVc> {
let next_config = get_config(context, project_path, next_configs()).await?;
Ok(if let Some(c) = *next_config {
any_content_changed(c)
} else {
CompletionVc::immutable()
let find_config_result = find_context_file(project_path, next_configs());
Ok(match *find_config_result.await? {
FindContextFileResult::Found(config_path, _) => {
let module = context.process(
SourceAssetVc::new(config_path).as_asset(),
Value::new(ReferenceType::Internal(InnerAssetsVc::empty())),
);
any_content_changed(module.into())
}
FindContextFileResult::NotFound(_) => CompletionVc::immutable(),
})
}
......@@ -173,25 +161,30 @@ async fn config_assets(
project_path: FileSystemPathVc,
page_extensions: StringsVc,
) -> Result<InnerAssetsVc> {
let middleware_config =
get_config(context, project_path, middleware_files(page_extensions)).await?;
let find_config_result = find_context_file(project_path, middleware_files(page_extensions));
// The router.ts file expects a manifest of chunks for the middleware. If there
// is no middleware file, then we need to generate a default empty manifest
// and we cannot process it with the next-edge transition because it
// requires a real file for some reason.
let (manifest, config) = match &*middleware_config {
Some(c) => {
let (manifest, config) = match *find_config_result.await? {
FindContextFileResult::Found(config_path, _) => {
let config = context.process(
SourceAssetVc::new(config_path).into(),
Value::new(ReferenceType::EcmaScriptModules(
EcmaScriptModulesReferenceSubType::Undefined,
)),
);
let config = parse_config_from_source(config);
let manifest = context.with_transition("next-edge").process(
*c,
SourceAssetVc::new(config_path).into(),
Value::new(ReferenceType::EcmaScriptModules(
EcmaScriptModulesReferenceSubType::Undefined,
)),
);
let config = parse_config_from_source(*c);
(manifest, config)
}
None => {
FindContextFileResult::NotFound(_) => {
let manifest = context.process(
VirtualAssetVc::new(
project_path.join("middleware.js"),
......@@ -219,13 +212,13 @@ async fn config_assets(
);
Ok(InnerAssetsVc::cell(indexmap! {
"MIDDLEWARE_CHUNK_GROUP".to_string() => manifest,
"MIDDLEWARE_CONFIG".to_string() => config_asset,
"MIDDLEWARE_CHUNK_GROUP".to_string() => manifest.into(),
"MIDDLEWARE_CONFIG".to_string() => config_asset.into(),
}))
}
#[turbo_tasks::function]
fn route_executor(context: AssetContextVc, configs: InnerAssetsVc) -> AssetVc {
fn route_executor(context: AssetContextVc, configs: InnerAssetsVc) -> ModuleVc {
context.process(
next_asset("entry/router.ts"),
Value::new(ReferenceType::Internal(configs)),
......@@ -363,7 +356,7 @@ async fn route_internal(
};
let server_addr = server_addr.await?;
let result = evaluate(
router_asset,
router_asset.into(),
project_path,
env,
AssetIdentVc::from_path(project_path),
......@@ -434,7 +427,7 @@ async fn route_internal(
RouterResult::Error(shared_anyhow!(
trace_stack(
error,
router_asset,
router_asset.into(),
chunking_context.output_root(),
project_path
)
......
......@@ -10,10 +10,11 @@ use turbopack_binding::{
turbo::tasks_fs::{json::parse_json_rope_with_source_context, FileContent, FileSystemPathVc},
turbopack::{
core::{
asset::{Asset, AssetVc},
asset::Asset,
environment::{ServerAddrVc, ServerInfo},
ident::AssetIdentVc,
issue::{Issue, IssueSeverity, IssueSeverityVc, IssueVc, OptionIssueSourceVc},
module::ModuleVc,
reference_type::{EcmaScriptModulesReferenceSubType, ReferenceType},
resolve::{
self, handle_resolve_error, node::node_cjs_resolve_options, parse::RequestVc,
......@@ -165,15 +166,15 @@ impl Issue for NextSourceConfigParsingIssue {
}
#[turbo_tasks::function]
pub async fn parse_config_from_source(module_asset: AssetVc) -> Result<NextSourceConfigVc> {
if let Some(ecmascript_asset) = EcmascriptModuleAssetVc::resolve_from(module_asset).await? {
pub async fn parse_config_from_source(module: ModuleVc) -> Result<NextSourceConfigVc> {
if let Some(ecmascript_asset) = EcmascriptModuleAssetVc::resolve_from(module).await? {
if let ParseResult::Ok {
program: Program::Module(module),
program: Program::Module(module_ast),
eval_context,
..
} = &*ecmascript_asset.parse().await?
{
for item in &module.body {
for item in &module_ast.body {
if let Some(decl) = item
.as_module_decl()
.and_then(|mod_decl| mod_decl.as_export_decl())
......@@ -188,10 +189,10 @@ pub async fn parse_config_from_source(module_asset: AssetVc) -> Result<NextSourc
{
if let Some(init) = decl.init.as_ref() {
let value = eval_context.eval(init);
return Ok(parse_config_from_js_value(module_asset, &value).cell());
return Ok(parse_config_from_js_value(module, &value).cell());
} else {
NextSourceConfigParsingIssue {
ident: module_asset.ident(),
ident: module.ident(),
detail: StringVc::cell(
"The exported config object must contain an variable \
initializer."
......@@ -211,7 +212,7 @@ pub async fn parse_config_from_source(module_asset: AssetVc) -> Result<NextSourc
Ok(NextSourceConfigVc::default())
}
fn parse_config_from_js_value(module_asset: AssetVc, value: &JsValue) -> NextSourceConfig {
fn parse_config_from_js_value(module_asset: ModuleVc, value: &JsValue) -> NextSourceConfig {
let mut config = NextSourceConfig::default();
let invalid_config = |detail: &str, value: &JsValue| {
let (explainer, hints) = value.explain(2, 0);
......
......@@ -6,7 +6,7 @@ use turbopack_binding::{
},
turbopack::{
core::{
chunk::{ChunkableAssetVc, ChunkingContextVc},
chunk::{ChunkableModuleVc, ChunkingContextVc},
compile_time_defines,
compile_time_info::{
CompileTimeDefines, CompileTimeDefinesVc, CompileTimeInfo, CompileTimeInfoVc,
......@@ -181,7 +181,7 @@ pub async fn create_web_entry_source(
chunking_context,
Some(runtime_entries.with_entry(ecmascript.into())),
))
} else if let Some(chunkable) = ChunkableAssetVc::resolve_from(module).await? {
} else if let Some(chunkable) = ChunkableModuleVc::resolve_from(module).await? {
// TODO this is missing runtime code, so it's probably broken and we should also
// add an ecmascript chunk with the runtime code
Ok((chunkable, chunking_context, None))
......
......@@ -992,8 +992,8 @@ importers:
'@types/react': 18.2.7
'@types/react-dom': 18.2.4
'@vercel/ncc': ^0.36.0
'@vercel/turbopack-ecmascript-runtime': https://gitpkg-fork.vercel.sh/vercel/turbo/crates/turbopack-ecmascript-runtime/js?turbopack-230707.3
'@vercel/turbopack-node': https://gitpkg-fork.vercel.sh/vercel/turbo/crates/turbopack-node/js?turbopack-230707.3
'@vercel/turbopack-ecmascript-runtime': https://gitpkg-fork.vercel.sh/vercel/turbo/crates/turbopack-ecmascript-runtime/js?turbopack-230710.2
'@vercel/turbopack-node': https://gitpkg-fork.vercel.sh/vercel/turbo/crates/turbopack-node/js?turbopack-230710.2
anser: ^2.1.1
css.escape: ^1.5.1
find-up: ^6.3.0
......@@ -1005,8 +1005,8 @@ importers:
stacktrace-parser: ^0.1.10
strip-ansi: ^7.0.1
dependencies:
'@vercel/turbopack-ecmascript-runtime': '@gitpkg-fork.vercel.sh/vercel/turbo/crates/turbopack-ecmascript-runtime/js?turbopack-230707.3_react-refresh@0.12.0'
'@vercel/turbopack-node': '@gitpkg-fork.vercel.sh/vercel/turbo/crates/turbopack-node/js?turbopack-230707.3'
'@vercel/turbopack-ecmascript-runtime': '@gitpkg-fork.vercel.sh/vercel/turbo/crates/turbopack-ecmascript-runtime/js?turbopack-230710.2_react-refresh@0.12.0'
'@vercel/turbopack-node': '@gitpkg-fork.vercel.sh/vercel/turbo/crates/turbopack-node/js?turbopack-230710.2'
anser: 2.1.1
css.escape: 1.5.1
next: link:../../../../next
......@@ -6136,7 +6136,7 @@ packages:
dependencies:
'@mdx-js/mdx': 2.2.1
source-map: 0.7.3
webpack: 5.86.0
webpack: 5.86.0_@swc+core@1.3.55
transitivePeerDependencies:
- supports-color
......@@ -6810,7 +6810,6 @@ packages:
cpu: [arm64]
os: [darwin]
requiresBuild: true
dev: true
optional: true
/@swc/core-darwin-x64/1.3.55:
......@@ -6819,7 +6818,6 @@ packages:
cpu: [x64]
os: [darwin]
requiresBuild: true
dev: true
optional: true
/@swc/core-linux-arm-gnueabihf/1.3.55:
......@@ -6828,7 +6826,6 @@ packages:
cpu: [arm]
os: [linux]
requiresBuild: true
dev: true
optional: true
/@swc/core-linux-arm64-gnu/1.3.55:
......@@ -6837,7 +6834,6 @@ packages:
cpu: [arm64]
os: [linux]
requiresBuild: true
dev: true
optional: true
/@swc/core-linux-arm64-musl/1.3.55:
......@@ -6846,7 +6842,6 @@ packages:
cpu: [arm64]
os: [linux]
requiresBuild: true
dev: true
optional: true
/@swc/core-linux-x64-gnu/1.3.55:
......@@ -6855,7 +6850,6 @@ packages:
cpu: [x64]
os: [linux]
requiresBuild: true
dev: true
optional: true
/@swc/core-linux-x64-musl/1.3.55:
......@@ -6864,7 +6858,6 @@ packages:
cpu: [x64]
os: [linux]
requiresBuild: true
dev: true
optional: true
/@swc/core-win32-arm64-msvc/1.3.55:
......@@ -6873,7 +6866,6 @@ packages:
cpu: [arm64]
os: [win32]
requiresBuild: true
dev: true
optional: true
/@swc/core-win32-ia32-msvc/1.3.55:
......@@ -6882,7 +6874,6 @@ packages:
cpu: [ia32]
os: [win32]
requiresBuild: true
dev: true
optional: true
/@swc/core-win32-x64-msvc/1.3.55:
......@@ -6891,7 +6882,6 @@ packages:
cpu: [x64]
os: [win32]
requiresBuild: true
dev: true
optional: true
/@swc/core/1.3.55_@swc+helpers@0.5.1:
......@@ -6916,7 +6906,6 @@ packages:
'@swc/core-win32-arm64-msvc': 1.3.55
'@swc/core-win32-ia32-msvc': 1.3.55
'@swc/core-win32-x64-msvc': 1.3.55
dev: true
/@swc/helpers/0.4.14:
resolution: {integrity: sha512-4C7nX/dvpzB7za4Ql9K81xK3HPxCpHMgwTZVyf+9JQ6VUbn9jjZVN7/Nkdz/Ugzs2CSjqnL/UPXroiVBVHUWUw==}
......@@ -23814,7 +23803,6 @@ packages:
serialize-javascript: 6.0.1
terser: 5.17.7
webpack: 5.86.0_@swc+core@1.3.55
dev: true
/terser/5.10.0:
resolution: {integrity: sha512-AMmF99DMfEDiRJfxfY5jj5wNH/bYO09cniSqhfoyxc8sFoYIgkJy86G04UoZU5VjlpnplVu0K6Tx6E9b5+DlHA==}
......@@ -25172,7 +25160,6 @@ packages:
- '@swc/core'
- esbuild
- uglify-js
dev: true
/websocket-driver/0.7.3:
resolution: {integrity: sha512-bpxWlvbbB459Mlipc5GBzzZwhoZgGEZLuqPaR0INBGnPAY1vdBX6hPnoFXiw+3yWxDuHyQjO2oXTMyS8A5haFg==}
......@@ -25581,9 +25568,9 @@ packages:
/zwitch/2.0.4:
resolution: {integrity: sha512-bXE4cR/kVZhKZX/RjPEflHaKVhUVl85noU3v6b8apfQEc1x4A+zBxjZ4lN8LqGd6WZ3dl98pY4o717VFmoPp+A==}
'@gitpkg-fork.vercel.sh/vercel/turbo/crates/turbopack-ecmascript-runtime/js?turbopack-230707.3_react-refresh@0.12.0':
resolution: {tarball: https://gitpkg-fork.vercel.sh/vercel/turbo/crates/turbopack-ecmascript-runtime/js?turbopack-230707.3}
id: '@gitpkg-fork.vercel.sh/vercel/turbo/crates/turbopack-ecmascript-runtime/js?turbopack-230707.3'
'@gitpkg-fork.vercel.sh/vercel/turbo/crates/turbopack-ecmascript-runtime/js?turbopack-230710.2_react-refresh@0.12.0':
resolution: {tarball: https://gitpkg-fork.vercel.sh/vercel/turbo/crates/turbopack-ecmascript-runtime/js?turbopack-230710.2}
id: '@gitpkg-fork.vercel.sh/vercel/turbo/crates/turbopack-ecmascript-runtime/js?turbopack-230710.2'
name: '@vercel/turbopack-ecmascript-runtime'
version: 0.0.0
dependencies:
......@@ -25594,8 +25581,8 @@ packages:
- webpack
dev: false
'@gitpkg-fork.vercel.sh/vercel/turbo/crates/turbopack-node/js?turbopack-230707.3':
resolution: {tarball: https://gitpkg-fork.vercel.sh/vercel/turbo/crates/turbopack-node/js?turbopack-230707.3}
'@gitpkg-fork.vercel.sh/vercel/turbo/crates/turbopack-node/js?turbopack-230710.2':
resolution: {tarball: https://gitpkg-fork.vercel.sh/vercel/turbo/crates/turbopack-node/js?turbopack-230710.2}
name: '@vercel/turbopack-node'
version: 0.0.0
dependencies:
......
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