Adjustments for Netlify Edge Functions (#3150)

* Adjustments for Netlify Edge Functions

* Adds a changeset
This commit is contained in:
Matthew Phillips 2022-04-19 13:13:52 -04:00 committed by GitHub
parent 44e294c9cb
commit 05cf1a5067
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 3 deletions

View file

@ -0,0 +1,5 @@
---
'@astrojs/netlify': patch
---
Outputs manifest.json in correct folder for Netlify Edge Functions

View file

@ -43,7 +43,7 @@ async function createEdgeManifest(routes: RouteData[], entryFile: string, dir: U
} else { } else {
functions.push({ functions.push({
function: entryFile, 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, 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, ' '); const _manifest = JSON.stringify(manifest, null, ' ');
await fs.promises.writeFile(manifestURL, _manifest, 'utf-8'); await fs.promises.writeFile(manifestURL, _manifest, 'utf-8');
} }
@ -79,6 +82,7 @@ export function netlifyEdgeFunctions({ dist }: NetlifyEdgeFunctionsOptions = {})
entryFile = buildConfig.serverEntry.replace(/\.m?js/, ''); entryFile = buildConfig.serverEntry.replace(/\.m?js/, '');
buildConfig.client = _config.outDir; buildConfig.client = _config.outDir;
buildConfig.server = new URL('./edge-functions/', _config.outDir); buildConfig.server = new URL('./edge-functions/', _config.outDir);
buildConfig.serverEntry = 'entry.js';
}, },
'astro:build:setup': ({ vite, target }) => { 'astro:build:setup': ({ vite, target }) => {
if (target === 'server') { if (target === 'server') {
@ -88,7 +92,7 @@ export function netlifyEdgeFunctions({ dist }: NetlifyEdgeFunctionsOptions = {})
} }
}, },
'astro:build:done': async ({ routes, dir }) => { 'astro:build:done': async ({ routes, dir }) => {
await createEdgeManifest(routes, entryFile, new URL('./edge-functions/', dir)); await createEdgeManifest(routes, entryFile, _config.root);
}, },
}, },
}; };