From 13db5bad3a1b4ad2e85bc0a79717878a7e82a72a Mon Sep 17 00:00:00 2001 From: "Fred K. Schott" Date: Sat, 25 Jun 2022 21:48:30 -0700 Subject: [PATCH 01/19] Start of work on astroConfig.mode === 'server' --- .changeset/lucky-apes-yell.md | 5 +++ .changeset/perfect-drinks-fold.md | 5 +++ examples/basics/astro.config.mjs | 6 ++- packages/astro/package.json | 1 + packages/astro/src/@types/astro.ts | 9 ++-- packages/astro/src/adapter-node/index.ts | 9 ++++ packages/astro/src/adapter-node/server.ts | 44 +++++++++++++++++++ packages/astro/src/adapter-ssg/index.ts | 23 ---------- packages/astro/src/core/add/index.ts | 14 +++--- packages/astro/src/core/build/generate.ts | 6 +-- packages/astro/src/core/build/index.ts | 25 +++++++---- packages/astro/src/core/build/page-data.ts | 6 +-- packages/astro/src/core/build/static-build.ts | 15 +++---- .../astro/src/core/build/vite-plugin-pages.ts | 3 +- packages/astro/src/core/config.ts | 6 ++- packages/astro/src/core/endpoint/dev/index.ts | 3 +- packages/astro/src/core/logger/node.ts | 1 + packages/astro/src/core/render/dev/index.ts | 4 +- packages/astro/src/core/request.ts | 2 +- packages/astro/src/integrations/index.ts | 33 +++++--------- .../src/vite-plugin-astro-server/index.ts | 6 +-- .../integrations/vercel/src/static/adapter.ts | 6 ++- packages/webapi/mod.d.ts | 2 +- 23 files changed, 143 insertions(+), 91 deletions(-) create mode 100644 .changeset/lucky-apes-yell.md create mode 100644 .changeset/perfect-drinks-fold.md create mode 100644 packages/astro/src/adapter-node/index.ts create mode 100644 packages/astro/src/adapter-node/server.ts delete mode 100644 packages/astro/src/adapter-ssg/index.ts diff --git a/.changeset/lucky-apes-yell.md b/.changeset/lucky-apes-yell.md new file mode 100644 index 000000000000..ea244403e574 --- /dev/null +++ b/.changeset/lucky-apes-yell.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +Update "astro add" output to remove confusing multi-select prompt. diff --git a/.changeset/perfect-drinks-fold.md b/.changeset/perfect-drinks-fold.md new file mode 100644 index 000000000000..2af9edabaf61 --- /dev/null +++ b/.changeset/perfect-drinks-fold.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +Update the help output to improve formatting diff --git a/examples/basics/astro.config.mjs b/examples/basics/astro.config.mjs index 882e6515a67e..c7f4bce2d410 100644 --- a/examples/basics/astro.config.mjs +++ b/examples/basics/astro.config.mjs @@ -1,4 +1,8 @@ import { defineConfig } from 'astro/config'; +import netlify from "@astrojs/netlify"; + // https://astro.build/config -export default defineConfig({}); +export default defineConfig({ + mode: "static", +}); \ No newline at end of file diff --git a/packages/astro/package.json b/packages/astro/package.json index 8d5a27e491bf..a0a44f75ea6c 100644 --- a/packages/astro/package.json +++ b/packages/astro/package.json @@ -42,6 +42,7 @@ "./package.json": "./package.json", "./runtime/*": "./dist/runtime/*", "./server/*": "./dist/runtime/server/*", + "./adapter-node/server.js": "./dist/adapter-node/server.js", "./vite-plugin-astro": "./dist/vite-plugin-astro/index.js", "./vite-plugin-astro/*": "./dist/vite-plugin-astro/*", "./vite-plugin-astro-postprocess": "./dist/vite-plugin-astro-postprocess/index.js", diff --git a/packages/astro/src/@types/astro.ts b/packages/astro/src/@types/astro.ts index 2e6b167c0c23..1cd59b651b12 100644 --- a/packages/astro/src/@types/astro.ts +++ b/packages/astro/src/@types/astro.ts @@ -76,7 +76,6 @@ export interface BuildConfig { client: URL; server: URL; serverEntry: string; - staticMode: boolean | undefined; } /** @@ -637,7 +636,11 @@ export interface AstroUserConfig { * } * ``` */ - adapter?: AstroIntegration; + deploy?: AstroIntegration; + + // TODO: Document + mode?: 'static' | 'server'; + /** * @docs @@ -750,7 +753,7 @@ export interface AstroConfig extends z.output { // This is a more detailed type than zod validation gives us. // TypeScript still confirms zod validation matches this type. integrations: AstroIntegration[]; - adapter?: AstroIntegration; + // Private: // We have a need to pass context based on configured state, // that is different from the user-exposed configuration. diff --git a/packages/astro/src/adapter-node/index.ts b/packages/astro/src/adapter-node/index.ts new file mode 100644 index 000000000000..0284f02f9f17 --- /dev/null +++ b/packages/astro/src/adapter-node/index.ts @@ -0,0 +1,9 @@ +import { AstroAdapter } from "../@types/astro"; + +export function getGenericNodeAdapter(): AstroAdapter { + return { + name: 'node', + serverEntrypoint: 'astro/adapter-node/server.js', + exports: ['handler'], + }; +} diff --git a/packages/astro/src/adapter-node/server.ts b/packages/astro/src/adapter-node/server.ts new file mode 100644 index 000000000000..22afddfbe123 --- /dev/null +++ b/packages/astro/src/adapter-node/server.ts @@ -0,0 +1,44 @@ +import { polyfill } from '@astrojs/webapi'; +import type { IncomingMessage, ServerResponse } from 'http'; +import type { Readable } from 'stream'; +import { SSRManifest } from '../@types/astro'; +import { NodeApp } from '../core/app/node'; + +polyfill(globalThis, { + exclude: 'window document', +}); + +export function createExports(manifest: SSRManifest) { + const app = new NodeApp(manifest); + return { + async handler(req: IncomingMessage, res: ServerResponse, next?: (err?: unknown) => void) { + const route = app.match(req); + + if (route) { + try { + const response = await app.render(req); + await writeWebResponse(res, response); + } catch (err: unknown) { + if (next) { + next(err); + } else { + throw err; + } + } + } else if (next) { + return next(); + } + }, + }; +} + +async function writeWebResponse(res: ServerResponse, webResponse: Response) { + const { status, headers, body } = webResponse; + res.writeHead(status, Object.fromEntries(headers.entries())); + if (body) { + for await (const chunk of body as unknown as Readable) { + res.write(chunk); + } + } + res.end(); +} diff --git a/packages/astro/src/adapter-ssg/index.ts b/packages/astro/src/adapter-ssg/index.ts deleted file mode 100644 index 703289d8fc0a..000000000000 --- a/packages/astro/src/adapter-ssg/index.ts +++ /dev/null @@ -1,23 +0,0 @@ -import type { AstroAdapter, AstroIntegration } from '../@types/astro'; - -export function getAdapter(): AstroAdapter { - return { - name: '@astrojs/ssg', - // This one has no server entrypoint and is mostly just an integration - //serverEntrypoint: '@astrojs/ssg/server.js', - }; -} - -export default function createIntegration(): AstroIntegration { - return { - name: '@astrojs/ssg', - hooks: { - 'astro:config:done': ({ setAdapter }) => { - setAdapter(getAdapter()); - }, - 'astro:build:start': ({ buildConfig }) => { - buildConfig.staticMode = true; - }, - }, - }; -} diff --git a/packages/astro/src/core/add/index.ts b/packages/astro/src/core/add/index.ts index fe75c42c71d6..7790a71f01fc 100644 --- a/packages/astro/src/core/add/index.ts +++ b/packages/astro/src/core/add/index.ts @@ -66,7 +66,7 @@ export default async function add(names: string[], { cwd, flags, logging, teleme ['--yes', 'Accept all prompts.'], ['--help', 'Show this help message.'], ], - 'Example: Add a UI Framework': [ + 'Recommended: UI Frameworks': [ ['react', 'astro add react'], ['preact', 'astro add preact'], ['vue', 'astro add vue'], @@ -74,7 +74,13 @@ export default async function add(names: string[], { cwd, flags, logging, teleme ['solid-js', 'astro add solid-js'], ['lit', 'astro add lit'], ], - 'Example: Add an Integration': [ + 'Recommended: Hosting': [ + ['netlify', 'astro add netlify'], + ['vercel', 'astro add vercel'], + ['cloudflare', 'astro add cloudflare'], + ['deno', 'astro add deno'], + ], + 'Recommended: Integrations': [ ['tailwind', 'astro add tailwind'], ['partytown', 'astro add partytown'], ['sitemap', 'astro add sitemap'], @@ -85,9 +91,7 @@ export default async function add(names: string[], { cwd, flags, logging, teleme ['deno', 'astro add deno'], ], }, - description: `Check out the full integration catalog: ${cyan( - 'https://astro.build/integrations' - )}`, + description: `For more integrations, check out: ${cyan('https://astro.build/integrations')}`, }); return; } diff --git a/packages/astro/src/core/build/generate.ts b/packages/astro/src/core/build/generate.ts index 2a181fe7f305..4b2f8d55cb7b 100644 --- a/packages/astro/src/core/build/generate.ts +++ b/packages/astro/src/core/build/generate.ts @@ -18,7 +18,7 @@ import { debug, info } from '../logger/core.js'; import { render } from '../render/core.js'; import { createLinkStylesheetElementSet, createModuleScriptsSet } from '../render/ssr-element.js'; import { createRequest } from '../request.js'; -import { getOutputFilename, isBuildingToSSR } from '../util.js'; +import { getOutputFilename } from '../util.js'; import { getOutFile, getOutFolder } from './common.js'; import { eachPageData, getPageDataByComponent } from './internal.js'; import type { PageBuildData, SingleFileBuiltModule, StaticBuildOptions } from './types'; @@ -97,7 +97,7 @@ export async function generatePages( const timer = performance.now(); info(opts.logging, null, `\n${bgGreen(black(' generating static routes '))}`); - const ssr = isBuildingToSSR(opts.astroConfig); + const ssr = opts.astroConfig.mode === 'server'; const serverEntry = opts.buildConfig.serverEntry; const outFolder = ssr ? opts.buildConfig.server : opts.astroConfig.outDir; const ssrEntryURL = new URL('./' + serverEntry + `?time=${Date.now()}`, outFolder); @@ -207,7 +207,7 @@ async function generatePath( } } - const ssr = isBuildingToSSR(opts.astroConfig); + const ssr = opts.astroConfig.mode === 'server'; const url = new URL(opts.astroConfig.base + removeLeadingForwardSlash(pathname), origin); const options: RenderOptions = { adapterName: undefined, diff --git a/packages/astro/src/core/build/index.ts b/packages/astro/src/core/build/index.ts index f35e2d12f6a9..1d5c671d236d 100644 --- a/packages/astro/src/core/build/index.ts +++ b/packages/astro/src/core/build/index.ts @@ -1,5 +1,5 @@ import type { AstroTelemetry } from '@astrojs/telemetry'; -import type { AstroConfig, BuildConfig, ManifestData, RuntimeMode } from '../../@types/astro'; +import type { AstroAdapter, AstroConfig, BuildConfig, ManifestData, RuntimeMode } from '../../@types/astro'; import type { LogOptions } from '../logger/core'; import fs from 'fs'; @@ -18,7 +18,7 @@ import { debug, info, levels, timerMessage } from '../logger/core.js'; import { apply as applyPolyfill } from '../polyfill.js'; import { RouteCache } from '../render/route-cache.js'; import { createRouteManifest } from '../routing/index.js'; -import { createSafeError, isBuildingToSSR } from '../util.js'; +import { createSafeError } from '../util.js'; import { collectPagesData } from './page-data.js'; import { staticBuild } from './static-build.js'; import { getTimeStat } from './util.js'; @@ -98,11 +98,21 @@ class AstroBuilder { client: new URL('./client/', this.config.outDir), server: new URL('./server/', this.config.outDir), serverEntry: 'entry.mjs', - staticMode: undefined, }; await runHookBuildStart({ config: this.config, buildConfig }); - info(this.logging, 'build', 'Collecting build information...'); + const getPrettyDeployTarget = (adapter: AstroAdapter | undefined) => { + if (adapter?.name === 'node') { + return 'node.js (generic)'; + } + if (adapter?.name) { + return adapter?.name; + } + return 'unknown'; + } + info(this.logging, 'build', `build target: ${colors.green(this.config.mode)}`); + info(this.logging, 'build', `deploy target: ${colors.green(getPrettyDeployTarget(this.config._ctx.adapter))}`); + info(this.logging, 'build', 'Collecting build info...'); this.timer.loadStart = performance.now(); const { assets, allPages } = await collectPagesData({ astroConfig: this.config, @@ -111,7 +121,7 @@ class AstroBuilder { origin, routeCache: this.routeCache, viteServer, - ssr: isBuildingToSSR(this.config), + ssr: this.config.mode === 'server', }); debug('build', timerMessage('All pages loaded', this.timer.loadStart)); @@ -168,12 +178,11 @@ class AstroBuilder { }); if (this.logging.level && levels[this.logging.level] <= levels['info']) { - const buildMode = isBuildingToSSR(this.config) ? 'ssr' : 'static'; await this.printStats({ logging: this.logging, timeStart: this.timer.init, pageCount: pageNames.length, - buildMode, + buildMode: this.config.mode, }); } } @@ -198,7 +207,7 @@ class AstroBuilder { logging: LogOptions; timeStart: number; pageCount: number; - buildMode: 'static' | 'ssr'; + buildMode: 'static' | 'server'; }) { const total = getTimeStat(timeStart, performance.now()); diff --git a/packages/astro/src/core/build/page-data.ts b/packages/astro/src/core/build/page-data.ts index 23fb0283da29..03bf649866f7 100644 --- a/packages/astro/src/core/build/page-data.ts +++ b/packages/astro/src/core/build/page-data.ts @@ -10,7 +10,6 @@ import { debug } from '../logger/core.js'; import { removeTrailingForwardSlash } from '../path.js'; import { callGetStaticPaths, RouteCache, RouteCacheEntry } from '../render/route-cache.js'; import { matchRoute } from '../routing/match.js'; -import { isBuildingToSSR } from '../util.js'; export interface CollectPagesDataOptions { astroConfig: AstroConfig; @@ -36,9 +35,6 @@ export async function collectPagesData( const assets: Record = {}; const allPages: AllPagesData = {}; const builtPaths = new Set(); - - const buildMode = isBuildingToSSR(astroConfig) ? 'ssr' : 'static'; - const dataCollectionLogTimeout = setInterval(() => { info(opts.logging, 'build', 'The data collection step may take longer for larger projects...'); clearInterval(dataCollectionLogTimeout); @@ -72,7 +68,7 @@ export async function collectPagesData( }; clearInterval(routeCollectionLogTimeout); - if (buildMode === 'static') { + if (astroConfig.mode === 'static') { const html = `${route.pathname}`.replace(/\/?$/, '/index.html'); debug( 'build', diff --git a/packages/astro/src/core/build/static-build.ts b/packages/astro/src/core/build/static-build.ts index 33acb71618fe..455ba65c5097 100644 --- a/packages/astro/src/core/build/static-build.ts +++ b/packages/astro/src/core/build/static-build.ts @@ -11,7 +11,6 @@ import { runHookBuildSetup } from '../../integrations/index.js'; import { rollupPluginAstroBuildCSS } from '../../vite-plugin-build-css/index.js'; import type { ViteConfigWithSSR } from '../create-vite'; import { info } from '../logger/core.js'; -import { isBuildingToSSR } from '../util.js'; import { generatePages } from './generate.js'; import { trackPageData } from './internal.js'; import type { PageBuildData, StaticBuildOptions } from './types'; @@ -60,9 +59,7 @@ export async function staticBuild(opts: StaticBuildOptions) { info( opts.logging, 'build', - isBuildingToSSR(astroConfig) - ? 'Building SSR entrypoints...' - : 'Building entrypoints for prerendering...' + `Building ${astroConfig.mode} entrypoints...` ); const ssrResult = (await ssrBuild(opts, internals, pageInput)) as RollupOutput; info(opts.logging, 'build', dim(`Completed in ${getTimeStat(timer.ssr, performance.now())}.`)); @@ -83,7 +80,7 @@ export async function staticBuild(opts: StaticBuildOptions) { await clientBuild(opts, internals, clientInput); timer.generate = performance.now(); - if (opts.buildConfig.staticMode) { + if (astroConfig.mode === 'static') { try { await generatePages(ssrResult, opts, internals, facadeIdToPageDataMap); } finally { @@ -100,7 +97,7 @@ export async function staticBuild(opts: StaticBuildOptions) { async function ssrBuild(opts: StaticBuildOptions, internals: BuildInternals, input: Set) { const { astroConfig, viteConfig } = opts; - const ssr = isBuildingToSSR(astroConfig); + const ssr = astroConfig.mode === 'server'; const out = ssr ? opts.buildConfig.server : astroConfig.outDir; const viteBuildConfig: ViteConfigWithSSR = { @@ -144,7 +141,7 @@ async function ssrBuild(opts: StaticBuildOptions, internals: BuildInternals, inp }), ...(viteConfig.plugins || []), // SSR needs to be last - isBuildingToSSR(opts.astroConfig) && vitePluginSSR(internals, opts.astroConfig._ctx.adapter!), + opts.astroConfig.mode === 'server' && vitePluginSSR(internals, opts.astroConfig._ctx.adapter!), vitePluginAnalyzer(opts.astroConfig, internals), ], publicDir: ssr ? false : viteConfig.publicDir, @@ -174,7 +171,7 @@ async function clientBuild( ) { const { astroConfig, viteConfig } = opts; const timer = performance.now(); - const ssr = isBuildingToSSR(astroConfig); + const ssr = astroConfig.mode === 'server'; const out = ssr ? opts.buildConfig.client : astroConfig.outDir; // Nothing to do if there is no client-side JS. @@ -275,7 +272,7 @@ async function copyFiles(fromFolder: URL, toFolder: URL) { async function ssrMoveAssets(opts: StaticBuildOptions) { info(opts.logging, 'build', 'Rearranging server assets...'); - const serverRoot = opts.buildConfig.staticMode + const serverRoot = opts.astroConfig.mode === 'static' ? opts.buildConfig.client : opts.buildConfig.server; const clientRoot = opts.buildConfig.client; diff --git a/packages/astro/src/core/build/vite-plugin-pages.ts b/packages/astro/src/core/build/vite-plugin-pages.ts index 1158d69be42c..bba2e5b9cac7 100644 --- a/packages/astro/src/core/build/vite-plugin-pages.ts +++ b/packages/astro/src/core/build/vite-plugin-pages.ts @@ -1,6 +1,5 @@ import type { Plugin as VitePlugin } from 'vite'; import { pagesVirtualModuleId, resolvedPagesVirtualModuleId } from '../app/index.js'; -import { isBuildingToSSR } from '../util.js'; import { addRollupInput } from './add-rollup-input.js'; import type { BuildInternals } from './internal.js'; import { eachPageData } from './internal.js'; @@ -11,7 +10,7 @@ export function vitePluginPages(opts: StaticBuildOptions, internals: BuildIntern name: '@astro/plugin-build-pages', options(options) { - if (!isBuildingToSSR(opts.astroConfig)) { + if (opts.astroConfig.mode === 'static') { return addRollupInput(options, [pagesVirtualModuleId]); } }, diff --git a/packages/astro/src/core/config.ts b/packages/astro/src/core/config.ts index 75fabdc89857..66a1e5913f2c 100644 --- a/packages/astro/src/core/config.ts +++ b/packages/astro/src/core/config.ts @@ -89,7 +89,6 @@ export const LEGACY_ASTRO_CONFIG_KEYS = new Set([ ]); export const AstroConfigSchema = z.object({ - adapter: z.object({ name: z.string(), hooks: z.object({}).passthrough().default({}) }).optional(), root: z .string() .optional() @@ -124,6 +123,10 @@ export const AstroConfigSchema = z.object({ .union([z.literal('always'), z.literal('never'), z.literal('ignore')]) .optional() .default(ASTRO_CONFIG_DEFAULTS.trailingSlash), + mode: z + .union([z.literal('static'), z.literal('server')]) + .optional() + .default('static'), build: z .object({ format: z @@ -212,6 +215,7 @@ export const AstroConfigSchema = z.object({ vite: z .custom((data) => data instanceof Object && !Array.isArray(data)) .default(ASTRO_CONFIG_DEFAULTS.vite), + deploy: z.object({ name: z.string(), hooks: z.object({}).passthrough().default({}) }).optional(), }); /** Turn raw config values into normalized values */ diff --git a/packages/astro/src/core/endpoint/dev/index.ts b/packages/astro/src/core/endpoint/dev/index.ts index 1e7abe8df722..61e04892be75 100644 --- a/packages/astro/src/core/endpoint/dev/index.ts +++ b/packages/astro/src/core/endpoint/dev/index.ts @@ -1,13 +1,12 @@ import type { EndpointHandler } from '../../../@types/astro'; import type { SSROptions } from '../../render/dev'; import { preload } from '../../render/dev/index.js'; -import { isBuildingToSSR } from '../../util.js'; import { call as callEndpoint } from '../index.js'; export async function call(ssrOpts: SSROptions) { const [, mod] = await preload(ssrOpts); return await callEndpoint(mod as unknown as EndpointHandler, { ...ssrOpts, - ssr: isBuildingToSSR(ssrOpts.astroConfig), + ssr: ssrOpts.astroConfig.mode === 'server', }); } diff --git a/packages/astro/src/core/logger/node.ts b/packages/astro/src/core/logger/node.ts index b655b2631925..ed2c869c00d8 100644 --- a/packages/astro/src/core/logger/node.ts +++ b/packages/astro/src/core/logger/node.ts @@ -126,6 +126,7 @@ export const logger = { export function enableVerboseLogging() { //debugPackage.enable('*,-babel'); + console.log('ah!'); debug('cli', '--verbose flag enabled! Enabling: DEBUG="*,-babel"'); debug( 'cli', diff --git a/packages/astro/src/core/render/dev/index.ts b/packages/astro/src/core/render/dev/index.ts index e3b6f0ac7c96..67a9d75aad11 100644 --- a/packages/astro/src/core/render/dev/index.ts +++ b/packages/astro/src/core/render/dev/index.ts @@ -11,7 +11,7 @@ import type { } from '../../../@types/astro'; import { prependForwardSlash } from '../../../core/path.js'; import { LogOptions } from '../../logger/core.js'; -import { isBuildingToSSR, isPage } from '../../util.js'; +import { isPage } from '../../util.js'; import { render as coreRender } from '../core.js'; import { RouteCache } from '../route-cache.js'; import { collectMdMetadata } from '../util.js'; @@ -183,7 +183,7 @@ export async function render( route, routeCache, site: astroConfig.site ? new URL(astroConfig.base, astroConfig.site).toString() : undefined, - ssr: isBuildingToSSR(astroConfig), + ssr: astroConfig.mode === 'server', streaming: true, }); diff --git a/packages/astro/src/core/request.ts b/packages/astro/src/core/request.ts index 59d8acae92fb..36d4bccf8d80 100644 --- a/packages/astro/src/core/request.ts +++ b/packages/astro/src/core/request.ts @@ -56,7 +56,7 @@ export function createRequest({ warn( logging, 'ssg', - `Headers are not exposed in static-site generation (SSG) mode. To enable reading headers you need to set an SSR adapter in your config.` + `Headers are not exposed in static-site generation (SSG) mode. To enable reading headers: set \`mode: "server"\` in your config file.` ); return _headers; }, diff --git a/packages/astro/src/integrations/index.ts b/packages/astro/src/integrations/index.ts index d13d05d52045..772c6e5d3117 100644 --- a/packages/astro/src/integrations/index.ts +++ b/packages/astro/src/integrations/index.ts @@ -7,12 +7,11 @@ import { HookParameters, RouteData, } from '../@types/astro.js'; -import ssgAdapter from '../adapter-ssg/index.js'; +import { getGenericNodeAdapter } from '../adapter-node/index.js'; import type { SerializedSSRManifest } from '../core/app/types'; import type { PageBuildData } from '../core/build/types'; import { mergeConfig } from '../core/config.js'; import type { ViteConfigWithSSR } from '../core/create-vite.js'; -import { isBuildingToSSR } from '../core/util.js'; export async function runHookConfigSetup({ config: _config, @@ -21,9 +20,10 @@ export async function runHookConfigSetup({ config: AstroConfig; command: 'dev' | 'build'; }): Promise { - if (_config.adapter) { - _config.integrations.push(_config.adapter); - } + // DEPRECATED + // if (_config.adapter) { + // _config.integrations.push(_config.adapter); + // } let updatedConfig: AstroConfig = { ..._config }; for (const integration of _config.integrations) { @@ -80,7 +80,7 @@ export async function runHookConfigDone({ config }: { config: AstroConfig }) { setAdapter(adapter) { if (config._ctx.adapter && config._ctx.adapter.name !== adapter.name) { throw new Error( - `Adapter already set to ${config._ctx.adapter.name}. You can only have one adapter.` + `Integration "${integration.name}" conflicts with "${config._ctx.adapter.name}". You can only configure one deployment integration.` ); } config._ctx.adapter = adapter; @@ -88,22 +88,13 @@ export async function runHookConfigDone({ config }: { config: AstroConfig }) { }); } } - // Call the default adapter - if (!config._ctx.adapter) { - const integration = ssgAdapter(); - config.integrations.push(integration); - if (integration?.hooks?.['astro:config:done']) { - await integration.hooks['astro:config:done']({ - config, - setAdapter(adapter) { - config._ctx.adapter = adapter; - }, - }); - } - } + // Call the default adapter + if (!config._ctx.adapter && config.mode === 'server') { + config._ctx.adapter = getGenericNodeAdapter(); + } } -export async function runHookServerSetup({ +export async function runHookServerSetup({ config, server, }: { @@ -203,7 +194,7 @@ export async function runHookBuildDone({ pages: string[]; routes: RouteData[]; }) { - const dir = isBuildingToSSR(config) ? buildConfig.client : config.outDir; + const dir = config.mode === 'server' ? buildConfig.client : config.outDir; for (const integration of config.integrations) { if (integration?.hooks?.['astro:build:done']) { diff --git a/packages/astro/src/vite-plugin-astro-server/index.ts b/packages/astro/src/vite-plugin-astro-server/index.ts index 84a92f00de1a..625193d648f8 100644 --- a/packages/astro/src/vite-plugin-astro-server/index.ts +++ b/packages/astro/src/vite-plugin-astro-server/index.ts @@ -20,7 +20,7 @@ import { preload, ssr } from '../core/render/dev/index.js'; import { RouteCache } from '../core/render/route-cache.js'; import { createRequest } from '../core/request.js'; import { createRouteManifest, matchRoute } from '../core/routing/index.js'; -import { createSafeError, isBuildingToSSR, resolvePages } from '../core/util.js'; +import { createSafeError, resolvePages } from '../core/util.js'; import notFoundTemplate, { subpathNotUsedTemplate } from '../template/4xx.js'; interface AstroPluginOptions { @@ -205,7 +205,7 @@ async function handleRequest( ) { const reqStart = performance.now(); const origin = `${viteServer.config.server.https ? 'https' : 'http'}://${req.headers.host}`; - const buildingToSSR = isBuildingToSSR(config); + const buildingToSSR = config.mode === 'server'; // Ignore `.html` extensions and `index.html` in request URLS to ensure that // routing behavior matches production builds. This supports both file and directory // build formats, and is necessary based on how the manifest tracks build targets. @@ -276,7 +276,7 @@ async function handleRequest( routeCache, pathname: pathname, logging, - ssr: isBuildingToSSR(config), + ssr: config.mode === 'server', }); if (paramsAndPropsRes === GetParamsAndPropsError.NoMatchingStaticPath) { warn( diff --git a/packages/integrations/vercel/src/static/adapter.ts b/packages/integrations/vercel/src/static/adapter.ts index db6690f8cedf..50f9cb757cca 100644 --- a/packages/integrations/vercel/src/static/adapter.ts +++ b/packages/integrations/vercel/src/static/adapter.ts @@ -24,7 +24,11 @@ export default function vercelStatic(): AstroIntegration { _config = config; }, 'astro:build:start': async ({ buildConfig }) => { - buildConfig.staticMode = true; + if (String(process.env.ENABLE_VC_BUILD) !== '1') { + throw new Error( + `The enviroment variable "ENABLE_VC_BUILD" was not found. Make sure you have it set to "1" in your Vercel project.\nLearn how to set enviroment variables here: https://vercel.com/docs/concepts/projects/environment-variables` + ); + } // Ensure to have `.vercel/output` empty. // This is because, when building to static, outDir = .vercel/output/static/, diff --git a/packages/webapi/mod.d.ts b/packages/webapi/mod.d.ts index a3c49dc5c406..b385e82a5e29 100644 --- a/packages/webapi/mod.d.ts +++ b/packages/webapi/mod.d.ts @@ -1,5 +1,5 @@ export { pathToPosix } from './lib/utils'; -export { AbortController, AbortSignal, alert, atob, Blob, btoa, ByteLengthQueuingStrategy, cancelAnimationFrame, cancelIdleCallback, CanvasRenderingContext2D, CharacterData, clearTimeout, Comment, CountQueuingStrategy, CSSStyleSheet, CustomElementRegistry, CustomEvent, Document, DocumentFragment, DOMException, Element, Event, EventTarget, fetch, File, FormData, Headers, HTMLBodyElement, HTMLCanvasElement, HTMLDivElement, HTMLDocument, HTMLElement, HTMLHeadElement, HTMLHtmlElement, HTMLImageElement, HTMLSpanElement, HTMLStyleElement, HTMLTemplateElement, HTMLUnknownElement, Image, ImageData, IntersectionObserver, MediaQueryList, MutationObserver, Node, NodeFilter, NodeIterator, OffscreenCanvas, ReadableByteStreamController, ReadableStream, ReadableStreamBYOBReader, ReadableStreamBYOBRequest, ReadableStreamDefaultController, ReadableStreamDefaultReader, Request, requestAnimationFrame, requestIdleCallback, ResizeObserver, Response, setTimeout, ShadowRoot, structuredClone, StyleSheet, Text, TransformStream, TreeWalker, URLPattern, Window, WritableStream, WritableStreamDefaultController, WritableStreamDefaultWriter } from './mod.js'; +export { AbortController, AbortSignal, alert, atob, Blob, btoa, ByteLengthQueuingStrategy, cancelAnimationFrame, cancelIdleCallback, CanvasRenderingContext2D, CharacterData, clearTimeout, Comment, CountQueuingStrategy, CSSStyleSheet, CustomElementRegistry, CustomEvent, Document, DocumentFragment, DOMException, Element, Event, EventTarget, fetch, File, FormData, Headers, HTMLBodyElement, HTMLCanvasElement, HTMLDivElement, HTMLDocument, HTMLElement, HTMLHeadElement, HTMLHtmlElement, HTMLImageElement, HTMLSpanElement, HTMLStyleElement, HTMLTemplateElement, HTMLUnknownElement, Image, ImageData, IntersectionObserver, MediaQueryList, MutationObserver, Node, NodeFilter, NodeIterator, OffscreenCanvas, ReadableByteStreamController, ReadableStream, ReadableStreamBYOBReader, ReadableStreamBYOBRequest, ReadableStreamDefaultController, ReadableStreamDefaultReader, Request, requestAnimationFrame, requestIdleCallback, ResizeObserver, Response, setTimeout, ShadowRoot, structuredClone, StyleSheet, Text, TransformStream, TreeWalker, URLPattern, Window, WritableStream, WritableStreamDefaultController, WritableStreamDefaultWriter, } from './mod.js'; export declare const polyfill: { (target: any, options?: PolyfillOptions): any; internals(target: any, name: string): any; From d1bc9ee5f7b82e5d3246c28116f2acdfebf63fc5 Mon Sep 17 00:00:00 2001 From: Matthew Phillips Date: Thu, 21 Jul 2022 15:26:43 -0400 Subject: [PATCH 02/19] Add tests and more --- packages/astro/src/adapter-node/index.ts | 9 -- packages/astro/src/adapter-node/server.ts | 44 -------- packages/astro/src/core/build/static-build.ts | 10 ++ packages/astro/src/core/logger/node.ts | 3 +- packages/astro/src/core/render/result.ts | 1 + packages/astro/src/integrations/index.ts | 13 +-- packages/astro/test/config-mode.test.js | 101 ++++++++++++++++++ 7 files changed, 117 insertions(+), 64 deletions(-) delete mode 100644 packages/astro/src/adapter-node/index.ts delete mode 100644 packages/astro/src/adapter-node/server.ts create mode 100644 packages/astro/test/config-mode.test.js diff --git a/packages/astro/src/adapter-node/index.ts b/packages/astro/src/adapter-node/index.ts deleted file mode 100644 index 0284f02f9f17..000000000000 --- a/packages/astro/src/adapter-node/index.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { AstroAdapter } from "../@types/astro"; - -export function getGenericNodeAdapter(): AstroAdapter { - return { - name: 'node', - serverEntrypoint: 'astro/adapter-node/server.js', - exports: ['handler'], - }; -} diff --git a/packages/astro/src/adapter-node/server.ts b/packages/astro/src/adapter-node/server.ts deleted file mode 100644 index 22afddfbe123..000000000000 --- a/packages/astro/src/adapter-node/server.ts +++ /dev/null @@ -1,44 +0,0 @@ -import { polyfill } from '@astrojs/webapi'; -import type { IncomingMessage, ServerResponse } from 'http'; -import type { Readable } from 'stream'; -import { SSRManifest } from '../@types/astro'; -import { NodeApp } from '../core/app/node'; - -polyfill(globalThis, { - exclude: 'window document', -}); - -export function createExports(manifest: SSRManifest) { - const app = new NodeApp(manifest); - return { - async handler(req: IncomingMessage, res: ServerResponse, next?: (err?: unknown) => void) { - const route = app.match(req); - - if (route) { - try { - const response = await app.render(req); - await writeWebResponse(res, response); - } catch (err: unknown) { - if (next) { - next(err); - } else { - throw err; - } - } - } else if (next) { - return next(); - } - }, - }; -} - -async function writeWebResponse(res: ServerResponse, webResponse: Response) { - const { status, headers, body } = webResponse; - res.writeHead(status, Object.fromEntries(headers.entries())); - if (body) { - for await (const chunk of body as unknown as Readable) { - res.write(chunk); - } - } - res.end(); -} diff --git a/packages/astro/src/core/build/static-build.ts b/packages/astro/src/core/build/static-build.ts index 455ba65c5097..8df30cd3b90a 100644 --- a/packages/astro/src/core/build/static-build.ts +++ b/packages/astro/src/core/build/static-build.ts @@ -24,6 +24,16 @@ import { injectManifest, vitePluginSSR } from './vite-plugin-ssr.js'; export async function staticBuild(opts: StaticBuildOptions) { const { allPages, astroConfig } = opts; + // Verify this app is buildable. + if(opts.astroConfig.mode === 'server' && !opts.astroConfig._ctx.adapter) { + throw new Error(`Cannot use mode: 'server' without an adapter. Please install and configure an adapter by setting it on the deploy configuration. + +export default { + mode: 'static', + adapter: netlify(), +}`) + } + // The pages to be built for rendering purposes. const pageInput = new Set(); diff --git a/packages/astro/src/core/logger/node.ts b/packages/astro/src/core/logger/node.ts index ed2c869c00d8..3673ed150f23 100644 --- a/packages/astro/src/core/logger/node.ts +++ b/packages/astro/src/core/logger/node.ts @@ -125,8 +125,7 @@ export const logger = { }; export function enableVerboseLogging() { - //debugPackage.enable('*,-babel'); - console.log('ah!'); + debugPackage.enable('*,-babel'); debug('cli', '--verbose flag enabled! Enabling: DEBUG="*,-babel"'); debug( 'cli', diff --git a/packages/astro/src/core/render/result.ts b/packages/astro/src/core/render/result.ts index a7f36ee7933b..647588c9645b 100644 --- a/packages/astro/src/core/render/result.ts +++ b/packages/astro/src/core/render/result.ts @@ -115,6 +115,7 @@ export function createResult(args: CreateResultArgs): SSRResult { const headers = new Headers(); if (args.streaming) { headers.set('Transfer-Encoding', 'chunked'); + headers.set('Content-Type', 'text/html'); } else { headers.set('Content-Type', 'text/html'); } diff --git a/packages/astro/src/integrations/index.ts b/packages/astro/src/integrations/index.ts index 772c6e5d3117..ffbc4b575f9d 100644 --- a/packages/astro/src/integrations/index.ts +++ b/packages/astro/src/integrations/index.ts @@ -7,7 +7,6 @@ import { HookParameters, RouteData, } from '../@types/astro.js'; -import { getGenericNodeAdapter } from '../adapter-node/index.js'; import type { SerializedSSRManifest } from '../core/app/types'; import type { PageBuildData } from '../core/build/types'; import { mergeConfig } from '../core/config.js'; @@ -20,10 +19,10 @@ export async function runHookConfigSetup({ config: AstroConfig; command: 'dev' | 'build'; }): Promise { - // DEPRECATED - // if (_config.adapter) { - // _config.integrations.push(_config.adapter); - // } + // An adapter is an integration, so if one is provided push it. + if (_config.deploy) { + _config.integrations.push(_config.deploy); + } let updatedConfig: AstroConfig = { ..._config }; for (const integration of _config.integrations) { @@ -88,10 +87,6 @@ export async function runHookConfigDone({ config }: { config: AstroConfig }) { }); } } - // Call the default adapter - if (!config._ctx.adapter && config.mode === 'server') { - config._ctx.adapter = getGenericNodeAdapter(); - } } export async function runHookServerSetup({ diff --git a/packages/astro/test/config-mode.test.js b/packages/astro/test/config-mode.test.js new file mode 100644 index 000000000000..6393fddfd525 --- /dev/null +++ b/packages/astro/test/config-mode.test.js @@ -0,0 +1,101 @@ +import { expect } from 'chai'; +import { load as cheerioLoad } from 'cheerio'; +import { loadFixture } from './test-utils.js'; +import testAdapter from './test-adapter.js'; + +describe('AstroConfig - config.mode', () => { + describe(`mode: 'server'`, () => { + describe('deploy config provided', () => { + /** @type {import('./test-utils').Fixture} */ + let fixture; + + before(async () => { + fixture = await loadFixture({ + // This is just a random fixture to test, doesn't matter. + root: './fixtures/astro-basic/', + deploy: testAdapter(), + mode: 'server', + }); + await fixture.build(); + }); + + it('Builds an SSR-able app', async () => { + const app = await fixture.loadTestAdapterApp(); + const request = new Request('http://example.com/'); + const response = await app.render(request); + expect(response.status).to.equal(200); + expect(response.headers.get('content-type')).to.equal('text/html'); + const html = await response.text(); + expect(html.length).to.be.greaterThan(0); + }); + }); + + describe('deploy config omitted', () => { + /** @type {import('./test-utils').Fixture} */ + let fixture; + + before(async () => { + fixture = await loadFixture({ + // This is just a random fixture to test, doesn't matter. + root: './fixtures/astro-basic/', + mode: 'server' + }); + + }); + + it('Throws during the build', async () => { + let built = false; + try { + await fixture.build(); + built = true; + } catch(err) { + expect(err).to.be.an.instanceOf(Error); + expect(err.message).to.match(/without an adapter/); + } + + expect(built).to.equal(false, 'Should not have built'); + }); + }); + }); + + describe(`mode: 'static'`, () => { + describe('Deploy config omitted', () => { + /** @type {import('./test-utils').Fixture} */ + let fixture; + + before(async () => { + fixture = await loadFixture({ + // This is just a random fixture to test, doesn't matter. + root: './fixtures/astro-basic/', + mode: 'static' + }); + await fixture.build(); + }); + + it('Builds to static HTML', async () => { + let html; + try { + html = await fixture.readFile('/index.html'); + } catch(err) { + expect(false).to.equal(true, 'Couldnt find the file, which mean it did not build.'); + } + expect(html.length).to.be.greaterThan(0); + }); + }); + + describe.skip('deploy config provided - TODO, we need adapters to support static mode first', () => { + /** @type {import('./test-utils').Fixture} */ + let fixture; + + before(async () => { + fixture = await loadFixture({ + // This is just a random fixture to test, doesn't matter. + root: './fixtures/astro-basic/', + deploy: testAdapter(), + mode: 'server' + }); + await fixture.build(); + }); + }); + }); +}); From c873d9c3d9a4c499707d851ec7e915590e8796e3 Mon Sep 17 00:00:00 2001 From: Matthew Phillips Date: Thu, 21 Jul 2022 16:20:35 -0400 Subject: [PATCH 03/19] adapter -> deploy in some places --- packages/astro/src/core/render/dev/index.ts | 2 +- packages/astro/src/events/session.ts | 4 +--- packages/integrations/image/src/index.ts | 6 +++--- packages/integrations/sitemap/src/index.ts | 2 +- 4 files changed, 6 insertions(+), 8 deletions(-) diff --git a/packages/astro/src/core/render/dev/index.ts b/packages/astro/src/core/render/dev/index.ts index 67a9d75aad11..d1b8a13c40c8 100644 --- a/packages/astro/src/core/render/dev/index.ts +++ b/packages/astro/src/core/render/dev/index.ts @@ -161,7 +161,7 @@ export async function render( }); let response = await coreRender({ - adapterName: astroConfig.adapter?.name, + adapterName: astroConfig.deploy?.name, links, styles, logging, diff --git a/packages/astro/src/events/session.ts b/packages/astro/src/events/session.ts index 3fc3be723822..d22182170ff0 100644 --- a/packages/astro/src/events/session.ts +++ b/packages/astro/src/events/session.ts @@ -1,6 +1,4 @@ -import { createRequire } from 'node:module'; import type { AstroUserConfig } from '../@types/astro'; -const require = createRequire(import.meta.url); const EVENT_SESSION = 'ASTRO_CLI_SESSION_STARTED'; @@ -84,7 +82,7 @@ export function eventCliSession( typeof p === 'string' ? p : typeof p ) ?? []), ] as string[], - adapter: userConfig?.adapter?.name ?? null, + adapter: userConfig?.deploy?.name ?? null, integrations: (userConfig?.integrations ?? []).filter(Boolean).map((i: any) => i?.name), trailingSlash: userConfig?.trailingSlash, build: userConfig?.build diff --git a/packages/integrations/image/src/index.ts b/packages/integrations/image/src/index.ts index f857bdc70f5b..836419974157 100644 --- a/packages/integrations/image/src/index.ts +++ b/packages/integrations/image/src/index.ts @@ -46,7 +46,7 @@ const createIntegration = (options: IntegrationOptions = {}): AstroIntegration = _config = config; // Always treat `astro dev` as SSR mode, even without an adapter - const mode = command === 'dev' || config.adapter ? 'ssr' : 'ssg'; + const mode: 'server' | 'static' = command === 'dev' ? 'server' : config.mode; updateConfig({ vite: getViteConfiguration() }); @@ -58,7 +58,7 @@ const createIntegration = (options: IntegrationOptions = {}): AstroIntegration = // TODO: Add support for custom, user-provided filename format functions function filenameFormat(transform: TransformOptions, searchParams: URLSearchParams) { - if (mode === 'ssg') { + if (mode === 'static') { return isRemoteImage(transform.src) ? path.join(OUTPUT_DIR, path.basename(propsToFilename(transform))) : path.join( @@ -81,7 +81,7 @@ const createIntegration = (options: IntegrationOptions = {}): AstroIntegration = filenameFormat, }; - if (mode === 'ssr') { + if (mode === 'server') { injectRoute({ pattern: ROUTE_PATTERN, entryPoint: diff --git a/packages/integrations/sitemap/src/index.ts b/packages/integrations/sitemap/src/index.ts index a1c9650f2bd2..682b76a2a655 100644 --- a/packages/integrations/sitemap/src/index.ts +++ b/packages/integrations/sitemap/src/index.ts @@ -98,7 +98,7 @@ const createPlugin = (options?: SitemapOptions): AstroIntegration => { if (pageUrls.length === 0) { // offer suggestion for SSR users - if (typeof config.adapter !== 'undefined') { + if (typeof config.deploy !== 'undefined') { logger.warn( `No pages found! We can only detect sitemap routes for "static" projects. Since you are using an SSR adapter, we recommend manually listing your sitemap routes using the "customPages" integration option.\n\nExample: \`sitemap({ customPages: ['https://example.com/route'] })\`` ); From 3e978e1125f0dce2939742baeb29a8707bf8e252 Mon Sep 17 00:00:00 2001 From: Matthew Phillips Date: Fri, 22 Jul 2022 08:34:51 -0400 Subject: [PATCH 04/19] Add fallback for `adapter` config --- examples/basics/astro.config.mjs | 4 +--- examples/ssr/astro.config.mjs | 3 ++- packages/astro/src/cli/index.ts | 4 ++-- packages/astro/src/core/config.ts | 21 ++++++++++++++----- .../test/ssr-adapter-build-config.test.js | 6 ++---- packages/astro/test/ssr-api-route.test.js | 6 ++---- packages/astro/test/ssr-assets.test.js | 6 ++---- packages/astro/test/ssr-dynamic.test.js | 6 ++---- packages/astro/test/ssr-env.test.js | 6 ++---- .../astro/test/ssr-hoisted-script.test.js | 6 ++---- packages/astro/test/ssr-large-array.test.js | 6 ++---- packages/astro/test/ssr-lit.test.js | 6 ++---- packages/astro/test/ssr-markdown.test.js | 6 ++---- packages/astro/test/ssr-partytown.test.js | 6 ++---- packages/astro/test/ssr-redirect.test.js | 6 ++---- packages/astro/test/ssr-request.test.js | 6 ++---- packages/astro/test/ssr-response.test.js | 6 ++---- packages/astro/test/ssr-scripts.test.js | 6 ++---- 18 files changed, 49 insertions(+), 67 deletions(-) diff --git a/examples/basics/astro.config.mjs b/examples/basics/astro.config.mjs index c7f4bce2d410..a07be03278c9 100644 --- a/examples/basics/astro.config.mjs +++ b/examples/basics/astro.config.mjs @@ -3,6 +3,4 @@ import netlify from "@astrojs/netlify"; // https://astro.build/config -export default defineConfig({ - mode: "static", -}); \ No newline at end of file +export default defineConfig({}); diff --git a/examples/ssr/astro.config.mjs b/examples/ssr/astro.config.mjs index 5794b07f1da4..c14390a100d3 100644 --- a/examples/ssr/astro.config.mjs +++ b/examples/ssr/astro.config.mjs @@ -4,6 +4,7 @@ import node from '@astrojs/node'; // https://astro.build/config export default defineConfig({ - adapter: node(), + mode: 'server', + deploy: node(), integrations: [svelte()], }); diff --git a/packages/astro/src/cli/index.ts b/packages/astro/src/cli/index.ts index 27aa7db304a0..a9e3ebe8e0fd 100644 --- a/packages/astro/src/cli/index.ts +++ b/packages/astro/src/cli/index.ts @@ -132,7 +132,7 @@ async function runCommand(cmd: string, flags: yargs.Arguments) { } } - let { astroConfig, userConfig, userConfigPath } = await openConfig({ cwd: root, flags, cmd }); + let { astroConfig, userConfig, userConfigPath } = await openConfig({ cwd: root, flags, cmd, logging }); telemetry.record(event.eventCliSession(cmd, userConfig, flags)); // Common CLI Commands: @@ -154,7 +154,7 @@ async function runCommand(cmd: string, flags: yargs.Arguments) { watcher.on('add', async function restartServerOnNewConfigFile(addedFile: string) { // if there was not a config before, attempt to resolve if (!userConfigPath && addedFile.includes('astro.config')) { - const addedConfig = await openConfig({ cwd: root, flags, cmd }); + const addedConfig = await openConfig({ cwd: root, flags, cmd, logging }); if (addedConfig.userConfigPath) { info(logging, 'astro', 'Astro config detected. Restarting server...'); astroConfig = addedConfig.astroConfig; diff --git a/packages/astro/src/core/config.ts b/packages/astro/src/core/config.ts index 66a1e5913f2c..19cd178ba314 100644 --- a/packages/astro/src/core/config.ts +++ b/packages/astro/src/core/config.ts @@ -15,6 +15,7 @@ import { mergeConfig as mergeViteConfig } from 'vite'; import { z } from 'zod'; import { appendForwardSlash, prependForwardSlash, trimSlashes } from './path.js'; import { arraify, isObject } from './util.js'; +import { LogOptions, warn } from './logger/core.js'; load.use([loadTypeScript]); @@ -222,7 +223,8 @@ export const AstroConfigSchema = z.object({ export async function validateConfig( userConfig: any, root: string, - cmd: string + cmd: string, + logging: LogOptions ): Promise { const fileProtocolRoot = pathToFileURL(root + path.sep); // Manual deprecation checks @@ -259,6 +261,13 @@ export async function validateConfig( process.exit(1); } + if('adapter' in userConfig) { + warn(logging, `The "adapter" config has been renamed to "deploy". Please update your config file.`); + userConfig.deploy = userConfig.adapter; + delete userConfig.adapter; + } + + let legacyConfigKey: string | undefined; for (const key of Object.keys(userConfig)) { if (LEGACY_ASTRO_CONFIG_KEYS.has(key)) { @@ -383,6 +392,7 @@ interface LoadConfigOptions { flags?: Flags; cmd: string; validate?: boolean; + logging: LogOptions; } /** @@ -454,7 +464,7 @@ export async function openConfig(configOptions: LoadConfigOptions): Promise { const mergedConfig = mergeCLIFlags(userConfig, flags, cmd); - const validatedConfig = await validateConfig(mergedConfig, root, cmd); + const validatedConfig = await validateConfig(mergedConfig, root, cmd, logging); return validatedConfig; } diff --git a/packages/astro/test/ssr-adapter-build-config.test.js b/packages/astro/test/ssr-adapter-build-config.test.js index 1f76d7e6a275..567b190fbd89 100644 --- a/packages/astro/test/ssr-adapter-build-config.test.js +++ b/packages/astro/test/ssr-adapter-build-config.test.js @@ -11,10 +11,8 @@ describe('Integration buildConfig hook', () => { let _config; fixture = await loadFixture({ root: './fixtures/ssr-request/', - experimental: { - ssr: true, - }, - adapter: { + mode: 'server', + deploy: { name: 'my-ssr-adapter', hooks: { 'astro:config:setup': ({ updateConfig }) => { diff --git a/packages/astro/test/ssr-api-route.test.js b/packages/astro/test/ssr-api-route.test.js index ec6e65641434..8232754c098a 100644 --- a/packages/astro/test/ssr-api-route.test.js +++ b/packages/astro/test/ssr-api-route.test.js @@ -9,10 +9,8 @@ describe('API routes in SSR', () => { before(async () => { fixture = await loadFixture({ root: './fixtures/ssr-api-route/', - experimental: { - ssr: true, - }, - adapter: testAdapter(), + mode: 'server', + deploy: testAdapter(), }); await fixture.build(); }); diff --git a/packages/astro/test/ssr-assets.test.js b/packages/astro/test/ssr-assets.test.js index ca62fbd88b77..7b92d6809396 100644 --- a/packages/astro/test/ssr-assets.test.js +++ b/packages/astro/test/ssr-assets.test.js @@ -9,10 +9,8 @@ describe('SSR Assets', () => { before(async () => { fixture = await loadFixture({ root: './fixtures/ssr-assets/', - experimental: { - ssr: true, - }, - adapter: testAdapter(), + mode: 'server', + deploy: testAdapter(), }); await fixture.build(); }); diff --git a/packages/astro/test/ssr-dynamic.test.js b/packages/astro/test/ssr-dynamic.test.js index f2795794f5c1..36861026d02c 100644 --- a/packages/astro/test/ssr-dynamic.test.js +++ b/packages/astro/test/ssr-dynamic.test.js @@ -10,10 +10,8 @@ describe('Dynamic pages in SSR', () => { before(async () => { fixture = await loadFixture({ root: './fixtures/ssr-dynamic/', - experimental: { - ssr: true, - }, - adapter: testAdapter(), + mode: 'server', + deploy: testAdapter(), }); await fixture.build(); }); diff --git a/packages/astro/test/ssr-env.test.js b/packages/astro/test/ssr-env.test.js index da823fa201c0..9156b725e516 100644 --- a/packages/astro/test/ssr-env.test.js +++ b/packages/astro/test/ssr-env.test.js @@ -10,10 +10,8 @@ describe('SSR Environment Variables', () => { before(async () => { fixture = await loadFixture({ root: './fixtures/ssr-env/', - experimental: { - ssr: true, - }, - adapter: testAdapter(), + mode: 'server', + deploy: testAdapter(), }); await fixture.build(); }); diff --git a/packages/astro/test/ssr-hoisted-script.test.js b/packages/astro/test/ssr-hoisted-script.test.js index 134744ae9f16..4e0866c34437 100644 --- a/packages/astro/test/ssr-hoisted-script.test.js +++ b/packages/astro/test/ssr-hoisted-script.test.js @@ -10,10 +10,8 @@ describe('Hoisted scripts in SSR', () => { before(async () => { fixture = await loadFixture({ root: './fixtures/ssr-hoisted-script/', - experimental: { - ssr: true, - }, - adapter: testAdapter(), + mode: 'server', + deploy: testAdapter(), }); await fixture.build(); }); diff --git a/packages/astro/test/ssr-large-array.test.js b/packages/astro/test/ssr-large-array.test.js index 64a82222b32b..114c0e8816c6 100644 --- a/packages/astro/test/ssr-large-array.test.js +++ b/packages/astro/test/ssr-large-array.test.js @@ -10,10 +10,8 @@ describe('SSR with Large Array and client rendering', () => { before(async () => { fixture = await loadFixture({ root: './fixtures/large-array/', - experimental: { - ssr: true, - }, - adapter: testAdapter(), + mode: 'server', + deploy: testAdapter(), }); await fixture.build(); }); diff --git a/packages/astro/test/ssr-lit.test.js b/packages/astro/test/ssr-lit.test.js index 46dccd680bd6..fc39ff437ad3 100644 --- a/packages/astro/test/ssr-lit.test.js +++ b/packages/astro/test/ssr-lit.test.js @@ -10,10 +10,8 @@ describe('Lit integration in SSR', () => { before(async () => { fixture = await loadFixture({ root: './fixtures/lit-element/', - experimental: { - ssr: true, - }, - adapter: testAdapter(), + mode: 'server', + deploy: testAdapter(), }); await fixture.build(); }); diff --git a/packages/astro/test/ssr-markdown.test.js b/packages/astro/test/ssr-markdown.test.js index 40c12449e872..5c9211dc24f3 100644 --- a/packages/astro/test/ssr-markdown.test.js +++ b/packages/astro/test/ssr-markdown.test.js @@ -10,10 +10,8 @@ describe('Markdown pages in SSR', () => { before(async () => { fixture = await loadFixture({ root: './fixtures/ssr-markdown/', - experimental: { - ssr: true, - }, - adapter: testAdapter(), + mode: 'server', + deploy: testAdapter(), }); await fixture.build(); }); diff --git a/packages/astro/test/ssr-partytown.test.js b/packages/astro/test/ssr-partytown.test.js index 5ea2bcde59e9..a4735a5633c2 100644 --- a/packages/astro/test/ssr-partytown.test.js +++ b/packages/astro/test/ssr-partytown.test.js @@ -10,10 +10,8 @@ describe('Using the Partytown integration in SSR', () => { before(async () => { fixture = await loadFixture({ root: './fixtures/ssr-partytown/', - adapter: testAdapter(), - experimental: { - ssr: true, - }, + deploy: testAdapter(), + mode: 'server' }); await fixture.build(); }); diff --git a/packages/astro/test/ssr-redirect.test.js b/packages/astro/test/ssr-redirect.test.js index 29fe701f7a00..8035c458aaed 100644 --- a/packages/astro/test/ssr-redirect.test.js +++ b/packages/astro/test/ssr-redirect.test.js @@ -9,10 +9,8 @@ describe('Astro.redirect', () => { before(async () => { fixture = await loadFixture({ root: './fixtures/ssr-redirect/', - experimental: { - ssr: true, - }, - adapter: testAdapter(), + mode: 'server', + deploy: testAdapter(), }); await fixture.build(); }); diff --git a/packages/astro/test/ssr-request.test.js b/packages/astro/test/ssr-request.test.js index a9c1dd6b6159..e8c37fd1c974 100644 --- a/packages/astro/test/ssr-request.test.js +++ b/packages/astro/test/ssr-request.test.js @@ -10,10 +10,8 @@ describe('Using Astro.request in SSR', () => { before(async () => { fixture = await loadFixture({ root: './fixtures/ssr-request/', - adapter: testAdapter(), - experimental: { - ssr: true, - }, + deploy: testAdapter(), + mode: 'server' }); await fixture.build(); }); diff --git a/packages/astro/test/ssr-response.test.js b/packages/astro/test/ssr-response.test.js index ffabcbba4a34..55fdd1c2d6df 100644 --- a/packages/astro/test/ssr-response.test.js +++ b/packages/astro/test/ssr-response.test.js @@ -10,10 +10,8 @@ describe('Using Astro.response in SSR', () => { before(async () => { fixture = await loadFixture({ root: './fixtures/ssr-response/', - adapter: testAdapter(), - experimental: { - ssr: true, - }, + deploy: testAdapter(), + mode: 'server' }); await fixture.build(); }); diff --git a/packages/astro/test/ssr-scripts.test.js b/packages/astro/test/ssr-scripts.test.js index f44099e41c27..dfe194cea999 100644 --- a/packages/astro/test/ssr-scripts.test.js +++ b/packages/astro/test/ssr-scripts.test.js @@ -9,10 +9,8 @@ describe('SSR Hydrated component scripts', () => { before(async () => { fixture = await loadFixture({ root: './fixtures/ssr-scripts/', - experimental: { - ssr: true, - }, - adapter: testAdapter(), + mode: 'server', + deploy: testAdapter(), }); await fixture.build(); }); From 2242088176037d42dc82d268076f372c5d6a9b4e Mon Sep 17 00:00:00 2001 From: Matthew Phillips Date: Fri, 22 Jul 2022 09:06:22 -0400 Subject: [PATCH 05/19] Update more tests --- packages/astro/test/client-address.test.js | 6 ++---- .../fixtures/static-build-ssr/astro.config.mjs | 3 ++- packages/astro/test/streaming.test.js | 12 ++++-------- packages/astro/test/test-utils.js | 14 +++++++------- 4 files changed, 15 insertions(+), 20 deletions(-) diff --git a/packages/astro/test/client-address.test.js b/packages/astro/test/client-address.test.js index c356c16ebd6f..e2f445bf92b9 100644 --- a/packages/astro/test/client-address.test.js +++ b/packages/astro/test/client-address.test.js @@ -12,10 +12,8 @@ describe('Astro.clientAddress', () => { before(async () => { fixture = await loadFixture({ root: './fixtures/client-address/', - experimental: { - ssr: true, - }, - adapter: testAdapter(), + mode: 'server', + deploy: testAdapter(), }); }); diff --git a/packages/astro/test/fixtures/static-build-ssr/astro.config.mjs b/packages/astro/test/fixtures/static-build-ssr/astro.config.mjs index cf1980887653..775beb317ecd 100644 --- a/packages/astro/test/fixtures/static-build-ssr/astro.config.mjs +++ b/packages/astro/test/fixtures/static-build-ssr/astro.config.mjs @@ -2,5 +2,6 @@ import { defineConfig } from 'astro/config'; import nodejs from '@astrojs/node'; export default defineConfig({ - adapter: nodejs(), + deploy: nodejs(), + mode: 'server', }); diff --git a/packages/astro/test/streaming.test.js b/packages/astro/test/streaming.test.js index fc7afba05be7..37babbe0a034 100644 --- a/packages/astro/test/streaming.test.js +++ b/packages/astro/test/streaming.test.js @@ -12,10 +12,8 @@ describe('Streaming', () => { before(async () => { fixture = await loadFixture({ root: './fixtures/streaming/', - adapter: testAdapter(), - experimental: { - ssr: true, - }, + deploy: testAdapter(), + mode: 'server' }); }); @@ -81,10 +79,8 @@ describe('Streaming disabled', () => { before(async () => { fixture = await loadFixture({ root: './fixtures/streaming/', - adapter: testAdapter(), - experimental: { - ssr: true, - }, + deploy: testAdapter(), + mode: 'server', server: { streaming: false, }, diff --git a/packages/astro/test/test-utils.js b/packages/astro/test/test-utils.js index ab43a94cc8ce..ded7e7745051 100644 --- a/packages/astro/test/test-utils.js +++ b/packages/astro/test/test-utils.js @@ -72,8 +72,14 @@ export async function loadFixture(inlineConfig) { } } + /** @type {import('../src/core/logger/core').LogOptions} */ + const logging = { + dest: nodeLogDestination, + level: 'error', + }; + // Load the config. - let config = await loadConfig({ cwd: fileURLToPath(cwd) }); + let config = await loadConfig({ cwd: fileURLToPath(cwd), logging }); config = merge(config, { ...inlineConfig, root: cwd }); // HACK: the inline config doesn't run through config validation where these normalizations usually occur @@ -89,12 +95,6 @@ export async function loadFixture(inlineConfig) { config._ctx.renderers.unshift(jsxRenderer); } - /** @type {import('../src/core/logger/core').LogOptions} */ - const logging = { - dest: nodeLogDestination, - level: 'error', - }; - /** @type {import('@astrojs/telemetry').AstroTelemetry} */ const telemetry = { record() { From 5a4b66e506ad2b684e9cf7b568c6af1dff0a4589 Mon Sep 17 00:00:00 2001 From: Matthew Phillips Date: Fri, 22 Jul 2022 09:11:40 -0400 Subject: [PATCH 06/19] Update image tests --- packages/integrations/image/test/image-ssr.test.js | 12 ++++-------- packages/integrations/image/test/picture-ssr.test.js | 12 ++++-------- 2 files changed, 8 insertions(+), 16 deletions(-) diff --git a/packages/integrations/image/test/image-ssr.test.js b/packages/integrations/image/test/image-ssr.test.js index 784a92e538ba..6d9293ff23ac 100644 --- a/packages/integrations/image/test/image-ssr.test.js +++ b/packages/integrations/image/test/image-ssr.test.js @@ -9,10 +9,8 @@ describe('SSR images - build', function () { before(async () => { fixture = await loadFixture({ root: './fixtures/basic-image/', - adapter: testAdapter(), - experimental: { - ssr: true, - }, + deploy: testAdapter(), + mode: 'server', }); await fixture.build(); }); @@ -123,10 +121,8 @@ describe('SSR images - dev', function () { before(async () => { fixture = await loadFixture({ root: './fixtures/basic-image/', - adapter: testAdapter(), - experimental: { - ssr: true, - }, + deploy: testAdapter(), + mode: 'server', }); devServer = await fixture.startDevServer(); diff --git a/packages/integrations/image/test/picture-ssr.test.js b/packages/integrations/image/test/picture-ssr.test.js index 4914b73545ec..2712fdf5d784 100644 --- a/packages/integrations/image/test/picture-ssr.test.js +++ b/packages/integrations/image/test/picture-ssr.test.js @@ -9,10 +9,8 @@ describe('SSR pictures - build', function () { before(async () => { fixture = await loadFixture({ root: './fixtures/basic-picture/', - adapter: testAdapter(), - experimental: { - ssr: true, - }, + deploy: testAdapter(), + mode: 'server', }); await fixture.build(); }); @@ -171,10 +169,8 @@ describe('SSR images - dev', function () { before(async () => { fixture = await loadFixture({ root: './fixtures/basic-picture/', - adapter: testAdapter(), - experimental: { - ssr: true, - }, + deploy: testAdapter(), + mode: 'server', }); devServer = await fixture.startDevServer(); From 511687ace173601058d6507706183e843c1b18ed Mon Sep 17 00:00:00 2001 From: Matthew Phillips Date: Fri, 22 Jul 2022 10:25:11 -0400 Subject: [PATCH 07/19] Fix clientAddress test --- packages/astro/test/client-address.test.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/packages/astro/test/client-address.test.js b/packages/astro/test/client-address.test.js index e2f445bf92b9..73d28481d528 100644 --- a/packages/astro/test/client-address.test.js +++ b/packages/astro/test/client-address.test.js @@ -65,10 +65,8 @@ describe('Astro.clientAddress', () => { before(async () => { fixture = await loadFixture({ root: './fixtures/client-address/', - experimental: { - ssr: true, - }, - adapter: testAdapter({ provideAddress: false }), + mode: 'server', + deploy: testAdapter({ provideAddress: false }), }); await fixture.build(); }); @@ -88,6 +86,7 @@ describe('Astro.clientAddress', () => { before(async () => { fixture = await loadFixture({ root: './fixtures/client-address/', + mode: 'static', }); }); From 570a9f35f1512334a39a67b0ff5964bce47ee242 Mon Sep 17 00:00:00 2001 From: Matthew Phillips Date: Fri, 22 Jul 2022 11:06:26 -0400 Subject: [PATCH 08/19] Updates based on PR review --- examples/basics/astro.config.mjs | 2 -- packages/astro/src/@types/astro.ts | 4 ++-- packages/astro/src/core/build/index.ts | 10 +--------- packages/astro/src/core/build/static-build.ts | 4 ++-- packages/astro/src/core/logger/node.ts | 1 - packages/astro/src/core/util.ts | 11 ++--------- packages/integrations/cloudflare/src/index.ts | 4 ++++ packages/integrations/deno/src/index.ts | 6 +++++- .../netlify/src/integration-edge-functions.ts | 4 ++++ .../integrations/netlify/src/integration-functions.ts | 4 ++++ packages/integrations/node/src/index.ts | 6 +++++- 11 files changed, 29 insertions(+), 27 deletions(-) diff --git a/examples/basics/astro.config.mjs b/examples/basics/astro.config.mjs index a07be03278c9..882e6515a67e 100644 --- a/examples/basics/astro.config.mjs +++ b/examples/basics/astro.config.mjs @@ -1,6 +1,4 @@ import { defineConfig } from 'astro/config'; -import netlify from "@astrojs/netlify"; - // https://astro.build/config export default defineConfig({}); diff --git a/packages/astro/src/@types/astro.ts b/packages/astro/src/@types/astro.ts index 1cd59b651b12..e2ff5cd0f76c 100644 --- a/packages/astro/src/@types/astro.ts +++ b/packages/astro/src/@types/astro.ts @@ -621,7 +621,7 @@ export interface AstroUserConfig { /** * @docs * @kind heading - * @name Adapter + * @name Deploy * @description * * Deploy to your favorite server, serverless, or edge host with build adapters. Import one of our first-party adapters for [Netlify](https://docs.astro.build/en/guides/deploy/netlify/#adapter-for-ssredge), [Vercel](https://docs.astro.build/en/guides/deploy/vercel/#adapter-for-ssr), and more to engage Astro SSR. @@ -632,7 +632,7 @@ export interface AstroUserConfig { * import netlify from '@astrojs/netlify/functions'; * { * // Example: Build for Netlify serverless deployment - * adapter: netlify(), + * deploy: netlify(), * } * ``` */ diff --git a/packages/astro/src/core/build/index.ts b/packages/astro/src/core/build/index.ts index 1d5c671d236d..5da8bd295074 100644 --- a/packages/astro/src/core/build/index.ts +++ b/packages/astro/src/core/build/index.ts @@ -101,15 +101,7 @@ class AstroBuilder { }; await runHookBuildStart({ config: this.config, buildConfig }); - const getPrettyDeployTarget = (adapter: AstroAdapter | undefined) => { - if (adapter?.name === 'node') { - return 'node.js (generic)'; - } - if (adapter?.name) { - return adapter?.name; - } - return 'unknown'; - } + const getPrettyDeployTarget = (adapter: AstroAdapter | undefined) => adapter?.name || 'unknown'; info(this.logging, 'build', `build target: ${colors.green(this.config.mode)}`); info(this.logging, 'build', `deploy target: ${colors.green(getPrettyDeployTarget(this.config._ctx.adapter))}`); info(this.logging, 'build', 'Collecting build info...'); diff --git a/packages/astro/src/core/build/static-build.ts b/packages/astro/src/core/build/static-build.ts index 8df30cd3b90a..0606aec19b04 100644 --- a/packages/astro/src/core/build/static-build.ts +++ b/packages/astro/src/core/build/static-build.ts @@ -6,7 +6,7 @@ import { fileURLToPath } from 'url'; import * as vite from 'vite'; import { BuildInternals, createBuildInternals } from '../../core/build/internal.js'; import { prependForwardSlash } from '../../core/path.js'; -import { emptyDir, removeDir } from '../../core/util.js'; +import { emptyDir, removeDir, isModeServerWithNoAdapter } from '../../core/util.js'; import { runHookBuildSetup } from '../../integrations/index.js'; import { rollupPluginAstroBuildCSS } from '../../vite-plugin-build-css/index.js'; import type { ViteConfigWithSSR } from '../create-vite'; @@ -25,7 +25,7 @@ export async function staticBuild(opts: StaticBuildOptions) { const { allPages, astroConfig } = opts; // Verify this app is buildable. - if(opts.astroConfig.mode === 'server' && !opts.astroConfig._ctx.adapter) { + if(isModeServerWithNoAdapter(opts.astroConfig)) { throw new Error(`Cannot use mode: 'server' without an adapter. Please install and configure an adapter by setting it on the deploy configuration. export default { diff --git a/packages/astro/src/core/logger/node.ts b/packages/astro/src/core/logger/node.ts index 3673ed150f23..23bb2e8bc0d7 100644 --- a/packages/astro/src/core/logger/node.ts +++ b/packages/astro/src/core/logger/node.ts @@ -125,7 +125,6 @@ export const logger = { }; export function enableVerboseLogging() { - debugPackage.enable('*,-babel'); debug('cli', '--verbose flag enabled! Enabling: DEBUG="*,-babel"'); debug( 'cli', diff --git a/packages/astro/src/core/util.ts b/packages/astro/src/core/util.ts index 76c2c310a884..fbf3b1eb0a9c 100644 --- a/packages/astro/src/core/util.ts +++ b/packages/astro/src/core/util.ts @@ -182,15 +182,8 @@ export function isPage(file: URL, config: AstroConfig): boolean { return endsWithPageExt(file, config); } -export function isBuildingToSSR(config: AstroConfig): boolean { - const adapter = config._ctx.adapter; - if (!adapter) return false; - - if (typeof adapter.serverEntrypoint === 'string') { - return true; - } else { - return false; - } +export function isModeServerWithNoAdapter(config: AstroConfig): boolean { + return config.mode === 'static' && !config._ctx.adapter; } export function emoji(char: string, fallback: string) { diff --git a/packages/integrations/cloudflare/src/index.ts b/packages/integrations/cloudflare/src/index.ts index dc65f23ce5b0..e34880ebc16b 100644 --- a/packages/integrations/cloudflare/src/index.ts +++ b/packages/integrations/cloudflare/src/index.ts @@ -21,6 +21,10 @@ export default function createIntegration(): AstroIntegration { 'astro:config:done': ({ setAdapter, config }) => { setAdapter(getAdapter()); _config = config; + + if(config.mode === 'static') { + console.warn(`@astrojs/cloudflare does not support static mode.`); + } }, 'astro:build:start': ({ buildConfig }) => { _buildConfig = buildConfig; diff --git a/packages/integrations/deno/src/index.ts b/packages/integrations/deno/src/index.ts index 9a6df4f769de..cd8636327df1 100644 --- a/packages/integrations/deno/src/index.ts +++ b/packages/integrations/deno/src/index.ts @@ -29,8 +29,12 @@ export default function createIntegration(args?: Options): AstroIntegration { return { name: '@astrojs/deno', hooks: { - 'astro:config:done': ({ setAdapter }) => { + 'astro:config:done': ({ setAdapter, config }) => { setAdapter(getAdapter(args)); + + if(config.mode === 'static') { + console.warn(`@astrojs/deno does not support static mode.`); + } }, 'astro:build:start': ({ buildConfig }) => { _buildConfig = buildConfig; diff --git a/packages/integrations/netlify/src/integration-edge-functions.ts b/packages/integrations/netlify/src/integration-edge-functions.ts index b3f27997d5aa..227de4882ed9 100644 --- a/packages/integrations/netlify/src/integration-edge-functions.ts +++ b/packages/integrations/netlify/src/integration-edge-functions.ts @@ -135,6 +135,10 @@ export function netlifyEdgeFunctions({ dist }: NetlifyEdgeFunctionsOptions = {}) 'astro:config:done': ({ config, setAdapter }) => { setAdapter(getAdapter()); _config = config; + + if(config.mode === 'static') { + console.warn(`@astrojs/netlify does not support static mode.`); + } }, 'astro:build:start': async ({ buildConfig }) => { _buildConfig = buildConfig; diff --git a/packages/integrations/netlify/src/integration-functions.ts b/packages/integrations/netlify/src/integration-functions.ts index e9b4aae33b38..e6a12e256d7e 100644 --- a/packages/integrations/netlify/src/integration-functions.ts +++ b/packages/integrations/netlify/src/integration-functions.ts @@ -35,6 +35,10 @@ function netlifyFunctions({ 'astro:config:done': ({ config, setAdapter }) => { setAdapter(getAdapter({ binaryMediaTypes })); _config = config; + + if(config.mode === 'static') { + console.warn(`@astrojs/netlify does not support static mode.`); + } }, 'astro:build:start': async ({ buildConfig }) => { entryFile = buildConfig.serverEntry.replace(/\.m?js/, ''); diff --git a/packages/integrations/node/src/index.ts b/packages/integrations/node/src/index.ts index b90cd9d2e990..20d4dd7eea02 100644 --- a/packages/integrations/node/src/index.ts +++ b/packages/integrations/node/src/index.ts @@ -12,8 +12,12 @@ export default function createIntegration(): AstroIntegration { return { name: '@astrojs/node', hooks: { - 'astro:config:done': ({ setAdapter }) => { + 'astro:config:done': ({ setAdapter, config }) => { setAdapter(getAdapter()); + + if(config.mode === 'static') { + console.warn(`@astrojs/node does not support static mode.`); + } }, }, }; From fa48c4e30ba2c3f2e277db07794461fab1331ec2 Mon Sep 17 00:00:00 2001 From: Matthew Phillips Date: Fri, 22 Jul 2022 11:11:26 -0400 Subject: [PATCH 09/19] Add a changeset --- .changeset/famous-coins-destroy.md | 36 ++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 .changeset/famous-coins-destroy.md diff --git a/.changeset/famous-coins-destroy.md b/.changeset/famous-coins-destroy.md new file mode 100644 index 000000000000..3c595414fd83 --- /dev/null +++ b/.changeset/famous-coins-destroy.md @@ -0,0 +1,36 @@ +--- +'astro': minor +'@astrojs/cloudflare': minor +'@astrojs/deno': minor +'@astrojs/image': minor +'@astrojs/netlify': minor +'@astrojs/node': minor +'@astrojs/sitemap': minor +'@astrojs/vercel': minor +--- + +New `mode` configuration option + +This change introduces a new configuration option `mode`. Mode can be either + +* `static` - The default, when building a static site. +* `server` - When building an app to be deployed for SSR (server-side rendering). + +The default, `static`, can be omitted from your config file. + +If you want to use SSR you now need to provide `mode: 'server'` *in addition* to an adapter. + +The `adapter` configuration has been renamed to `deploy`. In the future adapters will support configuring a static site as well! + +For SSR make this change: + +```diff +import { defineConfig } from 'astro/config'; +import netlify from '@astrojs/netlify/functions'; + +export default defineConfig({ +- adapter: netlify(), ++ deploy: netlify(), ++ mode: 'server', +}); +``` From 93468918dd518119546f2f4a0adac408ebaf00b8 Mon Sep 17 00:00:00 2001 From: Matthew Phillips Date: Fri, 22 Jul 2022 11:24:07 -0400 Subject: [PATCH 10/19] Update integrations tests + readme --- packages/integrations/cloudflare/README.md | 3 ++- packages/integrations/deno/README.md | 12 ++++++++---- .../deno/test/fixtures/basics/astro.config.mjs | 6 ++---- .../deno/test/fixtures/dynimport/astro.config.mjs | 6 ++---- packages/integrations/netlify/README.md | 9 ++++++--- .../fixtures/dynimport/astro.config.mjs | 6 ++---- .../fixtures/edge-basic/astro.config.mjs | 6 ++---- .../fixtures/root-dynamic/astro.config.mjs | 6 ++---- .../netlify/test/functions/base64-response.test.js | 6 ++---- .../netlify/test/functions/cookies.test.js | 6 ++---- .../netlify/test/functions/dynamic-route.test.js | 6 ++---- packages/integrations/node/README.md | 3 ++- packages/integrations/vercel/README.md | 5 +++-- 13 files changed, 37 insertions(+), 43 deletions(-) diff --git a/packages/integrations/cloudflare/README.md b/packages/integrations/cloudflare/README.md index 3417149b84c0..0b7ab4031ce8 100644 --- a/packages/integrations/cloudflare/README.md +++ b/packages/integrations/cloudflare/README.md @@ -9,7 +9,8 @@ import { defineConfig } from 'astro/config'; import cloudflare from '@astrojs/cloudflare'; export default defineConfig({ - adapter: cloudflare() + mode: 'server', + deploy: cloudflare() }); ``` diff --git a/packages/integrations/deno/README.md b/packages/integrations/deno/README.md index bc8dfe8f6b0d..ddb322bea9b8 100644 --- a/packages/integrations/deno/README.md +++ b/packages/integrations/deno/README.md @@ -37,7 +37,8 @@ import deno from '@astrojs/deno'; export default defineConfig({ // ... - adapter: deno() + mode: 'server', + deploy: deno() }); ``` @@ -69,7 +70,8 @@ import { defineConfig } from 'astro/config'; import deno from '@astrojs/deno'; export default defineConfig({ - adapter: deno({ + mode: 'server', + deploy: deno({ //options go here }) }); @@ -85,7 +87,8 @@ export default defineConfig({ import deno from '@astrojs/deno'; export default defineConfig({ - adapter: deno({ + mode: 'server', + deploy: deno({ start: false }) }); @@ -115,7 +118,8 @@ export default defineConfig({ import deno from '@astrojs/deno'; export default defineConfig({ - adapter: deno({ + mode: 'server', + deploy: deno({ port: 8081, hostname: 'myhost' }) diff --git a/packages/integrations/deno/test/fixtures/basics/astro.config.mjs b/packages/integrations/deno/test/fixtures/basics/astro.config.mjs index af5f1aa6b2ca..d70d49ed8f00 100644 --- a/packages/integrations/deno/test/fixtures/basics/astro.config.mjs +++ b/packages/integrations/deno/test/fixtures/basics/astro.config.mjs @@ -3,9 +3,7 @@ import deno from '@astrojs/deno'; import react from '@astrojs/react'; export default defineConfig({ - adapter: deno(), + deploy: deno(), integrations: [react()], - experimental: { - ssr: true - } + mode: 'server', }) diff --git a/packages/integrations/deno/test/fixtures/dynimport/astro.config.mjs b/packages/integrations/deno/test/fixtures/dynimport/astro.config.mjs index e56fe2e985fd..73ed78f1deb7 100644 --- a/packages/integrations/deno/test/fixtures/dynimport/astro.config.mjs +++ b/packages/integrations/deno/test/fixtures/dynimport/astro.config.mjs @@ -2,8 +2,6 @@ import { defineConfig } from 'astro/config'; import deno from '@astrojs/deno'; export default defineConfig({ - adapter: deno(), - experimental: { - ssr: true - } + deploy: deno(), + mode: 'server', }) diff --git a/packages/integrations/netlify/README.md b/packages/integrations/netlify/README.md index 5f6b61fa217d..96febf6eedbd 100644 --- a/packages/integrations/netlify/README.md +++ b/packages/integrations/netlify/README.md @@ -37,7 +37,8 @@ import { defineConfig } from 'astro/config'; import netlify from '@astrojs/netlify/functions'; export default defineConfig({ - adapter: netlify(), + mode: 'server', + deploy: netlify(), }); ``` @@ -51,7 +52,8 @@ import { defineConfig } from 'astro/config'; + import netlify from '@astrojs/netlify/edge-functions'; export default defineConfig({ - adapter: netlify(), + mode: 'server', + deploy: netlify(), }); ``` ## Usage @@ -83,7 +85,8 @@ import { defineConfig } from 'astro/config'; import netlify from '@astrojs/netlify/functions'; export default defineConfig({ - adapter: netlify({ + mode: 'server', + deploy: netlify({ dist: new URL('./dist/', import.meta.url) }) }); diff --git a/packages/integrations/netlify/test/edge-functions/fixtures/dynimport/astro.config.mjs b/packages/integrations/netlify/test/edge-functions/fixtures/dynimport/astro.config.mjs index c55135e43b7a..e961746c67c1 100644 --- a/packages/integrations/netlify/test/edge-functions/fixtures/dynimport/astro.config.mjs +++ b/packages/integrations/netlify/test/edge-functions/fixtures/dynimport/astro.config.mjs @@ -2,10 +2,8 @@ import { defineConfig } from 'astro/config'; import { netlifyEdgeFunctions } from '@astrojs/netlify'; export default defineConfig({ - adapter: netlifyEdgeFunctions({ + deploy: netlifyEdgeFunctions({ dist: new URL('./dist/', import.meta.url), }), - experimental: { - ssr: true - } + mode: 'server', }) diff --git a/packages/integrations/netlify/test/edge-functions/fixtures/edge-basic/astro.config.mjs b/packages/integrations/netlify/test/edge-functions/fixtures/edge-basic/astro.config.mjs index d7c89926484f..65d900580f20 100644 --- a/packages/integrations/netlify/test/edge-functions/fixtures/edge-basic/astro.config.mjs +++ b/packages/integrations/netlify/test/edge-functions/fixtures/edge-basic/astro.config.mjs @@ -3,11 +3,9 @@ import { netlifyEdgeFunctions } from '@astrojs/netlify'; import react from "@astrojs/react"; export default defineConfig({ - adapter: netlifyEdgeFunctions({ + deploy: netlifyEdgeFunctions({ dist: new URL('./dist/', import.meta.url), }), integrations: [react()], - experimental: { - ssr: true - } + mode: 'server', }) diff --git a/packages/integrations/netlify/test/edge-functions/fixtures/root-dynamic/astro.config.mjs b/packages/integrations/netlify/test/edge-functions/fixtures/root-dynamic/astro.config.mjs index c55135e43b7a..e961746c67c1 100644 --- a/packages/integrations/netlify/test/edge-functions/fixtures/root-dynamic/astro.config.mjs +++ b/packages/integrations/netlify/test/edge-functions/fixtures/root-dynamic/astro.config.mjs @@ -2,10 +2,8 @@ import { defineConfig } from 'astro/config'; import { netlifyEdgeFunctions } from '@astrojs/netlify'; export default defineConfig({ - adapter: netlifyEdgeFunctions({ + deploy: netlifyEdgeFunctions({ dist: new URL('./dist/', import.meta.url), }), - experimental: { - ssr: true - } + mode: 'server', }) diff --git a/packages/integrations/netlify/test/functions/base64-response.test.js b/packages/integrations/netlify/test/functions/base64-response.test.js index 064cff1542bd..12eca045cd28 100644 --- a/packages/integrations/netlify/test/functions/base64-response.test.js +++ b/packages/integrations/netlify/test/functions/base64-response.test.js @@ -9,10 +9,8 @@ describe('Base64 Responses', () => { before(async () => { fixture = await loadFixture({ root: new URL('./fixtures/base64-response/', import.meta.url).toString(), - experimental: { - ssr: true, - }, - adapter: netlifyAdapter({ + mode: 'server', + deploy: netlifyAdapter({ dist: new URL('./fixtures/base64-response/dist/', import.meta.url), binaryMediaTypes: ['font/otf'], }), diff --git a/packages/integrations/netlify/test/functions/cookies.test.js b/packages/integrations/netlify/test/functions/cookies.test.js index e9121b429377..95ebc7ef24ea 100644 --- a/packages/integrations/netlify/test/functions/cookies.test.js +++ b/packages/integrations/netlify/test/functions/cookies.test.js @@ -11,10 +11,8 @@ describe('Cookies', () => { before(async () => { fixture = await loadFixture({ root: new URL('./fixtures/cookies/', import.meta.url).toString(), - experimental: { - ssr: true, - }, - adapter: netlifyAdapter({ + mode: 'server', + deploy: netlifyAdapter({ dist: new URL('./fixtures/cookies/dist/', import.meta.url), }), site: `http://example.com`, diff --git a/packages/integrations/netlify/test/functions/dynamic-route.test.js b/packages/integrations/netlify/test/functions/dynamic-route.test.js index 8c8977f7efb2..0e0120bf1f4f 100644 --- a/packages/integrations/netlify/test/functions/dynamic-route.test.js +++ b/packages/integrations/netlify/test/functions/dynamic-route.test.js @@ -9,10 +9,8 @@ describe('Dynamic pages', () => { before(async () => { fixture = await loadFixture({ root: new URL('./fixtures/dynamic-route/', import.meta.url).toString(), - experimental: { - ssr: true, - }, - adapter: netlifyAdapter({ + mode: 'server', + deploy: netlifyAdapter({ dist: new URL('./fixtures/dynamic-route/dist/', import.meta.url), }), site: `http://example.com`, diff --git a/packages/integrations/node/README.md b/packages/integrations/node/README.md index 3772a23d8d08..464804349f3f 100644 --- a/packages/integrations/node/README.md +++ b/packages/integrations/node/README.md @@ -37,7 +37,8 @@ import node from '@astrojs/node'; export default defineConfig({ // ... - adapter: node() + mode: 'server', + deploy: node() }) ``` diff --git a/packages/integrations/vercel/README.md b/packages/integrations/vercel/README.md index aaab5eb40520..408361a5fa07 100644 --- a/packages/integrations/vercel/README.md +++ b/packages/integrations/vercel/README.md @@ -25,7 +25,7 @@ First, install the `@astrojs/vercel` package using your package manager. If you' npm install @astrojs/vercel ``` -Then, install this adapter in your `astro.config.*` file using the `adapter` property (note the import from `@astrojs/vercel/serverless` - see [targets](#targets)). +Then, install this adapter in your `astro.config.*` file using the `deploy` property (note the import from `@astrojs/vercel/serverless` - see [targets](#targets)). __`astro.config.mjs`__ @@ -34,7 +34,8 @@ import { defineConfig } from 'astro/config'; import vercel from '@astrojs/vercel/serverless'; export default defineConfig({ - adapter: vercel() + mode: 'server', + deploy: vercel() }); ``` From 4d06b4fb89966f894a9b5c841c29df926069b3d8 Mon Sep 17 00:00:00 2001 From: Matthew Phillips Date: Fri, 22 Jul 2022 11:30:23 -0400 Subject: [PATCH 11/19] Oops --- packages/astro/src/core/util.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/astro/src/core/util.ts b/packages/astro/src/core/util.ts index fbf3b1eb0a9c..95cabf883f09 100644 --- a/packages/astro/src/core/util.ts +++ b/packages/astro/src/core/util.ts @@ -183,7 +183,7 @@ export function isPage(file: URL, config: AstroConfig): boolean { } export function isModeServerWithNoAdapter(config: AstroConfig): boolean { - return config.mode === 'static' && !config._ctx.adapter; + return config.mode === 'server' && !config._ctx.adapter; } export function emoji(char: string, fallback: string) { From 71259525d7d069e2938cba64ae8efa4cb76b67db Mon Sep 17 00:00:00 2001 From: Matthew Phillips Date: Fri, 22 Jul 2022 11:33:36 -0400 Subject: [PATCH 12/19] Remove old option --- packages/integrations/vercel/src/static/adapter.ts | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/packages/integrations/vercel/src/static/adapter.ts b/packages/integrations/vercel/src/static/adapter.ts index 50f9cb757cca..abc9483f5f6b 100644 --- a/packages/integrations/vercel/src/static/adapter.ts +++ b/packages/integrations/vercel/src/static/adapter.ts @@ -23,13 +23,7 @@ export default function vercelStatic(): AstroIntegration { setAdapter(getAdapter()); _config = config; }, - 'astro:build:start': async ({ buildConfig }) => { - if (String(process.env.ENABLE_VC_BUILD) !== '1') { - throw new Error( - `The enviroment variable "ENABLE_VC_BUILD" was not found. Make sure you have it set to "1" in your Vercel project.\nLearn how to set enviroment variables here: https://vercel.com/docs/concepts/projects/environment-variables` - ); - } - + 'astro:build:start': async () => { // Ensure to have `.vercel/output` empty. // This is because, when building to static, outDir = .vercel/output/static/, // so .vercel/output itself won't get cleaned. From a5ffe45eca8909b6f62d2abd1937230d1d1be9b5 Mon Sep 17 00:00:00 2001 From: Matthew Phillips Date: Fri, 22 Jul 2022 15:40:46 -0400 Subject: [PATCH 13/19] Rename `mode` to `output` --- .changeset/famous-coins-destroy.md | 4 ++-- examples/ssr/astro.config.mjs | 2 +- packages/astro/src/@types/astro.ts | 22 +++++++++++++++++-- packages/astro/src/core/build/generate.ts | 4 ++-- packages/astro/src/core/build/index.ts | 6 ++--- packages/astro/src/core/build/page-data.ts | 2 +- packages/astro/src/core/build/static-build.ts | 16 +++++++------- .../astro/src/core/build/vite-plugin-pages.ts | 2 +- packages/astro/src/core/config.ts | 2 +- packages/astro/src/core/endpoint/dev/index.ts | 2 +- packages/astro/src/core/render/dev/index.ts | 2 +- packages/astro/src/core/util.ts | 2 +- packages/astro/src/integrations/index.ts | 2 +- .../src/vite-plugin-astro-server/index.ts | 4 ++-- packages/astro/test/client-address.test.js | 6 ++--- packages/astro/test/config-mode.test.js | 12 +++++----- .../static-build-ssr/astro.config.mjs | 2 +- .../test/ssr-adapter-build-config.test.js | 2 +- packages/astro/test/ssr-api-route.test.js | 2 +- packages/astro/test/ssr-assets.test.js | 2 +- packages/astro/test/ssr-dynamic.test.js | 2 +- packages/astro/test/ssr-env.test.js | 2 +- .../astro/test/ssr-hoisted-script.test.js | 2 +- packages/astro/test/ssr-large-array.test.js | 2 +- packages/astro/test/ssr-lit.test.js | 2 +- packages/astro/test/ssr-markdown.test.js | 2 +- packages/astro/test/ssr-partytown.test.js | 2 +- packages/astro/test/ssr-redirect.test.js | 2 +- packages/astro/test/ssr-request.test.js | 2 +- packages/astro/test/ssr-response.test.js | 2 +- packages/astro/test/ssr-scripts.test.js | 2 +- packages/astro/test/streaming.test.js | 4 ++-- packages/integrations/cloudflare/README.md | 2 +- packages/integrations/cloudflare/src/index.ts | 2 +- packages/integrations/deno/README.md | 8 +++---- packages/integrations/deno/src/index.ts | 2 +- .../test/fixtures/basics/astro.config.mjs | 2 +- .../test/fixtures/dynimport/astro.config.mjs | 2 +- packages/integrations/image/src/index.ts | 6 ++--- .../integrations/image/test/image-ssr.test.js | 4 ++-- .../image/test/picture-ssr.test.js | 4 ++-- packages/integrations/netlify/README.md | 6 ++--- .../netlify/src/integration-edge-functions.ts | 2 +- .../netlify/src/integration-functions.ts | 2 +- .../fixtures/dynimport/astro.config.mjs | 2 +- .../fixtures/edge-basic/astro.config.mjs | 2 +- .../fixtures/root-dynamic/astro.config.mjs | 2 +- .../test/functions/base64-response.test.js | 2 +- .../netlify/test/functions/cookies.test.js | 2 +- .../test/functions/dynamic-route.test.js | 2 +- packages/integrations/node/README.md | 2 +- packages/integrations/node/src/index.ts | 2 +- packages/integrations/vercel/README.md | 2 +- 53 files changed, 101 insertions(+), 83 deletions(-) diff --git a/.changeset/famous-coins-destroy.md b/.changeset/famous-coins-destroy.md index 3c595414fd83..4118e25754ab 100644 --- a/.changeset/famous-coins-destroy.md +++ b/.changeset/famous-coins-destroy.md @@ -18,7 +18,7 @@ This change introduces a new configuration option `mode`. Mode can be either The default, `static`, can be omitted from your config file. -If you want to use SSR you now need to provide `mode: 'server'` *in addition* to an adapter. +If you want to use SSR you now need to provide `output: 'server'` *in addition* to an adapter. The `adapter` configuration has been renamed to `deploy`. In the future adapters will support configuring a static site as well! @@ -31,6 +31,6 @@ import netlify from '@astrojs/netlify/functions'; export default defineConfig({ - adapter: netlify(), + deploy: netlify(), -+ mode: 'server', ++ output: 'server', }); ``` diff --git a/examples/ssr/astro.config.mjs b/examples/ssr/astro.config.mjs index c14390a100d3..602020a718be 100644 --- a/examples/ssr/astro.config.mjs +++ b/examples/ssr/astro.config.mjs @@ -4,7 +4,7 @@ import node from '@astrojs/node'; // https://astro.build/config export default defineConfig({ - mode: 'server', + output: 'server', deploy: node(), integrations: [svelte()], }); diff --git a/packages/astro/src/@types/astro.ts b/packages/astro/src/@types/astro.ts index e2ff5cd0f76c..8012abe34d41 100644 --- a/packages/astro/src/@types/astro.ts +++ b/packages/astro/src/@types/astro.ts @@ -638,8 +638,26 @@ export interface AstroUserConfig { */ deploy?: AstroIntegration; - // TODO: Document - mode?: 'static' | 'server'; + /** + * @docs + * @kind heading + * @name Output + * @description + * + * Specifies the output target for builds. + * + * - 'static' - Building a static site to be deploy to any static host. + * - 'server' - Building an app to be deployed to a host supporting SSR (server-side rendering). + * + * ```js + * import { defineConfig } from 'astro/config'; + * + * export default defineConfig({ + * output: 'static' + * }) + * ``` + */ + output?: 'static' | 'server'; /** diff --git a/packages/astro/src/core/build/generate.ts b/packages/astro/src/core/build/generate.ts index 4b2f8d55cb7b..56dc36c76114 100644 --- a/packages/astro/src/core/build/generate.ts +++ b/packages/astro/src/core/build/generate.ts @@ -97,7 +97,7 @@ export async function generatePages( const timer = performance.now(); info(opts.logging, null, `\n${bgGreen(black(' generating static routes '))}`); - const ssr = opts.astroConfig.mode === 'server'; + const ssr = opts.astroConfig.output === 'server'; const serverEntry = opts.buildConfig.serverEntry; const outFolder = ssr ? opts.buildConfig.server : opts.astroConfig.outDir; const ssrEntryURL = new URL('./' + serverEntry + `?time=${Date.now()}`, outFolder); @@ -207,7 +207,7 @@ async function generatePath( } } - const ssr = opts.astroConfig.mode === 'server'; + const ssr = opts.astroConfig.output === 'server'; const url = new URL(opts.astroConfig.base + removeLeadingForwardSlash(pathname), origin); const options: RenderOptions = { adapterName: undefined, diff --git a/packages/astro/src/core/build/index.ts b/packages/astro/src/core/build/index.ts index 5da8bd295074..08e7b40bc6f9 100644 --- a/packages/astro/src/core/build/index.ts +++ b/packages/astro/src/core/build/index.ts @@ -102,7 +102,7 @@ class AstroBuilder { await runHookBuildStart({ config: this.config, buildConfig }); const getPrettyDeployTarget = (adapter: AstroAdapter | undefined) => adapter?.name || 'unknown'; - info(this.logging, 'build', `build target: ${colors.green(this.config.mode)}`); + info(this.logging, 'build', `build target: ${colors.green(this.config.output)}`); info(this.logging, 'build', `deploy target: ${colors.green(getPrettyDeployTarget(this.config._ctx.adapter))}`); info(this.logging, 'build', 'Collecting build info...'); this.timer.loadStart = performance.now(); @@ -113,7 +113,7 @@ class AstroBuilder { origin, routeCache: this.routeCache, viteServer, - ssr: this.config.mode === 'server', + ssr: this.config.output === 'server', }); debug('build', timerMessage('All pages loaded', this.timer.loadStart)); @@ -174,7 +174,7 @@ class AstroBuilder { logging: this.logging, timeStart: this.timer.init, pageCount: pageNames.length, - buildMode: this.config.mode, + buildMode: this.config.output, }); } } diff --git a/packages/astro/src/core/build/page-data.ts b/packages/astro/src/core/build/page-data.ts index 03bf649866f7..74c1e45aa995 100644 --- a/packages/astro/src/core/build/page-data.ts +++ b/packages/astro/src/core/build/page-data.ts @@ -68,7 +68,7 @@ export async function collectPagesData( }; clearInterval(routeCollectionLogTimeout); - if (astroConfig.mode === 'static') { + if (astroConfig.output === 'static') { const html = `${route.pathname}`.replace(/\/?$/, '/index.html'); debug( 'build', diff --git a/packages/astro/src/core/build/static-build.ts b/packages/astro/src/core/build/static-build.ts index 0606aec19b04..a0b0f91eb54a 100644 --- a/packages/astro/src/core/build/static-build.ts +++ b/packages/astro/src/core/build/static-build.ts @@ -26,10 +26,10 @@ export async function staticBuild(opts: StaticBuildOptions) { // Verify this app is buildable. if(isModeServerWithNoAdapter(opts.astroConfig)) { - throw new Error(`Cannot use mode: 'server' without an adapter. Please install and configure an adapter by setting it on the deploy configuration. + throw new Error(`Cannot use output: 'server' without an adapter. Please install and configure an adapter by setting it on the deploy configuration. export default { - mode: 'static', + output: 'static', adapter: netlify(), }`) } @@ -69,7 +69,7 @@ export default { info( opts.logging, 'build', - `Building ${astroConfig.mode} entrypoints...` + `Building ${astroConfig.output} entrypoints...` ); const ssrResult = (await ssrBuild(opts, internals, pageInput)) as RollupOutput; info(opts.logging, 'build', dim(`Completed in ${getTimeStat(timer.ssr, performance.now())}.`)); @@ -90,7 +90,7 @@ export default { await clientBuild(opts, internals, clientInput); timer.generate = performance.now(); - if (astroConfig.mode === 'static') { + if (astroConfig.output === 'static') { try { await generatePages(ssrResult, opts, internals, facadeIdToPageDataMap); } finally { @@ -107,7 +107,7 @@ export default { async function ssrBuild(opts: StaticBuildOptions, internals: BuildInternals, input: Set) { const { astroConfig, viteConfig } = opts; - const ssr = astroConfig.mode === 'server'; + const ssr = astroConfig.output === 'server'; const out = ssr ? opts.buildConfig.server : astroConfig.outDir; const viteBuildConfig: ViteConfigWithSSR = { @@ -151,7 +151,7 @@ async function ssrBuild(opts: StaticBuildOptions, internals: BuildInternals, inp }), ...(viteConfig.plugins || []), // SSR needs to be last - opts.astroConfig.mode === 'server' && vitePluginSSR(internals, opts.astroConfig._ctx.adapter!), + opts.astroConfig.output === 'server' && vitePluginSSR(internals, opts.astroConfig._ctx.adapter!), vitePluginAnalyzer(opts.astroConfig, internals), ], publicDir: ssr ? false : viteConfig.publicDir, @@ -181,7 +181,7 @@ async function clientBuild( ) { const { astroConfig, viteConfig } = opts; const timer = performance.now(); - const ssr = astroConfig.mode === 'server'; + const ssr = astroConfig.output === 'server'; const out = ssr ? opts.buildConfig.client : astroConfig.outDir; // Nothing to do if there is no client-side JS. @@ -282,7 +282,7 @@ async function copyFiles(fromFolder: URL, toFolder: URL) { async function ssrMoveAssets(opts: StaticBuildOptions) { info(opts.logging, 'build', 'Rearranging server assets...'); - const serverRoot = opts.astroConfig.mode === 'static' + const serverRoot = opts.astroConfig.output === 'static' ? opts.buildConfig.client : opts.buildConfig.server; const clientRoot = opts.buildConfig.client; diff --git a/packages/astro/src/core/build/vite-plugin-pages.ts b/packages/astro/src/core/build/vite-plugin-pages.ts index bba2e5b9cac7..ceaf87eebfe3 100644 --- a/packages/astro/src/core/build/vite-plugin-pages.ts +++ b/packages/astro/src/core/build/vite-plugin-pages.ts @@ -10,7 +10,7 @@ export function vitePluginPages(opts: StaticBuildOptions, internals: BuildIntern name: '@astro/plugin-build-pages', options(options) { - if (opts.astroConfig.mode === 'static') { + if (opts.astroConfig.output === 'static') { return addRollupInput(options, [pagesVirtualModuleId]); } }, diff --git a/packages/astro/src/core/config.ts b/packages/astro/src/core/config.ts index 19cd178ba314..632112f6be26 100644 --- a/packages/astro/src/core/config.ts +++ b/packages/astro/src/core/config.ts @@ -124,7 +124,7 @@ export const AstroConfigSchema = z.object({ .union([z.literal('always'), z.literal('never'), z.literal('ignore')]) .optional() .default(ASTRO_CONFIG_DEFAULTS.trailingSlash), - mode: z + output: z .union([z.literal('static'), z.literal('server')]) .optional() .default('static'), diff --git a/packages/astro/src/core/endpoint/dev/index.ts b/packages/astro/src/core/endpoint/dev/index.ts index 61e04892be75..342c9a4f400d 100644 --- a/packages/astro/src/core/endpoint/dev/index.ts +++ b/packages/astro/src/core/endpoint/dev/index.ts @@ -7,6 +7,6 @@ export async function call(ssrOpts: SSROptions) { const [, mod] = await preload(ssrOpts); return await callEndpoint(mod as unknown as EndpointHandler, { ...ssrOpts, - ssr: ssrOpts.astroConfig.mode === 'server', + ssr: ssrOpts.astroConfig.output === 'server', }); } diff --git a/packages/astro/src/core/render/dev/index.ts b/packages/astro/src/core/render/dev/index.ts index d1b8a13c40c8..f140baa3841d 100644 --- a/packages/astro/src/core/render/dev/index.ts +++ b/packages/astro/src/core/render/dev/index.ts @@ -183,7 +183,7 @@ export async function render( route, routeCache, site: astroConfig.site ? new URL(astroConfig.base, astroConfig.site).toString() : undefined, - ssr: astroConfig.mode === 'server', + ssr: astroConfig.output === 'server', streaming: true, }); diff --git a/packages/astro/src/core/util.ts b/packages/astro/src/core/util.ts index 95cabf883f09..4ba0a7286649 100644 --- a/packages/astro/src/core/util.ts +++ b/packages/astro/src/core/util.ts @@ -183,7 +183,7 @@ export function isPage(file: URL, config: AstroConfig): boolean { } export function isModeServerWithNoAdapter(config: AstroConfig): boolean { - return config.mode === 'server' && !config._ctx.adapter; + return config.output === 'server' && !config._ctx.adapter; } export function emoji(char: string, fallback: string) { diff --git a/packages/astro/src/integrations/index.ts b/packages/astro/src/integrations/index.ts index ffbc4b575f9d..05e1a865d06c 100644 --- a/packages/astro/src/integrations/index.ts +++ b/packages/astro/src/integrations/index.ts @@ -189,7 +189,7 @@ export async function runHookBuildDone({ pages: string[]; routes: RouteData[]; }) { - const dir = config.mode === 'server' ? buildConfig.client : config.outDir; + const dir = config.output === 'server' ? buildConfig.client : config.outDir; for (const integration of config.integrations) { if (integration?.hooks?.['astro:build:done']) { diff --git a/packages/astro/src/vite-plugin-astro-server/index.ts b/packages/astro/src/vite-plugin-astro-server/index.ts index 625193d648f8..3f073529b397 100644 --- a/packages/astro/src/vite-plugin-astro-server/index.ts +++ b/packages/astro/src/vite-plugin-astro-server/index.ts @@ -205,7 +205,7 @@ async function handleRequest( ) { const reqStart = performance.now(); const origin = `${viteServer.config.server.https ? 'https' : 'http'}://${req.headers.host}`; - const buildingToSSR = config.mode === 'server'; + const buildingToSSR = config.output === 'server'; // Ignore `.html` extensions and `index.html` in request URLS to ensure that // routing behavior matches production builds. This supports both file and directory // build formats, and is necessary based on how the manifest tracks build targets. @@ -276,7 +276,7 @@ async function handleRequest( routeCache, pathname: pathname, logging, - ssr: config.mode === 'server', + ssr: config.output === 'server', }); if (paramsAndPropsRes === GetParamsAndPropsError.NoMatchingStaticPath) { warn( diff --git a/packages/astro/test/client-address.test.js b/packages/astro/test/client-address.test.js index 73d28481d528..85eea189c4a3 100644 --- a/packages/astro/test/client-address.test.js +++ b/packages/astro/test/client-address.test.js @@ -12,7 +12,7 @@ describe('Astro.clientAddress', () => { before(async () => { fixture = await loadFixture({ root: './fixtures/client-address/', - mode: 'server', + output: 'server', deploy: testAdapter(), }); }); @@ -65,7 +65,7 @@ describe('Astro.clientAddress', () => { before(async () => { fixture = await loadFixture({ root: './fixtures/client-address/', - mode: 'server', + output: 'server', deploy: testAdapter({ provideAddress: false }), }); await fixture.build(); @@ -86,7 +86,7 @@ describe('Astro.clientAddress', () => { before(async () => { fixture = await loadFixture({ root: './fixtures/client-address/', - mode: 'static', + output: 'static', }); }); diff --git a/packages/astro/test/config-mode.test.js b/packages/astro/test/config-mode.test.js index 6393fddfd525..054bc34cee09 100644 --- a/packages/astro/test/config-mode.test.js +++ b/packages/astro/test/config-mode.test.js @@ -4,7 +4,7 @@ import { loadFixture } from './test-utils.js'; import testAdapter from './test-adapter.js'; describe('AstroConfig - config.mode', () => { - describe(`mode: 'server'`, () => { + describe(`output: 'server'`, () => { describe('deploy config provided', () => { /** @type {import('./test-utils').Fixture} */ let fixture; @@ -14,7 +14,7 @@ describe('AstroConfig - config.mode', () => { // This is just a random fixture to test, doesn't matter. root: './fixtures/astro-basic/', deploy: testAdapter(), - mode: 'server', + output: 'server', }); await fixture.build(); }); @@ -38,7 +38,7 @@ describe('AstroConfig - config.mode', () => { fixture = await loadFixture({ // This is just a random fixture to test, doesn't matter. root: './fixtures/astro-basic/', - mode: 'server' + output: 'server' }); }); @@ -58,7 +58,7 @@ describe('AstroConfig - config.mode', () => { }); }); - describe(`mode: 'static'`, () => { + describe(`output: 'static'`, () => { describe('Deploy config omitted', () => { /** @type {import('./test-utils').Fixture} */ let fixture; @@ -67,7 +67,7 @@ describe('AstroConfig - config.mode', () => { fixture = await loadFixture({ // This is just a random fixture to test, doesn't matter. root: './fixtures/astro-basic/', - mode: 'static' + output: 'static' }); await fixture.build(); }); @@ -92,7 +92,7 @@ describe('AstroConfig - config.mode', () => { // This is just a random fixture to test, doesn't matter. root: './fixtures/astro-basic/', deploy: testAdapter(), - mode: 'server' + output: 'server' }); await fixture.build(); }); diff --git a/packages/astro/test/fixtures/static-build-ssr/astro.config.mjs b/packages/astro/test/fixtures/static-build-ssr/astro.config.mjs index 775beb317ecd..2af420d69262 100644 --- a/packages/astro/test/fixtures/static-build-ssr/astro.config.mjs +++ b/packages/astro/test/fixtures/static-build-ssr/astro.config.mjs @@ -3,5 +3,5 @@ import nodejs from '@astrojs/node'; export default defineConfig({ deploy: nodejs(), - mode: 'server', + output: 'server', }); diff --git a/packages/astro/test/ssr-adapter-build-config.test.js b/packages/astro/test/ssr-adapter-build-config.test.js index 567b190fbd89..968a86834339 100644 --- a/packages/astro/test/ssr-adapter-build-config.test.js +++ b/packages/astro/test/ssr-adapter-build-config.test.js @@ -11,7 +11,7 @@ describe('Integration buildConfig hook', () => { let _config; fixture = await loadFixture({ root: './fixtures/ssr-request/', - mode: 'server', + output: 'server', deploy: { name: 'my-ssr-adapter', hooks: { diff --git a/packages/astro/test/ssr-api-route.test.js b/packages/astro/test/ssr-api-route.test.js index 8232754c098a..4af48e36a843 100644 --- a/packages/astro/test/ssr-api-route.test.js +++ b/packages/astro/test/ssr-api-route.test.js @@ -9,7 +9,7 @@ describe('API routes in SSR', () => { before(async () => { fixture = await loadFixture({ root: './fixtures/ssr-api-route/', - mode: 'server', + output: 'server', deploy: testAdapter(), }); await fixture.build(); diff --git a/packages/astro/test/ssr-assets.test.js b/packages/astro/test/ssr-assets.test.js index 7b92d6809396..a261ff9dc0f1 100644 --- a/packages/astro/test/ssr-assets.test.js +++ b/packages/astro/test/ssr-assets.test.js @@ -9,7 +9,7 @@ describe('SSR Assets', () => { before(async () => { fixture = await loadFixture({ root: './fixtures/ssr-assets/', - mode: 'server', + output: 'server', deploy: testAdapter(), }); await fixture.build(); diff --git a/packages/astro/test/ssr-dynamic.test.js b/packages/astro/test/ssr-dynamic.test.js index 36861026d02c..21a3103695e2 100644 --- a/packages/astro/test/ssr-dynamic.test.js +++ b/packages/astro/test/ssr-dynamic.test.js @@ -10,7 +10,7 @@ describe('Dynamic pages in SSR', () => { before(async () => { fixture = await loadFixture({ root: './fixtures/ssr-dynamic/', - mode: 'server', + output: 'server', deploy: testAdapter(), }); await fixture.build(); diff --git a/packages/astro/test/ssr-env.test.js b/packages/astro/test/ssr-env.test.js index 9156b725e516..c4eea6684d59 100644 --- a/packages/astro/test/ssr-env.test.js +++ b/packages/astro/test/ssr-env.test.js @@ -10,7 +10,7 @@ describe('SSR Environment Variables', () => { before(async () => { fixture = await loadFixture({ root: './fixtures/ssr-env/', - mode: 'server', + output: 'server', deploy: testAdapter(), }); await fixture.build(); diff --git a/packages/astro/test/ssr-hoisted-script.test.js b/packages/astro/test/ssr-hoisted-script.test.js index 4e0866c34437..cb87a7c41ae3 100644 --- a/packages/astro/test/ssr-hoisted-script.test.js +++ b/packages/astro/test/ssr-hoisted-script.test.js @@ -10,7 +10,7 @@ describe('Hoisted scripts in SSR', () => { before(async () => { fixture = await loadFixture({ root: './fixtures/ssr-hoisted-script/', - mode: 'server', + output: 'server', deploy: testAdapter(), }); await fixture.build(); diff --git a/packages/astro/test/ssr-large-array.test.js b/packages/astro/test/ssr-large-array.test.js index 114c0e8816c6..7d600c377d7b 100644 --- a/packages/astro/test/ssr-large-array.test.js +++ b/packages/astro/test/ssr-large-array.test.js @@ -10,7 +10,7 @@ describe('SSR with Large Array and client rendering', () => { before(async () => { fixture = await loadFixture({ root: './fixtures/large-array/', - mode: 'server', + output: 'server', deploy: testAdapter(), }); await fixture.build(); diff --git a/packages/astro/test/ssr-lit.test.js b/packages/astro/test/ssr-lit.test.js index fc39ff437ad3..20d69e42108f 100644 --- a/packages/astro/test/ssr-lit.test.js +++ b/packages/astro/test/ssr-lit.test.js @@ -10,7 +10,7 @@ describe('Lit integration in SSR', () => { before(async () => { fixture = await loadFixture({ root: './fixtures/lit-element/', - mode: 'server', + output: 'server', deploy: testAdapter(), }); await fixture.build(); diff --git a/packages/astro/test/ssr-markdown.test.js b/packages/astro/test/ssr-markdown.test.js index 5c9211dc24f3..809ee0a83dd9 100644 --- a/packages/astro/test/ssr-markdown.test.js +++ b/packages/astro/test/ssr-markdown.test.js @@ -10,7 +10,7 @@ describe('Markdown pages in SSR', () => { before(async () => { fixture = await loadFixture({ root: './fixtures/ssr-markdown/', - mode: 'server', + output: 'server', deploy: testAdapter(), }); await fixture.build(); diff --git a/packages/astro/test/ssr-partytown.test.js b/packages/astro/test/ssr-partytown.test.js index a4735a5633c2..62df9a488098 100644 --- a/packages/astro/test/ssr-partytown.test.js +++ b/packages/astro/test/ssr-partytown.test.js @@ -11,7 +11,7 @@ describe('Using the Partytown integration in SSR', () => { fixture = await loadFixture({ root: './fixtures/ssr-partytown/', deploy: testAdapter(), - mode: 'server' + output: 'server' }); await fixture.build(); }); diff --git a/packages/astro/test/ssr-redirect.test.js b/packages/astro/test/ssr-redirect.test.js index 8035c458aaed..9c64cc4a9fca 100644 --- a/packages/astro/test/ssr-redirect.test.js +++ b/packages/astro/test/ssr-redirect.test.js @@ -9,7 +9,7 @@ describe('Astro.redirect', () => { before(async () => { fixture = await loadFixture({ root: './fixtures/ssr-redirect/', - mode: 'server', + output: 'server', deploy: testAdapter(), }); await fixture.build(); diff --git a/packages/astro/test/ssr-request.test.js b/packages/astro/test/ssr-request.test.js index e8c37fd1c974..f79e9c7d0e6d 100644 --- a/packages/astro/test/ssr-request.test.js +++ b/packages/astro/test/ssr-request.test.js @@ -11,7 +11,7 @@ describe('Using Astro.request in SSR', () => { fixture = await loadFixture({ root: './fixtures/ssr-request/', deploy: testAdapter(), - mode: 'server' + output: 'server' }); await fixture.build(); }); diff --git a/packages/astro/test/ssr-response.test.js b/packages/astro/test/ssr-response.test.js index 55fdd1c2d6df..7627456363a1 100644 --- a/packages/astro/test/ssr-response.test.js +++ b/packages/astro/test/ssr-response.test.js @@ -11,7 +11,7 @@ describe('Using Astro.response in SSR', () => { fixture = await loadFixture({ root: './fixtures/ssr-response/', deploy: testAdapter(), - mode: 'server' + output: 'server' }); await fixture.build(); }); diff --git a/packages/astro/test/ssr-scripts.test.js b/packages/astro/test/ssr-scripts.test.js index dfe194cea999..fa768290118d 100644 --- a/packages/astro/test/ssr-scripts.test.js +++ b/packages/astro/test/ssr-scripts.test.js @@ -9,7 +9,7 @@ describe('SSR Hydrated component scripts', () => { before(async () => { fixture = await loadFixture({ root: './fixtures/ssr-scripts/', - mode: 'server', + output: 'server', deploy: testAdapter(), }); await fixture.build(); diff --git a/packages/astro/test/streaming.test.js b/packages/astro/test/streaming.test.js index 37babbe0a034..1fcbfeaafb78 100644 --- a/packages/astro/test/streaming.test.js +++ b/packages/astro/test/streaming.test.js @@ -13,7 +13,7 @@ describe('Streaming', () => { fixture = await loadFixture({ root: './fixtures/streaming/', deploy: testAdapter(), - mode: 'server' + output: 'server' }); }); @@ -80,7 +80,7 @@ describe('Streaming disabled', () => { fixture = await loadFixture({ root: './fixtures/streaming/', deploy: testAdapter(), - mode: 'server', + output: 'server', server: { streaming: false, }, diff --git a/packages/integrations/cloudflare/README.md b/packages/integrations/cloudflare/README.md index 0b7ab4031ce8..596cd4673d7d 100644 --- a/packages/integrations/cloudflare/README.md +++ b/packages/integrations/cloudflare/README.md @@ -9,7 +9,7 @@ import { defineConfig } from 'astro/config'; import cloudflare from '@astrojs/cloudflare'; export default defineConfig({ - mode: 'server', + output: 'server', deploy: cloudflare() }); ``` diff --git a/packages/integrations/cloudflare/src/index.ts b/packages/integrations/cloudflare/src/index.ts index e34880ebc16b..b3dbf4b262e2 100644 --- a/packages/integrations/cloudflare/src/index.ts +++ b/packages/integrations/cloudflare/src/index.ts @@ -22,7 +22,7 @@ export default function createIntegration(): AstroIntegration { setAdapter(getAdapter()); _config = config; - if(config.mode === 'static') { + if(config.output === 'static') { console.warn(`@astrojs/cloudflare does not support static mode.`); } }, diff --git a/packages/integrations/deno/README.md b/packages/integrations/deno/README.md index ddb322bea9b8..9b9131af8c32 100644 --- a/packages/integrations/deno/README.md +++ b/packages/integrations/deno/README.md @@ -37,7 +37,7 @@ import deno from '@astrojs/deno'; export default defineConfig({ // ... - mode: 'server', + output: 'server', deploy: deno() }); ``` @@ -70,7 +70,7 @@ import { defineConfig } from 'astro/config'; import deno from '@astrojs/deno'; export default defineConfig({ - mode: 'server', + output: 'server', deploy: deno({ //options go here }) @@ -87,7 +87,7 @@ export default defineConfig({ import deno from '@astrojs/deno'; export default defineConfig({ - mode: 'server', + output: 'server', deploy: deno({ start: false }) @@ -118,7 +118,7 @@ export default defineConfig({ import deno from '@astrojs/deno'; export default defineConfig({ - mode: 'server', + output: 'server', deploy: deno({ port: 8081, hostname: 'myhost' diff --git a/packages/integrations/deno/src/index.ts b/packages/integrations/deno/src/index.ts index cd8636327df1..8bc58c9dbc1c 100644 --- a/packages/integrations/deno/src/index.ts +++ b/packages/integrations/deno/src/index.ts @@ -32,7 +32,7 @@ export default function createIntegration(args?: Options): AstroIntegration { 'astro:config:done': ({ setAdapter, config }) => { setAdapter(getAdapter(args)); - if(config.mode === 'static') { + if(config.output === 'static') { console.warn(`@astrojs/deno does not support static mode.`); } }, diff --git a/packages/integrations/deno/test/fixtures/basics/astro.config.mjs b/packages/integrations/deno/test/fixtures/basics/astro.config.mjs index d70d49ed8f00..d24e1f45a07d 100644 --- a/packages/integrations/deno/test/fixtures/basics/astro.config.mjs +++ b/packages/integrations/deno/test/fixtures/basics/astro.config.mjs @@ -5,5 +5,5 @@ import react from '@astrojs/react'; export default defineConfig({ deploy: deno(), integrations: [react()], - mode: 'server', + output: 'server', }) diff --git a/packages/integrations/deno/test/fixtures/dynimport/astro.config.mjs b/packages/integrations/deno/test/fixtures/dynimport/astro.config.mjs index 73ed78f1deb7..85a52c649827 100644 --- a/packages/integrations/deno/test/fixtures/dynimport/astro.config.mjs +++ b/packages/integrations/deno/test/fixtures/dynimport/astro.config.mjs @@ -3,5 +3,5 @@ import deno from '@astrojs/deno'; export default defineConfig({ deploy: deno(), - mode: 'server', + output: 'server', }) diff --git a/packages/integrations/image/src/index.ts b/packages/integrations/image/src/index.ts index 836419974157..08935bf289bd 100644 --- a/packages/integrations/image/src/index.ts +++ b/packages/integrations/image/src/index.ts @@ -46,7 +46,7 @@ const createIntegration = (options: IntegrationOptions = {}): AstroIntegration = _config = config; // Always treat `astro dev` as SSR mode, even without an adapter - const mode: 'server' | 'static' = command === 'dev' ? 'server' : config.mode; + const output: 'server' | 'static' = command === 'dev' ? 'server' : config.output; updateConfig({ vite: getViteConfiguration() }); @@ -58,7 +58,7 @@ const createIntegration = (options: IntegrationOptions = {}): AstroIntegration = // TODO: Add support for custom, user-provided filename format functions function filenameFormat(transform: TransformOptions, searchParams: URLSearchParams) { - if (mode === 'static') { + if (output === 'static') { return isRemoteImage(transform.src) ? path.join(OUTPUT_DIR, path.basename(propsToFilename(transform))) : path.join( @@ -81,7 +81,7 @@ const createIntegration = (options: IntegrationOptions = {}): AstroIntegration = filenameFormat, }; - if (mode === 'server') { + if (output === 'server') { injectRoute({ pattern: ROUTE_PATTERN, entryPoint: diff --git a/packages/integrations/image/test/image-ssr.test.js b/packages/integrations/image/test/image-ssr.test.js index 6d9293ff23ac..4e5aa2f43cee 100644 --- a/packages/integrations/image/test/image-ssr.test.js +++ b/packages/integrations/image/test/image-ssr.test.js @@ -10,7 +10,7 @@ describe('SSR images - build', function () { fixture = await loadFixture({ root: './fixtures/basic-image/', deploy: testAdapter(), - mode: 'server', + output: 'server', }); await fixture.build(); }); @@ -122,7 +122,7 @@ describe('SSR images - dev', function () { fixture = await loadFixture({ root: './fixtures/basic-image/', deploy: testAdapter(), - mode: 'server', + output: 'server', }); devServer = await fixture.startDevServer(); diff --git a/packages/integrations/image/test/picture-ssr.test.js b/packages/integrations/image/test/picture-ssr.test.js index 2712fdf5d784..c4b28ab8e3e4 100644 --- a/packages/integrations/image/test/picture-ssr.test.js +++ b/packages/integrations/image/test/picture-ssr.test.js @@ -10,7 +10,7 @@ describe('SSR pictures - build', function () { fixture = await loadFixture({ root: './fixtures/basic-picture/', deploy: testAdapter(), - mode: 'server', + output: 'server', }); await fixture.build(); }); @@ -170,7 +170,7 @@ describe('SSR images - dev', function () { fixture = await loadFixture({ root: './fixtures/basic-picture/', deploy: testAdapter(), - mode: 'server', + output: 'server', }); devServer = await fixture.startDevServer(); diff --git a/packages/integrations/netlify/README.md b/packages/integrations/netlify/README.md index 96febf6eedbd..e53eb02cdc6c 100644 --- a/packages/integrations/netlify/README.md +++ b/packages/integrations/netlify/README.md @@ -37,7 +37,7 @@ import { defineConfig } from 'astro/config'; import netlify from '@astrojs/netlify/functions'; export default defineConfig({ - mode: 'server', + output: 'server', deploy: netlify(), }); ``` @@ -52,7 +52,7 @@ import { defineConfig } from 'astro/config'; + import netlify from '@astrojs/netlify/edge-functions'; export default defineConfig({ - mode: 'server', + output: 'server', deploy: netlify(), }); ``` @@ -85,7 +85,7 @@ import { defineConfig } from 'astro/config'; import netlify from '@astrojs/netlify/functions'; export default defineConfig({ - mode: 'server', + output: 'server', deploy: netlify({ dist: new URL('./dist/', import.meta.url) }) diff --git a/packages/integrations/netlify/src/integration-edge-functions.ts b/packages/integrations/netlify/src/integration-edge-functions.ts index 227de4882ed9..085d0d48fdd5 100644 --- a/packages/integrations/netlify/src/integration-edge-functions.ts +++ b/packages/integrations/netlify/src/integration-edge-functions.ts @@ -136,7 +136,7 @@ export function netlifyEdgeFunctions({ dist }: NetlifyEdgeFunctionsOptions = {}) setAdapter(getAdapter()); _config = config; - if(config.mode === 'static') { + if(config.output === 'static') { console.warn(`@astrojs/netlify does not support static mode.`); } }, diff --git a/packages/integrations/netlify/src/integration-functions.ts b/packages/integrations/netlify/src/integration-functions.ts index e6a12e256d7e..c3e4d8460454 100644 --- a/packages/integrations/netlify/src/integration-functions.ts +++ b/packages/integrations/netlify/src/integration-functions.ts @@ -36,7 +36,7 @@ function netlifyFunctions({ setAdapter(getAdapter({ binaryMediaTypes })); _config = config; - if(config.mode === 'static') { + if(config.output === 'static') { console.warn(`@astrojs/netlify does not support static mode.`); } }, diff --git a/packages/integrations/netlify/test/edge-functions/fixtures/dynimport/astro.config.mjs b/packages/integrations/netlify/test/edge-functions/fixtures/dynimport/astro.config.mjs index e961746c67c1..aa78247ea1f6 100644 --- a/packages/integrations/netlify/test/edge-functions/fixtures/dynimport/astro.config.mjs +++ b/packages/integrations/netlify/test/edge-functions/fixtures/dynimport/astro.config.mjs @@ -5,5 +5,5 @@ export default defineConfig({ deploy: netlifyEdgeFunctions({ dist: new URL('./dist/', import.meta.url), }), - mode: 'server', + output: 'server', }) diff --git a/packages/integrations/netlify/test/edge-functions/fixtures/edge-basic/astro.config.mjs b/packages/integrations/netlify/test/edge-functions/fixtures/edge-basic/astro.config.mjs index 65d900580f20..57fdea136b22 100644 --- a/packages/integrations/netlify/test/edge-functions/fixtures/edge-basic/astro.config.mjs +++ b/packages/integrations/netlify/test/edge-functions/fixtures/edge-basic/astro.config.mjs @@ -7,5 +7,5 @@ export default defineConfig({ dist: new URL('./dist/', import.meta.url), }), integrations: [react()], - mode: 'server', + output: 'server', }) diff --git a/packages/integrations/netlify/test/edge-functions/fixtures/root-dynamic/astro.config.mjs b/packages/integrations/netlify/test/edge-functions/fixtures/root-dynamic/astro.config.mjs index e961746c67c1..aa78247ea1f6 100644 --- a/packages/integrations/netlify/test/edge-functions/fixtures/root-dynamic/astro.config.mjs +++ b/packages/integrations/netlify/test/edge-functions/fixtures/root-dynamic/astro.config.mjs @@ -5,5 +5,5 @@ export default defineConfig({ deploy: netlifyEdgeFunctions({ dist: new URL('./dist/', import.meta.url), }), - mode: 'server', + output: 'server', }) diff --git a/packages/integrations/netlify/test/functions/base64-response.test.js b/packages/integrations/netlify/test/functions/base64-response.test.js index 12eca045cd28..98606896ec4c 100644 --- a/packages/integrations/netlify/test/functions/base64-response.test.js +++ b/packages/integrations/netlify/test/functions/base64-response.test.js @@ -9,7 +9,7 @@ describe('Base64 Responses', () => { before(async () => { fixture = await loadFixture({ root: new URL('./fixtures/base64-response/', import.meta.url).toString(), - mode: 'server', + output: 'server', deploy: netlifyAdapter({ dist: new URL('./fixtures/base64-response/dist/', import.meta.url), binaryMediaTypes: ['font/otf'], diff --git a/packages/integrations/netlify/test/functions/cookies.test.js b/packages/integrations/netlify/test/functions/cookies.test.js index 95ebc7ef24ea..04e8cc362869 100644 --- a/packages/integrations/netlify/test/functions/cookies.test.js +++ b/packages/integrations/netlify/test/functions/cookies.test.js @@ -11,7 +11,7 @@ describe('Cookies', () => { before(async () => { fixture = await loadFixture({ root: new URL('./fixtures/cookies/', import.meta.url).toString(), - mode: 'server', + output: 'server', deploy: netlifyAdapter({ dist: new URL('./fixtures/cookies/dist/', import.meta.url), }), diff --git a/packages/integrations/netlify/test/functions/dynamic-route.test.js b/packages/integrations/netlify/test/functions/dynamic-route.test.js index 0e0120bf1f4f..9a79d3745bd9 100644 --- a/packages/integrations/netlify/test/functions/dynamic-route.test.js +++ b/packages/integrations/netlify/test/functions/dynamic-route.test.js @@ -9,7 +9,7 @@ describe('Dynamic pages', () => { before(async () => { fixture = await loadFixture({ root: new URL('./fixtures/dynamic-route/', import.meta.url).toString(), - mode: 'server', + output: 'server', deploy: netlifyAdapter({ dist: new URL('./fixtures/dynamic-route/dist/', import.meta.url), }), diff --git a/packages/integrations/node/README.md b/packages/integrations/node/README.md index 464804349f3f..092216b2e6b9 100644 --- a/packages/integrations/node/README.md +++ b/packages/integrations/node/README.md @@ -37,7 +37,7 @@ import node from '@astrojs/node'; export default defineConfig({ // ... - mode: 'server', + output: 'server', deploy: node() }) ``` diff --git a/packages/integrations/node/src/index.ts b/packages/integrations/node/src/index.ts index 20d4dd7eea02..ef10cc38ef3e 100644 --- a/packages/integrations/node/src/index.ts +++ b/packages/integrations/node/src/index.ts @@ -15,7 +15,7 @@ export default function createIntegration(): AstroIntegration { 'astro:config:done': ({ setAdapter, config }) => { setAdapter(getAdapter()); - if(config.mode === 'static') { + if(config.output === 'static') { console.warn(`@astrojs/node does not support static mode.`); } }, diff --git a/packages/integrations/vercel/README.md b/packages/integrations/vercel/README.md index 408361a5fa07..2325c4021fe3 100644 --- a/packages/integrations/vercel/README.md +++ b/packages/integrations/vercel/README.md @@ -34,7 +34,7 @@ import { defineConfig } from 'astro/config'; import vercel from '@astrojs/vercel/serverless'; export default defineConfig({ - mode: 'server', + output: 'server', deploy: vercel() }); ``` From 9634907fa319c705d063cb39f831ab409f9afc8b Mon Sep 17 00:00:00 2001 From: Matthew Phillips Date: Fri, 22 Jul 2022 16:05:21 -0400 Subject: [PATCH 14/19] Update Node adapter test --- packages/integrations/node/test/api-route.test.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/packages/integrations/node/test/api-route.test.js b/packages/integrations/node/test/api-route.test.js index a28b88e7f363..c796bce456b7 100644 --- a/packages/integrations/node/test/api-route.test.js +++ b/packages/integrations/node/test/api-route.test.js @@ -9,10 +9,8 @@ describe('API routes', () => { before(async () => { fixture = await loadFixture({ root: './fixtures/api-route/', - experimental: { - ssr: true, - }, - adapter: nodejs(), + output: 'server', + deploy: nodejs(), }); await fixture.build(); }); From 5aab8d0cfdad307df982bea9c64cb90203e1c4e0 Mon Sep 17 00:00:00 2001 From: Matthew Phillips Date: Fri, 22 Jul 2022 17:00:16 -0400 Subject: [PATCH 15/19] Update test --- packages/astro/test/ssr-404-500-pages.test.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/packages/astro/test/ssr-404-500-pages.test.js b/packages/astro/test/ssr-404-500-pages.test.js index 37ff3d3a5ecd..c4de8ce7e9bc 100644 --- a/packages/astro/test/ssr-404-500-pages.test.js +++ b/packages/astro/test/ssr-404-500-pages.test.js @@ -10,10 +10,8 @@ describe('404 and 500 pages', () => { before(async () => { fixture = await loadFixture({ root: './fixtures/ssr-api-route-custom-404/', - experimental: { - ssr: true, - }, - adapter: testAdapter(), + output: 'server', + deploy: testAdapter(), }); await fixture.build({}); }); From 6f3a8b8d2e878a37ffd6e407c7b8e12d807e10d6 Mon Sep 17 00:00:00 2001 From: "Fred K. Schott" Date: Sun, 24 Jul 2022 23:27:53 -0400 Subject: [PATCH 16/19] fred pass --- .changeset/famous-coins-destroy.md | 23 ++++++++----------- .changeset/lucky-apes-yell.md | 5 ---- .changeset/perfect-drinks-fold.md | 5 ---- examples/ssr/astro.config.mjs | 2 +- packages/astro/package.json | 1 - packages/astro/src/@types/astro.ts | 6 ++--- packages/astro/src/core/build/static-build.ts | 17 +++++++++----- packages/astro/src/core/config.ts | 11 +-------- packages/astro/src/core/render/dev/index.ts | 2 +- packages/astro/src/events/session.ts | 2 +- packages/astro/src/integrations/index.ts | 4 ++-- packages/astro/test/client-address.test.js | 4 ++-- packages/astro/test/config-mode.test.js | 4 ++-- .../static-build-ssr/astro.config.mjs | 2 +- packages/astro/test/ssr-404-500-pages.test.js | 2 +- .../test/ssr-adapter-build-config.test.js | 2 +- packages/astro/test/ssr-api-route.test.js | 2 +- packages/astro/test/ssr-assets.test.js | 2 +- packages/astro/test/ssr-dynamic.test.js | 2 +- packages/astro/test/ssr-env.test.js | 2 +- .../astro/test/ssr-hoisted-script.test.js | 2 +- packages/astro/test/ssr-large-array.test.js | 2 +- packages/astro/test/ssr-lit.test.js | 2 +- packages/astro/test/ssr-markdown.test.js | 2 +- packages/astro/test/ssr-partytown.test.js | 2 +- packages/astro/test/ssr-redirect.test.js | 2 +- packages/astro/test/ssr-request.test.js | 2 +- packages/astro/test/ssr-response.test.js | 2 +- packages/astro/test/ssr-scripts.test.js | 2 +- packages/astro/test/streaming.test.js | 4 ++-- packages/integrations/cloudflare/README.md | 2 +- packages/integrations/deno/README.md | 8 +++---- .../test/fixtures/basics/astro.config.mjs | 2 +- .../test/fixtures/dynimport/astro.config.mjs | 2 +- .../integrations/image/src/integration.ts | 10 ++++---- .../integrations/image/test/image-ssr.test.js | 4 ++-- .../image/test/picture-ssr.test.js | 4 ++-- packages/integrations/netlify/README.md | 6 ++--- .../fixtures/dynimport/astro.config.mjs | 2 +- .../fixtures/edge-basic/astro.config.mjs | 2 +- .../fixtures/root-dynamic/astro.config.mjs | 2 +- .../test/functions/base64-response.test.js | 2 +- .../netlify/test/functions/cookies.test.js | 2 +- .../test/functions/dynamic-route.test.js | 2 +- packages/integrations/node/README.md | 2 +- .../integrations/node/test/api-route.test.js | 2 +- packages/integrations/sitemap/src/index.ts | 4 ++-- packages/integrations/vercel/README.md | 2 +- 48 files changed, 82 insertions(+), 100 deletions(-) delete mode 100644 .changeset/lucky-apes-yell.md delete mode 100644 .changeset/perfect-drinks-fold.md diff --git a/.changeset/famous-coins-destroy.md b/.changeset/famous-coins-destroy.md index 4118e25754ab..f47932b19b61 100644 --- a/.changeset/famous-coins-destroy.md +++ b/.changeset/famous-coins-destroy.md @@ -9,28 +9,25 @@ '@astrojs/vercel': minor --- -New `mode` configuration option +New `output` configuration option -This change introduces a new configuration option `mode`. Mode can be either +This change introduces a new "output target" configuration option (`output`). Setting the output target lets you decide the format of your final build, either: -* `static` - The default, when building a static site. -* `server` - When building an app to be deployed for SSR (server-side rendering). +* `"static"` (default): A static site. Your final build will be a collection of static assets (HTML, CSS, JS) that you can deploy to any static site host. +* `"server"`: A dynamic server application. Your final build will be an application that will run in a hosted server environment, generating HTML dynamically for different requests. -The default, `static`, can be omitted from your config file. +If `output` is omitted from your config, the default value `"static"` will be used. -If you want to use SSR you now need to provide `output: 'server'` *in addition* to an adapter. +When using the `"server"` output target, you must also include a runtime adapter via the `adapter` configuration. An adapter will *adapt* your final build to run on the deployed platform of your choice (Netlify, Vercel, Node.js, Deno, etc). -The `adapter` configuration has been renamed to `deploy`. In the future adapters will support configuring a static site as well! - -For SSR make this change: +To migrate: No action is required for most users. If you currently define an `adapter`, you will need to also add `output: 'server'` to your config file to make it explicit that you are building a server. Here is an example of what that change would look like for someone deploying to Netlify: ```diff import { defineConfig } from 'astro/config'; import netlify from '@astrojs/netlify/functions'; export default defineConfig({ -- adapter: netlify(), -+ deploy: netlify(), -+ output: 'server', + adapter: netlify(), ++ output: 'server', }); -``` +``` \ No newline at end of file diff --git a/.changeset/lucky-apes-yell.md b/.changeset/lucky-apes-yell.md deleted file mode 100644 index ea244403e574..000000000000 --- a/.changeset/lucky-apes-yell.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -'astro': patch ---- - -Update "astro add" output to remove confusing multi-select prompt. diff --git a/.changeset/perfect-drinks-fold.md b/.changeset/perfect-drinks-fold.md deleted file mode 100644 index 2af9edabaf61..000000000000 --- a/.changeset/perfect-drinks-fold.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -'astro': patch ---- - -Update the help output to improve formatting diff --git a/examples/ssr/astro.config.mjs b/examples/ssr/astro.config.mjs index 602020a718be..b859914ac3ab 100644 --- a/examples/ssr/astro.config.mjs +++ b/examples/ssr/astro.config.mjs @@ -5,6 +5,6 @@ import node from '@astrojs/node'; // https://astro.build/config export default defineConfig({ output: 'server', - deploy: node(), + adapter: node(), integrations: [svelte()], }); diff --git a/packages/astro/package.json b/packages/astro/package.json index 28811f16d177..081c68066e34 100644 --- a/packages/astro/package.json +++ b/packages/astro/package.json @@ -42,7 +42,6 @@ "./package.json": "./package.json", "./runtime/*": "./dist/runtime/*", "./server/*": "./dist/runtime/server/*", - "./adapter-node/server.js": "./dist/adapter-node/server.js", "./vite-plugin-astro": "./dist/vite-plugin-astro/index.js", "./vite-plugin-astro/*": "./dist/vite-plugin-astro/*", "./vite-plugin-astro-postprocess": "./dist/vite-plugin-astro-postprocess/index.js", diff --git a/packages/astro/src/@types/astro.ts b/packages/astro/src/@types/astro.ts index 219337c24a14..cc4bc42ab885 100644 --- a/packages/astro/src/@types/astro.ts +++ b/packages/astro/src/@types/astro.ts @@ -608,7 +608,7 @@ export interface AstroUserConfig { /** * @docs * @kind heading - * @name Deploy + * @name Adapter * @description * * Deploy to your favorite server, serverless, or edge host with build adapters. Import one of our first-party adapters for [Netlify](https://docs.astro.build/en/guides/deploy/netlify/#adapter-for-ssredge), [Vercel](https://docs.astro.build/en/guides/deploy/vercel/#adapter-for-ssr), and more to engage Astro SSR. @@ -619,11 +619,11 @@ export interface AstroUserConfig { * import netlify from '@astrojs/netlify/functions'; * { * // Example: Build for Netlify serverless deployment - * deploy: netlify(), + * adapter: netlify(), * } * ``` */ - deploy?: AstroIntegration; + adapter?: AstroIntegration; /** * @docs diff --git a/packages/astro/src/core/build/static-build.ts b/packages/astro/src/core/build/static-build.ts index a0b0f91eb54a..7919fed4522e 100644 --- a/packages/astro/src/core/build/static-build.ts +++ b/packages/astro/src/core/build/static-build.ts @@ -26,12 +26,17 @@ export async function staticBuild(opts: StaticBuildOptions) { // Verify this app is buildable. if(isModeServerWithNoAdapter(opts.astroConfig)) { - throw new Error(`Cannot use output: 'server' without an adapter. Please install and configure an adapter by setting it on the deploy configuration. - -export default { - output: 'static', - adapter: netlify(), -}`) + throw new Error(`Cannot use \`output: 'server'\` without a deploy adapter. +Install and configure the appropriate deploy adapter for your hosting platform. +Example: + + // astro.config.js + import netlify from '@astrojs/netlify'; + export default { + output: 'server', + adapter: netlify(), + } +`) } // The pages to be built for rendering purposes. diff --git a/packages/astro/src/core/config.ts b/packages/astro/src/core/config.ts index a740f685abef..86cf10a5459f 100644 --- a/packages/astro/src/core/config.ts +++ b/packages/astro/src/core/config.ts @@ -131,7 +131,7 @@ export const AstroConfigSchema = z.object({ .union([z.literal('static'), z.literal('server')]) .optional() .default('static'), - deploy: z.object({ name: z.string(), hooks: z.object({}).passthrough().default({}) }).optional(), + adapter: z.object({ name: z.string(), hooks: z.object({}).passthrough().default({}) }).optional(), integrations: z.preprocess( // preprocess (val) => (Array.isArray(val) ? val.flat(Infinity).filter(Boolean) : val), @@ -270,15 +270,6 @@ export async function validateConfig( process.exit(1); } - if ('adapter' in userConfig) { - warn( - logging, - `The "adapter" config has been renamed to "deploy". Please update your config file.` - ); - userConfig.deploy = userConfig.adapter; - delete userConfig.adapter; - } - let legacyConfigKey: string | undefined; for (const key of Object.keys(userConfig)) { if (LEGACY_ASTRO_CONFIG_KEYS.has(key)) { diff --git a/packages/astro/src/core/render/dev/index.ts b/packages/astro/src/core/render/dev/index.ts index 2945fe7de64f..a6643fc359cb 100644 --- a/packages/astro/src/core/render/dev/index.ts +++ b/packages/astro/src/core/render/dev/index.ts @@ -169,7 +169,7 @@ export async function render( }); let response = await coreRender({ - adapterName: astroConfig.deploy?.name, + adapterName: astroConfig.adapter?.name, links, styles, logging, diff --git a/packages/astro/src/events/session.ts b/packages/astro/src/events/session.ts index d22182170ff0..f2c26d980750 100644 --- a/packages/astro/src/events/session.ts +++ b/packages/astro/src/events/session.ts @@ -82,7 +82,7 @@ export function eventCliSession( typeof p === 'string' ? p : typeof p ) ?? []), ] as string[], - adapter: userConfig?.deploy?.name ?? null, + adapter: userConfig?.adapter?.name ?? null, integrations: (userConfig?.integrations ?? []).filter(Boolean).map((i: any) => i?.name), trailingSlash: userConfig?.trailingSlash, build: userConfig?.build diff --git a/packages/astro/src/integrations/index.ts b/packages/astro/src/integrations/index.ts index 05e1a865d06c..a005b62b6beb 100644 --- a/packages/astro/src/integrations/index.ts +++ b/packages/astro/src/integrations/index.ts @@ -20,8 +20,8 @@ export async function runHookConfigSetup({ command: 'dev' | 'build'; }): Promise { // An adapter is an integration, so if one is provided push it. - if (_config.deploy) { - _config.integrations.push(_config.deploy); + if (_config.adapter) { + _config.integrations.push(_config.adapter); } let updatedConfig: AstroConfig = { ..._config }; diff --git a/packages/astro/test/client-address.test.js b/packages/astro/test/client-address.test.js index 85eea189c4a3..a3c65835d21d 100644 --- a/packages/astro/test/client-address.test.js +++ b/packages/astro/test/client-address.test.js @@ -13,7 +13,7 @@ describe('Astro.clientAddress', () => { fixture = await loadFixture({ root: './fixtures/client-address/', output: 'server', - deploy: testAdapter(), + adapter: testAdapter(), }); }); @@ -66,7 +66,7 @@ describe('Astro.clientAddress', () => { fixture = await loadFixture({ root: './fixtures/client-address/', output: 'server', - deploy: testAdapter({ provideAddress: false }), + adapter: testAdapter({ provideAddress: false }), }); await fixture.build(); }); diff --git a/packages/astro/test/config-mode.test.js b/packages/astro/test/config-mode.test.js index 054bc34cee09..5c623fdce7c7 100644 --- a/packages/astro/test/config-mode.test.js +++ b/packages/astro/test/config-mode.test.js @@ -13,7 +13,7 @@ describe('AstroConfig - config.mode', () => { fixture = await loadFixture({ // This is just a random fixture to test, doesn't matter. root: './fixtures/astro-basic/', - deploy: testAdapter(), + adapter: testAdapter(), output: 'server', }); await fixture.build(); @@ -91,7 +91,7 @@ describe('AstroConfig - config.mode', () => { fixture = await loadFixture({ // This is just a random fixture to test, doesn't matter. root: './fixtures/astro-basic/', - deploy: testAdapter(), + adapter: testAdapter(), output: 'server' }); await fixture.build(); diff --git a/packages/astro/test/fixtures/static-build-ssr/astro.config.mjs b/packages/astro/test/fixtures/static-build-ssr/astro.config.mjs index 2af420d69262..3d24e915eb37 100644 --- a/packages/astro/test/fixtures/static-build-ssr/astro.config.mjs +++ b/packages/astro/test/fixtures/static-build-ssr/astro.config.mjs @@ -2,6 +2,6 @@ import { defineConfig } from 'astro/config'; import nodejs from '@astrojs/node'; export default defineConfig({ - deploy: nodejs(), + adapter: nodejs(), output: 'server', }); diff --git a/packages/astro/test/ssr-404-500-pages.test.js b/packages/astro/test/ssr-404-500-pages.test.js index c4de8ce7e9bc..4f5f1f8cf9de 100644 --- a/packages/astro/test/ssr-404-500-pages.test.js +++ b/packages/astro/test/ssr-404-500-pages.test.js @@ -11,7 +11,7 @@ describe('404 and 500 pages', () => { fixture = await loadFixture({ root: './fixtures/ssr-api-route-custom-404/', output: 'server', - deploy: testAdapter(), + adapter: testAdapter(), }); await fixture.build({}); }); diff --git a/packages/astro/test/ssr-adapter-build-config.test.js b/packages/astro/test/ssr-adapter-build-config.test.js index 968a86834339..ab0ccf3af42e 100644 --- a/packages/astro/test/ssr-adapter-build-config.test.js +++ b/packages/astro/test/ssr-adapter-build-config.test.js @@ -12,7 +12,7 @@ describe('Integration buildConfig hook', () => { fixture = await loadFixture({ root: './fixtures/ssr-request/', output: 'server', - deploy: { + adapter: { name: 'my-ssr-adapter', hooks: { 'astro:config:setup': ({ updateConfig }) => { diff --git a/packages/astro/test/ssr-api-route.test.js b/packages/astro/test/ssr-api-route.test.js index 4af48e36a843..8b007391dfa6 100644 --- a/packages/astro/test/ssr-api-route.test.js +++ b/packages/astro/test/ssr-api-route.test.js @@ -10,7 +10,7 @@ describe('API routes in SSR', () => { fixture = await loadFixture({ root: './fixtures/ssr-api-route/', output: 'server', - deploy: testAdapter(), + adapter: testAdapter(), }); await fixture.build(); }); diff --git a/packages/astro/test/ssr-assets.test.js b/packages/astro/test/ssr-assets.test.js index a261ff9dc0f1..e02045bc04db 100644 --- a/packages/astro/test/ssr-assets.test.js +++ b/packages/astro/test/ssr-assets.test.js @@ -10,7 +10,7 @@ describe('SSR Assets', () => { fixture = await loadFixture({ root: './fixtures/ssr-assets/', output: 'server', - deploy: testAdapter(), + adapter: testAdapter(), }); await fixture.build(); }); diff --git a/packages/astro/test/ssr-dynamic.test.js b/packages/astro/test/ssr-dynamic.test.js index 21a3103695e2..a75ace7e3c2a 100644 --- a/packages/astro/test/ssr-dynamic.test.js +++ b/packages/astro/test/ssr-dynamic.test.js @@ -11,7 +11,7 @@ describe('Dynamic pages in SSR', () => { fixture = await loadFixture({ root: './fixtures/ssr-dynamic/', output: 'server', - deploy: testAdapter(), + adapter: testAdapter(), }); await fixture.build(); }); diff --git a/packages/astro/test/ssr-env.test.js b/packages/astro/test/ssr-env.test.js index c4eea6684d59..fb369482dff1 100644 --- a/packages/astro/test/ssr-env.test.js +++ b/packages/astro/test/ssr-env.test.js @@ -11,7 +11,7 @@ describe('SSR Environment Variables', () => { fixture = await loadFixture({ root: './fixtures/ssr-env/', output: 'server', - deploy: testAdapter(), + adapter: testAdapter(), }); await fixture.build(); }); diff --git a/packages/astro/test/ssr-hoisted-script.test.js b/packages/astro/test/ssr-hoisted-script.test.js index cb87a7c41ae3..7d31875ffdf5 100644 --- a/packages/astro/test/ssr-hoisted-script.test.js +++ b/packages/astro/test/ssr-hoisted-script.test.js @@ -11,7 +11,7 @@ describe('Hoisted scripts in SSR', () => { fixture = await loadFixture({ root: './fixtures/ssr-hoisted-script/', output: 'server', - deploy: testAdapter(), + adapter: testAdapter(), }); await fixture.build(); }); diff --git a/packages/astro/test/ssr-large-array.test.js b/packages/astro/test/ssr-large-array.test.js index 7d600c377d7b..0145a2fe4591 100644 --- a/packages/astro/test/ssr-large-array.test.js +++ b/packages/astro/test/ssr-large-array.test.js @@ -11,7 +11,7 @@ describe('SSR with Large Array and client rendering', () => { fixture = await loadFixture({ root: './fixtures/large-array/', output: 'server', - deploy: testAdapter(), + adapter: testAdapter(), }); await fixture.build(); }); diff --git a/packages/astro/test/ssr-lit.test.js b/packages/astro/test/ssr-lit.test.js index 20d69e42108f..53555b9838ac 100644 --- a/packages/astro/test/ssr-lit.test.js +++ b/packages/astro/test/ssr-lit.test.js @@ -11,7 +11,7 @@ describe('Lit integration in SSR', () => { fixture = await loadFixture({ root: './fixtures/lit-element/', output: 'server', - deploy: testAdapter(), + adapter: testAdapter(), }); await fixture.build(); }); diff --git a/packages/astro/test/ssr-markdown.test.js b/packages/astro/test/ssr-markdown.test.js index 809ee0a83dd9..4f9ae9f940d6 100644 --- a/packages/astro/test/ssr-markdown.test.js +++ b/packages/astro/test/ssr-markdown.test.js @@ -11,7 +11,7 @@ describe('Markdown pages in SSR', () => { fixture = await loadFixture({ root: './fixtures/ssr-markdown/', output: 'server', - deploy: testAdapter(), + adapter: testAdapter(), }); await fixture.build(); }); diff --git a/packages/astro/test/ssr-partytown.test.js b/packages/astro/test/ssr-partytown.test.js index 62df9a488098..4978ead32347 100644 --- a/packages/astro/test/ssr-partytown.test.js +++ b/packages/astro/test/ssr-partytown.test.js @@ -10,7 +10,7 @@ describe('Using the Partytown integration in SSR', () => { before(async () => { fixture = await loadFixture({ root: './fixtures/ssr-partytown/', - deploy: testAdapter(), + adapter: testAdapter(), output: 'server' }); await fixture.build(); diff --git a/packages/astro/test/ssr-redirect.test.js b/packages/astro/test/ssr-redirect.test.js index 9c64cc4a9fca..dd23e26d382f 100644 --- a/packages/astro/test/ssr-redirect.test.js +++ b/packages/astro/test/ssr-redirect.test.js @@ -10,7 +10,7 @@ describe('Astro.redirect', () => { fixture = await loadFixture({ root: './fixtures/ssr-redirect/', output: 'server', - deploy: testAdapter(), + adapter: testAdapter(), }); await fixture.build(); }); diff --git a/packages/astro/test/ssr-request.test.js b/packages/astro/test/ssr-request.test.js index f79e9c7d0e6d..b8e0300416f6 100644 --- a/packages/astro/test/ssr-request.test.js +++ b/packages/astro/test/ssr-request.test.js @@ -10,7 +10,7 @@ describe('Using Astro.request in SSR', () => { before(async () => { fixture = await loadFixture({ root: './fixtures/ssr-request/', - deploy: testAdapter(), + adapter: testAdapter(), output: 'server' }); await fixture.build(); diff --git a/packages/astro/test/ssr-response.test.js b/packages/astro/test/ssr-response.test.js index 7627456363a1..2e3277e89b62 100644 --- a/packages/astro/test/ssr-response.test.js +++ b/packages/astro/test/ssr-response.test.js @@ -10,7 +10,7 @@ describe('Using Astro.response in SSR', () => { before(async () => { fixture = await loadFixture({ root: './fixtures/ssr-response/', - deploy: testAdapter(), + adapter: testAdapter(), output: 'server' }); await fixture.build(); diff --git a/packages/astro/test/ssr-scripts.test.js b/packages/astro/test/ssr-scripts.test.js index fa768290118d..241ec894bce5 100644 --- a/packages/astro/test/ssr-scripts.test.js +++ b/packages/astro/test/ssr-scripts.test.js @@ -10,7 +10,7 @@ describe('SSR Hydrated component scripts', () => { fixture = await loadFixture({ root: './fixtures/ssr-scripts/', output: 'server', - deploy: testAdapter(), + adapter: testAdapter(), }); await fixture.build(); }); diff --git a/packages/astro/test/streaming.test.js b/packages/astro/test/streaming.test.js index 1fcbfeaafb78..2ca8ee549c3c 100644 --- a/packages/astro/test/streaming.test.js +++ b/packages/astro/test/streaming.test.js @@ -12,7 +12,7 @@ describe('Streaming', () => { before(async () => { fixture = await loadFixture({ root: './fixtures/streaming/', - deploy: testAdapter(), + adapter: testAdapter(), output: 'server' }); }); @@ -79,7 +79,7 @@ describe('Streaming disabled', () => { before(async () => { fixture = await loadFixture({ root: './fixtures/streaming/', - deploy: testAdapter(), + adapter: testAdapter(), output: 'server', server: { streaming: false, diff --git a/packages/integrations/cloudflare/README.md b/packages/integrations/cloudflare/README.md index 596cd4673d7d..d2c886df6820 100644 --- a/packages/integrations/cloudflare/README.md +++ b/packages/integrations/cloudflare/README.md @@ -10,7 +10,7 @@ import cloudflare from '@astrojs/cloudflare'; export default defineConfig({ output: 'server', - deploy: cloudflare() + adapter: cloudflare() }); ``` diff --git a/packages/integrations/deno/README.md b/packages/integrations/deno/README.md index 9b9131af8c32..35fb27a622b9 100644 --- a/packages/integrations/deno/README.md +++ b/packages/integrations/deno/README.md @@ -38,7 +38,7 @@ import deno from '@astrojs/deno'; export default defineConfig({ // ... output: 'server', - deploy: deno() + adapter: deno() }); ``` @@ -71,7 +71,7 @@ import deno from '@astrojs/deno'; export default defineConfig({ output: 'server', - deploy: deno({ + adapter: deno({ //options go here }) }); @@ -88,7 +88,7 @@ export default defineConfig({ export default defineConfig({ output: 'server', - deploy: deno({ + adapter: deno({ start: false }) }); @@ -119,7 +119,7 @@ export default defineConfig({ export default defineConfig({ output: 'server', - deploy: deno({ + adapter: deno({ port: 8081, hostname: 'myhost' }) diff --git a/packages/integrations/deno/test/fixtures/basics/astro.config.mjs b/packages/integrations/deno/test/fixtures/basics/astro.config.mjs index d24e1f45a07d..d01a93632d5c 100644 --- a/packages/integrations/deno/test/fixtures/basics/astro.config.mjs +++ b/packages/integrations/deno/test/fixtures/basics/astro.config.mjs @@ -3,7 +3,7 @@ import deno from '@astrojs/deno'; import react from '@astrojs/react'; export default defineConfig({ - deploy: deno(), + adapter: deno(), integrations: [react()], output: 'server', }) diff --git a/packages/integrations/deno/test/fixtures/dynimport/astro.config.mjs b/packages/integrations/deno/test/fixtures/dynimport/astro.config.mjs index 85a52c649827..d670faac6720 100644 --- a/packages/integrations/deno/test/fixtures/dynimport/astro.config.mjs +++ b/packages/integrations/deno/test/fixtures/dynimport/astro.config.mjs @@ -2,6 +2,6 @@ import { defineConfig } from 'astro/config'; import deno from '@astrojs/deno'; export default defineConfig({ - deploy: deno(), + adapter: deno(), output: 'server', }) diff --git a/packages/integrations/image/src/integration.ts b/packages/integrations/image/src/integration.ts index afbeb00a9651..725276d03cc7 100644 --- a/packages/integrations/image/src/integration.ts +++ b/packages/integrations/image/src/integration.ts @@ -16,7 +16,7 @@ export default function integration(options: IntegrationOptions = {}): AstroInte const staticImages = new Map>(); let _config: AstroConfig; - let mode: 'ssr' | 'ssg'; + let output: 'server' | 'static'; function getViteConfiguration() { return { @@ -37,11 +37,11 @@ export default function integration(options: IntegrationOptions = {}): AstroInte _config = config; // Always treat `astro dev` as SSR mode, even without an adapter - mode = command === 'dev' || config.adapter ? 'ssr' : 'ssg'; + output = command === 'dev' ? 'server' : config.output; updateConfig({ vite: getViteConfiguration() }); - if (mode === 'ssr') { + if (output === 'server') { injectRoute({ pattern: ROUTE_PATTERN, entryPoint: @@ -67,7 +67,7 @@ export default function integration(options: IntegrationOptions = {}): AstroInte // Helpers for building static images should only be available for SSG globalThis.astroImage = - mode === 'ssg' + output === 'static' ? { addStaticImage, filenameFormat, @@ -75,7 +75,7 @@ export default function integration(options: IntegrationOptions = {}): AstroInte : {}; }, 'astro:build:done': async ({ dir }) => { - if (mode === 'ssr') { + if (output === 'server') { // for SSR builds, copy all image files from src to dist // to make sure they are available for use in production await ssrBuild({ srcDir: _config.srcDir, outDir: dir }); diff --git a/packages/integrations/image/test/image-ssr.test.js b/packages/integrations/image/test/image-ssr.test.js index c0cbc3e2472e..37274c929aa6 100644 --- a/packages/integrations/image/test/image-ssr.test.js +++ b/packages/integrations/image/test/image-ssr.test.js @@ -18,7 +18,7 @@ describe('SSR images - build', function () { before(async () => { fixture = await loadFixture({ root: './fixtures/basic-image/', - deploy: testAdapter({ streaming: false }), + adapter: testAdapter({ streaming: false }), output: 'server', }); await fixture.build(); @@ -136,7 +136,7 @@ describe('SSR images - dev', function () { before(async () => { fixture = await loadFixture({ root: './fixtures/basic-image/', - deploy: testAdapter(), + adapter: testAdapter(), output: 'server', }); diff --git a/packages/integrations/image/test/picture-ssr.test.js b/packages/integrations/image/test/picture-ssr.test.js index c87ba9e95082..ebfbdf7497ab 100644 --- a/packages/integrations/image/test/picture-ssr.test.js +++ b/packages/integrations/image/test/picture-ssr.test.js @@ -18,7 +18,7 @@ describe('SSR pictures - build', function () { before(async () => { fixture = await loadFixture({ root: './fixtures/basic-picture/', - deploy: testAdapter(), + adapter: testAdapter(), output: 'server', }); await fixture.build(); @@ -184,7 +184,7 @@ describe('SSR images - dev', function () { before(async () => { fixture = await loadFixture({ root: './fixtures/basic-picture/', - deploy: testAdapter(), + adapter: testAdapter(), output: 'server', }); diff --git a/packages/integrations/netlify/README.md b/packages/integrations/netlify/README.md index e53eb02cdc6c..0dc6f3db88aa 100644 --- a/packages/integrations/netlify/README.md +++ b/packages/integrations/netlify/README.md @@ -38,7 +38,7 @@ import netlify from '@astrojs/netlify/functions'; export default defineConfig({ output: 'server', - deploy: netlify(), + adapter: netlify(), }); ``` @@ -53,7 +53,7 @@ import { defineConfig } from 'astro/config'; export default defineConfig({ output: 'server', - deploy: netlify(), + adapter: netlify(), }); ``` ## Usage @@ -86,7 +86,7 @@ import netlify from '@astrojs/netlify/functions'; export default defineConfig({ output: 'server', - deploy: netlify({ + adapter: netlify({ dist: new URL('./dist/', import.meta.url) }) }); diff --git a/packages/integrations/netlify/test/edge-functions/fixtures/dynimport/astro.config.mjs b/packages/integrations/netlify/test/edge-functions/fixtures/dynimport/astro.config.mjs index aa78247ea1f6..cd758352b5f7 100644 --- a/packages/integrations/netlify/test/edge-functions/fixtures/dynimport/astro.config.mjs +++ b/packages/integrations/netlify/test/edge-functions/fixtures/dynimport/astro.config.mjs @@ -2,7 +2,7 @@ import { defineConfig } from 'astro/config'; import { netlifyEdgeFunctions } from '@astrojs/netlify'; export default defineConfig({ - deploy: netlifyEdgeFunctions({ + adapter: netlifyEdgeFunctions({ dist: new URL('./dist/', import.meta.url), }), output: 'server', diff --git a/packages/integrations/netlify/test/edge-functions/fixtures/edge-basic/astro.config.mjs b/packages/integrations/netlify/test/edge-functions/fixtures/edge-basic/astro.config.mjs index 57fdea136b22..a08e8e89d382 100644 --- a/packages/integrations/netlify/test/edge-functions/fixtures/edge-basic/astro.config.mjs +++ b/packages/integrations/netlify/test/edge-functions/fixtures/edge-basic/astro.config.mjs @@ -3,7 +3,7 @@ import { netlifyEdgeFunctions } from '@astrojs/netlify'; import react from "@astrojs/react"; export default defineConfig({ - deploy: netlifyEdgeFunctions({ + adapter: netlifyEdgeFunctions({ dist: new URL('./dist/', import.meta.url), }), integrations: [react()], diff --git a/packages/integrations/netlify/test/edge-functions/fixtures/root-dynamic/astro.config.mjs b/packages/integrations/netlify/test/edge-functions/fixtures/root-dynamic/astro.config.mjs index aa78247ea1f6..cd758352b5f7 100644 --- a/packages/integrations/netlify/test/edge-functions/fixtures/root-dynamic/astro.config.mjs +++ b/packages/integrations/netlify/test/edge-functions/fixtures/root-dynamic/astro.config.mjs @@ -2,7 +2,7 @@ import { defineConfig } from 'astro/config'; import { netlifyEdgeFunctions } from '@astrojs/netlify'; export default defineConfig({ - deploy: netlifyEdgeFunctions({ + adapter: netlifyEdgeFunctions({ dist: new URL('./dist/', import.meta.url), }), output: 'server', diff --git a/packages/integrations/netlify/test/functions/base64-response.test.js b/packages/integrations/netlify/test/functions/base64-response.test.js index 98606896ec4c..6e59bd192210 100644 --- a/packages/integrations/netlify/test/functions/base64-response.test.js +++ b/packages/integrations/netlify/test/functions/base64-response.test.js @@ -10,7 +10,7 @@ describe('Base64 Responses', () => { fixture = await loadFixture({ root: new URL('./fixtures/base64-response/', import.meta.url).toString(), output: 'server', - deploy: netlifyAdapter({ + adapter: netlifyAdapter({ dist: new URL('./fixtures/base64-response/dist/', import.meta.url), binaryMediaTypes: ['font/otf'], }), diff --git a/packages/integrations/netlify/test/functions/cookies.test.js b/packages/integrations/netlify/test/functions/cookies.test.js index 04e8cc362869..bc1771512c58 100644 --- a/packages/integrations/netlify/test/functions/cookies.test.js +++ b/packages/integrations/netlify/test/functions/cookies.test.js @@ -12,7 +12,7 @@ describe('Cookies', () => { fixture = await loadFixture({ root: new URL('./fixtures/cookies/', import.meta.url).toString(), output: 'server', - deploy: netlifyAdapter({ + adapter: netlifyAdapter({ dist: new URL('./fixtures/cookies/dist/', import.meta.url), }), site: `http://example.com`, diff --git a/packages/integrations/netlify/test/functions/dynamic-route.test.js b/packages/integrations/netlify/test/functions/dynamic-route.test.js index 9a79d3745bd9..0cfb5359b45a 100644 --- a/packages/integrations/netlify/test/functions/dynamic-route.test.js +++ b/packages/integrations/netlify/test/functions/dynamic-route.test.js @@ -10,7 +10,7 @@ describe('Dynamic pages', () => { fixture = await loadFixture({ root: new URL('./fixtures/dynamic-route/', import.meta.url).toString(), output: 'server', - deploy: netlifyAdapter({ + adapter: netlifyAdapter({ dist: new URL('./fixtures/dynamic-route/dist/', import.meta.url), }), site: `http://example.com`, diff --git a/packages/integrations/node/README.md b/packages/integrations/node/README.md index 092216b2e6b9..2743525771b6 100644 --- a/packages/integrations/node/README.md +++ b/packages/integrations/node/README.md @@ -38,7 +38,7 @@ import node from '@astrojs/node'; export default defineConfig({ // ... output: 'server', - deploy: node() + adapter: node() }) ``` diff --git a/packages/integrations/node/test/api-route.test.js b/packages/integrations/node/test/api-route.test.js index c796bce456b7..034b53c07f53 100644 --- a/packages/integrations/node/test/api-route.test.js +++ b/packages/integrations/node/test/api-route.test.js @@ -10,7 +10,7 @@ describe('API routes', () => { fixture = await loadFixture({ root: './fixtures/api-route/', output: 'server', - deploy: nodejs(), + adapter: nodejs(), }); await fixture.build(); }); diff --git a/packages/integrations/sitemap/src/index.ts b/packages/integrations/sitemap/src/index.ts index 682b76a2a655..bab3d5af6fb3 100644 --- a/packages/integrations/sitemap/src/index.ts +++ b/packages/integrations/sitemap/src/index.ts @@ -98,9 +98,9 @@ const createPlugin = (options?: SitemapOptions): AstroIntegration => { if (pageUrls.length === 0) { // offer suggestion for SSR users - if (typeof config.deploy !== 'undefined') { + if (config.output !== 'static') { logger.warn( - `No pages found! We can only detect sitemap routes for "static" projects. Since you are using an SSR adapter, we recommend manually listing your sitemap routes using the "customPages" integration option.\n\nExample: \`sitemap({ customPages: ['https://example.com/route'] })\`` + `No pages found! We can only detect sitemap routes for "static" builds. Since you are using an SSR adapter, we recommend manually listing your sitemap routes using the "customPages" integration option.\n\nExample: \`sitemap({ customPages: ['https://example.com/route'] })\`` ); } else { logger.warn(`No pages found!\n\`${OUTFILE}\` not created.`); diff --git a/packages/integrations/vercel/README.md b/packages/integrations/vercel/README.md index 2325c4021fe3..f7726805b2c6 100644 --- a/packages/integrations/vercel/README.md +++ b/packages/integrations/vercel/README.md @@ -35,7 +35,7 @@ import vercel from '@astrojs/vercel/serverless'; export default defineConfig({ output: 'server', - deploy: vercel() + adapter: vercel() }); ``` From 3b84aaeb69427b8a3a1afb7f2b8096cbce3976b3 Mon Sep 17 00:00:00 2001 From: "Fred K. Schott" Date: Sun, 24 Jul 2022 23:37:51 -0400 Subject: [PATCH 17/19] fred pass --- packages/astro/src/@types/astro.ts | 86 ++++++++++--------- packages/astro/src/core/build/index.ts | 15 +++- packages/astro/src/core/build/static-build.ts | 4 +- 3 files changed, 57 insertions(+), 48 deletions(-) diff --git a/packages/astro/src/@types/astro.ts b/packages/astro/src/@types/astro.ts index cc4bc42ab885..dc437fe36e8b 100644 --- a/packages/astro/src/@types/astro.ts +++ b/packages/astro/src/@types/astro.ts @@ -423,6 +423,50 @@ export interface AstroUserConfig { */ trailingSlash?: 'always' | 'never' | 'ignore'; + /** + * @docs + * @name adapter + * @typeraw {AstroIntegration} + * @see output + * @description + * + * Deploy to your favorite server, serverless, or edge host with build adapters. Import one of our first-party adapters for [Netlify](https://docs.astro.build/en/guides/deploy/netlify/#adapter-for-ssredge), [Vercel](https://docs.astro.build/en/guides/deploy/vercel/#adapter-for-ssr), and more to engage Astro SSR. + * + * [See our Server-side Rendering guide](https://docs.astro.build/en/guides/server-side-rendering/) for more on SSR, and [our deployment guides](https://docs.astro.build/en/guides/deploy/) for a complete list of hosts. + * + * ```js + * import netlify from '@astrojs/netlify/functions'; + * { + * // Example: Build for Netlify serverless deployment + * adapter: netlify(), + * } + * ``` + */ + adapter?: AstroIntegration; + + /** + * @docs + * @name output + * @type {('static' | 'server')} + * @default `'static'` + * @see adapter + * @description + * + * Specifies the output target for builds. + * + * - 'static' - Building a static site to be deploy to any static host. + * - 'server' - Building an app to be deployed to a host supporting SSR (server-side rendering). + * + * ```js + * import { defineConfig } from 'astro/config'; + * + * export default defineConfig({ + * output: 'static' + * }) + * ``` + */ + output?: 'static' | 'server'; + /** * @docs * @kind heading @@ -605,48 +649,6 @@ export interface AstroUserConfig { rehypePlugins?: RehypePlugins; }; - /** - * @docs - * @kind heading - * @name Adapter - * @description - * - * Deploy to your favorite server, serverless, or edge host with build adapters. Import one of our first-party adapters for [Netlify](https://docs.astro.build/en/guides/deploy/netlify/#adapter-for-ssredge), [Vercel](https://docs.astro.build/en/guides/deploy/vercel/#adapter-for-ssr), and more to engage Astro SSR. - * - * [See our Server-side Rendering guide](https://docs.astro.build/en/guides/server-side-rendering/) for more on SSR, and [our deployment guides](https://docs.astro.build/en/guides/deploy/) for a complete list of hosts. - * - * ```js - * import netlify from '@astrojs/netlify/functions'; - * { - * // Example: Build for Netlify serverless deployment - * adapter: netlify(), - * } - * ``` - */ - adapter?: AstroIntegration; - - /** - * @docs - * @kind heading - * @name Output - * @description - * - * Specifies the output target for builds. - * - * - 'static' - Building a static site to be deploy to any static host. - * - 'server' - Building an app to be deployed to a host supporting SSR (server-side rendering). - * - * ```js - * import { defineConfig } from 'astro/config'; - * - * export default defineConfig({ - * output: 'static' - * }) - * ``` - */ - output?: 'static' | 'server'; - - /** * @docs * @kind heading diff --git a/packages/astro/src/core/build/index.ts b/packages/astro/src/core/build/index.ts index 08e7b40bc6f9..41b18556a30c 100644 --- a/packages/astro/src/core/build/index.ts +++ b/packages/astro/src/core/build/index.ts @@ -1,5 +1,11 @@ import type { AstroTelemetry } from '@astrojs/telemetry'; -import type { AstroAdapter, AstroConfig, BuildConfig, ManifestData, RuntimeMode } from '../../@types/astro'; +import type { + AstroAdapter, + AstroConfig, + BuildConfig, + ManifestData, + RuntimeMode, +} from '../../@types/astro'; import type { LogOptions } from '../logger/core'; import fs from 'fs'; @@ -101,9 +107,10 @@ class AstroBuilder { }; await runHookBuildStart({ config: this.config, buildConfig }); - const getPrettyDeployTarget = (adapter: AstroAdapter | undefined) => adapter?.name || 'unknown'; - info(this.logging, 'build', `build target: ${colors.green(this.config.output)}`); - info(this.logging, 'build', `deploy target: ${colors.green(getPrettyDeployTarget(this.config._ctx.adapter))}`); + info(this.logging, 'build', `output target: ${colors.green(this.config.output)}`); + if (this.config._ctx.adapter) { + info(this.logging, 'build', `deploy adapter: ${colors.green(this.config._ctx.adapter.name)}`); + } info(this.logging, 'build', 'Collecting build info...'); this.timer.loadStart = performance.now(); const { assets, allPages } = await collectPagesData({ diff --git a/packages/astro/src/core/build/static-build.ts b/packages/astro/src/core/build/static-build.ts index 7919fed4522e..931285eeee2a 100644 --- a/packages/astro/src/core/build/static-build.ts +++ b/packages/astro/src/core/build/static-build.ts @@ -26,8 +26,8 @@ export async function staticBuild(opts: StaticBuildOptions) { // Verify this app is buildable. if(isModeServerWithNoAdapter(opts.astroConfig)) { - throw new Error(`Cannot use \`output: 'server'\` without a deploy adapter. -Install and configure the appropriate deploy adapter for your hosting platform. + throw new Error(`Cannot use \`output: 'server'\` without an adapter. +Install and configure the appropriate server adapter for your final deployment. Example: // astro.config.js From b4ec13ea6b55b4ee7e16704d4a6a8cf78a0c2755 Mon Sep 17 00:00:00 2001 From: "Fred K. Schott" Date: Mon, 25 Jul 2022 00:02:21 -0400 Subject: [PATCH 18/19] fred pass --- packages/astro/src/core/request.ts | 2 +- packages/integrations/cloudflare/src/index.ts | 3 ++- packages/integrations/deno/src/index.ts | 3 ++- .../integrations/netlify/src/integration-edge-functions.ts | 5 +++-- packages/integrations/netlify/src/integration-functions.ts | 3 ++- packages/integrations/node/src/index.ts | 2 +- 6 files changed, 11 insertions(+), 7 deletions(-) diff --git a/packages/astro/src/core/request.ts b/packages/astro/src/core/request.ts index 36d4bccf8d80..24356983f768 100644 --- a/packages/astro/src/core/request.ts +++ b/packages/astro/src/core/request.ts @@ -56,7 +56,7 @@ export function createRequest({ warn( logging, 'ssg', - `Headers are not exposed in static-site generation (SSG) mode. To enable reading headers: set \`mode: "server"\` in your config file.` + `Headers are not exposed in static (SSG) output mode. To enable headers: set \`output: "server"\` in your config file.` ); return _headers; }, diff --git a/packages/integrations/cloudflare/src/index.ts b/packages/integrations/cloudflare/src/index.ts index b3dbf4b262e2..7070af17fb95 100644 --- a/packages/integrations/cloudflare/src/index.ts +++ b/packages/integrations/cloudflare/src/index.ts @@ -23,7 +23,8 @@ export default function createIntegration(): AstroIntegration { _config = config; if(config.output === 'static') { - console.warn(`@astrojs/cloudflare does not support static mode.`); + 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.`); } }, 'astro:build:start': ({ buildConfig }) => { diff --git a/packages/integrations/deno/src/index.ts b/packages/integrations/deno/src/index.ts index 8bc58c9dbc1c..73ccf01e0714 100644 --- a/packages/integrations/deno/src/index.ts +++ b/packages/integrations/deno/src/index.ts @@ -33,7 +33,8 @@ export default function createIntegration(args?: Options): AstroIntegration { setAdapter(getAdapter(args)); if(config.output === 'static') { - console.warn(`@astrojs/deno does not support static mode.`); + console.warn(`[@astrojs/deno] \`output: "server"\` is required to use this adapter.`); + console.warn(`[@astrojs/deno] Otherwise, this adapter is not required to deploy a static site to Deno.`); } }, 'astro:build:start': ({ buildConfig }) => { diff --git a/packages/integrations/netlify/src/integration-edge-functions.ts b/packages/integrations/netlify/src/integration-edge-functions.ts index 085d0d48fdd5..0556317d7ada 100644 --- a/packages/integrations/netlify/src/integration-edge-functions.ts +++ b/packages/integrations/netlify/src/integration-edge-functions.ts @@ -137,8 +137,9 @@ export function netlifyEdgeFunctions({ dist }: NetlifyEdgeFunctionsOptions = {}) _config = config; if(config.output === 'static') { - console.warn(`@astrojs/netlify does not support static mode.`); - } + console.warn(`[@astrojs/netlify] \`output: "server"\` is required to use this adapter.`); + console.warn(`[@astrojs/netlify] Otherwise, this adapter is not required to deploy a static site to Netlify.`); + } }, 'astro:build:start': async ({ buildConfig }) => { _buildConfig = buildConfig; diff --git a/packages/integrations/netlify/src/integration-functions.ts b/packages/integrations/netlify/src/integration-functions.ts index c3e4d8460454..d0b327f87eb3 100644 --- a/packages/integrations/netlify/src/integration-functions.ts +++ b/packages/integrations/netlify/src/integration-functions.ts @@ -37,7 +37,8 @@ function netlifyFunctions({ _config = config; if(config.output === 'static') { - console.warn(`@astrojs/netlify does not support static mode.`); + console.warn(`[@astrojs/netlify] \`output: "server"\` is required to use this adapter.`); + console.warn(`[@astrojs/netlify] Otherwise, this adapter is not required to deploy a static site to Netlify.`); } }, 'astro:build:start': async ({ buildConfig }) => { diff --git a/packages/integrations/node/src/index.ts b/packages/integrations/node/src/index.ts index ef10cc38ef3e..8ff6fc423787 100644 --- a/packages/integrations/node/src/index.ts +++ b/packages/integrations/node/src/index.ts @@ -16,7 +16,7 @@ export default function createIntegration(): AstroIntegration { setAdapter(getAdapter()); if(config.output === 'static') { - console.warn(`@astrojs/node does not support static mode.`); + console.warn(`[@astrojs/Node] \`output: "server"\` is required to use this adapter.`); } }, }, From 3d179ab03a2ad029ed7dd76e473085201e4007c8 Mon Sep 17 00:00:00 2001 From: "Fred K. Schott" Date: Mon, 25 Jul 2022 00:17:42 -0400 Subject: [PATCH 19/19] fix test --- packages/astro/test/static-build.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/astro/test/static-build.test.js b/packages/astro/test/static-build.test.js index ce470b2b6ccc..a8c67eff3c9d 100644 --- a/packages/astro/test/static-build.test.js +++ b/packages/astro/test/static-build.test.js @@ -176,7 +176,7 @@ describe('Static build', () => { for (const log of logs) { if ( log.type === 'ssg' && - /[hH]eaders are not exposed in static-site generation/.test(log.args[0]) + /[hH]eaders are not exposed in static \(SSG\) output mode/.test(log.args[0]) ) { found = true; }