2020-07-10 10:51:52 +00:00
|
|
|
/**
|
2024-01-03 10:11:33 +00:00
|
|
|
* @license
|
|
|
|
* Copyright 2020 Google Inc.
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
2020-07-10 10:51:52 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This script ensures that the pinned version of devtools-protocol in
|
2023-05-02 06:53:40 +00:00
|
|
|
* package.json is the right version for the current revision of Chrome that
|
2020-07-10 10:51:52 +00:00
|
|
|
* 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.
|
|
|
|
*
|
2023-05-02 06:53:40 +00:00
|
|
|
* Chrome branches/releases are figured out at a later point in time, so it's
|
|
|
|
* not true that each Chrome revision will have an exact matching revision
|
2020-07-10 10:51:52 +00:00
|
|
|
* 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
|
2022-06-01 09:11:09 +00:00
|
|
|
* that's \<= the revision that Puppeteer is using.
|
2020-07-10 10:51:52 +00:00
|
|
|
*
|
|
|
|
* This script uses npm's `view` function to list all versions in a range and
|
2023-05-02 06:53:40 +00:00
|
|
|
* find the one closest to our Chrome revision.
|
2020-07-10 10:51:52 +00:00
|
|
|
*/
|
|
|
|
|
2022-06-22 13:25:44 +00:00
|
|
|
import {execSync} from 'child_process';
|
2020-07-10 10:51:52 +00:00
|
|
|
|
2023-10-23 11:59:10 +00:00
|
|
|
import packageJson from '../package.json' assert {type: 'json'};
|
2023-02-15 23:09:31 +00:00
|
|
|
import {PUPPETEER_REVISIONS} from '../src/revisions.js';
|
2020-07-10 10:51:52 +00:00
|
|
|
|
2023-05-02 06:53:40 +00:00
|
|
|
async function main() {
|
|
|
|
const currentProtocolPackageInstalledVersion =
|
|
|
|
packageJson.dependencies['devtools-protocol'];
|
2020-07-10 10:51:52 +00:00
|
|
|
|
2023-05-02 06:53:40 +00:00
|
|
|
/**
|
|
|
|
* Ensure that the devtools-protocol version is pinned.
|
|
|
|
*/
|
|
|
|
if (/^[^0-9]/.test(currentProtocolPackageInstalledVersion)) {
|
|
|
|
console.log(
|
|
|
|
`ERROR: devtools-protocol package is not pinned to a specific version.\n`
|
|
|
|
);
|
|
|
|
process.exit(1);
|
|
|
|
}
|
2020-07-10 10:51:52 +00:00
|
|
|
|
2023-05-02 06:53:40 +00:00
|
|
|
const chromeVersion = PUPPETEER_REVISIONS.chrome;
|
|
|
|
// find the right revision for our Chrome version.
|
|
|
|
const req = await fetch(
|
2023-10-23 11:59:10 +00:00
|
|
|
`https://googlechromelabs.github.io/chrome-for-testing/known-good-versions.json`
|
2023-05-02 06:53:40 +00:00
|
|
|
);
|
2023-10-23 11:59:10 +00:00
|
|
|
const releases = await req.json();
|
|
|
|
const chromeRevision = releases.versions.find(release => {
|
2023-05-02 06:53:40 +00:00
|
|
|
return release.version === chromeVersion;
|
2023-10-23 11:59:10 +00:00
|
|
|
}).revision;
|
2023-05-02 06:53:40 +00:00
|
|
|
console.log(`Revisions for ${chromeVersion}: ${chromeRevision}`);
|
2020-07-10 10:51:52 +00:00
|
|
|
|
2023-05-02 06:53:40 +00:00
|
|
|
const command = `npm view "devtools-protocol@<=0.0.${chromeRevision}" version | tail -1`;
|
2020-07-10 10:51:52 +00:00
|
|
|
|
2023-05-02 06:53:40 +00:00
|
|
|
console.log(
|
|
|
|
'Checking npm for devtools-protocol revisions:\n',
|
|
|
|
`'${command}'`,
|
|
|
|
'\n'
|
|
|
|
);
|
2020-07-10 10:51:52 +00:00
|
|
|
|
2023-05-02 06:53:40 +00:00
|
|
|
const output = execSync(command, {
|
|
|
|
encoding: 'utf8',
|
|
|
|
});
|
2020-07-10 10:51:52 +00:00
|
|
|
|
2023-05-02 06:53:40 +00:00
|
|
|
const bestRevisionFromNpm = output.split(' ')[1]!.replace(/'|\n/g, '');
|
2020-07-10 10:51:52 +00:00
|
|
|
|
2023-05-02 06:53:40 +00:00
|
|
|
if (currentProtocolPackageInstalledVersion !== bestRevisionFromNpm) {
|
|
|
|
console.log(`ERROR: bad devtools-protocol revision detected:
|
2020-07-10 10:51:52 +00:00
|
|
|
|
2023-05-02 06:53:40 +00:00
|
|
|
Current Puppeteer Chrome revision: ${chromeRevision}
|
2020-07-10 10:51:52 +00:00
|
|
|
Current devtools-protocol version in package.json: ${currentProtocolPackageInstalledVersion}
|
|
|
|
Expected devtools-protocol version: ${bestRevisionFromNpm}`);
|
|
|
|
|
2023-05-02 06:53:40 +00:00
|
|
|
process.exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
console.log(
|
|
|
|
`Correct devtools-protocol version found (${bestRevisionFromNpm}).`
|
|
|
|
);
|
|
|
|
process.exit(0);
|
2020-07-10 10:51:52 +00:00
|
|
|
}
|
|
|
|
|
2023-05-02 06:53:40 +00:00
|
|
|
void main();
|