From a1b2c1318eca55fcc509372a7cf57eebd8cf3d51 Mon Sep 17 00:00:00 2001 From: Tobias Koppers Date: Thu, 25 May 2023 13:48:22 +0000 Subject: [PATCH] replace EcmascriptModuleAssetVc::new with ReferenceType::Internal --- .../crates/next-core/src/app_source.rs | 8 ++-- .../crates/next-core/src/asset_helpers.rs | 27 ------------- .../crates/next-core/src/bootstrap.rs | 9 ++--- packages/next-swc/crates/next-core/src/lib.rs | 1 - .../crates/next-core/src/next_config.rs | 15 ++----- .../next-core/src/next_font/google/mod.rs | 39 ++++++++++--------- .../crates/next-core/src/page_loader.rs | 7 ++-- .../next-swc/crates/next-core/src/router.rs | 30 +++++++------- 8 files changed, 47 insertions(+), 89 deletions(-) delete mode 100644 packages/next-swc/crates/next-core/src/asset_helpers.rs diff --git a/packages/next-swc/crates/next-core/src/app_source.rs b/packages/next-swc/crates/next-core/src/app_source.rs index 0ef4b3f4a9422..ce0ca5ccc18ae 100644 --- a/packages/next-swc/crates/next-core/src/app_source.rs +++ b/packages/next-swc/crates/next-core/src/app_source.rs @@ -64,7 +64,6 @@ use crate::{ get_entrypoints, get_global_metadata, Components, Entrypoint, GlobalMetadataVc, LoaderTree, LoaderTreeVc, Metadata, MetadataItem, MetadataWithAltItem, OptionAppDirVc, }, - asset_helpers::as_es_module_asset, bootstrap::{route_bootstrap, BootstrapConfigVc}, embed_js::{next_asset, next_js_file, next_js_file_path}, env::env_for_js, @@ -890,12 +889,11 @@ import {}, {{ chunks as {} }} from "COMPONENT_{}"; .push(format!("import {identifier} from \"{inner_module_id}\";")); state.inner_assets.insert( inner_module_id, - as_es_module_asset( + state.context.process( TextContentSourceAssetVc::new(SourceAssetVc::new(*alt_path).into()) .into(), - state.context, - ) - .into(), + Value::new(ReferenceType::Internal(InnerAssetsVc::empty())), + ), ); writeln!(state.loader_tree_code, "{s} alt: {identifier},")?; } diff --git a/packages/next-swc/crates/next-core/src/asset_helpers.rs b/packages/next-swc/crates/next-core/src/asset_helpers.rs deleted file mode 100644 index d6d37bb3c60c5..0000000000000 --- a/packages/next-swc/crates/next-core/src/asset_helpers.rs +++ /dev/null @@ -1,27 +0,0 @@ -use turbo_tasks::Value; -use turbopack_binding::turbopack::{ - core::{ - asset::AssetVc, - context::{AssetContext, AssetContextVc}, - }, - ecmascript::{ - EcmascriptInputTransform, EcmascriptInputTransformsVc, EcmascriptModuleAssetType, - EcmascriptModuleAssetVc, - }, -}; - -pub(crate) fn as_es_module_asset( - asset: AssetVc, - context: AssetContextVc, -) -> EcmascriptModuleAssetVc { - EcmascriptModuleAssetVc::new( - asset, - context, - Value::new(EcmascriptModuleAssetType::Typescript), - EcmascriptInputTransformsVc::cell(vec![EcmascriptInputTransform::TypeScript { - use_define_for_class_fields: false, - }]), - Default::default(), - context.compile_time_info(), - ) -} diff --git a/packages/next-swc/crates/next-core/src/bootstrap.rs b/packages/next-swc/crates/next-core/src/bootstrap.rs index 3868dd8a4b5c8..2143c9c35c5be 100644 --- a/packages/next-swc/crates/next-core/src/bootstrap.rs +++ b/packages/next-swc/crates/next-core/src/bootstrap.rs @@ -15,8 +15,6 @@ use turbopack_binding::turbopack::{ ecmascript::{resolve::esm_resolve, utils::StringifyJs, EcmascriptModuleAssetVc}, }; -use crate::asset_helpers::as_es_module_asset; - #[turbo_tasks::function] pub async fn route_bootstrap( asset: AssetVc, @@ -102,7 +100,7 @@ pub async fn bootstrap( config.insert("PAGE".to_string(), path.to_string()); config.insert("PATHNAME".to_string(), pathname); - let config_asset = as_es_module_asset( + let config_asset = context.process( VirtualAssetVc::new( asset.ident().path().join("bootstrap-config.ts"), File::from( @@ -115,9 +113,8 @@ pub async fn bootstrap( .into(), ) .as_asset(), - context, - ) - .as_asset(); + Value::new(ReferenceType::Internal(InnerAssetsVc::empty())), + ); let mut inner_assets = inner_assets.await?.clone_value(); inner_assets.insert("ENTRY".to_string(), asset); diff --git a/packages/next-swc/crates/next-core/src/lib.rs b/packages/next-swc/crates/next-core/src/lib.rs index 4b6ed291f529c..41cdb7e6460c8 100644 --- a/packages/next-swc/crates/next-core/src/lib.rs +++ b/packages/next-swc/crates/next-core/src/lib.rs @@ -6,7 +6,6 @@ mod app_render; mod app_segment_config; mod app_source; pub mod app_structure; -mod asset_helpers; mod babel; mod bootstrap; mod embed_js; diff --git a/packages/next-swc/crates/next-core/src/next_config.rs b/packages/next-swc/crates/next-core/src/next_config.rs index 6e23aefb6f32c..497cd6eec872e 100644 --- a/packages/next-swc/crates/next-core/src/next_config.rs +++ b/packages/next-swc/crates/next-core/src/next_config.rs @@ -18,7 +18,7 @@ use turbopack_binding::{ context::AssetContext, ident::AssetIdentVc, issue::{Issue, IssueContextExt, IssueSeverity, IssueSeverityVc, IssueVc}, - reference_type::{EntryReferenceSubType, ReferenceType}, + reference_type::{EntryReferenceSubType, InnerAssetsVc, ReferenceType}, resolve::{ find_context_file, options::{ImportMap, ImportMapping}, @@ -26,9 +26,6 @@ use turbopack_binding::{ }, source_asset::SourceAssetVc, }, - ecmascript::{ - EcmascriptInputTransformsVc, EcmascriptModuleAssetType, EcmascriptModuleAssetVc, - }, ecmascript_plugin::transform::{ emotion::EmotionTransformConfig, relay::RelayConfig, styled_components::StyledComponentsTransformConfig, @@ -670,15 +667,11 @@ pub async fn load_next_config_internal( let config_changed = config_asset.map_or_else(CompletionVc::immutable, |config_asset| { // This invalidates the execution when anything referenced by the config file // changes - let config_asset = EcmascriptModuleAssetVc::new( + let config_asset = context.process( config_asset.into(), - context, - Value::new(EcmascriptModuleAssetType::Ecmascript), - EcmascriptInputTransformsVc::cell(vec![]), - Default::default(), - context.compile_time_info(), + Value::new(ReferenceType::Internal(InnerAssetsVc::empty())), ); - any_content_changed(config_asset.into()) + any_content_changed(config_asset) }); let load_next_config_asset = context.process( next_asset("entry/config/next.js"), diff --git a/packages/next-swc/crates/next-core/src/next_font/google/mod.rs b/packages/next-swc/crates/next-core/src/next_font/google/mod.rs index 7cd9722160fff..356339dcae2e3 100644 --- a/packages/next-swc/crates/next-core/src/next_font/google/mod.rs +++ b/packages/next-swc/crates/next-core/src/next_font/google/mod.rs @@ -406,7 +406,11 @@ async fn get_mock_stylesheet( tasks_fs::{DiskFileSystemVc, File, FileSystem}, }, turbopack::{ - core::{context::AssetContext, ident::AssetIdentVc}, + core::{ + context::AssetContext, + ident::AssetIdentVc, + reference_type::{InnerAssetsVc, ReferenceType}, + }, ecmascript::{ EcmascriptInputTransformsVc, EcmascriptModuleAssetType, EcmascriptModuleAssetVc, }, @@ -440,26 +444,23 @@ async fn get_mock_stylesheet( } = *execution_context.await?; let context = node_evaluate_asset_context(execution_context, None, None); let loader_path = mock_fs.root().join("loader.js"); - let mocked_response_asset = EcmascriptModuleAssetVc::new( - VirtualAssetVc::new( - loader_path, - File::from(format!( - "import data from './{}'; export default function load() {{ return data; }};", - response_path - .file_name() - .context("Must exist")? - .to_string_lossy(), - )) + let mocked_response_asset = context + .process( + VirtualAssetVc::new( + loader_path, + File::from(format!( + "import data from './{}'; export default function load() {{ return data; }};", + response_path + .file_name() + .context("Must exist")? + .to_string_lossy(), + )) + .into(), + ) .into(), + Value::new(ReferenceType::Internal(InnerAssetsVc::empty())), ) - .into(), - context, - Value::new(EcmascriptModuleAssetType::Ecmascript), - EcmascriptInputTransformsVc::cell(vec![]), - Default::default(), - context.compile_time_info(), - ) - .into(); + .into(); let root = mock_fs.root(); let val = evaluate( diff --git a/packages/next-swc/crates/next-core/src/page_loader.rs b/packages/next-swc/crates/next-core/src/page_loader.rs index 9e4b5cf5647d4..cefe05b874991 100644 --- a/packages/next-swc/crates/next-core/src/page_loader.rs +++ b/packages/next-swc/crates/next-core/src/page_loader.rs @@ -90,9 +90,10 @@ impl PageLoaderAssetVc { let module = this.client_context.process( loader_entry_asset, Value::new(ReferenceType::Internal( - InnerAssetsVc::cell(indexmap! { - "PAGE".to_string() => this.client_context.process(this.entry_asset, Value::new(ReferenceType::Entry(EntryReferenceSubType::Page))) - }))), + InnerAssetsVc::cell(indexmap! { + "PAGE".to_string() => this.client_context.process(this.entry_asset, Value::new(ReferenceType::Entry(EntryReferenceSubType::Page))) + }) + )), ); let Some(module) = EvaluatableAssetVc::resolve_from(module).await? else { diff --git a/packages/next-swc/crates/next-core/src/router.rs b/packages/next-swc/crates/next-core/src/router.rs index fd3ea74c0e9ed..8e73b5f8d493e 100644 --- a/packages/next-swc/crates/next-core/src/router.rs +++ b/packages/next-swc/crates/next-core/src/router.rs @@ -16,7 +16,7 @@ use turbopack_binding::{ }, turbopack::{ core::{ - asset::AssetVc, + asset::{AssetOptionVc, AssetVc}, changed::any_content_changed, chunk::ChunkingContext, context::{AssetContext, AssetContextVc}, @@ -29,7 +29,6 @@ use turbopack_binding::{ virtual_asset::VirtualAssetVc, }, dev::DevChunkingContextVc, - ecmascript::OptionEcmascriptModuleAssetVc, node::{ evaluate::evaluate, execution_context::{ExecutionContext, ExecutionContextVc}, @@ -42,7 +41,6 @@ use turbopack_binding::{ }; use crate::{ - asset_helpers::as_es_module_asset, embed_js::next_asset, mode::NextMode, next_config::NextConfigVc, @@ -143,16 +141,16 @@ async fn get_config( context: AssetContextVc, project_path: FileSystemPathVc, configs: StringsVc, -) -> Result { +) -> Result { let find_config_result = find_context_file(project_path, configs); let config_asset = match &*find_config_result.await? { - FindContextFileResult::Found(config_path, _) => Some(as_es_module_asset( + FindContextFileResult::Found(config_path, _) => Some(context.process( SourceAssetVc::new(*config_path).as_asset(), - context, + Value::new(ReferenceType::Internal(InnerAssetsVc::empty())), )), FindContextFileResult::NotFound(_) => None, }; - Ok(OptionEcmascriptModuleAssetVc::cell(config_asset)) + Ok(AssetOptionVc::cell(config_asset)) } #[turbo_tasks::function] @@ -184,30 +182,29 @@ async fn config_assets( let (manifest, config) = match &*middleware_config { Some(c) => { let manifest = context.with_transition("next-edge").process( - c.as_asset(), + *c, Value::new(ReferenceType::EcmaScriptModules( EcmaScriptModulesReferenceSubType::Undefined, )), ); - let config = parse_config_from_source(c.as_asset()); + let config = parse_config_from_source(*c); (manifest, config) } None => { - let manifest = as_es_module_asset( + let manifest = context.process( VirtualAssetVc::new( project_path.join("middleware.js"), File::from("export default [];").into(), ) .as_asset(), - context, - ) - .as_asset(); + Value::new(ReferenceType::Internal(InnerAssetsVc::empty())), + ); let config = NextSourceConfigVc::default(); (manifest, config) } }; - let config_asset = as_es_module_asset( + let config_asset = context.process( VirtualAssetVc::new( project_path.join("middleware_config.js"), File::from(format!( @@ -217,9 +214,8 @@ async fn config_assets( .into(), ) .as_asset(), - context, - ) - .as_asset(); + Value::new(ReferenceType::Internal(InnerAssetsVc::empty())), + ); Ok(InnerAssetsVc::cell(indexmap! { "MIDDLEWARE_CHUNK_GROUP".to_string() => manifest,