Skip to content

Commit

Permalink
feat(turbopack): add support for esm externals in app dir
Browse files Browse the repository at this point in the history
  • Loading branch information
ForsakenHarmony committed Apr 23, 2024
1 parent 416cf45 commit 3994c69
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -138,15 +137,15 @@ impl ClientReferenceManifest {
} else {
Vec::new()
};

let mut ssr_manifest_node = ManifestNode::default();
ssr_manifest_node.module_exports.insert(
"*".to_string(),
ManifestNodeEntry {
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?,
},
);

Expand Down
4 changes: 2 additions & 2 deletions packages/next-swc/crates/next-core/src/next_server/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()];
Expand Down

0 comments on commit 3994c69

Please sign in to comment.