Use .mjs extension when building for netlify edge and vercel serverless (#6317)
This commit is contained in:
parent
2a6d09e5d2
commit
2eb73cb9d1
13 changed files with 119 additions and 3 deletions
6
.changeset/eighty-rockets-crash.md
Normal file
6
.changeset/eighty-rockets-crash.md
Normal file
|
@ -0,0 +1,6 @@
|
|||
---
|
||||
'@astrojs/netlify': patch
|
||||
'@astrojs/vercel': patch
|
||||
---
|
||||
|
||||
Use .mjs extension when building to support CJS environments
|
|
@ -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": {
|
||||
|
|
|
@ -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',
|
||||
},
|
||||
});
|
||||
},
|
||||
|
|
|
@ -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',
|
||||
})
|
|
@ -0,0 +1,9 @@
|
|||
{
|
||||
"name": "@test/astro-netlify-prerender",
|
||||
"version": "0.0.0",
|
||||
"private": true,
|
||||
"dependencies": {
|
||||
"@astrojs/netlify": "workspace:*",
|
||||
"astro": "workspace:*"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
---
|
||||
export const prerender = true
|
||||
---
|
||||
|
||||
<html>
|
||||
<head>
|
||||
<title>testing</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>testing</h1>
|
||||
</body>
|
||||
</html>
|
|
@ -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();
|
||||
},
|
||||
});
|
|
@ -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),
|
||||
},
|
||||
|
|
7
packages/integrations/vercel/test/fixtures/serverless-prerender/astro.config.mjs
vendored
Normal file
7
packages/integrations/vercel/test/fixtures/serverless-prerender/astro.config.mjs
vendored
Normal file
|
@ -0,0 +1,7 @@
|
|||
import { defineConfig } from 'astro/config';
|
||||
import vercel from '@astrojs/vercel/serverless';
|
||||
|
||||
export default defineConfig({
|
||||
adapter: vercel(),
|
||||
output: 'server'
|
||||
});
|
9
packages/integrations/vercel/test/fixtures/serverless-prerender/package.json
vendored
Normal file
9
packages/integrations/vercel/test/fixtures/serverless-prerender/package.json
vendored
Normal file
|
@ -0,0 +1,9 @@
|
|||
{
|
||||
"name": "@test/astro-vercel-serverless-prerender",
|
||||
"version": "0.0.0",
|
||||
"private": true,
|
||||
"dependencies": {
|
||||
"@astrojs/vercel": "workspace:*",
|
||||
"astro": "workspace:*"
|
||||
}
|
||||
}
|
12
packages/integrations/vercel/test/fixtures/serverless-prerender/src/pages/index.astro
vendored
Normal file
12
packages/integrations/vercel/test/fixtures/serverless-prerender/src/pages/index.astro
vendored
Normal file
|
@ -0,0 +1,12 @@
|
|||
---
|
||||
export const prerender = true
|
||||
---
|
||||
|
||||
<html>
|
||||
<head>
|
||||
<title>testing</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>testing</h1>
|
||||
</body>
|
||||
</html>
|
|
@ -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;
|
||||
});
|
||||
});
|
|
@ -3096,6 +3096,14 @@ importers:
|
|||
react: 18.2.0
|
||||
react-dom: 18.2.0_react@18.2.0
|
||||
|
||||
packages/integrations/netlify/test/edge-functions/fixtures/prerender:
|
||||
specifiers:
|
||||
'@astrojs/netlify': workspace:*
|
||||
astro: workspace:*
|
||||
dependencies:
|
||||
'@astrojs/netlify': link:../../../..
|
||||
astro: link:../../../../../../astro
|
||||
|
||||
packages/integrations/netlify/test/edge-functions/fixtures/root-dynamic:
|
||||
specifiers:
|
||||
'@astrojs/netlify': workspace:*
|
||||
|
@ -3399,6 +3407,14 @@ importers:
|
|||
'@astrojs/vercel': link:../../..
|
||||
astro: link:../../../../../astro
|
||||
|
||||
packages/integrations/vercel/test/fixtures/serverless-prerender:
|
||||
specifiers:
|
||||
'@astrojs/vercel': workspace:*
|
||||
astro: workspace:*
|
||||
dependencies:
|
||||
'@astrojs/vercel': link:../../..
|
||||
astro: link:../../../../../astro
|
||||
|
||||
packages/integrations/vue:
|
||||
specifiers:
|
||||
'@types/chai': ^4.3.3
|
||||
|
|
Loading…
Reference in a new issue