Skip to content

Commit

Permalink
better @vercel/og alias
Browse files Browse the repository at this point in the history
  • Loading branch information
ForsakenHarmony committed Sep 6, 2023
1 parent 5a05f66 commit 7d3e3ae
Showing 1 changed file with 36 additions and 10 deletions.
46 changes: 36 additions & 10 deletions packages/next-swc/crates/next-core/src/next_import_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,14 @@ pub async fn get_next_server_import_map(

let ty = ty.into_value();

insert_next_server_special_aliases(&mut import_map, ty, mode, NextRuntime::NodeJs).await?;
insert_next_server_special_aliases(
&mut import_map,
project_path,
ty,
mode,
NextRuntime::NodeJs,
)
.await?;
let external = ImportMapping::External(None).cell();

match ty {
Expand Down Expand Up @@ -288,7 +295,8 @@ pub async fn get_next_edge_import_map(

let ty = ty.into_value();

insert_next_server_special_aliases(&mut import_map, ty, mode, NextRuntime::Edge).await?;
insert_next_server_special_aliases(&mut import_map, project_path, ty, mode, NextRuntime::Edge)
.await?;

match ty {
ServerContextType::Pages { .. } | ServerContextType::PagesData { .. } => {}
Expand Down Expand Up @@ -369,6 +377,7 @@ static NEXT_ALIASES: [(&str, &str); 23] = [

async fn insert_next_server_special_aliases(
import_map: &mut ImportMap,
project_path: Vc<FileSystemPath>,
ty: ServerContextType,
mode: NextMode,
runtime: NextRuntime,
Expand Down Expand Up @@ -529,6 +538,31 @@ async fn insert_next_server_special_aliases(
(_, ServerContextType::Middleware) => {}
}

import_map.insert_exact_alias(
"@vercel/og",
external_if_node(
project_path,
"next/dist/server/web/spec-extension/image-response",
),
);

// TODO: use this alias
// let og_mapping = match runtime {
// NextRuntime::Edge => {
// request_to_import_mapping(project_path, "next/dist/compiled/@vercel/og/index.edge.js")
// }
// NextRuntime::NodeJs => {
// request_to_import_mapping(project_path, "next/dist/compiled/@vercel/og/index.node.js")
// // external_request_to_import_mapping("next/dist/compiled/@vercel/
// // og/index.node.js")
// }
// };
// import_map.insert_exact_alias("@vercel/og", og_mapping);
// import_map.insert_exact_alias(
// "next/dist/server/web/spec-extension/image-response",
// og_mapping,
// );

Ok(())
}

Expand Down Expand Up @@ -614,14 +648,6 @@ pub async fn insert_next_shared_aliases(
.into(),
);

import_map.insert_exact_alias(
"@vercel/og",
request_to_import_mapping(
package_root,
"next/dist/server/web/spec-extension/image-response",
),
);

import_map.insert_singleton_alias("@swc/helpers", get_next_package(project_path));
import_map.insert_singleton_alias("styled-jsx", get_next_package(project_path));
import_map.insert_singleton_alias("next", project_path);
Expand Down

0 comments on commit 7d3e3ae

Please sign in to comment.