Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion benchmark/packages/adapter/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ class MyApp extends BaseApp {

createPipeline(streaming: boolean) {
return AppPipeline.create({
logger: this.logger,
manifest: this.manifest,
streaming,
});
Expand Down
6 changes: 5 additions & 1 deletion packages/astro/src/cli/preferences/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,11 @@ export async function preferences(
const inlineConfig = flagsToAstroInlineConfig(flags);
const logger = createLoggerFromFlags(flags);
const { astroConfig } = await resolveConfig(inlineConfig ?? {}, 'dev');
const settings = await createSettings(astroConfig, fileURLToPath(astroConfig.root));
const settings = await createSettings(
astroConfig,
inlineConfig.logLevel,
fileURLToPath(astroConfig.root),
);
const opts: SubcommandOptions = {
location: flags.global ? 'global' : undefined,
json: !!flags.json,
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/src/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export function getViteConfig(
]);
const logger = createNodeLogger(inlineAstroConfig);
const { astroConfig: config } = await resolveConfig(inlineAstroConfig, cmd);
let settings = await createSettings(config, userViteConfig.root);
let settings = await createSettings(config, inlineAstroConfig.logLevel, userViteConfig.root);
settings = await runHookConfigSetup({ settings, command: cmd, logger });
const routesList = await createRoutesList(
{
Expand Down
1 change: 1 addition & 0 deletions packages/astro/src/container/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ function createManifest(
latestAstroVersion: undefined,
debugInfoOutput: '',
},
logLevel: 'silent',
};
}

Expand Down
1 change: 0 additions & 1 deletion packages/astro/src/core/app/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { AppPipeline } from './pipeline.js';
export class App extends BaseApp {
createPipeline(streaming: boolean): AppPipeline {
return AppPipeline.create({
logger: this.logger,
manifest: this.manifest,
streaming,
});
Expand Down
9 changes: 5 additions & 4 deletions packages/astro/src/core/app/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,15 +108,16 @@ export abstract class BaseApp<P extends Pipeline = AppPipeline> {
pipeline: P;
adapterLogger: AstroIntegrationLogger;
baseWithoutTrailingSlash: string;
logger = new Logger({
dest: consoleLogDestination,
level: 'info',
});
logger: Logger;
constructor(manifest: SSRManifest, streaming = true, ...args: any[]) {
this.manifest = manifest;
this.manifestData = { routes: manifest.routes.map((route) => route.routeData) };
this.baseWithoutTrailingSlash = removeTrailingForwardSlash(manifest.base);
this.pipeline = this.createPipeline(streaming, manifest, ...args);
this.logger = new Logger({
dest: consoleLogDestination,
level: manifest.logLevel,
});
this.adapterLogger = new AstroIntegrationLogger(this.logger.options, manifest.adapterName);
// This is necessary to allow running middlewares for 404 in SSR. There's special handling
// to return the host 404 if the user doesn't provide a custom 404
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/src/core/app/entrypoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { createConsoleLogger } from './logging.js';

export function createApp(dev = import.meta.env.DEV): BaseApp {
if (dev) {
const logger = createConsoleLogger('debug');
const logger = createConsoleLogger(manifest.logLevel);
return new DevApp(manifest, true, logger);
} else {
return new App(manifest);
Expand Down
8 changes: 3 additions & 5 deletions packages/astro/src/core/app/pipeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,14 @@ import {
} from '../render/ssr-element.js';
import { getFallbackRoute, routeIsFallback, routeIsRedirect } from '../routing/index.js';
import { findRouteToRewrite } from '../routing/rewrite.js';
import { createConsoleLogger } from './logging.js';

export class AppPipeline extends Pipeline {
getName(): string {
return 'AppPipeline';
}

static create({
logger,
manifest,
streaming,
}: Pick<AppPipeline, 'logger' | 'manifest' | 'streaming'>) {
static create({ manifest, streaming }: Pick<AppPipeline, 'manifest' | 'streaming'>) {
const resolve = async function resolve(specifier: string) {
if (!(specifier in manifest.entryModules)) {
throw new Error(`Unable to resolve [${specifier}]`);
Expand All @@ -33,6 +30,7 @@ export class AppPipeline extends Pipeline {
return createAssetLink(bundlePath, manifest.base, manifest.assetsPrefix);
}
};
const logger = createConsoleLogger(manifest.logLevel);
const pipeline = new AppPipeline(
logger,
manifest,
Expand Down
2 changes: 2 additions & 0 deletions packages/astro/src/core/app/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import type {
} from '../../types/public/internal.js';
import type { SinglePageBuiltModule } from '../build/types.js';
import type { CspDirective } from '../csp/config.js';
import type { LoggerLevel } from '../logger/core.js';
import type { SessionDriver } from '../session.js';
import type { RoutingStrategies } from './common.js';

Expand Down Expand Up @@ -123,6 +124,7 @@ export type SSRManifest = {
debugInfoOutput: string | undefined;
};
internalFetchHeaders?: Record<string, string>;
logLevel: LoggerLevel;
};

export type SSRActions = {
Expand Down
23 changes: 14 additions & 9 deletions packages/astro/src/core/build/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,10 @@ export async function generatePages(
// Grab the manifest and create the pipeline
const manifest: SSRManifest = prerenderEntry.manifest;
const pipeline = BuildPipeline.create({ internals, manifest, options });
const { config, logger } = pipeline;
const app = prerenderEntry.app as BaseApp;

const { config } = pipeline;
const logger = app.logger;

// HACK! `astro:assets` relies on a global to know if its running in dev, prod, ssr, ssg, full moon
// If we don't delete it here, it's technically not impossible (albeit improbable) for it to leak
Expand All @@ -72,7 +75,6 @@ export async function generatePages(
const pagesToGenerate = pipeline.retrieveRoutesToGenerate();
const routeToHeaders: RouteToHeaders = new Map();

const app = prerenderEntry.app as BaseApp;
if (ssr) {
for (const [routeData, _] of pagesToGenerate) {
if (routeData.prerender) {
Expand Down Expand Up @@ -203,7 +205,8 @@ async function generatePage(
routeToHeaders: RouteToHeaders,
) {
// prepare information we need
const { config, logger } = pipeline;
const logger = app.logger;
const { config } = pipeline;

async function generatePathWithLogs(
path: string,
Expand All @@ -214,7 +217,7 @@ async function generatePage(
isConcurrent: boolean,
) {
const timeStart = performance.now();
pipeline.logger.debug('build', `Generating: ${path}`);
logger.debug('build', `Generating: ${path}`);

const filePath = getOutputFilename(config, path, routeData);
const lineIcon =
Expand Down Expand Up @@ -298,7 +301,8 @@ async function getPathsForRoute(
pipeline: BuildPipeline,
builtPaths: Set<string>,
): Promise<Array<string>> {
const { logger, options, manifest } = pipeline;
const { options, manifest } = pipeline;
const logger = app.logger;
// TODO: investigate if BuildPipeline can be removed. We already have app.pipeline
// which contains routeCache and other pipeline data. Eventually all pipeline info
// should come from app.pipeline and BuildPipeline can be eliminated.
Expand Down Expand Up @@ -506,7 +510,8 @@ async function generatePath(
integrationRoute: IntegrationResolvedRoute,
routeToHeaders: RouteToHeaders,
): Promise<boolean | undefined> {
const { config, logger, options } = pipeline;
const { config, options } = pipeline;
const logger = app.logger;
logger.debug('build', `Generating: ${pathname}`);

// This adds the page name to the array so it can be shown as part of stats.
Expand Down Expand Up @@ -548,10 +553,10 @@ async function generatePath(

const url = getUrlForPath(
pathname,
config.base,
app.manifest.base,
options.origin,
config.build.format,
config.trailingSlash,
app.manifest.buildFormat,
app.manifest.trailingSlash,
route.type,
);

Expand Down
6 changes: 5 additions & 1 deletion packages/astro/src/core/build/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,11 @@ export default async function build(
const { userConfig, astroConfig } = await resolveConfig(inlineConfig, 'build');
telemetry.record(eventCliSession('build', userConfig));

const settings = await createSettings(astroConfig, fileURLToPath(astroConfig.root));
const settings = await createSettings(
astroConfig,
inlineConfig.logLevel,
fileURLToPath(astroConfig.root),
);

if (inlineConfig.force) {
// isDev is always false, because it's interested in the build command, not the output type
Expand Down
1 change: 1 addition & 0 deletions packages/astro/src/core/build/plugins/plugin-manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -368,5 +368,6 @@ async function buildManifest(
debugInfoOutput: '',
},
internalFetchHeaders,
logLevel: settings.logLevel,
};
}
16 changes: 12 additions & 4 deletions packages/astro/src/core/config/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import toml from 'smol-toml';
import { getContentPaths } from '../../content/index.js';
import createPreferences from '../../preferences/index.js';
import type { AstroSettings } from '../../types/astro.js';
import type { AstroConfig } from '../../types/public/config.js';
import type { AstroConfig, AstroInlineConfig } from '../../types/public/config.js';
import { markdownContentEntryType } from '../../vite-plugin-markdown/content-entry-type.js';
import { getDefaultClientDirectives } from '../client-directive/index.js';
import { SUPPORTED_MARKDOWN_FILE_EXTENSIONS } from './../constants.js';
Expand All @@ -19,7 +19,10 @@ import {
import { AstroTimer } from './timer.js';
import { loadTSConfig } from './tsconfig.js';

export function createBaseSettings(config: AstroConfig): AstroSettings {
export function createBaseSettings(
config: AstroConfig,
logLevel: AstroInlineConfig['logLevel'],
): AstroSettings {
const { contentDir } = getContentPaths(config);
const dotAstroDir = new URL('.astro/', config.root);
const preferences = createPreferences(config, dotAstroDir);
Expand Down Expand Up @@ -152,12 +155,17 @@ export function createBaseSettings(config: AstroConfig): AstroSettings {
fontResources: new Set(),
styleHashes: [],
},
logLevel: logLevel ?? 'info',
};
}

export async function createSettings(config: AstroConfig, cwd?: string): Promise<AstroSettings> {
export async function createSettings(
config: AstroConfig,
logLevel: AstroInlineConfig['logLevel'],
cwd?: string,
): Promise<AstroSettings> {
const tsconfig = await loadTSConfig(cwd);
const settings = createBaseSettings(config);
const settings = createBaseSettings(config, logLevel);

let watchFiles = [];
if (cwd) {
Expand Down
12 changes: 10 additions & 2 deletions packages/astro/src/core/dev/restart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,11 @@ async function restartContainer(container: Container): Promise<Container | Error
"Astro's Content Security Policy (CSP) does not work in development mode. To verify your CSP implementation, build the project and run the preview server.",
);
}
const settings = await createSettings(astroConfig, fileURLToPath(existingSettings.config.root));
const settings = await createSettings(
astroConfig,
container.inlineConfig.logLevel,
fileURLToPath(existingSettings.config.root),
);
await close();
return await createRestartedContainer(container, settings);
} catch (_err) {
Expand Down Expand Up @@ -134,7 +138,11 @@ export async function createContainerWithAutomaticRestart({
}
telemetry.record(eventCliSession('dev', userConfig));

const settings = await createSettings(astroConfig, fileURLToPath(astroConfig.root));
const settings = await createSettings(
astroConfig,
inlineConfig?.logLevel,
fileURLToPath(astroConfig.root),
);

const initialContainer = await createContainer({
settings,
Expand Down
6 changes: 5 additions & 1 deletion packages/astro/src/core/preview/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ export default async function preview(inlineConfig: AstroInlineConfig): Promise<
const { userConfig, astroConfig } = await resolveConfig(inlineConfig ?? {}, 'preview');
telemetry.record(eventCliSession('preview', userConfig));

const _settings = await createSettings(astroConfig, fileURLToPath(astroConfig.root));
const _settings = await createSettings(
astroConfig,
inlineConfig.logLevel,
fileURLToPath(astroConfig.root),
);

const settings = await runHookConfigSetup({
settings: _settings,
Expand Down
13 changes: 9 additions & 4 deletions packages/astro/src/core/render/params-and-props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,16 @@ export function getParams(route: RouteData, pathname: string): Params {
if (!route.params.length) return {};
// The RegExp pattern expects a decoded string, but the pathname is encoded
// when the URL contains non-English characters.
let path = pathname;
// The path could contain `.html` at the end. We remove it so we can correctly the parameters
// with the generated keyed parameters.
if (pathname.endsWith('.html')) {
path = path.slice(0, -5);
}

const paramsMatch =
route.pattern.exec(pathname) ||
route.fallbackRoutes
.map((fallbackRoute) => fallbackRoute.pattern.exec(pathname))
.find((x) => x);
route.pattern.exec(path) ||
route.fallbackRoutes.map((fallbackRoute) => fallbackRoute.pattern.exec(path)).find((x) => x);
if (!paramsMatch) return {};
const params: Params = {};
route.params.forEach((key, i) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/src/core/sync/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export default async function sync(
if (_telemetry) {
telemetry.record(eventCliSession('sync', userConfig));
}
let settings = await createSettings(astroConfig, inlineConfig.root);
let settings = await createSettings(astroConfig, inlineConfig.logLevel, inlineConfig.root);
settings = await runHookConfigSetup({
command: 'sync',
settings,
Expand Down
6 changes: 1 addition & 5 deletions packages/astro/src/entrypoints/prerender.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,9 @@ import { manifest as _manifest } from 'virtual:astro:manifest';
import { createApp } from 'astro/app/entrypoint';

const app = createApp();
const { pageMap, renderers } = _manifest;
const { renderers } = _manifest;

// Export middleware lazy-loaded
const middleware = () => import('virtual:astro:middleware');

Object.assign(_manifest, {
pageMap,
});

export { app, _manifest as manifest, renderers, middleware, actions };
1 change: 1 addition & 0 deletions packages/astro/src/manifest/serialized.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,5 +151,6 @@ async function createSerializedManifest(settings: AstroSettings): Promise<Serial
print: false,
}),
},
logLevel: settings.logLevel,
};
}
3 changes: 2 additions & 1 deletion packages/astro/src/types/astro.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { AstroTimer } from '../core/config/timer.js';
import type { TSConfig } from '../core/config/tsconfig.js';
import type { Logger } from '../core/logger/core.js';
import type { Logger, LoggerLevel } from '../core/logger/core.js';
import type { AstroPreferences } from '../preferences/index.js';
import type { AstroComponentFactory } from '../runtime/server/index.js';
import type { GetStaticPaths } from './public/common.js';
Expand Down Expand Up @@ -73,6 +73,7 @@ export interface AstroSettings {
fontResources: Set<string>;
styleHashes: Required<CspObject['styleDirective']>['hashes'];
};
logLevel: LoggerLevel;
}

/** Generic interface for a component (Astro, Svelte, React, etc.) */
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/src/vite-plugin-app/createAstroServerApp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export default async function createAstroServerApp(
) {
const logger = new Logger({
dest: nodeLogDestination,
level: 'info',
level: settings.logLevel,
});
const routesList: RoutesList = { routes: routes.map((r: RouteInfo) => r.routeData) };

Expand Down
1 change: 1 addition & 0 deletions packages/astro/src/vite-plugin-astro-server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,5 +250,6 @@ export async function createDevelopmentManifest(settings: AstroSettings): Promis
latestAstroVersion: settings.latestAstroVersion,
debugInfoOutput: '',
},
logLevel: settings.logLevel,
};
}
Loading