chore: stop Protocol types being globally available (#5899)

We should import them just like any other module. This commit makes that
change. It does not change any behaviours or the types themselves.

EXPECTED_PROTOCOL_DIFF as we're updating the structure of it.
This commit is contained in:
Jack Franklin 2020-05-21 17:04:05 +01:00 committed by GitHub
parent d8e0557d18
commit dfb2e6056b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
19 changed files with 15034 additions and 15011 deletions

View File

@ -14,12 +14,9 @@
* limitations under the License.
*/
// Used as a TypeDef
// eslint-disable-next-line no-unused-vars
import { CDPSession } from './Connection';
// Used as a TypeDef
// eslint-disable-next-line no-unused-vars
import { ElementHandle } from './JSHandle';
import Protocol from './protocol';
interface SerializedAXNode {
role: string;

View File

@ -18,6 +18,7 @@ import { helper, assert } from './helper';
import { Target } from './Target';
import * as EventEmitter from 'events';
import { Events } from './Events';
import Protocol from './protocol';
import { Connection } from './Connection';
import { Page } from './Page';
import { ChildProcess } from 'child_process';

View File

@ -18,6 +18,7 @@ import { Events } from './Events';
import * as debug from 'debug';
const debugProtocol = debug('puppeteer:protocol');
import Protocol from './protocol';
import type { ConnectionTransport } from './ConnectionTransport';
import * as EventEmitter from 'events';

View File

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

View File

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

View File

@ -19,6 +19,7 @@ import { createJSHandle, JSHandle, ElementHandle } from './JSHandle';
import { CDPSession } from './Connection';
import { DOMWorld } from './DOMWorld';
import { Frame } from './FrameManager';
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,6 +15,7 @@
*/
import { ElementHandle } from './JSHandle';
import Protocol from './protocol';
import { assert } from './helper';
export class FileChooser {

View File

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

View File

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

View File

@ -15,6 +15,7 @@
*/
import * as EventEmitter from 'events';
import { helper, assert, debugError } from './helper';
import Protocol from './protocol';
import { Events } from './Events';
import { CDPSession } from './Connection';
import { FrameManager } from './FrameManager';

View File

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

View File

@ -17,6 +17,7 @@ import { CDPSession } from './Connection';
import { Frame } from './FrameManager';
import { Response } from './Response';
import { helper, assert, debugError } from './helper';
import Protocol from './protocol';
export class Request {
_requestId: string;

View File

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

View File

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

View File

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

View File

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

View File

@ -18,6 +18,7 @@ import * as debug from 'debug';
import * as fs from 'fs';
import { CDPSession } from './Connection';
import { promisify } from 'util';
import Protocol from './protocol';
const openAsync = promisify(fs.open);
const writeAsync = promisify(fs.write);

29944
src/protocol.d.ts vendored

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,7 @@
// @ts-check
const path = require('path');
const puppeteer = require('../..');
const { execSync } = require('child_process');
const fetchAndGenerateProtocolDefinitions = () =>
puppeteer
@ -21,51 +22,51 @@ const fetchAndGenerateProtocolDefinitions = () =>
await browser.close();
const output = `// This is generated from /utils/protocol-types-generator/index.js
type binary = string;
declare global {
module Protocol {${json.domains
.map(
(domain) => `${
domain.description
? `
declare module Protocol {${json.domains
.map(
(domain) => `${
domain.description
? `
/**
* ${domain.description}
*/`
: ''
}
: ''
}
export module ${domain.domain} {${(domain.types || [])
.map(
(type) =>
`${
type.description
? `
.map(
(type) =>
`${
type.description
? `
/**
* ${type.description}
*/`
: ''
}${
type.properties
? `
: ''
}${
type.properties
? `
export interface ${type.id} {${(type.properties || [])
.map(
(property) => `${
property.description
? `
.map(
(property) => `${
property.description
? `
/**
* ${property.description}
*/`
: ''
}
: ''
}
${property.name}${property.optional ? '?' : ''}: ${typeOfProperty(
property
)};`
)
.join(``)}
property
)};`
)
.join(``)}
}`
: `
: `
export type ${type.id} = ${typeOfProperty(type)};`
}`
)
.join('')}
}`
)
.join('')}
${(domain.events || [])
.map(
(event) =>
@ -146,8 +147,8 @@ declare global {
.join('')}
}
`
)
.join('')}
)
.join('')}
export interface Events {${json.domains
.map((domain) =>
(domain.events || [])
@ -182,7 +183,6 @@ declare global {
.join('')}
}
}
}
export default Protocol;
`;
@ -204,8 +204,13 @@ const writeOutputToDisk = ({ output, version }) => {
console.log(`You should commit the changes.`);
};
const lastCommitMessage = () => {
return execSync('git log --no-merges -n 1', { encoding: 'utf8' });
};
const cli = async () => {
const scriptToRun = process.argv[2];
const changeExpected = lastCommitMessage().includes('EXPECTED_PROTOCOL_DIFF');
if (scriptToRun === 'update') {
writeOutputToDisk(await fetchAndGenerateProtocolDefinitions());
@ -216,6 +221,12 @@ const cli = async () => {
});
if (output === outputOnDisk) {
console.log(`Success: ${relativeProtocolOutputPath} is up to date.`);
} else if (changeExpected) {
console.log(`Warning: ${relativeProtocolOutputPath} is out of date`);
console.log(
' continuing because EXPECTED_PROTOCOL_DIFF was found in the last commit message.'
);
} else {
console.log(`Error: ${relativeProtocolOutputPath} is out of date.`);
console.log(