Skip to content

Commit 8e63654

Browse files
committed
add a fallback
1 parent 33a2e7e commit 8e63654

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

packages/optimizer/lib/fetchRuntimeParameters.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717

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

120-
debugger;
121121
const configResponse = await config.fetch(componentConfigUrl);
122122
let latestVersionsConfigResponse = await config.fetch(componentLatestVersionsUrl);
123123
if (!configResponse.ok) {
@@ -132,12 +132,16 @@ async function fetchComponentVersions_(config, runtimeParameters) {
132132
latestVersionsConfigResponse = await config.fetch(componentLatestVersionsUrlFallback);
133133
if (!latestVersionsConfigResponse.ok) {
134134
throw new Error(
135-
`Failed fetching latest component versions from ${URL_COMPONENT_LATEST_VERSIONS} with status: ${latestVersionsConfig.status}`
135+
`Failed fetching latest component versions from ${URL_COMPONENT_LATEST_VERSIONS} with status: ${latestVersionsConfigResponse.status}`
136136
);
137137
}
138138
}
139139
const configJson = await configResponse.json();
140-
const latestVersionConfigJson = JSON5.parse(await latestVersionsConfigResponse.text());
140+
const latestVersionsConfigJson = JSON5.parse(await latestVersionsConfigResponse.text());
141+
configJson.forEach((entry) => {
142+
entry['latestVersion'] = latestVersionsConfigJson[entry.name];
143+
});
144+
return configJson;
141145
}
142146

143147
/**

0 commit comments

Comments
 (0)