From 3994c69487fc26644aa899f7a36b4134583f2c68 Mon Sep 17 00:00:00 2001 From: hrmny <8845940+ForsakenHarmony@users.noreply.github.com> Date: Tue, 23 Apr 2024 15:17:22 +0200 Subject: [PATCH] feat(turbopack): add support for esm externals in app dir --- .../client_reference_manifest.rs | 25 +++++++++---------- .../next-core/src/next_server/context.rs | 4 +-- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/packages/next-swc/crates/next-core/src/next_manifests/client_reference_manifest.rs b/packages/next-swc/crates/next-core/src/next_manifests/client_reference_manifest.rs index 286fe3837a239..5522269684e2a 100644 --- a/packages/next-swc/crates/next-core/src/next_manifests/client_reference_manifest.rs +++ b/packages/next-swc/crates/next-core/src/next_manifests/client_reference_manifest.rs @@ -5,7 +5,7 @@ use turbo_tasks_fs::{File, FileSystemPath}; use turbopack_binding::turbopack::{ core::{ asset::AssetContent, - chunk::{ChunkItemExt, ChunkableModule, ModuleId as TurbopackModuleId}, + chunk::{ChunkItem, ChunkItemExt, ChunkableModule, ModuleId as TurbopackModuleId}, output::OutputAsset, virtual_output::VirtualOutputAsset, }, @@ -66,11 +66,11 @@ impl ClientReferenceManifest { .to_string() .await?; - let client_module_id = ecmascript_client_reference + let client_chunk_item = ecmascript_client_reference .client_module - .as_chunk_item(Vc::upcast(client_chunking_context)) - .id() - .await?; + .as_chunk_item(Vc::upcast(client_chunking_context)); + + let client_module_id = client_chunk_item.id().await?; let client_chunks_paths = if let Some(client_chunks) = client_references_chunks .client_component_client_chunks @@ -100,17 +100,16 @@ impl ClientReferenceManifest { name: "*".to_string(), id: (&*client_module_id).into(), chunks: client_chunks_paths, - // TODO(WEB-434) - r#async: false, + r#async: *client_chunk_item.is_self_async().await?, }, ); if let Some(ssr_chunking_context) = ssr_chunking_context { - let ssr_module_id = ecmascript_client_reference + let ssr_chunk_item = ecmascript_client_reference .ssr_module - .as_chunk_item(Vc::upcast(ssr_chunking_context)) - .id() - .await?; + .as_chunk_item(Vc::upcast(ssr_chunking_context)); + + let ssr_module_id = ssr_chunk_item.id().await?; let ssr_chunks_paths = if runtime == NextRuntime::Edge { // the chunks get added to the middleware-manifest.json instead @@ -138,6 +137,7 @@ impl ClientReferenceManifest { } else { Vec::new() }; + let mut ssr_manifest_node = ManifestNode::default(); ssr_manifest_node.module_exports.insert( "*".to_string(), @@ -145,8 +145,7 @@ impl ClientReferenceManifest { name: "*".to_string(), id: (&*ssr_module_id).into(), chunks: ssr_chunks_paths, - // TODO(WEB-434) - r#async: false, + r#async: *ssr_chunk_item.is_self_async().await?, }, ); 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 80dda4d981186..2b5a27d1e28af 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 @@ -138,9 +138,9 @@ pub async fn get_server_resolve_options_context( project_path, project_path.root(), ExternalPredicate::Only(Vc::cell(external_packages)).cell(), - // TODO(sokra) esmExternals support - false, + *next_config.import_externals().await?, ); + let ty = ty.into_value(); let mut custom_conditions = vec![mode.await?.condition().to_string()];