Skip to content

Commit

Permalink
add a fallback
Browse files Browse the repository at this point in the history
  • Loading branch information
erwinmombay committed Jan 5, 2022
1 parent 33a2e7e commit 8e63654
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions packages/optimizer/lib/fetchRuntimeParameters.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@

const URL_COMPONENT_VERSIONS =
'https://raw.githubusercontent.com/ampproject/amphtml/main/build-system/compile/bundles.config.extensions.json';
const URL_COMPONENT_LATEST_VERSIONS = 'https://raw.githubusercontent.com/ampproject/amphtml/main/build-system/compile/bundles.legacy-latest-versions.jsonc';
const URL_COMPONENT_LATEST_VERSIONS =
'https://raw.githubusercontent.com/ampproject/amphtml/main/build-system/compile/bundles.legacy-latest-versions.jsonc';
const validatorRulesProvider = require('@ampproject/toolbox-validator-rules');
const {MaxAge} = require('@ampproject/toolbox-core');
const JSON5 = require('json5');
Expand Down Expand Up @@ -117,7 +118,6 @@ async function fetchComponentVersions_(config, runtimeParameters) {
const componentLatestVersionsUrl = `https://raw.githubusercontent.com/ampproject/amphtml/${releaseTag}/build-system/compile/bundles.legacy-latest-versions.jsonc`;
const componentLatestVersionsUrlFallback = `https://raw.githubusercontent.com/ampproject/amphtml/main/build-system/compile/bundles.legacy-latest-versions.jsonc`;

debugger;
const configResponse = await config.fetch(componentConfigUrl);
let latestVersionsConfigResponse = await config.fetch(componentLatestVersionsUrl);
if (!configResponse.ok) {
Expand All @@ -132,12 +132,16 @@ async function fetchComponentVersions_(config, runtimeParameters) {
latestVersionsConfigResponse = await config.fetch(componentLatestVersionsUrlFallback);
if (!latestVersionsConfigResponse.ok) {
throw new Error(
`Failed fetching latest component versions from ${URL_COMPONENT_LATEST_VERSIONS} with status: ${latestVersionsConfig.status}`
`Failed fetching latest component versions from ${URL_COMPONENT_LATEST_VERSIONS} with status: ${latestVersionsConfigResponse.status}`
);
}
}
const configJson = await configResponse.json();
const latestVersionConfigJson = JSON5.parse(await latestVersionsConfigResponse.text());
const latestVersionsConfigJson = JSON5.parse(await latestVersionsConfigResponse.text());
configJson.forEach((entry) => {
entry['latestVersion'] = latestVersionsConfigJson[entry.name];
});
return configJson;
}

/**
Expand Down

0 comments on commit 8e63654

Please sign in to comment.