chore: create common directory (#6042)

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.
This commit is contained in:
Jack Franklin 2020-06-18 15:53:23 +01:00 committed by GitHub
parent f6af7b8df0
commit 9522f80116
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
50 changed files with 102 additions and 98 deletions

View File

@ -14,4 +14,4 @@
* limitations under the License.
*/
module.exports = require('./lib/DeviceDescriptors');
module.exports = require('./lib/common/DeviceDescriptors');

View File

@ -14,4 +14,4 @@
* limitations under the License.
*/
module.exports = require('./lib/Errors');
module.exports = require('./lib/common/Errors');

View File

@ -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';

View File

@ -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,
};

View File

@ -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.

View File

@ -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';

View File

@ -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';

View File

@ -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';

View File

@ -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.

View File

@ -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;

View File

@ -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;

View File

@ -15,7 +15,7 @@
*/
import { ElementHandle } from './JSHandle';
import Protocol from './protocol';
import Protocol from '../protocol';
import { assert } from './assert';
export class FileChooser {

View File

@ -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__';

View File

@ -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;

View File

@ -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;

View File

@ -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 }>;

View File

@ -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';

View File

@ -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);

View File

@ -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,
@ -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;

View File

@ -14,7 +14,7 @@
* limitations under the License.
*/
import Protocol from './protocol';
import Protocol from '../protocol';
export class SecurityDetails {
private _subjectName: string;

View File

@ -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;

View File

@ -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,

View File

@ -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';

View File

@ -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: {

View File

@ -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 = {

View File

@ -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');

View File

@ -14,7 +14,7 @@
* limitations under the License.
*/
import { Viewport } from '../PuppeteerViewport';
import { Viewport } from '../common/PuppeteerViewport';
export interface ChromeArgOptions {
headless?: boolean;

View File

@ -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);

View File

@ -13,8 +13,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { helper, debugError, PuppeteerEventListener } from '../helper';
import { ConnectionTransport } from '../ConnectionTransport';
import { helper, debugError, PuppeteerEventListener } from '../common/helper';
import { ConnectionTransport } from '../common/ConnectionTransport';
export class PipeTransport implements ConnectionTransport {
_pipeWrite: NodeJS.WritableStream;

View File

@ -1,4 +1,4 @@
const { EventEmitter } = require('../lib/EventEmitter');
const { EventEmitter } = require('../lib/common/EventEmitter');
const sinon = require('sinon');
const expect = require('expect');

View File

@ -104,7 +104,7 @@ const trackCoverage = () => {
before(() => {
const api = require('../lib/api');
const events = require('../lib/Events');
const events = require('../lib/common/Events');
for (const [className, classType] of Object.entries(api))
traceAPICoverage(coverageMap, events, className, classType);
});

View File

@ -17,7 +17,7 @@ const fs = require('fs');
const os = require('os');
const path = require('path');
const sinon = require('sinon');
const { helper } = require('../lib/helper');
const { helper } = require('../lib/common/helper');
const rmAsync = helper.promisify(require('rimraf'));
const mkdtempAsync = helper.promisify(fs.mkdtemp);
const readFileAsync = helper.promisify(fs.readFile);

View File

@ -61,6 +61,7 @@ async function run() {
* we'll just list the directories manually.
*/
...(await Source.readdir(path.join(PROJECT_DIR, 'src'), 'ts')),
...(await Source.readdir(path.join(PROJECT_DIR, 'src', 'common'), 'ts')),
...(await Source.readdir(path.join(PROJECT_DIR, 'src', 'node'), 'ts')),
];
@ -68,7 +69,11 @@ async function run() {
(source) => !source.filePath().endsWith('.d.ts')
);
const jsSources = await Source.readdir(path.join(PROJECT_DIR, 'lib'));
const jsSources = [
...(await Source.readdir(path.join(PROJECT_DIR, 'lib'))),
...(await Source.readdir(path.join(PROJECT_DIR, 'lib', 'common'))),
...(await Source.readdir(path.join(PROJECT_DIR, 'lib', 'node'))),
];
const allSrcCode = [...jsSources, ...tsSourcesNoDefinitions];
messages.push(...(await checkPublicAPI(page, mdSources, allSrcCode)));