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

This commit is contained in:
Matthew Phillips 2022-07-27 11:50:48 -04:00 committed by GitHub
parent 57770bbae2
commit 54b33d50fd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
15 changed files with 145 additions and 8 deletions

View file

@ -0,0 +1,6 @@
---
'@astrojs/cloudflare': minor
'@astrojs/vercel': minor
---
Add explicit errors when omitting output config

View file

@ -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"

View file

@ -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 }) => {

View file

@ -0,0 +1,6 @@
import { defineConfig } from 'astro/config';
import cloudflare from '@astrojs/cloudflare';
export default defineConfig({
adapter: cloudflare()
});

View file

@ -0,0 +1,9 @@
{
"name": "@test/astro-cloudflare-no-output",
"version": "0.0.0",
"private": true,
"dependencies": {
"@astrojs/cloudflare": "workspace:*",
"astro": "workspace:*"
}
}

View file

@ -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"`);
});
});

View file

@ -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);
}

View file

@ -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",

View file

@ -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';

View file

@ -0,0 +1,6 @@
import { defineConfig } from 'astro/config';
import vercel from '@astrojs/vercel/serverless';
export default defineConfig({
adapter: vercel()
});

View file

@ -0,0 +1,9 @@
{
"name": "@test/astro-vercel-no-output",
"version": "0.0.0",
"private": true,
"dependencies": {
"@astrojs/vercel": "workspace:*",
"astro": "workspace:*"
}
}

View file

@ -0,0 +1,8 @@
<html>
<head>
<title>testing</title>
</head>
<body>
<h1>testing</h1>
</body>
</html>

View file

@ -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"`);
});
});

View file

@ -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);
}

View file

@ -2039,6 +2039,14 @@ importers:
astro: link:../../astro
astro-scripts: link:../../../scripts
packages/integrations/cloudflare/test/fixtures/no-output:
specifiers:
'@astrojs/cloudflare': workspace:*
astro: workspace:*
dependencies:
'@astrojs/cloudflare': link:../../..
astro: link:../../../../../astro
packages/integrations/deno:
specifiers:
astro: workspace:*
@ -2431,6 +2439,14 @@ importers:
astro: link:../../astro
astro-scripts: link:../../../scripts
packages/integrations/vercel/test/fixtures/no-output:
specifiers:
'@astrojs/vercel': workspace:*
astro: workspace:*
dependencies:
'@astrojs/vercel': link:../../..
astro: link:../../../../../astro
packages/integrations/vue:
specifiers:
'@vitejs/plugin-vue': ^3.0.0