Skip to content

Commit

Permalink
refactor(next-core): consolidate react_refresh options
Browse files Browse the repository at this point in the history
  • Loading branch information
kwonoj committed May 15, 2023
1 parent 6fd866b commit 5bcec46
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 46 deletions.
66 changes: 33 additions & 33 deletions 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 Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ swc_core = { version = "0.75.41" }
testing = { version = "0.33.4" }

# Turbo crates
turbo-binding = { package = "turbopack-binding", git = "https://github.com/vercel/turbo.git", tag = "turbopack-230511.3" }
turbo-binding = { package = "turbopack-binding", git = "https://github.com/vercel/turbo.git", tag = "turbopack-230515.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-230511.3" }
turbo-tasks = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-230515.2" }
# [TODO]: need to refactor embed_directory! macro usage in next-core
turbo-tasks-fs = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-230511.3" }
turbo-tasks-fs = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-230515.2" }

# General Deps

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,15 +170,11 @@ pub async fn get_client_module_options_context(
let custom_rules = get_next_client_transforms_rules(next_config, ty.into_value()).await?;
let resolve_options_context =
get_client_resolve_options_context(project_path, ty, next_config, execution_context);
let enable_react_refresh =
assert_can_resolve_react_refresh(project_path, resolve_options_context)
.await?
.is_found();

let tsconfig = get_typescript_transform_options(project_path);
let decorators_options = get_decorators_transform_options(project_path);
let mdx_rs_options = *next_config.mdx_rs().await?;
let jsx_runtime_options = get_jsx_transform_options(project_path);
let jsx_runtime_options = get_jsx_transform_options(project_path, Some(resolve_options_context));
let enable_webpack_loaders = {
let options = &*next_config.webpack_loaders_options().await?;
let loaders_options = WebpackLoadersOptions {
Expand Down Expand Up @@ -240,7 +236,6 @@ pub async fn get_client_module_options_context(
// the modules.
enable_jsx: Some(jsx_runtime_options),
enable_emotion,
enable_react_refresh,
enable_styled_components,
enable_styled_jsx: true,
enable_postcss_transform: postcss_transform_options,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ pub async fn get_server_module_options_context(
let tsconfig = get_typescript_transform_options(project_path);
let decorators_options = get_decorators_transform_options(project_path);
let mdx_rs_options = *next_config.mdx_rs().await?;
let jsx_runtime_options = get_jsx_transform_options(project_path);
let jsx_runtime_options = get_jsx_transform_options(project_path, None);
let enable_emotion = *get_emotion_compiler_config(next_config).await?;
let enable_styled_components = *get_styled_components_compiler_config(next_config).await?;

Expand Down
20 changes: 17 additions & 3 deletions packages/next-swc/crates/next-core/src/transform_options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use turbo_binding::{
resolve::{find_context_file, node::node_cjs_resolve_options, FindContextFileResult},
source_asset::SourceAssetVc,
},
dev::react_refresh::assert_can_resolve_react_refresh,
ecmascript::typescript::resolve::{read_from_tsconfigs, read_tsconfigs, tsconfig},
ecmascript_plugin::transform::{
emotion::{
Expand All @@ -16,9 +17,12 @@ use turbo_binding::{
OptionStyledComponentsTransformConfigVc, StyledComponentsTransformConfig,
},
},
turbopack::module_options::{
DecoratorsKind, DecoratorsOptions, DecoratorsOptionsVc, JsxTransformOptions,
JsxTransformOptionsVc, TypescriptTransformOptions, TypescriptTransformOptionsVc,
turbopack::{
module_options::{
DecoratorsKind, DecoratorsOptions, DecoratorsOptionsVc, JsxTransformOptions,
JsxTransformOptionsVc, TypescriptTransformOptions, TypescriptTransformOptionsVc,
},
resolve_options_context::ResolveOptionsContextVc,
},
},
};
Expand Down Expand Up @@ -131,16 +135,26 @@ pub async fn get_decorators_transform_options(
#[turbo_tasks::function]
pub async fn get_jsx_transform_options(
project_path: FileSystemPathVc,
resolve_options_context: Option<ResolveOptionsContextVc>,
) -> Result<JsxTransformOptionsVc> {
let tsconfig = get_typescript_options(project_path).await;

let enable_react_refresh = if let Some(resolve_options_context) = resolve_options_context {
assert_can_resolve_react_refresh(project_path, resolve_options_context)
.await?
.is_found()
} else {
false
};

// [NOTE]: ref: WEB-901
// next.js does not allow to overriding react runtime config via tsconfig /
// jsconfig, it forces overrides into automatic runtime instead.
// [TODO]: we need to emit / validate config message like next.js devserver does
let react_transform_options = JsxTransformOptions {
import_source: None,
runtime: Some("automatic".to_string()),
react_refresh: enable_react_refresh,
};

let react_transform_options = if let Some(tsconfig) = tsconfig {
Expand Down

0 comments on commit 5bcec46

Please sign in to comment.