Unverified Commit a4d33d4a authored by OJ Kwon's avatar OJ Kwon Committed by GitHub

fix(next-core): adjust server alias for the context (#61690)

### What

This PR attempts to adjust import map to `server-only` / `client-only`
close to the existing webpack configs, makes to pass more tests.

Closes PACK-2396
parent bb7577aa
...@@ -532,22 +532,21 @@ async fn insert_next_server_special_aliases( ...@@ -532,22 +532,21 @@ async fn insert_next_server_special_aliases(
// see https://github.com/vercel/next.js/blob/8013ef7372fc545d49dbd060461224ceb563b454/packages/next/src/build/webpack-config.ts#L1449-L1531 // see https://github.com/vercel/next.js/blob/8013ef7372fc545d49dbd060461224ceb563b454/packages/next/src/build/webpack-config.ts#L1449-L1531
match ty { match ty {
ServerContextType::Pages { .. } ServerContextType::Pages { .. } => {
| ServerContextType::PagesData { .. }
| ServerContextType::PagesApi { .. } => {
insert_exact_alias_map( insert_exact_alias_map(
import_map, import_map,
project_path, project_path,
indexmap! { indexmap! {
"server-only" => "next/dist/compiled/server-only/index".to_string(), "server-only" => "next/dist/compiled/server-only/empty".to_string(),
"client-only" => "next/dist/compiled/client-only/index".to_string(), "client-only" => "next/dist/compiled/client-only/index".to_string(),
"next/dist/compiled/server-only" => "next/dist/compiled/server-only/index".to_string(), "next/dist/compiled/server-only" => "next/dist/compiled/server-only/empty".to_string(),
"next/dist/compiled/client-only" => "next/dist/compiled/client-only/index".to_string(), "next/dist/compiled/client-only" => "next/dist/compiled/client-only/index".to_string(),
}, },
); );
} }
// TODO: should include `ServerContextType::PagesApi` routes, but that type doesn't exist. ServerContextType::PagesData { .. }
ServerContextType::AppRSC { .. } | ServerContextType::PagesApi { .. }
| ServerContextType::AppRSC { .. }
| ServerContextType::AppRoute { .. } | ServerContextType::AppRoute { .. }
| ServerContextType::Middleware | ServerContextType::Middleware
| ServerContextType::Instrumentation => { | ServerContextType::Instrumentation => {
......
...@@ -5764,14 +5764,13 @@ ...@@ -5764,14 +5764,13 @@
"module layer with server-only in server targets should render routes marked with restriction marks without errors /app/route", "module layer with server-only in server targets should render routes marked with restriction marks without errors /app/route",
"module layer with server-only in server targets should render routes marked with restriction marks without errors /app/route-edge", "module layer with server-only in server targets should render routes marked with restriction marks without errors /app/route-edge",
"module layer with server-only in server targets should render routes marked with restriction marks without errors /app/server", "module layer with server-only in server targets should render routes marked with restriction marks without errors /app/server",
"module layer with server-only in server targets should render routes marked with restriction marks without errors /app/server-edge" "module layer with server-only in server targets should render routes marked with restriction marks without errors /app/server-edge",
],
"failed": [
"module layer no server-only in server targets should render routes marked with restriction marks without errors /api/hello", "module layer no server-only in server targets should render routes marked with restriction marks without errors /api/hello",
"module layer no server-only in server targets should render routes marked with restriction marks without errors /api/hello-edge", "module layer no server-only in server targets should render routes marked with restriction marks without errors /api/hello-edge",
"module layer with server-only in server targets should render routes marked with restriction marks without errors /api/hello", "module layer with server-only in server targets should render routes marked with restriction marks without errors /api/hello",
"module layer with server-only in server targets should render routes marked with restriction marks without errors /api/hello-edge" "module layer with server-only in server targets should render routes marked with restriction marks without errors /api/hello-edge"
], ],
"failed": [],
"pending": [], "pending": [],
"flakey": [], "flakey": [],
"runtimeError": false "runtimeError": false
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment