Unverified Commit cad6d3aa authored by OJ Kwon's avatar OJ Kwon Committed by GitHub

refactor(next-core): deprecate custom_ecmascript_transforms (#49629)

<!-- Thanks for opening a PR! Your contribution is much appreciated.
To make sure your PR is handled as smoothly as possible we request that
you follow the checklist sections below.
Choose the right checklist for the change(s) that you're making:

## For Contributors

### Improving Documentation or adding/fixing Examples

- The "examples guidelines" are followed from our contributing doc
https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md
- Make sure the linting passes by running `pnpm build && pnpm lint`. See
https://github.com/vercel/next.js/blob/canary/contributing/repository/linting.md

### Fixing a bug

- Related issues linked using `fixes #number`
- Tests added. See:
https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md

### Adding a feature

- Implements an existing feature request or RFC. Make sure the feature
request has been accepted for implementation before opening a PR. (A
discussion must be opened, see
https://github.com/vercel/next.js/discussions/new?category=ideas)
- Related issues/discussions are linked using `fixes #number`
- e2e tests added
(https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs
- Documentation added
- Telemetry added. In case of a feature if it's used or not.
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md



## For Maintainers

- Minimal description (aim for explaining to someone not on the team to
understand the PR)
- When linking to a Slack thread, you might want to share details of the
conclusion
- Link both the Linear (Fixes NEXT-xxx) and the GitHub issues
- Add review comments if necessary to explain to the reviewer the logic
behind a change



### Why?

### How?

Closes NEXT-
Fixes #

-->



### What?

WEB-1031.

Deprecate old custom_ecmascript_transforms, consolidate to use
ecmatransforms_plugin instead.
Requires https://github.com/vercel/turbo/pull/4886 .

---------
Co-authored-by: 's avatarAlex Kirszenberg <alex.kirszenberg@vercel.com>
Co-authored-by: 's avatarLeah <github.leah@hrmny.sh>
parent 16150a3e
This diff is collapsed.
......@@ -42,11 +42,11 @@ swc_core = { version = "0.75.41" }
testing = { version = "0.33.4" }
# Turbo crates
turbo-binding = { package = "turbopack-binding", git = "https://github.com/vercel/turbo.git", tag = "turbopack-230511.2" }
turbo-binding = { package = "turbopack-binding", git = "https://github.com/vercel/turbo.git", tag = "turbopack-230511.3" }
# [TODO]: need to refactor embed_directory! macro usages, as well as resolving turbo_tasks::function, macros..
turbo-tasks = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-230511.2" }
turbo-tasks = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-230511.3" }
# [TODO]: need to refactor embed_directory! macro usage in next-core
turbo-tasks-fs = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-230511.2" }
turbo-tasks-fs = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-230511.3" }
# General Deps
......
......@@ -19,7 +19,8 @@ use turbo_binding::{
free_var_references,
},
dev::{react_refresh::assert_can_resolve_react_refresh, DevChunkingContextVc},
ecmascript::EcmascriptInputTransform,
ecmascript::TransformPluginVc,
ecmascript_plugin::transform::directives::server::ServerDirectiveTransformer,
env::ProcessEnvAssetVc,
node::execution_context::ExecutionContextVc,
turbopack::{
......@@ -196,10 +197,19 @@ pub async fn get_client_module_options_context(
let enable_emotion = *get_emotion_compiler_config(next_config).await?;
let mut source_transforms = vec![];
if let Some(relay_transform_plugin) = *get_relay_transform_plugin(next_config).await? {
source_transforms.push(relay_transform_plugin);
}
let source_transforms = vec![
*get_relay_transform_plugin(next_config).await?,
Some(TransformPluginVc::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.
&StringVc::cell("TODO".to_string()),
),
))),
]
.into_iter()
.flatten()
.collect();
let custom_ecma_transform_plugins = Some(CustomEcmascriptTransformPluginsVc::cell(
CustomEcmascriptTransformPlugins {
......@@ -209,11 +219,6 @@ pub async fn get_client_module_options_context(
));
let module_options_context = ModuleOptionsContext {
custom_ecmascript_transforms: vec![EcmascriptInputTransform::ServerDirective(
// 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.
StringVc::cell("TODO".to_string()),
)],
preset_env_versions: Some(env),
execution_context: Some(execution_context),
custom_ecma_transform_plugins,
......
......@@ -23,16 +23,16 @@ use turbo_binding::{
ecmascript::{
EcmascriptInputTransformsVc, EcmascriptModuleAssetType, EcmascriptModuleAssetVc,
},
ecmascript_plugin::transform::emotion::EmotionTransformConfig,
ecmascript_plugin::transform::{
emotion::EmotionTransformConfig, relay::RelayConfig,
styled_components::StyledComponentsTransformConfig,
},
node::{
evaluate::evaluate,
execution_context::{ExecutionContext, ExecutionContextVc},
transforms::webpack::{WebpackLoaderConfigItems, WebpackLoaderConfigItemsVc},
},
turbopack::{
evaluate_context::node_evaluate_asset_context,
module_options::StyledComponentsTransformConfig,
},
turbopack::evaluate_context::node_evaluate_asset_context,
},
};
use turbo_tasks::{
......@@ -454,22 +454,6 @@ pub enum ReactRemoveProperties {
Config { properties: Option<Vec<String>> },
}
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, TraceRawVcs)]
#[serde(rename_all = "camelCase")]
pub struct RelayConfig {
pub src: String,
pub artifact_directory: Option<String>,
pub language: Option<RelayLanguage>,
}
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, TraceRawVcs)]
#[serde(rename_all = "lowercase")]
pub enum RelayLanguage {
TypeScript,
Flow,
JavaScript,
}
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, TraceRawVcs)]
#[serde(untagged)]
pub enum RemoveConsoleConfig {
......
......@@ -14,7 +14,10 @@ use turbo_binding::{
},
free_var_references,
},
ecmascript::EcmascriptInputTransform,
ecmascript::TransformPluginVc,
ecmascript_plugin::transform::directives::{
client::ClientDirectiveTransformer, server::ServerDirectiveTransformer,
},
node::execution_context::ExecutionContextVc,
turbopack::{
condition::ContextCondition,
......@@ -277,6 +280,17 @@ pub async fn get_server_module_options_context(
.clone_if()
};
let client_directive_transform_plugin = Some(TransformPluginVc::cell(Box::new(
ClientDirectiveTransformer::new(&StringVc::cell("server-to-client".to_string())),
)));
let server_directive_transform_plugin = Some(TransformPluginVc::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.
&StringVc::cell("TODO".to_string()),
),
)));
let tsconfig = get_typescript_transform_options(project_path);
let decorators_options = get_decorators_transform_options(project_path);
let mdx_rs_options = *next_config.mdx_rs().await?;
......@@ -288,11 +302,12 @@ pub async fn get_server_module_options_context(
if let Some(relay_transform_plugin) = *get_relay_transform_plugin(next_config).await? {
source_transforms.push(relay_transform_plugin);
}
let output_transforms = vec![];
let custom_ecma_transform_plugins = Some(CustomEcmascriptTransformPluginsVc::cell(
CustomEcmascriptTransformPlugins {
source_transforms,
output_transforms: vec![],
source_transforms: source_transforms.clone(),
output_transforms: output_transforms.clone(),
},
));
......@@ -335,12 +350,30 @@ pub async fn get_server_module_options_context(
}
}
ServerContextType::AppSSR { .. } => {
let mut base_source_transforms: Vec<TransformPluginVc> =
vec![server_directive_transform_plugin]
.into_iter()
.flatten()
.collect();
let base_ecma_transform_plugins = Some(CustomEcmascriptTransformPluginsVc::cell(
CustomEcmascriptTransformPlugins {
source_transforms: base_source_transforms.clone(),
output_transforms: vec![],
},
));
base_source_transforms.extend(source_transforms.clone());
let custom_ecma_transform_plugins = Some(CustomEcmascriptTransformPluginsVc::cell(
CustomEcmascriptTransformPlugins {
source_transforms: base_source_transforms,
output_transforms,
},
));
let module_options_context = ModuleOptionsContext {
custom_ecmascript_transforms: vec![EcmascriptInputTransform::ServerDirective(
// 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.
StringVc::cell("TODO".to_string()),
)],
custom_ecma_transform_plugins: base_ecma_transform_plugins,
execution_context: Some(execution_context),
..Default::default()
};
......@@ -375,18 +408,32 @@ pub async fn get_server_module_options_context(
}
}
ServerContextType::AppRSC { .. } => {
let mut base_source_transforms: Vec<TransformPluginVc> = vec![
client_directive_transform_plugin,
server_directive_transform_plugin,
]
.into_iter()
.flatten()
.collect();
let base_ecma_transform_plugins = Some(CustomEcmascriptTransformPluginsVc::cell(
CustomEcmascriptTransformPlugins {
source_transforms: base_source_transforms.clone(),
output_transforms: vec![],
},
));
base_source_transforms.extend(source_transforms.clone());
let custom_ecma_transform_plugins = Some(CustomEcmascriptTransformPluginsVc::cell(
CustomEcmascriptTransformPlugins {
source_transforms: base_source_transforms,
output_transforms,
},
));
let module_options_context = ModuleOptionsContext {
custom_ecmascript_transforms: vec![
EcmascriptInputTransform::ClientDirective(StringVc::cell(
"server-to-client".to_string(),
)),
EcmascriptInputTransform::ServerDirective(
// 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.
StringVc::cell("TODO".to_string()),
),
],
custom_ecma_transform_plugins: base_ecma_transform_plugins,
execution_context: Some(execution_context),
..Default::default()
};
......
use std::path::PathBuf;
use anyhow::Result;
use turbo_binding::{
swc::custom_transform::relay::{Config, RelayLanguageConfig},
turbopack::{
ecmascript::{OptionTransformPluginVc, TransformPluginVc},
ecmascript_plugin::transform::relay::RelayTransformer,
},
use turbo_binding::turbopack::{
ecmascript::{OptionTransformPluginVc, TransformPluginVc},
ecmascript_plugin::transform::relay::RelayTransformer,
};
use crate::next_config::{NextConfigVc, RelayLanguage};
use crate::next_config::NextConfigVc;
/// Returns a transform plugin for the relay graphql transform.
#[turbo_tasks::function]
......@@ -25,26 +20,13 @@ pub async fn get_relay_transform_plugin(
.relay
.as_ref()
.map(|config| {
// [TODO]: There are config mismatches between RelayConfig to swc_relay::Config
let swc_relay_config = Config {
artifact_directory: config.artifact_directory.as_ref().map(PathBuf::from),
language: config.language.as_ref().map_or(
RelayLanguageConfig::TypeScript,
|v| match v {
RelayLanguage::JavaScript => RelayLanguageConfig::JavaScript,
RelayLanguage::TypeScript => RelayLanguageConfig::TypeScript,
RelayLanguage::Flow => RelayLanguageConfig::Flow,
},
),
..Default::default()
};
OptionTransformPluginVc::cell(Some(TransformPluginVc::cell(Box::new(
RelayTransformer::new(swc_relay_config),
RelayTransformer::new(config),
))))
})
.unwrap_or(Default::default())
.unwrap_or_default()
})
.unwrap_or(Default::default());
.unwrap_or_default();
Ok(transform_plugin)
}
......@@ -8,14 +8,17 @@ use turbo_binding::{
source_asset::SourceAssetVc,
},
ecmascript::typescript::resolve::{read_from_tsconfigs, read_tsconfigs, tsconfig},
ecmascript_plugin::transform::emotion::{
EmotionTransformConfig, EmotionTransformConfigVc, OptionEmotionTransformConfigVc,
ecmascript_plugin::transform::{
emotion::{
EmotionTransformConfig, EmotionTransformConfigVc, OptionEmotionTransformConfigVc,
},
styled_components::{
OptionStyledComponentsTransformConfigVc, StyledComponentsTransformConfig,
},
},
turbopack::module_options::{
DecoratorsKind, DecoratorsOptions, DecoratorsOptionsVc, JsxTransformOptions,
JsxTransformOptionsVc, OptionStyledComponentsTransformConfigVc,
StyledComponentsTransformConfig, TypescriptTransformOptions,
TypescriptTransformOptionsVc,
JsxTransformOptionsVc, TypescriptTransformOptions, TypescriptTransformOptionsVc,
},
},
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment