Skip to content

Commit 472770b

Browse files
committed
pick next config keys for more granular caching
1 parent 402d26d commit 472770b

11 files changed

+46
-33
lines changed

crates/next-core/src/next_client/transforms.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ pub async fn get_next_client_transforms_rules(
2929
) -> Result<Vec<ModuleRule>> {
3030
let mut rules = vec![];
3131

32-
let modularize_imports_config = &next_config.await?.modularize_imports;
32+
let modularize_imports_config = &next_config.modularize_imports().await?;
3333
let enable_mdx_rs = next_config.mdx_rs().await?.is_some();
34-
if let Some(modularize_imports_config) = modularize_imports_config {
34+
if !modularize_imports_config.is_empty() {
3535
rules.push(get_next_modularize_imports_rule(
36-
modularize_imports_config,
36+
&modularize_imports_config,
3737
enable_mdx_rs,
3838
));
3939
}

crates/next-core/src/next_config.rs

+22-2
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ struct CustomRoutes {
3636
rewrites: Vc<Rewrites>,
3737
}
3838

39+
#[turbo_tasks::value(transparent)]
40+
pub struct ModularizeImports(IndexMap<String, ModularizeImportPackageConfig>);
41+
3942
#[turbo_tasks::value(serialization = "custom", eq = "manual")]
4043
#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
4144
#[serde(rename_all = "camelCase")]
@@ -481,7 +484,8 @@ pub enum ReactCompilerOptionsOrBoolean {
481484
#[turbo_tasks::value(transparent)]
482485
pub struct OptionalReactCompilerOptions(Option<Vc<ReactCompilerOptions>>);
483486

484-
#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize, TraceRawVcs)]
487+
#[turbo_tasks::value(eq = "manual")]
488+
#[derive(Clone, Debug, Default, PartialEq)]
485489
#[serde(rename_all = "camelCase")]
486490
pub struct ExperimentalConfig {
487491
pub allowed_revalidate_header_keys: Option<Vec<RcStr>>,
@@ -723,7 +727,8 @@ impl StyledComponentsTransformOptionsOrBoolean {
723727
}
724728
}
725729

726-
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, TraceRawVcs)]
730+
#[turbo_tasks::value(eq = "manual")]
731+
#[derive(Clone, Debug, PartialEq, Default)]
727732
#[serde(rename_all = "camelCase")]
728733
pub struct CompilerConfig {
729734
pub react_remove_properties: Option<ReactRemoveProperties>,
@@ -801,6 +806,11 @@ impl NextConfig {
801806
))
802807
}
803808

809+
#[turbo_tasks::function]
810+
pub fn compiler(&self) -> Vc<CompilerConfig> {
811+
self.compiler.clone().unwrap_or_default().cell()
812+
}
813+
804814
#[turbo_tasks::function]
805815
pub async fn env(&self) -> Result<Vc<EnvMap>> {
806816
// The value expected for env is Record<String, String>, but config itself
@@ -999,6 +1009,16 @@ impl NextConfig {
9991009
Ok(options.cell())
10001010
}
10011011

1012+
#[turbo_tasks::function]
1013+
pub fn modularize_imports(&self) -> Vc<ModularizeImports> {
1014+
Vc::cell(self.modularize_imports.clone().unwrap_or_default())
1015+
}
1016+
1017+
#[turbo_tasks::function]
1018+
pub fn experimental(&self) -> Vc<ExperimentalConfig> {
1019+
self.experimental.clone().cell()
1020+
}
1021+
10021022
#[turbo_tasks::function]
10031023
pub async fn react_compiler(&self) -> Result<Vc<OptionalReactCompilerOptions>> {
10041024
let options = &self.experimental.react_compiler;

crates/next-core/src/next_server/transforms.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@ pub async fn get_next_server_transforms_rules(
3232
) -> Result<Vec<ModuleRule>> {
3333
let mut rules = vec![];
3434

35-
let modularize_imports_config = &next_config.await?.modularize_imports;
35+
let modularize_imports_config = &next_config.modularize_imports().await?;
3636
let mdx_rs = next_config.mdx_rs().await?.is_some();
37-
if let Some(modularize_imports_config) = modularize_imports_config {
37+
if !modularize_imports_config.is_empty() {
3838
rules.push(get_next_modularize_imports_rule(
39-
modularize_imports_config,
39+
&modularize_imports_config,
4040
mdx_rs,
4141
));
4242
}

crates/next-core/src/next_shared/transforms/emotion.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ use crate::next_config::{EmotionTransformOptionsOrBoolean, NextConfig};
99
pub async fn get_emotion_transform_rule(next_config: Vc<NextConfig>) -> Result<Option<ModuleRule>> {
1010
let enable_mdx_rs = next_config.mdx_rs().await?.is_some();
1111
let module_rule = next_config
12+
.compiler()
1213
.await?
13-
.compiler
14+
.emotion
1415
.as_ref()
15-
.and_then(|value| value.emotion.as_ref())
1616
.and_then(|config| match config {
1717
EmotionTransformOptionsOrBoolean::Boolean(true) => {
1818
EmotionTransformer::new(&Default::default())

crates/next-core/src/next_shared/transforms/modularize_imports.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use turbopack_ecmascript::{CustomTransformer, EcmascriptInputTransform, Transfor
1818

1919
use super::module_rule_match_js_no_url;
2020

21-
#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize, TraceRawVcs)]
21+
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, TraceRawVcs)]
2222
#[serde(rename_all = "camelCase")]
2323
pub struct ModularizeImportPackageConfig {
2424
pub transform: Transform,
@@ -28,7 +28,7 @@ pub struct ModularizeImportPackageConfig {
2828
pub skip_default_conversion: bool,
2929
}
3030

31-
#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize, TraceRawVcs)]
31+
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, TraceRawVcs)]
3232
#[serde(untagged)]
3333
pub enum Transform {
3434
#[default]

crates/next-core/src/next_shared/transforms/react_remove_properties.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ pub async fn get_react_remove_properties_transform_rule(
2121
let enable_mdx_rs = next_config.mdx_rs().await?.is_some();
2222

2323
let module_rule = next_config
24+
.compiler()
2425
.await?
25-
.compiler
26+
.react_remove_properties
2627
.as_ref()
27-
.and_then(|value| value.react_remove_properties.as_ref())
2828
.and_then(|config| match config {
2929
ReactRemoveProperties::Boolean(false) => None,
3030
ReactRemoveProperties::Boolean(true) => {

crates/next-core/src/next_shared/transforms/relay.rs

+6-8
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,12 @@ pub async fn get_relay_transform_rule(
1414
) -> Result<Option<ModuleRule>> {
1515
let enable_mdx_rs = next_config.mdx_rs().await?.is_some();
1616
let project_path = &*project_path.await?;
17-
let module_rule = next_config.await?.compiler.as_ref().and_then(|value| {
18-
value.relay.as_ref().map(|config| {
19-
get_ecma_transform_rule(
20-
Box::new(RelayTransformer::new(config, project_path)),
21-
enable_mdx_rs,
22-
true,
23-
)
24-
})
17+
let module_rule = next_config.compiler().await?.relay.as_ref().map(|config| {
18+
get_ecma_transform_rule(
19+
Box::new(RelayTransformer::new(config, project_path)),
20+
enable_mdx_rs,
21+
true,
22+
)
2523
});
2624

2725
Ok(module_rule)

crates/next-core/src/next_shared/transforms/remove_console.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ pub async fn get_remove_console_transform_rule(
2121
let enable_mdx_rs = next_config.mdx_rs().await?.is_some();
2222

2323
let module_rule = next_config
24+
.compiler()
2425
.await?
25-
.compiler
26+
.remove_console
2627
.as_ref()
27-
.and_then(|value| value.remove_console.as_ref())
2828
.and_then(|config| match config {
2929
RemoveConsoleConfig::Boolean(false) => None,
3030
RemoveConsoleConfig::Boolean(true) => Some(remove_console::Config::All(true)),

crates/next-core/src/next_shared/transforms/styled_components.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ pub async fn get_styled_components_transform_rule(
1414
let enable_mdx_rs = next_config.mdx_rs().await?.is_some();
1515

1616
let module_rule = next_config
17+
.compiler()
1718
.await?
18-
.compiler
19+
.styled_components
1920
.as_ref()
20-
.and_then(|value| value.styled_components.as_ref())
2121
.and_then(|config| match config {
2222
StyledComponentsTransformOptionsOrBoolean::Boolean(true) => {
2323
Some(StyledComponentsTransformer::new(&Default::default()))

crates/next-core/src/next_shared/transforms/swc_ecma_transform_plugins.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ pub async fn get_swc_ecma_transform_plugin_rule(
1111
next_config: Vc<NextConfig>,
1212
project_path: Vc<FileSystemPath>,
1313
) -> Result<Option<ModuleRule>> {
14-
match next_config.await?.experimental.swc_plugins.as_ref() {
14+
match next_config.experimental().await?.swc_plugins.as_ref() {
1515
Some(plugin_configs) if !plugin_configs.is_empty() => {
1616
#[cfg(feature = "plugin")]
1717
{

crates/next-core/src/transform_options.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -136,12 +136,7 @@ pub async fn get_jsx_transform_options(
136136
false
137137
};
138138

139-
let is_emotion_enabled = next_config
140-
.await?
141-
.compiler
142-
.as_ref()
143-
.map(|c| c.emotion.is_some())
144-
.unwrap_or_default();
139+
let is_emotion_enabled = next_config.compiler().await?.emotion.is_some();
145140

146141
// [NOTE]: ref: WEB-901
147142
// next.js does not allow to overriding react runtime config via tsconfig /

0 commit comments

Comments
 (0)