From 6a8986784458e44beeb89e762b8d75f0e168c4b1 Mon Sep 17 00:00:00 2001 From: matthewp Date: Tue, 26 Jul 2022 12:57:00 +0000 Subject: [PATCH] [ci] format --- packages/astro/src/core/build/generate.ts | 60 +++++++++++----------- packages/astro/src/core/build/page-data.ts | 2 +- 2 files changed, 32 insertions(+), 30 deletions(-) diff --git a/packages/astro/src/core/build/generate.ts b/packages/astro/src/core/build/generate.ts index e6090608f0be..fb125dd28b18 100644 --- a/packages/astro/src/core/build/generate.ts +++ b/packages/astro/src/core/build/generate.ts @@ -1,7 +1,8 @@ import fs from 'fs'; +import * as colors from 'kleur/colors'; import { bgGreen, black, cyan, dim, green, magenta } from 'kleur/colors'; import npath from 'path'; -import type { OutputAsset, OutputChunk, RollupOutput } from 'rollup'; +import type { OutputAsset, OutputChunk } from 'rollup'; import { fileURLToPath } from 'url'; import type { AstroConfig, @@ -9,23 +10,27 @@ import type { EndpointHandler, SSRLoadedRenderer, } from '../../@types/astro'; -import * as colors from 'kleur/colors'; import type { BuildInternals } from '../../core/build/internal.js'; -import { joinPaths, prependForwardSlash, removeLeadingForwardSlash, removeTrailingForwardSlash } from '../../core/path.js'; +import { + joinPaths, + prependForwardSlash, + removeLeadingForwardSlash, + removeTrailingForwardSlash, +} from '../../core/path.js'; import type { RenderOptions } from '../../core/render/core'; import { BEFORE_HYDRATION_SCRIPT_ID } from '../../vite-plugin-scripts/index.js'; import { call as callEndpoint } from '../endpoint/index.js'; import { debug, info } from '../logger/core.js'; import { render } from '../render/core.js'; +import { callGetStaticPaths } from '../render/route-cache.js'; import { createLinkStylesheetElementSet, createModuleScriptsSet } from '../render/ssr-element.js'; import { createRequest } from '../request.js'; +import { matchRoute } from '../routing/match.js'; import { getOutputFilename } from '../util.js'; import { getOutFile, getOutFolder } from './common.js'; import { eachPageData, getPageDataByComponent } from './internal.js'; import type { PageBuildData, SingleFileBuiltModule, StaticBuildOptions } from './types'; import { getTimeStat } from './util.js'; -import { callGetStaticPaths, RouteCache, RouteCacheEntry } from '../render/route-cache.js'; -import { matchRoute } from '../routing/match.js'; // Render is usually compute, which Node.js can't parallelize well. // In real world testing, dropping from 10->1 showed a notiable perf @@ -91,10 +96,7 @@ export function chunkIsPage( return false; } -export async function generatePages( - opts: StaticBuildOptions, - internals: BuildInternals, -) { +export async function generatePages(opts: StaticBuildOptions, internals: BuildInternals) { const timer = performance.now(); info(opts.logging, null, `\n${bgGreen(black(' generating static routes '))}`); @@ -103,7 +105,7 @@ export async function generatePages( const outFolder = ssr ? opts.buildConfig.server : opts.astroConfig.outDir; const ssrEntryURL = new URL('./' + serverEntry + `?time=${Date.now()}`, outFolder); const ssrEntry = await import(ssrEntryURL.toString()); - const builtPaths = new Set; + const builtPaths = new Set(); for (const pageData of eachPageData(internals)) { await generatePage(opts, internals, pageData, ssrEntry, builtPaths); @@ -116,7 +118,7 @@ async function generatePage( internals: BuildInternals, pageData: PageBuildData, ssrEntry: SingleFileBuiltModule, - builtPaths: Set, + builtPaths: Set ) { let timeStart = performance.now(); const renderers = ssrEntry.renderers; @@ -169,10 +171,10 @@ async function getPathsForRoute( pageData: PageBuildData, mod: ComponentInstance, opts: StaticBuildOptions, - builtPaths: Set, + builtPaths: Set ): Promise> { let paths: Array = []; - if(pageData.route.pathname) { + if (pageData.route.pathname) { paths.push(pageData.route.pathname); builtPaths.add(pageData.route.pathname); } else { @@ -182,22 +184,22 @@ async function getPathsForRoute( route: pageData.route, isValidate: false, logging: opts.logging, - ssr: opts.astroConfig.output === 'server' + ssr: opts.astroConfig.output === 'server', }) - .then((_result) => { - const label = _result.staticPaths.length === 1 ? 'page' : 'pages'; - debug( - 'build', - `├── ${colors.bold(colors.green('✔'))} ${route.component} → ${colors.magenta( - `[${_result.staticPaths.length} ${label}]` - )}` - ); - return _result; - }) - .catch((err) => { - debug('build', `├── ${colors.bold(colors.red('✗'))} ${route.component}`); - throw err; - }); + .then((_result) => { + const label = _result.staticPaths.length === 1 ? 'page' : 'pages'; + debug( + 'build', + `├── ${colors.bold(colors.green('✔'))} ${route.component} → ${colors.magenta( + `[${_result.staticPaths.length} ${label}]` + )}` + ); + return _result; + }) + .catch((err) => { + debug('build', `├── ${colors.bold(colors.red('✗'))} ${route.component}`); + throw err; + }); // Save the route cache so it doesn't get called again opts.routeCache.set(route, result); @@ -225,7 +227,7 @@ async function getPathsForRoute( }); // Add each path to the builtPaths set, to avoid building it again later. - for(const staticPath of paths) { + for (const staticPath of paths) { builtPaths.add(removeTrailingForwardSlash(staticPath)); } } diff --git a/packages/astro/src/core/build/page-data.ts b/packages/astro/src/core/build/page-data.ts index d5e63d074bae..97c6a2915e50 100644 --- a/packages/astro/src/core/build/page-data.ts +++ b/packages/astro/src/core/build/page-data.ts @@ -27,7 +27,7 @@ export interface CollectPagesDataResult { export async function collectPagesData( opts: CollectPagesDataOptions ): Promise { - const { astroConfig, manifest } = opts; + const { astroConfig, manifest } = opts; const assets: Record = {}; const allPages: AllPagesData = {};