Skip to content

Commit

Permalink
Rename mode to output
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewp committed Jul 22, 2022
1 parent 7125952 commit 1e97fdf
Show file tree
Hide file tree
Showing 52 changed files with 97 additions and 79 deletions.
4 changes: 2 additions & 2 deletions .changeset/famous-coins-destroy.md
Original file line number Diff line number Diff line change
Expand Up @@ -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!

Expand All @@ -31,6 +31,6 @@ import netlify from '@astrojs/netlify/functions';
export default defineConfig({
- adapter: netlify(),
+ deploy: netlify(),
+ mode: 'server',
+ output: 'server',
});
```
2 changes: 1 addition & 1 deletion examples/ssr/astro.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import node from '@astrojs/node';

// https://astro.build/config
export default defineConfig({
mode: 'server',
output: 'server',
deploy: node(),
integrations: [svelte()],
});
22 changes: 20 additions & 2 deletions packages/astro/src/@types/astro.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';


/**
Expand Down
4 changes: 2 additions & 2 deletions packages/astro/src/core/build/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/src/core/build/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/src/core/build/page-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
14 changes: 7 additions & 7 deletions packages/astro/src/core/build/static-build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
}`)
}
Expand Down Expand Up @@ -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 {
Expand All @@ -107,7 +107,7 @@ export default {

async function ssrBuild(opts: StaticBuildOptions, internals: BuildInternals, input: Set<string>) {
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 = {
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/src/core/build/vite-plugin-pages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
}
},
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/src/core/endpoint/dev/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
});
}
2 changes: 1 addition & 1 deletion packages/astro/src/core/render/dev/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});

Expand Down
2 changes: 1 addition & 1 deletion packages/astro/src/core/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/src/integrations/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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']) {
Expand Down
4 changes: 2 additions & 2 deletions packages/astro/src/vite-plugin-astro-server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -276,7 +276,7 @@ async function handleRequest(
routeCache,
pathname: pathname,
logging,
ssr: config.mode === 'server',
ssr: config.output === 'server',
});
if (paramsAndPropsRes === GetParamsAndPropsError.NoMatchingStaticPath) {
warn(
Expand Down
6 changes: 3 additions & 3 deletions packages/astro/test/client-address.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ describe('Astro.clientAddress', () => {
before(async () => {
fixture = await loadFixture({
root: './fixtures/client-address/',
mode: 'server',
output: 'server',
deploy: testAdapter(),
});
});
Expand Down Expand Up @@ -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();
Expand All @@ -86,7 +86,7 @@ describe('Astro.clientAddress', () => {
before(async () => {
fixture = await loadFixture({
root: './fixtures/client-address/',
mode: 'static',
output: 'static',
});
});

Expand Down
12 changes: 6 additions & 6 deletions packages/astro/test/config-mode.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
});
Expand All @@ -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'
});

});
Expand All @@ -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;
Expand All @@ -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();
});
Expand All @@ -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();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ import nodejs from '@astrojs/node';

export default defineConfig({
deploy: nodejs(),
mode: 'server',
output: 'server',
});
2 changes: 1 addition & 1 deletion packages/astro/test/ssr-adapter-build-config.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/test/ssr-api-route.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/test/ssr-assets.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/test/ssr-dynamic.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/test/ssr-env.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/test/ssr-hoisted-script.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/test/ssr-large-array.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/test/ssr-lit.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/test/ssr-markdown.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/test/ssr-partytown.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/test/ssr-redirect.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Loading

0 comments on commit 1e97fdf

Please sign in to comment.