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

Publish as ESM #302

Merged
merged 6 commits into from
May 18, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/chrome-finder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
*/
'use strict';

import fs = require('fs');
import path = require('path');
import fs from 'fs';
import path from 'path';
import {homedir} from 'os';
import {execSync, execFileSync} from 'child_process';
import escapeRegExp = require('escape-string-regexp');
const log = require('lighthouse-logger');
import escapeRegExp from 'escape-string-regexp';
import log from 'lighthouse-logger';

import {getWSLLocalAppDataPath, toWSLPath, ChromePathNotSetError} from './utils';

Expand Down
3 changes: 2 additions & 1 deletion src/chrome-launcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ import {DEFAULT_FLAGS} from './flags';
import {makeTmpDir, defaults, delay, getPlatform, toWin32Path, InvalidUserDataDirectoryError, UnsupportedPlatformError, ChromeNotInstalledError} from './utils';
import {ChildProcess} from 'child_process';
import {spawn, spawnSync} from 'child_process';
const log = require('lighthouse-logger');
import log from 'lighthouse-logger';

const isWsl = getPlatform() === 'wsl';
const isWindows = getPlatform() === 'win32';
const _SIGINT = 'SIGINT';
Expand Down
34 changes: 34 additions & 0 deletions src/internal-env/lighthouse-logger.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/**
* @license Copyright 2023 Google Inc. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
*/

declare module 'lighthouse-logger' {
interface Status {
msg: string;
id: string;
args?: any[];
}
export function setLevel(level: string): void;
export function isVerbose(): boolean;
export function formatProtocol(prefix: string, data: Object, level?: string): void;
export function log(title: string, ...args: any[]): void;
export function warn(title: string, ...args: any[]): void;
export function error(title: string, ...args: any[]): void;
export function verbose(title: string, ...args: any[]): void;
export function time(status: Status, level?: string): void;
export function timeEnd(status: Status, level?: string): void;
export function reset(): string;
export const cross: string;
export const dim: string;
export const tick: string;
export const bold: string;
export const purple: string;
export function redify(message: any): string;
export function greenify(message: any): string;
/** Retrieves and clears all stored time entries */
export function takeTimeEntries(): PerformanceEntry[];
export function getTimeEntries(): PerformanceEntry[];
export const events: import('events').EventEmitter;
}
2 changes: 1 addition & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import {join} from 'path';
import {execSync, execFileSync} from 'child_process';
import {mkdirSync} from 'fs';
import isWsl = require('is-wsl');
import isWsl from 'is-wsl';

export const enum LaunchErrorCodes {
ERR_LAUNCHER_PATH_NOT_SET = 'ERR_LAUNCHER_PATH_NOT_SET',
Expand Down
3 changes: 2 additions & 1 deletion test/chrome-launcher-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
import * as assert from 'assert';
import * as fs from 'fs';

const log = require('lighthouse-logger');
import log from 'lighthouse-logger';

Check failure on line 15 in test/chrome-launcher-test.ts

View workflow job for this annotation

GitHub Actions / unit_macos-latest

Could not find a declaration file for module 'lighthouse-logger'. '/Users/runner/work/chrome-launcher/chrome-launcher/node_modules/lighthouse-logger/index.js' implicitly has an 'any' type.

const fsMock = {
openSync: () => {},
closeSync: () => {},
Expand Down
3 changes: 2 additions & 1 deletion test/launch-signature-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
import {launch} from '../src/';
import * as assert from 'assert';

const log = require('lighthouse-logger');
import log from 'lighthouse-logger';

describe('Launcher', () => {

beforeEach(() => {
Expand Down
6 changes: 4 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"compilerOptions": {
"module": "commonjs",
"module": "esnext",
"moduleResolution": "node",
"outDir": "dist",
"target": "es2019",
"declaration": true,
Expand All @@ -10,7 +11,8 @@
"strictNullChecks": true,
"noImplicitReturns": true,
"noUnusedLocals": true,
"noUnusedParameters": true
"noUnusedParameters": true,
"allowSyntheticDefaultImports": true,
},
"exclude": [
"node_modules"
Expand Down