Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions crates/next-api/src/app.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use anyhow::{Context, Result, bail};
use next_core::{
all_assets_from_entries,
app_segment_config::NextSegmentConfig,
app_structure::{
AppPageLoaderTree, CollectedRootParams, Entrypoint as AppEntrypoint,
Entrypoints as AppEntrypoints, FileSystemPathVec, MetadataItem, collect_root_params,
Expand Down Expand Up @@ -34,6 +33,7 @@ use next_core::{
},
next_server_utility::{NEXT_SERVER_UTILITY_MERGE_TAG, NextServerUtilityTransition},
parse_segment_config_from_source,
segment_config::{NextSegmentConfig, ParseSegmentMode},
util::{NextRuntime, app_function_name, module_styles_rule_condition, styles_rule_condition},
};
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -1106,7 +1106,7 @@ impl AppEndpoint {

for layout in root_layouts.iter().rev() {
let source = Vc::upcast(FileSource::new(layout.clone()));
let layout_config = parse_segment_config_from_source(source);
let layout_config = parse_segment_config_from_source(source, ParseSegmentMode::App);
config.apply_parent_config(&*layout_config.await?);
}

Expand Down
24 changes: 13 additions & 11 deletions crates/next-api/src/middleware.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ use next_core::{
next_edge::entry::wrap_edge_entry,
next_manifests::{EdgeFunctionDefinition, MiddlewareMatcher, MiddlewaresManifestV2, Regions},
next_server::{ServerContextType, get_server_runtime_entries},
util::{MiddlewareMatcherKind, NextRuntime, parse_config_from_source},
parse_segment_config_from_source,
segment_config::ParseSegmentMode,
util::{MiddlewareMatcherKind, NextRuntime},
};
use tracing::Instrument;
use turbo_rcstr::{RcStr, rcstr};
Expand Down Expand Up @@ -86,10 +88,12 @@ impl MiddlewareEndpoint {
userland_module,
);

let config =
parse_config_from_source(*self.source, userland_module, NextRuntime::Edge).await?;
let runtime = parse_segment_config_from_source(*self.source, ParseSegmentMode::Base)
.await?
.runtime
.unwrap_or(NextRuntime::Edge);

if matches!(config.runtime, NextRuntime::NodeJs) {
if matches!(runtime, NextRuntime::NodeJs) {
return Ok(module);
}
Ok(wrap_edge_entry(
Expand Down Expand Up @@ -175,11 +179,9 @@ impl MiddlewareEndpoint {
async fn output_assets(self: Vc<Self>) -> Result<Vc<OutputAssets>> {
let this = self.await?;

let userland_module = self.userland_module();

let config =
parse_config_from_source(*self.await?.source, userland_module, NextRuntime::Edge)
.await?;
parse_segment_config_from_source(*self.await?.source, ParseSegmentMode::Base).await?;
let runtime = config.runtime.unwrap_or(NextRuntime::Edge);

let next_config = this.project.next_config().await?;
let has_i18n = next_config.i18n.is_some();
Expand All @@ -190,7 +192,7 @@ impl MiddlewareEndpoint {
.unwrap_or(false);
let base_path = next_config.base_path.as_ref();

let matchers = if let Some(matchers) = config.matcher.as_ref() {
let matchers = if let Some(matchers) = config.middleware_matcher.as_ref() {
matchers
.iter()
.map(|matcher| {
Expand Down Expand Up @@ -247,7 +249,7 @@ impl MiddlewareEndpoint {
}]
};

if matches!(config.runtime, NextRuntime::NodeJs) {
if matches!(runtime, NextRuntime::NodeJs) {
let chunk = self.node_chunk().to_resolved().await?;
let mut output_assets = vec![chunk];
if this.project.next_mode().await?.is_production() {
Expand Down Expand Up @@ -296,7 +298,7 @@ impl MiddlewareEndpoint {
let all_assets =
get_asset_paths_from_root(&node_root_value, &all_output_assets).await?;

let regions = if let Some(regions) = config.regions.as_ref() {
let regions = if let Some(regions) = config.preferred_region.as_ref() {
if regions.len() == 1 {
regions
.first()
Expand Down
26 changes: 14 additions & 12 deletions crates/next-api/src/pages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ use next_core::{
pages_structure::{
PagesDirectoryStructure, PagesStructure, PagesStructureItem, find_pages_structure,
},
util::{
NextRuntime, get_asset_prefix_from_pathname, pages_function_name, parse_config_from_source,
},
parse_segment_config_from_source,
segment_config::ParseSegmentMode,
util::{NextRuntime, get_asset_prefix_from_pathname, pages_function_name},
};
use serde::{Deserialize, Serialize};
use tracing::Instrument;
Expand Down Expand Up @@ -930,7 +930,9 @@ impl PageEndpoint {
.module();

let config =
parse_config_from_source(self.source(), ssr_module, NextRuntime::default()).await?;
parse_segment_config_from_source(self.source(), ParseSegmentMode::Base).await?;

let runtime = config.runtime.unwrap_or(NextRuntime::NodeJs);

Ok(
// `/_app` and `/_document` never get rendered directly so they don't need to be
Expand All @@ -944,9 +946,9 @@ impl PageEndpoint {
// /_app and /_document are always rendered for Node.js for this case. For edge
// they're included in the page bundle.
runtime: NextRuntime::NodeJs,
regions: config.regions.clone(),
regions: config.preferred_region.clone(),
}
} else if config.runtime == NextRuntime::Edge {
} else if runtime == NextRuntime::Edge {
let modules = create_page_ssr_entry_module(
this.pathname.clone(),
reference_type,
Expand All @@ -955,7 +957,7 @@ impl PageEndpoint {
self.source(),
this.original_name.clone(),
*this.pages_structure,
config.runtime,
runtime,
this.pages_project.project().next_config(),
)
.await?;
Expand All @@ -964,8 +966,8 @@ impl PageEndpoint {
ssr_module: modules.ssr_module,
app_module: modules.app_module,
document_module: modules.document_module,
runtime: config.runtime,
regions: config.regions.clone(),
runtime,
regions: config.preferred_region.clone(),
}
} else {
let modules = create_page_ssr_entry_module(
Expand All @@ -976,16 +978,16 @@ impl PageEndpoint {
self.source(),
this.original_name.clone(),
*this.pages_structure,
config.runtime,
runtime,
this.pages_project.project().next_config(),
)
.await?;
InternalSsrChunkModule {
ssr_module: modules.ssr_module,
app_module: modules.app_module,
document_module: modules.document_module,
runtime: config.runtime,
regions: config.regions.clone(),
runtime,
regions: config.preferred_region.clone(),
}
}
.cell(),
Expand Down
19 changes: 8 additions & 11 deletions crates/next-api/src/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ use next_core::{
get_server_module_options_context, get_server_resolve_options_context,
},
next_telemetry::NextFeatureTelemetry,
util::{NextRuntime, OptionEnvMap, parse_config_from_source},
parse_segment_config_from_source,
segment_config::ParseSegmentMode,
util::{NextRuntime, OptionEnvMap},
};
use serde::{Deserialize, Serialize};
use tracing::Instrument;
Expand Down Expand Up @@ -66,7 +68,6 @@ use turbopack_core::{
export_usage::{OptionExportUsageInfo, compute_export_usage_info},
},
output::{OutputAsset, OutputAssets},
reference_type::{EntryReferenceSubType, ReferenceType},
resolve::{FindContextFileResult, find_context_file},
source_map::OptionStringifiedSourceMap,
version::{
Expand Down Expand Up @@ -1412,16 +1413,12 @@ impl Project {
};
let source = Vc::upcast(FileSource::new(fs_path.clone()));

let module = edge_module_context
.process(
source,
ReferenceType::Entry(EntryReferenceSubType::Middleware),
)
.module();

let config = parse_config_from_source(source, module, NextRuntime::Edge).await?;
let runtime = parse_segment_config_from_source(source, ParseSegmentMode::Base)
.await?
.runtime
.unwrap_or(NextRuntime::Edge);

if matches!(config.runtime, NextRuntime::NodeJs) {
if matches!(runtime, NextRuntime::NodeJs) {
Ok(self.node_middleware_context())
} else {
Ok(edge_module_context)
Expand Down
Loading
Loading