Unverified Commit 1c998d86 authored by Tobias Koppers's avatar Tobias Koppers Committed by GitHub

route/middleware/instrumentation use server assets instead of client assets (#62134)

### What?

route/middleware/instrumentation use server assets
server assets use full url rewrite

### Why?

### How?

https://github.com/vercel/turbo/pull/7750

Fixes PACK-2522

fixes PACK-2645
parent da1010bc
...@@ -98,6 +98,12 @@ impl AppProject { ...@@ -98,6 +98,12 @@ impl AppProject {
} }
} }
fn route_ty(self: Vc<Self>) -> ServerContextType {
ServerContextType::AppRoute {
app_dir: self.app_dir(),
}
}
fn ssr_ty(self: Vc<Self>) -> ServerContextType { fn ssr_ty(self: Vc<Self>) -> ServerContextType {
ServerContextType::AppSSR { ServerContextType::AppSSR {
app_dir: self.app_dir(), app_dir: self.app_dir(),
...@@ -174,6 +180,17 @@ impl AppProject { ...@@ -174,6 +180,17 @@ impl AppProject {
)) ))
} }
#[turbo_tasks::function]
async fn route_module_options_context(self: Vc<Self>) -> Result<Vc<ModuleOptionsContext>> {
Ok(get_server_module_options_context(
self.project().project_path(),
self.project().execution_context(),
Value::new(self.route_ty()),
self.project().next_mode(),
self.project().next_config(),
))
}
#[turbo_tasks::function] #[turbo_tasks::function]
async fn rsc_resolve_options_context(self: Vc<Self>) -> Result<Vc<ResolveOptionsContext>> { async fn rsc_resolve_options_context(self: Vc<Self>) -> Result<Vc<ResolveOptionsContext>> {
Ok(get_server_resolve_options_context( Ok(get_server_resolve_options_context(
...@@ -196,6 +213,30 @@ impl AppProject { ...@@ -196,6 +213,30 @@ impl AppProject {
)) ))
} }
#[turbo_tasks::function]
async fn route_resolve_options_context(self: Vc<Self>) -> Result<Vc<ResolveOptionsContext>> {
Ok(get_server_resolve_options_context(
self.project().project_path(),
Value::new(self.route_ty()),
self.project().next_mode(),
self.project().next_config(),
self.project().execution_context(),
))
}
#[turbo_tasks::function]
async fn edge_route_resolve_options_context(
self: Vc<Self>,
) -> Result<Vc<ResolveOptionsContext>> {
Ok(get_edge_resolve_options_context(
self.project().project_path(),
Value::new(self.route_ty()),
self.project().next_mode(),
self.project().next_config(),
self.project().execution_context(),
))
}
#[turbo_tasks::function] #[turbo_tasks::function]
fn rsc_module_context(self: Vc<Self>) -> Vc<ModuleAssetContext> { fn rsc_module_context(self: Vc<Self>) -> Vc<ModuleAssetContext> {
let transitions = [ let transitions = [
...@@ -257,6 +298,28 @@ impl AppProject { ...@@ -257,6 +298,28 @@ impl AppProject {
) )
} }
#[turbo_tasks::function]
fn route_module_context(self: Vc<Self>) -> Vc<ModuleAssetContext> {
ModuleAssetContext::new(
Default::default(),
self.project().server_compile_time_info(),
self.route_module_options_context(),
self.route_resolve_options_context(),
Vc::cell("app-route".to_string()),
)
}
#[turbo_tasks::function]
fn edge_route_module_context(self: Vc<Self>) -> Vc<ModuleAssetContext> {
ModuleAssetContext::new(
Default::default(),
self.project().edge_compile_time_info(),
self.route_module_options_context(),
self.edge_route_resolve_options_context(),
Vc::cell("app-edge-route".to_string()),
)
}
#[turbo_tasks::function] #[turbo_tasks::function]
fn client_module_context(self: Vc<Self>) -> Vc<ModuleAssetContext> { fn client_module_context(self: Vc<Self>) -> Vc<ModuleAssetContext> {
ModuleAssetContext::new( ModuleAssetContext::new(
...@@ -490,8 +553,8 @@ impl AppEndpoint { ...@@ -490,8 +553,8 @@ impl AppEndpoint {
#[turbo_tasks::function] #[turbo_tasks::function]
fn app_route_entry(&self, path: Vc<FileSystemPath>) -> Vc<AppEntry> { fn app_route_entry(&self, path: Vc<FileSystemPath>) -> Vc<AppEntry> {
get_app_route_entry( get_app_route_entry(
self.app_project.rsc_module_context(), self.app_project.route_module_context(),
self.app_project.edge_rsc_module_context(), self.app_project.edge_route_module_context(),
Vc::upcast(FileSource::new(path)), Vc::upcast(FileSource::new(path)),
self.page.clone(), self.page.clone(),
self.app_project.project().project_path(), self.app_project.project().project_path(),
...@@ -520,19 +583,18 @@ impl AppEndpoint { ...@@ -520,19 +583,18 @@ impl AppEndpoint {
async fn output(self: Vc<Self>) -> Result<Vc<AppEndpointOutput>> { async fn output(self: Vc<Self>) -> Result<Vc<AppEndpointOutput>> {
let this = self.await?; let this = self.await?;
let (app_entry, process_client, process_ssr, has_client_side_assets) = match this.ty { let (app_entry, process_client, process_ssr) = match this.ty {
AppEndpointType::Page { ty, loader_tree } => ( AppEndpointType::Page { ty, loader_tree } => (
self.app_page_entry(loader_tree), self.app_page_entry(loader_tree),
true, true,
matches!(ty, AppPageEndpointType::Html), matches!(ty, AppPageEndpointType::Html),
true,
), ),
// NOTE(alexkirsz) For routes, technically, a lot of the following code is not needed, // NOTE(alexkirsz) For routes, technically, a lot of the following code is not needed,
// as we know we won't have any client references. However, for now, for simplicity's // as we know we won't have any client references. However, for now, for simplicity's
// sake, we just do the same thing as for pages. // sake, we just do the same thing as for pages.
AppEndpointType::Route { path } => (self.app_route_entry(path), false, false, false), AppEndpointType::Route { path } => (self.app_route_entry(path), false, false),
AppEndpointType::Metadata { metadata } => { AppEndpointType::Metadata { metadata } => {
(self.app_metadata_entry(metadata), false, false, false) (self.app_metadata_entry(metadata), false, false)
} }
}; };
...@@ -613,12 +675,12 @@ impl AppEndpoint { ...@@ -613,12 +675,12 @@ impl AppEndpoint {
let ssr_chunking_context = if process_ssr { let ssr_chunking_context = if process_ssr {
Some(match runtime { Some(match runtime {
NextRuntime::NodeJs => { NextRuntime::NodeJs => {
Vc::upcast(this.app_project.project().server_chunking_context()) Vc::upcast(this.app_project.project().server_chunking_context(true))
} }
NextRuntime::Edge => this NextRuntime::Edge => this
.app_project .app_project
.project() .project()
.edge_chunking_context(has_client_side_assets), .edge_chunking_context(process_client),
}) })
} else { } else {
None None
...@@ -845,7 +907,7 @@ impl AppEndpoint { ...@@ -845,7 +907,7 @@ impl AppEndpoint {
let chunking_context = this let chunking_context = this
.app_project .app_project
.project() .project()
.edge_chunking_context(has_client_side_assets); .edge_chunking_context(process_client);
let mut evaluatable_assets = this let mut evaluatable_assets = this
.app_project .app_project
.edge_rsc_runtime_entries() .edge_rsc_runtime_entries()
...@@ -985,6 +1047,11 @@ impl AppEndpoint { ...@@ -985,6 +1047,11 @@ impl AppEndpoint {
let mut evaluatable_assets = let mut evaluatable_assets =
this.app_project.rsc_runtime_entries().await?.clone_value(); this.app_project.rsc_runtime_entries().await?.clone_value();
let chunking_context = this
.app_project
.project()
.server_chunking_context(process_client);
if let Some(app_server_reference_modules) = app_server_reference_modules { if let Some(app_server_reference_modules) = app_server_reference_modules {
let (loader, manifest) = create_server_actions_manifest( let (loader, manifest) = create_server_actions_manifest(
Vc::upcast(app_entry.rsc_entry), Vc::upcast(app_entry.rsc_entry),
...@@ -994,7 +1061,7 @@ impl AppEndpoint { ...@@ -994,7 +1061,7 @@ impl AppEndpoint {
&app_entry.original_name, &app_entry.original_name,
NextRuntime::NodeJs, NextRuntime::NodeJs,
Vc::upcast(this.app_project.rsc_module_context()), Vc::upcast(this.app_project.rsc_module_context()),
Vc::upcast(this.app_project.project().server_chunking_context()), Vc::upcast(chunking_context),
) )
.await?; .await?;
server_assets.push(manifest); server_assets.push(manifest);
...@@ -1003,10 +1070,7 @@ impl AppEndpoint { ...@@ -1003,10 +1070,7 @@ impl AppEndpoint {
let EntryChunkGroupResult { let EntryChunkGroupResult {
asset: rsc_chunk, .. asset: rsc_chunk, ..
} = *this } = *chunking_context
.app_project
.project()
.server_chunking_context()
.entry_chunk_group( .entry_chunk_group(
server_path.join(format!( server_path.join(format!(
"app{original_name}.js", "app{original_name}.js",
...@@ -1035,7 +1099,7 @@ impl AppEndpoint { ...@@ -1035,7 +1099,7 @@ impl AppEndpoint {
let dynamic_import_modules = let dynamic_import_modules =
collect_next_dynamic_imports(app_entry.rsc_entry).await?; collect_next_dynamic_imports(app_entry.rsc_entry).await?;
let dynamic_import_entries = collect_chunk_group( let dynamic_import_entries = collect_chunk_group(
this.app_project.project().server_chunking_context(), chunking_context,
dynamic_import_modules, dynamic_import_modules,
availability_info, availability_info,
) )
......
...@@ -108,7 +108,7 @@ impl InstrumentationEndpoint { ...@@ -108,7 +108,7 @@ impl InstrumentationEndpoint {
#[turbo_tasks::function] #[turbo_tasks::function]
async fn node_chunk(&self) -> Result<Vc<Box<dyn OutputAsset>>> { async fn node_chunk(&self) -> Result<Vc<Box<dyn OutputAsset>>> {
let chunking_context = self.project.server_chunking_context(); let chunking_context = self.project.server_chunking_context(false);
let userland_module = self let userland_module = self
.context .context
......
...@@ -794,7 +794,7 @@ impl PageEndpoint { ...@@ -794,7 +794,7 @@ impl PageEndpoint {
this.pages_project.project().project_path(), this.pages_project.project().project_path(),
this.pages_project.ssr_module_context(), this.pages_project.ssr_module_context(),
this.pages_project.edge_ssr_module_context(), this.pages_project.edge_ssr_module_context(),
this.pages_project.project().server_chunking_context(), this.pages_project.project().server_chunking_context(true),
this.pages_project.project().edge_chunking_context(true), this.pages_project.project().edge_chunking_context(true),
this.pages_project.ssr_runtime_entries(), this.pages_project.ssr_runtime_entries(),
this.pages_project.edge_ssr_runtime_entries(), this.pages_project.edge_ssr_runtime_entries(),
...@@ -814,7 +814,7 @@ impl PageEndpoint { ...@@ -814,7 +814,7 @@ impl PageEndpoint {
this.pages_project.project().project_path(), this.pages_project.project().project_path(),
this.pages_project.ssr_data_module_context(), this.pages_project.ssr_data_module_context(),
this.pages_project.edge_ssr_data_module_context(), this.pages_project.edge_ssr_data_module_context(),
this.pages_project.project().server_chunking_context(), this.pages_project.project().server_chunking_context(true),
this.pages_project.project().edge_chunking_context(true), this.pages_project.project().edge_chunking_context(true),
this.pages_project.ssr_data_runtime_entries(), this.pages_project.ssr_data_runtime_entries(),
this.pages_project.edge_ssr_data_runtime_entries(), this.pages_project.edge_ssr_data_runtime_entries(),
...@@ -834,7 +834,7 @@ impl PageEndpoint { ...@@ -834,7 +834,7 @@ impl PageEndpoint {
this.pages_project.project().project_path(), this.pages_project.project().project_path(),
this.pages_project.api_module_context(), this.pages_project.api_module_context(),
this.pages_project.edge_api_module_context(), this.pages_project.edge_api_module_context(),
this.pages_project.project().server_chunking_context(), this.pages_project.project().server_chunking_context(false),
this.pages_project.project().edge_chunking_context(false), this.pages_project.project().edge_chunking_context(false),
this.pages_project.ssr_runtime_entries(), this.pages_project.ssr_runtime_entries(),
this.pages_project.edge_ssr_runtime_entries(), this.pages_project.edge_ssr_runtime_entries(),
......
...@@ -13,8 +13,9 @@ use next_core::{ ...@@ -13,8 +13,9 @@ use next_core::{
next_client::{get_client_chunking_context, get_client_compile_time_info}, next_client::{get_client_chunking_context, get_client_compile_time_info},
next_config::{JsConfig, NextConfig}, next_config::{JsConfig, NextConfig},
next_server::{ next_server::{
get_server_chunking_context, get_server_compile_time_info, get_server_chunking_context, get_server_chunking_context_with_client_assets,
get_server_module_options_context, get_server_resolve_options_context, ServerContextType, get_server_compile_time_info, get_server_module_options_context,
get_server_resolve_options_context, ServerContextType,
}, },
next_telemetry::NextFeatureTelemetry, next_telemetry::NextFeatureTelemetry,
}; };
...@@ -557,25 +558,35 @@ impl Project { ...@@ -557,25 +558,35 @@ impl Project {
} }
#[turbo_tasks::function] #[turbo_tasks::function]
pub(super) async fn server_chunking_context( pub(super) fn server_chunking_context(
self: Vc<Self>, self: Vc<Self>,
) -> Result<Vc<NodeJsChunkingContext>> { client_assets: bool,
Ok(get_server_chunking_context( ) -> Vc<NodeJsChunkingContext> {
self.next_mode(), if client_assets {
self.project_path(), get_server_chunking_context_with_client_assets(
self.node_root(), self.next_mode(),
self.client_relative_path(), self.project_path(),
self.next_config().computed_asset_prefix(), self.node_root(),
self.server_compile_time_info().environment(), self.client_relative_path(),
)) self.next_config().computed_asset_prefix(),
self.server_compile_time_info().environment(),
)
} else {
get_server_chunking_context(
self.next_mode(),
self.project_path(),
self.node_root(),
self.server_compile_time_info().environment(),
)
}
} }
#[turbo_tasks::function] #[turbo_tasks::function]
pub(super) fn edge_chunking_context( pub(super) fn edge_chunking_context(
self: Vc<Self>, self: Vc<Self>,
client_assets: bool, client_assets: bool,
) -> Result<Vc<Box<dyn EcmascriptChunkingContext>>> { ) -> Vc<Box<dyn EcmascriptChunkingContext>> {
Ok(if client_assets { if client_assets {
get_edge_chunking_context_with_client_assets( get_edge_chunking_context_with_client_assets(
self.next_mode(), self.next_mode(),
self.project_path(), self.project_path(),
...@@ -591,7 +602,7 @@ impl Project { ...@@ -591,7 +602,7 @@ impl Project {
self.node_root(), self.node_root(),
self.edge_compile_time_info().environment(), self.edge_compile_time_info().environment(),
) )
}) }
} }
/// Emit a telemetry event corresponding to [webpack configuration telemetry](https://github.com/vercel/next.js/blob/9da305fe320b89ee2f8c3cfb7ecbf48856368913/packages/next/src/build/webpack-config.ts#L2516) /// Emit a telemetry event corresponding to [webpack configuration telemetry](https://github.com/vercel/next.js/blob/9da305fe320b89ee2f8c3cfb7ecbf48856368913/packages/next/src/build/webpack-config.ts#L2516)
......
...@@ -163,7 +163,7 @@ pub async fn get_edge_chunking_context_with_client_assets( ...@@ -163,7 +163,7 @@ pub async fn get_edge_chunking_context_with_client_assets(
project_path, project_path,
output_root, output_root,
client_root, client_root,
output_root.join("chunks".to_string()), output_root.join("chunks/ssr".to_string()),
client_root.join("static/media".to_string()), client_root.join("static/media".to_string()),
environment, environment,
next_mode.runtime_type(), next_mode.runtime_type(),
...@@ -200,6 +200,7 @@ pub async fn get_edge_chunking_context( ...@@ -200,6 +200,7 @@ pub async fn get_edge_chunking_context(
// asset from the output directory. // asset from the output directory.
.asset_base_path(Vc::cell(Some("blob:server/edge/".to_string()))) .asset_base_path(Vc::cell(Some("blob:server/edge/".to_string())))
.reference_chunk_source_maps(should_debug("edge")) .reference_chunk_source_maps(should_debug("edge"))
.minify_type(next_mode.minify_type())
.build(), .build(),
)) ))
} }
...@@ -675,32 +675,34 @@ async fn rsc_aliases( ...@@ -675,32 +675,34 @@ async fn rsc_aliases(
}; };
if runtime == NextRuntime::NodeJs { if runtime == NextRuntime::NodeJs {
if let ServerContextType::AppSSR { .. } = ty { match ty {
alias.extend(indexmap! { ServerContextType::AppSSR { .. } => {
"react/jsx-runtime" => format!("next/dist/server/future/route-modules/app-page/vendored/ssr/react-jsx-runtime"), alias.extend(indexmap! {
"react/jsx-dev-runtime" => format!("next/dist/server/future/route-modules/app-page/vendored/ssr/react-jsx-dev-runtime"), "react/jsx-runtime" => format!("next/dist/server/future/route-modules/app-page/vendored/ssr/react-jsx-runtime"),
"react" => format!("next/dist/server/future/route-modules/app-page/vendored/ssr/react"), "react/jsx-dev-runtime" => format!("next/dist/server/future/route-modules/app-page/vendored/ssr/react-jsx-dev-runtime"),
"react-dom" => format!("next/dist/server/future/route-modules/app-page/vendored/ssr/react-dom"), "react" => format!("next/dist/server/future/route-modules/app-page/vendored/ssr/react"),
"react-server-dom-webpack/client.edge" => format!("next/dist/server/future/route-modules/app-page/vendored/ssr/react-server-dom-turbopack-client-edge"), "react-dom" => format!("next/dist/server/future/route-modules/app-page/vendored/ssr/react-dom"),
"react-server-dom-turbopack/client.edge" => format!("next/dist/server/future/route-modules/app-page/vendored/ssr/react-server-dom-turbopack-client-edge"), "react-server-dom-webpack/client.edge" => format!("next/dist/server/future/route-modules/app-page/vendored/ssr/react-server-dom-turbopack-client-edge"),
}) "react-server-dom-turbopack/client.edge" => format!("next/dist/server/future/route-modules/app-page/vendored/ssr/react-server-dom-turbopack-client-edge"),
} })
}
if let ServerContextType::AppRSC { .. } = ty { ServerContextType::AppRSC { .. } | ServerContextType::AppRoute { .. } => {
alias.extend(indexmap! { alias.extend(indexmap! {
"react/jsx-runtime" => format!("next/dist/server/future/route-modules/app-page/vendored/rsc/react-jsx-runtime"), "react/jsx-runtime" => format!("next/dist/server/future/route-modules/app-page/vendored/rsc/react-jsx-runtime"),
"react/jsx-dev-runtime" => format!("next/dist/server/future/route-modules/app-page/vendored/rsc/react-jsx-dev-runtime"), "react/jsx-dev-runtime" => format!("next/dist/server/future/route-modules/app-page/vendored/rsc/react-jsx-dev-runtime"),
"react" => format!("next/dist/server/future/route-modules/app-page/vendored/rsc/react"), "react" => format!("next/dist/server/future/route-modules/app-page/vendored/rsc/react"),
"react-dom" => format!("next/dist/server/future/route-modules/app-page/vendored/rsc/react-dom"), "react-dom" => format!("next/dist/server/future/route-modules/app-page/vendored/rsc/react-dom"),
"react-server-dom-webpack/server.edge" => format!("next/dist/server/future/route-modules/app-page/vendored/rsc/react-server-dom-turbopack-server-edge"), "react-server-dom-webpack/server.edge" => format!("next/dist/server/future/route-modules/app-page/vendored/rsc/react-server-dom-turbopack-server-edge"),
"react-server-dom-webpack/server.node" => format!("next/dist/server/future/route-modules/app-page/vendored/rsc/react-server-dom-turbopack-server-node"), "react-server-dom-webpack/server.node" => format!("next/dist/server/future/route-modules/app-page/vendored/rsc/react-server-dom-turbopack-server-node"),
"react-server-dom-turbopack/server.edge" => format!("next/dist/server/future/route-modules/app-page/vendored/rsc/react-server-dom-turbopack-server-edge"), "react-server-dom-turbopack/server.edge" => format!("next/dist/server/future/route-modules/app-page/vendored/rsc/react-server-dom-turbopack-server-edge"),
"react-server-dom-turbopack/server.node" => format!("next/dist/server/future/route-modules/app-page/vendored/rsc/react-server-dom-turbopack-server-node"), "react-server-dom-turbopack/server.node" => format!("next/dist/server/future/route-modules/app-page/vendored/rsc/react-server-dom-turbopack-server-node"),
"next/navigation" => format!("next/dist/api/navigation.react-server"), "next/navigation" => format!("next/dist/api/navigation.react-server"),
// Needed to make `react-dom/server` work. // Needed to make `react-dom/server` work.
"next/dist/compiled/react" => format!("next/dist/compiled/react/index.js"), "next/dist/compiled/react" => format!("next/dist/compiled/react/index.js"),
}) })
}
_ => {}
} }
} }
......
...@@ -161,13 +161,15 @@ pub async fn get_server_resolve_options_context( ...@@ -161,13 +161,15 @@ pub async fn get_server_resolve_options_context(
custom_conditions.extend(ty.conditions().iter().map(ToString::to_string)); custom_conditions.extend(ty.conditions().iter().map(ToString::to_string));
match ty { match ty {
ServerContextType::AppRSC { .. } => custom_conditions.push("react-server".to_string()), ServerContextType::AppRSC { .. }
ServerContextType::AppRoute { .. } | ServerContextType::AppRoute { .. }
| ServerContextType::Pages { .. }
| ServerContextType::PagesData { .. }
| ServerContextType::PagesApi { .. } | ServerContextType::PagesApi { .. }
| ServerContextType::Middleware { .. } => {
custom_conditions.push("react-server".to_string())
}
ServerContextType::Pages { .. }
| ServerContextType::PagesData { .. }
| ServerContextType::AppSSR { .. } | ServerContextType::AppSSR { .. }
| ServerContextType::Middleware { .. }
| ServerContextType::Instrumentation { .. } => {} | ServerContextType::Instrumentation { .. } => {}
}; };
let external_cjs_modules_plugin = ExternalCjsModulesResolvePlugin::new( let external_cjs_modules_plugin = ExternalCjsModulesResolvePlugin::new(
...@@ -435,7 +437,8 @@ pub async fn get_server_module_options_context( ...@@ -435,7 +437,8 @@ pub async fn get_server_module_options_context(
..Default::default() ..Default::default()
}; };
let module_options_context = match ty.into_value() { let ty = ty.into_value();
let module_options_context = match ty {
ServerContextType::Pages { .. } ServerContextType::Pages { .. }
| ServerContextType::PagesData { .. } | ServerContextType::PagesData { .. }
| ServerContextType::PagesApi { .. } => { | ServerContextType::PagesApi { .. } => {
...@@ -445,7 +448,7 @@ pub async fn get_server_module_options_context( ...@@ -445,7 +448,7 @@ pub async fn get_server_module_options_context(
.flatten() .flatten()
.collect(); .collect();
if let ServerContextType::Pages { .. } = ty.into_value() { if let ServerContextType::Pages { .. } = ty {
custom_source_transform_rules.push( custom_source_transform_rules.push(
get_next_react_server_components_transform_rule(next_config, false, None) get_next_react_server_components_transform_rule(next_config, false, None)
.await?, .await?,
...@@ -460,7 +463,7 @@ pub async fn get_server_module_options_context( ...@@ -460,7 +463,7 @@ pub async fn get_server_module_options_context(
let url_rewrite_behavior = Some( let url_rewrite_behavior = Some(
//https://github.com/vercel/next.js/blob/bbb730e5ef10115ed76434f250379f6f53efe998/packages/next/src/build/webpack-config.ts#L1384 //https://github.com/vercel/next.js/blob/bbb730e5ef10115ed76434f250379f6f53efe998/packages/next/src/build/webpack-config.ts#L1384
if let ServerContextType::PagesApi { .. } = ty.into_value() { if let ServerContextType::PagesApi { .. } = ty {
UrlRewriteBehavior::Full UrlRewriteBehavior::Full
} else { } else {
UrlRewriteBehavior::Relative UrlRewriteBehavior::Relative
...@@ -647,6 +650,7 @@ pub async fn get_server_module_options_context( ...@@ -647,6 +650,7 @@ pub async fn get_server_module_options_context(
..module_options_context.clone() ..module_options_context.clone()
}; };
ModuleOptionsContext { ModuleOptionsContext {
enable_jsx: Some(rsc_jsx_runtime_options),
enable_webpack_loaders, enable_webpack_loaders,
enable_postcss_transform, enable_postcss_transform,
enable_typescript_transform: Some(tsconfig), enable_typescript_transform: Some(tsconfig),
...@@ -676,6 +680,10 @@ pub async fn get_server_module_options_context( ...@@ -676,6 +680,10 @@ pub async fn get_server_module_options_context(
next_server_rules.extend(custom_source_transform_rules); next_server_rules.extend(custom_source_transform_rules);
next_server_rules.extend(source_transform_rules); next_server_rules.extend(source_transform_rules);
let module_options_context = ModuleOptionsContext {
esm_url_rewrite_behavior: Some(UrlRewriteBehavior::Full),
..module_options_context
};
let foreign_code_module_options_context = ModuleOptionsContext { let foreign_code_module_options_context = ModuleOptionsContext {
custom_rules: internal_custom_rules.clone(), custom_rules: internal_custom_rules.clone(),
enable_webpack_loaders: foreign_webpack_loaders, enable_webpack_loaders: foreign_webpack_loaders,
...@@ -715,6 +723,17 @@ pub async fn get_server_module_options_context( ...@@ -715,6 +723,17 @@ pub async fn get_server_module_options_context(
Ok(module_options_context) Ok(module_options_context)
} }
#[turbo_tasks::function]
pub fn get_build_module_options_context() -> Vc<ModuleOptionsContext> {
ModuleOptionsContext {
enable_typescript_transform: Some(Default::default()),
tree_shaking_mode: Some(TreeShakingMode::ReexportsOnly),
esm_url_rewrite_behavior: Some(UrlRewriteBehavior::Full),
..Default::default()
}
.cell()
}
#[turbo_tasks::function] #[turbo_tasks::function]
pub fn get_server_runtime_entries( pub fn get_server_runtime_entries(
_ty: Value<ServerContextType>, _ty: Value<ServerContextType>,
...@@ -725,12 +744,10 @@ pub fn get_server_runtime_entries( ...@@ -725,12 +744,10 @@ pub fn get_server_runtime_entries(
} }
#[turbo_tasks::function] #[turbo_tasks::function]
pub async fn get_server_chunking_context( pub async fn get_server_chunking_context_with_client_assets(
mode: Vc<NextMode>, mode: Vc<NextMode>,
project_path: Vc<FileSystemPath>, project_path: Vc<FileSystemPath>,
node_root: Vc<FileSystemPath>, node_root: Vc<FileSystemPath>,
// TODO(alexkirsz) Is this even necessary? Are assets not always on the client chunking context
// anyway?
client_root: Vc<FileSystemPath>, client_root: Vc<FileSystemPath>,
asset_prefix: Vc<Option<String>>, asset_prefix: Vc<Option<String>>,
environment: Vc<Environment>, environment: Vc<Environment>,
...@@ -743,7 +760,7 @@ pub async fn get_server_chunking_context( ...@@ -743,7 +760,7 @@ pub async fn get_server_chunking_context(
project_path, project_path,
node_root, node_root,
client_root, client_root,
node_root.join("server/chunks".to_string()), node_root.join("server/chunks/ssr".to_string()),
client_root.join("static/media".to_string()), client_root.join("static/media".to_string()),
environment, environment,
next_mode.runtime_type(), next_mode.runtime_type(),
...@@ -752,3 +769,27 @@ pub async fn get_server_chunking_context( ...@@ -752,3 +769,27 @@ pub async fn get_server_chunking_context(
.minify_type(next_mode.minify_type()) .minify_type(next_mode.minify_type())
.build()) .build())
} }
#[turbo_tasks::function]
pub async fn get_server_chunking_context(
mode: Vc<NextMode>,
project_path: Vc<FileSystemPath>,
node_root: Vc<FileSystemPath>,
environment: Vc<Environment>,
) -> Result<Vc<NodeJsChunkingContext>> {
let next_mode = mode.await?;
// TODO(alexkirsz) This should return a trait that can be implemented by the
// different server chunking contexts. OR the build chunking context should
// support both production and development modes.
Ok(NodeJsChunkingContext::builder(
project_path,
node_root,
node_root,
node_root.join("server/chunks".to_string()),
node_root.join("server/assets".to_string()),
environment,
next_mode.runtime_type(),
)
.minify_type(next_mode.minify_type())
.build())
}
...@@ -3,6 +3,7 @@ pub(crate) mod resolve; ...@@ -3,6 +3,7 @@ pub(crate) mod resolve;
pub(crate) mod transforms; pub(crate) mod transforms;
pub use context::{ pub use context::{
get_server_chunking_context, get_server_compile_time_info, get_server_module_options_context, get_server_chunking_context, get_server_chunking_context_with_client_assets,
get_server_compile_time_info, get_server_module_options_context,
get_server_resolve_options_context, get_server_runtime_entries, ServerContextType, get_server_resolve_options_context, get_server_runtime_entries, ServerContextType,
}; };
...@@ -21,7 +21,7 @@ describe('default', () => { ...@@ -21,7 +21,7 @@ describe('default', () => {
const app = await launchApp(appDir, port) const app = await launchApp(appDir, port)
await renderViaHTTP(port, '/') await renderViaHTTP(port, '/')
if (process.env.TURBOPACK) { if (process.env.TURBOPACK) {
const ssrPath = join(appDir, '.next/server/chunks') const ssrPath = join(appDir, '.next/server/chunks/ssr')
const pageBundleBasenames = (await fs.readdir(ssrPath)).filter((p) => const pageBundleBasenames = (await fs.readdir(ssrPath)).filter((p) =>
p.match(/\.js$/) p.match(/\.js$/)
) )
......
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