Skip to content

Commit

Permalink
refactor(turbopack): Use ResolvedVc for turbopack-ecmascript (ver…
Browse files Browse the repository at this point in the history
…cel#72564)

### What?

Use `ResolvedVc` for struct fields in `turbopack-ecmascript` crate

### Why?

Follow-up of vercel#72200,
vercel#72382,
vercel#72320

### How?

Closes PACK-3438

---------

Co-authored-by: Benjamin Woodruff <benjamin.woodruff@vercel.com>
  • Loading branch information
kdy1 and bgw authored Nov 16, 2024
1 parent 16bee25 commit bcabce7
Show file tree
Hide file tree
Showing 73 changed files with 757 additions and 705 deletions.
7 changes: 4 additions & 3 deletions crates/next-core/src/next_shared/transforms/debug_fn_name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@ use anyhow::Result;
use async_trait::async_trait;
use next_custom_transforms::transforms::debug_fn_name::debug_fn_name;
use swc_core::ecma::{ast::Program, visit::VisitMutWith};
use turbo_tasks::{ResolvedVc, Vc};
use turbo_tasks::ResolvedVc;
use turbopack::module_options::{ModuleRule, ModuleRuleEffect};
use turbopack_ecmascript::{CustomTransformer, EcmascriptInputTransform, TransformContext};

use super::module_rule_match_js_no_url;

pub fn get_debug_fn_name_rule(enable_mdx_rs: bool) -> ModuleRule {
let debug_fn_name_transform =
EcmascriptInputTransform::Plugin(Vc::cell(Box::new(DebugFnNameTransformer {}) as _));
let debug_fn_name_transform = EcmascriptInputTransform::Plugin(ResolvedVc::cell(Box::new(
DebugFnNameTransformer {},
) as _));

ModuleRule::new(
module_rule_match_js_no_url(enable_mdx_rs),
Expand Down
4 changes: 2 additions & 2 deletions crates/next-core/src/next_shared/transforms/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub use next_font::get_next_font_transform_rule;
pub use next_lint::get_next_lint_transform_rule;
pub use next_strip_page_exports::get_next_pages_transforms_rule;
pub use server_actions::get_server_actions_transform_rule;
use turbo_tasks::{ReadRef, ResolvedVc, Value, Vc};
use turbo_tasks::{ReadRef, ResolvedVc, Value};
use turbo_tasks_fs::FileSystemPath;
use turbopack::module_options::{ModuleRule, ModuleRuleEffect, ModuleType, RuleCondition};
use turbopack_core::reference_type::{ReferenceType, UrlReferenceSubType};
Expand Down Expand Up @@ -136,7 +136,7 @@ pub(crate) fn get_ecma_transform_rule(
enable_mdx_rs: bool,
prepend: bool,
) -> ModuleRule {
let transformer = EcmascriptInputTransform::Plugin(Vc::cell(transformer as _));
let transformer = EcmascriptInputTransform::Plugin(ResolvedVc::cell(transformer as _));
let (prepend, append) = if prepend {
(
ResolvedVc::cell(vec![transformer]),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use async_trait::async_trait;
use modularize_imports::{modularize_imports, PackageConfig};
use serde::{Deserialize, Serialize};
use swc_core::ecma::ast::Program;
use turbo_tasks::{trace::TraceRawVcs, FxIndexMap, ResolvedVc, Vc};
use turbo_tasks::{trace::TraceRawVcs, FxIndexMap, ResolvedVc};
use turbopack::module_options::{ModuleRule, ModuleRuleEffect};
use turbopack_ecmascript::{CustomTransformer, EcmascriptInputTransform, TransformContext};

Expand Down Expand Up @@ -35,7 +35,7 @@ pub fn get_next_modularize_imports_rule(
modularize_imports_config: &FxIndexMap<String, ModularizeImportPackageConfig>,
enable_mdx_rs: bool,
) -> ModuleRule {
let transformer = EcmascriptInputTransform::Plugin(Vc::cell(Box::new(
let transformer = EcmascriptInputTransform::Plugin(ResolvedVc::cell(Box::new(
ModularizeImportsTransformer::new(modularize_imports_config),
) as _));
ModuleRule::new(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ use anyhow::Result;
use async_trait::async_trait;
use next_custom_transforms::transforms::amp_attributes::amp_attributes;
use swc_core::ecma::ast::*;
use turbo_tasks::{ResolvedVc, Vc};
use turbo_tasks::ResolvedVc;
use turbopack::module_options::{ModuleRule, ModuleRuleEffect};
use turbopack_ecmascript::{CustomTransformer, EcmascriptInputTransform, TransformContext};

use super::module_rule_match_js_no_url;

pub fn get_next_amp_attr_rule(enable_mdx_rs: bool) -> ModuleRule {
let transformer =
EcmascriptInputTransform::Plugin(Vc::cell(Box::new(NextAmpAttributes {}) as _));
EcmascriptInputTransform::Plugin(ResolvedVc::cell(Box::new(NextAmpAttributes {}) as _));
ModuleRule::new(
module_rule_match_js_no_url(enable_mdx_rs),
vec![ModuleRuleEffect::ExtendEcmascriptTransforms {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use swc_core::{
common::SyntaxContext,
ecma::{ast::*, visit::VisitMutWith},
};
use turbo_tasks::{ResolvedVc, Vc};
use turbo_tasks::ResolvedVc;
use turbopack::module_options::{ModuleRule, ModuleRuleEffect};
use turbopack_ecmascript::{CustomTransformer, EcmascriptInputTransform, TransformContext};

Expand Down Expand Up @@ -47,8 +47,9 @@ pub fn get_next_cjs_optimizer_rule(enable_mdx_rs: bool) -> ModuleRule {
)]),
};

let transformer =
EcmascriptInputTransform::Plugin(Vc::cell(Box::new(NextCjsOptimizer { config }) as _));
let transformer = EcmascriptInputTransform::Plugin(ResolvedVc::cell(
Box::new(NextCjsOptimizer { config }) as _,
));
ModuleRule::new(
module_rule_match_js_no_url(enable_mdx_rs),
vec![ModuleRuleEffect::ExtendEcmascriptTransforms {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use anyhow::Result;
use async_trait::async_trait;
use next_custom_transforms::transforms::disallow_re_export_all_in_page::disallow_re_export_all_in_page;
use swc_core::ecma::ast::*;
use turbo_tasks::{ReadRef, ResolvedVc, Vc};
use turbo_tasks::{ReadRef, ResolvedVc};
use turbo_tasks_fs::FileSystemPath;
use turbopack::module_options::{ModuleRule, ModuleRuleEffect};
use turbopack_ecmascript::{CustomTransformer, EcmascriptInputTransform, TransformContext};
Expand All @@ -13,8 +13,9 @@ pub fn get_next_disallow_export_all_in_page_rule(
enable_mdx_rs: bool,
pages_dir: ReadRef<FileSystemPath>,
) -> ModuleRule {
let transformer =
EcmascriptInputTransform::Plugin(Vc::cell(Box::new(NextDisallowReExportAllInPage) as _));
let transformer = EcmascriptInputTransform::Plugin(ResolvedVc::cell(Box::new(
NextDisallowReExportAllInPage,
) as _));
ModuleRule::new(
module_rule_match_pages_page_file(enable_mdx_rs, pages_dir),
vec![ModuleRuleEffect::ExtendEcmascriptTransforms {
Expand Down
13 changes: 7 additions & 6 deletions crates/next-core/src/next_shared/transforms/next_dynamic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@ pub async fn get_next_dynamic_transform_rule(
mode: Vc<NextMode>,
enable_mdx_rs: bool,
) -> Result<ModuleRule> {
let dynamic_transform = EcmascriptInputTransform::Plugin(Vc::cell(Box::new(NextJsDynamic {
is_server_compiler,
is_react_server_layer,
is_app_dir,
mode: *mode.await?,
}) as _));
let dynamic_transform =
EcmascriptInputTransform::Plugin(ResolvedVc::cell(Box::new(NextJsDynamic {
is_server_compiler,
is_react_server_layer,
is_app_dir,
mode: *mode.await?,
}) as _));
Ok(ModuleRule::new(
module_rule_match_js_no_url(enable_mdx_rs),
vec![ModuleRuleEffect::ExtendEcmascriptTransforms {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use swc_core::{
common::SyntaxContext,
ecma::{ast::*, utils::ExprCtx, visit::VisitWith},
};
use turbo_tasks::{ResolvedVc, Vc};
use turbo_tasks::ResolvedVc;
use turbopack::module_options::{ModuleRule, ModuleRuleEffect};
use turbopack_ecmascript::{CustomTransformer, EcmascriptInputTransform, TransformContext};

Expand All @@ -16,10 +16,11 @@ pub fn next_edge_node_api_assert(
should_error_for_node_apis: bool,
is_production: bool,
) -> ModuleRule {
let transformer = EcmascriptInputTransform::Plugin(Vc::cell(Box::new(NextEdgeNodeApiAssert {
should_error_for_node_apis,
is_production,
}) as _));
let transformer =
EcmascriptInputTransform::Plugin(ResolvedVc::cell(Box::new(NextEdgeNodeApiAssert {
should_error_for_node_apis,
is_production,
}) as _));
ModuleRule::new(
module_rule_match_js_no_url(enable_mdx_rs),
vec![ModuleRuleEffect::ExtendEcmascriptTransforms {
Expand Down
6 changes: 4 additions & 2 deletions crates/next-core/src/next_shared/transforms/next_font.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use anyhow::Result;
use async_trait::async_trait;
use next_custom_transforms::transforms::fonts::*;
use swc_core::ecma::{ast::Program, atoms::JsWord, visit::VisitMutWith};
use turbo_tasks::{ResolvedVc, Vc};
use turbo_tasks::ResolvedVc;
use turbopack::module_options::{ModuleRule, ModuleRuleEffect};
use turbopack_ecmascript::{CustomTransformer, EcmascriptInputTransform, TransformContext};

Expand All @@ -18,7 +18,9 @@ pub fn get_next_font_transform_rule(enable_mdx_rs: bool) -> ModuleRule {
];

let transformer =
EcmascriptInputTransform::Plugin(Vc::cell(Box::new(NextJsFont { font_loaders }) as _));
EcmascriptInputTransform::Plugin(ResolvedVc::cell(
Box::new(NextJsFont { font_loaders }) as _
));
ModuleRule::new(
// TODO: Only match in pages (not pages/api), app/, etc.
module_rule_match_js_no_url(enable_mdx_rs),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@ use anyhow::Result;
use async_trait::async_trait;
use next_custom_transforms::transforms::middleware_dynamic::next_middleware_dynamic;
use swc_core::ecma::{ast::*, visit::VisitMutWith};
use turbo_tasks::{ResolvedVc, Vc};
use turbo_tasks::ResolvedVc;
use turbopack::module_options::{ModuleRule, ModuleRuleEffect};
use turbopack_ecmascript::{CustomTransformer, EcmascriptInputTransform, TransformContext};

use super::module_rule_match_js_no_url;

pub fn get_middleware_dynamic_assert_rule(enable_mdx_rs: bool) -> ModuleRule {
let transformer =
EcmascriptInputTransform::Plugin(Vc::cell(Box::new(NextMiddlewareDynamicAssert {}) as _));
let transformer = EcmascriptInputTransform::Plugin(ResolvedVc::cell(Box::new(
NextMiddlewareDynamicAssert {},
) as _));
ModuleRule::new(
module_rule_match_js_no_url(enable_mdx_rs),
vec![ModuleRuleEffect::ExtendEcmascriptTransforms {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use anyhow::Result;
use async_trait::async_trait;
use next_custom_transforms::transforms::optimize_server_react::{optimize_server_react, Config};
use swc_core::ecma::ast::*;
use turbo_tasks::{ResolvedVc, Vc};
use turbo_tasks::ResolvedVc;
use turbopack::module_options::{ModuleRule, ModuleRuleEffect};
use turbopack_ecmascript::{CustomTransformer, EcmascriptInputTransform, TransformContext};

Expand All @@ -14,7 +14,7 @@ pub fn get_next_optimize_server_react_rule(
optimize_use_state: bool,
) -> ModuleRule {
let transformer =
EcmascriptInputTransform::Plugin(Vc::cell(Box::new(NextOptimizeServerReact {
EcmascriptInputTransform::Plugin(ResolvedVc::cell(Box::new(NextOptimizeServerReact {
optimize_use_state,
}) as _));
ModuleRule::new(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use anyhow::Result;
use async_trait::async_trait;
use next_custom_transforms::transforms::page_config::page_config;
use swc_core::ecma::ast::*;
use turbo_tasks::{ReadRef, ResolvedVc, Vc};
use turbo_tasks::{ReadRef, ResolvedVc};
use turbo_tasks_fs::FileSystemPath;
use turbopack::module_options::{ModuleRule, ModuleRuleEffect};
use turbopack_ecmascript::{CustomTransformer, EcmascriptInputTransform, TransformContext};
Expand All @@ -13,7 +13,7 @@ pub fn get_next_page_config_rule(
enable_mdx_rs: bool,
pages_dir: ReadRef<FileSystemPath>,
) -> ModuleRule {
let transformer = EcmascriptInputTransform::Plugin(Vc::cell(Box::new(NextPageConfig {
let transformer = EcmascriptInputTransform::Plugin(ResolvedVc::cell(Box::new(NextPageConfig {
// [TODO]: update once turbopack build works
is_development: true,
}) as _));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@ pub fn get_next_page_static_info_assert_rule(
server_context: Option<ServerContextType>,
client_context: Option<ClientContextType>,
) -> ModuleRule {
let transformer = EcmascriptInputTransform::Plugin(Vc::cell(Box::new(NextPageStaticInfo {
server_context,
client_context,
}) as _));
let transformer =
EcmascriptInputTransform::Plugin(ResolvedVc::cell(Box::new(NextPageStaticInfo {
server_context,
client_context,
}) as _));
ModuleRule::new(
module_rule_match_js_no_url(enable_mdx_rs),
vec![ModuleRuleEffect::ExtendEcmascriptTransforms {
Expand Down Expand Up @@ -129,7 +130,7 @@ impl CustomTransformer for NextPageStaticInfo {

#[turbo_tasks::value(shared)]
pub struct PageStaticInfoIssue {
pub file_path: Vc<FileSystemPath>,
pub file_path: ResolvedVc<FileSystemPath>,
pub messages: Vec<String>,
pub severity: IssueSeverity,
}
Expand All @@ -153,7 +154,7 @@ impl Issue for PageStaticInfoIssue {

#[turbo_tasks::function]
fn file_path(&self) -> Vc<FileSystemPath> {
self.file_path
*self.file_path
}

#[turbo_tasks::function]
Expand Down
5 changes: 3 additions & 2 deletions crates/next-core/src/next_shared/transforms/next_pure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ use anyhow::Result;
use async_trait::async_trait;
use next_custom_transforms::transforms::pure::pure_magic;
use swc_core::ecma::{ast::*, visit::VisitMutWith};
use turbo_tasks::{ResolvedVc, Vc};
use turbo_tasks::ResolvedVc;
use turbopack::module_options::{ModuleRule, ModuleRuleEffect};
use turbopack_ecmascript::{CustomTransformer, EcmascriptInputTransform, TransformContext};

use super::module_rule_match_js_no_url;

pub fn get_next_pure_rule(enable_mdx_rs: bool) -> ModuleRule {
let transformer = EcmascriptInputTransform::Plugin(Vc::cell(Box::new(NextPure {}) as _));
let transformer =
EcmascriptInputTransform::Plugin(ResolvedVc::cell(Box::new(NextPure {}) as _));
ModuleRule::new(
module_rule_match_js_no_url(enable_mdx_rs),
vec![ModuleRuleEffect::ExtendEcmascriptTransforms {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@ use anyhow::Result;
use async_trait::async_trait;
use next_custom_transforms::transforms::shake_exports::{shake_exports, Config};
use swc_core::ecma::ast::*;
use turbo_tasks::{ResolvedVc, Vc};
use turbo_tasks::ResolvedVc;
use turbopack::module_options::{ModuleRule, ModuleRuleEffect};
use turbopack_ecmascript::{CustomTransformer, EcmascriptInputTransform, TransformContext};

use super::module_rule_match_js_no_url;

#[allow(dead_code)]
pub fn get_next_shake_exports_rule(enable_mdx_rs: bool, ignore: Vec<String>) -> ModuleRule {
let transformer =
EcmascriptInputTransform::Plugin(Vc::cell(Box::new(NextShakeExports { ignore }) as _));
let transformer = EcmascriptInputTransform::Plugin(ResolvedVc::cell(
Box::new(NextShakeExports { ignore }) as _,
));
ModuleRule::new(
module_rule_match_js_no_url(enable_mdx_rs),
vec![ModuleRuleEffect::ExtendEcmascriptTransforms {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ pub async fn get_next_pages_transforms_rule(
enable_mdx_rs: bool,
) -> Result<ModuleRule> {
// Apply the Next SSG transform to all pages.
let strip_transform = EcmascriptInputTransform::Plugin(Vc::cell(Box::new(
NextJsStripPageExports { export_filter },
) as _));
let strip_transform =
EcmascriptInputTransform::Plugin(ResolvedVc::cell(Box::new(NextJsStripPageExports {
export_filter,
}) as _));
Ok(ModuleRule::new(
RuleCondition::all(vec![
RuleCondition::all(vec![
Expand Down
11 changes: 6 additions & 5 deletions crates/next-core/src/next_shared/transforms/server_actions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use anyhow::Result;
use async_trait::async_trait;
use next_custom_transforms::transforms::server_actions::{server_actions, Config};
use swc_core::{common::FileName, ecma::ast::Program};
use turbo_tasks::{ResolvedVc, Vc};
use turbo_tasks::ResolvedVc;
use turbopack::module_options::{ModuleRule, ModuleRuleEffect};
use turbopack_ecmascript::{CustomTransformer, EcmascriptInputTransform, TransformContext};

Expand All @@ -20,10 +20,11 @@ pub fn get_server_actions_transform_rule(
enable_mdx_rs: bool,
dynamic_io_enabled: bool,
) -> ModuleRule {
let transformer = EcmascriptInputTransform::Plugin(Vc::cell(Box::new(NextServerActions {
transform,
dynamic_io_enabled,
}) as _));
let transformer =
EcmascriptInputTransform::Plugin(ResolvedVc::cell(Box::new(NextServerActions {
transform,
dynamic_io_enabled,
}) as _));
ModuleRule::new(
module_rule_match_js_no_url(enable_mdx_rs),
vec![ModuleRuleEffect::ExtendEcmascriptTransforms {
Expand Down
10 changes: 5 additions & 5 deletions turbopack/crates/turbopack-cli/src/contexts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,16 +145,16 @@ async fn get_client_module_options_context(
conditions,
vec![ModuleRuleEffect::ExtendEcmascriptTransforms {
prepend: ResolvedVc::cell(vec![
EcmascriptInputTransform::Plugin(Vc::cell(Box::new(
EcmascriptInputTransform::Plugin(ResolvedVc::cell(Box::new(
EmotionTransformer::new(&EmotionTransformConfig::default())
.expect("Should be able to create emotion transformer"),
) as _)),
EcmascriptInputTransform::Plugin(Vc::cell(Box::new(
EcmascriptInputTransform::Plugin(ResolvedVc::cell(Box::new(
StyledComponentsTransformer::new(&StyledComponentsTransformConfig::default()),
) as _)),
EcmascriptInputTransform::Plugin(Vc::cell(Box::new(StyledJsxTransformer::new(
versions,
)) as _)),
EcmascriptInputTransform::Plugin(ResolvedVc::cell(Box::new(
StyledJsxTransformer::new(versions),
) as _)),
]),
append: ResolvedVc::cell(vec![]),
}],
Expand Down
4 changes: 2 additions & 2 deletions turbopack/crates/turbopack-core/src/introspect/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ pub async fn children_from_module_references(
let key = reference_ty();
let mut children = FxIndexSet::default();
let references = references.await?;
for reference in &*references {
for &reference in &*references {
let mut key = key;
if let Some(chunkable) =
Vc::try_resolve_downcast::<Box<dyn ChunkableModuleReference>>(*reference).await?
Vc::try_resolve_downcast::<Box<dyn ChunkableModuleReference>>(reference).await?
{
match &*chunkable.chunking_type().await? {
None => {}
Expand Down
Loading

0 comments on commit bcabce7

Please sign in to comment.