Skip to content

Commit

Permalink
[ci] format
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewp authored and astrobot-houston committed Jul 26, 2022
1 parent 453c026 commit 6a89867
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 30 deletions.
60 changes: 31 additions & 29 deletions packages/astro/src/core/build/generate.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,36 @@
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,
ComponentInstance,
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
Expand Down Expand Up @@ -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 '))}`);

Expand All @@ -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<string>;
const builtPaths = new Set<string>();

for (const pageData of eachPageData(internals)) {
await generatePage(opts, internals, pageData, ssrEntry, builtPaths);
Expand All @@ -116,7 +118,7 @@ async function generatePage(
internals: BuildInternals,
pageData: PageBuildData,
ssrEntry: SingleFileBuiltModule,
builtPaths: Set<string>,
builtPaths: Set<string>
) {
let timeStart = performance.now();
const renderers = ssrEntry.renderers;
Expand Down Expand Up @@ -169,10 +171,10 @@ async function getPathsForRoute(
pageData: PageBuildData,
mod: ComponentInstance,
opts: StaticBuildOptions,
builtPaths: Set<string>,
builtPaths: Set<string>
): Promise<Array<string>> {
let paths: Array<string> = [];
if(pageData.route.pathname) {
if (pageData.route.pathname) {
paths.push(pageData.route.pathname);
builtPaths.add(pageData.route.pathname);
} else {
Expand All @@ -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);
Expand Down Expand Up @@ -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));
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/src/core/build/page-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export interface CollectPagesDataResult {
export async function collectPagesData(
opts: CollectPagesDataOptions
): Promise<CollectPagesDataResult> {
const { astroConfig, manifest } = opts;
const { astroConfig, manifest } = opts;

const assets: Record<string, string> = {};
const allPages: AllPagesData = {};
Expand Down

0 comments on commit 6a89867

Please sign in to comment.