Skip to content

Commit a5c023f

Browse files
authored
refactor: use published Edge Function Manifest types (#461)
See netlify/edge-functions-bootstrap#343.
1 parent 2012922 commit a5c023f

File tree

3 files changed

+12
-24
lines changed

3 files changed

+12
-24
lines changed

package-lock.json

+7-7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
"@netlify/blobs": "^7.3.0",
5353
"@netlify/build": "^29.41.2",
5454
"@netlify/edge-bundler": "^12.0.0",
55-
"@netlify/edge-functions": "^2.6.0",
55+
"@netlify/edge-functions": "^2.6.1",
5656
"@netlify/eslint-config-node": "^7.0.1",
5757
"@netlify/functions": "^2.5.1",
5858
"@netlify/serverless-functions-api": "^1.18.0",

src/build/functions/edge.ts

+4-16
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,14 @@
11
import { cp, mkdir, readFile, rm, writeFile } from 'node:fs/promises'
22
import { dirname, join } from 'node:path'
33

4+
import type { Manifest, ManifestFunction } from '@netlify/edge-functions'
45
import { glob } from 'fast-glob'
56
import type { EdgeFunctionDefinition as NextDefinition } from 'next/dist/build/webpack/plugins/middleware-plugin.js'
67
import { pathToRegexp } from 'path-to-regexp'
78

89
import { EDGE_HANDLER_NAME, PluginContext } from '../plugin-context.js'
910

10-
interface NetlifyDefinition {
11-
function: string
12-
name: string
13-
pattern: string
14-
cache?: 'manual'
15-
generator: string
16-
}
17-
18-
interface NetlifyManifest {
19-
version: number
20-
functions: NetlifyDefinition[]
21-
}
22-
23-
const writeEdgeManifest = async (ctx: PluginContext, manifest: NetlifyManifest) => {
11+
const writeEdgeManifest = async (ctx: PluginContext, manifest: Manifest) => {
2412
await mkdir(ctx.edgeFunctionsDir, { recursive: true })
2513
await writeFile(join(ctx.edgeFunctionsDir, 'manifest.json'), JSON.stringify(manifest, null, 2))
2614
}
@@ -157,7 +145,7 @@ const getHandlerName = ({ name }: Pick<NextDefinition, 'name'>): string =>
157145
const buildHandlerDefinition = (
158146
ctx: PluginContext,
159147
{ name, matchers, page }: NextDefinition,
160-
): Array<NetlifyDefinition> => {
148+
): Array<ManifestFunction> => {
161149
const fun = getHandlerName({ name })
162150
const funName = name.endsWith('middleware')
163151
? 'Next.js Middleware Handler'
@@ -185,7 +173,7 @@ export const createEdgeHandlers = async (ctx: PluginContext) => {
185173
await Promise.all(nextDefinitions.map((def) => createEdgeHandler(ctx, def)))
186174

187175
const netlifyDefinitions = nextDefinitions.flatMap((def) => buildHandlerDefinition(ctx, def))
188-
const netlifyManifest = {
176+
const netlifyManifest: Manifest = {
189177
version: 1,
190178
functions: netlifyDefinitions,
191179
}

0 commit comments

Comments
 (0)