-
Notifications
You must be signed in to change notification settings - Fork 26.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(next-core): move transforms to plugin (#49621)
### What? relateed to WEB-1048. Moving emotion to the plugin, deprecate enable_emotion option.
- Loading branch information
Showing
7 changed files
with
192 additions
and
118 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
packages/next-swc/crates/next-core/src/next_shared/transforms/emotion.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
use anyhow::Result; | ||
use turbopack_binding::turbopack::{ | ||
ecmascript::{OptionTransformPluginVc, TransformPluginVc}, | ||
ecmascript_plugin::transform::emotion::{EmotionTransformConfig, EmotionTransformer}, | ||
}; | ||
|
||
use crate::next_config::{EmotionTransformOptionsOrBoolean, NextConfigVc}; | ||
|
||
#[turbo_tasks::function] | ||
pub async fn get_emotion_transform_plugin( | ||
next_config: NextConfigVc, | ||
) -> Result<OptionTransformPluginVc> { | ||
let transform_plugin = next_config | ||
.await? | ||
.compiler | ||
.as_ref() | ||
.map(|value| { | ||
value | ||
.emotion | ||
.as_ref() | ||
.map(|value| { | ||
let transformer = match value { | ||
EmotionTransformOptionsOrBoolean::Boolean(true) => { | ||
EmotionTransformer::new(&EmotionTransformConfig { | ||
..Default::default() | ||
}) | ||
} | ||
EmotionTransformOptionsOrBoolean::Boolean(false) => None, | ||
|
||
EmotionTransformOptionsOrBoolean::Options(value) => { | ||
EmotionTransformer::new(value) | ||
} | ||
}; | ||
|
||
transformer.map_or_else( | ||
|| OptionTransformPluginVc::cell(None), | ||
|v| { | ||
OptionTransformPluginVc::cell(Some(TransformPluginVc::cell(Box::new( | ||
v, | ||
)))) | ||
}, | ||
) | ||
}) | ||
.unwrap_or_default() | ||
}) | ||
.unwrap_or_default(); | ||
|
||
Ok(transform_plugin) | ||
} |
3 changes: 3 additions & 0 deletions
3
packages/next-swc/crates/next-core/src/next_shared/transforms/mod.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
packages/next-swc/crates/next-core/src/next_shared/transforms/styled_components.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
use anyhow::Result; | ||
use turbopack_binding::turbopack::{ | ||
ecmascript::{OptionTransformPluginVc, TransformPluginVc}, | ||
ecmascript_plugin::transform::styled_components::{ | ||
StyledComponentsTransformConfig, StyledComponentsTransformer, | ||
}, | ||
}; | ||
|
||
use crate::next_config::{NextConfigVc, StyledComponentsTransformOptionsOrBoolean}; | ||
|
||
#[turbo_tasks::function] | ||
pub async fn get_styled_components_transform_plugin( | ||
next_config: NextConfigVc, | ||
) -> Result<OptionTransformPluginVc> { | ||
let transform_plugin = next_config | ||
.await? | ||
.compiler | ||
.as_ref() | ||
.map(|value| { | ||
value | ||
.styled_components | ||
.as_ref() | ||
.map(|value| { | ||
let transformer = match value { | ||
StyledComponentsTransformOptionsOrBoolean::Boolean(true) => Some( | ||
StyledComponentsTransformer::new(&StyledComponentsTransformConfig { | ||
..Default::default() | ||
}), | ||
), | ||
StyledComponentsTransformOptionsOrBoolean::Boolean(false) => None, | ||
StyledComponentsTransformOptionsOrBoolean::Options(value) => { | ||
Some(StyledComponentsTransformer::new(value)) | ||
} | ||
}; | ||
|
||
transformer.map_or_else( | ||
|| OptionTransformPluginVc::cell(None), | ||
|v| { | ||
OptionTransformPluginVc::cell(Some(TransformPluginVc::cell(Box::new( | ||
v, | ||
)))) | ||
}, | ||
) | ||
}) | ||
.unwrap_or_default() | ||
}) | ||
.unwrap_or_default(); | ||
|
||
Ok(transform_plugin) | ||
} |
13 changes: 13 additions & 0 deletions
13
packages/next-swc/crates/next-core/src/next_shared/transforms/styled_jsx.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
use anyhow::Result; | ||
use turbopack_binding::turbopack::{ | ||
ecmascript::{OptionTransformPluginVc, TransformPluginVc}, | ||
ecmascript_plugin::transform::styled_jsx::StyledJsxTransformer, | ||
}; | ||
|
||
/// Returns a transform plugin for the relay graphql transform. | ||
#[turbo_tasks::function] | ||
pub async fn get_styled_jsx_transform_plugin() -> Result<OptionTransformPluginVc> { | ||
Ok(OptionTransformPluginVc::cell(Some( | ||
TransformPluginVc::cell(Box::new(StyledJsxTransformer::new())), | ||
))) | ||
} |
Oops, something went wrong.