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 Apr 19, 2023
1 parent 9f5463d commit e4230f4
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 26 deletions.
25 changes: 20 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,10 @@ use turbo_binding::{
env::ProcessEnvAssetVc,
node::execution_context::ExecutionContextVc,
turbopack::{
condition::ContextCondition,
module_options::{
module_options_context::{ModuleOptionsContext, ModuleOptionsContextVc},
PostCssTransformOptions, WebpackLoadersOptions,
PostCssTransformOptions, TypescriptTransformOptions, WebpackLoadersOptions,
},
resolve_options_context::{ResolveOptionsContext, ResolveOptionsContextVc},
transition::TransitionsByNameVc,
Expand All @@ -34,10 +35,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 @@ -205,10 +208,22 @@ 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()),
..module_options_context.clone()
})
.cell(),
),
],
custom_rules,
..module_options_context
}
Expand Down
98 changes: 77 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 @@ -13,21 +13,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 @@ -245,6 +248,12 @@ 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 @@ -255,10 +264,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 @@ -273,6 +288,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 @@ -283,10 +303,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 @@ -307,6 +333,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 @@ -316,10 +346,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 @@ -329,16 +365,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 @@ -348,6 +394,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 @@ -358,10 +408,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 e4230f4

Please sign in to comment.