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 13, 2023
1 parent 1d30045 commit 2fa8b23
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 @@ -204,10 +207,22 @@ pub async fn get_client_module_options_context(
enable_webpack_loaders,
enable_typescript_transform: Some(tsconfig),
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 @@ -244,6 +247,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 @@ -253,10 +262,16 @@ pub async fn get_server_module_options_context(
enable_webpack_loaders,
enable_typescript_transform: Some(tsconfig),
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 @@ -271,6 +286,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 @@ -280,10 +300,16 @@ pub async fn get_server_module_options_context(
enable_webpack_loaders,
enable_typescript_transform: Some(tsconfig),
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 @@ -304,6 +330,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 @@ -312,10 +342,16 @@ pub async fn get_server_module_options_context(
enable_webpack_loaders,
enable_typescript_transform: Some(tsconfig),
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 @@ -325,15 +361,25 @@ 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),
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 @@ -343,6 +389,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 @@ -352,10 +402,16 @@ pub async fn get_server_module_options_context(
enable_webpack_loaders,
enable_typescript_transform: Some(tsconfig),
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 2fa8b23

Please sign in to comment.