diff --git a/src/Connection.ts b/src/Connection.ts index cb55228469f..04329d1336b 100644 --- a/src/Connection.ts +++ b/src/Connection.ts @@ -13,8 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import helper = require('./helper'); -const {assert} = helper; +import {assert} from './helper'; import EventsModule = require('./Events'); const {Events} = EventsModule; diff --git a/src/Dialog.ts b/src/Dialog.ts index 91204f25574..792c37700ce 100644 --- a/src/Dialog.ts +++ b/src/Dialog.ts @@ -14,11 +14,9 @@ * limitations under the License. */ -import helpers = require('./helper'); +import {assert} from './helper'; import {CDPSession} from './Connection'; -const {assert} = helpers; - enum DialogType { Alert = 'alert', BeforeUnload = 'beforeunload', diff --git a/src/PipeTransport.ts b/src/PipeTransport.ts index d23ef096517..b997ee5dc06 100644 --- a/src/PipeTransport.ts +++ b/src/PipeTransport.ts @@ -13,8 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import helperUtils = require('./helper'); -const {helper, debugError} = helperUtils; +import {helper, debugError, PuppeteerEventListener} from './helper'; class PipeTransport implements Puppeteer.ConnectionTransport { _pipeWrite: NodeJS.WritableStream; diff --git a/src/helper.ts b/src/helper.ts index b3e9e8fe4b9..fb9fa265b3c 100644 --- a/src/helper.ts +++ b/src/helper.ts @@ -16,7 +16,6 @@ import Errors = require('./Errors'); import debug = require('debug'); -const debugError = debug('puppeteer:error'); import fs = require('fs'); import promisify = require('./promisify'); import {CDPSession} from './Connection'; @@ -27,7 +26,9 @@ const openAsync = promisify(fs.open); const writeAsync = promisify(fs.write); const closeAsync = promisify(fs.close); -function assert(value: unknown, message?: string): void { +export const debugError = debug('puppeteer:error'); + +export function assert(value: unknown, message?: string): void { if (!value) throw new Error(message); } @@ -103,6 +104,11 @@ function installAsyncStackHooks(classType: AnyClass): void { } } +export interface PuppeteerEventListener { + emitter: NodeJS.EventEmitter; + eventName: string | symbol; + handler: (...args: any[]) => void; +} function addEventListener(emitter: NodeJS.EventEmitter, eventName: string|symbol, handler: (...args: any[]) => void): PuppeteerEventListener { emitter.on(eventName, handler); @@ -212,22 +218,18 @@ async function readProtocolStream(client: CDPSession, handle: string, path?: str } -export = { - helper: { - promisify, - evaluationString, - readProtocolStream, - waitWithTimeout, - waitForEvent, - isString, - isNumber, - addEventListener, - removeEventListeners, - valueFromRemoteObject, - installAsyncStackHooks, - getExceptionMessage, - releaseObject, - }, - assert, - debugError +export const helper = { + promisify, + evaluationString, + readProtocolStream, + waitWithTimeout, + waitForEvent, + isString, + isNumber, + addEventListener, + removeEventListeners, + valueFromRemoteObject, + installAsyncStackHooks, + getExceptionMessage, + releaseObject, }; diff --git a/src/types.d.ts b/src/types.d.ts deleted file mode 100644 index 8be41bae854..00000000000 --- a/src/types.d.ts +++ /dev/null @@ -1,25 +0,0 @@ -/** - * Copyright 2020 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. - */ - -/* These types exist here until we migrate over to ESM where we can - * import / export them properly from modules - TS doesn't support - * exposing interfaces in CommonJS land. - */ -interface PuppeteerEventListener { - emitter: NodeJS.EventEmitter; - eventName: string | symbol; - handler: (...args: any[]) => void; -}