Skip to content

Commit 9d1540b

Browse files
committed
Revert "make all next config fields private"
This reverts commit da6fc2c.
1 parent fc60d34 commit 9d1540b

File tree

5 files changed

+55
-93
lines changed

5 files changed

+55
-93
lines changed

crates/next-api/src/middleware.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -157,14 +157,14 @@ impl MiddlewareEndpoint {
157157
parse_segment_config_from_source(*self.await?.source, ParseSegmentMode::Base).await?;
158158
let runtime = config.runtime.unwrap_or(NextRuntime::Edge);
159159

160-
let next_config = this.project.next_config();
161-
let i18n = next_config.i18n().await?;
162-
let has_i18n = i18n.is_some();
163-
let has_i18n_locales = i18n
160+
let next_config = this.project.next_config().await?;
161+
let has_i18n = next_config.i18n.is_some();
162+
let has_i18n_locales = next_config
163+
.i18n
164164
.as_ref()
165165
.map(|i18n| i18n.locales.len() > 1)
166166
.unwrap_or(false);
167-
let base_path = next_config.base_path().await?;
167+
let base_path = next_config.base_path.as_ref();
168168

169169
let matchers = if let Some(matchers) = config.middleware_matcher.as_ref() {
170170
matchers
@@ -202,7 +202,7 @@ impl MiddlewareEndpoint {
202202

203203
source.insert_str(0, "/:nextData(_next/data/[^/]{1,})?");
204204

205-
if let Some(base_path) = base_path.as_ref() {
205+
if let Some(base_path) = base_path {
206206
source.insert_str(0, base_path);
207207
}
208208

crates/next-api/src/project.rs

Lines changed: 13 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -479,8 +479,8 @@ impl ProjectContainer {
479479
}
480480

481481
let dist_dir = next_config
482-
.dist_dir()
483482
.await?
483+
.dist_dir
484484
.as_ref()
485485
.map_or_else(|| rcstr!(".next"), |d| d.clone());
486486

@@ -722,17 +722,13 @@ impl Project {
722722

723723
#[turbo_tasks::function]
724724
pub async fn client_relative_path(self: Vc<Self>) -> Result<Vc<FileSystemPath>> {
725-
let next_config = self.next_config();
725+
let next_config = self.next_config().await?;
726726
Ok(self
727727
.client_root()
728728
.await?
729729
.join(&format!(
730730
"{}/_next",
731-
next_config
732-
.base_path()
733-
.await?
734-
.as_deref()
735-
.unwrap_or_default(),
731+
next_config.base_path.clone().unwrap_or_default(),
736732
))?
737733
.cell())
738734
}
@@ -1160,38 +1156,26 @@ impl Project {
11601156
*config.persistent_caching_enabled().await?,
11611157
);
11621158

1163-
emit_event(
1164-
"modularizeImports",
1165-
!config.modularize_imports().await?.is_empty(),
1166-
);
1167-
emit_event(
1168-
"transpilePackages",
1169-
!config.transpile_packages().await?.is_empty(),
1170-
);
1159+
let config = &config.await?;
1160+
1161+
emit_event("modularizeImports", config.modularize_imports.is_some());
1162+
emit_event("transpilePackages", config.transpile_packages.is_some());
11711163
emit_event("turbotrace", false);
11721164

11731165
// compiler options
1174-
let compiler_options = config.compiler().await?;
1175-
let swc_relay_enabled = compiler_options.relay.is_some();
1166+
let compiler_options = config.compiler.as_ref();
1167+
let swc_relay_enabled = compiler_options.and_then(|c| c.relay.as_ref()).is_some();
11761168
let styled_components_enabled = compiler_options
1177-
.styled_components
1178-
.as_ref()
1179-
.map(|sc| sc.is_enabled())
1169+
.and_then(|c| c.styled_components.as_ref().map(|sc| sc.is_enabled()))
11801170
.unwrap_or_default();
11811171
let react_remove_properties_enabled = compiler_options
1182-
.react_remove_properties
1183-
.as_ref()
1184-
.map(|rc| rc.is_enabled())
1172+
.and_then(|c| c.react_remove_properties.as_ref().map(|rc| rc.is_enabled()))
11851173
.unwrap_or_default();
11861174
let remove_console_enabled = compiler_options
1187-
.remove_console
1188-
.as_ref()
1189-
.map(|rc| rc.is_enabled())
1175+
.and_then(|c| c.remove_console.as_ref().map(|rc| rc.is_enabled()))
11901176
.unwrap_or_default();
11911177
let emotion_enabled = compiler_options
1192-
.emotion
1193-
.as_ref()
1194-
.map(|e| e.is_enabled())
1178+
.and_then(|c| c.emotion.as_ref().map(|e| e.is_enabled()))
11951179
.unwrap_or_default();
11961180

11971181
emit_event("swcRelay", swc_relay_enabled);

crates/next-core/src/next_app/app_page_entry.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ pub async fn get_app_page_entry(
4848
let server_component_transition =
4949
ResolvedVc::upcast(NextServerComponentTransition::new().to_resolved().await?);
5050

51-
let base_path = next_config.base_path().owned().await?;
51+
let base_path = next_config.await?.base_path.clone();
5252
let loader_tree = AppPageLoaderTreeModule::build(
5353
loader_tree,
5454
module_asset_context,

crates/next-core/src/next_config.rs

Lines changed: 33 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -75,40 +75,40 @@ impl Default for CacheKinds {
7575
#[derive(Clone, Debug, Default, PartialEq)]
7676
#[serde(default, rename_all = "camelCase")]
7777
pub struct NextConfig {
78-
// IMPORTANT: all fields should be private and access should be wrapped within a turbo-tasks
79-
// function. Otherwise changing NextConfig will lead to invalidating all tasks accessing it.
80-
config_file: Option<RcStr>,
81-
config_file_name: RcStr,
78+
// TODO all fields should be private and access should be wrapped within a turbo-tasks function
79+
// Otherwise changing NextConfig will lead to invalidating all tasks accessing it.
80+
pub config_file: Option<RcStr>,
81+
pub config_file_name: RcStr,
8282

8383
/// In-memory cache size in bytes.
8484
///
8585
/// If `cache_max_memory_size: 0` disables in-memory caching.
86-
cache_max_memory_size: Option<f64>,
86+
pub cache_max_memory_size: Option<f64>,
8787
/// custom path to a cache handler to use
88-
cache_handler: Option<RcStr>,
89-
90-
env: FxIndexMap<String, JsonValue>,
91-
experimental: ExperimentalConfig,
92-
images: ImageConfig,
93-
page_extensions: Vec<RcStr>,
94-
react_compiler: Option<ReactCompilerOptionsOrBoolean>,
95-
react_production_profiling: Option<bool>,
96-
react_strict_mode: Option<bool>,
97-
transpile_packages: Option<Vec<RcStr>>,
98-
modularize_imports: Option<FxIndexMap<String, ModularizeImportPackageConfig>>,
99-
dist_dir: Option<RcStr>,
100-
deployment_id: Option<RcStr>,
88+
pub cache_handler: Option<RcStr>,
89+
90+
pub env: FxIndexMap<String, JsonValue>,
91+
pub experimental: ExperimentalConfig,
92+
pub images: ImageConfig,
93+
pub page_extensions: Vec<RcStr>,
94+
pub react_compiler: Option<ReactCompilerOptionsOrBoolean>,
95+
pub react_production_profiling: Option<bool>,
96+
pub react_strict_mode: Option<bool>,
97+
pub transpile_packages: Option<Vec<RcStr>>,
98+
pub modularize_imports: Option<FxIndexMap<String, ModularizeImportPackageConfig>>,
99+
pub dist_dir: Option<RcStr>,
100+
pub deployment_id: Option<RcStr>,
101101
sass_options: Option<serde_json::Value>,
102-
trailing_slash: Option<bool>,
103-
asset_prefix: Option<RcStr>,
104-
base_path: Option<RcStr>,
105-
skip_middleware_url_normalize: Option<bool>,
106-
skip_trailing_slash_redirect: Option<bool>,
107-
i18n: Option<I18NConfig>,
102+
pub trailing_slash: Option<bool>,
103+
pub asset_prefix: Option<RcStr>,
104+
pub base_path: Option<RcStr>,
105+
pub skip_middleware_url_normalize: Option<bool>,
106+
pub skip_trailing_slash_redirect: Option<bool>,
107+
pub i18n: Option<I18NConfig>,
108108
cross_origin: Option<CrossOriginConfig>,
109-
dev_indicators: Option<DevIndicatorsConfig>,
109+
pub dev_indicators: Option<DevIndicatorsConfig>,
110110
output: Option<OutputType>,
111-
turbopack: Option<TurbopackConfig>,
111+
pub turbopack: Option<TurbopackConfig>,
112112
production_browser_source_maps: bool,
113113
output_file_tracing_includes: Option<serde_json::Value>,
114114
output_file_tracing_excludes: Option<serde_json::Value>,
@@ -119,21 +119,21 @@ pub struct NextConfig {
119119
/// server-side bundles.
120120
///
121121
/// [API Reference](https://nextjs.org/docs/pages/api-reference/next-config-js/bundlePagesRouterDependencies)
122-
bundle_pages_router_dependencies: Option<bool>,
122+
pub bundle_pages_router_dependencies: Option<bool>,
123123

124124
/// A list of packages that should be treated as external on the server
125125
/// build.
126126
///
127127
/// [API Reference](https://nextjs.org/docs/app/api-reference/next-config-js/serverExternalPackages)
128-
server_external_packages: Option<Vec<RcStr>>,
128+
pub server_external_packages: Option<Vec<RcStr>>,
129129

130130
#[serde(rename = "_originalRedirects")]
131-
original_redirects: Option<Vec<Redirect>>,
131+
pub original_redirects: Option<Vec<Redirect>>,
132132

133133
// Partially supported
134-
compiler: Option<CompilerConfig>,
134+
pub compiler: Option<CompilerConfig>,
135135

136-
optimize_fonts: Option<bool>,
136+
pub optimize_fonts: Option<bool>,
137137

138138
clean_dist_dir: bool,
139139
compress: bool,
@@ -265,7 +265,7 @@ struct HttpAgentConfig {
265265
}
266266

267267
#[derive(
268-
Clone, Debug, PartialEq, Eq, Serialize, Deserialize, TraceRawVcs, NonLocalValue, OperationValue,
268+
Clone, Debug, PartialEq, Serialize, Deserialize, TraceRawVcs, NonLocalValue, OperationValue,
269269
)]
270270
#[serde(rename_all = "camelCase")]
271271
pub struct DomainLocale {
@@ -276,7 +276,7 @@ pub struct DomainLocale {
276276
}
277277

278278
#[derive(
279-
Clone, Debug, PartialEq, Eq, Serialize, Deserialize, TraceRawVcs, NonLocalValue, OperationValue,
279+
Clone, Debug, PartialEq, Serialize, Deserialize, TraceRawVcs, NonLocalValue, OperationValue,
280280
)]
281281
#[serde(rename_all = "camelCase")]
282282
pub struct I18NConfig {
@@ -286,9 +286,6 @@ pub struct I18NConfig {
286286
pub locales: Vec<String>,
287287
}
288288

289-
#[turbo_tasks::value(transparent)]
290-
pub struct OptionI18NConfig(Option<I18NConfig>);
291-
292289
#[derive(
293290
Clone, Debug, PartialEq, Eq, Serialize, Deserialize, TraceRawVcs, NonLocalValue, OperationValue,
294291
)]
@@ -1339,11 +1336,6 @@ impl NextConfig {
13391336
Vc::cell(self.output == Some(OutputType::Standalone))
13401337
}
13411338

1342-
#[turbo_tasks::function]
1343-
pub fn base_path(&self) -> Vc<Option<RcStr>> {
1344-
Vc::cell(self.base_path.clone())
1345-
}
1346-
13471339
#[turbo_tasks::function]
13481340
pub fn cache_handler(&self, project_path: FileSystemPath) -> Result<Vc<OptionFileSystemPath>> {
13491341
if let Some(handler) = &self.cache_handler {
@@ -1545,11 +1537,6 @@ impl NextConfig {
15451537
}))
15461538
}
15471539

1548-
#[turbo_tasks::function]
1549-
pub fn inline_css(&self) -> Vc<bool> {
1550-
Vc::cell(self.experimental.inline_css.unwrap_or(false))
1551-
}
1552-
15531540
#[turbo_tasks::function]
15541541
pub fn mdx_rs(&self) -> Vc<OptionalMdxTransformOptions> {
15551542
let options = &self.experimental.mdx_rs;
@@ -1585,11 +1572,6 @@ impl NextConfig {
15851572
Vc::cell(self.modularize_imports.clone().unwrap_or_default())
15861573
}
15871574

1588-
#[turbo_tasks::function]
1589-
pub fn dist_dir(&self) -> Vc<Option<RcStr>> {
1590-
Vc::cell(self.dist_dir.clone())
1591-
}
1592-
15931575
#[turbo_tasks::function]
15941576
pub fn experimental_cache_handlers(
15951577
&self,
@@ -1886,11 +1868,6 @@ impl NextConfig {
18861868
Vc::cell(self.cross_origin.clone())
18871869
}
18881870

1889-
#[turbo_tasks::function]
1890-
pub fn i18n(&self) -> Vc<OptionI18NConfig> {
1891-
Vc::cell(self.i18n.clone())
1892-
}
1893-
18941871
#[turbo_tasks::function]
18951872
pub fn output(&self) -> Vc<OptionOutputType> {
18961873
Vc::cell(self.output.clone())

crates/next-core/src/next_manifests/client_reference_manifest.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,8 @@ async fn build_manifest(
438438
cached_chunk_paths(&mut client_chunk_path_cache, client_chunks.iter().copied())
439439
.await?;
440440
// Inlining breaks HMR so it is always disabled in dev.
441-
let inlined_css = *next_config.inline_css().await? && mode.is_production();
441+
let inlined_css =
442+
next_config.await?.experimental.inline_css.unwrap_or(false) && mode.is_production();
442443

443444
for (chunk, chunk_path) in client_chunks_with_path {
444445
if let Some(path) = client_relative_path.get_path_to(&chunk_path) {

0 commit comments

Comments
 (0)