From 57c7fea7aa6fec10fe0bba4ad0866edb72b4c3b6 Mon Sep 17 00:00:00 2001 From: Connor Clark Date: Mon, 7 Mar 2022 15:55:00 -0800 Subject: [PATCH] core(lighthouse-logger): convert to ES modules (#13720) --- build/build-bundle.js | 3 +++ lighthouse-logger/index.js | 12 +++++------- lighthouse-logger/package.json | 1 + 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/build/build-bundle.js b/build/build-bundle.js index 5851b673a3e8..71aef80bfc10 100644 --- a/build/build-bundle.js +++ b/build/build-bundle.js @@ -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. diff --git a/lighthouse-logger/index.js b/lighthouse-logger/index.js index f98575a21cae..5853a7830f1d 100644 --- a/lighthouse-logger/index.js +++ b/lighthouse-logger/index.js @@ -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'; +import {EventEmitter} from 'events'; -const EventEmitter = require('events').EventEmitter; const isWindows = process.platform === 'win32'; // @ts-expect-error: process.browser is set via Rollup. @@ -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); @@ -239,5 +239,3 @@ Log.takeTimeEntries = () => { return entries; }; Log.getTimeEntries = () => marky.getEntries(); - -module.exports = Log; diff --git a/lighthouse-logger/package.json b/lighthouse-logger/package.json index 2456b62b7b2e..9a8ac553a3e1 100644 --- a/lighthouse-logger/package.json +++ b/lighthouse-logger/package.json @@ -1,4 +1,5 @@ { + "type": "module", "name": "lighthouse-logger", "version": "1.3.0", "license": "Apache-2.0",