[ci] yarn format
This commit is contained in:
parent
c8a257adc4
commit
72096858e8
4 changed files with 45 additions and 30 deletions
|
@ -180,7 +180,7 @@ export type GetHydrateCallback = () => Promise<(element: Element, innerHTML: str
|
||||||
export type GetStaticPathsItem = { params: Params; props?: Props };
|
export type GetStaticPathsItem = { params: Params; props?: Props };
|
||||||
export type GetStaticPathsResult = GetStaticPathsItem[];
|
export type GetStaticPathsResult = GetStaticPathsItem[];
|
||||||
export type GetStaticPathsResultKeyed = GetStaticPathsResult & {
|
export type GetStaticPathsResultKeyed = GetStaticPathsResult & {
|
||||||
keyed: Map<string, GetStaticPathsItem>
|
keyed: Map<string, GetStaticPathsItem>;
|
||||||
};
|
};
|
||||||
|
|
||||||
export interface HydrateOptions {
|
export interface HydrateOptions {
|
||||||
|
|
|
@ -48,26 +48,26 @@ function chunkIsPage(output: OutputAsset | OutputChunk, internals: BuildInternal
|
||||||
}
|
}
|
||||||
|
|
||||||
// Throttle the rendering a paths to prevents creating too many Promises on the microtask queue.
|
// Throttle the rendering a paths to prevents creating too many Promises on the microtask queue.
|
||||||
function *throttle(max: number, inPaths: string[]) {
|
function* throttle(max: number, inPaths: string[]) {
|
||||||
let tmp = [];
|
let tmp = [];
|
||||||
let i = 0;
|
let i = 0;
|
||||||
for(let path of inPaths) {
|
for (let path of inPaths) {
|
||||||
tmp.push(path);
|
tmp.push(path);
|
||||||
if(i === max) {
|
if (i === max) {
|
||||||
yield tmp;
|
yield tmp;
|
||||||
// Empties the array, to avoid allocating a new one.
|
// Empties the array, to avoid allocating a new one.
|
||||||
tmp.length = 0;
|
tmp.length = 0;
|
||||||
i = 0;
|
i = 0;
|
||||||
} else {
|
} else {
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// If tmp has items in it, that means there were less than {max} paths remaining
|
// If tmp has items in it, that means there were less than {max} paths remaining
|
||||||
// at the end, so we need to yield these too.
|
// at the end, so we need to yield these too.
|
||||||
if(tmp.length) {
|
if (tmp.length) {
|
||||||
yield tmp;
|
yield tmp;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function staticBuild(opts: StaticBuildOptions) {
|
export async function staticBuild(opts: StaticBuildOptions) {
|
||||||
|
@ -273,15 +273,15 @@ async function generatePage(output: OutputChunk, opts: StaticBuildOptions, inter
|
||||||
|
|
||||||
const renderPromises = [];
|
const renderPromises = [];
|
||||||
// Throttle the paths to avoid overloading the CPU with too many tasks.
|
// Throttle the paths to avoid overloading the CPU with too many tasks.
|
||||||
for(const paths of throttle(MAX_CONCURRENT_RENDERS, pageData.paths)) {
|
for (const paths of throttle(MAX_CONCURRENT_RENDERS, pageData.paths)) {
|
||||||
for(const path of paths) {
|
for (const path of paths) {
|
||||||
renderPromises.push(generatePath(path, opts, generationOptions));
|
renderPromises.push(generatePath(path, opts, generationOptions));
|
||||||
}
|
}
|
||||||
// This blocks generating more paths until these 10 complete.
|
// This blocks generating more paths until these 10 complete.
|
||||||
await Promise.all(renderPromises);
|
await Promise.all(renderPromises);
|
||||||
// This empties the array without allocating a new one.
|
// This empties the array without allocating a new one.
|
||||||
renderPromises.length = 0;
|
renderPromises.length = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
interface GeneratePathOptions {
|
interface GeneratePathOptions {
|
||||||
|
@ -310,7 +310,7 @@ async function generatePath(pathname: string, opts: StaticBuildOptions, gopts: G
|
||||||
mod,
|
mod,
|
||||||
// Do not validate as validation already occurred for static routes
|
// Do not validate as validation already occurred for static routes
|
||||||
// and validation is relatively expensive.
|
// and validation is relatively expensive.
|
||||||
validate: false
|
validate: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
debug(logging, 'generate', `Generating: ${pathname}`);
|
debug(logging, 'generate', `Generating: ${pathname}`);
|
||||||
|
|
|
@ -1,6 +1,19 @@
|
||||||
import type { BuildResult } from 'esbuild';
|
import type { BuildResult } from 'esbuild';
|
||||||
import type vite from '../vite';
|
import type vite from '../vite';
|
||||||
import type { AstroConfig, ComponentInstance, GetStaticPathsResult, GetStaticPathsResultKeyed, Params, Props, Renderer, RouteCache, RouteData, RuntimeMode, SSRElement, SSRError } from '../../@types/astro';
|
import type {
|
||||||
|
AstroConfig,
|
||||||
|
ComponentInstance,
|
||||||
|
GetStaticPathsResult,
|
||||||
|
GetStaticPathsResultKeyed,
|
||||||
|
Params,
|
||||||
|
Props,
|
||||||
|
Renderer,
|
||||||
|
RouteCache,
|
||||||
|
RouteData,
|
||||||
|
RuntimeMode,
|
||||||
|
SSRElement,
|
||||||
|
SSRError,
|
||||||
|
} from '../../@types/astro';
|
||||||
import type { LogOptions } from '../logger';
|
import type { LogOptions } from '../logger';
|
||||||
|
|
||||||
import eol from 'eol';
|
import eol from 'eol';
|
||||||
|
@ -132,7 +145,7 @@ export async function getParamsAndProps({
|
||||||
logging,
|
logging,
|
||||||
pathname,
|
pathname,
|
||||||
mod,
|
mod,
|
||||||
validate = true
|
validate = true,
|
||||||
}: {
|
}: {
|
||||||
route: RouteData | undefined;
|
route: RouteData | undefined;
|
||||||
routeCache: RouteCache;
|
routeCache: RouteCache;
|
||||||
|
@ -151,13 +164,13 @@ export async function getParamsAndProps({
|
||||||
params = getParams(route.params)(paramsMatch);
|
params = getParams(route.params)(paramsMatch);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(validate) {
|
if (validate) {
|
||||||
validateGetStaticPathsModule(mod);
|
validateGetStaticPathsModule(mod);
|
||||||
}
|
}
|
||||||
if (!routeCache[route.component]) {
|
if (!routeCache[route.component]) {
|
||||||
await assignStaticPaths(routeCache, route, mod);
|
await assignStaticPaths(routeCache, route, mod);
|
||||||
}
|
}
|
||||||
if(validate) {
|
if (validate) {
|
||||||
// This validation is expensive so we only want to do it in dev.
|
// This validation is expensive so we only want to do it in dev.
|
||||||
validateGetStaticPathsResult(routeCache[route.component], logging);
|
validateGetStaticPathsResult(routeCache[route.component], logging);
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,15 +10,17 @@ export async function callGetStaticPaths(mod: ComponentInstance, route: RouteDat
|
||||||
const staticPaths: GetStaticPathsResult = await (
|
const staticPaths: GetStaticPathsResult = await (
|
||||||
await mod.getStaticPaths!({
|
await mod.getStaticPaths!({
|
||||||
paginate: generatePaginateFunction(route),
|
paginate: generatePaginateFunction(route),
|
||||||
rss: rssFn || (() => {
|
rss:
|
||||||
/* noop */
|
rssFn ||
|
||||||
}),
|
(() => {
|
||||||
|
/* noop */
|
||||||
|
}),
|
||||||
})
|
})
|
||||||
).flat();
|
).flat();
|
||||||
|
|
||||||
const keyedStaticPaths = staticPaths as GetStaticPathsResultKeyed;
|
const keyedStaticPaths = staticPaths as GetStaticPathsResultKeyed;
|
||||||
keyedStaticPaths.keyed = new Map<string, GetStaticPathsItem>();
|
keyedStaticPaths.keyed = new Map<string, GetStaticPathsItem>();
|
||||||
for(const sp of keyedStaticPaths) {
|
for (const sp of keyedStaticPaths) {
|
||||||
const paramsKey = JSON.stringify(sp.params);
|
const paramsKey = JSON.stringify(sp.params);
|
||||||
keyedStaticPaths.keyed.set(paramsKey, sp);
|
keyedStaticPaths.keyed.set(paramsKey, sp);
|
||||||
}
|
}
|
||||||
|
@ -43,7 +45,7 @@ export async function ensureRouteCached(routeCache: RouteCache, route: RouteData
|
||||||
|
|
||||||
export function findPathItemByKey(staticPaths: GetStaticPathsResultKeyed, paramsKey: string, logging: LogOptions) {
|
export function findPathItemByKey(staticPaths: GetStaticPathsResultKeyed, paramsKey: string, logging: LogOptions) {
|
||||||
let matchedStaticPath = staticPaths.keyed.get(paramsKey);
|
let matchedStaticPath = staticPaths.keyed.get(paramsKey);
|
||||||
if(matchedStaticPath) {
|
if (matchedStaticPath) {
|
||||||
return matchedStaticPath;
|
return matchedStaticPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue