[Reporting] TS changes to reference an interface instead of class as the logger object (#78359)

* [Reporting] TS changes to reference an interface instead of class, making functions more shareable

* rename the interface

* less flexible interface
This commit is contained in:
Tim Sullivan 2020-09-24 08:54:34 -07:00 committed by GitHub
parent 8ba60a4004
commit 38f517ae9f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 17 additions and 10 deletions

View file

@ -7,13 +7,13 @@
import del from 'del';
import { readdirSync } from 'fs';
import { resolve as resolvePath } from 'path';
import { LevelLogger } from '../../lib';
import { GenericLevelLogger } from '../../lib/level_logger';
import { asyncMap } from './util';
/**
* Delete any file in the `dir` that is not in the expectedPaths
*/
export async function clean(dir: string, expectedPaths: string[], logger: LevelLogger) {
export async function clean(dir: string, expectedPaths: string[], logger: GenericLevelLogger) {
let filenames: string[];
try {
filenames = await readdirSync(dir);

View file

@ -8,7 +8,7 @@ import Axios from 'axios';
import { createHash } from 'crypto';
import { closeSync, mkdirSync, openSync, writeSync } from 'fs';
import { dirname } from 'path';
import { LevelLogger } from '../../lib';
import { GenericLevelLogger } from '../../lib/level_logger';
/**
* Download a url and calculate it's checksum
@ -16,7 +16,7 @@ import { LevelLogger } from '../../lib';
* @param {String} path
* @return {Promise<String>} checksum of the downloaded file
*/
export async function download(url: string, path: string, logger: LevelLogger) {
export async function download(url: string, path: string, logger: GenericLevelLogger) {
logger.info(`Downloading ${url} to ${path}`);
const hash = createHash('md5');

View file

@ -7,7 +7,7 @@
import { existsSync } from 'fs';
import { resolve as resolvePath } from 'path';
import { BrowserDownload, chromium } from '../';
import { LevelLogger } from '../../lib';
import { GenericLevelLogger } from '../../lib/level_logger';
import { md5 } from './checksum';
import { clean } from './clean';
import { download } from './download';
@ -18,7 +18,7 @@ import { asyncMap } from './util';
* download them if they are missing or their checksum is invalid
* @return {Promise<undefined>}
*/
export async function ensureBrowserDownloaded(logger: LevelLogger) {
export async function ensureBrowserDownloaded(logger: GenericLevelLogger) {
await ensureDownloaded([chromium], logger);
}
@ -29,7 +29,7 @@ export async function ensureBrowserDownloaded(logger: LevelLogger) {
* @param {BrowserSpec} browsers
* @return {Promise<undefined>}
*/
async function ensureDownloaded(browsers: BrowserDownload[], logger: LevelLogger) {
async function ensureDownloaded(browsers: BrowserDownload[], logger: GenericLevelLogger) {
await asyncMap(browsers, async (browser) => {
const { archivesPath } = browser.paths;

View file

@ -8,7 +8,7 @@ import del from 'del';
import os from 'os';
import path from 'path';
import * as Rx from 'rxjs';
import { LevelLogger } from '../lib';
import { GenericLevelLogger } from '../lib/level_logger';
import { paths } from './chromium/paths';
import { ensureBrowserDownloaded } from './download';
// @ts-ignore
@ -46,7 +46,7 @@ export const getBinaryPath = (
* archive. If there is an error extracting the archive an `ExtractError` is thrown
*/
export function installBrowser(
logger: LevelLogger,
logger: GenericLevelLogger,
chromiumPath: string = path.resolve(__dirname, '../../chromium'),
platform: string = process.platform,
architecture: string = os.arch()

View file

@ -10,7 +10,14 @@ const trimStr = (toTrim: string) => {
return typeof toTrim === 'string' ? toTrim.trim() : toTrim;
};
export class LevelLogger {
export interface GenericLevelLogger {
debug: (msg: string) => void;
info: (msg: string) => void;
warning: (msg: string) => void;
error: (msg: Error) => void;
}
export class LevelLogger implements GenericLevelLogger {
private _logger: LoggerFactory;
private _tags: string[];
public warning: (msg: string, tags?: string[]) => void;