diff --git a/packages/astro/src/@types/astro.ts b/packages/astro/src/@types/astro.ts index f76f0c96f..448cee9c6 100644 --- a/packages/astro/src/@types/astro.ts +++ b/packages/astro/src/@types/astro.ts @@ -177,15 +177,11 @@ export interface ComponentInfo { export type Components = Map; -type AsyncRendererComponentFn = ( - Component: any, - props: any, - children: string | undefined -) => Promise; +type AsyncRendererComponentFn = (Component: any, props: any, children: string | undefined) => Promise; export interface Renderer { check: AsyncRendererComponentFn; renderToStaticMarkup: AsyncRendererComponentFn<{ html: string; }>; -} \ No newline at end of file +} diff --git a/packages/astro/src/config_manager.ts b/packages/astro/src/config_manager.ts index 808ed4246..69635fda4 100644 --- a/packages/astro/src/config_manager.ts +++ b/packages/astro/src/config_manager.ts @@ -17,12 +17,7 @@ interface RendererInstance { const CONFIG_MODULE_BASE_NAME = '__astro_config.js'; const CONFIG_MODULE_URL = `/_astro_frontend/${CONFIG_MODULE_BASE_NAME}`; -const DEFAULT_RENDERERS = [ - '@astrojs/renderer-vue', - '@astrojs/renderer-svelte', - '@astrojs/renderer-react', - '@astrojs/renderer-preact' -]; +const DEFAULT_RENDERERS = ['@astrojs/renderer-vue', '@astrojs/renderer-svelte', '@astrojs/renderer-react', '@astrojs/renderer-preact']; export class ConfigManager { private state: 'initial' | 'dirty' | 'clean' = 'initial'; @@ -31,10 +26,7 @@ export class ConfigManager { private rendererNames!: string[]; private version = 1; - constructor( - private astroConfig: AstroConfig, - private resolvePackageUrl: (pkgName: string) => Promise, - ) { + constructor(private astroConfig: AstroConfig, private resolvePackageUrl: (pkgName: string) => Promise) { this.setRendererNames(this.astroConfig); } @@ -43,9 +35,9 @@ export class ConfigManager { } async update() { - if(this.needsUpdate() && this.snowpackRuntime) { + if (this.needsUpdate() && this.snowpackRuntime) { // astro.config.mjs has changed, reload it. - if(this.state === 'dirty') { + if (this.state === 'dirty') { const version = this.version++; const astroConfig = await loadConfig(this.astroConfig.projectRoot.pathname, `astro.config.mjs?version=${version}`); this.setRendererNames(astroConfig); @@ -79,15 +71,15 @@ export class ConfigManager { ) ).map(({ default: raw }, i) => { const { name = rendererNames[i], client, server, snowpackPlugin: snowpackPluginName, snowpackPluginOptions } = raw; - + if (typeof client !== 'string') { throw new Error(`Expected "client" from ${name} to be a relative path to the client-side renderer!`); } - + if (typeof server !== 'string') { throw new Error(`Expected "server" from ${name} to be a relative path to the server-side renderer!`); } - + let snowpackPlugin: RendererSnowpackPlugin; if (typeof snowpackPluginName === 'string') { if (snowpackPluginOptions) { @@ -98,7 +90,7 @@ export class ConfigManager { } else if (snowpackPluginName) { throw new Error(`Expected the snowpackPlugin from ${name} to be a "string" but encountered "${typeof snowpackPluginName}"!`); } - + return { name, snowpackPlugin, @@ -118,7 +110,7 @@ export class ConfigManager { import { setRenderers } from 'astro/dist/internal/__astro_component.js'; -let rendererSources = [${rendererClientPackages.map(pkg => `"${pkg}"`).join(', ')}]; +let rendererSources = [${rendererClientPackages.map((pkg) => `"${pkg}"`).join(', ')}]; let renderers = [${rendererServerPackages.map((_, i) => `__renderer_${i}`).join(', ')}]; ${contents} @@ -137,4 +129,4 @@ ${contents} private async importModule(snowpackRuntime: SnowpackServerRuntime): Promise { await snowpackRuntime!.importModule(CONFIG_MODULE_URL); } -} \ No newline at end of file +} diff --git a/packages/astro/src/frontend/__astro_config.ts b/packages/astro/src/frontend/__astro_config.ts index 1765ffffc..11d99ee3b 100644 --- a/packages/astro/src/frontend/__astro_config.ts +++ b/packages/astro/src/frontend/__astro_config.ts @@ -3,4 +3,4 @@ declare function setRenderers(sources: string[], renderers: any[]): void; declare let rendererSources: string[]; declare let renderers: any[]; -setRenderers(rendererSources, renderers); \ No newline at end of file +setRenderers(rendererSources, renderers); diff --git a/packages/astro/src/runtime.ts b/packages/astro/src/runtime.ts index 58606d3a0..a8992cae0 100644 --- a/packages/astro/src/runtime.ts +++ b/packages/astro/src/runtime.ts @@ -94,7 +94,7 @@ async function load(config: RuntimeConfig, rawPathname: string | undefined): Pro let rss: { data: any[] & CollectionRSS } = {} as any; try { - if(configManager.needsUpdate()) { + if (configManager.needsUpdate()) { await configManager.update(); } const mod = await snowpackRuntime.importModule(snowpackURL);