cherry-pick(#15933): fix: accomodate to changed MSEdge download format (#15935)

Fixes #15932
This commit is contained in:
Andrey Lushnikov 2022-07-25 17:38:19 -07:00 committed by GitHub
parent 2964ed5982
commit dc0651ddd2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -746,21 +746,22 @@ export class Registry {
private async _installMSEdgeChannel(channel: 'msedge'|'msedge-beta'|'msedge-dev', scripts: Record<'linux' | 'darwin' | 'win32', string>) {
const scriptArgs: string[] = [];
if (process.platform !== 'linux') {
const products = JSON.parse(await fetchData({ url: 'https://edgeupdates.microsoft.com/api/products' }));
const products = lowercaseAllKeys(JSON.parse(await fetchData({ url: 'https://edgeupdates.microsoft.com/api/products' })));
const productName = {
'msedge': 'Stable',
'msedge-beta': 'Beta',
'msedge-dev': 'Dev',
}[channel];
const product = products.find((product: any) => product.Product === productName);
const product = products.find((product: any) => product.product === productName);
const searchConfig = ({
darwin: { platform: 'MacOS', arch: 'universal', artifact: 'pkg' },
win32: { platform: 'Windows', arch: 'x64', artifact: 'msi' },
} as any)[process.platform];
const release = searchConfig ? product.Releases.find((release: any) => release.Platform === searchConfig.platform && release.Architecture === searchConfig.arch) : null;
const artifact = release ? release.Artifacts.find((artifact: any) => artifact.ArtifactName === searchConfig.artifact) : null;
const release = searchConfig ? product.releases.find((release: any) => release.platform === searchConfig.platform && release.architecture === searchConfig.arch) : null;
const artifact = release ? release.artifacts.find((artifact: any) => artifact.artifactname === searchConfig.artifact) : null;
if (artifact)
scriptArgs.push(artifact.Location /* url */);
scriptArgs.push(artifact.location /* url */);
else
throw new Error(`Cannot install ${channel} on ${process.platform}`);
}
@ -908,4 +909,17 @@ export function findChromiumChannel(sdkLanguage: string): string | undefined {
return channel;
}
function lowercaseAllKeys(json: any): any {
if (typeof json !== 'object' || !json)
return json;
if (Array.isArray(json))
return json.map(lowercaseAllKeys);
const result: any = {};
for (const [key, value] of Object.entries(json))
result[key.toLowerCase()] = lowercaseAllKeys(value);
return result;
}
export const registry = new Registry(require('../../../browsers.json'));