Unverified Commit 8303c564 authored by JJ Kasper's avatar JJ Kasper Committed by GitHub

Pass through original matcher source in manifest (#46753)

This ensures we pass through the original matcher source in the
middleware manifest for posterity.
parent 25efdfad
...@@ -30,6 +30,7 @@ export interface MiddlewareMatcher { ...@@ -30,6 +30,7 @@ export interface MiddlewareMatcher {
locale?: false locale?: false
has?: RouteHas[] has?: RouteHas[]
missing?: RouteHas[] missing?: RouteHas[]
originalSource: string
} }
export interface PageStaticInfo { export interface PageStaticInfo {
...@@ -197,6 +198,7 @@ export function getMiddlewareMatchers( ...@@ -197,6 +198,7 @@ export function getMiddlewareMatchers(
return { return {
...rest, ...rest,
regexp: parsedPage.regexStr, regexp: parsedPage.regexStr,
originalSource: source,
} }
}) })
} }
......
...@@ -416,7 +416,7 @@ export async function createEntrypoints(params: CreateEntrypointsParams) { ...@@ -416,7 +416,7 @@ export async function createEntrypoints(params: CreateEntrypointsParams) {
if (isMiddlewareFile(page)) { if (isMiddlewareFile(page)) {
middlewareMatchers = staticInfo.middleware?.matchers ?? [ middlewareMatchers = staticInfo.middleware?.matchers ?? [
{ regexp: '.*' }, { regexp: '.*', originalSource: '/:path*' },
] ]
} }
......
...@@ -171,14 +171,20 @@ function getCreateAssets(params: { ...@@ -171,14 +171,20 @@ function getCreateAssets(params: {
continue continue
} }
const { namedRegex } = getNamedMiddlewareRegex( const matcherSource = metadata.edgeSSR?.isAppDir
metadata.edgeSSR?.isAppDir ? normalizeAppPath(page) : page, ? normalizeAppPath(page)
{ : page
catchAll: !metadata.edgeSSR && !metadata.edgeApiFunction,
} const catchAll = !metadata.edgeSSR && !metadata.edgeApiFunction
)
const { namedRegex } = getNamedMiddlewareRegex(matcherSource, {
catchAll,
})
const matchers = metadata?.edgeMiddleware?.matchers ?? [ const matchers = metadata?.edgeMiddleware?.matchers ?? [
{ regexp: namedRegex }, {
regexp: namedRegex,
originalSource: page === '/' && catchAll ? '/:path*' : matcherSource,
},
] ]
const edgeFunctionDefinition: EdgeFunctionDefinition = { const edgeFunctionDefinition: EdgeFunctionDefinition = {
......
...@@ -497,7 +497,7 @@ export default class DevServer extends Server { ...@@ -497,7 +497,7 @@ export default class DevServer extends Server {
} }
this.actualMiddlewareFile = rootFile this.actualMiddlewareFile = rootFile
middlewareMatchers = staticInfo.middleware?.matchers || [ middlewareMatchers = staticInfo.middleware?.matchers || [
{ regexp: '.*' }, { regexp: '.*', originalSource: '/:path*' },
] ]
continue continue
} }
......
...@@ -88,7 +88,7 @@ export async function makeResolver( ...@@ -88,7 +88,7 @@ export async function makeResolver(
if (middleware.files?.length) { if (middleware.files?.length) {
const matchers = middleware.matcher const matchers = middleware.matcher
? getMiddlewareMatchers(middleware.matcher, nextConfig) ? getMiddlewareMatchers(middleware.matcher, nextConfig)
: [{ regexp: '.*' }] : [{ regexp: '.*', originalSource: '/:path*' }]
// @ts-expect-error // @ts-expect-error
devServer.middleware = { devServer.middleware = {
page: '/', page: '/',
......
...@@ -61,6 +61,7 @@ createNextDescribe( ...@@ -61,6 +61,7 @@ createNextDescribe(
expect(manifest.functions['/(group)/group/page'].matchers).toEqual([ expect(manifest.functions['/(group)/group/page'].matchers).toEqual([
{ {
regexp: '^/group$', regexp: '^/group$',
originalSource: '/group',
}, },
]) ])
}) })
......
...@@ -109,7 +109,7 @@ describe('Middleware Runtime', () => { ...@@ -109,7 +109,7 @@ describe('Middleware Runtime', () => {
`/_next/static/${next.buildId}/_devMiddlewareManifest.json` `/_next/static/${next.buildId}/_devMiddlewareManifest.json`
) )
const matchers = await res.json() const matchers = await res.json()
expect(matchers).toEqual([{ regexp: '.*' }]) expect(matchers).toEqual([{ regexp: '.*', originalSource: '/:path*' }])
}) })
} }
...@@ -131,7 +131,7 @@ describe('Middleware Runtime', () => { ...@@ -131,7 +131,7 @@ describe('Middleware Runtime', () => {
]), ]),
name: 'middleware', name: 'middleware',
page: '/', page: '/',
matchers: [{ regexp: '^/.*$' }], matchers: [{ regexp: '^/.*$', originalSource: '/:path*' }],
wasm: [], wasm: [],
assets: [], assets: [],
regions: 'auto', regions: 'auto',
......
...@@ -115,7 +115,7 @@ describe('Middleware Runtime trailing slash', () => { ...@@ -115,7 +115,7 @@ describe('Middleware Runtime trailing slash', () => {
name: 'middleware', name: 'middleware',
env: [], env: [],
page: '/', page: '/',
matchers: [{ regexp: '^/.*$' }], matchers: [{ regexp: '^/.*$', originalSource: '/:path*' }],
wasm: [], wasm: [],
assets: [], assets: [],
}, },
......
...@@ -194,7 +194,9 @@ describe('Switchable runtime', () => { ...@@ -194,7 +194,9 @@ describe('Switchable runtime', () => {
], ],
name: 'pages/api/hello', name: 'pages/api/hello',
page: '/api/hello', page: '/api/hello',
matchers: [{ regexp: '^/api/hello$' }], matchers: [
{ regexp: '^/api/hello$', originalSource: '/api/hello' },
],
wasm: [], wasm: [],
}, },
'/api/edge': { '/api/edge': {
...@@ -205,7 +207,9 @@ describe('Switchable runtime', () => { ...@@ -205,7 +207,9 @@ describe('Switchable runtime', () => {
], ],
name: 'pages/api/edge', name: 'pages/api/edge',
page: '/api/edge', page: '/api/edge',
matchers: [{ regexp: '^/api/edge$' }], matchers: [
{ regexp: '^/api/edge$', originalSource: '/api/edge' },
],
wasm: [], wasm: [],
}, },
}, },
...@@ -626,7 +630,9 @@ describe('Switchable runtime', () => { ...@@ -626,7 +630,9 @@ describe('Switchable runtime', () => {
], ],
name: 'pages/api/hello', name: 'pages/api/hello',
page: '/api/hello', page: '/api/hello',
matchers: [{ regexp: '^/api/hello$' }], matchers: [
{ regexp: '^/api/hello$', originalSource: '/api/hello' },
],
wasm: [], wasm: [],
}, },
'/api/edge': { '/api/edge': {
...@@ -637,7 +643,9 @@ describe('Switchable runtime', () => { ...@@ -637,7 +643,9 @@ describe('Switchable runtime', () => {
], ],
name: 'pages/api/edge', name: 'pages/api/edge',
page: '/api/edge', page: '/api/edge',
matchers: [{ regexp: '^/api/edge$' }], matchers: [
{ regexp: '^/api/edge$', originalSource: '/api/edge' },
],
wasm: [], wasm: [],
}, },
}, },
......
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