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. * limitations under the License.
*/ */
// Used as a TypeDef
// eslint-disable-next-line no-unused-vars
import { CDPSession } from './Connection'; import { CDPSession } from './Connection';
// Used as a TypeDef
// eslint-disable-next-line no-unused-vars
import { ElementHandle } from './JSHandle'; import { ElementHandle } from './JSHandle';
import Protocol from './protocol';
interface SerializedAXNode { interface SerializedAXNode {
role: string; role: string;

View File

@ -18,6 +18,7 @@ import { helper, assert } from './helper';
import { Target } from './Target'; import { Target } from './Target';
import * as EventEmitter from 'events'; import * as EventEmitter from 'events';
import { Events } from './Events'; import { Events } from './Events';
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

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

View File

@ -15,6 +15,7 @@
*/ */
import { helper, debugError, assert, PuppeteerEventListener } from './helper'; import { helper, debugError, assert, PuppeteerEventListener } from './helper';
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

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

View File

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

View File

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

View File

@ -21,6 +21,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';
interface BoxModel { interface BoxModel {
content: Array<{ x: number; y: number }>; content: Array<{ x: number; y: number }>;

View File

@ -15,6 +15,7 @@
*/ */
import * as EventEmitter from 'events'; import * as EventEmitter from 'events';
import { helper, assert, debugError } from './helper'; import { helper, assert, debugError } from './helper';
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

@ -39,6 +39,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';
const writeFileAsync = helper.promisify(fs.writeFile); const writeFileAsync = helper.promisify(fs.writeFile);

View File

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

View File

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

View File

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

View File

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

View File

@ -18,6 +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';
type ConsoleAPICalledCallback = ( type ConsoleAPICalledCallback = (
eventType: string, eventType: string,

View File

@ -18,6 +18,7 @@ import * as 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';
const openAsync = promisify(fs.open); const openAsync = promisify(fs.open);
const writeAsync = promisify(fs.write); const writeAsync = promisify(fs.write);

6
src/protocol.d.ts vendored
View File

@ -1,7 +1,7 @@
// This is generated from /utils/protocol-types-generator/index.js // This is generated from /utils/protocol-types-generator/index.js
type binary = string; type binary = string;
declare global {
module Protocol { declare module Protocol {
export module Accessibility { export module Accessibility {
/** /**
* Unique accessibility node identifier. * Unique accessibility node identifier.
@ -15499,6 +15499,4 @@ unsubscribes current runtime agent from Runtime.bindingCalled notifications.
"Schema.getDomains": Schema.getDomainsReturnValue; "Schema.getDomains": Schema.getDomainsReturnValue;
} }
} }
}
export default Protocol; export default Protocol;

View File

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