Skip to content

Commit

Permalink
fix(next_core): do not apply user config to internal assets
Browse files Browse the repository at this point in the history
  • Loading branch information
kwonoj committed May 2, 2023
1 parent 7b2c79d commit 14860d1
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 26 deletions.
27 changes: 22 additions & 5 deletions packages/next-swc/crates/next-core/src/next_client/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@ use turbo_binding::{
env::ProcessEnvAssetVc,
node::execution_context::ExecutionContextVc,
turbopack::{
condition::ContextCondition,
module_options::{
module_options_context::{ModuleOptionsContext, ModuleOptionsContextVc},
PostCssTransformOptions, WebpackLoadersOptions,
JsxTransformOptions, PostCssTransformOptions, TypescriptTransformOptions,
WebpackLoadersOptions,
},
resolve_options_context::{ResolveOptionsContext, ResolveOptionsContextVc},
transition::TransitionsByNameVc,
Expand All @@ -34,10 +36,12 @@ use turbo_binding::{
},
};
use turbo_tasks::{primitives::StringVc, Value};
use turbo_tasks_fs::FileSystem;

use super::transforms::get_next_client_transforms_rules;
use crate::{
babel::maybe_add_babel_loader,
embed_js::next_js_fs,
env::env_for_js,
next_build::{get_external_next_compiled_package_mapping, get_postcss_package_mapping},
next_client::runtime_entry::{RuntimeEntriesVc, RuntimeEntry},
Expand Down Expand Up @@ -219,10 +223,23 @@ pub async fn get_client_module_options_context(
enable_typescript_transform: Some(tsconfig),
enable_mdx_rs: mdx_rs_options,
decorators: Some(decorators_options),
rules: vec![(
foreign_code_context_condition(next_config).await?,
module_options_context.clone().cell(),
)],
rules: vec![
(
foreign_code_context_condition(next_config).await?,
module_options_context.clone().cell(),
),
// If module is internal assets (i.e overlay, fallback) coming from embed_js fs root
// We will not apply any user defined transforms
(
ContextCondition::InPath(next_js_fs().root()),
(ModuleOptionsContext {
enable_typescript_transform: Some(TypescriptTransformOptions::default().cell()),
enable_jsx: Some(JsxTransformOptions::default().cell()),
..module_options_context.clone()
})
.cell(),
),
],
custom_rules,
..module_options_context
}
Expand Down
99 changes: 78 additions & 21 deletions packages/next-swc/crates/next-core/src/next_server/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,24 @@ use turbo_binding::{
ecmascript::EcmascriptInputTransform,
node::execution_context::ExecutionContextVc,
turbopack::{
condition::ContextCondition,
module_options::{
ModuleOptionsContext, ModuleOptionsContextVc, PostCssTransformOptions,
WebpackLoadersOptions,
TypescriptTransformOptions, WebpackLoadersOptions,
},
resolve_options_context::{ResolveOptionsContext, ResolveOptionsContextVc},
},
},
};
use turbo_tasks::{primitives::StringVc, Value};
use turbo_tasks_fs::FileSystem;

use super::{
resolve::ExternalCjsModulesResolvePluginVc, transforms::get_next_server_transforms_rules,
};
use crate::{
babel::maybe_add_babel_loader,
embed_js::next_js_fs,
next_build::{get_external_next_compiled_package_mapping, get_postcss_package_mapping},
next_config::NextConfigVc,
next_import_map::get_next_server_import_map,
Expand Down Expand Up @@ -270,6 +273,13 @@ pub async fn get_server_module_options_context(
execution_context: Some(execution_context),
..Default::default()
};

let internal_module_options_context = ModuleOptionsContext {
enable_typescript_transform: Some(TypescriptTransformOptions::default().cell()),
enable_jsx: Some(JsxTransformOptions::default().cell()),
..module_options_context.clone()
};

ModuleOptionsContext {
enable_jsx: Some(jsx_runtime_options),
enable_styled_jsx: true,
Expand All @@ -280,10 +290,16 @@ pub async fn get_server_module_options_context(
enable_typescript_transform: Some(tsconfig),
enable_mdx_rs: mdx_rs_options,
decorators: Some(decorators_options),
rules: vec![(
foreign_code_context_condition,
module_options_context.clone().cell(),
)],
rules: vec![
(
foreign_code_context_condition,
module_options_context.clone().cell(),
),
(
ContextCondition::InPath(next_js_fs().root()),
internal_module_options_context.cell(),
),
],
custom_rules,
..module_options_context
}
Expand All @@ -298,6 +314,11 @@ pub async fn get_server_module_options_context(
execution_context: Some(execution_context),
..Default::default()
};
let internal_module_options_context = ModuleOptionsContext {
enable_typescript_transform: Some(TypescriptTransformOptions::default().cell()),
..module_options_context.clone()
};

ModuleOptionsContext {
enable_jsx: Some(jsx_runtime_options),
enable_styled_jsx: true,
Expand All @@ -308,10 +329,16 @@ pub async fn get_server_module_options_context(
enable_typescript_transform: Some(tsconfig),
enable_mdx_rs: mdx_rs_options,
decorators: Some(decorators_options),
rules: vec![(
foreign_code_context_condition,
module_options_context.clone().cell(),
)],
rules: vec![
(
foreign_code_context_condition,
module_options_context.clone().cell(),
),
(
ContextCondition::InPath(next_js_fs().root()),
internal_module_options_context.cell(),
),
],
custom_rules,
..module_options_context
}
Expand All @@ -332,6 +359,10 @@ pub async fn get_server_module_options_context(
execution_context: Some(execution_context),
..Default::default()
};
let internal_module_options_context = ModuleOptionsContext {
enable_typescript_transform: Some(TypescriptTransformOptions::default().cell()),
..module_options_context.clone()
};
ModuleOptionsContext {
enable_jsx: Some(jsx_runtime_options),
enable_emotion,
Expand All @@ -341,10 +372,16 @@ pub async fn get_server_module_options_context(
enable_typescript_transform: Some(tsconfig),
enable_mdx_rs: mdx_rs_options,
decorators: Some(decorators_options),
rules: vec![(
foreign_code_context_condition,
module_options_context.clone().cell(),
)],
rules: vec![
(
foreign_code_context_condition,
module_options_context.clone().cell(),
),
(
ContextCondition::InPath(next_js_fs().root()),
internal_module_options_context.cell(),
),
],
custom_rules,
..module_options_context
}
Expand All @@ -354,16 +391,26 @@ pub async fn get_server_module_options_context(
execution_context: Some(execution_context),
..Default::default()
};
let internal_module_options_context = ModuleOptionsContext {
enable_typescript_transform: Some(TypescriptTransformOptions::default().cell()),
..module_options_context.clone()
};
ModuleOptionsContext {
enable_postcss_transform,
enable_webpack_loaders,
enable_typescript_transform: Some(tsconfig),
enable_mdx_rs: mdx_rs_options,
decorators: Some(decorators_options),
rules: vec![(
foreign_code_context_condition,
module_options_context.clone().cell(),
)],
rules: vec![
(
foreign_code_context_condition,
module_options_context.clone().cell(),
),
(
ContextCondition::InPath(next_js_fs().root()),
internal_module_options_context.cell(),
),
],
custom_rules,
..module_options_context
}
Expand All @@ -373,6 +420,10 @@ pub async fn get_server_module_options_context(
execution_context: Some(execution_context),
..Default::default()
};
let internal_module_options_context = ModuleOptionsContext {
enable_typescript_transform: Some(TypescriptTransformOptions::default().cell()),
..module_options_context.clone()
};
ModuleOptionsContext {
enable_jsx: Some(jsx_runtime_options),
enable_emotion,
Expand All @@ -383,10 +434,16 @@ pub async fn get_server_module_options_context(
enable_typescript_transform: Some(tsconfig),
enable_mdx_rs: mdx_rs_options,
decorators: Some(decorators_options),
rules: vec![(
foreign_code_context_condition,
module_options_context.clone().cell(),
)],
rules: vec![
(
foreign_code_context_condition,
module_options_context.clone().cell(),
),
(
ContextCondition::InPath(next_js_fs().root()),
internal_module_options_context.cell(),
),
],
custom_rules,
..module_options_context
}
Expand Down

0 comments on commit 14860d1

Please sign in to comment.