Skip to content

Commit

Permalink
Updates based on PR review
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewp committed Jul 22, 2022
1 parent 511687a commit 570a9f3
Show file tree
Hide file tree
Showing 11 changed files with 29 additions and 27 deletions.
2 changes: 0 additions & 2 deletions examples/basics/astro.config.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import { defineConfig } from 'astro/config';
import netlify from "@astrojs/netlify";


// https://astro.build/config
export default defineConfig({});
4 changes: 2 additions & 2 deletions packages/astro/src/@types/astro.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -632,7 +632,7 @@ export interface AstroUserConfig {
* import netlify from '@astrojs/netlify/functions';
* {
* // Example: Build for Netlify serverless deployment
* adapter: netlify(),
* deploy: netlify(),
* }
* ```
*/
Expand Down
10 changes: 1 addition & 9 deletions packages/astro/src/core/build/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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...');
Expand Down
4 changes: 2 additions & 2 deletions packages/astro/src/core/build/static-build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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 {
Expand Down
1 change: 0 additions & 1 deletion packages/astro/src/core/logger/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ export const logger = {
};

export function enableVerboseLogging() {
debugPackage.enable('*,-babel');
debug('cli', '--verbose flag enabled! Enabling: DEBUG="*,-babel"');
debug(
'cli',
Expand Down
11 changes: 2 additions & 9 deletions packages/astro/src/core/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 4 additions & 0 deletions packages/integrations/cloudflare/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 5 additions & 1 deletion packages/integrations/deno/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions packages/integrations/netlify/src/integration-functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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/, '');
Expand Down
6 changes: 5 additions & 1 deletion packages/integrations/node/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.`);
}
},
},
};
Expand Down

0 comments on commit 570a9f3

Please sign in to comment.