Unverified Commit b90dcdd0 authored by OJ Kwon's avatar OJ Kwon Committed by GitHub

feat(next-core): set nextconfigoutput correctly (#63848)

### What

PR updates route's template injection correctly sets `nextConfigOutput`.
parent 389ea366
...@@ -20,6 +20,7 @@ use next_core::{ ...@@ -20,6 +20,7 @@ use next_core::{
get_client_runtime_entries, ClientContextType, RuntimeEntries, get_client_runtime_entries, ClientContextType, RuntimeEntries,
}, },
next_client_reference::{ClientReferenceGraph, NextEcmascriptClientReferenceTransition}, next_client_reference::{ClientReferenceGraph, NextEcmascriptClientReferenceTransition},
next_config::NextConfig,
next_dynamic::NextDynamicTransition, next_dynamic::NextDynamicTransition,
next_edge::route_regex::get_named_middleware_regex, next_edge::route_regex::get_named_middleware_regex,
next_manifests::{ next_manifests::{
...@@ -601,6 +602,7 @@ impl AppEndpoint { ...@@ -601,6 +602,7 @@ impl AppEndpoint {
&self, &self,
path: Vc<FileSystemPath>, path: Vc<FileSystemPath>,
root_layouts: Vc<Vec<Vc<FileSystemPath>>>, root_layouts: Vc<Vec<Vc<FileSystemPath>>>,
next_config: Vc<NextConfig>,
) -> Result<Vc<AppEntry>> { ) -> Result<Vc<AppEntry>> {
let root_layouts = root_layouts.await?; let root_layouts = root_layouts.await?;
let config = if root_layouts.is_empty() { let config = if root_layouts.is_empty() {
...@@ -624,11 +626,16 @@ impl AppEndpoint { ...@@ -624,11 +626,16 @@ impl AppEndpoint {
self.page.clone(), self.page.clone(),
self.app_project.project().project_path(), self.app_project.project().project_path(),
config, config,
next_config,
)) ))
} }
#[turbo_tasks::function] #[turbo_tasks::function]
async fn app_metadata_entry(&self, metadata: MetadataItem) -> Result<Vc<AppEntry>> { async fn app_metadata_entry(
&self,
metadata: MetadataItem,
next_config: Vc<NextConfig>,
) -> Result<Vc<AppEntry>> {
Ok(get_app_metadata_route_entry( Ok(get_app_metadata_route_entry(
self.app_project.rsc_module_context(), self.app_project.rsc_module_context(),
self.app_project.edge_rsc_module_context(), self.app_project.edge_rsc_module_context(),
...@@ -636,6 +643,7 @@ impl AppEndpoint { ...@@ -636,6 +643,7 @@ impl AppEndpoint {
self.page.clone(), self.page.clone(),
*self.app_project.project().next_mode().await?, *self.app_project.project().next_mode().await?,
metadata, metadata,
next_config,
)) ))
} }
...@@ -648,6 +656,7 @@ impl AppEndpoint { ...@@ -648,6 +656,7 @@ 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 next_config = self.await?.app_project.project().next_config();
let (app_entry, process_client, process_ssr) = 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),
...@@ -657,11 +666,13 @@ impl AppEndpoint { ...@@ -657,11 +666,13 @@ impl AppEndpoint {
// 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, root_layouts } => { AppEndpointType::Route { path, root_layouts } => (
(self.app_route_entry(path, root_layouts), false, false) self.app_route_entry(path, root_layouts, next_config),
} false,
false,
),
AppEndpointType::Metadata { metadata } => { AppEndpointType::Metadata { metadata } => {
(self.app_metadata_entry(metadata), false, false) (self.app_metadata_entry(metadata, next_config), false, false)
} }
}; };
......
...@@ -18,6 +18,7 @@ use turbopack_binding::{ ...@@ -18,6 +18,7 @@ use turbopack_binding::{
use crate::{ use crate::{
app_segment_config::NextSegmentConfig, app_segment_config::NextSegmentConfig,
next_app::{AppEntry, AppPage, AppPath}, next_app::{AppEntry, AppPage, AppPath},
next_config::{NextConfig, OutputType},
next_edge::entry::wrap_edge_entry, next_edge::entry::wrap_edge_entry,
parse_segment_config_from_source, parse_segment_config_from_source,
util::{load_next_js_template, NextRuntime}, util::{load_next_js_template, NextRuntime},
...@@ -38,6 +39,7 @@ pub async fn get_app_route_entry( ...@@ -38,6 +39,7 @@ pub async fn get_app_route_entry(
page: AppPage, page: AppPage,
project_root: Vc<FileSystemPath>, project_root: Vc<FileSystemPath>,
original_segment_config: Option<Vc<NextSegmentConfig>>, original_segment_config: Option<Vc<NextSegmentConfig>>,
next_config: Vc<NextConfig>,
) -> Result<Vc<AppEntry>> { ) -> Result<Vc<AppEntry>> {
let segment_from_source = parse_segment_config_from_source(source); let segment_from_source = parse_segment_config_from_source(source);
let config = if let Some(original_segment_config) = original_segment_config { let config = if let Some(original_segment_config) = original_segment_config {
...@@ -62,6 +64,16 @@ pub async fn get_app_route_entry( ...@@ -62,6 +64,16 @@ pub async fn get_app_route_entry(
const INNER: &str = "INNER_APP_ROUTE"; const INNER: &str = "INNER_APP_ROUTE";
let output_type = next_config
.await?
.output
.as_ref()
.map(|o| match o {
OutputType::Standalone => "\"standalone\"".to_string(),
OutputType::Export => "\"export\"".to_string(),
})
.unwrap_or_else(|| "\"\"".to_string());
// Load the file from the next.js codebase. // Load the file from the next.js codebase.
let virtual_source = load_next_js_template( let virtual_source = load_next_js_template(
"app-route.js", "app-route.js",
...@@ -77,7 +89,7 @@ pub async fn get_app_route_entry( ...@@ -77,7 +89,7 @@ pub async fn get_app_route_entry(
"VAR_USERLAND" => INNER.to_string(), "VAR_USERLAND" => INNER.to_string(),
}, },
indexmap! { indexmap! {
"nextConfigOutput" => "\"\"".to_string(), "nextConfigOutput" => output_type
}, },
indexmap! {}, indexmap! {},
) )
......
...@@ -23,6 +23,7 @@ use crate::{ ...@@ -23,6 +23,7 @@ use crate::{
app_structure::MetadataItem, app_structure::MetadataItem,
mode::NextMode, mode::NextMode,
next_app::{app_entry::AppEntry, app_route_entry::get_app_route_entry, AppPage, PageSegment}, next_app::{app_entry::AppEntry, app_route_entry::get_app_route_entry, AppPage, PageSegment},
next_config::NextConfig,
parse_segment_config_from_source, parse_segment_config_from_source,
}; };
...@@ -58,6 +59,7 @@ pub fn get_app_metadata_route_entry( ...@@ -58,6 +59,7 @@ pub fn get_app_metadata_route_entry(
page: AppPage, page: AppPage,
mode: NextMode, mode: NextMode,
metadata: MetadataItem, metadata: MetadataItem,
next_config: Vc<NextConfig>,
) -> Vc<AppEntry> { ) -> Vc<AppEntry> {
// Read original source's segment config before replacing source into // Read original source's segment config before replacing source into
// dynamic|static metadata route handler. // dynamic|static metadata route handler.
...@@ -66,7 +68,7 @@ pub fn get_app_metadata_route_entry( ...@@ -66,7 +68,7 @@ pub fn get_app_metadata_route_entry(
}; };
let source = Vc::upcast(FileSource::new(original_path)); let source = Vc::upcast(FileSource::new(original_path));
let config = parse_segment_config_from_source(source); let segment_config = parse_segment_config_from_source(source);
get_app_route_entry( get_app_route_entry(
nodejs_context, nodejs_context,
...@@ -74,7 +76,8 @@ pub fn get_app_metadata_route_entry( ...@@ -74,7 +76,8 @@ pub fn get_app_metadata_route_entry(
get_app_metadata_route_source(page.clone(), mode, metadata), get_app_metadata_route_source(page.clone(), mode, metadata),
page, page,
project_root, project_root,
Some(config), Some(segment_config),
next_config,
) )
} }
......
...@@ -7511,11 +7511,10 @@ ...@@ -7511,11 +7511,10 @@
"passed": [ "passed": [
"app dir - with output export - dynamic api route dev development mode should work in dev with dynamicApiRoute 'error'", "app dir - with output export - dynamic api route dev development mode should work in dev with dynamicApiRoute 'error'",
"app dir - with output export - dynamic api route dev development mode should work in dev with dynamicApiRoute 'force-static'", "app dir - with output export - dynamic api route dev development mode should work in dev with dynamicApiRoute 'force-static'",
"app dir - with output export - dynamic api route dev development mode should work in dev with dynamicApiRoute undefined" "app dir - with output export - dynamic api route dev development mode should work in dev with dynamicApiRoute undefined",
],
"failed": [
"app dir - with output export - dynamic api route dev development mode should work in dev with dynamicApiRoute 'force-dynamic'" "app dir - with output export - dynamic api route dev development mode should work in dev with dynamicApiRoute 'force-dynamic'"
], ],
"failed": [],
"pending": [], "pending": [],
"flakey": [], "flakey": [],
"runtimeError": false "runtimeError": false
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