Unverified Commit 537f8c78 authored by Jiwon Choi's avatar Jiwon Choi Committed by GitHub

Log `Compiled proxy in ...` (#84746)

When using `proxy`, the `Compiled X in ...` message in Turbopack had
hardcoded `middleware`. Therefore, modify to display `proxy` if using a
proxy. Also, Webpack displayed with a leading slash `/proxy`, which
could be misinterpreted as a route, so I removed the leading slash.
parent ee152079
......@@ -752,6 +752,7 @@ impl NapiRoute {
#[napi(object)]
pub struct NapiMiddleware {
pub endpoint: External<ExternalEndpoint>,
pub is_proxy: bool,
}
impl NapiMiddleware {
......@@ -764,6 +765,7 @@ impl NapiMiddleware {
turbopack_ctx.clone(),
value.endpoint,
))),
is_proxy: value.is_proxy,
})
}
}
......
......@@ -55,8 +55,9 @@ impl EntrypointsOperation {
.iter()
.map(|(k, v)| (k.clone(), pick_route(entrypoints, k.clone(), v)))
.collect(),
middleware: e.middleware.as_ref().map(|_| MiddlewareOperation {
middleware: e.middleware.as_ref().map(|m| MiddlewareOperation {
endpoint: pick_endpoint(entrypoints, EndpointSelector::Middleware),
is_proxy: m.is_proxy,
}),
instrumentation: e
.instrumentation
......@@ -212,6 +213,7 @@ pub struct InstrumentationOperation {
#[derive(Serialize, Deserialize, TraceRawVcs, PartialEq, Eq, ValueDebugFormat, NonLocalValue)]
pub struct MiddlewareOperation {
pub endpoint: OperationVc<OptionEndpoint>,
pub is_proxy: bool,
}
#[turbo_tasks::value(shared)]
......
......@@ -255,6 +255,7 @@ pub struct DefineEnv {
#[derive(Serialize, Deserialize, TraceRawVcs, PartialEq, Eq, ValueDebugFormat, NonLocalValue)]
pub struct Middleware {
pub endpoint: ResolvedVc<Box<dyn Endpoint>>,
pub is_proxy: bool,
}
#[derive(Serialize, Deserialize, TraceRawVcs, PartialEq, Eq, ValueDebugFormat, NonLocalValue)]
......@@ -1269,9 +1270,11 @@ impl Project {
let pages_error_endpoint = self.pages_project().error_endpoint().to_resolved().await?;
let middleware = self.find_middleware();
let middleware = if let FindContextFileResult::Found(..) = *middleware.await? {
let middleware = if let FindContextFileResult::Found(fs_path, _) = &*middleware.await? {
let is_proxy = fs_path.file_stem() == Some("proxy");
Some(Middleware {
endpoint: self.middleware_endpoint().to_resolved().await?,
is_proxy,
})
} else {
None
......
......@@ -279,6 +279,7 @@ export interface NapiRoute {
}
export interface NapiMiddleware {
endpoint: ExternalObject<ExternalEndpoint>
isProxy: boolean
}
export interface NapiInstrumentation {
nodeJs: ExternalObject<ExternalEndpoint>
......
......@@ -486,8 +486,7 @@ function bindingToApi(
type NapiMiddleware = {
endpoint: NapiEndpoint
runtime: 'nodejs' | 'edge'
matcher?: string[]
isProxy: boolean
}
type NapiInstrumentation = {
......@@ -1054,8 +1053,7 @@ function bindingToApi(
}
const napiMiddlewareToMiddleware = (middleware: NapiMiddleware) => ({
endpoint: new EndpointImpl(middleware.endpoint),
runtime: middleware.runtime,
matcher: middleware.matcher,
isProxy: middleware.isProxy,
})
const middleware = entrypoints.middleware
? napiMiddlewareToMiddleware(entrypoints.middleware)
......
......@@ -144,6 +144,7 @@ export type TurbopackResult<T = {}> = T & {
export interface Middleware {
endpoint: Endpoint
isProxy: boolean
}
export interface Instrumentation {
......
......@@ -886,7 +886,11 @@ export function onDemandEntryHandler({
if (hasNewEntry) {
const routePage = isApp ? route.page : normalizeAppPath(route.page)
reportTrigger(routePage, url)
// If proxy file, remove the leading slash from "/proxy" to "proxy".
reportTrigger(
isMiddlewareFile(routePage) ? routePage.slice(1) : routePage,
url
)
}
if (entriesThatShouldBeInvalidated.length > 0) {
......
......@@ -35,6 +35,7 @@ import {
type EntryIssuesMap,
type TopLevelIssuesMap,
} from '../../shared/lib/turbopack/utils'
import { MIDDLEWARE_FILENAME, PROXY_FILENAME } from '../../lib/constants'
const onceErrorSet = new Set()
/**
......@@ -712,10 +713,13 @@ export async function handleEntrypoints({
const key = getEntryKey('root', 'server', 'middleware')
const endpoint = middleware.endpoint
const triggerName = middleware.isProxy
? PROXY_FILENAME
: MIDDLEWARE_FILENAME
async function processMiddleware() {
const finishBuilding = dev.hooks.startBuilding(
'middleware',
triggerName,
undefined,
true
)
......@@ -744,7 +748,7 @@ export async function handleEntrypoints({
endpoint,
async () => {
const finishBuilding = dev.hooks.startBuilding(
'middleware',
triggerName,
undefined,
true
)
......
......@@ -5,10 +5,17 @@ import { nextTestSetup } from 'e2e-utils'
import type { Response } from 'node-fetch'
describe('app-dir with proxy', () => {
const { next, isNextDeploy } = nextTestSetup({
const { next, isNextDev, isNextDeploy } = nextTestSetup({
files: __dirname,
})
if (isNextDev) {
it('should log Compiled proxy in', async () => {
await next.browser('/')
expect(next.cliOutput).toContain('Compiled proxy in')
})
}
it('should filter correctly after proxy rewrite', async () => {
const browser = await next.browser('/start')
......
export default function Page() {
return <p>hello world</p>
}
......@@ -13,7 +13,7 @@ describe('proxy-with-middleware', () => {
it('should error when both middleware and proxy files are detected', async () => {
if (isNextDev) {
await next.start()
await next.start().catch(() => {})
expect(next.cliOutput).toContain(
'Both "middleware" and "proxy" files are detected. Please use "proxy" instead.'
)
......
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