Skip to content

Commit

Permalink
misc(logger): add types, remove cjs (#15279)
Browse files Browse the repository at this point in the history
  • Loading branch information
adamraine authored Jul 17, 2023
1 parent f285585 commit 809eaea
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 8 deletions.
35 changes: 35 additions & 0 deletions lighthouse-logger/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ class Log {
log(...argsArray);
}

/**
* @param {string} title
*/
static loggerfn(title) {
title = `LH:${title}`;
let log = loggersByTitle[title];
Expand Down Expand Up @@ -123,30 +126,54 @@ class Log {
return level_ === 'verbose';
}

/**
* @param {{msg: string, id: string, args?: any[]}} status
* @param {string} level
*/
static time({msg, id, args = []}, level = 'log') {
marky.mark(id);
Log[level]('status', msg, ...args);
}

/**
* @param {{msg: string, id: string, args?: any[]}} status
* @param {string} level
*/
static timeEnd({msg, id, args = []}, level = 'verbose') {
Log[level]('statusEnd', msg, ...args);
marky.stop(id);
}

/**
* @param {string} title
* @param {...any} args
*/
static log(title, ...args) {
Log.events.issueStatus(title, args);
return Log._logToStdErr(title, args);
}

/**
* @param {string} title
* @param {...any} args
*/
static warn(title, ...args) {
Log.events.issueWarning(title, args);
return Log._logToStdErr(`${title}:warn`, args);
}

/**
* @param {string} title
* @param {...any} args
*/
static error(title, ...args) {
return Log._logToStdErr(`${title}:error`, args);
}

/**
* @param {string} title
* @param {...any} args
*/
static verbose(title, ...args) {
Log.events.issueStatus(title, args);
return Log._logToStdErr(`${title}:verbose`, args);
Expand Down Expand Up @@ -236,11 +263,19 @@ class Log {
}

Log.events = new Emitter();

/**
* @return {PerformanceEntry[]}
*/
Log.takeTimeEntries = () => {
const entries = marky.getEntries();
marky.clear();
return entries;
};

/**
* @return {PerformanceEntry[]}
*/
Log.getTimeEntries = () => marky.getEntries();

export default Log;
11 changes: 3 additions & 8 deletions lighthouse-logger/package.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
{
"type": "module",
"name": "lighthouse-logger",
"version": "1.4.2",
"version": "2.0.0",
"license": "Apache-2.0",
"main": "./dist/index.cjs",
"exports": {
"require": "./dist/index.cjs",
"import": "./index.js"
},
"scripts": {
"prepack": "yarn build-cjs",
"build-cjs": "npx rollup --format=cjs --file=dist/index.cjs -- index.js"
"prepack": "yarn build-types",
"build-types": "npx tsc index.js --allowJs --emitDeclarationOnly --declaration"
},
"dependencies": {
"debug": "^2.6.9",
Expand Down

0 comments on commit 809eaea

Please sign in to comment.