Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add errors to cloudflare/vercel adapters when no output config #4068

Merged
merged 1 commit into from
Jul 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/giant-dolls-reply.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@astrojs/cloudflare': minor
'@astrojs/vercel': minor
---

Add explicit errors when omitting output config
tony-sull marked this conversation as resolved.
Show resolved Hide resolved
3 changes: 2 additions & 1 deletion packages/integrations/cloudflare/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
"scripts": {
"build": "astro-scripts build \"src/**/*.ts\" && tsc",
"build:ci": "astro-scripts build \"src/**/*.ts\"",
"dev": "astro-scripts dev \"src/**/*.ts\""
"dev": "astro-scripts dev \"src/**/*.ts\"",
"test": "mocha --exit --timeout 20000 test/"
},
"dependencies": {
"esbuild": "^0.14.42"
Expand Down
10 changes: 4 additions & 6 deletions packages/integrations/cloudflare/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,10 @@ export default function createIntegration(): AstroIntegration {
_config = config;

if (config.output === 'static') {
console.warn(
`[@astrojs/cloudflare] \`output: "server"\` is required to use this adapter.`
);
console.warn(
`[@astrojs/cloudflare] Otherwise, this adapter is not required to deploy a static site to Cloudflare.`
);
throw new Error(`
[@astrojs/cloudflare] \`output: "server"\` is required to use this adapter. Otherwise, this adapter is not necessary to deploy a static site to Cloudflare.

`);
}
},
'astro:build:start': ({ buildConfig }) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { defineConfig } from 'astro/config';
import cloudflare from '@astrojs/cloudflare';

export default defineConfig({
adapter: cloudflare()
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "@test/astro-cloudflare-no-output",
"version": "0.0.0",
"private": true,
"dependencies": {
"@astrojs/cloudflare": "workspace:*",
"astro": "workspace:*"
}
}
25 changes: 25 additions & 0 deletions packages/integrations/cloudflare/test/no-output.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { loadFixture } from './test-utils.js';
import { expect } from 'chai';

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

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

it('throws during the build', async () => {
let error = undefined;
try {
await fixture.build();
} catch(err) {
error = err;
}
expect(error).to.not.be.equal(undefined);
expect(error.message).to.include(`output: "server"`);
});
});

10 changes: 10 additions & 0 deletions packages/integrations/cloudflare/test/test-utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { loadFixture as baseLoadFixture } from '../../../astro/test/test-utils.js';

export { fixLineEndings } from '../../../astro/test/test-utils.js';

export function loadFixture(config) {
if (config?.root) {
config.root = new URL(config.root, import.meta.url);
}
return baseLoadFixture(config);
}
3 changes: 2 additions & 1 deletion packages/integrations/vercel/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@
"scripts": {
"build": "astro-scripts build \"src/**/*.ts\" && tsc",
"build:ci": "astro-scripts build \"src/**/*.ts\"",
"dev": "astro-scripts dev \"src/**/*.ts\""
"dev": "astro-scripts dev \"src/**/*.ts\"",
"test": "mocha --exit --timeout 20000 test/"
},
"dependencies": {
"@astrojs/webapi": "^0.12.0",
Expand Down
7 changes: 7 additions & 0 deletions packages/integrations/vercel/src/serverless/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ export default function vercelEdge(): AstroIntegration {
'astro:config:done': ({ setAdapter, config }) => {
setAdapter(getAdapter());
_config = config;

if(config.output === 'static') {
throw new Error(`
[@astrojs/vercel] \`output: "server"\` is required to use the serverless adapter.

`);
}
},
'astro:build:start': async ({ buildConfig }) => {
buildConfig.serverEntry = serverEntry = 'entry.js';
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { defineConfig } from 'astro/config';
import vercel from '@astrojs/vercel/serverless';

export default defineConfig({
adapter: vercel()
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "@test/astro-vercel-no-output",
"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,8 @@
<html>
<head>
<title>testing</title>
</head>
<body>
<h1>testing</h1>
</body>
</html>
25 changes: 25 additions & 0 deletions packages/integrations/vercel/test/no-output.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { loadFixture } from './test-utils.js';
import { expect } from 'chai';

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

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

it('throws during the build', async () => {
let error = undefined;
try {
await fixture.build();
} catch(err) {
error = err;
}
expect(error).to.not.be.equal(undefined);
expect(error.message).to.include(`output: "server"`);
});
});

10 changes: 10 additions & 0 deletions packages/integrations/vercel/test/test-utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { loadFixture as baseLoadFixture } from '../../../astro/test/test-utils.js';

export { fixLineEndings } from '../../../astro/test/test-utils.js';

export function loadFixture(config) {
if (config?.root) {
config.root = new URL(config.root, import.meta.url);
}
return baseLoadFixture(config);
}
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.