From b558bd51403f79a3c8ed593a4daeaa0ec349fcea Mon Sep 17 00:00:00 2001 From: matthewp Date: Fri, 24 Mar 2023 15:20:00 +0000 Subject: [PATCH] [ci] format --- packages/astro/src/@types/astro.ts | 4 +-- packages/astro/src/content/runtime.ts | 8 +---- packages/astro/src/core/app/types.ts | 2 +- packages/astro/src/core/build/graph.ts | 1 - .../astro/src/core/render/dev/metadata.ts | 15 ++++---- packages/astro/src/core/render/result.ts | 6 +--- .../runtime/server/render/astro/factory.ts | 2 +- .../astro/src/runtime/server/render/page.ts | 5 +-- packages/astro/src/vite-plugin-head/index.ts | 35 +++++++++++-------- 9 files changed, 35 insertions(+), 43 deletions(-) diff --git a/packages/astro/src/@types/astro.ts b/packages/astro/src/@types/astro.ts index ebb15de1d8..a496a5aa04 100644 --- a/packages/astro/src/@types/astro.ts +++ b/packages/astro/src/@types/astro.ts @@ -1594,8 +1594,8 @@ export interface SSRMetadata { export type PropagationHint = 'none' | 'self' | 'in-tree'; export type SSRComponentMetadata = { - propagation: PropagationHint, - containsHead: boolean + propagation: PropagationHint; + containsHead: boolean; }; export interface SSRResult { diff --git a/packages/astro/src/content/runtime.ts b/packages/astro/src/content/runtime.ts index a8d18e06f3..b97133dde4 100644 --- a/packages/astro/src/content/runtime.ts +++ b/packages/astro/src/content/runtime.ts @@ -178,13 +178,7 @@ async function render({ return createHeadAndContent( unescapeHTML(styles + links + scripts) as any, - renderTemplate`${renderComponent( - result, - 'Content', - mod.Content, - props, - slots - )}` + renderTemplate`${renderComponent(result, 'Content', mod.Content, props, slots)}` ); }, propagation: 'self', diff --git a/packages/astro/src/core/app/types.ts b/packages/astro/src/core/app/types.ts index 46cb34e80e..b7b5fa45a9 100644 --- a/packages/astro/src/core/app/types.ts +++ b/packages/astro/src/core/app/types.ts @@ -1,9 +1,9 @@ import type { MarkdownRenderingOptions } from '@astrojs/markdown-remark'; import type { ComponentInstance, - SSRComponentMetadata, RouteData, SerializedRouteData, + SSRComponentMetadata, SSRLoadedRenderer, SSRResult, } from '../../@types/astro'; diff --git a/packages/astro/src/core/build/graph.ts b/packages/astro/src/core/build/graph.ts index 6d404b572e..6d7335c095 100644 --- a/packages/astro/src/core/build/graph.ts +++ b/packages/astro/src/core/build/graph.ts @@ -1,5 +1,4 @@ import type { GetModuleInfo, ModuleInfo } from 'rollup'; -import type { ViteDevServer } from 'vite'; import { resolvedPagesVirtualModuleId } from '../app/index.js'; diff --git a/packages/astro/src/core/render/dev/metadata.ts b/packages/astro/src/core/render/dev/metadata.ts index a79c381867..bd0205bd90 100644 --- a/packages/astro/src/core/render/dev/metadata.ts +++ b/packages/astro/src/core/render/dev/metadata.ts @@ -1,4 +1,4 @@ -import type { SSRResult, SSRComponentMetadata } from '../../../@types/astro'; +import type { SSRComponentMetadata, SSRResult } from '../../../@types/astro'; import type { ModuleInfo, ModuleLoader } from '../../module-loader/index'; @@ -24,21 +24,18 @@ export async function getComponentMetadata( return map; } -function addMetadata( - map: SSRResult['componentMetadata'], - modInfo: ModuleInfo | null -) { +function addMetadata(map: SSRResult['componentMetadata'], modInfo: ModuleInfo | null) { if (modInfo) { const astro = getAstroMetadata(modInfo); - if(astro) { + if (astro) { let metadata: SSRComponentMetadata = { containsHead: false, - propagation: 'none' + propagation: 'none', }; - if(astro.propagation) { + if (astro.propagation) { metadata.propagation = astro.propagation; } - if(astro.containsHead) { + if (astro.containsHead) { metadata.containsHead = astro.containsHead; } map.set(modInfo.id, metadata); diff --git a/packages/astro/src/core/render/result.ts b/packages/astro/src/core/render/result.ts index 651ccc74c5..5305400cbe 100644 --- a/packages/astro/src/core/render/result.ts +++ b/packages/astro/src/core/render/result.ts @@ -9,11 +9,7 @@ import type { SSRLoadedRenderer, SSRResult, } from '../../@types/astro'; -import { - renderSlot, - stringifyChunk, - type ComponentSlots, -} from '../../runtime/server/index.js'; +import { renderSlot, stringifyChunk, type ComponentSlots } from '../../runtime/server/index.js'; import { renderJSX } from '../../runtime/server/jsx.js'; import { AstroCookies } from '../cookies/index.js'; import { AstroError, AstroErrorData } from '../errors/index.js'; diff --git a/packages/astro/src/runtime/server/render/astro/factory.ts b/packages/astro/src/runtime/server/render/astro/factory.ts index 045329c0f7..6d1b08563a 100644 --- a/packages/astro/src/runtime/server/render/astro/factory.ts +++ b/packages/astro/src/runtime/server/render/astro/factory.ts @@ -48,7 +48,7 @@ export function isAPropagatingComponent( factory: AstroComponentFactory ): boolean { let hint: PropagationHint = factory.propagation || 'none'; - if(factory.moduleId && result.componentMetadata.has(factory.moduleId) && hint === 'none') { + if (factory.moduleId && result.componentMetadata.has(factory.moduleId) && hint === 'none') { hint = result.componentMetadata.get(factory.moduleId)!.propagation; } return hint === 'in-tree' || hint === 'self'; diff --git a/packages/astro/src/runtime/server/render/page.ts b/packages/astro/src/runtime/server/render/page.ts index c703b79c5d..ac05abb889 100644 --- a/packages/astro/src/runtime/server/render/page.ts +++ b/packages/astro/src/runtime/server/render/page.ts @@ -83,7 +83,7 @@ export async function renderPage( try { if (nonAstroPageNeedsHeadInjection(componentFactory)) { const parts = new HTMLParts(); - for await(const chunk of maybeRenderHead(result)) { + for await (const chunk of maybeRenderHead(result)) { parts.append(chunk, result); } head = parts.toString(); @@ -125,7 +125,8 @@ export async function renderPage( } // Mark if this page component contains a within its tree. If it does // We avoid implicit head injection entirely. - result._metadata.headInTree = result.componentMetadata.get(componentFactory.moduleId!)?.containsHead ?? false; + result._metadata.headInTree = + result.componentMetadata.get(componentFactory.moduleId!)?.containsHead ?? false; const factoryReturnValue = await componentFactory(result, props, children); const factoryIsHeadAndContent = isHeadAndContent(factoryReturnValue); if (isRenderTemplateResult(factoryReturnValue) || factoryIsHeadAndContent) { diff --git a/packages/astro/src/vite-plugin-head/index.ts b/packages/astro/src/vite-plugin-head/index.ts index f0a3cd2b34..fc19893e83 100644 --- a/packages/astro/src/vite-plugin-head/index.ts +++ b/packages/astro/src/vite-plugin-head/index.ts @@ -1,6 +1,6 @@ -import type * as vite from 'vite'; import type { ModuleInfo } from 'rollup'; -import type { AstroSettings, SSRResult, SSRComponentMetadata } from '../@types/astro'; +import type * as vite from 'vite'; +import type { AstroSettings, SSRComponentMetadata, SSRResult } from '../@types/astro'; import type { AstroBuildPlugin } from '../core/build/plugin.js'; import type { StaticBuildOptions } from '../core/build/types'; import type { PluginMetadata } from '../vite-plugin-astro/types'; @@ -21,26 +21,31 @@ export default function configHeadVitePlugin({ function propagateMetadata< P extends keyof PluginMetadata['astro'], V extends PluginMetadata['astro'][P] - >(this: { getModuleInfo(id: string): ModuleInfo | null }, id: string, prop: P, value: V, seen = new Set()) { - if(seen.has(id)) return; + >( + this: { getModuleInfo(id: string): ModuleInfo | null }, + id: string, + prop: P, + value: V, + seen = new Set() + ) { + if (seen.has(id)) return; seen.add(id); const mod = server.moduleGraph.getModuleById(id); const info = this.getModuleInfo(id); if (info?.meta.astro) { - const astroMetadata = getAstroMetadata(info) - if(astroMetadata) { + const astroMetadata = getAstroMetadata(info); + if (astroMetadata) { Reflect.set(astroMetadata, prop, value); - } + } } for (const parent of mod?.importers || []) { - if(parent.id) { + if (parent.id) { propagateMetadata.call(this, parent.id, prop, value, seen); } } } - return { name: 'astro:head-metadata', configureServer(_server) { @@ -52,7 +57,7 @@ export default function configHeadVitePlugin({ } let info = this.getModuleInfo(id); - if(info && getAstroMetadata(info)?.containsHead) { + if (info && getAstroMetadata(info)?.containsHead) { propagateMetadata.call(this, id, 'containsHead', true); } @@ -77,23 +82,23 @@ export function astroHeadBuildPlugin( generateBundle(_opts, bundle) { const map: SSRResult['componentMetadata'] = internals.componentMetadata; function getOrCreateMetadata(id: string): SSRComponentMetadata { - if(map.has(id)) return map.get(id)!; + if (map.has(id)) return map.get(id)!; const metadata: SSRComponentMetadata = { propagation: 'none', - containsHead: false + containsHead: false, }; map.set(id, metadata); return metadata; } - for (const [,output] of Object.entries(bundle)) { + for (const [, output] of Object.entries(bundle)) { if (output.type !== 'chunk') continue; for (const [id, mod] of Object.entries(output.modules)) { const modinfo = this.getModuleInfo(id); // tag in the tree - if(modinfo && getAstroMetadata(modinfo)?.containsHead) { - for(const [pageInfo] of getTopLevelPages(id, this)) { + if (modinfo && getAstroMetadata(modinfo)?.containsHead) { + for (const [pageInfo] of getTopLevelPages(id, this)) { let metadata = getOrCreateMetadata(pageInfo.id); metadata.containsHead = true; }