Skip to content

Commit

Permalink
feat: support ef excluded patterns (#5366)
Browse files Browse the repository at this point in the history
* feat: support ef excluded patterns

* fix: sync shrinkwrap

* fix: revert changes to package.json - let renovate handle this

* refactor: make more readable

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
  • Loading branch information
Skn0tt and kodiakhq[bot] authored Jan 12, 2023
1 parent b5efce8 commit 780d872
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/lib/edge-functions/registry.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,15 @@ export class EdgeFunctionsRegistry {
...route,
pattern: new RegExp(route.pattern),
}))
const functionNames = routes.filter(({ pattern }) => pattern.test(urlPath)).map((route) => route.function)
const functionNames = routes
.filter(({ pattern }) => pattern.test(urlPath))
.filter(({ function: name }) => {
const isExcluded = manifest.function_config[name]?.excluded_patterns.some((pattern) =>
new RegExp(pattern).test(urlPath),
)
return !isExcluded
})
.map((route) => route.function)
const orphanedDeclarations = await this.matchURLPathAgainstOrphanedDeclarations(urlPath)

return { functionNames, orphanedDeclarations }
Expand Down
32 changes: 32 additions & 0 deletions tests/integration/100.command.dev.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -726,6 +726,38 @@ test('should respect in-source configuration from edge functions', async (t) =>
})
})

test('should respect excluded paths', async (t) => {
await withSiteBuilder('site-with-excluded-path', async (builder) => {
const publicDir = 'public'
await builder
.withNetlifyToml({
config: {
build: {
publish: publicDir,
edge_functions: 'netlify/edge-functions',
},
},
})
.withEdgeFunction({
config: { path: '/*', excludedPath: '/static/*' },
handler: () => new Response('Hello world'),
name: 'hello',
})

await builder.buildAsync()

await withDevServer({ cwd: builder.directory }, async ({ port }) => {
const res1 = await got(`http://localhost:${port}/foo`, { throwHttpErrors: false })

t.is(res1.statusCode, 200)
t.is(res1.body, 'Hello world')

const res2 = await got(`http://localhost:${port}/static/foo`, { throwHttpErrors: false })
t.is(res2.statusCode, 404)
})
})
})

test('should respect in-source configuration from internal edge functions', async (t) => {
await withSiteBuilder('site-with-internal-edge-functions', async (builder) => {
const publicDir = 'public'
Expand Down

1 comment on commit 780d872

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📊 Benchmark results

  • Package size: 260 MB

Please sign in to comment.