From 05cf1a506702f06ed48cd26cbe5ca108839ff0e6 Mon Sep 17 00:00:00 2001 From: Matthew Phillips Date: Tue, 19 Apr 2022 13:13:52 -0400 Subject: [PATCH] Adjustments for Netlify Edge Functions (#3150) * Adjustments for Netlify Edge Functions * Adds a changeset --- .changeset/small-radios-whisper.md | 5 +++++ .../netlify/src/integration-edge-functions.ts | 10 +++++++--- 2 files changed, 12 insertions(+), 3 deletions(-) create mode 100644 .changeset/small-radios-whisper.md diff --git a/.changeset/small-radios-whisper.md b/.changeset/small-radios-whisper.md new file mode 100644 index 000000000..2403fa3ce --- /dev/null +++ b/.changeset/small-radios-whisper.md @@ -0,0 +1,5 @@ +--- +'@astrojs/netlify': patch +--- + +Outputs manifest.json in correct folder for Netlify Edge Functions diff --git a/packages/integrations/netlify/src/integration-edge-functions.ts b/packages/integrations/netlify/src/integration-edge-functions.ts index c607a5493..b059ac886 100644 --- a/packages/integrations/netlify/src/integration-edge-functions.ts +++ b/packages/integrations/netlify/src/integration-edge-functions.ts @@ -43,7 +43,7 @@ async function createEdgeManifest(routes: RouteData[], entryFile: string, dir: U } else { functions.push({ function: entryFile, - pattern: route.pattern.source, + pattern: route.pattern.toString(), }); } } @@ -53,7 +53,10 @@ async function createEdgeManifest(routes: RouteData[], entryFile: string, dir: U version: 1, }; - const manifestURL = new URL('./manifest.json', dir); + const baseDir = new URL('./.netlify/edge-functions/', dir) + await fs.promises.mkdir(baseDir, { recursive: true }); + + const manifestURL = new URL('./manifest.json', baseDir); const _manifest = JSON.stringify(manifest, null, ' '); await fs.promises.writeFile(manifestURL, _manifest, 'utf-8'); } @@ -79,6 +82,7 @@ export function netlifyEdgeFunctions({ dist }: NetlifyEdgeFunctionsOptions = {}) entryFile = buildConfig.serverEntry.replace(/\.m?js/, ''); buildConfig.client = _config.outDir; buildConfig.server = new URL('./edge-functions/', _config.outDir); + buildConfig.serverEntry = 'entry.js'; }, 'astro:build:setup': ({ vite, target }) => { if (target === 'server') { @@ -88,7 +92,7 @@ export function netlifyEdgeFunctions({ dist }: NetlifyEdgeFunctionsOptions = {}) } }, 'astro:build:done': async ({ routes, dir }) => { - await createEdgeManifest(routes, entryFile, new URL('./edge-functions/', dir)); + await createEdgeManifest(routes, entryFile, _config.root); }, }, };