Skip to content

Commit 537f8c7

Browse files
authored
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.
1 parent ee15207 commit 537f8c7

File tree

16 files changed

+36
-11
lines changed

16 files changed

+36
-11
lines changed

crates/napi/src/next_api/project.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -752,6 +752,7 @@ impl NapiRoute {
752752
#[napi(object)]
753753
pub struct NapiMiddleware {
754754
pub endpoint: External<ExternalEndpoint>,
755+
pub is_proxy: bool,
755756
}
756757

757758
impl NapiMiddleware {
@@ -764,6 +765,7 @@ impl NapiMiddleware {
764765
turbopack_ctx.clone(),
765766
value.endpoint,
766767
))),
768+
is_proxy: value.is_proxy,
767769
})
768770
}
769771
}

crates/next-api/src/operation.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,9 @@ impl EntrypointsOperation {
5555
.iter()
5656
.map(|(k, v)| (k.clone(), pick_route(entrypoints, k.clone(), v)))
5757
.collect(),
58-
middleware: e.middleware.as_ref().map(|_| MiddlewareOperation {
58+
middleware: e.middleware.as_ref().map(|m| MiddlewareOperation {
5959
endpoint: pick_endpoint(entrypoints, EndpointSelector::Middleware),
60+
is_proxy: m.is_proxy,
6061
}),
6162
instrumentation: e
6263
.instrumentation
@@ -212,6 +213,7 @@ pub struct InstrumentationOperation {
212213
#[derive(Serialize, Deserialize, TraceRawVcs, PartialEq, Eq, ValueDebugFormat, NonLocalValue)]
213214
pub struct MiddlewareOperation {
214215
pub endpoint: OperationVc<OptionEndpoint>,
216+
pub is_proxy: bool,
215217
}
216218

217219
#[turbo_tasks::value(shared)]

crates/next-api/src/project.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,7 @@ pub struct DefineEnv {
255255
#[derive(Serialize, Deserialize, TraceRawVcs, PartialEq, Eq, ValueDebugFormat, NonLocalValue)]
256256
pub struct Middleware {
257257
pub endpoint: ResolvedVc<Box<dyn Endpoint>>,
258+
pub is_proxy: bool,
258259
}
259260

260261
#[derive(Serialize, Deserialize, TraceRawVcs, PartialEq, Eq, ValueDebugFormat, NonLocalValue)]
@@ -1269,9 +1270,11 @@ impl Project {
12691270
let pages_error_endpoint = self.pages_project().error_endpoint().to_resolved().await?;
12701271

12711272
let middleware = self.find_middleware();
1272-
let middleware = if let FindContextFileResult::Found(..) = *middleware.await? {
1273+
let middleware = if let FindContextFileResult::Found(fs_path, _) = &*middleware.await? {
1274+
let is_proxy = fs_path.file_stem() == Some("proxy");
12731275
Some(Middleware {
12741276
endpoint: self.middleware_endpoint().to_resolved().await?,
1277+
is_proxy,
12751278
})
12761279
} else {
12771280
None

packages/next/src/build/swc/generated-native.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,7 @@ export interface NapiRoute {
279279
}
280280
export interface NapiMiddleware {
281281
endpoint: ExternalObject<ExternalEndpoint>
282+
isProxy: boolean
282283
}
283284
export interface NapiInstrumentation {
284285
nodeJs: ExternalObject<ExternalEndpoint>

packages/next/src/build/swc/index.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -486,8 +486,7 @@ function bindingToApi(
486486

487487
type NapiMiddleware = {
488488
endpoint: NapiEndpoint
489-
runtime: 'nodejs' | 'edge'
490-
matcher?: string[]
489+
isProxy: boolean
491490
}
492491

493492
type NapiInstrumentation = {
@@ -1054,8 +1053,7 @@ function bindingToApi(
10541053
}
10551054
const napiMiddlewareToMiddleware = (middleware: NapiMiddleware) => ({
10561055
endpoint: new EndpointImpl(middleware.endpoint),
1057-
runtime: middleware.runtime,
1058-
matcher: middleware.matcher,
1056+
isProxy: middleware.isProxy,
10591057
})
10601058
const middleware = entrypoints.middleware
10611059
? napiMiddlewareToMiddleware(entrypoints.middleware)

packages/next/src/build/swc/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ export type TurbopackResult<T = {}> = T & {
144144

145145
export interface Middleware {
146146
endpoint: Endpoint
147+
isProxy: boolean
147148
}
148149

149150
export interface Instrumentation {

packages/next/src/server/dev/on-demand-entry-handler.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -886,7 +886,11 @@ export function onDemandEntryHandler({
886886

887887
if (hasNewEntry) {
888888
const routePage = isApp ? route.page : normalizeAppPath(route.page)
889-
reportTrigger(routePage, url)
889+
// If proxy file, remove the leading slash from "/proxy" to "proxy".
890+
reportTrigger(
891+
isMiddlewareFile(routePage) ? routePage.slice(1) : routePage,
892+
url
893+
)
890894
}
891895

892896
if (entriesThatShouldBeInvalidated.length > 0) {

packages/next/src/server/dev/turbopack-utils.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import {
3535
type EntryIssuesMap,
3636
type TopLevelIssuesMap,
3737
} from '../../shared/lib/turbopack/utils'
38+
import { MIDDLEWARE_FILENAME, PROXY_FILENAME } from '../../lib/constants'
3839

3940
const onceErrorSet = new Set()
4041
/**
@@ -712,10 +713,13 @@ export async function handleEntrypoints({
712713
const key = getEntryKey('root', 'server', 'middleware')
713714

714715
const endpoint = middleware.endpoint
716+
const triggerName = middleware.isProxy
717+
? PROXY_FILENAME
718+
: MIDDLEWARE_FILENAME
715719

716720
async function processMiddleware() {
717721
const finishBuilding = dev.hooks.startBuilding(
718-
'middleware',
722+
triggerName,
719723
undefined,
720724
true
721725
)
@@ -744,7 +748,7 @@ export async function handleEntrypoints({
744748
endpoint,
745749
async () => {
746750
const finishBuilding = dev.hooks.startBuilding(
747-
'middleware',
751+
triggerName,
748752
undefined,
749753
true
750754
)

test/e2e/app-dir/app-middleware-proxy/app-middleware-proxy.test.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,17 @@ import { nextTestSetup } from 'e2e-utils'
55
import type { Response } from 'node-fetch'
66

77
describe('app-dir with proxy', () => {
8-
const { next, isNextDeploy } = nextTestSetup({
8+
const { next, isNextDev, isNextDeploy } = nextTestSetup({
99
files: __dirname,
1010
})
1111

12+
if (isNextDev) {
13+
it('should log Compiled proxy in', async () => {
14+
await next.browser('/')
15+
expect(next.cliOutput).toContain('Compiled proxy in')
16+
})
17+
}
18+
1219
it('should filter correctly after proxy rewrite', async () => {
1320
const browser = await next.browser('/start')
1421

File renamed without changes.

0 commit comments

Comments
 (0)