Skip to content

Commit

Permalink
Ensure the right devtools-protocol package version
Browse files Browse the repository at this point in the history
  • Loading branch information
jackfranklin committed Jul 8, 2020
1 parent 97045c8 commit 7e511b1
Show file tree
Hide file tree
Showing 6 changed files with 95 additions and 10 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Expand Up @@ -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.
Expand Down
6 changes: 3 additions & 3 deletions new-docs/puppeteer.cdpsession.send.md
Expand Up @@ -7,17 +7,17 @@
<b>Signature:</b>

```typescript
send<T extends keyof Protocol.CommandParameters>(method: T, params?: Protocol.CommandParameters[T]): Promise<Protocol.CommandReturnValues[T]>;
send<T extends keyof ProtocolMapping.Commands>(method: T, params?: ProtocolMapping.Commands[T]['paramsType'][0]): Promise<ProtocolMapping.Commands[T]['returnType']>;
```
## Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| method | T | |
| params | Protocol.CommandParameters\[T\] | |
| params | ProtocolMapping.Commands\[T\]\['paramsType'\]\[0\] | |
<b>Returns:</b>
Promise&lt;Protocol.CommandReturnValues\[T\]&gt;
Promise&lt;ProtocolMapping.Commands\[T\]\['returnType'\]&gt;
6 changes: 3 additions & 3 deletions new-docs/puppeteer.connection.send.md
Expand Up @@ -7,17 +7,17 @@
<b>Signature:</b>

```typescript
send<T extends keyof Protocol.CommandParameters>(method: T, params?: Protocol.CommandParameters[T]): Promise<Protocol.CommandReturnValues[T]>;
send<T extends keyof ProtocolMapping.Commands>(method: T, params?: ProtocolMapping.Commands[T]['paramsType'][0]): Promise<ProtocolMapping.Commands[T]['returnType']>;
```
## Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| method | T | |
| params | Protocol.CommandParameters\[T\] | |
| params | ProtocolMapping.Commands\[T\]\['paramsType'\]\[0\] | |
<b>Returns:</b>
Promise&lt;Protocol.CommandReturnValues\[T\]&gt;
Promise&lt;ProtocolMapping.Commands\[T\]\['returnType'\]&gt;
4 changes: 2 additions & 2 deletions new-docs/puppeteer.page.deletecookie.md
Expand Up @@ -7,14 +7,14 @@
<b>Signature:</b>

```typescript
deleteCookie(...cookies: Protocol.Network.deleteCookiesParameters[]): Promise<void>;
deleteCookie(...cookies: Protocol.Network.DeleteCookiesRequest[]): Promise<void>;
```

## Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| cookies | Protocol.Network.deleteCookiesParameters\[\] | |
| cookies | Protocol.Network.DeleteCookiesRequest\[\] | |

<b>Returns:</b>

Expand Down
5 changes: 3 additions & 2 deletions package.json
Expand Up @@ -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/",
Expand All @@ -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",
Expand Down
83 changes: 83 additions & 0 deletions 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);

0 comments on commit 7e511b1

Please sign in to comment.