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. * 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. * 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. * Once we have migrated to API Extractor and removed DocLint we can remove the duplication and use this file.
*/ */
export * from './Accessibility'; export * from './common/Accessibility';
export * from './Browser'; export * from './common/Browser';
export * from './node/BrowserFetcher'; export * from './node/BrowserFetcher';
export * from './Connection'; export * from './common/Connection';
export * from './ConsoleMessage'; export * from './common/ConsoleMessage';
export * from './Coverage'; export * from './common/Coverage';
export * from './Dialog'; export * from './common/Dialog';
export * from './JSHandle'; export * from './common/JSHandle';
export * from './ExecutionContext'; export * from './common/ExecutionContext';
export * from './EventEmitter'; export * from './common/EventEmitter';
export * from './FileChooser'; export * from './common/FileChooser';
export * from './FrameManager'; export * from './common/FrameManager';
export * from './JSHandle'; export * from './common/Input';
export * from './Input'; export * from './common/Page';
export * from './Page'; export * from './common/Puppeteer';
export * from './Puppeteer'; export * from './common/HTTPRequest';
export * from './HTTPRequest'; export * from './common/HTTPResponse';
export * from './HTTPResponse'; export * from './common/SecurityDetails';
export * from './SecurityDetails'; export * from './common/Target';
export * from './Target'; export * from './common/Errors';
export * from './Errors'; export * from './common/Tracing';
export * from './Tracing'; export * from './common/WebWorker';
export * from './WebWorker';

View File

@ -19,30 +19,30 @@
* 2) index.js uses it to iterate through all methods and call helper.installAsyncStackHooks on * 2) index.js uses it to iterate through all methods and call helper.installAsyncStackHooks on
*/ */
module.exports = { module.exports = {
Accessibility: require('./Accessibility').Accessibility, Accessibility: require('./common/Accessibility').Accessibility,
Browser: require('./Browser').Browser, Browser: require('./common/Browser').Browser,
BrowserContext: require('./Browser').BrowserContext, BrowserContext: require('./common/Browser').BrowserContext,
BrowserFetcher: require('./node/BrowserFetcher').BrowserFetcher, BrowserFetcher: require('./node/BrowserFetcher').BrowserFetcher,
CDPSession: require('./Connection').CDPSession, CDPSession: require('./common/Connection').CDPSession,
ConsoleMessage: require('./ConsoleMessage').ConsoleMessage, ConsoleMessage: require('./common/ConsoleMessage').ConsoleMessage,
Coverage: require('./Coverage').Coverage, Coverage: require('./common/Coverage').Coverage,
Dialog: require('./Dialog').Dialog, Dialog: require('./common/Dialog').Dialog,
ElementHandle: require('./JSHandle').ElementHandle, ElementHandle: require('./common/JSHandle').ElementHandle,
ExecutionContext: require('./ExecutionContext').ExecutionContext, ExecutionContext: require('./common/ExecutionContext').ExecutionContext,
EventEmitter: require('./EventEmitter').EventEmitter, EventEmitter: require('./common/EventEmitter').EventEmitter,
FileChooser: require('./FileChooser').FileChooser, FileChooser: require('./common/FileChooser').FileChooser,
Frame: require('./FrameManager').Frame, Frame: require('./common/FrameManager').Frame,
JSHandle: require('./JSHandle').JSHandle, JSHandle: require('./common/JSHandle').JSHandle,
Keyboard: require('./Input').Keyboard, Keyboard: require('./common/Input').Keyboard,
Mouse: require('./Input').Mouse, Mouse: require('./common/Input').Mouse,
Page: require('./Page').Page, Page: require('./common/Page').Page,
Puppeteer: require('./Puppeteer').Puppeteer, Puppeteer: require('./common/Puppeteer').Puppeteer,
HTTPRequest: require('./HTTPRequest').HTTPRequest, HTTPRequest: require('./common/HTTPRequest').HTTPRequest,
HTTPResponse: require('./HTTPResponse').HTTPResponse, HTTPResponse: require('./common/HTTPResponse').HTTPResponse,
SecurityDetails: require('./SecurityDetails').SecurityDetails, SecurityDetails: require('./common/SecurityDetails').SecurityDetails,
Target: require('./Target').Target, Target: require('./common/Target').Target,
TimeoutError: require('./Errors').TimeoutError, TimeoutError: require('./common/Errors').TimeoutError,
Touchscreen: require('./Input').Touchscreen, Touchscreen: require('./common/Input').Touchscreen,
Tracing: require('./Tracing').Tracing, Tracing: require('./common/Tracing').Tracing,
WebWorker: require('./WebWorker').WebWorker, WebWorker: require('./common/WebWorker').WebWorker,
}; };

View File

@ -16,7 +16,7 @@
import { CDPSession } from './Connection'; import { CDPSession } from './Connection';
import { ElementHandle } from './JSHandle'; 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. * 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 { Target } from './Target';
import { EventEmitter } from './EventEmitter'; import { EventEmitter } from './EventEmitter';
import { Events } from './Events'; import { Events } from './Events';
import Protocol from './protocol'; import Protocol from '../protocol';
import { Connection } from './Connection'; import { Connection } from './Connection';
import { Page } from './Page'; import { Page } from './Page';
import { ChildProcess } from 'child_process'; import { ChildProcess } from 'child_process';

View File

@ -19,7 +19,7 @@ import { debug } from './Debug';
const debugProtocolSend = debug('puppeteer:protocol:SEND ►'); const debugProtocolSend = debug('puppeteer:protocol:SEND ►');
const debugProtocolReceive = debug('puppeteer:protocol:RECV ◀'); const debugProtocolReceive = debug('puppeteer:protocol:RECV ◀');
import Protocol from './protocol'; import Protocol from '../protocol';
import { ConnectionTransport } from './ConnectionTransport'; import { ConnectionTransport } from './ConnectionTransport';
import { EventEmitter } from './EventEmitter'; import { EventEmitter } from './EventEmitter';

View File

@ -16,7 +16,7 @@
import { assert } from './assert'; import { assert } from './assert';
import { helper, debugError, PuppeteerEventListener } from './helper'; import { helper, debugError, PuppeteerEventListener } from './helper';
import Protocol from './protocol'; import Protocol from '../protocol';
import { CDPSession } from './Connection'; import { CDPSession } from './Connection';
import { EVALUATION_SCRIPT_URL } from './ExecutionContext'; import { EVALUATION_SCRIPT_URL } from './ExecutionContext';

View File

@ -16,7 +16,7 @@
import { assert } from './assert'; import { assert } from './assert';
import { CDPSession } from './Connection'; import { CDPSession } from './Connection';
import Protocol from './protocol'; import Protocol from '../protocol';
/** /**
* Dialog instances are dispatched by the {@link Page} via the `dialog` event. * Dialog instances are dispatched by the {@link Page} via the `dialog` event.

View File

@ -15,7 +15,7 @@
*/ */
import { CDPSession } from './Connection'; import { CDPSession } from './Connection';
import { Viewport } from './PuppeteerViewport'; import { Viewport } from './PuppeteerViewport';
import Protocol from './protocol'; import Protocol from '../protocol';
export class EmulationManager { export class EmulationManager {
_client: CDPSession; _client: CDPSession;

View File

@ -20,7 +20,7 @@ import { createJSHandle, JSHandle, ElementHandle } from './JSHandle';
import { CDPSession } from './Connection'; import { CDPSession } from './Connection';
import { DOMWorld } from './DOMWorld'; import { DOMWorld } from './DOMWorld';
import { Frame } from './FrameManager'; import { Frame } from './FrameManager';
import Protocol from './protocol'; import Protocol from '../protocol';
export const EVALUATION_SCRIPT_URL = '__puppeteer_evaluation_script__'; export const EVALUATION_SCRIPT_URL = '__puppeteer_evaluation_script__';
const SOURCE_URL_REGEX = /^[\040\t]*\/\/[@#] sourceURL=\s*(\S*?)\s*$/m; const SOURCE_URL_REGEX = /^[\040\t]*\/\/[@#] sourceURL=\s*(\S*?)\s*$/m;

View File

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

View File

@ -28,7 +28,7 @@ import { JSHandle, ElementHandle } from './JSHandle';
import { MouseButtonInput } from './Input'; import { MouseButtonInput } from './Input';
import { Page } from './Page'; import { Page } from './Page';
import { HTTPResponse } from './HTTPResponse'; import { HTTPResponse } from './HTTPResponse';
import Protocol from './protocol'; import Protocol from '../protocol';
const UTILITY_WORLD_NAME = '__puppeteer_utility_world__'; const UTILITY_WORLD_NAME = '__puppeteer_utility_world__';

View File

@ -18,7 +18,7 @@ import { Frame } from './FrameManager';
import { HTTPResponse } from './HTTPResponse'; import { HTTPResponse } from './HTTPResponse';
import { assert } from './assert'; import { assert } from './assert';
import { helper, debugError } from './helper'; import { helper, debugError } from './helper';
import Protocol from './protocol'; import Protocol from '../protocol';
export class HTTPRequest { export class HTTPRequest {
_requestId: string; _requestId: string;

View File

@ -17,7 +17,7 @@ import { CDPSession } from './Connection';
import { Frame } from './FrameManager'; import { Frame } from './FrameManager';
import { HTTPRequest } from './HTTPRequest'; import { HTTPRequest } from './HTTPRequest';
import { SecurityDetails } from './SecurityDetails'; import { SecurityDetails } from './SecurityDetails';
import Protocol from './protocol'; import Protocol from '../protocol';
interface RemoteAddress { interface RemoteAddress {
ip: string; ip: string;

View File

@ -22,7 +22,7 @@ import { CDPSession } from './Connection';
import { KeyInput } from './USKeyboardLayout'; import { KeyInput } from './USKeyboardLayout';
import { FrameManager, Frame } from './FrameManager'; import { FrameManager, Frame } from './FrameManager';
import { getQueryHandlerAndSelector } from './QueryHandler'; import { getQueryHandlerAndSelector } from './QueryHandler';
import Protocol from './protocol'; import Protocol from '../protocol';
interface BoxModel { interface BoxModel {
content: Array<{ x: number; y: number }>; content: Array<{ x: number; y: number }>;

View File

@ -16,7 +16,7 @@
import { EventEmitter } from './EventEmitter'; import { EventEmitter } from './EventEmitter';
import { assert } from './assert'; import { assert } from './assert';
import { helper, debugError } from './helper'; import { helper, debugError } from './helper';
import Protocol from './protocol'; import Protocol from '../protocol';
import { Events } from './Events'; import { Events } from './Events';
import { CDPSession } from './Connection'; import { CDPSession } from './Connection';
import { FrameManager } from './FrameManager'; import { FrameManager } from './FrameManager';

View File

@ -40,7 +40,7 @@ import { TimeoutSettings } from './TimeoutSettings';
import { FileChooser } from './FileChooser'; import { FileChooser } from './FileChooser';
import { ConsoleMessage } from './ConsoleMessage'; import { ConsoleMessage } from './ConsoleMessage';
import { PuppeteerLifeCycleEvent } from './LifecycleWatcher'; import { PuppeteerLifeCycleEvent } from './LifecycleWatcher';
import Protocol from './protocol'; import Protocol from '../protocol';
const writeFileAsync = helper.promisify(fs.writeFile); const writeFileAsync = helper.promisify(fs.writeFile);

View File

@ -13,19 +13,19 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
import Launcher from './node/Launcher'; import Launcher from '../node/Launcher';
import { import {
LaunchOptions, LaunchOptions,
ChromeArgOptions, ChromeArgOptions,
BrowserOptions, BrowserOptions,
} from './node/LaunchOptions'; } from '../node/LaunchOptions';
import { ProductLauncher } from './node/Launcher'; import { ProductLauncher } from '../node/Launcher';
import { BrowserFetcher, BrowserFetcherOptions } from './node/BrowserFetcher'; import { BrowserFetcher, BrowserFetcherOptions } from '../node/BrowserFetcher';
import { puppeteerErrors, PuppeteerErrors } from './Errors'; import { puppeteerErrors, PuppeteerErrors } from './Errors';
import { ConnectionTransport } from './ConnectionTransport'; import { ConnectionTransport } from './ConnectionTransport';
import { devicesMap } from './DeviceDescriptors'; import { devicesMap } from './DeviceDescriptors';
import { DevicesMap } from './/DeviceDescriptors'; import { DevicesMap } from './DeviceDescriptors';
import { Browser } from './Browser'; import { Browser } from './Browser';
import { import {
registerCustomQueryHandler, registerCustomQueryHandler,
@ -102,7 +102,7 @@ export class Puppeteer {
) { ) {
// @ts-ignore // @ts-ignore
// eslint-disable-next-line @typescript-eslint/no-var-requires // eslint-disable-next-line @typescript-eslint/no-var-requires
const packageJson = require('../package.json'); const packageJson = require('../../package.json');
switch (this._productName) { switch (this._productName) {
case 'firefox': case 'firefox':
this._preferredRevision = packageJson.puppeteer.firefox_revision; this._preferredRevision = packageJson.puppeteer.firefox_revision;

View File

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

View File

@ -20,7 +20,7 @@ import { WebWorker } from './WebWorker';
import { CDPSession } from './Connection'; import { CDPSession } from './Connection';
import { Browser, BrowserContext } from './Browser'; import { Browser, BrowserContext } from './Browser';
import { Viewport } from './PuppeteerViewport'; import { Viewport } from './PuppeteerViewport';
import Protocol from './protocol'; import Protocol from '../protocol';
export class Target { export class Target {
_targetInfo: Protocol.Target.TargetInfo; _targetInfo: Protocol.Target.TargetInfo;

View File

@ -18,7 +18,7 @@ import { debugError } from './helper';
import { ExecutionContext } from './ExecutionContext'; import { ExecutionContext } from './ExecutionContext';
import { JSHandle } from './JSHandle'; import { JSHandle } from './JSHandle';
import { CDPSession } from './Connection'; import { CDPSession } from './Connection';
import Protocol from './protocol'; import Protocol from '../protocol';
type ConsoleAPICalledCallback = ( type ConsoleAPICalledCallback = (
eventType: string, eventType: string,

View File

@ -18,7 +18,7 @@ import { debug } from './Debug';
import * as fs from 'fs'; import * as fs from 'fs';
import { CDPSession } from './Connection'; import { CDPSession } from './Connection';
import { promisify } from 'util'; import { promisify } from 'util';
import Protocol from './protocol'; import Protocol from '../protocol';
import { CommonEventEmitter } from './EventEmitter'; import { CommonEventEmitter } from './EventEmitter';
import { assert } from './assert'; import { assert } from './assert';

View File

@ -19,9 +19,9 @@
// eslint-disable-next-line @typescript-eslint/no-var-requires // eslint-disable-next-line @typescript-eslint/no-var-requires
const api = require('./api'); const api = require('./api');
import { helper } from './helper'; import { helper } from './common/helper';
import { Page } from './Page'; import { Page } from './common/Page';
import { Puppeteer } from './Puppeteer'; import { Puppeteer } from './common/Puppeteer';
interface InitOptions { interface InitOptions {
packageJson: { packageJson: {

View File

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

View File

@ -14,18 +14,18 @@
* limitations under the License. * limitations under the License.
*/ */
import { debug } from '../Debug'; import { debug } from '../common/Debug';
import removeFolder from 'rimraf'; import removeFolder from 'rimraf';
import * as childProcess from 'child_process'; import * as childProcess from 'child_process';
import { assert } from '../assert'; import { assert } from '../common/assert';
import { helper, debugError } from '../helper'; import { helper, debugError } from '../common/helper';
import { LaunchOptions } from './LaunchOptions'; import { LaunchOptions } from './LaunchOptions';
import { Connection } from '../Connection'; import { Connection } from '../common/Connection';
import { WebSocketTransport } from '../WebSocketTransport'; import { WebSocketTransport } from '../common/WebSocketTransport';
import { PipeTransport } from './PipeTransport'; import { PipeTransport } from './PipeTransport';
import * as readline from 'readline'; import * as readline from 'readline';
import { TimeoutError } from '../Errors'; import { TimeoutError } from '../common/Errors';
const removeFolderAsync = helper.promisify(removeFolder); const removeFolderAsync = helper.promisify(removeFolder);
const debugLauncher = debug('puppeteer:launcher'); const debugLauncher = debug('puppeteer:launcher');

View File

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

View File

@ -21,12 +21,12 @@ import * as URL from 'url';
import * as fs from 'fs'; import * as fs from 'fs';
import { BrowserFetcher } from './BrowserFetcher'; import { BrowserFetcher } from './BrowserFetcher';
import { Connection } from '../Connection'; import { Connection } from '../common/Connection';
import { Browser } from '../Browser'; import { Browser } from '../common/Browser';
import { assert } from '../assert'; import { assert } from '../common/assert';
import { helper, debugError } from '../helper'; import { helper, debugError } from '../common/helper';
import { ConnectionTransport } from '../ConnectionTransport'; import { ConnectionTransport } from '../common/ConnectionTransport';
import { WebSocketTransport } from '../WebSocketTransport'; import { WebSocketTransport } from '../common/WebSocketTransport';
import { BrowserRunner } from './BrowserRunner'; import { BrowserRunner } from './BrowserRunner';
const mkdtempAsync = helper.promisify(fs.mkdtemp); const mkdtempAsync = helper.promisify(fs.mkdtemp);

View File

@ -13,8 +13,8 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
import { helper, debugError, PuppeteerEventListener } from '../helper'; import { helper, debugError, PuppeteerEventListener } from '../common/helper';
import { ConnectionTransport } from '../ConnectionTransport'; import { ConnectionTransport } from '../common/ConnectionTransport';
export class PipeTransport implements ConnectionTransport { export class PipeTransport implements ConnectionTransport {
_pipeWrite: NodeJS.WritableStream; _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 sinon = require('sinon');
const expect = require('expect'); const expect = require('expect');

View File

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

View File

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

View File

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