diff --git a/.changeset/giant-dolls-reply.md b/.changeset/giant-dolls-reply.md new file mode 100644 index 000000000..934967b7e --- /dev/null +++ b/.changeset/giant-dolls-reply.md @@ -0,0 +1,6 @@ +--- +'@astrojs/cloudflare': minor +'@astrojs/vercel': minor +--- + +Add explicit errors when omitting output config diff --git a/packages/integrations/cloudflare/package.json b/packages/integrations/cloudflare/package.json index 26c4fb30d..64a9e65a0 100644 --- a/packages/integrations/cloudflare/package.json +++ b/packages/integrations/cloudflare/package.json @@ -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" diff --git a/packages/integrations/cloudflare/src/index.ts b/packages/integrations/cloudflare/src/index.ts index 29341453c..37faf690e 100644 --- a/packages/integrations/cloudflare/src/index.ts +++ b/packages/integrations/cloudflare/src/index.ts @@ -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 }) => { diff --git a/packages/integrations/cloudflare/test/fixtures/no-output/astro.config.mjs b/packages/integrations/cloudflare/test/fixtures/no-output/astro.config.mjs new file mode 100644 index 000000000..b90fd5b24 --- /dev/null +++ b/packages/integrations/cloudflare/test/fixtures/no-output/astro.config.mjs @@ -0,0 +1,6 @@ +import { defineConfig } from 'astro/config'; +import cloudflare from '@astrojs/cloudflare'; + +export default defineConfig({ + adapter: cloudflare() +}); diff --git a/packages/integrations/cloudflare/test/fixtures/no-output/package.json b/packages/integrations/cloudflare/test/fixtures/no-output/package.json new file mode 100644 index 000000000..569c30890 --- /dev/null +++ b/packages/integrations/cloudflare/test/fixtures/no-output/package.json @@ -0,0 +1,9 @@ +{ + "name": "@test/astro-cloudflare-no-output", + "version": "0.0.0", + "private": true, + "dependencies": { + "@astrojs/cloudflare": "workspace:*", + "astro": "workspace:*" + } +} diff --git a/packages/integrations/cloudflare/test/no-output.test.js b/packages/integrations/cloudflare/test/no-output.test.js new file mode 100644 index 000000000..c82d45210 --- /dev/null +++ b/packages/integrations/cloudflare/test/no-output.test.js @@ -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"`); + }); +}); + diff --git a/packages/integrations/cloudflare/test/test-utils.js b/packages/integrations/cloudflare/test/test-utils.js new file mode 100644 index 000000000..6bb3e7c25 --- /dev/null +++ b/packages/integrations/cloudflare/test/test-utils.js @@ -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); +} diff --git a/packages/integrations/vercel/package.json b/packages/integrations/vercel/package.json index 9cb39a4df..08da5e991 100644 --- a/packages/integrations/vercel/package.json +++ b/packages/integrations/vercel/package.json @@ -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", diff --git a/packages/integrations/vercel/src/serverless/adapter.ts b/packages/integrations/vercel/src/serverless/adapter.ts index a83dcab74..0face02e2 100644 --- a/packages/integrations/vercel/src/serverless/adapter.ts +++ b/packages/integrations/vercel/src/serverless/adapter.ts @@ -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'; diff --git a/packages/integrations/vercel/test/fixtures/no-output/astro.config.mjs b/packages/integrations/vercel/test/fixtures/no-output/astro.config.mjs new file mode 100644 index 000000000..664b64d56 --- /dev/null +++ b/packages/integrations/vercel/test/fixtures/no-output/astro.config.mjs @@ -0,0 +1,6 @@ +import { defineConfig } from 'astro/config'; +import vercel from '@astrojs/vercel/serverless'; + +export default defineConfig({ + adapter: vercel() +}); diff --git a/packages/integrations/vercel/test/fixtures/no-output/package.json b/packages/integrations/vercel/test/fixtures/no-output/package.json new file mode 100644 index 000000000..604b4e4ea --- /dev/null +++ b/packages/integrations/vercel/test/fixtures/no-output/package.json @@ -0,0 +1,9 @@ +{ + "name": "@test/astro-vercel-no-output", + "version": "0.0.0", + "private": true, + "dependencies": { + "@astrojs/vercel": "workspace:*", + "astro": "workspace:*" + } +} diff --git a/packages/integrations/vercel/test/fixtures/no-output/src/pages/index.astro b/packages/integrations/vercel/test/fixtures/no-output/src/pages/index.astro new file mode 100644 index 000000000..6368ce118 --- /dev/null +++ b/packages/integrations/vercel/test/fixtures/no-output/src/pages/index.astro @@ -0,0 +1,8 @@ + + + testing + + +

testing

+ + diff --git a/packages/integrations/vercel/test/no-output.test.js b/packages/integrations/vercel/test/no-output.test.js new file mode 100644 index 000000000..c82d45210 --- /dev/null +++ b/packages/integrations/vercel/test/no-output.test.js @@ -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"`); + }); +}); + diff --git a/packages/integrations/vercel/test/test-utils.js b/packages/integrations/vercel/test/test-utils.js new file mode 100644 index 000000000..6bb3e7c25 --- /dev/null +++ b/packages/integrations/vercel/test/test-utils.js @@ -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); +} diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 517396ae4..dee90e4f4 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -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