Allow an adapter to export default (#3022)

* Allow an adapter to export default

* Adds a changeset
This commit is contained in:
Matthew Phillips 2022-04-07 13:21:56 -04:00 committed by GitHub
parent c1a759b5d2
commit 8c04ff1f0b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 17 additions and 5 deletions

View file

@ -0,0 +1,6 @@
---
'astro': patch
'@astrojs/vercel': patch
---
Allows adapters to export default

View file

@ -45,8 +45,14 @@ const _args = ${adapter.args ? JSON.stringify(adapter.args) : 'undefined'};
${
adapter.exports
? `const _exports = adapter.createExports(_manifest, _args);
${adapter.exports.map((name) => `export const ${name} = _exports['${name}'];`).join('\n')}
${adapter.exports.includes('_default') ? `export default _default` : ''}
${adapter.exports.map((name) => {
if(name === 'default') {
return `const _default = _exports['default'];
export { _default as default };`;
} else {
return `export const ${name} = _exports['${name}'];`
}
}).join('\n')}
`
: ''
}

View file

@ -13,7 +13,7 @@ export function getAdapter(): AstroAdapter {
return {
name: '@astrojs/vercel',
serverEntrypoint: '@astrojs/vercel/server-entrypoint',
exports: ['_default'],
exports: ['default'],
};
}

View file

@ -12,7 +12,7 @@ polyfill(globalThis, {
export const createExports = (manifest: SSRManifest) => {
const app = new App(manifest);
const _default = async (req: IncomingMessage, res: ServerResponse) => {
const handler = async (req: IncomingMessage, res: ServerResponse) => {
let request: Request;
try {
@ -30,5 +30,5 @@ export const createExports = (manifest: SSRManifest) => {
await setResponse(res, await app.render(request));
};
return { _default };
return { 'default': handler };
};