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

fix(next_core): do not apply user config to internal assets #48210

Merged
merged 5 commits into from
May 2, 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
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 the module is an internal asset (i.e overlay, fallback) coming from the embedded
// FS, don't apply user defined transforms.
(
ContextCondition::InPath(next_js_fs().root()),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are more paths that are affected. turbopack-dev has an filesystem too

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should next-core need to aware & control turbopack-dev? wouldn't it more proper turbopack's core internally manages those the consumer shouldn't able to adjust those?

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
101 changes: 79 additions & 22 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,
JsxTransformOptions, ModuleOptionsContext, ModuleOptionsContextVc,
PostCssTransformOptions, 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