Skip to content

Commit

Permalink
Allow an adapter to export default (withastro#3022)
Browse files Browse the repository at this point in the history
* Allow an adapter to export default

* Adds a changeset
  • Loading branch information
matthewp committed Apr 7, 2022
1 parent c1a759b commit 8c04ff1
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 5 deletions.
6 changes: 6 additions & 0 deletions .changeset/forty-boats-remain.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'astro': patch
'@astrojs/vercel': patch
---

Allows adapters to export default
10 changes: 8 additions & 2 deletions packages/astro/src/core/build/vite-plugin-ssr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')}
`
: ''
}
Expand Down
2 changes: 1 addition & 1 deletion packages/integrations/vercel/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export function getAdapter(): AstroAdapter {
return {
name: '@astrojs/vercel',
serverEntrypoint: '@astrojs/vercel/server-entrypoint',
exports: ['_default'],
exports: ['default'],
};
}

Expand Down
4 changes: 2 additions & 2 deletions packages/integrations/vercel/src/server-entrypoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -30,5 +30,5 @@ export const createExports = (manifest: SSRManifest) => {
await setResponse(res, await app.render(request));
};

return { _default };
return { 'default': handler };
};

0 comments on commit 8c04ff1

Please sign in to comment.