|
1 | 1 | import { cp, mkdir, readFile, rm, writeFile } from 'node:fs/promises' |
2 | 2 | import { dirname, join } from 'node:path' |
3 | 3 |
|
| 4 | +import type { Manifest, ManifestFunction } from '@netlify/edge-functions' |
4 | 5 | import { glob } from 'fast-glob' |
5 | 6 | import type { EdgeFunctionDefinition as NextDefinition } from 'next/dist/build/webpack/plugins/middleware-plugin.js' |
6 | 7 | import { pathToRegexp } from 'path-to-regexp' |
7 | 8 |
|
8 | 9 | import { EDGE_HANDLER_NAME, PluginContext } from '../plugin-context.js' |
9 | 10 |
|
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) => { |
24 | 12 | await mkdir(ctx.edgeFunctionsDir, { recursive: true }) |
25 | 13 | await writeFile(join(ctx.edgeFunctionsDir, 'manifest.json'), JSON.stringify(manifest, null, 2)) |
26 | 14 | } |
@@ -157,7 +145,7 @@ const getHandlerName = ({ name }: Pick<NextDefinition, 'name'>): string => |
157 | 145 | const buildHandlerDefinition = ( |
158 | 146 | ctx: PluginContext, |
159 | 147 | { name, matchers, page }: NextDefinition, |
160 | | -): Array<NetlifyDefinition> => { |
| 148 | +): Array<ManifestFunction> => { |
161 | 149 | const fun = getHandlerName({ name }) |
162 | 150 | const funName = name.endsWith('middleware') |
163 | 151 | ? 'Next.js Middleware Handler' |
@@ -185,7 +173,7 @@ export const createEdgeHandlers = async (ctx: PluginContext) => { |
185 | 173 | await Promise.all(nextDefinitions.map((def) => createEdgeHandler(ctx, def))) |
186 | 174 |
|
187 | 175 | const netlifyDefinitions = nextDefinitions.flatMap((def) => buildHandlerDefinition(ctx, def)) |
188 | | - const netlifyManifest = { |
| 176 | + const netlifyManifest: Manifest = { |
189 | 177 | version: 1, |
190 | 178 | functions: netlifyDefinitions, |
191 | 179 | } |
|
0 commit comments