Skip to content

Commit

Permalink
Adjustments for Netlify Edge Functions (withastro#3150)
Browse files Browse the repository at this point in the history
* Adjustments for Netlify Edge Functions

* Adds a changeset
  • Loading branch information
matthewp authored Apr 19, 2022
1 parent 44e294c commit 05cf1a5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/small-radios-whisper.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@astrojs/netlify': patch
---

Outputs manifest.json in correct folder for Netlify Edge Functions
10 changes: 7 additions & 3 deletions packages/integrations/netlify/src/integration-edge-functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
});
}
}
Expand All @@ -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');
}
Expand All @@ -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') {
Expand All @@ -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);
},
},
};
Expand Down

0 comments on commit 05cf1a5

Please sign in to comment.