Skip to content

Commit ae2c103

Browse files
authored
fix: clean up edge functions during build (#1588)
* fix: clean up edge functions before build * chore: format
1 parent 3ae0ee6 commit ae2c103

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

packages/runtime/src/helpers/edge.ts

+12-4
Original file line numberDiff line numberDiff line change
@@ -123,12 +123,20 @@ const writeEdgeFunction = async ({
123123
}
124124
}
125125

126+
type NetlifyPluginConstantsWithEdgeFunctions = NetlifyPluginConstants & {
127+
// Until https://github.com/netlify/build/pull/4481 lands
128+
INTERNAL_EDGE_FUNCTIONS_SRC?: string
129+
}
130+
131+
export const cleanupEdgeFunctions = async ({
132+
INTERNAL_EDGE_FUNCTIONS_SRC = '.netlify/edge-functions',
133+
}: NetlifyPluginConstantsWithEdgeFunctions) => {
134+
await emptyDir(INTERNAL_EDGE_FUNCTIONS_SRC)
135+
}
136+
126137
export const writeDevEdgeFunction = async ({
127138
INTERNAL_EDGE_FUNCTIONS_SRC = '.netlify/edge-functions',
128-
}: NetlifyPluginConstants & {
129-
// The constants type needs an update
130-
INTERNAL_EDGE_FUNCTIONS_SRC?: string
131-
}) => {
139+
}: NetlifyPluginConstantsWithEdgeFunctions) => {
132140
const manifest: FunctionManifest = {
133141
functions: [
134142
{

packages/runtime/src/index.ts

+8-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,12 @@ import {
1616
generateCustomHeaders,
1717
} from './helpers/config'
1818
import { onPreDev } from './helpers/dev'
19-
import { enableEdgeInNextConfig, writeEdgeFunctions, loadMiddlewareManifest } from './helpers/edge'
19+
import {
20+
enableEdgeInNextConfig,
21+
writeEdgeFunctions,
22+
loadMiddlewareManifest,
23+
cleanupEdgeFunctions,
24+
} from './helpers/edge'
2025
import { moveStaticPages, movePublicFiles, patchNextFiles } from './helpers/files'
2126
import { generateFunctions, setupImageFunction, generatePagesResolver } from './helpers/functions'
2227
import { generateRedirects, generateStaticRedirects } from './helpers/redirects'
@@ -81,6 +86,8 @@ const plugin: NetlifyPlugin = {
8186
},
8287
)
8388

89+
await cleanupEdgeFunctions(constants)
90+
8491
const middlewareManifest = await loadMiddlewareManifest(netlifyConfig)
8592

8693
let usingEdge = false

0 commit comments

Comments
 (0)