Skip to content

Commit

Permalink
feat: add generator field to edge function manifest (#304)
Browse files Browse the repository at this point in the history
  • Loading branch information
khendrikse committed Feb 16, 2023
1 parent e4e0e52 commit 5a59fcc
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
1 change: 1 addition & 0 deletions node/declaration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ interface BaseDeclaration {
cache?: string
function: string
name?: string
generator?: string
}

type DeclarationWithPath = BaseDeclaration & {
Expand Down
25 changes: 25 additions & 0 deletions node/manifest.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,31 @@ test('Generates a manifest with display names', () => {
expect(manifest.bundler_version).toBe(env.npm_package_version as string)
})

test('Generates a manifest with a generator field', () => {
const functions = [
{ name: 'func-1', path: '/path/to/func-1.ts' },
{ name: 'func-2', path: '/path/to/func-2.ts' },
{ name: 'func-3', path: '/path/to/func-3.ts' },
]

const declarations = [
{ function: 'func-1', generator: '@netlify/fake-plugin@1.0.0', path: '/f1/*' },
{ function: 'func-2', path: '/f2/*' },
{ function: 'func-3', generator: '@netlify/fake-plugin@1.0.0', cache: 'manual', path: '/f3' },
]
const manifest = generateManifest({ bundles: [], declarations, functions })

const expectedRoutes = [
{ function: 'func-1', generator: '@netlify/fake-plugin@1.0.0', pattern: '^/f1/.*/?$' },
{ function: 'func-2', pattern: '^/f2/.*/?$' },
]
const expectedPostCacheRoutes = [{ function: 'func-3', generator: '@netlify/fake-plugin@1.0.0', pattern: '^/f3/?$' }]

expect(manifest.routes).toEqual(expectedRoutes)
expect(manifest.post_cache_routes).toEqual(expectedPostCacheRoutes)
expect(manifest.bundler_version).toBe(env.npm_package_version as string)
})

test('Generates a manifest with excluded paths and patterns', () => {
const functions = [
{ name: 'func-1', path: '/path/to/func-1.ts' },
Expand Down
3 changes: 3 additions & 0 deletions node/manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ interface Route {
function: string
name?: string
pattern: string
generator?: string
}
interface EdgeFunctionConfig {
excluded_patterns: string[]
Expand Down Expand Up @@ -47,6 +48,7 @@ interface Route {
function: string
name?: string
pattern: string
generator?: string
}

// JavaScript regular expressions are converted to strings with leading and
Expand Down Expand Up @@ -103,6 +105,7 @@ const generateManifest = ({
function: func.name,
name: declaration.name,
pattern: serializePattern(pattern),
generator: declaration.generator,
}
const excludedPattern = getExcludedRegularExpression(
declaration,
Expand Down

0 comments on commit 5a59fcc

Please sign in to comment.