Skip to content

Commit

Permalink
Use .mjs extension when building for netlify edge and vercel serverle…
Browse files Browse the repository at this point in the history
…ss (#6317)
  • Loading branch information
bluwy authored Feb 21, 2023
1 parent 2a6d09e commit 2eb73cb
Show file tree
Hide file tree
Showing 13 changed files with 119 additions and 3 deletions.
6 changes: 6 additions & 0 deletions .changeset/eighty-rockets-crash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@astrojs/netlify': patch
'@astrojs/vercel': patch
---

Use .mjs extension when building to support CJS environments
2 changes: 1 addition & 1 deletion packages/integrations/netlify/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"build:ci": "astro-scripts build \"src/**/*.ts\"",
"dev": "astro-scripts dev \"src/**/*.ts\"",
"test-fn": "mocha --exit --timeout 20000 test/functions/",
"test-edge": "deno test --allow-run --allow-read --allow-net ./test/edge-functions/",
"test-edge": "deno test --allow-run --allow-read --allow-net --allow-env ./test/edge-functions/",
"test": "npm run test-fn"
},
"dependencies": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ export function netlifyEdgeFunctions({ dist }: NetlifyEdgeFunctionsOptions = {})
build: {
client: outDir,
server: new URL('./.netlify/edge-functions/', config.root),
serverEntry: 'entry.js',
serverEntry: 'entry.mjs',
},
});
},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { defineConfig } from 'astro/config';
import { netlifyEdgeFunctions } from '@astrojs/netlify';

export default defineConfig({
adapter: netlifyEdgeFunctions({
dist: new URL('./dist/', import.meta.url),
}),
output: 'server',
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "@test/astro-netlify-prerender",
"version": "0.0.0",
"private": true,
"dependencies": {
"@astrojs/netlify": "workspace:*",
"astro": "workspace:*"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
export const prerender = true
---

<html>
<head>
<title>testing</title>
</head>
<body>
<h1>testing</h1>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// @ts-ignore
import { runBuild } from './test-utils.ts';
// @ts-ignore
import { assertEquals } from './deps.ts';

// @ts-ignore
Deno.test({
name: 'Prerender',
async fn() {
let close = await runBuild('./fixtures/prerender/');
const { default: handler } = await import(
'./fixtures/prerender/.netlify/edge-functions/entry.mjs'
);
const response = await handler(new Request('http://example.com/index.html'));
assertEquals(response, undefined, 'No response because this is an asset');
await close();
},
});
2 changes: 1 addition & 1 deletion packages/integrations/vercel/src/serverless/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export default function vercelServerless({
updateConfig({
outDir,
build: {
serverEntry: 'entry.js',
serverEntry: 'entry.mjs',
client: new URL('./static/', outDir),
server: new URL('./dist/', config.root),
},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { defineConfig } from 'astro/config';
import vercel from '@astrojs/vercel/serverless';

export default defineConfig({
adapter: vercel(),
output: 'server'
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "@test/astro-vercel-serverless-prerender",
"version": "0.0.0",
"private": true,
"dependencies": {
"@astrojs/vercel": "workspace:*",
"astro": "workspace:*"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
export const prerender = true
---

<html>
<head>
<title>testing</title>
</head>
<body>
<h1>testing</h1>
</body>
</html>
18 changes: 18 additions & 0 deletions packages/integrations/vercel/test/serverless-prerender.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { loadFixture } from './test-utils.js';
import { expect } from 'chai';

describe('Serverless prerender', () => {
/** @type {import('./test-utils').Fixture} */
let fixture;

before(async () => {
fixture = await loadFixture({
root: './fixtures/serverless-prerender/',
});
});

it('build successful', async () => {
await fixture.build();
expect(fixture.readFile('/static/index.html')).to.be.ok;
});
});
16 changes: 16 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 2eb73cb

Please sign in to comment.