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 2 commits
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
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
{
"name": "chrome-launcher",
"main": "./dist/index.js",
"type": "module",
"engines": {
"node": ">=12.13.0"
},
"scripts": {
"build": "tsc",
"dev": "tsc -w",
"test": "mocha --require ts-node/register --reporter=dot test/**/*-test.ts --timeout=10000",
"test": "TS_NODE_PROJECT=test/tsconfig.json mocha --loader=ts-node/esm --reporter=dot test/**/*-test.ts --timeout=10000",
"test-formatting": "test/check-formatting.sh",
"format": "scripts/format.sh",
"type-check": "tsc --allowJs --checkJs --noEmit --target es2019 *.js",
Expand All @@ -23,7 +24,7 @@
"clang-format": "^1.0.50",
"mocha": "^8.2.1",
"sinon": "^9.0.1",
"ts-node": "^9.1.0",
"ts-node": "^10.9.1",
"typescript": "^4.1.2"
},
"dependencies": {
Expand Down
10 changes: 5 additions & 5 deletions src/chrome-finder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
*/
'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';
import {getWSLLocalAppDataPath, toWSLPath, ChromePathNotSetError} from './utils.js';

const newLineRegex = /\r?\n/;

Expand Down
11 changes: 6 additions & 5 deletions src/chrome-launcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@
import * as childProcess from 'child_process';
import * as fs from 'fs';
import * as net from 'net';
import * as chromeFinder from './chrome-finder';
import {getRandomPort} from './random-port';
import {DEFAULT_FLAGS} from './flags';
import {makeTmpDir, defaults, delay, getPlatform, toWin32Path, InvalidUserDataDirectoryError, UnsupportedPlatformError, ChromeNotInstalledError} from './utils';
import * as chromeFinder from './chrome-finder.js';
import {getRandomPort} from './random-port.js';
import {DEFAULT_FLAGS} from './flags.js';
import {makeTmpDir, defaults, delay, getPlatform, toWin32Path, InvalidUserDataDirectoryError, UnsupportedPlatformError, ChromeNotInstalledError} from './utils.js';
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
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from './chrome-launcher';
export * from './chrome-launcher.js';
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
15 changes: 9 additions & 6 deletions test/chrome-launcher-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,17 @@
*/
'use strict';

import {Launcher, launch, killAll, Options, getChromePath} from '../src/chrome-launcher';
import {DEFAULT_FLAGS} from '../src/flags';
import {Launcher, launch, killAll, Options, getChromePath} from '../src/chrome-launcher.js';
import {DEFAULT_FLAGS} from '../src/flags.js';

import {spy, stub} from 'sinon';
import sinon from 'sinon';
import * as assert from 'assert';
import * as fs from 'fs';
import fs from 'fs';

import log from 'lighthouse-logger';

const {spy, stub} = sinon;

const log = require('lighthouse-logger');
const fsMock = {
openSync: () => {},
closeSync: () => {},
Expand All @@ -38,7 +41,7 @@ const launchChromeWithOpts = async (opts: Options = {}) => {
}
};

describe('Launcher', () => {
describe.only('Launcher', () => {
adamraine marked this conversation as resolved.
Show resolved Hide resolved
beforeEach(() => {
log.setLevel('error');
});
Expand Down
5 changes: 3 additions & 2 deletions test/launch-signature-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@

'use strict';

import {launch} from '../src/';
import {launch} from '../src/index.js';
import * as assert from 'assert';

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

describe('Launcher', () => {

beforeEach(() => {
Expand Down
2 changes: 1 addition & 1 deletion test/random-port-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
'use strict';

import * as assert from 'assert';
import {getRandomPort} from '../src/random-port';
import {getRandomPort} from '../src/random-port.js';

describe('Random port generation', () => {
it('generates a valid random port number', async () => {
Expand Down
10 changes: 10 additions & 0 deletions test/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extends": "../tsconfig.json",
"ts-node": {
"files": true,
},
"include": [
"*-test.ts",
"../types"
]
}
adamraine marked this conversation as resolved.
Show resolved Hide resolved
6 changes: 3 additions & 3 deletions test/utils-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
'use strict';

import * as assert from 'assert';
import { toWin32Path, toWSLPath, getWSLLocalAppDataPath } from '../src/utils';
import * as sinon from 'sinon';
import * as child_process from 'child_process';
import { toWin32Path, toWSLPath, getWSLLocalAppDataPath } from '../src/utils.js';
import sinon from 'sinon';
import child_process from 'child_process';

const execFileSyncStub = sinon.stub(child_process, 'execFileSync').callThrough();

Expand Down
9 changes: 6 additions & 3 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,12 +11,14 @@
"strictNullChecks": true,
"noImplicitReturns": true,
"noUnusedLocals": true,
"noUnusedParameters": true
"noUnusedParameters": true,
"allowSyntheticDefaultImports": true,
},
"exclude": [
"node_modules"
],
"include": [
"src"
"src",
"types"
adamraine marked this conversation as resolved.
Show resolved Hide resolved
]
}
34 changes: 34 additions & 0 deletions types/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;
}