Skip to content

Commit ed71eaf

Browse files
fix(logger): make AstroLoggerDestination not generic (#17390)
1 parent 30698a2 commit ed71eaf

12 files changed

Lines changed: 36 additions & 44 deletions

File tree

.changeset/little-sites-tie.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'astro': patch
3+
---
4+
5+
Removes an unused and undocumented generic from the `AstroLoggerDestination` type

packages/astro/src/core/app/types.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,8 @@ import type {
1414
SSRResult,
1515
} from '../../types/public/internal.js';
1616
import type { SinglePageBuiltModule } from '../build/types.js';
17+
import type { AstroLoggerDestination, AstroLoggerLevel } from '../logger/core.js';
1718
import type { CspDirective, CspHashEntry, CspResourceEntry } from '../csp/config.js';
18-
import type {
19-
AstroLoggerDestination,
20-
AstroLoggerLevel,
21-
AstroLoggerMessage,
22-
} from '../logger/core.js';
2319
import type { RoutingStrategies } from './common.js';
2420
import type { CacheProviderFactory, SSRManifestCache } from '../cache/types.js';
2521
import type { BaseSessionConfig, SessionDriverFactory } from '../session/types.js';
@@ -109,9 +105,7 @@ export type SSRManifest = {
109105
key: Promise<CryptoKey>;
110106
i18n: SSRManifestI18n | undefined;
111107
middleware?: () => Promise<AstroMiddlewareInstance> | AstroMiddlewareInstance;
112-
logger?: () =>
113-
| Promise<{ default: AstroLoggerDestination<AstroLoggerMessage> }>
114-
| { default: AstroLoggerDestination<AstroLoggerMessage> };
108+
logger?: () => Promise<{ default: AstroLoggerDestination }> | { default: AstroLoggerDestination };
115109
actions?: () => Promise<SSRActions> | SSRActions;
116110
sessionDriver?: () => Promise<{ default: SessionDriverFactory | null }>;
117111
cacheProvider?: () => Promise<{ default: CacheProviderFactory | null }>;

packages/astro/src/core/logger/core.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import colors from 'piccolore';
22

3-
export interface AstroLoggerDestination<T = unknown> {
3+
export interface AstroLoggerDestination {
44
/**
55
* It receives a message and writes it into a destination
66
*/
7-
write: (chunk: T) => void;
7+
write: (chunk: AstroLoggerMessage) => void;
88
/**
99
* It dumps logs without closing the connection to the destination.
1010
* Method that can be used by specialized loggers.
@@ -66,7 +66,7 @@ const AstroLoggerLabels = [
6666
type AstroLoggerLabel = (typeof AstroLoggerLabels)[number];
6767

6868
export interface AstroLogOptions {
69-
destination: AstroLoggerDestination<AstroLoggerMessage>;
69+
destination: AstroLoggerDestination;
7070
level: AstroLoggerLevel;
7171

7272
/**
@@ -234,7 +234,7 @@ export class AstroLogger {
234234
return new AstroIntegrationLogger(this.options, label);
235235
}
236236

237-
setDestination(destination: AstroLoggerDestination<AstroLoggerMessage>) {
237+
setDestination(destination: AstroLoggerDestination) {
238238
this.options.destination = destination;
239239
}
240240

packages/astro/src/core/logger/impls/console.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import {
22
getEventPrefix,
3-
type AstroLoggerMessage,
43
type AstroLoggerDestination,
54
levels,
65
type AstroLoggerLevel,
@@ -13,12 +12,10 @@ export type ConsoleHandlerConfig = {
1312
level?: AstroLoggerLevel;
1413
};
1514

16-
function consoleLogDestination(
17-
config: ConsoleHandlerConfig = {},
18-
): AstroLoggerDestination<AstroLoggerMessage> {
15+
function consoleLogDestination(config: ConsoleHandlerConfig = {}): AstroLoggerDestination {
1916
const { level = 'info' } = config;
2017
return {
21-
write(event: AstroLoggerMessage) {
18+
write(event) {
2219
let dest = console.error;
2320
if (levels[event.level] < levels['error']) {
2421
dest = console.info;
@@ -44,6 +41,6 @@ export function createConsoleLogger({ level }: { level: AstroLoggerLevel }): Ast
4441
});
4542
}
4643

47-
export default function (options?: NodeHandlerConfig): AstroLoggerDestination<AstroLoggerMessage> {
44+
export default function (options?: NodeHandlerConfig): AstroLoggerDestination {
4845
return consoleLogDestination(options);
4946
}

packages/astro/src/core/logger/impls/json.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import {
22
AstroLogger,
33
type AstroLoggerDestination,
44
type AstroLoggerLevel,
5-
type AstroLoggerMessage,
65
levels,
76
} from '../core.js';
87
import type { Writable } from 'node:stream';
@@ -28,7 +27,7 @@ export const SGR_REGEX = new RegExp(`${String.fromCharCode(0x1b)}\\[[0-9;]*m`, '
2827

2928
export default function jsonLoggerDestination(
3029
config: JsonHandlerConfig = {},
31-
): AstroLoggerDestination<AstroLoggerMessage> {
30+
): AstroLoggerDestination {
3231
const { pretty = false, level = 'info' } = config;
3332
return {
3433
write(event) {

packages/astro/src/core/logger/impls/node.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import {
22
AstroLogger,
33
type AstroLoggerDestination,
44
type AstroLoggerLevel,
5-
type AstroLoggerMessage,
65
getEventPrefix,
76
levels,
87
} from '../core.js';
@@ -18,12 +17,10 @@ export type NodeHandlerConfig = {
1817
level?: AstroLoggerLevel;
1918
};
2019

21-
function nodeLogDestination(
22-
config: NodeHandlerConfig = {},
23-
): AstroLoggerDestination<AstroLoggerMessage> {
20+
function nodeLogDestination(config: NodeHandlerConfig = {}): AstroLoggerDestination {
2421
const { level = 'info' } = config;
2522
return {
26-
write(event: AstroLoggerMessage) {
23+
write(event) {
2724
let dest: ConsoleStream = process.stderr;
2825
if (levels[event.level] < levels['error']) {
2926
dest = process.stdout;
@@ -43,7 +40,7 @@ function nodeLogDestination(
4340
};
4441
}
4542

46-
export default function (options?: NodeHandlerConfig): AstroLoggerDestination<AstroLoggerMessage> {
43+
export default function (options?: NodeHandlerConfig): AstroLoggerDestination {
4744
return nodeLogDestination(options);
4845
}
4946

packages/astro/test/prerender-conflict.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ describe('Prerender conflicts', () => {
2525
const logger = new AstroLogger({
2626
level: 'warn',
2727
destination: {
28-
write(chunk: AstroLoggerMessage) {
28+
write(chunk) {
2929
logs.push(chunk);
3030
return true;
3131
},
@@ -79,7 +79,7 @@ describe('Prerender conflicts', () => {
7979
const logger = new AstroLogger({
8080
level: 'warn',
8181
destination: {
82-
write(chunk: AstroLoggerMessage) {
82+
write(chunk) {
8383
logs.push(chunk);
8484
return true;
8585
},

packages/astro/test/units/logger/destination.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import jsonFactory, { SGR_REGEX } from '../../../dist/core/logger/impls/json.js'
66

77
let logs: AstroLoggerMessage[] = [];
88

9-
const testDestination: AstroLoggerDestination<AstroLoggerMessage> = {
10-
write(event: AstroLoggerMessage) {
9+
const testDestination: AstroLoggerDestination = {
10+
write(event) {
1111
logs.push(event);
1212
},
1313
};

packages/astro/test/units/logger/logger.test.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import assert from 'node:assert/strict';
22
import { describe, it } from 'node:test';
3-
import type { AstroLoggerMessage, AstroLoggerDestination } from '../../../dist/core/logger/core.js';
3+
import type { AstroLoggerDestination } from '../../../dist/core/logger/core.js';
44
import { AstroIntegrationLogger, AstroLogger } from '../../../dist/core/logger/core.js';
55

66
describe('AstroLogger', () => {
77
function createSpyDestination() {
88
const calls: { method: string }[] = [];
9-
const destination: AstroLoggerDestination<AstroLoggerMessage> = {
9+
const destination: AstroLoggerDestination = {
1010
write: () => {},
1111
flush: () => {
1212
calls.push({ method: 'flush' });
@@ -30,7 +30,7 @@ describe('AstroLogger', () => {
3030
});
3131

3232
it('does not throw when destination has no flush', () => {
33-
const destination: AstroLoggerDestination<AstroLoggerMessage> = {
33+
const destination: AstroLoggerDestination = {
3434
write: () => {},
3535
};
3636
const logger = new AstroLogger({ destination, level: 'info' });
@@ -51,7 +51,7 @@ describe('AstroLogger', () => {
5151
});
5252

5353
it('does not throw when destination has no close', () => {
54-
const destination: AstroLoggerDestination<AstroLoggerMessage> = {
54+
const destination: AstroLoggerDestination = {
5555
write: () => {},
5656
};
5757
const logger = new AstroLogger({ destination, level: 'info' });
@@ -63,12 +63,12 @@ describe('AstroLogger', () => {
6363
describe('setDestination', () => {
6464
it('replaces the destination', () => {
6565
const writes: string[] = [];
66-
const originalDestination: AstroLoggerDestination<AstroLoggerMessage> = {
66+
const originalDestination: AstroLoggerDestination = {
6767
write: (msg) => {
6868
writes.push('original:' + msg.message);
6969
},
7070
};
71-
const newDestination: AstroLoggerDestination<AstroLoggerMessage> = {
71+
const newDestination: AstroLoggerDestination = {
7272
write: (msg) => {
7373
writes.push('new:' + msg.message);
7474
},
@@ -89,7 +89,7 @@ describe('AstroLogger', () => {
8989
describe('AstroIntegrationLogger', () => {
9090
function createSpyDestination() {
9191
const calls: { method: string }[] = [];
92-
const destination: AstroLoggerDestination<AstroLoggerMessage> = {
92+
const destination: AstroLoggerDestination = {
9393
write: () => {},
9494
flush: () => {
9595
calls.push({ method: 'flush' });
@@ -113,7 +113,7 @@ describe('AstroIntegrationLogger', () => {
113113
});
114114

115115
it('does not throw when destination has no flush', () => {
116-
const destination: AstroLoggerDestination<AstroLoggerMessage> = {
116+
const destination: AstroLoggerDestination = {
117117
write: () => {},
118118
};
119119
const logger = new AstroIntegrationLogger({ destination, level: 'info' }, 'test');
@@ -134,7 +134,7 @@ describe('AstroIntegrationLogger', () => {
134134
});
135135

136136
it('does not throw when destination has no close', () => {
137-
const destination: AstroLoggerDestination<AstroLoggerMessage> = {
137+
const destination: AstroLoggerDestination = {
138138
write: () => {},
139139
};
140140
const logger = new AstroIntegrationLogger({ destination, level: 'info' }, 'test');

packages/astro/test/units/routing/manifest.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ function getLogger() {
1919
return {
2020
logger: new AstroLogger({
2121
destination: {
22-
write(msg: AstroLoggerMessage) {
22+
write(msg) {
2323
logs.push(msg);
2424
return true;
2525
},

0 commit comments

Comments
 (0)