Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core(lighthouse-logger): convert to ES modules #13720

Merged
merged 3 commits into from
Mar 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions build/build-bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,9 @@ async function build(entryPath, distPath, opts = {minify: true}) {
// This package exports to default in a way that causes Rollup to get confused,
// resulting in MessageFormat being undefined.
'require(\'intl-messageformat\').default': 'require(\'intl-messageformat\')',
// Below we replace lighthouse-logger with a local copy, which is ES modules. Need
// to change every require of the package to reflect this.
'require(\'lighthouse-logger\');': 'require(\'lighthouse-logger\').default;',
// Rollup doesn't replace this, so let's manually change it to false.
'require.main === module': 'false',
// TODO: Use globalThis directly.
Expand Down
12 changes: 5 additions & 7 deletions lighthouse-logger/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
*/
'use strict';

const process = require('process');
const debug = require('debug');
const marky = require('marky');
import process from 'process';
import debug from 'debug';
import * as marky from 'marky';

This comment was marked as spam.

import {EventEmitter} from 'events';

const EventEmitter = require('events').EventEmitter;
const isWindows = process.platform === 'win32';

// @ts-expect-error: process.browser is set via Rollup.
Expand Down Expand Up @@ -55,7 +55,7 @@ const loggersByTitle = {};
const loggingBufferColumns = 25;
let level_;

class Log {
export default class Log {
static _logToStdErr(title, argsArray) {
const log = Log.loggerfn(title);
log(...argsArray);
Expand Down Expand Up @@ -239,5 +239,3 @@ Log.takeTimeEntries = () => {
return entries;
};
Log.getTimeEntries = () => marky.getEntries();

module.exports = Log;
1 change: 1 addition & 0 deletions lighthouse-logger/package.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"type": "module",
"name": "lighthouse-logger",
"version": "1.3.0",
"license": "Apache-2.0",
Expand Down