Add errors to cloudflare/vercel adapters when no output config (#4068)
This commit is contained in:
parent
57770bbae2
commit
54b33d50fd
15 changed files with 145 additions and 8 deletions
6
.changeset/giant-dolls-reply.md
Normal file
6
.changeset/giant-dolls-reply.md
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
---
|
||||||
|
'@astrojs/cloudflare': minor
|
||||||
|
'@astrojs/vercel': minor
|
||||||
|
---
|
||||||
|
|
||||||
|
Add explicit errors when omitting output config
|
|
@ -24,7 +24,8 @@
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "astro-scripts build \"src/**/*.ts\" && tsc",
|
"build": "astro-scripts build \"src/**/*.ts\" && tsc",
|
||||||
"build:ci": "astro-scripts build \"src/**/*.ts\"",
|
"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": {
|
"dependencies": {
|
||||||
"esbuild": "^0.14.42"
|
"esbuild": "^0.14.42"
|
||||||
|
|
|
@ -23,12 +23,10 @@ export default function createIntegration(): AstroIntegration {
|
||||||
_config = config;
|
_config = config;
|
||||||
|
|
||||||
if (config.output === 'static') {
|
if (config.output === 'static') {
|
||||||
console.warn(
|
throw new Error(`
|
||||||
`[@astrojs/cloudflare] \`output: "server"\` is required to use this adapter.`
|
[@astrojs/cloudflare] \`output: "server"\` is required to use this adapter. Otherwise, this adapter is not necessary to deploy a static site to Cloudflare.
|
||||||
);
|
|
||||||
console.warn(
|
`);
|
||||||
`[@astrojs/cloudflare] Otherwise, this adapter is not required to deploy a static site to Cloudflare.`
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
'astro:build:start': ({ buildConfig }) => {
|
'astro:build:start': ({ buildConfig }) => {
|
||||||
|
|
6
packages/integrations/cloudflare/test/fixtures/no-output/astro.config.mjs
vendored
Normal file
6
packages/integrations/cloudflare/test/fixtures/no-output/astro.config.mjs
vendored
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
import { defineConfig } from 'astro/config';
|
||||||
|
import cloudflare from '@astrojs/cloudflare';
|
||||||
|
|
||||||
|
export default defineConfig({
|
||||||
|
adapter: cloudflare()
|
||||||
|
});
|
9
packages/integrations/cloudflare/test/fixtures/no-output/package.json
vendored
Normal file
9
packages/integrations/cloudflare/test/fixtures/no-output/package.json
vendored
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
{
|
||||||
|
"name": "@test/astro-cloudflare-no-output",
|
||||||
|
"version": "0.0.0",
|
||||||
|
"private": true,
|
||||||
|
"dependencies": {
|
||||||
|
"@astrojs/cloudflare": "workspace:*",
|
||||||
|
"astro": "workspace:*"
|
||||||
|
}
|
||||||
|
}
|
25
packages/integrations/cloudflare/test/no-output.test.js
Normal file
25
packages/integrations/cloudflare/test/no-output.test.js
Normal 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"`);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
10
packages/integrations/cloudflare/test/test-utils.js
Normal file
10
packages/integrations/cloudflare/test/test-utils.js
Normal 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);
|
||||||
|
}
|
|
@ -39,7 +39,8 @@
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "astro-scripts build \"src/**/*.ts\" && tsc",
|
"build": "astro-scripts build \"src/**/*.ts\" && tsc",
|
||||||
"build:ci": "astro-scripts build \"src/**/*.ts\"",
|
"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": {
|
"dependencies": {
|
||||||
"@astrojs/webapi": "^0.12.0",
|
"@astrojs/webapi": "^0.12.0",
|
||||||
|
|
|
@ -28,6 +28,13 @@ export default function vercelEdge(): AstroIntegration {
|
||||||
'astro:config:done': ({ setAdapter, config }) => {
|
'astro:config:done': ({ setAdapter, config }) => {
|
||||||
setAdapter(getAdapter());
|
setAdapter(getAdapter());
|
||||||
_config = config;
|
_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 }) => {
|
'astro:build:start': async ({ buildConfig }) => {
|
||||||
buildConfig.serverEntry = serverEntry = 'entry.js';
|
buildConfig.serverEntry = serverEntry = 'entry.js';
|
||||||
|
|
6
packages/integrations/vercel/test/fixtures/no-output/astro.config.mjs
vendored
Normal file
6
packages/integrations/vercel/test/fixtures/no-output/astro.config.mjs
vendored
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
import { defineConfig } from 'astro/config';
|
||||||
|
import vercel from '@astrojs/vercel/serverless';
|
||||||
|
|
||||||
|
export default defineConfig({
|
||||||
|
adapter: vercel()
|
||||||
|
});
|
9
packages/integrations/vercel/test/fixtures/no-output/package.json
vendored
Normal file
9
packages/integrations/vercel/test/fixtures/no-output/package.json
vendored
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
{
|
||||||
|
"name": "@test/astro-vercel-no-output",
|
||||||
|
"version": "0.0.0",
|
||||||
|
"private": true,
|
||||||
|
"dependencies": {
|
||||||
|
"@astrojs/vercel": "workspace:*",
|
||||||
|
"astro": "workspace:*"
|
||||||
|
}
|
||||||
|
}
|
8
packages/integrations/vercel/test/fixtures/no-output/src/pages/index.astro
vendored
Normal file
8
packages/integrations/vercel/test/fixtures/no-output/src/pages/index.astro
vendored
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>testing</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h1>testing</h1>
|
||||||
|
</body>
|
||||||
|
</html>
|
25
packages/integrations/vercel/test/no-output.test.js
Normal file
25
packages/integrations/vercel/test/no-output.test.js
Normal 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"`);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
10
packages/integrations/vercel/test/test-utils.js
Normal file
10
packages/integrations/vercel/test/test-utils.js
Normal 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);
|
||||||
|
}
|
|
@ -2039,6 +2039,14 @@ importers:
|
||||||
astro: link:../../astro
|
astro: link:../../astro
|
||||||
astro-scripts: link:../../../scripts
|
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:
|
packages/integrations/deno:
|
||||||
specifiers:
|
specifiers:
|
||||||
astro: workspace:*
|
astro: workspace:*
|
||||||
|
@ -2431,6 +2439,14 @@ importers:
|
||||||
astro: link:../../astro
|
astro: link:../../astro
|
||||||
astro-scripts: link:../../../scripts
|
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:
|
packages/integrations/vue:
|
||||||
specifiers:
|
specifiers:
|
||||||
'@vitejs/plugin-vue': ^3.0.0
|
'@vitejs/plugin-vue': ^3.0.0
|
||||||
|
|
Loading…
Reference in a new issue