From 7e511b11a806e0c4abc528cc77b075fbcf314596 Mon Sep 17 00:00:00 2001 From: Jack Franklin Date: Wed, 8 Jul 2020 10:29:21 +0100 Subject: [PATCH] Ensure the right devtools-protocol package version --- .travis.yml | 1 + new-docs/puppeteer.cdpsession.send.md | 6 +- new-docs/puppeteer.connection.send.md | 6 +- new-docs/puppeteer.page.deletecookie.md | 4 +- package.json | 5 +- ...nsure-correct-devtools-protocol-package.ts | 83 +++++++++++++++++++ 6 files changed, 95 insertions(+), 10 deletions(-) create mode 100644 scripts/ensure-correct-devtools-protocol-package.ts diff --git a/.travis.yml b/.travis.yml index e94866667d1be..323bbb3e4cdb3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -66,6 +66,7 @@ jobs: - npm run lint - npm run test-doclint - npm run ensure-new-docs-up-to-date + - npm run ensure-correct-devtools-protocol-package # This bot runs separately as it changes package.json to test puppeteer-core # and we don't want that leaking into other bots and causing issues. diff --git a/new-docs/puppeteer.cdpsession.send.md b/new-docs/puppeteer.cdpsession.send.md index 8fba8aa8ca60f..7e5559b952336 100644 --- a/new-docs/puppeteer.cdpsession.send.md +++ b/new-docs/puppeteer.cdpsession.send.md @@ -7,7 +7,7 @@ Signature: ```typescript -send(method: T, params?: Protocol.CommandParameters[T]): Promise; +send(method: T, params?: ProtocolMapping.Commands[T]['paramsType'][0]): Promise; ``` ## Parameters @@ -15,9 +15,9 @@ send(method: T, params?: Protocol.Co | Parameter | Type | Description | | --- | --- | --- | | method | T | | -| params | Protocol.CommandParameters\[T\] | | +| params | ProtocolMapping.Commands\[T\]\['paramsType'\]\[0\] | | Returns: -Promise<Protocol.CommandReturnValues\[T\]> +Promise<ProtocolMapping.Commands\[T\]\['returnType'\]> diff --git a/new-docs/puppeteer.connection.send.md b/new-docs/puppeteer.connection.send.md index f5efdddadfa36..ac9f6953244b9 100644 --- a/new-docs/puppeteer.connection.send.md +++ b/new-docs/puppeteer.connection.send.md @@ -7,7 +7,7 @@ Signature: ```typescript -send(method: T, params?: Protocol.CommandParameters[T]): Promise; +send(method: T, params?: ProtocolMapping.Commands[T]['paramsType'][0]): Promise; ``` ## Parameters @@ -15,9 +15,9 @@ send(method: T, params?: Protocol.Co | Parameter | Type | Description | | --- | --- | --- | | method | T | | -| params | Protocol.CommandParameters\[T\] | | +| params | ProtocolMapping.Commands\[T\]\['paramsType'\]\[0\] | | Returns: -Promise<Protocol.CommandReturnValues\[T\]> +Promise<ProtocolMapping.Commands\[T\]\['returnType'\]> diff --git a/new-docs/puppeteer.page.deletecookie.md b/new-docs/puppeteer.page.deletecookie.md index 58522b41a81ce..edb0e6c4fb490 100644 --- a/new-docs/puppeteer.page.deletecookie.md +++ b/new-docs/puppeteer.page.deletecookie.md @@ -7,14 +7,14 @@ Signature: ```typescript -deleteCookie(...cookies: Protocol.Network.deleteCookiesParameters[]): Promise; +deleteCookie(...cookies: Protocol.Network.DeleteCookiesRequest[]): Promise; ``` ## Parameters | Parameter | Type | Description | | --- | --- | --- | -| cookies | Protocol.Network.deleteCookiesParameters\[\] | | +| cookies | Protocol.Network.DeleteCookiesRequest\[\] | | Returns: diff --git a/package.json b/package.json index 10f0c6fa813da..3ba06be909414 100644 --- a/package.json +++ b/package.json @@ -32,7 +32,8 @@ "test-install": "scripts/test-install.sh", "generate-docs": "npm run tsc && api-extractor run --local --verbose && api-documenter markdown -i temp -o new-docs", "ensure-new-docs-up-to-date": "npm run generate-docs && exit `git status --porcelain | head -255 | wc -l`", - "generate-dependency-graph": "echo 'Requires graphviz installed locally!' && depcruise --exclude 'api.ts' --do-not-follow '^node_modules' --output-type dot src/index.ts | dot -T png > dependency-chart.png" + "generate-dependency-graph": "echo 'Requires graphviz installed locally!' && depcruise --exclude 'api.ts' --do-not-follow '^node_modules' --output-type dot src/index.ts | dot -T png > dependency-chart.png", + "ensure-correct-devtools-protocol-revision": "ts-node scripts/ensure-correct-devtools-protocol-package" }, "files": [ "lib/", @@ -45,7 +46,7 @@ "license": "Apache-2.0", "dependencies": { "debug": "^4.1.0", - "devtools-protocol": "0.0.758979", + "devtools-protocol": "0.0.754670", "extract-zip": "^2.0.0", "https-proxy-agent": "^4.0.0", "mime": "^2.0.3", diff --git a/scripts/ensure-correct-devtools-protocol-package.ts b/scripts/ensure-correct-devtools-protocol-package.ts new file mode 100644 index 0000000000000..eb3a1f149ff5b --- /dev/null +++ b/scripts/ensure-correct-devtools-protocol-package.ts @@ -0,0 +1,83 @@ +/** + * Copyright 2020 Google Inc. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * This script ensures that the pinned version of devtools-protocol in + * package.json is the right version for the current revision of Chromium that + * Puppeteer ships with. + * + * The devtools-protocol package publisher runs every hour and checks if there + * are protocol changes. If there are, it will be versioned with the revision + * number of the commit that last changed the .pdl files. + * + * Chromium branches/releases are figured out at a later point in time, so it's + * not true that each Chromium revision will have an exact matching revision + * version of devtools-protocol. To ensure we're using a devtools-protocol that + * is aligned with our revision, we want to find the largest package number + * that's <= the revision that Puppeteer is using. + * + * This script uses npm's `view` function to list all versions in a range and + * find the one closest to our Chromium revision. + */ + +import { PUPPETEER_REVISIONS } from '../src/revisions'; +import { execSync } from 'child_process'; + +import packageJson from '../package.json'; + +const currentProtocolPackageInstalledVersion = + packageJson.dependencies['devtools-protocol']; + +/** + * Ensure that the devtools-protocol version is pinned. + */ +if (!currentProtocolPackageInstalledVersion[0].match(/[0-9]/)) { + console.log( + `ERROR: devtools-protocol package is not pinned to a specific version.\n` + ); + process.exit(1); +} + +// find the right revision for our Chromium revision + +const command = `npm view "devtools-protocol@<=0.0.${PUPPETEER_REVISIONS.chromium}" version | tail -1`; + +console.log( + 'Checking npm for devtools-protocol revisions:\n', + `'${command}'`, + '\n' +); + +const output = execSync(command, { + encoding: 'utf8', +}); + +const bestRevisionFromNpm = output.split(' ')[1].replace(/'|\n/g, ''); + +if (currentProtocolPackageInstalledVersion !== bestRevisionFromNpm) { + console.log(`ERROR: bad devtools-protocol revision detected: + + Current Pptr Chromium revision: ${PUPPETEER_REVISIONS.chromium} + Current devtools-protocol version in package.json: ${currentProtocolPackageInstalledVersion} + Expected devtools-protocol version: ${bestRevisionFromNpm}`); + + process.exit(1); +} + +console.log( + `Correct devtools-protocol version found (${bestRevisionFromNpm}).` +); +process.exit(0);