From 948f82048b6a7a35a2e26cc2a6ad394d4f4210e2 Mon Sep 17 00:00:00 2001 From: matthewp Date: Tue, 21 Jun 2022 12:33:55 +0000 Subject: [PATCH] [ci] format --- packages/astro/src/core/build/generate.ts | 5 +- packages/astro/src/core/build/graph.ts | 2 +- packages/astro/src/core/build/page-data.ts | 3 +- packages/astro/src/core/build/static-build.ts | 15 +++--- .../src/core/build/vite-plugin-analyzer.ts | 52 ++++++++----------- .../astro/src/core/build/vite-plugin-ssr.ts | 6 +-- packages/astro/src/runtime/server/metadata.ts | 3 +- packages/astro/src/vite-plugin-astro/index.ts | 4 +- packages/astro/src/vite-plugin-astro/types.ts | 8 +-- .../astro/src/vite-plugin-build-css/index.ts | 5 +- .../astro/src/vite-plugin-markdown/index.ts | 5 +- .../astro/test/astro-markdown-drafts.test.js | 2 +- packages/integrations/lit/server-shim.js | 4 +- packages/integrations/lit/server.js | 4 +- packages/integrations/lit/src/index.ts | 2 +- .../netlify/src/integration-edge-functions.ts | 12 ++--- .../edge-functions/dynamic-import.test.js | 2 +- 17 files changed, 61 insertions(+), 73 deletions(-) diff --git a/packages/astro/src/core/build/generate.ts b/packages/astro/src/core/build/generate.ts index 469d04c50..37abb91ad 100644 --- a/packages/astro/src/core/build/generate.ts +++ b/packages/astro/src/core/build/generate.ts @@ -61,7 +61,8 @@ function shouldSkipDraft(pageModule: ComponentInstance, astroConfig: AstroConfig // Drafts are disabled !astroConfig.markdown.drafts && // This is a draft post - ('frontmatter' in pageModule && (pageModule as any).frontmatter.draft === true) + 'frontmatter' in pageModule && + (pageModule as any).frontmatter.draft === true ); } @@ -133,7 +134,7 @@ async function generatePage( ); } - if(shouldSkipDraft(pageModule, opts.astroConfig)) { + if (shouldSkipDraft(pageModule, opts.astroConfig)) { info(opts.logging, null, `${magenta('⚠️')} Skipping draft ${pageData.route.component}`); return; } diff --git a/packages/astro/src/core/build/graph.ts b/packages/astro/src/core/build/graph.ts index e1b0b62b7..a0fa4a8b9 100644 --- a/packages/astro/src/core/build/graph.ts +++ b/packages/astro/src/core/build/graph.ts @@ -1,4 +1,4 @@ -import type { GetModuleInfo, ModuleInfo, OutputChunk } from 'rollup'; +import type { GetModuleInfo, ModuleInfo } from 'rollup'; import { resolvedPagesVirtualModuleId } from '../app/index.js'; // This walks up the dependency graph and yields out each ModuleInfo object. diff --git a/packages/astro/src/core/build/page-data.ts b/packages/astro/src/core/build/page-data.ts index 371b7bd26..232278346 100644 --- a/packages/astro/src/core/build/page-data.ts +++ b/packages/astro/src/core/build/page-data.ts @@ -8,7 +8,6 @@ import * as colors from 'kleur/colors'; import { fileURLToPath } from 'url'; import { debug } from '../logger/core.js'; import { removeTrailingForwardSlash } from '../path.js'; -import { preload as ssrPreload } from '../render/dev/index.js'; import { callGetStaticPaths, RouteCache, RouteCacheEntry } from '../render/route-cache.js'; import { matchRoute } from '../routing/match.js'; import { isBuildingToSSR } from '../util.js'; @@ -132,7 +131,7 @@ export async function collectPagesData( moduleSpecifier: '', css: new Set(), hoistedScript: undefined, - scripts: new Set() + scripts: new Set(), }; } diff --git a/packages/astro/src/core/build/static-build.ts b/packages/astro/src/core/build/static-build.ts index 2300c790a..cbce7ab14 100644 --- a/packages/astro/src/core/build/static-build.ts +++ b/packages/astro/src/core/build/static-build.ts @@ -4,10 +4,7 @@ import { bgGreen, bgMagenta, black, dim } from 'kleur/colors'; import type { RollupOutput } from 'rollup'; import { fileURLToPath } from 'url'; import * as vite from 'vite'; -import { - BuildInternals, - createBuildInternals, -} from '../../core/build/internal.js'; +import { BuildInternals, createBuildInternals } from '../../core/build/internal.js'; import { prependForwardSlash } from '../../core/path.js'; import { emptyDir, removeDir } from '../../core/util.js'; import { runHookBuildSetup } from '../../integrations/index.js'; @@ -19,11 +16,11 @@ import { generatePages } from './generate.js'; import { trackPageData } from './internal.js'; import type { PageBuildData, StaticBuildOptions } from './types'; import { getTimeStat } from './util.js'; +import { vitePluginAnalyzer } from './vite-plugin-analyzer.js'; import { vitePluginHoistedScripts } from './vite-plugin-hoisted-scripts.js'; import { vitePluginInternals } from './vite-plugin-internals.js'; import { vitePluginPages } from './vite-plugin-pages.js'; -import { vitePluginSSR, injectManifest } from './vite-plugin-ssr.js'; -import { vitePluginAnalyzer } from './vite-plugin-analyzer.js'; +import { injectManifest, vitePluginSSR } from './vite-plugin-ssr.js'; export async function staticBuild(opts: StaticBuildOptions) { const { allPages, astroConfig } = opts; @@ -73,7 +70,7 @@ export async function staticBuild(opts: StaticBuildOptions) { const clientInput = new Set([ ...internals.discoveredHydratedComponents, ...internals.discoveredClientOnlyComponents, - ...astroConfig._ctx.renderers.map(r => r.clientEntrypoint).filter(a => a) as string[], + ...(astroConfig._ctx.renderers.map((r) => r.clientEntrypoint).filter((a) => a) as string[]), ...internals.discoveredScripts, ]); @@ -90,7 +87,7 @@ export async function staticBuild(opts: StaticBuildOptions) { } } else { // Inject the manifest - await injectManifest(opts, internals) + await injectManifest(opts, internals); info(opts.logging, null, `\n${bgMagenta(black(' finalizing server assets '))}\n`); await ssrMoveAssets(opts); @@ -144,7 +141,7 @@ async function ssrBuild(opts: StaticBuildOptions, internals: BuildInternals, inp // SSR needs to be last isBuildingToSSR(opts.astroConfig) && vitePluginSSR(opts, internals, opts.astroConfig._ctx.adapter!), - vitePluginAnalyzer(opts.astroConfig, internals) + vitePluginAnalyzer(opts.astroConfig, internals), ], publicDir: ssr ? false : viteConfig.publicDir, root: viteConfig.root, diff --git a/packages/astro/src/core/build/vite-plugin-analyzer.ts b/packages/astro/src/core/build/vite-plugin-analyzer.ts index 8b8b663e6..5759cf6bd 100644 --- a/packages/astro/src/core/build/vite-plugin-analyzer.ts +++ b/packages/astro/src/core/build/vite-plugin-analyzer.ts @@ -1,41 +1,33 @@ - - -import type { Plugin as VitePlugin } from 'vite'; import type { PluginContext } from 'rollup'; +import type { Plugin as VitePlugin } from 'vite'; import type { AstroConfig } from '../../@types/astro'; import type { BuildInternals } from '../../core/build/internal.js'; import type { PluginMetadata as AstroPluginMetadata } from '../../vite-plugin-astro/types'; import { prependForwardSlash } from '../../core/path.js'; -import { getPageDataByViteID, trackClientOnlyPageDatas } from './internal.js'; import { getTopLevelPages } from './graph.js'; - +import { getPageDataByViteID, trackClientOnlyPageDatas } from './internal.js'; export function vitePluginAnalyzer( astroConfig: AstroConfig, internals: BuildInternals ): VitePlugin { - function hoistedScriptScanner() { const uniqueHoistedIds = new Map(); const pageScripts = new Map>(); return { - scan( - this: PluginContext, - scripts: AstroPluginMetadata['astro']['scripts'], - from: string - ) { + scan(this: PluginContext, scripts: AstroPluginMetadata['astro']['scripts'], from: string) { const hoistedScripts = new Set(); - for(let i = 0; i < scripts.length; i++) { + for (let i = 0; i < scripts.length; i++) { const hid = `${from.replace('/@fs', '')}?astro&type=script&index=${i}`; hoistedScripts.add(hid); } if (hoistedScripts.size) { - for(const pageId of getTopLevelPages(from, this)) { - for(const hid of hoistedScripts) { - if(pageScripts.has(pageId)) { + for (const pageId of getTopLevelPages(from, this)) { + for (const hid of hoistedScripts) { + if (pageScripts.has(pageId)) { pageScripts.get(pageId)?.add(hid); } else { pageScripts.set(pageId, new Set([hid])); @@ -46,16 +38,16 @@ export function vitePluginAnalyzer( }, finalize() { - for(const [pageId, hoistedScripts] of pageScripts) { + for (const [pageId, hoistedScripts] of pageScripts) { const pageData = getPageDataByViteID(internals, pageId); - if(!pageData) continue; + if (!pageData) continue; const { component } = pageData; const astroModuleId = prependForwardSlash(component); const uniqueHoistedId = JSON.stringify(Array.from(hoistedScripts).sort()); let moduleId: string; - + // If we're already tracking this set of hoisted scripts, get the unique id if (uniqueHoistedIds.has(uniqueHoistedId)) { moduleId = uniqueHoistedIds.get(uniqueHoistedId)!; @@ -65,7 +57,7 @@ export function vitePluginAnalyzer( uniqueHoistedIds.set(uniqueHoistedId, moduleId); } internals.discoveredScripts.add(moduleId); - + // Make sure to track that this page uses this set of hoisted scripts if (internals.hoistedScriptIdToPagesMap.has(moduleId)) { const pages = internals.hoistedScriptIdToPagesMap.get(moduleId); @@ -75,42 +67,42 @@ export function vitePluginAnalyzer( internals.hoistedScriptIdToHoistedMap.set(moduleId, hoistedScripts); } } - } + }, }; } - + return { name: '@astro/rollup-plugin-astro-analyzer', generateBundle() { const hoistScanner = hoistedScriptScanner(); const ids = this.getModuleIds(); - for(const id of ids) { + for (const id of ids) { const info = this.getModuleInfo(id); - if(!info || !info.meta?.astro) continue; + if (!info || !info.meta?.astro) continue; const astro = info.meta.astro as AstroPluginMetadata['astro']; - for(const c of astro.hydratedComponents) { + for (const c of astro.hydratedComponents) { internals.discoveredHydratedComponents.add(c.resolvedPath || c.specifier); } // Scan hoisted scripts hoistScanner.scan.call(this, astro.scripts, id); - if(astro.clientOnlyComponents.length) { + if (astro.clientOnlyComponents.length) { const clientOnlys: string[] = []; - for(const c of astro.clientOnlyComponents) { + for (const c of astro.clientOnlyComponents) { const cid = c.resolvedPath || c.specifier; internals.discoveredClientOnlyComponents.add(cid); clientOnlys.push(cid); } - for(const pageId of getTopLevelPages(id, this)) { + for (const pageId of getTopLevelPages(id, this)) { const pageData = getPageDataByViteID(internals, pageId); - if(!pageData) continue; - + if (!pageData) continue; + trackClientOnlyPageDatas(internals, pageData, clientOnlys); } } @@ -118,6 +110,6 @@ export function vitePluginAnalyzer( // Finalize hoisting hoistScanner.finalize(); - } + }, }; } diff --git a/packages/astro/src/core/build/vite-plugin-ssr.ts b/packages/astro/src/core/build/vite-plugin-ssr.ts index 4fc1274c7..e543e925e 100644 --- a/packages/astro/src/core/build/vite-plugin-ssr.ts +++ b/packages/astro/src/core/build/vite-plugin-ssr.ts @@ -5,6 +5,7 @@ import type { BuildInternals } from './internal.js'; import type { StaticBuildOptions } from './types'; import glob from 'fast-glob'; +import * as fs from 'fs'; import { fileURLToPath } from 'url'; import { runHookBuildSsr } from '../../integrations/index.js'; import { BEFORE_HYDRATION_SCRIPT_ID } from '../../vite-plugin-scripts/index.js'; @@ -12,7 +13,6 @@ import { pagesVirtualModuleId } from '../app/index.js'; import { serializeRouteData } from '../routing/index.js'; import { addRollupInput } from './add-rollup-input.js'; import { eachPageData } from './internal.js'; -import * as fs from 'fs'; export const virtualModuleId = '@astrojs-ssr-virtual-entry'; const resolvedVirtualModuleId = '\0' + virtualModuleId; @@ -82,7 +82,7 @@ if(_start in adapter) { internals.staticFiles.add(chunk.fileName); } } - + for (const [chunkName, chunk] of Object.entries(bundle)) { if (chunk.type === 'asset') { continue; @@ -97,7 +97,7 @@ if(_start in adapter) { } export async function injectManifest(buildOpts: StaticBuildOptions, internals: BuildInternals) { - if(!internals.ssrEntryChunk) { + if (!internals.ssrEntryChunk) { throw new Error(`Did not generate an entry chunk for SSR`); } diff --git a/packages/astro/src/runtime/server/metadata.ts b/packages/astro/src/runtime/server/metadata.ts index 11adeb4ea..c2bf0407f 100644 --- a/packages/astro/src/runtime/server/metadata.ts +++ b/packages/astro/src/runtime/server/metadata.ts @@ -52,7 +52,8 @@ export class Metadata { *hoistedScriptPaths() { for (const metadata of this.deepMetadata()) { - let i = 0, pathname = metadata.mockURL.pathname; + let i = 0, + pathname = metadata.mockURL.pathname; while (i < metadata.hoisted.length) { // Strip off the leading "/@fs" added during compilation. diff --git a/packages/astro/src/vite-plugin-astro/index.ts b/packages/astro/src/vite-plugin-astro/index.ts index b0e97c2e0..94fea7c89 100644 --- a/packages/astro/src/vite-plugin-astro/index.ts +++ b/packages/astro/src/vite-plugin-astro/index.ts @@ -113,7 +113,7 @@ export default function astro({ config, logging }: AstroPluginOptions): vite.Plu source, ssr: Boolean(opts?.ssr), viteTransform, - pluginContext: this + pluginContext: this, }; if (query.astro) { if (query.type === 'style') { @@ -222,7 +222,7 @@ export default function astro({ config, logging }: AstroPluginOptions): vite.Plu const astroMetadata: AstroPluginMetadata['astro'] = { clientOnlyComponents: transformResult.clientOnlyComponents, hydratedComponents: transformResult.hydratedComponents, - scripts: transformResult.scripts + scripts: transformResult.scripts, }; return { diff --git a/packages/astro/src/vite-plugin-astro/types.ts b/packages/astro/src/vite-plugin-astro/types.ts index 6537b6f38..bf6a1cee5 100644 --- a/packages/astro/src/vite-plugin-astro/types.ts +++ b/packages/astro/src/vite-plugin-astro/types.ts @@ -2,8 +2,8 @@ import type { TransformResult } from '@astrojs/compiler'; export interface PluginMetadata { astro: { - hydratedComponents: TransformResult['hydratedComponents'], - clientOnlyComponents: TransformResult['clientOnlyComponents'], - scripts: TransformResult['scripts'] - } + hydratedComponents: TransformResult['hydratedComponents']; + clientOnlyComponents: TransformResult['clientOnlyComponents']; + scripts: TransformResult['scripts']; + }; } diff --git a/packages/astro/src/vite-plugin-build-css/index.ts b/packages/astro/src/vite-plugin-build-css/index.ts index 46fcdecff..1407688b1 100644 --- a/packages/astro/src/vite-plugin-build-css/index.ts +++ b/packages/astro/src/vite-plugin-build-css/index.ts @@ -1,13 +1,12 @@ -import type { GetModuleInfo, ModuleInfo, OutputChunk } from 'rollup'; +import type { GetModuleInfo, OutputChunk } from 'rollup'; import { BuildInternals } from '../core/build/internal'; import type { PageBuildData } from '../core/build/types'; import crypto from 'crypto'; import esbuild from 'esbuild'; import { Plugin as VitePlugin } from 'vite'; -import { resolvedPagesVirtualModuleId } from '../core/app/index.js'; -import { getPageDataByViteID, getPageDatasByClientOnlyID } from '../core/build/internal.js'; import { getTopLevelPages, walkParentInfos } from '../core/build/graph.js'; +import { getPageDataByViteID, getPageDatasByClientOnlyID } from '../core/build/internal.js'; import { isCSSRequest } from '../core/render/util.js'; interface PluginOptions { diff --git a/packages/astro/src/vite-plugin-markdown/index.ts b/packages/astro/src/vite-plugin-markdown/index.ts index 77b70a2aa..431097200 100644 --- a/packages/astro/src/vite-plugin-markdown/index.ts +++ b/packages/astro/src/vite-plugin-markdown/index.ts @@ -7,15 +7,14 @@ import matter from 'gray-matter'; import { fileURLToPath } from 'url'; import type { Plugin } from 'vite'; import type { AstroConfig } from '../@types/astro'; -import type { PluginMetadata as AstroPluginMetadata } from '../vite-plugin-astro/types'; import { pagesVirtualModuleId } from '../core/app/index.js'; import { collectErrorMetadata } from '../core/errors.js'; import { prependForwardSlash } from '../core/path.js'; import { resolvePages, viteID } from '../core/util.js'; +import type { PluginMetadata as AstroPluginMetadata } from '../vite-plugin-astro/types'; import { PAGE_SSR_SCRIPT_ID } from '../vite-plugin-scripts/index.js'; import { getFileInfo } from '../vite-plugin-utils/index.js'; - interface AstroPluginOptions { config: AstroConfig; } @@ -212,7 +211,7 @@ ${tsResult}`; const astroMetadata: AstroPluginMetadata['astro'] = { clientOnlyComponents: transformResult.clientOnlyComponents, hydratedComponents: transformResult.hydratedComponents, - scripts: transformResult.scripts + scripts: transformResult.scripts, }; return { diff --git a/packages/astro/test/astro-markdown-drafts.test.js b/packages/astro/test/astro-markdown-drafts.test.js index 4d44bdb67..8f6c753e4 100644 --- a/packages/astro/test/astro-markdown-drafts.test.js +++ b/packages/astro/test/astro-markdown-drafts.test.js @@ -19,7 +19,7 @@ describe('Astro Markdown with draft posts disabled', () => { } catch (err) { expect(err.code).to.equal('ENOENT'); } - expect(renderedDraft).to.equal(false,'Rendered a draft post'); + expect(renderedDraft).to.equal(false, 'Rendered a draft post'); }); }); diff --git a/packages/integrations/lit/server-shim.js b/packages/integrations/lit/server-shim.js index e4d123c37..9a4c7e408 100644 --- a/packages/integrations/lit/server-shim.js +++ b/packages/integrations/lit/server-shim.js @@ -7,7 +7,7 @@ document.getElementsByTagName = () => []; document.currentScript = null; const ceDefine = customElements.define; -customElements.define = function(tagName, Ctr) { +customElements.define = function (tagName, Ctr) { Ctr[Symbol.for('tagName')] = tagName; return ceDefine.call(this, tagName, Ctr); -} +}; diff --git a/packages/integrations/lit/server.js b/packages/integrations/lit/server.js index df284dbeb..bc8995061 100644 --- a/packages/integrations/lit/server.js +++ b/packages/integrations/lit/server.js @@ -9,7 +9,7 @@ function isCustomElementTag(name) { function getCustomElementConstructor(name) { if (typeof customElements !== 'undefined' && isCustomElementTag(name)) { return customElements.get(name) || null; - } else if(typeof name === 'function') { + } else if (typeof name === 'function') { return name; } return null; @@ -28,7 +28,7 @@ async function check(Component, _props, _children) { function* render(Component, attrs, children) { let tagName = Component; - if(typeof tagName !== 'string') { + if (typeof tagName !== 'string') { tagName = Component[Symbol.for('tagName')]; } const instance = new LitElementRenderer(tagName); diff --git a/packages/integrations/lit/src/index.ts b/packages/integrations/lit/src/index.ts index bebb58ac3..95db13c3d 100644 --- a/packages/integrations/lit/src/index.ts +++ b/packages/integrations/lit/src/index.ts @@ -18,7 +18,7 @@ function getViteConfiguration() { '@lit-labs/ssr/lib/install-global-dom-shim.js', '@lit-labs/ssr/lib/render-lit-html.js', '@lit-labs/ssr/lib/lit-element-renderer.js', - '@astrojs/lit/server.js' + '@astrojs/lit/server.js', ], }, }; diff --git a/packages/integrations/netlify/src/integration-edge-functions.ts b/packages/integrations/netlify/src/integration-edge-functions.ts index f82e6ecc2..72788abaf 100644 --- a/packages/integrations/netlify/src/integration-edge-functions.ts +++ b/packages/integrations/netlify/src/integration-edge-functions.ts @@ -1,9 +1,9 @@ import type { AstroAdapter, AstroConfig, AstroIntegration, BuildConfig, RouteData } from 'astro'; -import type { Plugin as VitePlugin } from 'vite'; import esbuild from 'esbuild'; import * as fs from 'fs'; import * as npath from 'path'; import { fileURLToPath } from 'url'; +import type { Plugin as VitePlugin } from 'vite'; import { createRedirects } from './shared.js'; export function getAdapter(): AstroAdapter { @@ -109,19 +109,19 @@ export function netlifyEdgeFunctions({ dist }: NetlifyEdgeFunctionsOptions = {}) const injectPlugin: VitePlugin = { name: '@astrojs/netlify/plugin-inject', generateBundle(_options, bundle) { - if(_buildConfig.serverEntry in bundle) { + if (_buildConfig.serverEntry in bundle) { const chunk = bundle[_buildConfig.serverEntry]; - if(chunk && chunk.type === 'chunk') { + if (chunk && chunk.type === 'chunk') { chunk.code = `globalThis.process = { argv: [], env: {}, };${chunk.code}`; } } - } + }, }; updateConfig({ vite: { - plugins: [injectPlugin] - } + plugins: [injectPlugin], + }, }); }, 'astro:config:done': ({ config, setAdapter }) => { diff --git a/packages/integrations/netlify/test/edge-functions/dynamic-import.test.js b/packages/integrations/netlify/test/edge-functions/dynamic-import.test.js index b23f9b4c4..2a261b7f6 100644 --- a/packages/integrations/netlify/test/edge-functions/dynamic-import.test.js +++ b/packages/integrations/netlify/test/edge-functions/dynamic-import.test.js @@ -19,7 +19,7 @@ Deno.test({ const doc = new DOMParser().parseFromString(html, `text/html`); const div = doc.querySelector('#thing'); assert(div, 'div exists'); - } catch(err) { + } catch (err) { console.error(err); } finally { await close();