Skip to content

Commit bba7172

Browse files
committed
feat: add generator to edge
1 parent 76d4250 commit bba7172

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/runtime/src/helpers/edge.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ import { outdent } from 'outdent'
1313
import { IMAGE_FUNCTION_NAME } from '../constants'
1414

1515
import { getRequiredServerFiles, NextConfig } from './config'
16+
import { writeEdgeFunctionConfiguration } from './functionsMetaData'
1617
import { makeLocaleOptional, stripLookahead, transformCaptureGroups } from './matchers'
1718
import { RoutesManifest } from './types'
18-
1919
// This is the format as of [email protected]
2020
interface EdgeFunctionDefinitionV1 {
2121
env: string[]
@@ -57,12 +57,14 @@ export interface FunctionManifest {
5757
name?: string
5858
path: string
5959
cache?: 'manual'
60+
generator?: string
6061
}
6162
| {
6263
function: string
6364
name?: string
6465
pattern: string
6566
cache?: 'manual'
67+
generator?: string
6668
}
6769
>
6870
import_map?: string
@@ -220,15 +222,17 @@ const generateEdgeFunctionMiddlewareMatchers = ({
220222
const middlewareMatcherToEdgeFunctionDefinition = (
221223
matcher: MiddlewareMatcher,
222224
name: string,
225+
generator: string,
223226
cache?: 'manual',
224227
): {
225228
function: string
226229
name?: string
227230
pattern: string
228231
cache?: 'manual'
232+
generator?: string
229233
} => {
230234
const pattern = transformCaptureGroups(stripLookahead(matcher.regexp))
231-
return { function: name, pattern, name, cache }
235+
return { function: name, pattern, name, cache, generator }
232236
}
233237

234238
export const cleanupEdgeFunctions = ({
@@ -262,7 +266,7 @@ export const writeDevEdgeFunction = async ({
262266
* Writes an edge function that routes RSC data requests to the `.rsc` route
263267
*/
264268

265-
export const writeRscDataEdgeFunction = async ({
269+
export const writeRscDataEdgeFunction = async ({
266270
prerenderManifest,
267271
appPathRoutesManifest,
268272
}: {
@@ -343,6 +347,9 @@ export const writeEdgeFunctions = async ({
343347
netlifyConfig: NetlifyConfig
344348
routesManifest: RoutesManifest
345349
}) => {
350+
351+
const nextjsPluginVersion = await writeEdgeFunctionConfiguration()
352+
346353
const manifest: FunctionManifest = {
347354
functions: [],
348355
version: 1,
@@ -400,7 +407,7 @@ export const writeEdgeFunctions = async ({
400407
})
401408

402409
manifest.functions.push(
403-
...matchers.map((matcher) => middlewareMatcherToEdgeFunctionDefinition(matcher, functionName)),
410+
...matchers.map((matcher) => middlewareMatcherToEdgeFunctionDefinition(matcher, functionName, nextjsPluginVersion)),
404411
)
405412
}
406413
// Functions (i.e. not middleware, but edge SSR and API routes)
@@ -440,6 +447,7 @@ export const writeEdgeFunctions = async ({
440447
pattern,
441448
// cache: "manual" is currently experimental, so we restrict it to sites that use experimental appDir
442449
cache: usesAppDir ? 'manual' : undefined,
450+
generator: `${nextjsPluginVersion}`,
443451
})
444452
// pages-dir page routes also have a data route. If there's a match, add an entry mapping that to the function too
445453
const dataRoute = dataRoutesMap.get(edgeFunctionDefinition.page)
@@ -449,6 +457,7 @@ export const writeEdgeFunctions = async ({
449457
name: edgeFunctionDefinition.name,
450458
pattern: dataRoute,
451459
cache: usesAppDir ? 'manual' : undefined,
460+
generator: `${nextjsPluginVersion}`
452461
})
453462
}
454463
}
@@ -474,6 +483,7 @@ export const writeEdgeFunctions = async ({
474483
function: 'ipx',
475484
name: 'next/image handler',
476485
path: '/_next/image*',
486+
generator: `${nextjsPluginVersion}`
477487
})
478488
} else {
479489
console.log(
@@ -487,6 +497,6 @@ export const writeEdgeFunctions = async ({
487497
This feature is in beta. Please share your feedback here: https://ntl.fyi/next-netlify-edge
488498
`)
489499
}
490-
500+
console.log('MANIFEST', manifest, nextjsPluginVersion)
491501
await writeJson(join(edgeFunctionRoot, 'manifest.json'), manifest)
492502
}

0 commit comments

Comments
 (0)