Skip to content

Commit

Permalink
chore: create common directory (#6042)
Browse files Browse the repository at this point in the history
These files will be used by both the web and node versions of Puppeteer.
Another name for this might be "core" but I don't want to cause
confusion with the puppeteer-core package that we publish at the moment.
  • Loading branch information
jackfranklin committed Jun 18, 2020
1 parent f6af7b8 commit 9522f80
Show file tree
Hide file tree
Showing 50 changed files with 102 additions and 98 deletions.
2 changes: 1 addition & 1 deletion DeviceDescriptors.js
Expand Up @@ -14,4 +14,4 @@
* limitations under the License.
*/

module.exports = require('./lib/DeviceDescriptors');
module.exports = require('./lib/common/DeviceDescriptors');
2 changes: 1 addition & 1 deletion Errors.js
Expand Up @@ -14,4 +14,4 @@
* limitations under the License.
*/

module.exports = require('./lib/Errors');
module.exports = require('./lib/common/Errors');
43 changes: 21 additions & 22 deletions src/api-docs-entry.ts
Expand Up @@ -23,26 +23,25 @@
*
* Once we have migrated to API Extractor and removed DocLint we can remove the duplication and use this file.
*/
export * from './Accessibility';
export * from './Browser';
export * from './common/Accessibility';
export * from './common/Browser';
export * from './node/BrowserFetcher';
export * from './Connection';
export * from './ConsoleMessage';
export * from './Coverage';
export * from './Dialog';
export * from './JSHandle';
export * from './ExecutionContext';
export * from './EventEmitter';
export * from './FileChooser';
export * from './FrameManager';
export * from './JSHandle';
export * from './Input';
export * from './Page';
export * from './Puppeteer';
export * from './HTTPRequest';
export * from './HTTPResponse';
export * from './SecurityDetails';
export * from './Target';
export * from './Errors';
export * from './Tracing';
export * from './WebWorker';
export * from './common/Connection';
export * from './common/ConsoleMessage';
export * from './common/Coverage';
export * from './common/Dialog';
export * from './common/JSHandle';
export * from './common/ExecutionContext';
export * from './common/EventEmitter';
export * from './common/FileChooser';
export * from './common/FrameManager';
export * from './common/Input';
export * from './common/Page';
export * from './common/Puppeteer';
export * from './common/HTTPRequest';
export * from './common/HTTPResponse';
export * from './common/SecurityDetails';
export * from './common/Target';
export * from './common/Errors';
export * from './common/Tracing';
export * from './common/WebWorker';
50 changes: 25 additions & 25 deletions src/api.ts
Expand Up @@ -19,30 +19,30 @@
* 2) index.js uses it to iterate through all methods and call helper.installAsyncStackHooks on
*/
module.exports = {
Accessibility: require('./Accessibility').Accessibility,
Browser: require('./Browser').Browser,
BrowserContext: require('./Browser').BrowserContext,
Accessibility: require('./common/Accessibility').Accessibility,
Browser: require('./common/Browser').Browser,
BrowserContext: require('./common/Browser').BrowserContext,
BrowserFetcher: require('./node/BrowserFetcher').BrowserFetcher,
CDPSession: require('./Connection').CDPSession,
ConsoleMessage: require('./ConsoleMessage').ConsoleMessage,
Coverage: require('./Coverage').Coverage,
Dialog: require('./Dialog').Dialog,
ElementHandle: require('./JSHandle').ElementHandle,
ExecutionContext: require('./ExecutionContext').ExecutionContext,
EventEmitter: require('./EventEmitter').EventEmitter,
FileChooser: require('./FileChooser').FileChooser,
Frame: require('./FrameManager').Frame,
JSHandle: require('./JSHandle').JSHandle,
Keyboard: require('./Input').Keyboard,
Mouse: require('./Input').Mouse,
Page: require('./Page').Page,
Puppeteer: require('./Puppeteer').Puppeteer,
HTTPRequest: require('./HTTPRequest').HTTPRequest,
HTTPResponse: require('./HTTPResponse').HTTPResponse,
SecurityDetails: require('./SecurityDetails').SecurityDetails,
Target: require('./Target').Target,
TimeoutError: require('./Errors').TimeoutError,
Touchscreen: require('./Input').Touchscreen,
Tracing: require('./Tracing').Tracing,
WebWorker: require('./WebWorker').WebWorker,
CDPSession: require('./common/Connection').CDPSession,
ConsoleMessage: require('./common/ConsoleMessage').ConsoleMessage,
Coverage: require('./common/Coverage').Coverage,
Dialog: require('./common/Dialog').Dialog,
ElementHandle: require('./common/JSHandle').ElementHandle,
ExecutionContext: require('./common/ExecutionContext').ExecutionContext,
EventEmitter: require('./common/EventEmitter').EventEmitter,
FileChooser: require('./common/FileChooser').FileChooser,
Frame: require('./common/FrameManager').Frame,
JSHandle: require('./common/JSHandle').JSHandle,
Keyboard: require('./common/Input').Keyboard,
Mouse: require('./common/Input').Mouse,
Page: require('./common/Page').Page,
Puppeteer: require('./common/Puppeteer').Puppeteer,
HTTPRequest: require('./common/HTTPRequest').HTTPRequest,
HTTPResponse: require('./common/HTTPResponse').HTTPResponse,
SecurityDetails: require('./common/SecurityDetails').SecurityDetails,
Target: require('./common/Target').Target,
TimeoutError: require('./common/Errors').TimeoutError,
Touchscreen: require('./common/Input').Touchscreen,
Tracing: require('./common/Tracing').Tracing,
WebWorker: require('./common/WebWorker').WebWorker,
};
2 changes: 1 addition & 1 deletion src/Accessibility.ts → src/common/Accessibility.ts
Expand Up @@ -16,7 +16,7 @@

import { CDPSession } from './Connection';
import { ElementHandle } from './JSHandle';
import Protocol from './protocol';
import Protocol from '../protocol';

/**
* Represents a Node and the properties of it that are relevant to Accessibility.
Expand Down
2 changes: 1 addition & 1 deletion src/Browser.ts → src/common/Browser.ts
Expand Up @@ -19,7 +19,7 @@ import { helper } from './helper';
import { Target } from './Target';
import { EventEmitter } from './EventEmitter';
import { Events } from './Events';
import Protocol from './protocol';
import Protocol from '../protocol';
import { Connection } from './Connection';
import { Page } from './Page';
import { ChildProcess } from 'child_process';
Expand Down
2 changes: 1 addition & 1 deletion src/Connection.ts → src/common/Connection.ts
Expand Up @@ -19,7 +19,7 @@ import { debug } from './Debug';
const debugProtocolSend = debug('puppeteer:protocol:SEND ►');
const debugProtocolReceive = debug('puppeteer:protocol:RECV ◀');

import Protocol from './protocol';
import Protocol from '../protocol';
import { ConnectionTransport } from './ConnectionTransport';
import { EventEmitter } from './EventEmitter';

Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion src/Coverage.ts → src/common/Coverage.ts
Expand Up @@ -16,7 +16,7 @@

import { assert } from './assert';
import { helper, debugError, PuppeteerEventListener } from './helper';
import Protocol from './protocol';
import Protocol from '../protocol';
import { CDPSession } from './Connection';

import { EVALUATION_SCRIPT_URL } from './ExecutionContext';
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion src/Dialog.ts → src/common/Dialog.ts
Expand Up @@ -16,7 +16,7 @@

import { assert } from './assert';
import { CDPSession } from './Connection';
import Protocol from './protocol';
import Protocol from '../protocol';

/**
* Dialog instances are dispatched by the {@link Page} via the `dialog` event.
Expand Down
2 changes: 1 addition & 1 deletion src/EmulationManager.ts → src/common/EmulationManager.ts
Expand Up @@ -15,7 +15,7 @@
*/
import { CDPSession } from './Connection';
import { Viewport } from './PuppeteerViewport';
import Protocol from './protocol';
import Protocol from '../protocol';

export class EmulationManager {
_client: CDPSession;
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion src/ExecutionContext.ts → src/common/ExecutionContext.ts
Expand Up @@ -20,7 +20,7 @@ import { createJSHandle, JSHandle, ElementHandle } from './JSHandle';
import { CDPSession } from './Connection';
import { DOMWorld } from './DOMWorld';
import { Frame } from './FrameManager';
import Protocol from './protocol';
import Protocol from '../protocol';

export const EVALUATION_SCRIPT_URL = '__puppeteer_evaluation_script__';
const SOURCE_URL_REGEX = /^[\040\t]*\/\/[@#] sourceURL=\s*(\S*?)\s*$/m;
Expand Down
2 changes: 1 addition & 1 deletion src/FileChooser.ts → src/common/FileChooser.ts
Expand Up @@ -15,7 +15,7 @@
*/

import { ElementHandle } from './JSHandle';
import Protocol from './protocol';
import Protocol from '../protocol';
import { assert } from './assert';

export class FileChooser {
Expand Down
2 changes: 1 addition & 1 deletion src/FrameManager.ts → src/common/FrameManager.ts
Expand Up @@ -28,7 +28,7 @@ import { JSHandle, ElementHandle } from './JSHandle';
import { MouseButtonInput } from './Input';
import { Page } from './Page';
import { HTTPResponse } from './HTTPResponse';
import Protocol from './protocol';
import Protocol from '../protocol';

const UTILITY_WORLD_NAME = '__puppeteer_utility_world__';

Expand Down
2 changes: 1 addition & 1 deletion src/HTTPRequest.ts → src/common/HTTPRequest.ts
Expand Up @@ -18,7 +18,7 @@ import { Frame } from './FrameManager';
import { HTTPResponse } from './HTTPResponse';
import { assert } from './assert';
import { helper, debugError } from './helper';
import Protocol from './protocol';
import Protocol from '../protocol';

export class HTTPRequest {
_requestId: string;
Expand Down
2 changes: 1 addition & 1 deletion src/HTTPResponse.ts → src/common/HTTPResponse.ts
Expand Up @@ -17,7 +17,7 @@ import { CDPSession } from './Connection';
import { Frame } from './FrameManager';
import { HTTPRequest } from './HTTPRequest';
import { SecurityDetails } from './SecurityDetails';
import Protocol from './protocol';
import Protocol from '../protocol';

interface RemoteAddress {
ip: string;
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion src/JSHandle.ts → src/common/JSHandle.ts
Expand Up @@ -22,7 +22,7 @@ import { CDPSession } from './Connection';
import { KeyInput } from './USKeyboardLayout';
import { FrameManager, Frame } from './FrameManager';
import { getQueryHandlerAndSelector } from './QueryHandler';
import Protocol from './protocol';
import Protocol from '../protocol';

interface BoxModel {
content: Array<{ x: number; y: number }>;
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion src/NetworkManager.ts → src/common/NetworkManager.ts
Expand Up @@ -16,7 +16,7 @@
import { EventEmitter } from './EventEmitter';
import { assert } from './assert';
import { helper, debugError } from './helper';
import Protocol from './protocol';
import Protocol from '../protocol';
import { Events } from './Events';
import { CDPSession } from './Connection';
import { FrameManager } from './FrameManager';
Expand Down
2 changes: 1 addition & 1 deletion src/Page.ts → src/common/Page.ts
Expand Up @@ -40,7 +40,7 @@ import { TimeoutSettings } from './TimeoutSettings';
import { FileChooser } from './FileChooser';
import { ConsoleMessage } from './ConsoleMessage';
import { PuppeteerLifeCycleEvent } from './LifecycleWatcher';
import Protocol from './protocol';
import Protocol from '../protocol';

const writeFileAsync = helper.promisify(fs.writeFile);

Expand Down
12 changes: 6 additions & 6 deletions src/Puppeteer.ts → src/common/Puppeteer.ts
Expand Up @@ -13,19 +13,19 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import Launcher from './node/Launcher';
import Launcher from '../node/Launcher';
import {
LaunchOptions,
ChromeArgOptions,
BrowserOptions,
} from './node/LaunchOptions';
import { ProductLauncher } from './node/Launcher';
import { BrowserFetcher, BrowserFetcherOptions } from './node/BrowserFetcher';
} from '../node/LaunchOptions';
import { ProductLauncher } from '../node/Launcher';
import { BrowserFetcher, BrowserFetcherOptions } from '../node/BrowserFetcher';
import { puppeteerErrors, PuppeteerErrors } from './Errors';
import { ConnectionTransport } from './ConnectionTransport';

import { devicesMap } from './DeviceDescriptors';
import { DevicesMap } from './/DeviceDescriptors';
import { DevicesMap } from './DeviceDescriptors';
import { Browser } from './Browser';
import {
registerCustomQueryHandler,
Expand Down Expand Up @@ -102,7 +102,7 @@ export class Puppeteer {
) {
// @ts-ignore
// eslint-disable-next-line @typescript-eslint/no-var-requires
const packageJson = require('../package.json');
const packageJson = require('../../package.json');
switch (this._productName) {
case 'firefox':
this._preferredRevision = packageJson.puppeteer.firefox_revision;
Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion src/SecurityDetails.ts → src/common/SecurityDetails.ts
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

import Protocol from './protocol';
import Protocol from '../protocol';

export class SecurityDetails {
private _subjectName: string;
Expand Down
2 changes: 1 addition & 1 deletion src/Target.ts → src/common/Target.ts
Expand Up @@ -20,7 +20,7 @@ import { WebWorker } from './WebWorker';
import { CDPSession } from './Connection';
import { Browser, BrowserContext } from './Browser';
import { Viewport } from './PuppeteerViewport';
import Protocol from './protocol';
import Protocol from '../protocol';

export class Target {
_targetInfo: Protocol.Target.TargetInfo;
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion src/WebWorker.ts → src/common/WebWorker.ts
Expand Up @@ -18,7 +18,7 @@ import { debugError } from './helper';
import { ExecutionContext } from './ExecutionContext';
import { JSHandle } from './JSHandle';
import { CDPSession } from './Connection';
import Protocol from './protocol';
import Protocol from '../protocol';

type ConsoleAPICalledCallback = (
eventType: string,
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion src/helper.ts → src/common/helper.ts
Expand Up @@ -18,7 +18,7 @@ import { debug } from './Debug';
import * as fs from 'fs';
import { CDPSession } from './Connection';
import { promisify } from 'util';
import Protocol from './protocol';
import Protocol from '../protocol';
import { CommonEventEmitter } from './EventEmitter';
import { assert } from './assert';

Expand Down
6 changes: 3 additions & 3 deletions src/index.ts
Expand Up @@ -19,9 +19,9 @@
// eslint-disable-next-line @typescript-eslint/no-var-requires
const api = require('./api');

import { helper } from './helper';
import { Page } from './Page';
import { Puppeteer } from './Puppeteer';
import { helper } from './common/helper';
import { Page } from './common/Page';
import { Puppeteer } from './common/Puppeteer';

interface InitOptions {
packageJson: {
Expand Down
6 changes: 3 additions & 3 deletions src/node/BrowserFetcher.ts
Expand Up @@ -23,13 +23,13 @@ import * as https from 'https';
import * as http from 'http';

import extractZip from 'extract-zip';
import { debug } from '../Debug';
import { debug } from '../common/Debug';
import removeRecursive from 'rimraf';
import * as URL from 'url';
import ProxyAgent from 'https-proxy-agent';
import { getProxyForUrl } from 'proxy-from-env';
import { assert } from '../assert';
import { helper } from '../helper';
import { assert } from '../common/assert';
import { helper } from '../common/helper';
const debugFetcher = debug(`puppeteer:fetcher`);

const downloadURLs = {
Expand Down
12 changes: 6 additions & 6 deletions src/node/BrowserRunner.ts
Expand Up @@ -14,18 +14,18 @@
* limitations under the License.
*/

import { debug } from '../Debug';
import { debug } from '../common/Debug';

import removeFolder from 'rimraf';
import * as childProcess from 'child_process';
import { assert } from '../assert';
import { helper, debugError } from '../helper';
import { assert } from '../common/assert';
import { helper, debugError } from '../common/helper';
import { LaunchOptions } from './LaunchOptions';
import { Connection } from '../Connection';
import { WebSocketTransport } from '../WebSocketTransport';
import { Connection } from '../common/Connection';
import { WebSocketTransport } from '../common/WebSocketTransport';
import { PipeTransport } from './PipeTransport';
import * as readline from 'readline';
import { TimeoutError } from '../Errors';
import { TimeoutError } from '../common/Errors';

const removeFolderAsync = helper.promisify(removeFolder);
const debugLauncher = debug('puppeteer:launcher');
Expand Down
2 changes: 1 addition & 1 deletion src/node/LaunchOptions.ts
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

import { Viewport } from '../PuppeteerViewport';
import { Viewport } from '../common/PuppeteerViewport';

export interface ChromeArgOptions {
headless?: boolean;
Expand Down
12 changes: 6 additions & 6 deletions src/node/Launcher.ts
Expand Up @@ -21,12 +21,12 @@ import * as URL from 'url';
import * as fs from 'fs';

import { BrowserFetcher } from './BrowserFetcher';
import { Connection } from '../Connection';
import { Browser } from '../Browser';
import { assert } from '../assert';
import { helper, debugError } from '../helper';
import { ConnectionTransport } from '../ConnectionTransport';
import { WebSocketTransport } from '../WebSocketTransport';
import { Connection } from '../common/Connection';
import { Browser } from '../common/Browser';
import { assert } from '../common/assert';
import { helper, debugError } from '../common/helper';
import { ConnectionTransport } from '../common/ConnectionTransport';
import { WebSocketTransport } from '../common/WebSocketTransport';
import { BrowserRunner } from './BrowserRunner';

const mkdtempAsync = helper.promisify(fs.mkdtemp);
Expand Down

0 comments on commit 9522f80

Please sign in to comment.