-
Notifications
You must be signed in to change notification settings - Fork 88
feat: add Generator to edge functions #2019
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 28 commits
Commits
Show all changes
38 commits
Select commit
Hold shift + click to select a range
76d4250
feat: updated funcmetadata to include edge
taty2010 bba7172
feat: add generator to edge
taty2010 a522350
chore: prettier
taty2010 9e4b2bb
Merge branch 'main' into tn/generator-edgeFunc
taty2010 3158b22
feat: refactored nextpluginversion to use within writeEdge
taty2010 ade4960
fix: updated func causing tests fails
taty2010 04b5b8f
Merge branch 'main' into tn/generator-edgeFunc
taty2010 cfebd77
feat: added testing for edge function generator
taty2010 7426594
Merge branch 'main' into tn/generator-edgeFunc
taty2010 3f0c121
chore: removed console.log
taty2010 9c55d4b
Update variable naming to match constants
taty2010 f69e2ab
fix: fixed naming
taty2010 7f89ed3
Update test/functionsMetaData.spec.ts
taty2010 1fbbe28
chore: refactoring test
taty2010 6650517
chore: added functionManifest interface within tests to catch errors
taty2010 d6e073d
chore: removed comment
taty2010 6c0fada
chore: removed comment
taty2010 530f493
Merge branch 'main' into tn/generator-edgeFunc
taty2010 98a7f1f
chore: updated naming, refactored functionality, and removed tests
taty2010 22f1962
chore: added new tests and added generator to rsc in edge
taty2010 7f6f806
Merge branch 'main' into tn/generator-edgeFunc
taty2010 fc0e015
chore: updated snapshot
taty2010 af9ceac
fix: snapshot update with most recent changes
taty2010 07f997c
fix: new tests snapshot fix
taty2010 b701ddb
fix: testing
taty2010 75b214a
fix: testing to see if tests pass after removing new test/snpshot
taty2010 8b2a424
chore: adding new tests back in
taty2010 92d7afe
Merge branch 'main' into tn/generator-edgeFunc
taty2010 0b5f70c
chore: removed string literals
taty2010 472bde3
fix: updated tests to now sort manifest data
taty2010 f0ffb8f
Merge branch 'main' into tn/generator-edgeFunc
taty2010 2dc856a
chore: renaming and adding gen to dev edge
taty2010 430e985
fix: snapshot
taty2010 3602e86
Merge branch 'main' into tn/generator-edgeFunc
taty2010 85f8f22
fix: removed snapshot testing and updated rsc tests
taty2010 0f3252e
chore: forgot to remove obsolete snapshots
taty2010 63e791d
chore: sort not needed
taty2010 bc9dae5
Merge branch 'main' into tn/generator-edgeFunc
taty2010 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,9 +13,9 @@ import { outdent } from 'outdent' | |
import { IMAGE_FUNCTION_NAME } from '../constants' | ||
|
||
import { getRequiredServerFiles, NextConfig } from './config' | ||
import { getPluginVersion } from './functionsMetaData' | ||
import { makeLocaleOptional, stripLookahead, transformCaptureGroups } from './matchers' | ||
import { RoutesManifest } from './types' | ||
|
||
// This is the format as of [email protected] | ||
interface EdgeFunctionDefinitionV1 { | ||
env: string[] | ||
|
@@ -57,12 +57,14 @@ export interface FunctionManifest { | |
name?: string | ||
path: string | ||
cache?: 'manual' | ||
generator?: string | ||
} | ||
| { | ||
function: string | ||
name?: string | ||
pattern: string | ||
cache?: 'manual' | ||
generator?: string | ||
} | ||
> | ||
layers?: Array<{ name: `https://${string}/mod.ts`; flag: string }> | ||
|
@@ -221,15 +223,17 @@ const generateEdgeFunctionMiddlewareMatchers = ({ | |
const middlewareMatcherToEdgeFunctionDefinition = ( | ||
matcher: MiddlewareMatcher, | ||
name: string, | ||
generator: string, | ||
cache?: 'manual', | ||
): { | ||
function: string | ||
name?: string | ||
pattern: string | ||
cache?: 'manual' | ||
generator?: string | ||
LekoArts marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} => { | ||
const pattern = transformCaptureGroups(stripLookahead(matcher.regexp)) | ||
return { function: name, pattern, name, cache } | ||
return { function: name, pattern, name, cache, generator } | ||
} | ||
|
||
export const cleanupEdgeFunctions = ({ | ||
|
@@ -270,6 +274,7 @@ export const writeRscDataEdgeFunction = async ({ | |
prerenderManifest?: PrerenderManifest | ||
appPathRoutesManifest?: Record<string, string> | ||
}): Promise<FunctionManifest['functions']> => { | ||
const nextjsPluginVersion = await getPluginVersion() | ||
if (!prerenderManifest || !appPathRoutesManifest) { | ||
return [] | ||
} | ||
|
@@ -300,11 +305,13 @@ export const writeRscDataEdgeFunction = async ({ | |
function: 'rsc-data', | ||
name: 'RSC data routing', | ||
path, | ||
generator: `${nextjsPluginVersion}`, | ||
taty2010 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
})), | ||
...dynamicAppDirRoutes.map((pattern) => ({ | ||
function: 'rsc-data', | ||
name: 'RSC data routing', | ||
pattern, | ||
generator: `${nextjsPluginVersion}`, | ||
taty2010 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
})), | ||
] | ||
} | ||
|
@@ -344,6 +351,8 @@ export const writeEdgeFunctions = async ({ | |
netlifyConfig: NetlifyConfig | ||
routesManifest: RoutesManifest | ||
}) => { | ||
const nextjsPluginVersion = await getPluginVersion() | ||
|
||
const manifest: FunctionManifest = { | ||
functions: [], | ||
layers: [], | ||
|
@@ -402,7 +411,9 @@ export const writeEdgeFunctions = async ({ | |
}) | ||
|
||
manifest.functions.push( | ||
...matchers.map((matcher) => middlewareMatcherToEdgeFunctionDefinition(matcher, functionName)), | ||
...matchers.map((matcher) => | ||
middlewareMatcherToEdgeFunctionDefinition(matcher, functionName, nextjsPluginVersion), | ||
), | ||
) | ||
} | ||
// Functions (i.e. not middleware, but edge SSR and API routes) | ||
|
@@ -442,6 +453,7 @@ export const writeEdgeFunctions = async ({ | |
pattern, | ||
// cache: "manual" is currently experimental, so we restrict it to sites that use experimental appDir | ||
cache: usesAppDir ? 'manual' : undefined, | ||
generator: `${nextjsPluginVersion}`, | ||
taty2010 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}) | ||
// pages-dir page routes also have a data route. If there's a match, add an entry mapping that to the function too | ||
const dataRoute = dataRoutesMap.get(edgeFunctionDefinition.page) | ||
|
@@ -451,6 +463,7 @@ export const writeEdgeFunctions = async ({ | |
name: edgeFunctionDefinition.name, | ||
pattern: dataRoute, | ||
cache: usesAppDir ? 'manual' : undefined, | ||
generator: `${nextjsPluginVersion}`, | ||
taty2010 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}) | ||
} | ||
} | ||
|
@@ -476,6 +489,7 @@ export const writeEdgeFunctions = async ({ | |
function: 'ipx', | ||
name: 'next/image handler', | ||
path: nextConfig.images.path || '/_next/image', | ||
generator: `${nextjsPluginVersion}`, | ||
taty2010 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}) | ||
|
||
manifest.layers.push({ | ||
|
@@ -494,6 +508,5 @@ export const writeEdgeFunctions = async ({ | |
This feature is in beta. Please share your feedback here: https://ntl.fyi/next-netlify-edge | ||
`) | ||
} | ||
|
||
await writeJson(join(edgeFunctionRoot, 'manifest.json'), manifest) | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.