Skip to content

Commit bffff19

Browse files
committed
add missing name and generator to middleware EF
1 parent 242d71f commit bffff19

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

src/adapter/constants.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { readFileSync } from 'node:fs'
2+
import { join } from 'node:path'
3+
import { fileURLToPath } from 'node:url'
4+
5+
const MODULE_DIR = fileURLToPath(new URL('.', import.meta.url))
6+
export const PLUGIN_DIR = join(MODULE_DIR, '../..')
7+
8+
const packageJSON = JSON.parse(readFileSync(join(PLUGIN_DIR, 'package.json'), 'utf-8'))
9+
10+
export const GENERATOR = `${packageJSON.name}@${packageJSON.version}`

src/adapter/middleware.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { cp, mkdir, readFile, writeFile } from 'node:fs/promises'
22
import { dirname, join, parse } from 'node:path'
3-
import { fileURLToPath } from 'node:url'
43

54
import { glob } from 'fast-glob'
65
import { pathToRegexp } from 'path-to-regexp'
76

7+
import { GENERATOR, PLUGIN_DIR } from './constants.js'
88
import type { FrameworksAPIConfig, NextConfigComplete, OnBuildCompleteContext } from './types.js'
99

1010
const NETLIFY_FRAMEWORKS_API_EDGE_FUNCTIONS = '.netlify/v1/edge-functions'
@@ -15,9 +15,6 @@ const MIDDLEWARE_FUNCTION_DIR = join(
1515
MIDDLEWARE_FUNCTION_NAME,
1616
)
1717

18-
const MODULE_DIR = fileURLToPath(new URL('.', import.meta.url))
19-
const PLUGIN_DIR = join(MODULE_DIR, '../..')
20-
2118
export async function onBuildComplete(
2219
ctx: OnBuildCompleteContext,
2320
frameworksAPIConfigArg: FrameworksAPIConfig,
@@ -138,8 +135,10 @@ const writeHandlerFile = async (
138135
export default (req, context) => handleMiddleware(req, context, handler);
139136
140137
export const config = ${JSON.stringify({
141-
pattern: augmentMatchers(middleware, nextConfig).map((matcher) => matcher.regexp),
142138
cache: undefined,
139+
generator: GENERATOR,
140+
name: 'Next.js Middleware Handler',
141+
pattern: augmentMatchers(middleware, nextConfig).map((matcher) => matcher.regexp),
143142
})}
144143
`,
145144
)

0 commit comments

Comments
 (0)