[ci] format
This commit is contained in:
parent
453c026aa7
commit
6a89867844
2 changed files with 32 additions and 30 deletions
|
@ -1,7 +1,8 @@
|
||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
|
import * as colors from 'kleur/colors';
|
||||||
import { bgGreen, black, cyan, dim, green, magenta } from 'kleur/colors';
|
import { bgGreen, black, cyan, dim, green, magenta } from 'kleur/colors';
|
||||||
import npath from 'path';
|
import npath from 'path';
|
||||||
import type { OutputAsset, OutputChunk, RollupOutput } from 'rollup';
|
import type { OutputAsset, OutputChunk } from 'rollup';
|
||||||
import { fileURLToPath } from 'url';
|
import { fileURLToPath } from 'url';
|
||||||
import type {
|
import type {
|
||||||
AstroConfig,
|
AstroConfig,
|
||||||
|
@ -9,23 +10,27 @@ import type {
|
||||||
EndpointHandler,
|
EndpointHandler,
|
||||||
SSRLoadedRenderer,
|
SSRLoadedRenderer,
|
||||||
} from '../../@types/astro';
|
} from '../../@types/astro';
|
||||||
import * as colors from 'kleur/colors';
|
|
||||||
import type { BuildInternals } from '../../core/build/internal.js';
|
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 type { RenderOptions } from '../../core/render/core';
|
||||||
import { BEFORE_HYDRATION_SCRIPT_ID } from '../../vite-plugin-scripts/index.js';
|
import { BEFORE_HYDRATION_SCRIPT_ID } from '../../vite-plugin-scripts/index.js';
|
||||||
import { call as callEndpoint } from '../endpoint/index.js';
|
import { call as callEndpoint } from '../endpoint/index.js';
|
||||||
import { debug, info } from '../logger/core.js';
|
import { debug, info } from '../logger/core.js';
|
||||||
import { render } from '../render/core.js';
|
import { render } from '../render/core.js';
|
||||||
|
import { callGetStaticPaths } from '../render/route-cache.js';
|
||||||
import { createLinkStylesheetElementSet, createModuleScriptsSet } from '../render/ssr-element.js';
|
import { createLinkStylesheetElementSet, createModuleScriptsSet } from '../render/ssr-element.js';
|
||||||
import { createRequest } from '../request.js';
|
import { createRequest } from '../request.js';
|
||||||
|
import { matchRoute } from '../routing/match.js';
|
||||||
import { getOutputFilename } from '../util.js';
|
import { getOutputFilename } from '../util.js';
|
||||||
import { getOutFile, getOutFolder } from './common.js';
|
import { getOutFile, getOutFolder } from './common.js';
|
||||||
import { eachPageData, getPageDataByComponent } from './internal.js';
|
import { eachPageData, getPageDataByComponent } from './internal.js';
|
||||||
import type { PageBuildData, SingleFileBuiltModule, StaticBuildOptions } from './types';
|
import type { PageBuildData, SingleFileBuiltModule, StaticBuildOptions } from './types';
|
||||||
import { getTimeStat } from './util.js';
|
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.
|
// Render is usually compute, which Node.js can't parallelize well.
|
||||||
// In real world testing, dropping from 10->1 showed a notiable perf
|
// In real world testing, dropping from 10->1 showed a notiable perf
|
||||||
|
@ -91,10 +96,7 @@ export function chunkIsPage(
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function generatePages(
|
export async function generatePages(opts: StaticBuildOptions, internals: BuildInternals) {
|
||||||
opts: StaticBuildOptions,
|
|
||||||
internals: BuildInternals,
|
|
||||||
) {
|
|
||||||
const timer = performance.now();
|
const timer = performance.now();
|
||||||
info(opts.logging, null, `\n${bgGreen(black(' generating static routes '))}`);
|
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 outFolder = ssr ? opts.buildConfig.server : opts.astroConfig.outDir;
|
||||||
const ssrEntryURL = new URL('./' + serverEntry + `?time=${Date.now()}`, outFolder);
|
const ssrEntryURL = new URL('./' + serverEntry + `?time=${Date.now()}`, outFolder);
|
||||||
const ssrEntry = await import(ssrEntryURL.toString());
|
const ssrEntry = await import(ssrEntryURL.toString());
|
||||||
const builtPaths = new Set<string>;
|
const builtPaths = new Set<string>();
|
||||||
|
|
||||||
for (const pageData of eachPageData(internals)) {
|
for (const pageData of eachPageData(internals)) {
|
||||||
await generatePage(opts, internals, pageData, ssrEntry, builtPaths);
|
await generatePage(opts, internals, pageData, ssrEntry, builtPaths);
|
||||||
|
@ -116,7 +118,7 @@ async function generatePage(
|
||||||
internals: BuildInternals,
|
internals: BuildInternals,
|
||||||
pageData: PageBuildData,
|
pageData: PageBuildData,
|
||||||
ssrEntry: SingleFileBuiltModule,
|
ssrEntry: SingleFileBuiltModule,
|
||||||
builtPaths: Set<string>,
|
builtPaths: Set<string>
|
||||||
) {
|
) {
|
||||||
let timeStart = performance.now();
|
let timeStart = performance.now();
|
||||||
const renderers = ssrEntry.renderers;
|
const renderers = ssrEntry.renderers;
|
||||||
|
@ -169,10 +171,10 @@ async function getPathsForRoute(
|
||||||
pageData: PageBuildData,
|
pageData: PageBuildData,
|
||||||
mod: ComponentInstance,
|
mod: ComponentInstance,
|
||||||
opts: StaticBuildOptions,
|
opts: StaticBuildOptions,
|
||||||
builtPaths: Set<string>,
|
builtPaths: Set<string>
|
||||||
): Promise<Array<string>> {
|
): Promise<Array<string>> {
|
||||||
let paths: Array<string> = [];
|
let paths: Array<string> = [];
|
||||||
if(pageData.route.pathname) {
|
if (pageData.route.pathname) {
|
||||||
paths.push(pageData.route.pathname);
|
paths.push(pageData.route.pathname);
|
||||||
builtPaths.add(pageData.route.pathname);
|
builtPaths.add(pageData.route.pathname);
|
||||||
} else {
|
} else {
|
||||||
|
@ -182,22 +184,22 @@ async function getPathsForRoute(
|
||||||
route: pageData.route,
|
route: pageData.route,
|
||||||
isValidate: false,
|
isValidate: false,
|
||||||
logging: opts.logging,
|
logging: opts.logging,
|
||||||
ssr: opts.astroConfig.output === 'server'
|
ssr: opts.astroConfig.output === 'server',
|
||||||
})
|
})
|
||||||
.then((_result) => {
|
.then((_result) => {
|
||||||
const label = _result.staticPaths.length === 1 ? 'page' : 'pages';
|
const label = _result.staticPaths.length === 1 ? 'page' : 'pages';
|
||||||
debug(
|
debug(
|
||||||
'build',
|
'build',
|
||||||
`├── ${colors.bold(colors.green('✔'))} ${route.component} → ${colors.magenta(
|
`├── ${colors.bold(colors.green('✔'))} ${route.component} → ${colors.magenta(
|
||||||
`[${_result.staticPaths.length} ${label}]`
|
`[${_result.staticPaths.length} ${label}]`
|
||||||
)}`
|
)}`
|
||||||
);
|
);
|
||||||
return _result;
|
return _result;
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
debug('build', `├── ${colors.bold(colors.red('✗'))} ${route.component}`);
|
debug('build', `├── ${colors.bold(colors.red('✗'))} ${route.component}`);
|
||||||
throw err;
|
throw err;
|
||||||
});
|
});
|
||||||
|
|
||||||
// Save the route cache so it doesn't get called again
|
// Save the route cache so it doesn't get called again
|
||||||
opts.routeCache.set(route, result);
|
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.
|
// 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));
|
builtPaths.add(removeTrailingForwardSlash(staticPath));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,7 +27,7 @@ export interface CollectPagesDataResult {
|
||||||
export async function collectPagesData(
|
export async function collectPagesData(
|
||||||
opts: CollectPagesDataOptions
|
opts: CollectPagesDataOptions
|
||||||
): Promise<CollectPagesDataResult> {
|
): Promise<CollectPagesDataResult> {
|
||||||
const { astroConfig, manifest } = opts;
|
const { astroConfig, manifest } = opts;
|
||||||
|
|
||||||
const assets: Record<string, string> = {};
|
const assets: Record<string, string> = {};
|
||||||
const allPages: AllPagesData = {};
|
const allPages: AllPagesData = {};
|
||||||
|
|
Loading…
Reference in a new issue