[ci] yarn format

This commit is contained in:
matthewp 2021-06-21 12:46:24 +00:00 committed by GitHub Actions
parent 1f6fe888db
commit cab79548db
4 changed files with 14 additions and 26 deletions

View file

@ -177,15 +177,11 @@ export interface ComponentInfo {
export type Components = Map<string, ComponentInfo>; export type Components = Map<string, ComponentInfo>;
type AsyncRendererComponentFn<U> = ( type AsyncRendererComponentFn<U> = (Component: any, props: any, children: string | undefined) => Promise<U>;
Component: any,
props: any,
children: string | undefined
) => Promise<U>;
export interface Renderer { export interface Renderer {
check: AsyncRendererComponentFn<boolean>; check: AsyncRendererComponentFn<boolean>;
renderToStaticMarkup: AsyncRendererComponentFn<{ renderToStaticMarkup: AsyncRendererComponentFn<{
html: string; html: string;
}>; }>;
} }

View file

@ -17,12 +17,7 @@ interface RendererInstance {
const CONFIG_MODULE_BASE_NAME = '__astro_config.js'; const CONFIG_MODULE_BASE_NAME = '__astro_config.js';
const CONFIG_MODULE_URL = `/_astro_frontend/${CONFIG_MODULE_BASE_NAME}`; const CONFIG_MODULE_URL = `/_astro_frontend/${CONFIG_MODULE_BASE_NAME}`;
const DEFAULT_RENDERERS = [ const DEFAULT_RENDERERS = ['@astrojs/renderer-vue', '@astrojs/renderer-svelte', '@astrojs/renderer-react', '@astrojs/renderer-preact'];
'@astrojs/renderer-vue',
'@astrojs/renderer-svelte',
'@astrojs/renderer-react',
'@astrojs/renderer-preact'
];
export class ConfigManager { export class ConfigManager {
private state: 'initial' | 'dirty' | 'clean' = 'initial'; private state: 'initial' | 'dirty' | 'clean' = 'initial';
@ -31,10 +26,7 @@ export class ConfigManager {
private rendererNames!: string[]; private rendererNames!: string[];
private version = 1; private version = 1;
constructor( constructor(private astroConfig: AstroConfig, private resolvePackageUrl: (pkgName: string) => Promise<string>) {
private astroConfig: AstroConfig,
private resolvePackageUrl: (pkgName: string) => Promise<string>,
) {
this.setRendererNames(this.astroConfig); this.setRendererNames(this.astroConfig);
} }
@ -43,9 +35,9 @@ export class ConfigManager {
} }
async update() { async update() {
if(this.needsUpdate() && this.snowpackRuntime) { if (this.needsUpdate() && this.snowpackRuntime) {
// astro.config.mjs has changed, reload it. // astro.config.mjs has changed, reload it.
if(this.state === 'dirty') { if (this.state === 'dirty') {
const version = this.version++; const version = this.version++;
const astroConfig = await loadConfig(this.astroConfig.projectRoot.pathname, `astro.config.mjs?version=${version}`); const astroConfig = await loadConfig(this.astroConfig.projectRoot.pathname, `astro.config.mjs?version=${version}`);
this.setRendererNames(astroConfig); this.setRendererNames(astroConfig);
@ -79,15 +71,15 @@ export class ConfigManager {
) )
).map(({ default: raw }, i) => { ).map(({ default: raw }, i) => {
const { name = rendererNames[i], client, server, snowpackPlugin: snowpackPluginName, snowpackPluginOptions } = raw; const { name = rendererNames[i], client, server, snowpackPlugin: snowpackPluginName, snowpackPluginOptions } = raw;
if (typeof client !== 'string') { if (typeof client !== 'string') {
throw new Error(`Expected "client" from ${name} to be a relative path to the client-side renderer!`); throw new Error(`Expected "client" from ${name} to be a relative path to the client-side renderer!`);
} }
if (typeof server !== 'string') { if (typeof server !== 'string') {
throw new Error(`Expected "server" from ${name} to be a relative path to the server-side renderer!`); throw new Error(`Expected "server" from ${name} to be a relative path to the server-side renderer!`);
} }
let snowpackPlugin: RendererSnowpackPlugin; let snowpackPlugin: RendererSnowpackPlugin;
if (typeof snowpackPluginName === 'string') { if (typeof snowpackPluginName === 'string') {
if (snowpackPluginOptions) { if (snowpackPluginOptions) {
@ -98,7 +90,7 @@ export class ConfigManager {
} else if (snowpackPluginName) { } else if (snowpackPluginName) {
throw new Error(`Expected the snowpackPlugin from ${name} to be a "string" but encountered "${typeof snowpackPluginName}"!`); throw new Error(`Expected the snowpackPlugin from ${name} to be a "string" but encountered "${typeof snowpackPluginName}"!`);
} }
return { return {
name, name,
snowpackPlugin, snowpackPlugin,
@ -118,7 +110,7 @@ export class ConfigManager {
import { setRenderers } from 'astro/dist/internal/__astro_component.js'; 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(', ')}]; let renderers = [${rendererServerPackages.map((_, i) => `__renderer_${i}`).join(', ')}];
${contents} ${contents}
@ -137,4 +129,4 @@ ${contents}
private async importModule(snowpackRuntime: SnowpackServerRuntime): Promise<void> { private async importModule(snowpackRuntime: SnowpackServerRuntime): Promise<void> {
await snowpackRuntime!.importModule(CONFIG_MODULE_URL); await snowpackRuntime!.importModule(CONFIG_MODULE_URL);
} }
} }

View file

@ -3,4 +3,4 @@ declare function setRenderers(sources: string[], renderers: any[]): void;
declare let rendererSources: string[]; declare let rendererSources: string[];
declare let renderers: any[]; declare let renderers: any[];
setRenderers(rendererSources, renderers); setRenderers(rendererSources, renderers);

View file

@ -94,7 +94,7 @@ async function load(config: RuntimeConfig, rawPathname: string | undefined): Pro
let rss: { data: any[] & CollectionRSS } = {} as any; let rss: { data: any[] & CollectionRSS } = {} as any;
try { try {
if(configManager.needsUpdate()) { if (configManager.needsUpdate()) {
await configManager.update(); await configManager.update();
} }
const mod = await snowpackRuntime.importModule(snowpackURL); const mod = await snowpackRuntime.importModule(snowpackURL);