From 3b2eb113dc87345fa790d3f8d1c373fda71e6007 Mon Sep 17 00:00:00 2001 From: Mateusz Bocian Date: Tue, 22 Apr 2025 13:55:40 -0400 Subject: [PATCH 1/3] fix: enforce a single edge entrypoint for next edge handler --- src/build/functions/edge.ts | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/src/build/functions/edge.ts b/src/build/functions/edge.ts index d551afda5c..18d4d4e964 100644 --- a/src/build/functions/edge.ts +++ b/src/build/functions/edge.ts @@ -1,7 +1,7 @@ import { cp, mkdir, readFile, rm, writeFile } from 'node:fs/promises' import { dirname, join } from 'node:path' -import type { Manifest, ManifestFunction } from '@netlify/edge-functions' +import type { IntegrationsConfig, Manifest, ManifestFunction } from '@netlify/edge-functions' import { glob } from 'fast-glob' import type { EdgeFunctionDefinition as NextDefinition } from 'next/dist/build/webpack/plugins/middleware-plugin.js' import { pathToRegexp } from 'path-to-regexp' @@ -160,21 +160,25 @@ const getHandlerName = ({ name }: Pick): string => const buildHandlerDefinition = ( ctx: PluginContext, { name, matchers, page }: NextDefinition, -): Array => { - const fun = getHandlerName({ name }) - const funName = name.endsWith('middleware') +): ManifestFunction & IntegrationsConfig => { + const functionHandlerName = getHandlerName({ name }) + const functionName = name.endsWith('middleware') ? 'Next.js Middleware Handler' : `Next.js Edge Handler: ${page}` const cache = name.endsWith('middleware') ? undefined : ('manual' as const) const generator = `${ctx.pluginName}@${ctx.pluginVersion}` - - return augmentMatchers(matchers, ctx).map((matcher) => ({ - function: fun, - name: funName, - pattern: matcher.regexp, + const i18nAugmentedMatchers = augmentMatchers(matchers, ctx) + const combinedEdgeHandlerRegex = i18nAugmentedMatchers + .map((matcher) => `(${matcher.regexp})`) + .join('|') + + return { + function: functionHandlerName, + name: functionName, + pattern: combinedEdgeHandlerRegex, cache, generator, - })) + } } export const clearStaleEdgeHandlers = async (ctx: PluginContext) => { @@ -183,10 +187,7 @@ export const clearStaleEdgeHandlers = async (ctx: PluginContext) => { export const createEdgeHandlers = async (ctx: PluginContext) => { const nextManifest = await ctx.getMiddlewareManifest() - const nextDefinitions = [ - ...Object.values(nextManifest.middleware), - // ...Object.values(nextManifest.functions) - ] + const nextDefinitions = [...Object.values(nextManifest.middleware)] await Promise.all(nextDefinitions.map((def) => createEdgeHandler(ctx, def))) const netlifyDefinitions = nextDefinitions.flatMap((def) => buildHandlerDefinition(ctx, def)) From 6d97dd375ad43e3ca624d1bc2d38b5cc9f298ccf Mon Sep 17 00:00:00 2001 From: Mateusz Bocian Date: Wed, 23 Apr 2025 12:59:40 -0400 Subject: [PATCH 2/3] fix: use latest edge-function types --- package-lock.json | 17 +++++++++-------- package.json | 2 +- src/build/functions/edge.ts | 4 ++-- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/package-lock.json b/package-lock.json index 7bca56715c..72d523ecfa 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13,7 +13,7 @@ "@netlify/blobs": "^8.2.0", "@netlify/build": "^32.1.0", "@netlify/edge-bundler": "^13.0.2", - "@netlify/edge-functions": "^2.11.1", + "@netlify/edge-functions": "^2.12.0", "@netlify/eslint-config-node": "^7.0.1", "@netlify/functions": "^3.0.4", "@netlify/serverless-functions-api": "^1.38.0", @@ -4210,10 +4210,11 @@ } }, "node_modules/@netlify/edge-functions": { - "version": "2.11.1", - "resolved": "https://registry.npmjs.org/@netlify/edge-functions/-/edge-functions-2.11.1.tgz", - "integrity": "sha512-pyQOTZ8a+ge5lZlE+H/UAHyuqQqtL5gE0pXrHT9mOykr3YQqnkB2hZMtx12odatZ87gHg4EA+UPyMZUbLfnXvw==", - "dev": true + "version": "2.12.0", + "resolved": "https://registry.npmjs.org/@netlify/edge-functions/-/edge-functions-2.12.0.tgz", + "integrity": "sha512-6EWKqCQvOWyM6CHOofvDglX8qkBL2xcMF2T0h7kzZRrdBvHMRgxTk6BmPlBGt8z4LubSQo6vDAb46MYNJ7ZyaA==", + "dev": true, + "license": "MIT" }, "node_modules/@netlify/eslint-config-node": { "version": "7.0.1", @@ -37804,9 +37805,9 @@ } }, "@netlify/edge-functions": { - "version": "2.11.1", - "resolved": "https://registry.npmjs.org/@netlify/edge-functions/-/edge-functions-2.11.1.tgz", - "integrity": "sha512-pyQOTZ8a+ge5lZlE+H/UAHyuqQqtL5gE0pXrHT9mOykr3YQqnkB2hZMtx12odatZ87gHg4EA+UPyMZUbLfnXvw==", + "version": "2.12.0", + "resolved": "https://registry.npmjs.org/@netlify/edge-functions/-/edge-functions-2.12.0.tgz", + "integrity": "sha512-6EWKqCQvOWyM6CHOofvDglX8qkBL2xcMF2T0h7kzZRrdBvHMRgxTk6BmPlBGt8z4LubSQo6vDAb46MYNJ7ZyaA==", "dev": true }, "@netlify/eslint-config-node": { diff --git a/package.json b/package.json index e26470da9b..d2c978e268 100644 --- a/package.json +++ b/package.json @@ -52,7 +52,7 @@ "@netlify/blobs": "^8.2.0", "@netlify/build": "^32.1.0", "@netlify/edge-bundler": "^13.0.2", - "@netlify/edge-functions": "^2.11.1", + "@netlify/edge-functions": "^2.12.0", "@netlify/eslint-config-node": "^7.0.1", "@netlify/functions": "^3.0.4", "@netlify/serverless-functions-api": "^1.38.0", diff --git a/src/build/functions/edge.ts b/src/build/functions/edge.ts index 18d4d4e964..f51e05f768 100644 --- a/src/build/functions/edge.ts +++ b/src/build/functions/edge.ts @@ -1,7 +1,7 @@ import { cp, mkdir, readFile, rm, writeFile } from 'node:fs/promises' import { dirname, join } from 'node:path' -import type { IntegrationsConfig, Manifest, ManifestFunction } from '@netlify/edge-functions' +import type { Manifest, ManifestFunction } from '@netlify/edge-functions' import { glob } from 'fast-glob' import type { EdgeFunctionDefinition as NextDefinition } from 'next/dist/build/webpack/plugins/middleware-plugin.js' import { pathToRegexp } from 'path-to-regexp' @@ -160,7 +160,7 @@ const getHandlerName = ({ name }: Pick): string => const buildHandlerDefinition = ( ctx: PluginContext, { name, matchers, page }: NextDefinition, -): ManifestFunction & IntegrationsConfig => { +): ManifestFunction => { const functionHandlerName = getHandlerName({ name }) const functionName = name.endsWith('middleware') ? 'Next.js Middleware Handler' From cc24880986ce7f6ddeac1deb0b4d4685c28a8c3f Mon Sep 17 00:00:00 2001 From: Mateusz Bocian Date: Wed, 23 Apr 2025 13:09:21 -0400 Subject: [PATCH 3/3] fix: prettier cleanup --- run-local-test.sh | 1 - tests/prepare.mjs | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/run-local-test.sh b/run-local-test.sh index 5c1951975e..108d2805fb 100755 --- a/run-local-test.sh +++ b/run-local-test.sh @@ -18,4 +18,3 @@ cd ../next.js/ git apply $RUNTIME_DIR/tests/e2e-utils.patch || git apply $RUNTIME_DIR/tests/e2e-utils-v2.patch node run-tests.js --type e2e --debug --test-pattern $1 git checkout -- test/lib/e2e-utils.ts - diff --git a/tests/prepare.mjs b/tests/prepare.mjs index 072d08e6b5..1a16797b0e 100644 --- a/tests/prepare.mjs +++ b/tests/prepare.mjs @@ -1,7 +1,7 @@ // @ts-check // this installs and builds all the fixtures // Needed to run before executing the integration tests -import { existsSync, readdirSync } from 'node:fs' +import { readdirSync } from 'node:fs' import { rm, readFile } from 'node:fs/promises' import { join } from 'node:path' import { argv } from 'node:process'