Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(turbopack): support initial compiler.emotion / compiler.styledComponents flag #47991

Merged
merged 7 commits into from
Apr 12, 2023
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
60 changes: 30 additions & 30 deletions packages/next-swc/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions packages/next-swc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ swc_emotion = { version = "0.29.10" }
testing = { version = "0.31.31" }

# Turbo crates
turbo-binding = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-230411.2" }
turbo-binding = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-230412.2" }
# [TODO]: need to refactor embed_directory! macro usages, as well as resolving turbo_tasks::function, macros..
turbo-tasks = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-230411.2" }
turbo-tasks = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-230412.2" }
# [TODO]: need to refactor embed_directory! macro usage in next-core
turbo-tasks-fs = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-230411.2" }
turbo-tasks-fs = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-230412.2" }

# General Deps

Expand Down
12 changes: 8 additions & 4 deletions packages/next-swc/crates/next-core/src/next_client/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ use crate::{
},
react_refresh::assert_can_resolve_react_refresh,
transform_options::{
get_decorators_transform_options, get_jsx_transform_options,
get_typescript_transform_options,
get_decorators_transform_options, get_emotion_compiler_config, get_jsx_transform_options,
get_styled_components_compiler_config, get_typescript_transform_options,
},
util::foreign_code_context_condition,
};
Expand Down Expand Up @@ -175,6 +175,8 @@ pub async fn get_client_module_options_context(
.clone_if()
};

let enable_emotion = *get_emotion_compiler_config(next_config).await?;

let module_options_context = ModuleOptionsContext {
custom_ecmascript_transforms: vec![EcmascriptInputTransform::ServerDirective(
StringVc::cell("TODO".to_string()),
Expand All @@ -184,14 +186,16 @@ pub async fn get_client_module_options_context(
..Default::default()
};

let enable_styled_components = *get_styled_components_compiler_config(next_config).await?;

let module_options_context = ModuleOptionsContext {
// We don't need to resolve React Refresh for each module. Instead,
// we try resolve it once at the root and pass down a context to all
// the modules.
enable_jsx: Some(jsx_runtime_options),
enable_emotion: true,
enable_emotion,
enable_react_refresh,
enable_styled_components: true,
enable_styled_components,
enable_styled_jsx: true,
enable_postcss_transform: Some(PostCssTransformOptions {
postcss_package: Some(get_postcss_package_mapping(project_path)),
Expand Down
25 changes: 23 additions & 2 deletions packages/next-swc/crates/next-core/src/next_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ use turbo_binding::{
execution_context::{ExecutionContext, ExecutionContextVc},
transforms::webpack::{WebpackLoaderConfigItems, WebpackLoaderConfigItemsVc},
},
turbopack::evaluate_context::node_evaluate_asset_context,
turbopack::{
evaluate_context::node_evaluate_asset_context,
module_options::{EmotionTransformConfig, StyledComponentsTransformConfig},
},
},
};
use turbo_tasks::{
Expand All @@ -55,9 +58,11 @@ pub struct NextConfig {
pub rewrites: Rewrites,
pub transpile_packages: Option<Vec<String>>,

// Partially supported
pub compiler: Option<CompilerConfig>,

// unsupported
cross_origin: Option<String>,
compiler: Option<CompilerConfig>,
amp: AmpConfig,
analytics_id: String,
asset_prefix: String,
Expand Down Expand Up @@ -415,12 +420,28 @@ enum MiddlewarePrefetchType {
Flexible,
}

#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, TraceRawVcs)]
#[serde(untagged)]
pub enum EmotionTransformOptionsOrBoolean {
Boolean(bool),
Options(EmotionTransformConfig),
}

#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, TraceRawVcs)]
#[serde(untagged)]
pub enum StyledComponentsTransformOptionsOrBoolean {
Boolean(bool),
Options(StyledComponentsTransformConfig),
}

#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, TraceRawVcs)]
#[serde(rename_all = "camelCase")]
pub struct CompilerConfig {
pub react_remove_properties: Option<bool>,
pub relay: Option<RelayConfig>,
pub emotion: Option<EmotionTransformOptionsOrBoolean>,
pub remove_console: Option<RemoveConsoleConfig>,
pub styled_components: Option<StyledComponentsTransformOptionsOrBoolean>,
}

#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, TraceRawVcs)]
Expand Down
Loading