remove unused util polyfill dependency (#4097)

* remove util dependency

* update tests
This commit is contained in:
Fred K. Schott 2022-08-01 12:15:23 -04:00 committed by GitHub
parent 76ec35ff30
commit 643443bcd9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 17 additions and 22 deletions

View file

@ -539,7 +539,6 @@ async function tryToInstallIntegrations({
const installCommand = await getInstallIntegrationsCommand({ integrations, cwd }); const installCommand = await getInstallIntegrationsCommand({ integrations, cwd });
if (installCommand === null) { if (installCommand === null) {
info(logging, null);
return UpdateResult.none; return UpdateResult.none;
} else { } else {
const coloredOutput = `${bold(installCommand.pm)} ${ const coloredOutput = `${bold(installCommand.pm)} ${

View file

@ -168,8 +168,8 @@ export class App {
}); });
return response; return response;
} catch (err) { } catch (err: any) {
error(this.#logging, 'ssr', err); error(this.#logging, 'ssr', err.stack || err.message || String(err));
return new Response(null, { return new Response(null, {
status: 500, status: 500,
statusText: 'Internal server error', statusText: 'Internal server error',

View file

@ -1,5 +1,4 @@
import { bold, cyan, dim, red, reset, yellow } from 'kleur/colors'; import { bold, cyan, dim, red, reset, yellow } from 'kleur/colors';
import { format as utilFormat } from 'util';
import type { LogMessage } from './core.js'; import type { LogMessage } from './core.js';
import { dateTimeFormat, levels } from './core.js'; import { dateTimeFormat, levels } from './core.js';
@ -33,7 +32,7 @@ export const consoleLogDestination = {
return reset(prefix); return reset(prefix);
} }
let message = utilFormat(...event.args); let message = event.message;
// For repeat messages, only update the message counter // For repeat messages, only update the message counter
if (message === lastMessage) { if (message === lastMessage) {
lastMessageCount++; lastMessageCount++;

View file

@ -32,7 +32,6 @@ export interface LogMessage {
type: string | null; type: string | null;
level: LoggerLevel; level: LoggerLevel;
message: string; message: string;
args: Array<any>;
} }
export const levels: Record<LoggerLevel, number> = { export const levels: Record<LoggerLevel, number> = {
@ -48,15 +47,14 @@ export function log(
opts: LogOptions, opts: LogOptions,
level: LoggerLevel, level: LoggerLevel,
type: string | null, type: string | null,
...args: Array<any> message: string,
) { ) {
const logLevel = opts.level; const logLevel = opts.level;
const dest = opts.dest; const dest = opts.dest;
const event: LogMessage = { const event: LogMessage = {
type, type,
level, level,
args, message
message: '',
}; };
// test if this level is enabled or not // test if this level is enabled or not
@ -68,26 +66,26 @@ export function log(
} }
/** Emit a user-facing message. Useful for UI and other console messages. */ /** Emit a user-facing message. Useful for UI and other console messages. */
export function info(opts: LogOptions, type: string | null, ...messages: Array<any>) { export function info(opts: LogOptions, type: string | null, message: string) {
return log(opts, 'info', type, ...messages); return log(opts, 'info', type, message);
} }
/** Emit a warning message. Useful for high-priority messages that aren't necessarily errors. */ /** 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>) { export function warn(opts: LogOptions, type: string | null, message: string) {
return log(opts, 'warn', type, ...messages); return log(opts, 'warn', type, message);
} }
/** Emit a error message, Useful when Astro can't recover from some error. */ /** Emit a error message, Useful when Astro can't recover from some error. */
export function error(opts: LogOptions, type: string | null, ...messages: Array<any>) { export function error(opts: LogOptions, type: string | null, message: string) {
return log(opts, 'error', type, ...messages); return log(opts, 'error', type, message);
} }
type LogFn = typeof info | typeof warn | typeof error; type LogFn = typeof info | typeof warn | typeof error;
export function table(opts: LogOptions, columns: number[]) { export function table(opts: LogOptions, columns: number[]) {
return function logTable(logFn: LogFn, ...input: Array<any>) { return function logTable(logFn: LogFn, ...input: Array<any>) {
const messages = columns.map((len, i) => padStr(input[i].toString(), len)); const message = columns.map((len, i) => padStr(input[i].toString(), len)).join(' ');
logFn(opts, null, ...messages); logFn(opts, null, message);
}; };
} }

View file

@ -3,7 +3,6 @@ import { bold, cyan, dim, red, reset, yellow } from 'kleur/colors';
import * as readline from 'readline'; import * as readline from 'readline';
import { Writable } from 'stream'; import { Writable } from 'stream';
import stringWidth from 'string-width'; import stringWidth from 'string-width';
import { format as utilFormat } from 'util';
import { dateTimeFormat, error, info, warn } from './core.js'; import { dateTimeFormat, error, info, warn } from './core.js';
type ConsoleStream = Writable & { type ConsoleStream = Writable & {
@ -39,7 +38,8 @@ export const nodeLogDestination = new Writable({
return reset(prefix); 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 // For repeat messages, only update the message counter
if (message === lastMessage) { if (message === lastMessage) {
lastMessageCount++; lastMessageCount++;
@ -90,7 +90,6 @@ export interface LogMessage {
type: string | null; type: string | null;
level: LoggerLevel; level: LoggerLevel;
message: string; message: string;
args: Array<any>;
} }
export const levels: Record<LoggerLevel, number> = { export const levels: Record<LoggerLevel, number> = {

View file

@ -124,7 +124,7 @@ export default async function preview(
port++; port++;
return listen(); // retry return listen(); // retry
} else { } else {
error(logging, 'astro', err.stack); error(logging, 'astro', err.stack || err.message);
httpServer?.removeListener('error', onError); httpServer?.removeListener('error', onError);
reject(err); // reject reject(err); // reject
} }

View file

@ -176,7 +176,7 @@ describe('Static build', () => {
for (const log of logs) { for (const log of logs) {
if ( if (
log.type === 'ssg' && 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; found = true;
} }