Skip to content

Commit

Permalink
remove unused util polyfill dependency (withastro#4097)
Browse files Browse the repository at this point in the history
* remove util dependency

* update tests
  • Loading branch information
FredKSchott authored Aug 1, 2022
1 parent 76ec35f commit 643443b
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 22 deletions.
1 change: 0 additions & 1 deletion packages/astro/src/core/add/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,6 @@ async function tryToInstallIntegrations({
const installCommand = await getInstallIntegrationsCommand({ integrations, cwd });

if (installCommand === null) {
info(logging, null);
return UpdateResult.none;
} else {
const coloredOutput = `${bold(installCommand.pm)} ${
Expand Down
4 changes: 2 additions & 2 deletions packages/astro/src/core/app/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,8 @@ export class App {
});

return response;
} catch (err) {
error(this.#logging, 'ssr', err);
} catch (err: any) {
error(this.#logging, 'ssr', err.stack || err.message || String(err));
return new Response(null, {
status: 500,
statusText: 'Internal server error',
Expand Down
3 changes: 1 addition & 2 deletions packages/astro/src/core/logger/console.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { bold, cyan, dim, red, reset, yellow } from 'kleur/colors';
import { format as utilFormat } from 'util';
import type { LogMessage } from './core.js';
import { dateTimeFormat, levels } from './core.js';

Expand Down Expand Up @@ -33,7 +32,7 @@ export const consoleLogDestination = {
return reset(prefix);
}

let message = utilFormat(...event.args);
let message = event.message;
// For repeat messages, only update the message counter
if (message === lastMessage) {
lastMessageCount++;
Expand Down
22 changes: 10 additions & 12 deletions packages/astro/src/core/logger/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ export interface LogMessage {
type: string | null;
level: LoggerLevel;
message: string;
args: Array<any>;
}

export const levels: Record<LoggerLevel, number> = {
Expand All @@ -48,15 +47,14 @@ export function log(
opts: LogOptions,
level: LoggerLevel,
type: string | null,
...args: Array<any>
message: string,
) {
const logLevel = opts.level;
const dest = opts.dest;
const event: LogMessage = {
type,
level,
args,
message: '',
message
};

// test if this level is enabled or not
Expand All @@ -68,26 +66,26 @@ export function log(
}

/** Emit a user-facing message. Useful for UI and other console messages. */
export function info(opts: LogOptions, type: string | null, ...messages: Array<any>) {
return log(opts, 'info', type, ...messages);
export function info(opts: LogOptions, type: string | null, message: string) {
return log(opts, 'info', type, message);
}

/** Emit a warning message. Useful for high-priority messages that aren't necessarily errors. */
export function warn(opts: LogOptions, type: string | null, ...messages: Array<any>) {
return log(opts, 'warn', type, ...messages);
export function warn(opts: LogOptions, type: string | null, message: string) {
return log(opts, 'warn', type, message);
}

/** Emit a error message, Useful when Astro can't recover from some error. */
export function error(opts: LogOptions, type: string | null, ...messages: Array<any>) {
return log(opts, 'error', type, ...messages);
export function error(opts: LogOptions, type: string | null, message: string) {
return log(opts, 'error', type, message);
}

type LogFn = typeof info | typeof warn | typeof error;

export function table(opts: LogOptions, columns: number[]) {
return function logTable(logFn: LogFn, ...input: Array<any>) {
const messages = columns.map((len, i) => padStr(input[i].toString(), len));
logFn(opts, null, ...messages);
const message = columns.map((len, i) => padStr(input[i].toString(), len)).join(' ');
logFn(opts, null, message);
};
}

Expand Down
5 changes: 2 additions & 3 deletions packages/astro/src/core/logger/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { bold, cyan, dim, red, reset, yellow } from 'kleur/colors';
import * as readline from 'readline';
import { Writable } from 'stream';
import stringWidth from 'string-width';
import { format as utilFormat } from 'util';
import { dateTimeFormat, error, info, warn } from './core.js';

type ConsoleStream = Writable & {
Expand Down Expand Up @@ -39,7 +38,8 @@ export const nodeLogDestination = new Writable({
return reset(prefix);
}

let message = utilFormat(...event.args);
// console.log({msg: event.message, args: event.args});
let message = event.message;
// For repeat messages, only update the message counter
if (message === lastMessage) {
lastMessageCount++;
Expand Down Expand Up @@ -90,7 +90,6 @@ export interface LogMessage {
type: string | null;
level: LoggerLevel;
message: string;
args: Array<any>;
}

export const levels: Record<LoggerLevel, number> = {
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/src/core/preview/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ export default async function preview(
port++;
return listen(); // retry
} else {
error(logging, 'astro', err.stack);
error(logging, 'astro', err.stack || err.message);
httpServer?.removeListener('error', onError);
reject(err); // reject
}
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/test/static-build.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ describe('Static build', () => {
for (const log of logs) {
if (
log.type === 'ssg' &&
/[hH]eaders are not exposed in static \(SSG\) output mode/.test(log.args[0])
/[hH]eaders are not exposed in static \(SSG\) output mode/.test(log.message)
) {
found = true;
}
Expand Down

0 comments on commit 643443b

Please sign in to comment.