From 9c6b60a53428aa506e65b2477dbfa619e712db80 Mon Sep 17 00:00:00 2001 From: Justin Ridgewell Date: Mon, 23 Oct 2023 13:12:51 -0400 Subject: [PATCH] Revert "Remove ServerDirectiveTransformer (#56496)" This reverts commit bfdb349ebadced0346aa5b9c017851a166c493f6. --- .../next-core/src/next_client/context.rs | 6 +++++ .../next-core/src/next_server/context.rs | 23 ++++++++++++++----- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/packages/next-swc/crates/next-core/src/next_client/context.rs b/packages/next-swc/crates/next-core/src/next_client/context.rs index 8e0c3563dd361..d62499a3dabf1 100644 --- a/packages/next-swc/crates/next-core/src/next_client/context.rs +++ b/packages/next-swc/crates/next-core/src/next_client/context.rs @@ -18,6 +18,7 @@ use turbopack_binding::{ }, dev::{react_refresh::assert_can_resolve_react_refresh, DevChunkingContext}, ecmascript::chunk::EcmascriptChunkingContext, + ecmascript_plugin::transform::directives::server::ServerDirectiveTransformer, node::execution_context::ExecutionContext, turbopack::{ condition::ContextCondition, @@ -243,6 +244,11 @@ pub async fn get_client_module_options_context( *get_emotion_transform_plugin(next_config).await?, *get_styled_components_transform_plugin(next_config).await?, *get_styled_jsx_transform_plugin().await?, + Some(Vc::cell(Box::new(ServerDirectiveTransformer::new( + // ServerDirective is not implemented yet and always reports an issue. + // We don't have to pass a valid transition name yet, but the API is prepared. + &Vc::cell("TODO".to_string()), + )) as _)), ] .into_iter() .flatten() diff --git a/packages/next-swc/crates/next-core/src/next_server/context.rs b/packages/next-swc/crates/next-core/src/next_server/context.rs index d42d7c5c0856a..53fdcfdc12dfd 100644 --- a/packages/next-swc/crates/next-core/src/next_server/context.rs +++ b/packages/next-swc/crates/next-core/src/next_server/context.rs @@ -18,7 +18,9 @@ use turbopack_binding::{ resolve::{parse::Request, pattern::Pattern}, }, ecmascript::TransformPlugin, - ecmascript_plugin::transform::directives::client::ClientDirectiveTransformer, + ecmascript_plugin::transform::directives::{ + client::ClientDirectiveTransformer, server::ServerDirectiveTransformer, + }, node::execution_context::ExecutionContext, turbopack::{ condition::ContextCondition, @@ -289,6 +291,12 @@ pub async fn get_server_module_options_context( let styled_components_transform_plugin = *get_styled_components_transform_plugin(next_config).await?; let styled_jsx_transform_plugin = *get_styled_jsx_transform_plugin().await?; + let server_directive_transform_plugin = + Some(Vc::cell(Box::new(ServerDirectiveTransformer::new( + // ServerDirective is not implemented yet and always reports an issue. + // We don't have to pass a valid transition name yet, but the API is prepared. + &Vc::cell("TODO".to_string()), + )) as _)); // ModuleOptionsContext related options let tsconfig = get_typescript_transform_options(project_path); @@ -387,6 +395,7 @@ pub async fn get_server_module_options_context( let mut base_source_transforms: Vec> = vec![ styled_components_transform_plugin, styled_jsx_transform_plugin, + server_directive_transform_plugin, ] .into_iter() .flatten() @@ -460,11 +469,13 @@ pub async fn get_server_module_options_context( ecmascript_client_reference_transition_name, .. } => { - let mut base_source_transforms: Vec> = - vec![styled_components_transform_plugin] - .into_iter() - .flatten() - .collect(); + let mut base_source_transforms: Vec> = vec![ + styled_components_transform_plugin, + server_directive_transform_plugin, + ] + .into_iter() + .flatten() + .collect(); if let Some(ecmascript_client_reference_transition_name) = ecmascript_client_reference_transition_name