Skip to content

Commit 4fbddd8

Browse files
committed
fetch the jsonc latestVersion file
1 parent cdb8c1a commit 4fbddd8

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

packages/optimizer/lib/fetchRuntimeParameters.js

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -113,29 +113,31 @@ async function fetchComponentVersionsFromCache_(config, runtimeParameters) {
113113
async function fetchComponentVersions_(config, runtimeParameters) {
114114
// Strip the leading two chars from the version identifier to get the release tag
115115
const releaseTag = runtimeParameters.ampRuntimeVersion.substring(2);
116-
console.log('releaseTag', releaseTag);
117116
const componentConfigUrl = `https://raw.githubusercontent.com/ampproject/amphtml/${releaseTag}/build-system/compile/bundles.config.extensions.json`;
118117
const componentLatestVersionsUrl = `https://raw.githubusercontent.com/ampproject/amphtml/${releaseTag}/build-system/compile/bundles.legacy-latest-versions.jsonc`;
118+
const componentLatestVersionsUrlFallback = `https://raw.githubusercontent.com/ampproject/amphtml/main/build-system/compile/bundles.legacy-latest-versions.jsonc`;
119119

120+
debugger;
120121
const configResponse = await config.fetch(componentConfigUrl);
121-
const latestVersionsConfigResponse = await config.fetch(componentLatestVersionsUrl);
122+
let latestVersionsConfigResponse = await config.fetch(componentLatestVersionsUrl);
122123
if (!configResponse.ok) {
123-
console.log('a');
124-
debugger;
125124
throw new Error(
126125
`Failed fetching latest component versions from ${URL_COMPONENT_VERSIONS} with status: ${configResponse.status}`
127126
);
128127
}
129-
if (!latestVersionsConfig.ok) {
130-
console.log('b');
131-
debugger;
132-
throw new Error(
133-
`Failed fetching latest component versions from ${URL_COMPONENT_LATEST_VERSIONS} with status: ${latestVersionsConfig.status}`
134-
);
128+
// If the fetch for the latestVersion jsonc file fails, we try again using the
129+
// main branch since it might not exist yet in the old releaseTag. The latestVersion's
130+
// are frozen so its unlikely to have changed.
131+
if (!latestVersionsConfigResponse.ok) {
132+
latestVersionsConfigResponse = await config.fetch(componentLatestVersionsUrlFallback);
133+
if (!latestVersionsConfigResponse.ok) {
134+
throw new Error(
135+
`Failed fetching latest component versions from ${URL_COMPONENT_LATEST_VERSIONS} with status: ${latestVersionsConfig.status}`
136+
);
137+
}
135138
}
136-
console.log('c');
137-
debugger;
138-
return configResponse.json();
139+
const configJson = await configResponse.json();
140+
const latestVersionConfigJson = JSON5.parse(await latestVersionsConfigResponse.text());
139141
}
140142

141143
/**

0 commit comments

Comments
 (0)