Add dev server profile logs (#218)
This commit is contained in:
parent
cce8ac72e0
commit
3da2b58b9d
2 changed files with 14 additions and 2 deletions
|
@ -7,8 +7,9 @@ import { green } from 'kleur/colors';
|
|||
import http from 'http';
|
||||
import path from 'path';
|
||||
import { performance } from 'perf_hooks';
|
||||
import { defaultLogDestination, error, info, parseError } from './logger.js';
|
||||
import { defaultLogDestination, debug, error, info, parseError } from './logger.js';
|
||||
import { createRuntime } from './runtime.js';
|
||||
import { stopTimer } from './build/util';
|
||||
|
||||
const hostname = '127.0.0.1';
|
||||
|
||||
|
@ -24,11 +25,16 @@ const logging: LogOptions = {
|
|||
export default async function dev(astroConfig: AstroConfig) {
|
||||
const startServerTime = performance.now();
|
||||
const { projectRoot } = astroConfig;
|
||||
const timer: Record<string, number> = {};
|
||||
|
||||
timer.runtime = performance.now();
|
||||
const runtime = await createRuntime(astroConfig, { mode: 'development', logging });
|
||||
debug(logging, 'dev', `runtime created [${stopTimer(timer.runtime)}]`);
|
||||
|
||||
const server = http.createServer(async (req, res) => {
|
||||
timer.load = performance.now();
|
||||
const result = await runtime.load(req.url);
|
||||
debug(logging, 'dev', `loaded ${req.url} [${stopTimer(timer.load)}]`);
|
||||
|
||||
switch (result.statusCode) {
|
||||
case 200: {
|
||||
|
|
|
@ -6,8 +6,9 @@ import type { AstroConfig, CollectionResult, CollectionRSS, CreateCollection, Pa
|
|||
|
||||
import { existsSync } from 'fs';
|
||||
import { fileURLToPath } from 'url';
|
||||
import { performance } from 'perf_hooks';
|
||||
import { loadConfiguration, logger as snowpackLogger, startServer as startSnowpackServer } from 'snowpack';
|
||||
import { canonicalURL } from './build/util.js';
|
||||
import { canonicalURL, stopTimer } from './build/util.js';
|
||||
import { debug, info } from './logger.js';
|
||||
import { searchForPage } from './search.js';
|
||||
|
||||
|
@ -332,8 +333,10 @@ async function createSnowpack(astroConfig: AstroConfig, options: CreateSnowpackO
|
|||
|
||||
/** Core Astro runtime */
|
||||
export async function createRuntime(astroConfig: AstroConfig, { mode, logging }: RuntimeOptions): Promise<AstroRuntime> {
|
||||
const timer: Record<string, number> = {};
|
||||
const resolvePackageUrl = async (pkgName: string) => frontendSnowpack.getUrlForPackage(pkgName);
|
||||
|
||||
timer.backend = performance.now();
|
||||
const { snowpack: backendSnowpack, snowpackRuntime: backendSnowpackRuntime, snowpackConfig: backendSnowpackConfig } = await createSnowpack(astroConfig, {
|
||||
env: {
|
||||
astro: true,
|
||||
|
@ -341,13 +344,16 @@ export async function createRuntime(astroConfig: AstroConfig, { mode, logging }:
|
|||
mode,
|
||||
resolvePackageUrl,
|
||||
});
|
||||
debug(logging, 'core', `backend snowpack created [${stopTimer(timer.backend)}]`);
|
||||
|
||||
timer.frontend = performance.now();
|
||||
const { snowpack: frontendSnowpack, snowpackRuntime: frontendSnowpackRuntime, snowpackConfig: frontendSnowpackConfig } = await createSnowpack(astroConfig, {
|
||||
env: {
|
||||
astro: false,
|
||||
},
|
||||
mode,
|
||||
});
|
||||
debug(logging, 'core', `frontend snowpack created [${stopTimer(timer.frontend)}]`);
|
||||
|
||||
const runtimeConfig: RuntimeConfig = {
|
||||
astroConfig,
|
||||
|
|
Loading…
Reference in a new issue