11import { cp , mkdir , readFile , rm , writeFile } from 'node:fs/promises'
22import { dirname , join } from 'node:path'
33
4- import type { Manifest , ManifestFunction } from '@netlify/edge-functions'
4+ import type { IntegrationsConfig , Manifest , ManifestFunction } from '@netlify/edge-functions'
55import { glob } from 'fast-glob'
66import type { EdgeFunctionDefinition as NextDefinition } from 'next/dist/build/webpack/plugins/middleware-plugin.js'
77import { pathToRegexp } from 'path-to-regexp'
@@ -160,21 +160,25 @@ const getHandlerName = ({ name }: Pick<NextDefinition, 'name'>): string =>
160160const buildHandlerDefinition = (
161161 ctx : PluginContext ,
162162 { name, matchers, page } : NextDefinition ,
163- ) : Array < ManifestFunction > => {
164- const fun = getHandlerName ( { name } )
165- const funName = name . endsWith ( 'middleware' )
163+ ) : ManifestFunction & IntegrationsConfig => {
164+ const functionHandlerName = getHandlerName ( { name } )
165+ const functionName = name . endsWith ( 'middleware' )
166166 ? 'Next.js Middleware Handler'
167167 : `Next.js Edge Handler: ${ page } `
168168 const cache = name . endsWith ( 'middleware' ) ? undefined : ( 'manual' as const )
169169 const generator = `${ ctx . pluginName } @${ ctx . pluginVersion } `
170-
171- return augmentMatchers ( matchers , ctx ) . map ( ( matcher ) => ( {
172- function : fun ,
173- name : funName ,
174- pattern : matcher . regexp ,
170+ const i18nAugmentedMatchers = augmentMatchers ( matchers , ctx )
171+ const combinedEdgeHandlerRegex = i18nAugmentedMatchers
172+ . map ( ( matcher ) => `(${ matcher . regexp } )` )
173+ . join ( '|' )
174+
175+ return {
176+ function : functionHandlerName ,
177+ name : functionName ,
178+ pattern : combinedEdgeHandlerRegex ,
175179 cache,
176180 generator,
177- } ) )
181+ }
178182}
179183
180184export const clearStaleEdgeHandlers = async ( ctx : PluginContext ) => {
@@ -183,10 +187,7 @@ export const clearStaleEdgeHandlers = async (ctx: PluginContext) => {
183187
184188export const createEdgeHandlers = async ( ctx : PluginContext ) => {
185189 const nextManifest = await ctx . getMiddlewareManifest ( )
186- const nextDefinitions = [
187- ...Object . values ( nextManifest . middleware ) ,
188- // ...Object.values(nextManifest.functions)
189- ]
190+ const nextDefinitions = [ ...Object . values ( nextManifest . middleware ) ]
190191 await Promise . all ( nextDefinitions . map ( ( def ) => createEdgeHandler ( ctx , def ) ) )
191192
192193 const netlifyDefinitions = nextDefinitions . flatMap ( ( def ) => buildHandlerDefinition ( ctx , def ) )
0 commit comments